From 6ffc35a83b5c239eea3c79e973a5b7ae79ff4ee8 Mon Sep 17 00:00:00 2001 From: Emmett Gaines Date: Sat, 16 Nov 2019 19:21:31 -0500 Subject: [PATCH] Converts gravity slowdown into a movespeed mod and removes movement_delay() (#47808) Gravity still needs a rewrite but at least it's a speed modification now. EDIT: And now it's the last one, goodbye movement_delay()! cl ninjanomnom fix: Gravity slowdown applies to all mobs instead of just humanoids tweak: If you're floating in high gravity somehow you're no longer slowed down /cl --- code/__DEFINES/movespeed_modification.dm | 1 + code/game/area/areas.dm | 45 ------------------- code/game/atoms.dm | 45 +++++++++++++++++++ code/game/atoms_movable.dm | 2 +- code/modules/antagonists/cult/cult_items.dm | 6 +-- .../mob/living/carbon/human/human_movement.dm | 5 --- .../mob/living/carbon/human/species.dm | 15 ------- code/modules/mob/living/living.dm | 3 +- .../hostile/megafauna/hierophant.dm | 2 +- .../mob/living/simple_animal/parrot.dm | 1 - .../mob/living/simple_animal/slime/life.dm | 2 +- code/modules/mob/mob_movement.dm | 20 +++------ 12 files changed, 61 insertions(+), 86 deletions(-) diff --git a/code/__DEFINES/movespeed_modification.dm b/code/__DEFINES/movespeed_modification.dm index 483a18d7018..ae2a753f1c6 100644 --- a/code/__DEFINES/movespeed_modification.dm +++ b/code/__DEFINES/movespeed_modification.dm @@ -19,6 +19,7 @@ #define MOVESPEED_ID_MOB_WALK_RUN_CONFIG_SPEED "MOB_WALK_RUN" #define MOVESPEED_ID_MOB_GRAB_STATE "MOB_GRAB_STATE" #define MOVESPEED_ID_MOB_EQUIPMENT "MOB_EQUIPMENT" +#define MOVESPEED_ID_MOB_GRAVITY "MOB_GRAVITY" #define MOVESPEED_ID_CONFIG_SPEEDMOD "MOB_CONFIG_MODIFIER" #define MOVESPEED_ID_SLIME_REAGENTMOD "SLIME_REAGENT_MODIFIER" diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 8d0f669a036..f910eb01ad6 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -622,51 +622,6 @@ GLOBAL_LIST_EMPTY(teleportlocs) /client/proc/ResetAmbiencePlayed() played = FALSE -/** - * Returns true if this atom has gravity for the passed in turf - * - * Sends signals COMSIG_ATOM_HAS_GRAVITY and COMSIG_TURF_HAS_GRAVITY, both can force gravity with - * the forced gravity var - * - * Gravity situations: - * * No gravity if you're not in a turf - * * No gravity if this atom is in is a space turf - * * Gravity if the area it's in always has gravity - * * Gravity if there's a gravity generator on the z level - * * Gravity if the Z level has an SSMappingTrait for ZTRAIT_GRAVITY - * * otherwise no gravity - */ -/atom/proc/has_gravity(turf/T) - if(!T || !isturf(T)) - T = get_turf(src) - - if(!T) - return 0 - - var/list/forced_gravity = list() - SEND_SIGNAL(src, COMSIG_ATOM_HAS_GRAVITY, T, forced_gravity) - if(!forced_gravity.len) - SEND_SIGNAL(T, COMSIG_TURF_HAS_GRAVITY, src, forced_gravity) - if(forced_gravity.len) - var/max_grav - for(var/i in forced_gravity) - max_grav = max(max_grav, i) - return max_grav - - if(isspaceturf(T)) // Turf never has gravity - return 0 - - var/area/A = get_area(T) - if(A.has_gravity) // Areas which always has gravity - return A.has_gravity - else - // There's a gravity generator on our z level - if(GLOB.gravity_generators["[T.z]"]) - var/max_grav = 0 - for(var/obj/machinery/gravity_generator/main/G in GLOB.gravity_generators["[T.z]"]) - max_grav = max(G.setting,max_grav) - return max_grav - return SSmapping.level_trait(T.z, ZTRAIT_GRAVITY) /** * Setup an area (with the given name) * diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 8730ceea7c1..f7ae0b7fc50 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -1202,3 +1202,48 @@ custom_material.on_applied(src, materials[custom_material] * multiplier * material_modifier, material_flags) custom_materials[custom_material] += materials[x] * multiplier +/** + * Returns true if this atom has gravity for the passed in turf + * + * Sends signals COMSIG_ATOM_HAS_GRAVITY and COMSIG_TURF_HAS_GRAVITY, both can force gravity with + * the forced gravity var + * + * Gravity situations: + * * No gravity if you're not in a turf + * * No gravity if this atom is in is a space turf + * * Gravity if the area it's in always has gravity + * * Gravity if there's a gravity generator on the z level + * * Gravity if the Z level has an SSMappingTrait for ZTRAIT_GRAVITY + * * otherwise no gravity + */ +/atom/proc/has_gravity(turf/T) + if(!T || !isturf(T)) + T = get_turf(src) + + if(!T) + return 0 + + var/list/forced_gravity = list() + SEND_SIGNAL(src, COMSIG_ATOM_HAS_GRAVITY, T, forced_gravity) + if(!forced_gravity.len) + SEND_SIGNAL(T, COMSIG_TURF_HAS_GRAVITY, src, forced_gravity) + if(forced_gravity.len) + var/max_grav + for(var/i in forced_gravity) + max_grav = max(max_grav, i) + return max_grav + + if(isspaceturf(T)) // Turf never has gravity + return 0 + + var/area/A = get_area(T) + if(A.has_gravity) // Areas which always has gravity + return A.has_gravity + else + // There's a gravity generator on our z level + if(GLOB.gravity_generators["[T.z]"]) + var/max_grav = 0 + for(var/obj/machinery/gravity_generator/main/G in GLOB.gravity_generators["[T.z]"]) + max_grav = max(G.setting,max_grav) + return max_grav + return SSmapping.level_trait(T.z, ZTRAIT_GRAVITY) diff --git a/code/game/atoms_movable.dm b/code/game/atoms_movable.dm index 31404781763..4e823e46d7c 100644 --- a/code/game/atoms_movable.dm +++ b/code/game/atoms_movable.dm @@ -545,7 +545,7 @@ //They are moving! Wouldn't it be cool if we calculated their momentum and added it to the throw? if (thrower && thrower.last_move && thrower.client && thrower.client.move_delay >= world.time + world.tick_lag*2) - var/user_momentum = thrower.movement_delay() + var/user_momentum = thrower.cached_multiplicative_slowdown if (!user_momentum) //no movement_delay, this means they move once per byond tick, lets calculate from that instead. user_momentum = world.tick_lag diff --git a/code/modules/antagonists/cult/cult_items.dm b/code/modules/antagonists/cult/cult_items.dm index 48b5c3dd2d7..fd96a164e29 100644 --- a/code/modules/antagonists/cult/cult_items.dm +++ b/code/modules/antagonists/cult/cult_items.dm @@ -904,12 +904,12 @@ var/mob/living/simple_animal/hostile/illusion/M = new(owner.loc) M.faction = list("cult") M.Copy_Parent(owner, 70, 10, 5) - M.move_to_delay = owner.movement_delay() + M.move_to_delay = owner.cached_multiplicative_slowdown else var/mob/living/simple_animal/hostile/illusion/escape/E = new(owner.loc) E.Copy_Parent(owner, 70, 10) E.GiveTarget(owner) - E.Goto(owner, owner.movement_delay(), E.minimum_distance) + E.Goto(owner, owner.cached_multiplicative_slowdown, E.minimum_distance) return TRUE else if(prob(50)) @@ -917,7 +917,7 @@ H.Copy_Parent(owner, 100, 20, 5) H.faction = list("cult") H.GiveTarget(owner) - H.move_to_delay = owner.movement_delay() + H.move_to_delay = owner.cached_multiplicative_slowdown to_chat(owner, "[src] betrays you!") return FALSE diff --git a/code/modules/mob/living/carbon/human/human_movement.dm b/code/modules/mob/living/carbon/human/human_movement.dm index b815d8915bd..7f1c7c4c2fb 100644 --- a/code/modules/mob/living/carbon/human/human_movement.dm +++ b/code/modules/mob/living/carbon/human/human_movement.dm @@ -7,11 +7,6 @@ if(data[MOVESPEED_DATA_INDEX_FLAGS] & IGNORE_NOSLOW) .[id] = data -/mob/living/carbon/human/movement_delay() - . = ..() - if(dna && dna.species) - . += dna.species.movement_delay(src) - /mob/living/carbon/human/slip(knockdown_amount, obj/O, lube, paralyze, forcedrop) if(HAS_TRAIT(src, TRAIT_NOSLIPALL)) return 0 diff --git a/code/modules/mob/living/carbon/human/species.dm b/code/modules/mob/living/carbon/human/species.dm index 6fc9544df70..416b4257485 100644 --- a/code/modules/mob/living/carbon/human/species.dm +++ b/code/modules/mob/living/carbon/human/species.dm @@ -1150,21 +1150,6 @@ GLOBAL_LIST_EMPTY(roundstart_races) H.hairstyle = "Bald" H.update_hair() -//////////////// -// MOVE SPEED // -//////////////// - -/datum/species/proc/movement_delay(mob/living/carbon/human/H) - . = 0 //We start at 0. - var/gravity = H.has_gravity() - - if(!HAS_TRAIT(H, TRAIT_IGNORESLOWDOWN) && gravity > STANDARD_GRAVITY) - //Moving in high gravity is very slow (Flying too) - var/grav_force = min(gravity - STANDARD_GRAVITY,3) - . += 1 + grav_force - - return . - ////////////////// // ATTACK PROCS // ////////////////// diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 91241ab11ca..694f063d651 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -755,7 +755,8 @@ /mob/living/proc/get_visible_name() return name -/mob/living/update_gravity(has_gravity,override = 0) +/mob/living/update_gravity(has_gravity, override) + . = ..() if(!SSticker.HasRoundStarted()) return if(has_gravity) diff --git a/code/modules/mob/living/simple_animal/hostile/megafauna/hierophant.dm b/code/modules/mob/living/simple_animal/hostile/megafauna/hierophant.dm index 635ca6f537c..bec6ae87ceb 100644 --- a/code/modules/mob/living/simple_animal/hostile/megafauna/hierophant.dm +++ b/code/modules/mob/living/simple_animal/hostile/megafauna/hierophant.dm @@ -132,7 +132,7 @@ Difficulty: Hard var/mob/living/L if(isliving(target)) L = target - target_slowness += L.movement_delay() + target_slowness += L.cached_multiplicative_slowdown if(client) target_slowness += 1 diff --git a/code/modules/mob/living/simple_animal/parrot.dm b/code/modules/mob/living/simple_animal/parrot.dm index 09143b82760..715fd440db7 100644 --- a/code/modules/mob/living/simple_animal/parrot.dm +++ b/code/modules/mob/living/simple_animal/parrot.dm @@ -390,7 +390,6 @@ if(client && stat == CONSCIOUS && parrot_state != icon_living) icon_state = icon_living - //Because the most appropriate place to set icon_state is movement_delay(), clearly //-----SLEEPING if(parrot_state == PARROT_PERCH) diff --git a/code/modules/mob/living/simple_animal/slime/life.dm b/code/modules/mob/living/simple_animal/slime/life.dm index 2dea6dcb61e..88589b550b8 100644 --- a/code/modules/mob/living/simple_animal/slime/life.dm +++ b/code/modules/mob/living/simple_animal/slime/life.dm @@ -99,7 +99,7 @@ AIproc = 0 break - var/sleeptime = movement_delay() + var/sleeptime = cached_multiplicative_slowdown if(sleeptime <= 0) sleeptime = 1 diff --git a/code/modules/mob/mob_movement.dm b/code/modules/mob/mob_movement.dm index 9b1a2cc10bf..98a59b851cd 100644 --- a/code/modules/mob/mob_movement.dm +++ b/code/modules/mob/mob_movement.dm @@ -2,16 +2,6 @@ /mob/CanPass(atom/movable/mover, turf/target) return TRUE //There's almost no cases where non /living mobs should be used in game as actual mobs, other than ghosts. -/** - * Get the current movespeed delay of the mob - * - * DO NOT OVERRIDE THIS UNLESS YOU ABSOLUTELY HAVE TO. - * THIS IS BEING PHASED OUT FOR THE MOVESPEED MODIFICATION SYSTEM. - * See mob_movespeed.dm - */ -/mob/proc/movement_delay() //update /living/movement_delay() if you change this - return cached_multiplicative_slowdown - /** * If your mob is concious, drop the item in the active hand * @@ -131,7 +121,7 @@ if(!mob.Process_Spacemove(direct)) return FALSE //We are now going to move - var/add_delay = mob.movement_delay() + var/add_delay = mob.cached_multiplicative_slowdown if(old_move_delay + (add_delay*MOVEMENT_DELAY_BUFFER_DELTA) + MOVEMENT_DELAY_BUFFER > world.time) move_delay = old_move_delay else @@ -337,8 +327,12 @@ return /// Update the gravity status of this mob -/mob/proc/update_gravity() - return +/mob/proc/update_gravity(has_gravity, override=FALSE) + var/speed_change = max(0, has_gravity - STANDARD_GRAVITY) + if(!speed_change) + remove_movespeed_modifier(MOVESPEED_ID_MOB_GRAVITY, update=TRUE) + else + add_movespeed_modifier(MOVESPEED_ID_MOB_GRAVITY, update=TRUE, priority=100, override=TRUE, multiplicative_slowdown=speed_change, blacklisted_movetypes=FLOATING) //bodypart selection verbs - Cyberboss //8:repeated presses toggles through head - eyes - mouth