Files
Aurora.3/code/datums/statistic.dm
Lohikar 0ad3d4c189 Round-end statistics (#2483)
This PR adds a system to display round statistics at the end of the round, with the option of logging said statistics to the feedback database.

Tracked stats:

Most deaths by ckey.
Number of people cloned.
Number of times humans have fallen into openturfs.
Number of times humans have died from falling into openturfs.
Number of times humans have been gibbed.
2017-05-29 22:42:19 +03:00

113 lines
2.5 KiB
Plaintext

/datum/statistic
var/name
var/key
var/write_to_database = FALSE
var/broadcast_at_roundend = TRUE
/datum/statistic/proc/set_value()
WARNING("Statistic [type] does not have set_value implemented.")
/datum/statistic/proc/get_value()
WARNING("Statistic [type] does not have get_value implemented.")
/datum/statistic/proc/increment_value()
WARNING("Statistic [type] does not have increment_value implemented.")
/datum/statistic/proc/write_to_database()
/datum/statistic/proc/get_roundend_lines() // Must be a string or something stringifiable.
/datum/statistic/proc/has_value()
// key-num pairs.
/datum/statistic/grouped
var/list/values = list()
/datum/statistic/grouped/set_value(key, value)
LAZYINITLIST(values[key])
values[key] = value
/datum/statistic/grouped/get_value(key)
return LAZYACCESS(values, key)
/datum/statistic/grouped/increment_value(key)
set_value(key, get_value(key) + 1)
// Just a num.
/datum/statistic/numeric
var/value = 0
/datum/statistic/numeric/set_value(val)
value = val
/datum/statistic/numeric/get_value()
return value
/datum/statistic/numeric/increment_value()
value++
/datum/statistic/numeric/write_to_database()
feedback_set(key, value)
/datum/statistic/numeric/get_roundend_lines()
. = "[value]"
/datum/statistic/numeric/has_value()
return value > 1
/datum/statistic/numeric/openturf_falls
name = "Human Open Space Falls"
key = "openturf_human_falls"
write_to_database = TRUE
/datum/statistic/numeric/openturf_deaths
name = "Human Open Space Fatalities"
key = "openturf_human_deaths"
write_to_database = TRUE
/datum/statistic/numeric/gibbings
name = "Gibbings"
key = "gibs"
/datum/statistic/numeric/clonings
name = "Clones Produced"
key = "clones"
/datum/statistic/grouped/most_deaths
name = "Most Overall Deaths (by ckey)"
key = "ckey_deaths"
/datum/statistic/grouped/most_deaths/has_value()
if (!values.len)
return FALSE
var/sum
for (var/value in values)
sum += values[value]
if (sum != values.len)
return TRUE
return FALSE
/datum/statistic/grouped/most_deaths/get_roundend_lines()
sortTim(values, /proc/cmp_numeric_dsc, TRUE)
var/ckey = values[1]
. = "[ckey], with [values[ckey]] deaths."
/hook/death/proc/increment_statistics(mob/living/carbon/human/H, gibbed)
. = TRUE
if (!H.ckey)
return
SSfeedback.IncrementGroupedStat("ckey_deaths", H.ckey)
if (gibbed)
SSfeedback.IncrementSimpleStat("gibs")
/hook/clone/proc/increment_statistics(mob/living/carbon/human/H)
. = TRUE
if (!H.ckey)
return
SSfeedback.IncrementSimpleStat("clones")