mafia_controller
The mafia controller handles the mafia minigame in progress. It is first created when the first ghost signs up to play.
Vars | |
all_roles | all roles in the game, dead or alive. check their game status if you only want living or dead. |
---|---|
current_map | template picked when the game starts. used for the name and desc reading |
current_setup_text | Readable list of roles in current game, sent to the tgui panel for roles list > list("Psychologist x1", "Clown x2") |
custom_setup | for debugging and testing a full game, or adminbuse. If this is not empty, it will use this as a setup. clears when game is over |
default_role_list | The 12 roles used in a default game, selected randomly from each list, going in order of position. This is balanced for player amount, regardless of players you'll still be about equal town and evils. |
early_start | was our game forced to start early? |
judgement_abstain_votes | and these (judgement_innocent_votes, judgement_abstain_votes and judgement_guilty_votes) are the judgement phase votes, aka people sorting themselves into guilty and innocent, and "eh, i don't really care" lists. whichever has more inno or guilty wins! |
landmarks | spawn points for players, each one has a house |
living_roles | all living roles in the game, removed on death. |
map_deleter | map generation tool that deletes the current map after the game finishes |
next_phase_timer | current timer for phase |
on_trial | current role on trial for the judgement phase, will die if guilty is greater than innocent |
phase | what part of the game you're playing in. day phases, night phases, judgement phases, etc. |
player_outfit | starting outfit for all mafia players. it's just a grey jumpsuit. |
player_role_lookup | exists to speed up role retrieval, it's a dict.
player_role_lookup[player ckey/PDA] will give you the role they play |
time_speedup | How much faster the game should be, which triggers when half the players are dead. |
town_center_landmark | town center for when people get put on trial |
turn | how long the game has gone on for, changes with every sunrise. day one, night one, day two, etc. |
votes | group voting on one person, like putting people to trial or choosing who to kill as mafia |
Procs | |
add_setup_role | Helper proc that adds a random role of a type to a setup. if it doesn't exist in the setup, it adds the path to the list and otherwise bumps the path in the list up one. unique roles can only get added once. |
award_role | Lets the game award roles with all their checks and sanity, prevents achievements given out for debug games |
basic_setup | Called when enough players have signed up to fill a setup. DOESN'T NECESSARILY MEAN THE GAME WILL START. |
check_signups | Filters inactive player into a different list until they reconnect, and removes players who are no longer ghosts. |
check_start_votes | Checks if we have enough early start votes to begin the game early. |
check_trial | Players have voted someone up, and now the person must defend themselves while the town votes innocent or guilty. |
check_victory | Checks to see if a faction (or solo antagonist) has won. |
create_bodies | Called when the game is setting up, AFTER map is loaded but BEFORE the phase timers start. Creates and places each role's body and gives the correct player key |
display_votes | Adds mutable appearances to people who get publicly voted on (so not night votes) showing how many people are picking them Arguments: |
end_game | Cleans up the game, resetting variables back to the beginning and removing the map with the generator. |
filter_players | Handles the filtering of disconected signups when picking who gets to be in the round. |
forced_setup | Generates a forced role list and runs the game with the current number of signed-up players. |
generate_standard_setup | Returns a standard setup, with certain important/unique roles guaranteed. |
get_random_voter | Returns a random person who voted for whatever vote (day vote, night kill vote) Arguments: |
get_role_player | From a 'user' (Either a mob or ModPC) or TGUI UI, will try to find the Mafia role from 'player_role_lookup'. |
get_vote_count | Returns how many people voted for the role, in whatever vote (day vote, night kill vote) Arguments: |
get_vote_winner | Returns whichever role got the most votes, in whatever vote (day vote, night kill vote) returns null if no votes Arguments: |
lockdown | After the voting and judgement phases, the game goes to night shutting the windows and beginning night with a proc. |
lynch | Players have voted innocent or guilty on the person on trial, and that person is now killed or returned home. |
prepare_game | Triggers at beginning of the game when there is a confirmed list of valid, ready players. Creates a 100% ready game that has NOT started (no players in bodies) Followed by start game |
reset_votes | Clears out the votes of a certain type (day votes, mafia kill votes) while leaving others untouched |
resolve_night | The end of the night, and a series of signals for the order of events on a night. |
send_home | Teenie helper proc to move players back to their home. Used in the above, but also used in the debug button "send all players home" Arguments: |
send_message | Sends a global message to all players, or just 'team' if set. |
signup_mafia | Signs the player up for Mafia, or removes them from the list if they are already signed up. Args: |
start_day | How every day starts. |
start_game | The game by this point is now all set up, and so we can put people in their bodies and start the first phase. |
start_night | The actual start of night for players. Mostly info is given at the start of the night as the end of the night is when votes and actions are submitted and tried. |
start_the_end | The end of the game is in two procs, because we want a bit of time for players to see eachothers roles. Because of how check_victory works, the game is halted in other places by this point. We won't delete ourselves in a certain amount of time in unit tests, as the unit test will handle our deletion instead. |
start_voting_phase | Players have finished the discussion period, and now must put up someone to the chopping block. |
toggle_night_curtains | Shuts poddoors attached to mafia. Arguments: |
try_autostart | Called when someone signs up, and sees if there are enough people in the signup list to begin. |
vote_for | Proc that goes off when players vote for something with their mafia panel. |
Var Details
all_roles
all roles in the game, dead or alive. check their game status if you only want living or dead.
current_map
template picked when the game starts. used for the name and desc reading
current_setup_text
Readable list of roles in current game, sent to the tgui panel for roles list > list("Psychologist x1", "Clown x2")
custom_setup
for debugging and testing a full game, or adminbuse. If this is not empty, it will use this as a setup. clears when game is over
default_role_list
The 12 roles used in a default game, selected randomly from each list, going in order of position. This is balanced for player amount, regardless of players you'll still be about equal town and evils.
early_start
was our game forced to start early?
judgement_abstain_votes
and these (judgement_innocent_votes, judgement_abstain_votes and judgement_guilty_votes) are the judgement phase votes, aka people sorting themselves into guilty and innocent, and "eh, i don't really care" lists. whichever has more inno or guilty wins!
landmarks
spawn points for players, each one has a house
living_roles
all living roles in the game, removed on death.
map_deleter
map generation tool that deletes the current map after the game finishes
next_phase_timer
current timer for phase
on_trial
current role on trial for the judgement phase, will die if guilty is greater than innocent
phase
what part of the game you're playing in. day phases, night phases, judgement phases, etc.
player_outfit
starting outfit for all mafia players. it's just a grey jumpsuit.
player_role_lookup
exists to speed up role retrieval, it's a dict.
player_role_lookup[player ckey/PDA]
will give you the role they play
time_speedup
How much faster the game should be, which triggers when half the players are dead.
town_center_landmark
town center for when people get put on trial
turn
how long the game has gone on for, changes with every sunrise. day one, night one, day two, etc.
votes
group voting on one person, like putting people to trial or choosing who to kill as mafia
Proc Details
add_setup_role
Helper proc that adds a random role of a type to a setup. if it doesn't exist in the setup, it adds the path to the list and otherwise bumps the path in the list up one. unique roles can only get added once.
award_role
Lets the game award roles with all their checks and sanity, prevents achievements given out for debug games
Arguments:
- award: path of the award
- role: mafia_role datum to reward.
basic_setup
Called when enough players have signed up to fill a setup. DOESN'T NECESSARILY MEAN THE GAME WILL START.
Checks for a custom setup, if so gets the required players from that and if not it sets the player requirement to MAFIA_MAX_PLAYER_COUNT and generates one IF basic setup starts a game. Checks if everyone signed up is an observer, and is still connected. If people aren't, they're removed from the list. If there aren't enough players post sanity, it aborts. otherwise, it selects enough people for the game and starts preparing the game for real.
check_signups
Filters inactive player into a different list until they reconnect, and removes players who are no longer ghosts.
If a disconnected player gets a non-ghost mob and reconnects, they will be first put back into mafia_signup then filtered by that.
check_start_votes
Checks if we have enough early start votes to begin the game early.
Checks if we have the bare minimum of three signups, then checks if the number of early voters is at least half of the total number of active signups.
check_trial
Players have voted someone up, and now the person must defend themselves while the town votes innocent or guilty.
What players do in this phase:
- Vote innocent or guilty, if they are not on trial.
- Defend themselves and wait for judgement, if they are.
- Leads to the lynch phase. Arguments:
- verbose: boolean, announces whether there were votes or not. after judgement it goes back here with no voting period to end the day.
check_victory
Checks to see if a faction (or solo antagonist) has won.
Calculates in this order:
- counts up town, mafia, and solo
- solos can count as town members for the purposes of mafia winning
- sends the amount of living people to the solo antagonists, and see if they won, then if town, then if mafia
- starts the end of the game if a faction won
- returns TRUE if someone won the game, halting other procs from continuing in the case of a victory
create_bodies
Called when the game is setting up, AFTER map is loaded but BEFORE the phase timers start. Creates and places each role's body and gives the correct player key
Notably:
- Toggles godmode so the mafia players cannot kill themselves
- Adds signals for voting overlays, see display_votes proc
- gives mafia panel
- sends the greeting text (goals, role name, etc)
display_votes
Adds mutable appearances to people who get publicly voted on (so not night votes) showing how many people are picking them Arguments:
- source: the body of the role getting the overlays
- overlay_list: signal var passing the overlay list of the mob
end_game
Cleans up the game, resetting variables back to the beginning and removing the map with the generator.
filter_players
Handles the filtering of disconected signups when picking who gets to be in the round.
Filters out the player list, from a given max_players count. If more players are found in the signup list than max_players, those players will be notified that they will not be put into the game.
This should only be run as we are in the process of starting a game.
max_players - The maximum number of keys to put in our return list before we start telling people they're not getting in. filtered_keys_and_pdas - A list of player ckeys and PDAs, to be included in the game.
forced_setup
Generates a forced role list and runs the game with the current number of signed-up players.
Generates a randomized setup, and begins the game with everyone currently signed up.
generate_standard_setup
Returns a standard setup, with certain important/unique roles guaranteed.
please check the variables at the top of the proc to see how much of each role types it picks Args: req_players - The amount of players needed.
get_random_voter
Returns a random person who voted for whatever vote (day vote, night kill vote) Arguments:
- vote_type: vote type (getting a random day voter, or mafia night voter)
get_role_player
From a 'user' (Either a mob or ModPC) or TGUI UI, will try to find the Mafia role from 'player_role_lookup'.
get_vote_count
Returns how many people voted for the role, in whatever vote (day vote, night kill vote) Arguments:
- role: the mafia role the proc tries to get the amount of votes for
- vote_type: the vote type (getting how many day votes were for the role, or mafia night votes for the role)
get_vote_winner
Returns whichever role got the most votes, in whatever vote (day vote, night kill vote) returns null if no votes Arguments:
- vote_type: the vote type (getting the role that got the most day votes, or the role that got the most mafia votes)
lockdown
After the voting and judgement phases, the game goes to night shutting the windows and beginning night with a proc.
lynch
Players have voted innocent or guilty on the person on trial, and that person is now killed or returned home.
What players do in this phase:
- r/watchpeopledie
- If the accused is killed, their true role is revealed to the rest of the players.
prepare_game
Triggers at beginning of the game when there is a confirmed list of valid, ready players. Creates a 100% ready game that has NOT started (no players in bodies) Followed by start game
Does the following:
- Picks map, and loads it
- Grabs landmarks if it is the first time it's loading
- Sets up the role list
- Puts players in each role randomly Arguments:
- setup_list: list of all the datum setups (fancy list of roles) that would work for the game
- ready_ghosts_and_pdas: list of filtered, sane (so not playing or disconnected) ghost ckeys & PDAs for the game to put into roles.
reset_votes
Clears out the votes of a certain type (day votes, mafia kill votes) while leaving others untouched
resolve_night
The end of the night, and a series of signals for the order of events on a night.
Order of events, and what they mean:
- Start of resolve (NIGHT_START) is for activating night abilities that MUST go first
- Action phase (NIGHT_ACTION_PHASE) is for non-lethal day abilities
- Mafia then tallies votes and kills the highest voted person (note: one random voter visits that person for the purposes of roleblocking)
- Killing phase (NIGHT_KILL_PHASE) is for lethal night abilities
- End of resolve (NIGHT_END) is for cleaning up abilities that went off and i guess doing some that must go last
- Finally opens the curtains and calls the start of day phase, completing the cycle until check victory returns TRUE
send_home
Teenie helper proc to move players back to their home. Used in the above, but also used in the debug button "send all players home" Arguments:
- role: mafia role that is getting sent back to the game.
send_message
Sends a global message to all players, or just 'team' if set.
signup_mafia
Signs the player up for Mafia, or removes them from the list if they are already signed up. Args:
- ghost_client: is the client of the observer signing up. This can be null in favor of modpc.
- modpc: is a living player signing up through a PDA. This can be null in favor of ghost_client.
start_day
How every day starts.
What players do in this phase:
- If day one, just a small starting period to see who is in the game and check role, leading to the night phase.
- Otherwise, it's a longer period used to discuss events that happened during the night, leading to the voting phase.
start_game
The game by this point is now all set up, and so we can put people in their bodies and start the first phase.
Does the following:
- Creates bodies for all of the roles with the first proc
- Starts the first day manually (so no timer) with the second proc
start_night
The actual start of night for players. Mostly info is given at the start of the night as the end of the night is when votes and actions are submitted and tried.
What players do in this phase:
- Mafia are told to begin voting on who to kill
- Powers that are picked during the day announce themselves right now
start_the_end
The end of the game is in two procs, because we want a bit of time for players to see eachothers roles. Because of how check_victory works, the game is halted in other places by this point. We won't delete ourselves in a certain amount of time in unit tests, as the unit test will handle our deletion instead.
What players do in this phase:
- See everyone's role postgame
- See who won the game Arguments:
- message: string, if non-null it sends it to all players. used to announce team victories while solos are handled in check victory
start_voting_phase
Players have finished the discussion period, and now must put up someone to the chopping block.
What players do in this phase:
- Vote on which player to put up for lynching, leading to the judgement phase.
- If no votes are case, the judgement phase is skipped, leading to the night phase.
toggle_night_curtains
Shuts poddoors attached to mafia. Arguments:
- close: boolean, the state you want the curtains in.
try_autostart
Called when someone signs up, and sees if there are enough people in the signup list to begin.
Only checks if everyone is actually valid to start (still connected and an observer) if there are enough players (basic_setup)
vote_for
Proc that goes off when players vote for something with their mafia panel.
If teams, it hides the tally overlay and only sends the vote messages to the team that is voting Arguments:
- voter: the mafia role that is trying to vote for...
- target: the mafia role that is getting voted for
- vote_type: type of vote submitted (is this the day vote? is this the mafia night vote?)
- teams: see mafia team defines for what to put in, makes the messages only send to a specific team (so mafia night votes only sending messages to mafia at night)