Skip to content

Commit

Permalink
Trying to clean up Process_Spacemove() to find issues with EVA slipping.
Browse files Browse the repository at this point in the history
  • Loading branch information
MistakeNot4892 committed Jan 23, 2025
1 parent 17ea5f6 commit e8b5b4d
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 129 deletions.
7 changes: 6 additions & 1 deletion code/__defines/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,9 @@
#define CRAYON_DRAW_RUNE "rune"
#define CRAYON_DRAW_GRAFFITI "graffiti"
#define CRAYON_DRAW_LETTER "letter"
#define CRAYON_DRAW_ARROW "arrow"
#define CRAYON_DRAW_ARROW "arrow"

// Enum for results of is_space_movement_permitted()
#define SPACE_MOVE_SUPPORTED (-1)
#define SPACE_MOVE_FORBIDDEN 0
#define SPACE_MOVE_PERMITTED 1
4 changes: 2 additions & 2 deletions code/_helpers/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
var/user_loc = user.loc

var/drifting = 0
if(!user.Process_Spacemove(0) && user.inertia_dir)
if(user.is_space_movement_permitted() == SPACE_MOVE_FORBIDDEN && user.inertia_dir)
drifting = 1

var/target_loc = target.loc
Expand Down Expand Up @@ -101,7 +101,7 @@
var/atom/original_loc = user.loc

var/drifting = 0
if(!user.Process_Spacemove(0) && user.inertia_dir)
if(user.is_space_movement_permitted() == SPACE_MOVE_FORBIDDEN && user.inertia_dir)
drifting = 1

var/holding = user.get_active_held_item()
Expand Down
4 changes: 2 additions & 2 deletions code/controllers/subsystems/spacedrift.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ SUBSYSTEM_DEF(spacedrift)
return
continue

if (!AM.loc || AM.loc != AM.inertia_last_loc || AM.Process_Spacemove(0))
if (!AM.loc || AM.loc != AM.inertia_last_loc || AM.is_space_movement_permitted() != SPACE_MOVE_FORBIDDEN)
AM.inertia_dir = 0

AM.inertia_ignore = null

if (!AM.inertia_dir)
Expand Down
15 changes: 11 additions & 4 deletions code/datums/movement/mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,28 @@
return (MOVEMENT_PROCEED|MOVEMENT_HANDLED)

/datum/movement_handler/mob/space
var/allow_move
var/last_space_move_result

// Notes on space movement chain:
// - owning mob calls MayMove() via normal movement handler chain
// - MayMove() sets last_space_move_result based on is_space_movement_permitted() (checks for footing, magboots, etc)
// - last_space_move_result is checked in DoMove() and passed to try_space_move() as a param, which returns TRUE/FALSE
// - if the original move result was forbidden, or try_space_move() fails, the handler prevents movement.
// - Otherwise it goes ahead and lets the mob move.

// Space movement
/datum/movement_handler/mob/space/DoMove(direction, mob/mover, is_external)
if(mob.has_gravity() || (IS_NOT_SELF(mover) && is_external))
return
if(!allow_move || !mob.space_do_move(allow_move, direction))
if(last_space_move_result == SPACE_MOVE_FORBIDDEN || !mob.try_space_move(last_space_move_result, direction))
return MOVEMENT_HANDLED

/datum/movement_handler/mob/space/MayMove(mob/mover, is_external)
if(IS_NOT_SELF(mover) && is_external)
return MOVEMENT_PROCEED
if(!mob.has_gravity())
allow_move = mob.Process_Spacemove(1)
if(!allow_move)
last_space_move_result = mob.is_space_movement_permitted(allow_movement = TRUE)
if(last_space_move_result == SPACE_MOVE_FORBIDDEN)
return MOVEMENT_STOP
return MOVEMENT_PROCEED

Expand Down
27 changes: 10 additions & 17 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

//call this proc to start space drifting
/atom/movable/proc/space_drift(direction)//move this down
if(!loc || direction & (UP|DOWN) || Process_Spacemove(0))
if(!loc || direction & (UP|DOWN) || is_space_movement_permitted() != SPACE_MOVE_FORBIDDEN)
inertia_dir = 0
inertia_ignore = null
return 0
Expand All @@ -59,29 +59,22 @@
return 1

//return 0 to space drift, 1 to stop, -1 for mobs to handle space slips
/atom/movable/proc/Process_Spacemove(var/allow_movement)
/atom/movable/proc/is_space_movement_permitted(allow_movement = FALSE)
if(!simulated)
return 1

return SPACE_MOVE_PERMITTED
if(has_gravity())
return 1

return SPACE_MOVE_PERMITTED
if(length(grabbed_by))
return 1

return SPACE_MOVE_PERMITTED
if(throwing)
return 1

return SPACE_MOVE_PERMITTED
if(anchored)
return 1

return SPACE_MOVE_PERMITTED
if(!isturf(loc))
return 1

return SPACE_MOVE_PERMITTED
if(locate(/obj/structure/lattice) in range(1, get_turf(src))) //Not realistic but makes pushing things in space easier
return -1

return 0
return SPACE_MOVE_SUPPORTED
return SPACE_MOVE_FORBIDDEN

/atom/movable/attack_hand(mob/user)
// Unbuckle anything buckled to us.
Expand Down
2 changes: 1 addition & 1 deletion code/modules/ZAS/Airflow.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Contains helper procs for airflow, called by /connection_group.
return FALSE

/mob/living/human/handle_airflow_stun()
if(!slip_chance())
if(!get_slip_prob())
to_chat(src, SPAN_NOTICE("Air suddenly rushes past you!"))
return FALSE
. = ..()
Expand Down
15 changes: 6 additions & 9 deletions code/modules/mechs/equipment/utility.dm
Original file line number Diff line number Diff line change
Expand Up @@ -603,17 +603,14 @@
QDEL_NULL(ion_trail)
return ..()

/obj/item/mech_equipment/ionjets/proc/allowSpaceMove()
if (!active)
/obj/item/mech_equipment/ionjets/proc/provides_thrust()
if(!active)
return FALSE

var/obj/item/cell/C = owner.get_cell()
if (istype(C))
if (C.checked_use(movement_power * CELLRATE))
var/obj/item/cell/cell = owner?.get_cell()
if(istype(cell))
if(cell.checked_use(movement_power * CELLRATE))
return TRUE
else
deactivate()

deactivate()
return FALSE

/obj/item/mech_equipment/ionjets/attack_self(mob/user)
Expand Down
43 changes: 22 additions & 21 deletions code/modules/mechs/mech_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

// Space movement
/datum/movement_handler/mob/space/exosuit/DoMove(direction, mob/mover, is_external)
if(!mob.has_gravity() && (!allow_move || (allow_move == -1 && mob.handle_spaceslipping())))
if(!mob.has_gravity() && (last_space_move_result == SPACE_MOVE_FORBIDDEN || (last_space_move_result == SPACE_MOVE_SUPPORTED && mob.handle_spaceslipping())))
return MOVEMENT_HANDLED
mob.inertia_dir = 0

Expand All @@ -130,39 +130,40 @@
return MOVEMENT_PROCEED

if(!mob.has_gravity())
allow_move = mob.Process_Spacemove(1)
if(!allow_move)
last_space_move_result = mob.is_space_movement_permitted(allow_movement = TRUE)
if(last_space_move_result == SPACE_MOVE_FORBIDDEN)
return MOVEMENT_STOP
return MOVEMENT_PROCEED

/mob/living/exosuit/can_slip(magboots_only = FALSE) //mechs are always magbooting
return FALSE
/mob/living/exosuit/has_non_slip_footing()
return TRUE

/mob/living/exosuit/Process_Spacemove(allow_movement)
//Regardless of modules, emp prevents control
/mob/living/exosuit/has_magnetised_footing()
return TRUE

/mob/living/exosuit/is_space_movement_permitted(allow_movement = FALSE)
. = SPACE_MOVE_FORBIDDEN
anchored = FALSE
//Regardless of modules, emp prevents control
if(has_gravity() || throwing || !isturf(loc) || length(grabbed_by) || !can_slip(magboots_only = TRUE) || locate(/obj/structure/lattice) in range(1, get_turf(src)))
. = SPACE_MOVE_PERMITTED
else
var/obj/item/mech_equipment/ionjets/J = hardpoints[HARDPOINT_BACK]
if(istype(J) && ((allow_movement || J.stabilizers) && J.provides_thrust()))
. = SPACE_MOVE_PERMITTED
if(. == SPACE_MOVE_PERMITTED)
anchored = TRUE
return TRUE

var/obj/item/mech_equipment/ionjets/J = hardpoints[HARDPOINT_BACK]
if(istype(J) && ((allow_movement || J.stabilizers) && J.allowSpaceMove()))
return TRUE

anchored = FALSE
return FALSE

/mob/living/exosuit/space_do_move(allow_move)
if(allow_move == 1)
/mob/living/exosuit/try_space_move(space_move_result, direction)
if(space_move_result == SPACE_MOVE_PERMITTED)
if(emp_damage >= EMP_MOVE_DISRUPT && prob(25))
var/obj/item/mech_equipment/ionjets/J = hardpoints[HARDPOINT_BACK]
if(istype(J) && J.allowSpaceMove())
if(istype(J) && J.provides_thrust())
to_chat(src, SPAN_WARNING("\The [J] misfire, drifting \the [src] off course!"))
SetMoveCooldown(15) //2 seconds of random rando panic drifting
step(src, pick(global.alldirs))
return 0

. = ..()
return FALSE
return ..()

/mob/living/exosuit/overmap_can_discard()
for(var/atom/movable/AM in contents)
Expand Down
24 changes: 5 additions & 19 deletions code/modules/mob/living/human/human_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,19 @@
. = ..()
. += species.strength

/mob/living/human/space_do_move(var/allow_move, var/direction)
if(allow_move == 1)
/mob/living/human/try_space_move(space_move_result, direction)
if(space_move_result == SPACE_MOVE_PERMITTED)
var/obj/item/tank/jetpack/thrust = get_jetpack()
if(thrust && thrust.on && prob(skill_fail_chance(SKILL_EVA, 10, SKILL_ADEPT)))
to_chat(src, "<span class='warning'>You fumble with [thrust] controls!</span>")
to_chat(src, SPAN_WARNING("You fumble with the controls of \the [thrust]!"))
if(prob(50))
thrust.toggle()
if(prob(50))
thrust.stabilization_on = 0
SetMoveCooldown(15) //2 seconds of random rando panic drifting
step(src, pick(global.alldirs))
return 0

. = ..()

/mob/living/human/slip_chance(var/prob_slip = 5)
if(!..())
return 0
//Check hands and mod slip
for(var/hand_slot in get_held_item_slots())
var/datum/inventory_slot/inv_slot = get_inventory_slot_datum(hand_slot)
var/obj/item/held = inv_slot?.get_equipped_item()
if(!held)
prob_slip -= 2
else if(held.w_class <= ITEM_SIZE_SMALL)
prob_slip -= 1
return prob_slip
return FALSE
return ..()

/mob/living/human/Move()
. = ..()
Expand Down
4 changes: 0 additions & 4 deletions code/modules/mob/living/silicon/robot/drone/drone.dm
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@
if(amount && should_be_dead() && stat == DEAD && !QDELETED(src))
gib()

//DRONE MOVEMENT.
/mob/living/silicon/robot/drone/slip_chance(var/prob_slip)
return 0

//CONSOLE PROCS
/mob/living/silicon/robot/drone/proc/law_resync()

Expand Down
8 changes: 4 additions & 4 deletions code/modules/mob/living/silicon/robot/flying/flying.dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
if(. && !gibbed)
stop_flying()

/mob/living/silicon/robot/flying/Process_Spacemove()
return (pass_flags & PASS_FLAG_TABLE) || ..()
/mob/living/silicon/robot/flying/is_space_movement_permitted(allow_movement = FALSE)
return (pass_flags & PASS_FLAG_TABLE) ? SPACE_MOVE_PERMITTED : ..()

/mob/living/silicon/robot/flying/can_fall(var/anchor_bypass = FALSE, var/turf/location_override = loc)
return !Process_Spacemove()
return is_space_movement_permitted() == SPACE_MOVE_FORBIDDEN

/mob/living/silicon/robot/flying/can_overcome_gravity()
return Process_Spacemove()
return is_space_movement_permitted() != SPACE_MOVE_FORBIDDEN
4 changes: 2 additions & 2 deletions code/modules/mob/living/simple_animal/_simple_animal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -587,5 +587,5 @@ var/global/list/simplemob_icon_bitflag_cache = list()
if((. = ..()))
queue_icon_update()

/mob/living/simple_animal/Process_Spacemove(allow_movement)
return skip_spacemove ? 1 : ..()
/mob/living/simple_animal/is_space_movement_permitted(allow_movement = FALSE)
return skip_spacemove ? SPACE_MOVE_PERMITTED : ..()
17 changes: 11 additions & 6 deletions code/modules/mob/mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@
if(istype(paw) && paw.is_usable())
return paw

/mob/proc/get_solid_footing(turf_only = FALSE)
/mob/proc/get_solid_footing(ignore_walls = FALSE, turf_only = FALSE)

if(!loc)
return src // this is a bit weird but we shouldn't slip in nullspace probably
Expand All @@ -1417,8 +1417,11 @@
if(!istype(my_turf))
return my_turf

if(!my_turf.is_open() && (my_turf.is_wall() || my_turf.is_floor()))
return my_turf
if(!my_turf.is_open())
if(!ignore_walls && my_turf.is_wall())
return my_turf
if(my_turf.is_floor())
return my_turf

// Check for catwalks and lattices.
var/atom/platform = my_turf.get_supporting_platform() || (locate(/obj/structure/lattice) in my_turf)
Expand All @@ -1429,6 +1432,8 @@
for(var/turf/neighbor in RANGE_TURFS(my_turf, 1))
if(neighbor == my_turf)
continue
if(ignore_walls && neighbor.is_wall())
continue
if(neighbor.contains_dense_objects(exceptions = src))
return neighbor
platform = neighbor.get_supporting_platform() || (locate(/obj/structure/lattice) in neighbor)
Expand All @@ -1455,14 +1460,14 @@
if(!is_being_grabbed)
. = thing

/mob/proc/can_slip(magboots_only = FALSE)
/mob/proc/can_slip(ignore_walls = FALSE, magboots_only = FALSE)

// Are we immune to everything?
if(status_flags & GODMODE)
return FALSE

// Quick basic checks.
if(!simulated || !isturf(loc) || buckled || current_posture?.prone || immune_to_floor_hazards())
if(!simulated || !isturf(loc) || buckled || current_posture?.prone || throwing)
return FALSE

// Species flag/proc check.
Expand All @@ -1473,7 +1478,7 @@
if(!magboots_only && has_non_slip_footing())
return FALSE
// We can't magnetise onto a friendly handholding from our buddy.
if(has_magnetised_footing() && get_solid_footing(turf_only = TRUE))
if(has_magnetised_footing() && get_solid_footing(ignore_walls = ignore_walls, turf_only = TRUE))
return FALSE

// Slip!
Expand Down
Loading

0 comments on commit e8b5b4d

Please sign in to comment.