forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements Autotransfer, originally from Citadel
Current code ported from Nova to properly support a couple changes TG has made to GLOBs (pain)
- Loading branch information
CliffracerX
committed
Sep 28, 2024
1 parent
b1f4090
commit 6aaaef4
Showing
7 changed files
with
167 additions
and
8 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#define NO_MAXVOTES_CAP -1 | ||
|
||
SUBSYSTEM_DEF(autotransfer) | ||
name = "Autotransfer Vote" | ||
flags = SS_KEEP_TIMING | SS_BACKGROUND | ||
wait = 1 MINUTES | ||
|
||
var/starttime | ||
var/targettime | ||
var/voteinterval | ||
var/maxvotes | ||
var/curvotes = 0 | ||
|
||
/datum/controller/subsystem/autotransfer/Initialize() | ||
if(!CONFIG_GET(flag/autotransfer)) //Autotransfer voting disabled. | ||
can_fire = FALSE | ||
return SS_INIT_NO_NEED | ||
|
||
var/init_vote = CONFIG_GET(number/vote_autotransfer_initial) | ||
starttime = REALTIMEOFDAY | ||
targettime = starttime + init_vote | ||
voteinterval = CONFIG_GET(number/vote_autotransfer_interval) | ||
maxvotes = CONFIG_GET(number/vote_autotransfer_maximum) | ||
return SS_INIT_SUCCESS | ||
|
||
/datum/controller/subsystem/autotransfer/Recover() | ||
starttime = SSautotransfer.starttime | ||
voteinterval = SSautotransfer.voteinterval | ||
curvotes = SSautotransfer.curvotes | ||
|
||
/datum/controller/subsystem/autotransfer/fire() | ||
if(REALTIMEOFDAY < targettime) | ||
return | ||
if(maxvotes == NO_MAXVOTES_CAP || maxvotes > curvotes) | ||
SSvote.initiate_vote(/datum/vote/transfer_vote, "automatic transfer", forced = TRUE) | ||
targettime = targettime + voteinterval | ||
curvotes++ | ||
else | ||
SSshuttle.autoEnd() | ||
|
||
/** | ||
* At shift start, pulls the autotransfer interval from config and applies | ||
* | ||
* Arguments: | ||
* * real_round_shift_time - World time the round left the pregame lobby | ||
*/ | ||
/datum/controller/subsystem/autotransfer/proc/new_shift(real_round_start_time) | ||
var/init_vote = CONFIG_GET(number/vote_autotransfer_initial) // Check if an admin has manually set an override in the pre-game lobby | ||
starttime = real_round_start_time | ||
targettime = starttime + init_vote | ||
log_game("Autotransfer enabled, first vote in [DisplayTimeText(targettime - starttime)]") | ||
message_admins("Autotransfer enabled, first vote in [DisplayTimeText(targettime - starttime)]") | ||
|
||
#undef NO_MAXVOTES_CAP |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// Length of time before the first autotransfer vote is called (deciseconds, default 2 hours) | ||
/// Set to 0 to disable the subsystem altogether. | ||
/datum/config_entry/number/vote_autotransfer_initial | ||
config_entry_value = 72000 | ||
min_val = 0 | ||
|
||
///length of time to wait before subsequent autotransfer votes (deciseconds, default 30 minutes) | ||
/datum/config_entry/number/vote_autotransfer_interval | ||
config_entry_value = 18000 | ||
min_val = 0 | ||
|
||
/// maximum extensions until the round autoends. | ||
/// Set to 0 to force automatic crew transfer after the 'vote_autotransfer_initial' elapsed. | ||
/// Set to -1 to disable the maximum extensions cap. | ||
/datum/config_entry/number/vote_autotransfer_maximum | ||
config_entry_value = 4 | ||
min_val = -1 | ||
|
||
/// Determines if the autotransfer system runs or not. | ||
/datum/config_entry/flag/autotransfer | ||
|
||
|
||
/// Determines if the transfer vote can be started by anyone or not. | ||
/datum/config_entry/flag/allow_vote_transfer |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/// ADDITIONAL PROC EDITS AS FOLLOWS: | ||
// - code/modules/shuttle/emergency.dm - /obj/docking_port/mobile/emergency/request | ||
|
||
/datum/controller/subsystem/shuttle | ||
var/endvote_passed = FALSE | ||
|
||
/datum/controller/subsystem/shuttle/proc/autoEnd() | ||
if(EMERGENCY_IDLE_OR_RECALLED) | ||
SSshuttle.emergency.request(silent = TRUE) | ||
priority_announce("The shift has come to an end and the shuttle called. [SSsecurity_level.get_current_level_as_number() == SEC_LEVEL_RED ? "Red Alert state confirmed: Dispatching priority shuttle. " : "" ]It will arrive in [emergency.timeLeft(600)] minutes.", null, ANNOUNCER_SHUTTLECALLED, "Priority", color_override = "orange") | ||
log_game("Round end vote passed. Shuttle has been auto-called.") | ||
message_admins("Round end vote passed. Shuttle has been auto-called.") | ||
emergency_no_recall = TRUE | ||
endvote_passed = TRUE | ||
SSevents.can_fire = FALSE // we're going home |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#define CHOICE_TRANSFER "Initiate Crew Transfer" | ||
#define CHOICE_CONTINUE "Continue Playing" | ||
|
||
/datum/vote/transfer_vote | ||
name = "Transfer" | ||
default_choices = list( | ||
CHOICE_TRANSFER, | ||
CHOICE_CONTINUE, | ||
) | ||
default_message = "Vote to initiate a transfer, forcing a shuttle call \ | ||
that cannot be recalled. Don't touch it unless it's not working \ | ||
automatically." | ||
|
||
/datum/vote/transfer_vote/toggle_votable() | ||
CONFIG_SET(flag/allow_vote_transfer, !CONFIG_GET(flag/allow_vote_transfer)) | ||
|
||
/datum/vote/transfer_vote/is_config_enabled() | ||
return CONFIG_GET(flag/autotransfer) && CONFIG_GET(flag/allow_vote_transfer) | ||
|
||
/datum/vote/transfer_vote/can_be_initiated(forced) | ||
. = ..() | ||
if(. != VOTE_AVAILABLE) | ||
return . | ||
|
||
if(forced) | ||
return VOTE_AVAILABLE | ||
|
||
if(!CONFIG_GET(flag/autotransfer) || !CONFIG_GET(flag/allow_vote_transfer)) | ||
return "Transfer voting is disabled." | ||
|
||
return VOTE_AVAILABLE | ||
|
||
/datum/vote/transfer_vote/finalize_vote(winning_option) | ||
if(winning_option == CHOICE_CONTINUE) | ||
return | ||
|
||
if(winning_option == CHOICE_TRANSFER) | ||
SSshuttle.autoEnd() | ||
var/obj/machinery/computer/communications/comms_console = locate() in GLOB.shuttle_caller_list | ||
if(comms_console) | ||
comms_console.post_status("shuttle") | ||
return | ||
|
||
CRASH("[type] wasn't passed a valid winning choice. (Got: [winning_option || "null"])") | ||
|
||
#undef CHOICE_TRANSFER | ||
#undef CHOICE_CONTINUE |
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