no more ids

This commit is contained in:
kevinz000
2020-02-18 00:04:16 -07:00
parent 256d20cde0
commit 1c0b764dcf
9 changed files with 60 additions and 183 deletions
+60 -67
View File
@@ -1,12 +1,35 @@
/**
* Movespeed modification datums.
*/
/*! Movespeed modification datums.
How move speed for mobs works
Move speed is now calculated by using modifier datums which are added to mobs. Some of them (nonvariable ones) are globally cached, the variable ones are instanced and changed based on need.
This gives us the ability to have multiple sources of movespeed, reliabily keep them applied and remove them when they should be
THey can have unique sources and a bunch of extra fancy flags that control behaviour
Previously trying to update move speed was a shot in the dark that usually meant mobs got stuck going faster or slower
Movespeed modification list is a simple key = datum system. Key will be the datum's ID if it is overridden to not be null, or type if it is not.
DO NOT override datum IDs unless you are going to have multiple types that must overwrite each other. It's more efficient to use types, ID functionality is only kept for cases where dynamic creation of modifiers need to be done.
When update movespeed is called, the list of items is iterated, according to flags priority and a bunch of conditions
this spits out a final calculated value which is used as a modifer to last_move + modifier for calculating when a mob
can next move
Key procs
* [add_movespeed_modifier](mob.html#proc/add_movespeed_modifier)
* [remove_movespeed_modifier](mob.html#proc/remove_movespeed_modifier)
* [has_movespeed_modifier](mob.html#proc/has_movespeed_modifier)
* [update_movespeed](mob.html#proc/update_movespeed)
*/
/datum/movespeed_modifier
/// Whether or not this is a variable modifier. Variable modifiers can NOT be ever auto-cached. ONLY CHECKED VIA INITIAL(), EFFECTIVELY READ ONLY (and for very good reason)
var/variable = FALSE
/// Unique ID. You can never have different modifications with the same ID
/// Unique ID. You can never have different modifications with the same ID. By default, this SHOULD NOT be set. Only set it for cases where you're dynamically making modifiers/need to have two types overwrite each other. If unset, uses path as ID.
var/id
/// Higher ones override lower priorities. This is NOT used for ID, ID must be unique, if it isn't unique the newer one overwrites automatically if overriding.
@@ -25,42 +48,6 @@
/// Other modification datums this conflicts with.
var/conflicts_with
/*! How move speed for mobs works
Move speed is now calculated by using modifier datums which are added to mobs. Some of them (nonvariable ones) are globally cached, the variable ones are instanced and changed based on need.
This gives us the ability to have multiple sources of movespeed, reliabily keep them applied and remove them when they should be
THey can have unique sources and a bunch of extra fancy flags that control behaviour
Previously trying to update move speed was a shot in the dark that usually meant mobs got stuck going faster or slower
This list takes the following format
```Current movespeed modification list format:
list(
id = list(
priority,
flags,
legacy slowdown/speedup amount,
movetype_flags
)
)
```
WHen update movespeed is called, the list of items is iterated, according to flags priority and a bunch of conditions
this spits out a final calculated value which is used as a modifer to last_move + modifier for calculating when a mob
can next move
Key procs
* [add_movespeed_modifier](mob.html#proc/add_movespeed_modifier)
* [remove_movespeed_modifier](mob.html#proc/remove_movespeed_modifier)
* [has_movespeed_modifier](mob.html#proc/has_movespeed_modifier)
* [update_movespeed](mob.html#proc/update_movespeed)
*/
//ANY ADD/REMOVE DONE IN UPDATE_MOVESPEED MUST HAVE THE UPDATE ARGUMENT SET AS FALSE!
GLOBAL_LIST_EMPTY(movespeed_modification_cache)
/// Grabs a STATIC MODIFIER datum from cache. YOU MUST NEVER EDIT THESE DATUMS, OR IT WILL AFFECT ANYTHING ELSE USING IT TOO!
@@ -82,53 +69,56 @@ GLOBAL_LIST_EMPTY(movespeed_modification_cache)
type_or_datum = get_cached_movespeed_modifier(type_or_datum)
else
type_or_datum = new type_or_datum
var/datum/movespeed_modifier/existing = LAZYACCESS(movespeed_modification, type_or_datum.id)
var/key = type_or_datum.id || type_or_datum.type //Our key will be ID if it's overridden, or if not, path.
var/datum/movespeed_modifier/existing = LAZYACCESS(movespeed_modification, key)
if(existing)
if(existing == type_or_datum) //same thing don't need to touch
return TRUE
remove_movespeed_modifier(existing, FALSE)
if(length(movespeed_modification))
BINARY_INSERT(type_or_datum.id, movespeed_modification, datum/movespeed_modifier, type_or_datum, priority, COMPARE_VALUE)
LAZYSET(movespeed_modification, type_or_datum.id, type_or_datum)
BINARY_INSERT(key, movespeed_modification, datum/movespeed_modifier, type_or_datum, priority, COMPARE_VALUE)
LAZYSET(movespeed_modification, key, type_or_datum)
if(update)
update_movespeed()
return TRUE
/// Remove a move speed modifier from a mob, whether static or variable.
/mob/proc/remove_movespeed_modifier(datum/movespeed_modifier/type_id_datum, update = TRUE)
var/key
if(ispath(type_id_datum))
type_id_datum = initial(type_id_datum.id)
key = initial(type_id_datum.id) || type_id_datum //id if set, path if not.
else if(!istext(type_id_datum)) //if it isn't text it has to be a datum, as it isn't a type.
type_id_datum = type_id_datum.id
if(!LAZYACCESS(movespeed_modification, type_id_datum))
key = type_id_datum.id || type_id_datum.type
else //assume it's an id
key = type_id_datum
if(!LAZYACCESS(movespeed_modification, key))
return FALSE
LAZYREMOVE(movespeed_modification, type_id_datum)
LAZYREMOVE(movespeed_modification, key)
if(update)
update_movespeed(FALSE)
return TRUE
/// Used for variable slowdowns like hunger/health loss/etc, works somewhat like the old list-based modification adds. Returns the modifier datum if successful
/mob/proc/add_or_update_variable_movespeed_modifier(datum/movespeed_modifier/type_id_datum, update = TRUE, multiplicative_slowdown)
/*
/*! Used for variable slowdowns like hunger/health loss/etc, works somewhat like the old list-based modification adds. Returns the modifier datum if successful
How this SHOULD work is:
1. Ensures type_id_datum one way or another refers to a /variable datum. This makes sure it can't be cached. This includes if it's already in the modification list.
2. Instantiate a new datum if type_id_datum isn't already instantiated + in the list, using the type. Obviously, wouldn't work for ID only.
3. Add the datum if necessary using the regular add proc
4. If any of the rest of the args are not null (see: multiplicative slowdown), modify the datum
5. Update if necessary
*/
*/
/mob/proc/add_or_update_variable_movespeed_modifier(datum/movespeed_modifier/type_id_datum, update = TRUE, multiplicative_slowdown)
var/modified = FALSE
var/inject = FALSE
var/datum/movespeed_modifier/final
if(istext(type_id_datum))
final = LAZYACCESS(movespeed_modification, type_id_datum)
if(!final)
CRASH("Couldn't find existing modification when only provided an ID.")
CRASH("Couldn't find existing modification when provided a text ID.")
else if(ispath(type_id_datum))
if(!initial(type_id_datum.variable))
CRASH("Not a variable modifier")
var/id = initial(type_id_datum.id)
final = LAZYACCESS(movespeed_modification, id)
final = LAZYACCESS(movespeed_modification, id || type_or_datum)
if(!final)
final = new type_id_datum
inject = TRUE
@@ -137,7 +127,7 @@ GLOBAL_LIST_EMPTY(movespeed_modification_cache)
if(!initial(type_id_datum.variable))
CRASH("Not a variable modifier")
final = type_id_datum
if(!LAZYACCESS(movespeed_modification, final.id))
if(!LAZYACCESS(movespeed_modification, final.id || final.type))
inject = TRUE
modified = TRUE
if(!isnull(multiplicative_slowdown))
@@ -149,7 +139,7 @@ GLOBAL_LIST_EMPTY(movespeed_modification_cache)
update_movespeed(TRUE)
return final
///Handles the special case of editing the movement var
/// Handles the special case of editing the movement var
/mob/vv_edit_var(var_name, var_value)
var/slowdown_edit = (var_name == NAMEOF(src, cached_multiplicative_slowdown))
var/diff
@@ -162,29 +152,32 @@ GLOBAL_LIST_EMPTY(movespeed_modification_cache)
///Is there a movespeed modifier for this mob
/mob/proc/has_movespeed_modifier(datum/movespeed_modifier/datum_type_id)
var/key
if(ispath(datum_type_id))
datum_type_id = get_cached_movespeed_modifier(datum_type_id)
else if(!istext(datum_type_id))
datum_type_id = datum_type_id.id
return LAZYACCESS(movespeed_modification, datum_type_id)
key = initial(datum_type_id.id) || datum_type_id
else if(istext(datum_type_id))
key = datum_type_id
else
key = datum_type_id.id || datum_type_id.type
return LAZYACCESS(movespeed_modification, key)
///Set or update the global movespeed config on a mob
/// Set or update the global movespeed config on a mob
/mob/proc/update_config_movespeed()
add_or_update_variable_movespeed_modifier(/datum/movespeed_modifier/mob_config_speedmod, multiplicative_slowdown = get_config_multiplicative_speed())
///Get the global config movespeed of a mob by type
/// Get the global config movespeed of a mob by type
/mob/proc/get_config_multiplicative_speed()
if(!islist(GLOB.mob_config_movespeed_type_lookup) || !GLOB.mob_config_movespeed_type_lookup[type])
return 0
else
return GLOB.mob_config_movespeed_type_lookup[type]
///Go through the list of movespeed modifiers and calculate a final movespeed
/// Go through the list of movespeed modifiers and calculate a final movespeed. ANY ADD/REMOVE DONE IN UPDATE_MOVESPEED MUST HAVE THE UPDATE ARGUMENT SET AS FALSE!
/mob/proc/update_movespeed()
. = 0
var/list/conflict_tracker = list()
for(var/id in get_movespeed_modifiers())
var/datum/movespeed_modifier/M = movespeed_modification[id]
for(var/key in get_movespeed_modifiers())
var/datum/movespeed_modifier/M = movespeed_modification[key]
if(!(M.movetypes & movement_type)) // We don't affect any of these move types, skip
continue
if(M.blacklisted_movetypes & movement_type) // There's a movetype here that disables this modifier, skip
@@ -201,18 +194,18 @@ GLOBAL_LIST_EMPTY(movespeed_modification_cache)
. += amt
cached_multiplicative_slowdown = .
///Get the move speed modifiers list of the mob
/// Get the move speed modifiers list of the mob
/mob/proc/get_movespeed_modifiers()
return movespeed_modification
///Calculate the total slowdown of all movespeed modifiers
/// Calculate the total slowdown of all movespeed modifiers
/mob/proc/total_multiplicative_slowdown()
. = 0
for(var/id in get_movespeed_modifiers())
var/datum/movespeed_modifier/M = movespeed_modification[id]
. += M.multiplicative_slowdown
///Checks if a move speed modifier is valid and not missing any data
/// Checks if a move speed modifier is valid and not missing any data
/proc/movespeed_data_null_check(datum/movespeed_modifier/M) //Determines if a data list is not meaningful and should be discarded.
. = TRUE
if(M.multiplicative_slowdown)
@@ -1,15 +1,12 @@
/datum/movespeed_modifier/shrink_ray
id = MOVESPEED_ID_SHRINK_RAY
movetypes = GROUND
multiplicative_slowdown = 4
/datum/movespeed_modifier/snail_crawl
id = MOVESPEED_ID_SNAIL_CRAWL
multiplicative_slowdown = -7
movetypes = GROUND
/datum/movespeed_modifier/sanity
id = MOVESPEED_ID_SANITY
movetypes = (~FLYING)
/datum/movespeed_modifier/sanity/insane
@@ -1,18 +1,14 @@
/datum/movespeed_modifier/strained_muscles
id = MOVESPEED_ID_CHANGELING_MUSCLES
multiplicative_slowdown = -1
blacklisted_movetypes = (FLYING|FLOATING)
/datum/movespeed_modifier/pai_spacewalk
id = MOVESPEED_ID_PAI_SPACEWALK_SPEEDMOD
multiplicative_slowdown = 2
/datum/movespeed_modifier/species
id = MOVESPEED_ID_SPECIES
movetypes = ~FLYING
variable = TRUE
/datum/movespeed_modifier/dna_vault_speedup
id = MOVESPEED_ID_DNA_VAULT
blacklisted_movetypes = (FLYING|FLOATING)
multiplicative_slowdown = -0.4
@@ -3,13 +3,10 @@
movetypes = FLOATING
/datum/movespeed_modifier/jetpack/cybernetic
id = MOVESPEED_ID_CYBER_THRUSTER
multiplicative_slowdown = -0.5
/datum/movespeed_modifier/jetpack/fullspeed
id = MOVESPEED_ID_JETPACK
multiplicative_slowdown = -0.5
/datum/movespeed_modifier/die_of_fate
id = MOVESPEED_ID_DIE_OF_FATE
multiplicative_slowdown = 1
-2
View File
@@ -1,8 +1,6 @@
/datum/movespeed_modifier/admin_varedit
variable = TRUE
id = MOVESPEED_ID_ADMIN_VAREDIT
/datum/movespeed_modifier/yellow_orb
id = MOVESPEED_ID_YELLOW_ORB
multiplicative_slowdown = -2
blacklisted_movetypes = (FLYING|FLOATING)
-26
View File
@@ -1,44 +1,34 @@
/datum/movespeed_modifier/obesity
id = MOVESPEED_ID_FAT
multiplicative_slowdown = 1.5
/datum/movespeed_modifier/monkey_reagent_speedmod
variable = TRUE
id = MOVESPEED_ID_MONKEY_REAGENT_SPEEDMOD
/datum/movespeed_modifier/monkey_health_speedmod
variable = TRUE
id = MOVESPEED_ID_MONKEY_HEALTH_SPEEDMOD
/datum/movespeed_modifier/monkey_temperature_speedmod
variable = TRUE
id = MOVESPEED_ID_MONKEY_TEMPERATURE_SPEEDMOD
/datum/movespeed_modifier/hunger
id = MOVESPEED_ID_HUNGRY
variable = TRUE
/datum/movespeed_modifier/slaughter
id = MOVESPEED_ID_SLAUGHTER
multiplicative_slowdown = -1
/datum/movespeed_modifier/damage_slowdown
id = MOVESPEED_ID_DAMAGE_SLOWDOWN
blacklisted_movetypes = FLOATING|FLYING
variable = TRUE
/datum/movespeed_modifier/damage_slowdown_flying
id = MOVESPEED_ID_DAMAGE_SLOWDOWN_FLYING
movetypes = FLOATING
variable = TRUE
/datum/movespeed_modifier/equipment_speedmod
variable = TRUE
id = MOVESPEED_ID_MOB_EQUIPMENT
blacklisted_movetypes = FLOATING
/datum/movespeed_modifier/grab_slowdown
id = MOVESPEED_ID_MOB_GRAB_STATE
blacklisted_movetypes = FLOATING
/datum/movespeed_modifier/grab_slowdown/aggressive
@@ -51,15 +41,12 @@
multiplicative_slowdown = 9
/datum/movespeed_modifier/slime_reagentmod
id = MOVESPEED_ID_SLIME_REAGENTMOD
variable = TRUE
/datum/movespeed_modifier/slime_healthmod
id = MOVESPEED_ID_SLIME_HEALTHMOD
variable = TRUE
/datum/movespeed_modifier/config_walk_run
id = MOVESPEED_ID_MOB_WALK_RUN_CONFIG_SPEED
multiplicative_slowdown = 1
/datum/movespeed_modifier/config_walk_run/proc/sync()
@@ -73,58 +60,45 @@
multiplicative_slowdown = isnum(mod)? mod : initial(multiplicative_slowdown)
/datum/movespeed_modifier/turf_slowdown
id = MOVESPEED_ID_LIVING_TURF_SPEEDMOD
movetypes = GROUND
blacklisted_movetypes = (FLYING|FLOATING)
variable = TRUE
/datum/movespeed_modifier/bulky_drag
id = MOVESPEED_ID_BULKY_DRAGGING
variable = TRUE
/datum/movespeed_modifier/cold
id = MOVESPEED_ID_COLD
blacklisted_movetypes = FLOATING
variable = TRUE
/datum/movespeed_modifier/shove
id = MOVESPEED_ID_SHOVE
multiplicative_slowdown = SHOVE_SLOWDOWN_STRENGTH
/datum/movespeed_modifier/human_carry
id = MOVESPEED_ID_HUMAN_CARRYING
multiplicative_slowdown = HUMAN_CARRY_SLOWDOWN
/datum/movespeed_modifier/limbless
id = MOVESPEED_ID_LIVING_LIMBLESS
variable = TRUE
movetypes = GROUND
/datum/movespeed_modifier/simplemob_varspeed
id = MOVESPEED_ID_SIMPLEMOB_VARSPEED
variable = TRUE
/datum/movespeed_modifier/tarantula_web
id = MOVESPEED_ID_TARANTULA_WEB
multiplicative_slowdown = 3
/datum/movespeed_modifier/gravity
id = MOVESPEED_ID_MOB_GRAVITY
blacklisted_movetypes = FLOATING
variable = TRUE
/datum/movespeed_modifier/carbon_softcrit
id = MOVESPEED_ID_CARBON_SOFTCRIT
multiplicative_slowdown = SOFTCRIT_ADD_SLOWDOWN
/datum/movespeed_modifier/slime_tempmod
id = MOVESPEED_ID_SLIME_TEMPMOD
variable = TRUE
/datum/movespeed_modifier/carbon_crawling
id = MOVESPEED_ID_CARBON_CRAWLING
multiplicative_slowdown = CRAWLING_ADD_SLOWDOWN
/datum/movespeed_modifier/mob_config_speedmod
id = MOVESPEED_ID_CONFIG_SPEEDMOD
variable = TRUE
@@ -2,41 +2,31 @@
blacklisted_movetypes = (FLYING|FLOATING)
/datum/movespeed_modifier/reagent/stimulants
id = "stimulants_reagent"
multiplicative_slowdown = -1
/datum/movespeed_modifier/reagent/ephedrine
id = "ephedrine_reagent"
multiplicative_slowdown = -0.5
/datum/movespeed_modifier/reagent/pepperspray
id = MOVESPEED_ID_PEPPER_SPRAY
multiplicative_slowdown = 0.25
/datum/movespeed_modifier/reagent/badstims
id = "reagent_badstims"
multiplicative_slowdown = -0.45
/datum/movespeed_modifier/reagent/monkey_energy
id = "reagent_monkey_energy"
multiplicative_slowdown = -0.35
/datum/movespeed_modifier/reagent/changelinghaste
id = "reagent_changelinghaste"
multiplicative_slowdown = -2
/datum/movespeed_modifier/reagent/methamphetamine
id = "reagent_methamphetamine"
multiplicative_slowdown = -0.65
/datum/movespeed_modifier/reagent/nitryl
id = "reagent_nitryl"
multiplicative_slowdown = -0.65
/datum/movespeed_modifier/reagent/lenturi
id = "reagent_lenturi"
multiplicative_slowdown = 1.5
/datum/movespeed_modifier/reagent/nuka_cola
id = "reagent_nukacola"
multiplicative_slowdown = -0.35
@@ -1,22 +1,17 @@
/datum/movespeed_modifier/status_effect/bloodchill
id = "bloodchilled"
multiplicative_slowdown = 3
/datum/movespeed_modifier/status_effect/bonechill
id = "bonechilled"
multiplicative_slowdown = 3
/datum/movespeed_modifier/status_effect/lightpink
id = MOVESPEED_ID_SLIME_STATUS
multiplicative_slowdown = -0.5
blacklisted_movetypes = (FLYING|FLOATING)
/datum/movespeed_modifier/status_effect/tarfoot
id = MOVESPEED_ID_TARFOOT
multiplicative_slowdown = 0.5
blacklisted_movetypes = (FLYING|FLOATING)
/datum/movespeed_modifier/status_effect/sepia
variable = TRUE
id = MOVESPEED_ID_SEPIA
blacklisted_movetypes = (FLYING|FLOATING)