Skip to content

Commit

Permalink
[Port] Makes gravity event based, QOL additions as well as bugfixes r…
Browse files Browse the repository at this point in the history
…egarding gravity (#11406)

* floored mobs

* rahhh

* Update gravitygenerator.dm

* rah

* to do: gravity generator shenanigens

* rahhh

* Update fullscreen.dm

* rahhhhh

* asfas

* Update movetype_handler.dm

* aaa

* fffhg

* dassad

* now it works

* Update screen_alert.dmi

* sadasd

* CI/CD

* Update screen_alert.dmi

* 16h icon diff bot moment

* Update gravity.dm
  • Loading branch information
XeonMations authored Dec 7, 2024
1 parent 2dc0e7a commit fce35d1
Show file tree
Hide file tree
Showing 54 changed files with 403 additions and 150 deletions.
4 changes: 2 additions & 2 deletions code/__DEFINES/dcs/signals/signals_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
// /datum/element/movetype_handler signals
/// Called when the floating anim has to be temporarily stopped and restarted later: (timer)
#define COMSIG_PAUSE_FLOATING_ANIM "pause_floating_anim"
/// From base of datum/element/movetype_handler/on_movement_type_trait_gain: (flag)
/// From base of datum/element/movetype_handler/on_movement_type_trait_gain: (flag, old_movement_type)
#define COMSIG_MOVETYPE_FLAG_ENABLED "movetype_flag_enabled"
/// From base of datum/element/movetype_handler/on_movement_type_trait_loss: (flag)
/// From base of datum/element/movetype_handler/on_movement_type_trait_loss: (flag, old_movement_type)
#define COMSIG_MOVETYPE_FLAG_DISABLED "movetype_flag_disabled"

4 changes: 4 additions & 0 deletions code/__DEFINES/flags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
#define FLOATING (1<<3)
#define PHASING (1<<4) //! When moving, will Bump()/Cross() everything, but won't be stopped.
#define THROWN (1<<5) //! while an atom is being thrown
#define UPSIDE_DOWN (1<<6) /// The mob is walking on the ceiling. Or is generally just, upside down.

/// Combination flag for movetypes which, for all intents and purposes, mean the mob is not touching the ground
#define MOVETYPES_NOT_TOUCHING_GROUND (FLYING|FLOATING|UPSIDE_DOWN)

//! ## Fire and Acid stuff, for resistance_flags
#define LAVA_PROOF (1<<0)
Expand Down
17 changes: 14 additions & 3 deletions code/__DEFINES/gravity.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@
/// Singularity is stage 6 (11x11)
#define STAGE_SIX 11 //! From supermatter shard

/// Anything above this is high gravity, anything below no grav until negative gravity
#define STANDARD_GRAVITY 1
/**
* The point where gravity is negative enough to pull you upwards.
* That means walking checks for a ceiling instead of a floor, and you can fall "upwards"
*
* This should only be possible on multi-z maps because it works like shit on maps that aren't.
*/
#define NEGATIVE_GRAVITY -1

#define STANDARD_GRAVITY 1 //Anything above this is high gravity, anything below no grav until negative gravity
/// The gravity strength threshold for high gravity damage.
#define GRAVITY_DAMAGE_TRESHOLD 3
#define GRAVITY_DAMAGE_THRESHOLD 3
/// The scaling factor for high gravity damage.
#define GRAVITY_DAMAGE_SCALING 0.5
/// The maximum [BRUTE] damage a mob can take from high gravity per second.
#define GRAVITY_DAMAGE_MAXIMUM 1.5
7 changes: 7 additions & 0 deletions code/__DEFINES/traits/declarations.dm
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,11 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
/// The person with this trait always appears as 'unknown'.
#define TRAIT_UNKNOWN "unknown"

/// We are ignoring gravity
#define TRAIT_IGNORING_GRAVITY "ignores_gravity"
/// We have some form of forced gravity acting on us
#define TRAIT_FORCED_GRAVITY "forced_gravity"
#define TRAIT_MOVE_UPSIDE_DOWN "move_upside_down"
#define TRAIT_NEGATES_GRAVITY "negates_gravity"

// END TRAIT DEFINES
3 changes: 3 additions & 0 deletions code/__DEFINES/traits/sources.dm
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@
#define NO_GRAVITY_TRAIT "no-gravity"
#define LIFECANDLE_TRAIT "lifecandle"
#define LEAPER_BUBBLE_TRAIT "leaper-bubble"
#define NEGATIVE_GRAVITY_TRAIT "negative-gravity"
/// Sources for TRAIT_IGNORING_GRAVITY
#define IGNORING_GRAVITY_NEGATION "ignoring_gravity_negation"
3 changes: 2 additions & 1 deletion code/_globalvars/bitfields.dm
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ DEFINE_BITFIELD(movement_type, list(
"FLYING" = FLYING,
"VENTCRAWLING" = VENTCRAWLING,
"FLOATING" = FLOATING,
"PHASING" = PHASING
"PHASING" = PHASING,
"UPSIDE_DOWN" = UPSIDE_DOWN,
))

DEFINE_BITFIELD(mat_container_flags, list(
Expand Down
6 changes: 5 additions & 1 deletion code/_globalvars/traits/_traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ GLOBAL_LIST_INIT(traits_by_type, list(
"TRAIT_NORADDAMAGE" = TRAIT_NORADDAMAGE,
"TRAIT_MOBILE" = TRAIT_MOBILE,
"INSTANT_DO_AFTER" = INSTANT_DO_AFTER,
"TRAIT_UNKNOWN" = TRAIT_UNKNOWN
"TRAIT_UNKNOWN" = TRAIT_UNKNOWN,
"TRAIT_IGNORING_GRAVITY" = TRAIT_IGNORING_GRAVITY,
"TRAIT_FORCED_GRAVITY" = TRAIT_FORCED_GRAVITY,
"TRAIT_MOVE_UPSIDE_DOWN" = TRAIT_MOVE_UPSIDE_DOWN,
"TRAIT_NEGATES_GRAVITY" = TRAIT_NEGATES_GRAVITY
),
/obj/item/integrated_circuit = list(
"TRAIT_COMPONENT_MMI" = TRAIT_COMPONENT_MMI,
Expand Down
5 changes: 5 additions & 0 deletions code/_onclick/hud/alert.dm
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ If you're feeling frisky, examine yourself and click the underlined item to pull
var/mob/living/carbon/M = usr
return M.help_shake_act(M)

/atom/movable/screen/alert/negative
name = "Negative Gravity"
desc = "You're getting pulled upwards. While you won't have to worry about falling down anymore, you may accidentally fall upwards!"
icon_state = "negative"

/atom/movable/screen/alert/weightless
name = "Weightless"
desc = "Gravity has ceased affecting you, and you're floating around aimlessly. You'll need something large and heavy, like a \
Expand Down
25 changes: 25 additions & 0 deletions code/controllers/subsystem/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ SUBSYSTEM_DEF(mapping)
var/datum/space_level/empty_space
var/num_of_res_levels = 1

///shows the default gravity value for each z level. recalculated when gravity generators change.
///List in the form: list(z level num = max generator gravity in that z level OR the gravity level trait)
var/list/gravity_by_z_level = list()

/datum/controller/subsystem/mapping/PreInit()
..()
#ifdef FORCE_MAP
Expand Down Expand Up @@ -126,6 +130,7 @@ SUBSYSTEM_DEF(mapping)
generate_station_area_list()
transit = add_new_zlevel("Transit/Reserved", list(ZTRAIT_RESERVED = TRUE))
initialize_reserved_level(transit.z_value)
calculate_default_z_level_gravities()
return SS_INIT_SUCCESS

/datum/controller/subsystem/mapping/fire(resumed)
Expand Down Expand Up @@ -617,6 +622,9 @@ GLOBAL_LIST_EMPTY(the_station_areas)
/// - Adds to z_list, and builds its area turfs
/datum/controller/subsystem/mapping/proc/manage_z_level(datum/space_level/new_z, filled_with_space, contain_turfs = TRUE)
z_list += new_z

gravity_by_z_level.len += 1

if(contain_turfs)
build_area_turfs(new_z.z_value, filled_with_space)

Expand All @@ -632,6 +640,10 @@ GLOBAL_LIST_EMPTY(the_station_areas)
var/area/our_area = to_contain.loc
our_area.contained_turfs += to_contain

/datum/controller/subsystem/mapping/proc/calculate_default_z_level_gravities()
for(var/z_level in 1 to length(z_list))
calculate_z_level_gravity(z_level)

/datum/controller/subsystem/mapping/proc/generate_z_level_linkages()
for(var/z_level in 1 to length(z_list))
generate_linkages_for_z_level(z_level)
Expand All @@ -650,3 +662,16 @@ GLOBAL_LIST_EMPTY(the_station_areas)
multiz_levels[z_level] = new /list(LARGEST_Z_LEVEL_INDEX)
multiz_levels[z_level][Z_LEVEL_UP] = !!z_above
multiz_levels[z_level][Z_LEVEL_DOWN] = !!z_below

/datum/controller/subsystem/mapping/proc/calculate_z_level_gravity(z_level_number)
if(!isnum(z_level_number) || z_level_number < 1)
return FALSE

var/max_gravity = 0

for(var/obj/machinery/gravity_generator/main/grav_gen as anything in GLOB.gravity_generators["[z_level_number]"])
max_gravity = max(grav_gen.setting, max_gravity)

max_gravity = max_gravity || level_trait(z_level_number, ZTRAIT_GRAVITY) || 0 //just to make sure no nulls
gravity_by_z_level[z_level_number] = max_gravity
return max_gravity
2 changes: 1 addition & 1 deletion code/datums/components/caltrop.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
if(!(flags & CALTROP_BYPASS_SHOES) && (H.shoes || feetCover))
return

if((H.movement_type & (FLYING|FLOATING)) || (H.body_position == LYING_DOWN)|| H.buckled)
if((H.movement_type & MOVETYPES_NOT_TOUCHING_GROUND) || (H.body_position == LYING_DOWN)|| H.buckled)
return

var/damage = rand(min_damage, max_damage)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/chasm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
return FALSE
if(!isliving(AM) && !isobj(AM))
return FALSE
if(is_type_in_typecache(AM, forbidden_types) || AM.throwing || (AM.movement_type & (FLOATING|FLYING)))
if(is_type_in_typecache(AM, forbidden_types) || AM.throwing || (AM.movement_type & MOVETYPES_NOT_TOUCHING_GROUND))
return FALSE
//Flies right over the chasm
if(ismob(AM))
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/conveyor_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
source.delay = speed //We use the default delay
if(living_parent)
var/mob/living/moving_mob = parent
if((moving_mob.movement_type & (FLOATING|FLYING)) && !moving_mob.stat)
if((moving_mob.movement_type & MOVETYPES_NOT_TOUCHING_GROUND) && !moving_mob.stat)
return MOVELOOP_SKIP_STEP
var/atom/movable/moving_parent = parent
if(moving_parent.anchored || !moving_parent.has_gravity())
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/slippery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
if(!isliving(arrived))
return
var/mob/living/victim = arrived
if(!(victim.movement_type & (FLOATING|FLYING)) && victim.slip(knockdown_time, parent, lube_flags, paralyze_time, force_drop_items) && callback)
if(!(victim.movement_type & MOVETYPES_NOT_TOUCHING_GROUND) && victim.slip(knockdown_time, parent, lube_flags, paralyze_time, force_drop_items) && callback)
callback.Invoke(victim)

/datum/component/slippery/UnregisterFromParent()
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/spikes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
if(ishuman(C))
var/mob/living/carbon/human/H = C
var/feetCover = (H.wear_suit && (H.wear_suit.body_parts_covered & FEET)) || (H.w_uniform && (H.w_uniform.body_parts_covered & FEET))
if((H.movement_type & (FLOATING|FLYING)) || H.body_position == LYING_DOWN || H.buckled || H.shoes || feetCover)
if((H.movement_type & MOVETYPES_NOT_TOUCHING_GROUND) || H.body_position == LYING_DOWN || H.buckled || H.shoes || feetCover)
prick(H, 0.5)
else
prick(H, 2)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/squashable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

if(isliving(crossing_movable))
var/mob/living/crossing_mob = crossing_movable
if(crossing_mob.mob_size > MOB_SIZE_SMALL && !(crossing_mob.movement_type & (FLOATING|FLYING)))
if(crossing_mob.mob_size > MOB_SIZE_SMALL && !(crossing_mob.movement_type & MOVETYPES_NOT_TOUCHING_GROUND))
if(HAS_TRAIT(crossing_mob, TRAIT_PACIFISM))
crossing_mob.visible_message("<span class='notice'>[crossing_mob] carefully steps over [parent_as_living].</span>", "<span class='notice'>You carefully step over [parent_as_living] to avoid hurting it.</span>")
return
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/squeak.dm
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
return
if(istype(arrived, /obj/effect/dummy/phased_mob)) //don't squeek if they're in a phased/jaunting container.
return
if(arrived.movement_type & (FLYING|FLOATING) || !arrived.has_gravity())
if(arrived.movement_type & MOVETYPES_NOT_TOUCHING_GROUND || !arrived.has_gravity())
return
var/atom/current_parent = parent
if(isturf(current_parent?.loc))
Expand Down
17 changes: 11 additions & 6 deletions code/datums/elements/forced_gravity.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@
var/gravity
var/ignore_space

/datum/element/forced_gravity/Attach(datum/target, gravity=1, ignore_space=FALSE)
/datum/element/forced_gravity/Attach(datum/target, gravity=1, ignore_space=FALSE, can_override = FALSE)
. = ..()
if(!isatom(target))
return ELEMENT_INCOMPATIBLE

src.gravity = gravity
src.ignore_space = ignore_space

RegisterSignal(target, COMSIG_ATOM_HAS_GRAVITY, PROC_REF(gravity_check))
RegisterSignal(target, COMSIG_ATOM_HAS_GRAVITY, PROC_REF(gravity_check), override = can_override)
if(isturf(target))
RegisterSignal(target, COMSIG_TURF_HAS_GRAVITY, PROC_REF(turf_gravity_check))
RegisterSignal(target, COMSIG_TURF_HAS_GRAVITY, PROC_REF(turf_gravity_check), override = can_override)

ADD_TRAIT(target, TRAIT_FORCED_GRAVITY, REF(src))

/datum/element/forced_gravity/Detach(datum/source, force)
. = ..()
var/static/list/signals_b_gone = list(COMSIG_ATOM_HAS_GRAVITY, COMSIG_TURF_HAS_GRAVITY)
UnregisterSignal(source, signals_b_gone)
REMOVE_TRAIT(source, TRAIT_FORCED_GRAVITY, REF(src))

/datum/element/forced_gravity/proc/gravity_check(datum/source, turf/location, list/gravs)
SIGNAL_HANDLER
if(!ignore_space && isspaceturf(location))
return
if(!ignore_space && location.force_no_gravity)
return FALSE
gravs += gravity

return TRUE

/datum/element/forced_gravity/proc/turf_gravity_check(datum/source, atom/checker, list/gravs)
SIGNAL_HANDLER
return gravity_check(null, source, gravs)
gravity_check(null, source, gravs)
12 changes: 9 additions & 3 deletions code/datums/elements/movetype_handler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,24 @@
if(!(source.movement_type & (FLOATING|FLYING)) && (trait == TRAIT_MOVE_FLYING || trait == TRAIT_MOVE_FLOATING) && !paused_floating_anim_atoms[source] && !HAS_TRAIT(source, TRAIT_NO_FLOATING_ANIM))
DO_FLOATING_ANIM(source)
source.movement_type |= flag
SEND_SIGNAL(source, COMSIG_MOVETYPE_FLAG_ENABLED, flag)
if((trait == TRAIT_MOVE_FLYING || trait == TRAIT_MOVE_FLOATING) && !(source.movement_type & (FLOATING|FLYING)))
stop_floating(source)
SEND_SIGNAL(source, COMSIG_MOVETYPE_FLAG_DISABLED, flag)

/// Called when a movement type trait is removed from the movable. Disables the relative bitflag if it wasn't there in the compile-time bitfield.
/datum/element/movetype_handler/proc/on_movement_type_trait_loss(atom/movable/source, trait)
SIGNAL_HANDLER
var/flag = GLOB.movement_type_trait_to_flag[trait]
if(initial(source.movement_type) & flag)
return
var/old_state = source.movement_type
source.movement_type &= ~flag
if((trait == TRAIT_MOVE_FLYING || trait == TRAIT_MOVE_FLOATING) && !(source.movement_type & (FLOATING|FLYING)))
if((old_state & (FLOATING|FLYING)) && !(source.movement_type & (FLOATING|FLYING)))
stop_floating(source)
SEND_SIGNAL(source, COMSIG_MOVETYPE_FLAG_DISABLED, flag)
var/turf/pitfall = source.loc //Things that don't fly fall in open space.
if(istype(pitfall))
pitfall.zFall(source)
SEND_SIGNAL(source, COMSIG_MOVETYPE_FLAG_DISABLED, flag, old_state)

/// Called when the TRAIT_NO_FLOATING_ANIM trait is added to the movable. Stops it from bobbing up and down.
/datum/element/movetype_handler/proc/on_no_floating_anim_trait_gain(atom/movable/source, trait)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/proximity_monitor/fields/gravity.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/datum/proximity_monitor/advanced/gravity/setup_field_turf(turf/T)
. = ..()
T.AddElement(/datum/element/forced_gravity, gravity_value)
T.AddElement(/datum/element/forced_gravity, gravity_value, can_override = TRUE)
modified_turfs[T] = gravity_value

/datum/proximity_monitor/advanced/gravity/cleanup_field_turf(turf/T)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/weather/weather_types/floor_is_lava.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
return
if(!L.client) //Only sentient people are going along with it!
return
if(L.movement_type & (FLOATING|FLYING))
if(L.movement_type & MOVETYPES_NOT_TOUCHING_GROUND)
return
L.adjustFireLoss(3)
39 changes: 19 additions & 20 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,12 @@ CREATION_TEST_IGNORE_SUBTYPES(/atom)
* Sends signals [COMSIG_ATOM_HAS_GRAVITY] and [COMSIG_TURF_HAS_GRAVITY], both can force gravity with
* the forced gravity var.
*
* HEY JACKASS, LISTEN
* IF YOU ADD SOMETHING TO THIS PROC, MAKE SURE /mob/living ACCOUNTS FOR IT
*
* Living mobs treat gravity in an event based manner. We've decomposed this proc into different checks
* for them to use. If you add more to it, make sure you do that, or things will behave strangely
*
* Gravity situations:
* * No gravity if you're not in a turf
* * No gravity if this atom is in is a space turf
Expand All @@ -1909,32 +1915,25 @@ CREATION_TEST_IGNORE_SUBTYPES(/atom)
if(!isturf(gravity_turf))
gravity_turf = get_turf(src)

if(!gravity_turf)
if(!gravity_turf)//no gravity in nullspace
return FALSE

var/list/forced_gravity = list()
SEND_SIGNAL(src, COMSIG_ATOM_HAS_GRAVITY, gravity_turf, forced_gravity)
if(!length(forced_gravity))
SEND_SIGNAL(gravity_turf, COMSIG_TURF_HAS_GRAVITY, src, forced_gravity)
SEND_SIGNAL(gravity_turf, COMSIG_TURF_HAS_GRAVITY, src, forced_gravity)
if(length(forced_gravity))
var/max_grav
for(var/i in forced_gravity)
max_grav = max(max_grav, i)
return max_grav
var/positive_grav = max(forced_gravity)
var/negative_grav = min(min(forced_gravity), 0) //negative grav needs to be below or equal to 0

if(!gravity_turf.check_gravity()) // Turf never has gravity
return FALSE
var/area/A = get_area(gravity_turf)
if(A.has_gravity) // Areas which always has gravity
return TRUE
else if(SSmapping.level_trait(gravity_turf.z, ZTRAIT_GRAVITY)) // If the z-level always has gravity
return TRUE
else if(GLOB.gravity_generators["[gravity_turf.get_virtual_z_level()]"]) // If there's a gravity generator on our z level
var/max_grav = 0
for(var/obj/machinery/gravity_generator/main/G in GLOB.gravity_generators["[gravity_turf.get_virtual_z_level()]"])
max_grav = max(G.setting,max_grav)
return max_grav
return FALSE
//our gravity is sum of the most massive positive and negative numbers returned by the signal
//so that adding two forced_gravity elements with an effect size of 1 each doesnt add to 2 gravity
//but negative force gravity effects can cancel out positive ones

return (positive_grav + negative_grav)

var/area/turf_area = gravity_turf.loc

return !gravity_turf.force_no_gravity && (SSmapping.gravity_by_z_level[gravity_turf.z] || turf_area.has_gravity)

/*
* Called when something made out of plasma is exposed to high temperatures.
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/effects/mines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
/obj/effect/mine/proc/on_entered(datum/source, atom/movable/AM)
SIGNAL_HANDLER

if(!isturf(loc) || AM.throwing || (AM.movement_type & (FLYING | FLOATING)) || !AM.has_gravity() || triggered)
if(!isturf(loc) || AM.throwing || (AM.movement_type & MOVETYPES_NOT_TOUCHING_GROUND) || !AM.has_gravity() || triggered)
return
if(ismob(AM))
checksmartmine(AM)
Expand Down
Loading

0 comments on commit fce35d1

Please sign in to comment.