De-hardcodes the decomposition examine proc, and makes the decompose time editable (#65284)

Makes the decomposition examine proc, which handles the little examine warning telling you how close to decomposing a piece of food is, not hardcoded anymore. Doing this allowed me to also...

Adds a variable to food that lets them edit the decomposition timer. By default it's set to 0, which makes food automatically get its timer based off its flags. By setting the decomposition_time variable in a /obj/item/food to anything other than 0 (using SECONDS or MINUTES), it will take that amount of time to decompose instead.
This commit is contained in:
Wallem
2022-03-08 16:11:43 -08:00
committed by GitHub
parent 0c54b34a64
commit e0e677f145
2 changed files with 20 additions and 42 deletions
+17 -41
View File
@@ -4,10 +4,6 @@
#define DECOMPOSITION_TIME_RAW 5 MINUTES
#define DECOMPOSITION_TIME_GROSS 7 MINUTES
#define DECOMP_EXAM_NORMAL 0
#define DECOMP_EXAM_GROSS 1
#define DECOMP_EXAM_RAW 2
/datum/component/decomposition
dupe_mode = COMPONENT_DUPE_UNIQUE
/// Makes sure maploaded food only starts decomposing if a player's EVER picked it up before
@@ -16,6 +12,8 @@
var/protected = FALSE
/// Used to stop the timer & check for the examine proc
var/timerid
/// The total time that this takes to decompose
var/original_time = DECOMPOSITION_TIME
/// Used so the timer won't reset.
var/time_remaining = DECOMPOSITION_TIME
/// Used to give raw/gross food lower timers
@@ -24,10 +22,8 @@
var/decomp_result
/// Does our food attract ants?
var/produce_ants = TRUE
/// Used for examining
var/examine_type = DECOMP_EXAM_NORMAL
/datum/component/decomposition/Initialize(mapload, decomp_req_handle, decomp_flags = NONE, decomp_result, ant_attracting = TRUE)
/datum/component/decomposition/Initialize(mapload, decomp_req_handle, decomp_flags = NONE, decomp_result, ant_attracting = TRUE, custom_time = 0)
if(!isobj(parent))
return COMPONENT_INCOMPATIBLE
@@ -49,12 +45,14 @@
.proc/dropped)
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/examine)
if(decomp_flags & RAW) // Raw food overrides gross
time_remaining = DECOMPOSITION_TIME_RAW
examine_type = DECOMP_EXAM_RAW
if(custom_time) // We have a custom decomposition time, set it to that
original_time = custom_time
else if(decomp_flags & RAW) // Raw food overrides gross
original_time = DECOMPOSITION_TIME_RAW
else if(decomp_flags & GROSS)
time_remaining = DECOMPOSITION_TIME_GROSS
examine_type = DECOMP_EXAM_GROSS
original_time = DECOMPOSITION_TIME_GROSS
time_remaining = original_time
handle_movement()
@@ -125,36 +123,14 @@
time_d = timeleft(timerid)
else
time_d = time_remaining
switch(examine_type)
if(DECOMP_EXAM_NORMAL)// All other types
switch(time_d) // Deciseconds used so there's no gaps between examine times.
if(3001 to 4500) // 7.5 to 5 Minutes left
examine_list += "[parent] looks kinda stale."
if(1501 to 3000) // 5 to 2.5 Minutes left
examine_list += "[parent] is starting to look pretty gross."
if(1 to 1500) // 2.5 Minutes to 1 Decisecond left
examine_list += "[parent] looks barely edible."
if(DECOMP_EXAM_GROSS) // Gross food
switch(time_d)
if(2101 to 3150) // 5.25 to 3.5 Minutes
examine_list += "[parent] looks kinda stale."
if(1050 to 2100) // 3.5 to 1.75 Minutes left
examine_list += "[parent] is starting to look pretty gross."
if(1 to 1051) // 1.75 Minutes to 1 Decisecond left
examine_list += "[parent] looks barely edible."
if(DECOMP_EXAM_RAW) // Raw food
switch(time_d)
if(1501 to 2250) // 3.75 to 2.5 Minutes left
examine_list += "[parent] looks kinda stale."
if(751 to 1500) // 2.5 to 1.25 Minutes left
examine_list += "[parent] is starting to look pretty gross."
if(1 to 750) // 1.25 Minutes to 1 Decisecond left
examine_list += "[parent] looks barely edible."
switch(time_d / original_time)
if(0.5 to 0.75) // 25% rotten
examine_list += span_notice("[parent] looks kinda stale.")
if(0.25 to 0.5) // 50% rotten
examine_list += span_notice("[parent] is starting to look pretty gross.")
if(0 to 0.25) // 75% rotten
examine_list += span_danger("[parent] barely looks edible.")
#undef DECOMPOSITION_TIME
#undef DECOMPOSITION_TIME_GROSS
#undef DECOMPOSITION_TIME_RAW
#undef DECOMP_EXAM_NORMAL
#undef DECOMP_EXAM_GROSS
#undef DECOMP_EXAM_RAW