forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify
automatic_transfer_subsystem
by removing timer usage (#857)
## About The Pull Request simplify `automatic_transfer_subsystem` by removing timer usage ## Why It's Good For The Game Автоматический крю трансфер будет работать более стабильно, и код проще, как для такой простой системы. ## Changelog :cl: code: Упрощен код `automatic_transfer_subsystem` /:cl:
- Loading branch information
Showing
2 changed files
with
21 additions
and
24 deletions.
There are no files selected for viewing
44 changes: 21 additions & 23 deletions
44
modular_bandastation/automatic_crew_transfer/code/automatic_transfer_subsystem.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters