diff --git a/modular_bandastation/automatic_crew_transfer/code/automatic_transfer_subsystem.dm b/modular_bandastation/automatic_crew_transfer/code/automatic_transfer_subsystem.dm index 5f5b2e51e6d60..a9fc32539bacd 100644 --- a/modular_bandastation/automatic_crew_transfer/code/automatic_transfer_subsystem.dm +++ b/modular_bandastation/automatic_crew_transfer/code/automatic_transfer_subsystem.dm @@ -1,38 +1,36 @@ SUBSYSTEM_DEF(automatic_transfer) name = "Automatic Transfer" - flags = SS_NO_FIRE - runlevels = RUNLEVEL_SETUP | RUNLEVEL_GAME - /// Id of planned crew transfer timer - var/crew_transfer_timer_id + flags = SS_BACKGROUND + runlevels = RUNLEVEL_GAME + /// Time when next crew transfer vote will run + COOLDOWN_DECLARE(automatic_crew_transfer_vote_cooldown) /datum/controller/subsystem/automatic_transfer/Initialize() - if(CONFIG_GET(flag/enable_automatic_crew_transfer)) - setup_automatic_crew_transfer() + if(!CONFIG_GET(flag/enable_automatic_crew_transfer)) + flags |= SS_NO_FIRE + return SS_INIT_NO_NEED + + if(SSticker.current_state < GAME_STATE_PLAYING) + RegisterSignal(SSticker, COMSIG_TICKER_ROUND_STARTING, PROC_REF(on_round_starting)) + else if(SSticker.current_state == GAME_STATE_PLAYING) + on_round_starting() return SS_INIT_SUCCESS -/datum/controller/subsystem/automatic_transfer/proc/plan_crew_transfer_vote_signal(datum/controller/subsystem/ticker, delay) - SIGNAL_HANDLER - plan_crew_transfer_vote(delay) +/datum/controller/subsystem/automatic_transfer/fire(resumed) + if(COOLDOWN_FINISHED(src, automatic_crew_transfer_vote_cooldown)) + start_crew_transfer_vote() -/datum/controller/subsystem/automatic_transfer/proc/plan_crew_transfer_vote(delay) - if(!CONFIG_GET(flag/enable_automatic_crew_transfer)) - return - if(!delay) - delay = CONFIG_GET(number/automatic_crew_transfer_vote_interval) - if(!crew_transfer_timer_id) - crew_transfer_timer_id = addtimer(CALLBACK(src, PROC_REF(start_crew_transfer_vote)), delay) +/datum/controller/subsystem/automatic_transfer/Recover() + automatic_crew_transfer_vote_cooldown = SSautomatic_transfer.automatic_crew_transfer_vote_cooldown -/datum/controller/subsystem/automatic_transfer/proc/setup_automatic_crew_transfer() - PRIVATE_PROC(TRUE) +/datum/controller/subsystem/automatic_transfer/proc/on_round_starting(datum/controller/subsystem/ticker) + SIGNAL_HANDLER - if(SSticker.current_state < GAME_STATE_PLAYING) - RegisterSignal(SSticker, COMSIG_TICKER_ROUND_STARTING, PROC_REF(plan_crew_transfer_vote_signal)) - else if(SSticker.current_state == GAME_STATE_PLAYING) - plan_crew_transfer_vote(max(0, CONFIG_GET(number/automatic_crew_transfer_vote_delay) - (world.time - SSticker.round_start_time))) + COOLDOWN_START(src, automatic_crew_transfer_vote_cooldown, CONFIG_GET(number/automatic_crew_transfer_vote_delay)) /datum/controller/subsystem/automatic_transfer/proc/start_crew_transfer_vote() PRIVATE_PROC(TRUE) SSvote.initiate_vote(/datum/vote/crew_transfer, "Automatic Crew Transfer", forced = TRUE) - crew_transfer_timer_id = null + COOLDOWN_START(src, automatic_crew_transfer_vote_cooldown, CONFIG_GET(number/automatic_crew_transfer_vote_interval)) diff --git a/modular_bandastation/automatic_crew_transfer/code/crew_tranfer_vote.dm b/modular_bandastation/automatic_crew_transfer/code/crew_tranfer_vote.dm index 148e503a089df..aab46b6123b8a 100644 --- a/modular_bandastation/automatic_crew_transfer/code/crew_tranfer_vote.dm +++ b/modular_bandastation/automatic_crew_transfer/code/crew_tranfer_vote.dm @@ -29,7 +29,6 @@ return "Game not started yet." /datum/vote/crew_transfer/finalize_vote(winning_option) - SSautomatic_transfer.plan_crew_transfer_vote() switch(winning_option) if(CHOICE_CONTINUE) return