Conditional department goals (#9457)

* just need to autodoc

* some autodocs

* autodocs SSYogs

* removes the cargo tesla goal
This commit is contained in:
Nichlas Pihl
2020-08-15 15:05:25 +01:00
committed by GitHub
parent 30fb85b92b
commit e7c79c5f7b
6 changed files with 130 additions and 26 deletions

View File

@@ -14,4 +14,3 @@
var/obj/machinery/ore_silo/O = GLOB.ore_silo_default
var/datum/component/material_container/materials = O.GetComponent(/datum/component/material_container)
return materials.can_use_amount(500*MINERAL_MATERIAL_AMOUNT, MAT_URANIUM)

View File

@@ -1,52 +1,104 @@
/**
* # Department goal
*
* Goals that a department can complete for monetary (or other) rewards.
*
* Can be either do-once-and-complete goals that you just need to do once, or continuous goals that check every specified interval, and reward the department if they're still true.
* You shouldn't make direct subtypes of [/datum/department_goal], instead make subtypes of each subtype, IE [/datum/department_goal/sec] or [/datum/department_goal/eng].
*
* Each subtype is already preset to payout and show to the correct accounts, if you want to add more, you need to update [/datum/controller/subsystem/Yogs/proc/getDepartmentFromAccount].
*/
/datum/department_goal
/// The name of the goal - Should be kept short
var/name = "Be nice."
/// The description of the goal - Describe how to accomplish it
var/desc = "Be nice to each other for once."
var/endround = FALSE // Whether it's only accomplished at the end of the round, or if it's something you complete midround
/// If true, this goal will only be checked at round-end, otherwise it'll get checked every time [SSYogs][/datum/controller/subsystem/Yogs] fires
var/endround = FALSE
/// Whether its already been completed. If true, [SSYogs][/datum/controller/subsystem/Yogs] won't check it again
var/completed = FALSE
// Whether it ends once completed, or is an on-going thing with on-going payouts.
/// Whether the goal can be completed multiple times with multiple payouts, or just once. Will be 0 if it's completed-once, otherwise it'll be the amount of time inbetween checks
var/continuous = 0 // If on-going, this will be the minimum time required between completions
/// If false, it'll stop checking once failed, otherwise it'll keep checking but only reward when it's completed
var/fail_if_failed = FALSE
/// The account that the goal is tied to. Should probably not be fiddled with as most things rely on it.
var/account // See code/__DEFINES/economy.dm
var/reward // should be a number, if it's defined then it will just be given as a cash reward on on_complete()
/// If defined, this will be paid in to the given account on completion. Otherwise, define your own reward in [/datum/department_goal/proc/complete]
var/reward // should be a number, if it's defined then it will just be given as a cash reward on complete()
/**
* Creates the new goal.
*
* Adds the goal to the list of goals in [SSYogs][/datum/controller/subsystem/Yogs], and if the game is currently running, messages players. See: [/datum/department_goal/proc/message_players]
*/
/datum/department_goal/New()
SSYogs.department_goals += src
if(SSticker.current_state == GAME_STATE_PLAYING)
message_players("new")
return ..()
/**
* Destroys the goal.
*
* Removes the goal from the list of goals in [SSYogs][/datum/controller/subsystem/Yogs], and if the game is currently running, messages players. See: [/datum/department_goal/proc/message_players]
*/
/datum/department_goal/Destroy()
SSYogs.department_goals -= src
if(SSticker.current_state == GAME_STATE_PLAYING)
message_players("ded")
return ..()
// Should contain the conditions for completing it, not just checking whether the objective has *already* been completed
/**
* Returns true if the goal is available to be run, returns false otherwise. Used for conditional goals. See [/datum/department_goal/eng/additional_singularity]
*/
/datum/department_goal/proc/is_available()
return TRUE
/**
* Whether the goal is completed. On subtypes, contains all the logic for determining whether it's complete.
*/
/datum/department_goal/proc/check_complete()
return FALSE
// Should contain the effects on completing it, like paying the given department
/datum/department_goal/proc/on_complete(endOfRound = FALSE)
/**
* Called to complete the goal. If a reward is set, it doles it out automatically. Otherwise, put your own reward in it.
*
* Arguments:
* * endOfRound - Whether or not this was called at the end of the round. If it was, it completes the objective regardless of continuous status
*/
/datum/department_goal/proc/complete(endOfRound = FALSE)
if(!continuous || endOfRound)
completed = TRUE
if(!endOfRound)
message_players("complet")
else
SSYogs.department_goals[src] = world.time + continuous
else if(continuous)
continuing()
if(reward && account)
var/datum/bank_account/D = SSeconomy.get_dep_account(account)
D.adjust_money(reward)
/**
* Called at the end of the round, returns a string saying either `completed` or `not completed`
*/
/datum/department_goal/proc/get_result()
if(!completed && check_complete())
on_complete(TRUE)
complete(TRUE)
return "<li>[name] : <span class='[completed ? "greentext'>C" : "redtext'>Not c"]ompleted</span></li>"
/**
* Returns a string containing the name and the description of the goal
*/
/datum/department_goal/proc/get_name()
return "<li>[name] : [desc]</li>"
/**
* Messages the players of the goal's department, dependent on input
*
* Arguments:
* * message - Can be either "ded", "new", or "complet". Will output either that the objective has been deleted, created, or completed.
*/
/datum/department_goal/proc/message_players(message)
var/string = "Your department's goals have been updated, please have another look at them."
switch(message)
@@ -76,3 +128,8 @@
linkedServer = S
linkedServer.receive_information(signal, null)
/**
* If the goal is continuous, this will set the timer to now + how-ever-long-the-timer-is
*/
/datum/department_goal/proc/continuing()
SSYogs.department_goals[src] = world.time + continuous

View File

@@ -15,3 +15,30 @@
continue
charge += s.charge
return charge >= 70e6
// Fire up a supermatter
/datum/department_goal/eng/additional_supermatter
name = "Fire up a supermatter"
desc = "Order and fire up a supermatter shard"
reward = "50000"
// Only available if the station doesn't have a suppermatter
/datum/department_goal/eng/additional_supermatter/is_available()
return !(GLOB.main_supermatter_engine)
// Set up a singularity
/datum/department_goal/eng/additional_singularity
name = "Spark a singularity"
desc = "Start a singularity engine using a singularity generator"
reward = "50000"
/datum/department_goal/eng/additional_singularity/is_available()
return GLOB.main_supermatter_engine
/datum/department_goal/eng/additional_singularity/check_complete()
for(var/obj/singularity/s in GLOB.singularities)
if(is_station_level(s.z) && !istype(s, /obj/singularity/energy_ball))
return TRUE
return FALSE

View File

@@ -5,14 +5,13 @@
// Keep the nuclear core of the self-destruct device safe
/datum/department_goal/sec/nukecore
name = "Protect the nuke"
desc = "Protect the nuclear core of the station's self-destruct device, by keeping it there"
desc = "Protect the nuclear core of the station's self-destruct device, by keeping it in the device"
continuous = 1200 // Check every 2 minutes
reward = 2000 // Corresponds to 50k in 50mins
fail_if_failed = TRUE // Set this to false if we ever bother making it so you can stuff the core back into the self-destruct device
/datum/department_goal/sec/nukecore/check_complete()
for(var/obj/machinery/nuclearbomb/selfdestruct/s in GLOB.nuke_list)
if(s.core && is_station_level(s.z))
return TRUE
// Fail it if it's not there
completed = TRUE
return FALSE

View File

@@ -646,6 +646,10 @@ GLOBAL_DATUM(main_supermatter_engine, /obj/machinery/power/supermatter_crystal)
investigate_log("has been powered for the first time.", INVESTIGATE_SUPERMATTER)
message_admins("[src] has been powered for the first time [ADMIN_JMP(src)].")
has_been_powered = TRUE
var/datum/department_goal/eng/additional_supermatter/goal = locate() in SSYogs.department_goals
if(goal)
goal.complete()
else if(takes_damage)
damage += Proj.damage * config_bullet_energy
return BULLET_ACT_HIT

View File

@@ -63,22 +63,22 @@ SUBSYSTEM_DEF(Yogs)
// Picking department goals
// Engineering first
asvToldMeToRenameThisProcSoHereWeAre(/datum/department_goal/eng)
generateGoalsFromSubtypes(/datum/department_goal/eng)
// Then security
asvToldMeToRenameThisProcSoHereWeAre(/datum/department_goal/sec)
generateGoalsFromSubtypes(/datum/department_goal/sec)
// Then medical
asvToldMeToRenameThisProcSoHereWeAre(/datum/department_goal/med)
generateGoalsFromSubtypes(/datum/department_goal/med)
// Then cargo
asvToldMeToRenameThisProcSoHereWeAre(/datum/department_goal/car)
generateGoalsFromSubtypes(/datum/department_goal/car)
// Then service
asvToldMeToRenameThisProcSoHereWeAre(/datum/department_goal/srv)
generateGoalsFromSubtypes(/datum/department_goal/srv)
// Then science
asvToldMeToRenameThisProcSoHereWeAre(/datum/department_goal/sci)
generateGoalsFromSubtypes(/datum/department_goal/sci)
// Then spawn the papers with the goals on em on the heads' (and QM's) computers
for(var/obj/machinery/computer/C in GLOB.machines)
@@ -157,15 +157,33 @@ SUBSYSTEM_DEF(Yogs)
if(dg.completed || dg.endround || (department_goals[dg] && world.time < department_goals[dg]))
continue
if(dg.check_complete())
dg.on_complete()
dg.complete()
else if(dg.continuous && !dg.fail_if_failed)
dg.continuing()
/datum/controller/subsystem/Yogs/proc/asvToldMeToRenameThisProcSoHereWeAre(datum/d)
/**
* Generates up to 5 department goals of the given type.
*
* Arguments:
* * d - the given datum that we're getting the subtypes of.
*/
/datum/controller/subsystem/Yogs/proc/generateGoalsFromSubtypes(datum/d)
var/list/goals = subtypesof(d)
var/five = goals.len >= 5 ? 5 : goals.len
for(var/i in 1 to five)
var/datum/f = pick_n_take(goals)
new f
var/goalsSoFar = 0
while(goals.len && goalsSoFar < 5)
var/datum/typepath = pick_n_take(goals)
var/datum/department_goal/goal = new typepath
if(goal.is_available())
goalsSoFar++
else
qdel(goal)
/**
* Gets the correct string from the given department account. See code/__DEFINES/economy.dm
*
* Arguments:
* * account - The account that you're getting the string from. IE ACCOUNT_CIV or ACCOUNT_ENG
*/
/datum/controller/subsystem/Yogs/proc/getDepartmentFromAccount(var/account)
switch(account)
if(ACCOUNT_CIV)