Skip to content

Commit

Permalink
simplify automatic_transfer_subsystem by removing timer usage (#857)
Browse files Browse the repository at this point in the history
## 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
Gaxeer authored Dec 7, 2024
1 parent aa8e107 commit 73c6aed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
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))
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 73c6aed

Please sign in to comment.