/*
* GAMEMODES (by Rastaf0)
*
* In the new mode system all special roles are fully supported.
* You can have proper wizards/traitors/changelings/cultists during any mode.
* Only two things really depends on gamemode:
* 1. Starting roles, equipment and preparations
* 2. Conditions of finishing the round.
*
*/
/datum/game_mode
var/name = "invalid"
var/config_tag = null
var/votable = 1
var/probability = 0
var/station_was_nuked = 0 //see nuclearbomb.dm and malfunction.dm
var/explosion_in_progress = 0 //sit back and relax
var/round_ends_with_antag_death = 0 //flags the "one verse the station" antags as such
var/list/datum/mind/modePlayer = new
var/list/datum/mind/antag_candidates = list() // List of possible starting antags goes here
var/list/restricted_jobs = list() // Jobs it doesn't make sense to be. I.E chaplain or AI cultist
var/list/protected_jobs = list() // Jobs that can't be traitors because
var/required_players = 0
var/maximum_players = -1 // -1 is no maximum, positive numbers limit the selection of a mode on overstaffed stations
var/required_enemies = 0
var/recommended_enemies = 0
var/antag_flag = null //preferences flag such as BE_WIZARD that need to be turned on for players to be antag
var/mob/living/living_antag_player = null
var/list/datum/game_mode/replacementmode = null
var/round_converted = 0 //0: round not converted, 1: round going to convert, 2: round converted
var/reroll_friendly //During mode conversion only these are in the running
var/continuous_sanity_checked //Catches some cases where config options could be used to suggest that modes without antagonists should end when all antagonists die
var/enemy_minimum_age = 7 //How many days must players have been playing before they can play this antagonist
var/announce_span = "warning" //The gamemode's name will be in this span during announcement.
var/announce_text = "This gamemode forgot to set a descriptive text! Uh oh!" //Used to describe a gamemode when it's announced.
var/const/waittime_l = 600
var/const/waittime_h = 1800 // started at 1800
var/list/datum/station_goal/station_goals = list()
/datum/game_mode/proc/announce() //Shows the gamemode's name and a fast description.
to_chat(world, "The gamemode is: [name]!")
to_chat(world, "[announce_text]")
///Checks to see if the game can be setup and ran with the current number of players or whatnot.
/datum/game_mode/proc/can_start()
var/playerC = 0
for(var/mob/dead/new_player/player in GLOB.player_list)
if((player.client)&&(player.ready))
playerC++
if(!GLOB.Debug2)
if(playerC < required_players || (maximum_players >= 0 && playerC > maximum_players))
return 0
antag_candidates = get_players_for_role(antag_flag)
if(!GLOB.Debug2)
if(antag_candidates.len < required_enemies)
return 0
return 1
else
message_admins("DEBUG: GAME STARTING WITHOUT PLAYER NUMBER CHECKS, THIS WILL PROBABLY BREAK SHIT.")
return 1
///Attempts to select players for special roles the mode might have.
/datum/game_mode/proc/pre_setup()
return 1
///Everyone should now be on the station and have their normal gear. This is the place to give the special roles extra things
/datum/game_mode/proc/post_setup(report) //Gamemodes can override the intercept report. Passing TRUE as the argument will force a report.
if(!report)
report = config.intercept
addtimer(CALLBACK(GLOBAL_PROC, .proc/display_roundstart_logout_report), ROUNDSTART_LOGOUT_REPORT_TIME)
if(SSdbcore.Connect())
var/sql
if(SSticker && SSticker.mode)
sql += "game_mode = '[SSticker.mode]'"
if(GLOB.revdata.originmastercommit)
if(sql)
sql += ", "
sql += "commit_hash = '[GLOB.revdata.originmastercommit]'"
if(sql)
var/datum/DBQuery/query_round_game_mode = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET [sql] WHERE id = [GLOB.round_id]")
query_round_game_mode.Execute()
if(report)
addtimer(CALLBACK(src, .proc/send_intercept, 0), rand(waittime_l, waittime_h))
generate_station_goals()
return 1
///Handles late-join antag assignments
/datum/game_mode/proc/make_antag_chance(mob/living/carbon/human/character)
if(replacementmode && round_converted == 2)
replacementmode.make_antag_chance(character)
return
///Allows rounds to basically be "rerolled" should the initial premise fall through. Also known as mulligan antags.
/datum/game_mode/proc/convert_roundtype()
set waitfor = FALSE
var/list/living_crew = list()
for(var/mob/Player in GLOB.mob_list)
if(Player.mind && Player.stat != DEAD && !isnewplayer(Player) &&!isbrain(Player))
living_crew += Player
if(living_crew.len / GLOB.joined_player_list.len <= config.midround_antag_life_check) //If a lot of the player base died, we start fresh
message_admins("Convert_roundtype failed due to too many dead people. Limit is [config.midround_antag_life_check * 100]% living crew")
return null
var/list/datum/game_mode/runnable_modes = config.get_runnable_midround_modes(living_crew.len)
var/list/datum/game_mode/usable_modes = list()
for(var/datum/game_mode/G in runnable_modes)
if(G.reroll_friendly)
usable_modes += G
else
qdel(G)
if(!usable_modes)
message_admins("Convert_roundtype failed due to no valid modes to convert to. Please report this error to the Coders.")
return null
replacementmode = pickweight(usable_modes)
switch(SSshuttle.emergency.mode) //Rounds on the verge of ending don't get new antags, they just run out
if(SHUTTLE_STRANDED, SHUTTLE_ESCAPE)
return 1
if(SHUTTLE_CALL)
if(SSshuttle.emergency.timeLeft(1) < initial(SSshuttle.emergencyCallTime)*0.5)
return 1
if(world.time >= (config.midround_antag_time_check * 600))
message_admins("Convert_roundtype failed due to round length. Limit is [config.midround_antag_time_check] minutes.")
return null
var/list/antag_candidates = list()
for(var/mob/living/carbon/human/H in living_crew)
if(H.client && H.client.prefs.allow_midround_antag)
antag_candidates += H
if(!antag_candidates)
message_admins("Convert_roundtype failed due to no antag candidates.")
return null
antag_candidates = shuffle(antag_candidates)
if(config.protect_roles_from_antagonist)
replacementmode.restricted_jobs += replacementmode.protected_jobs
if(config.protect_assistant_from_antagonist)
replacementmode.restricted_jobs += "Assistant"
message_admins("The roundtype will be converted. If you have other plans for the station or feel the station is too messed up to inhabit stop the creation of antags or end the round now.")
. = 1
sleep(rand(600,1800))
//somewhere between 1 and 3 minutes from now
if(!config.midround_antag[SSticker.mode.config_tag])
round_converted = 0
return 1
for(var/mob/living/carbon/human/H in antag_candidates)
replacementmode.make_antag_chance(H)
round_converted = 2
message_admins("-- IMPORTANT: The roundtype has been converted to [replacementmode.name], antagonists may have been created! --")
///Called by the gameSSticker
/datum/game_mode/process()
return 0
/datum/game_mode/proc/check_finished() //to be called by SSticker
if(replacementmode && round_converted == 2)
return replacementmode.check_finished()
if(SSshuttle.emergency && (SSshuttle.emergency.mode == SHUTTLE_ENDGAME))
return TRUE
if(station_was_nuked)
return TRUE
if(!round_converted && (!config.continuous[config_tag] || (config.continuous[config_tag] && config.midround_antag[config_tag]))) //Non-continuous or continous with replacement antags
if(!continuous_sanity_checked) //make sure we have antags to be checking in the first place
for(var/mob/Player in GLOB.mob_list)
if(Player.mind)
if(Player.mind.special_role)
continuous_sanity_checked = 1
return 0
if(!continuous_sanity_checked)
message_admins("The roundtype ([config_tag]) has no antagonists, continuous round has been defaulted to on and midround_antag has been defaulted to off.")
config.continuous[config_tag] = 1
config.midround_antag[config_tag] = 0
SSshuttle.clearHostileEnvironment(src)
return 0
if(living_antag_player && living_antag_player.mind && isliving(living_antag_player) && living_antag_player.stat != DEAD && !isnewplayer(living_antag_player) &&!isbrain(living_antag_player))
return 0 //A resource saver: once we find someone who has to die for all antags to be dead, we can just keep checking them, cycling over everyone only when we lose our mark.
for(var/mob/Player in GLOB.living_mob_list)
if(Player.mind && Player.stat != DEAD && !isnewplayer(Player) &&!isbrain(Player))
if(Player.mind.special_role) //Someone's still antaging!
living_antag_player = Player
return 0
if(!config.continuous[config_tag])
return 1
else
round_converted = convert_roundtype()
if(!round_converted)
if(round_ends_with_antag_death)
return 1
else
config.midround_antag[config_tag] = 0
return 0
return 0
/datum/game_mode/proc/declare_completion()
var/clients = 0
var/surviving_humans = 0
var/surviving_total = 0
var/ghosts = 0
var/escaped_humans = 0
var/escaped_total = 0
for(var/mob/M in GLOB.player_list)
if(M.client)
clients++
if(ishuman(M))
if(!M.stat)
surviving_humans++
if(M.z == ZLEVEL_CENTCOM)
escaped_humans++
if(!M.stat)
surviving_total++
if(M.z == ZLEVEL_CENTCOM)
escaped_total++
if(isobserver(M))
ghosts++
if(clients > 0)
SSblackbox.set_val("round_end_clients",clients)
if(ghosts > 0)
SSblackbox.set_val("round_end_ghosts",ghosts)
if(surviving_humans > 0)
SSblackbox.set_val("survived_human",surviving_humans)
if(surviving_total > 0)
SSblackbox.set_val("survived_total",surviving_total)
if(escaped_humans > 0)
SSblackbox.set_val("escaped_human",escaped_humans)
if(escaped_total > 0)
SSblackbox.set_val("escaped_total",escaped_total)
send2irc("Server", "Round just ended.")
if(cult.len && !istype(SSticker.mode,/datum/game_mode/cult))
datum_cult_completion()
if(GLOB.borers.len)
var/borerwin = FALSE
var/borertext = "
The borers were:"
for(var/mob/living/simple_animal/borer/B in GLOB.borers)
if((B.key || B.controlling) && B.stat != DEAD)
borertext += "
[B.controlling ? B.victim.key : B.key] was [B.truename] ("
var/turf/location = get_turf(B)
if(location.z == ZLEVEL_CENTCOM && B.victim)
borertext += "escaped with host"
else
borertext += "failed"
borertext += ")"
to_chat(world, borertext)
var/total_borers = 0
for(var/mob/living/simple_animal/borer/B in GLOB.borers)
if((B.key || B.victim) && B.stat != DEAD)
total_borers++
if(total_borers)
var/total_borer_hosts = 0
for(var/mob/living/carbon/C in GLOB.mob_list)
var/mob/living/simple_animal/borer/D = C.has_brain_worms()
var/turf/location = get_turf(C)
if(location.z == ZLEVEL_CENTCOM && D && D.stat != DEAD)
total_borer_hosts++
if(GLOB.total_borer_hosts_needed <= total_borer_hosts)
borerwin = TRUE
to_chat(world, "There were [total_borers] borers alive at round end!")
to_chat(world, "A total of [total_borer_hosts] borers with hosts escaped on the shuttle alive. The borers needed [GLOB.total_borer_hosts_needed] hosts to escape.")
if(borerwin)
to_chat(world, "The borers were successful!")
else
to_chat(world, "The borers have failed!")
CHECK_TICK
return 0
/datum/game_mode/proc/check_win() //universal trigger to be called at mob death, nuke explosion, etc. To be called from everywhere.
return 0
/datum/game_mode/proc/send_intercept()
var/intercepttext = "Central Command Status Summary