Converts move intents to /decl/move_intent (#8993)

* Converts move intents to /decl/move_intent

Adds /decl/move_intent/walk and /decl/move_intent/run.

Switches all move intent checks to use the new IS_RUNNING and IS_WALKING macros.

Renames and refactors /mob/living/proc/set_m_intent() to /mob/living/proc/set_move_intent(decl/move_intent/intent).

Removes the unnecessary /mob/var/m_int and associated code.

Updates all move intent setters to use set_move_intent().

* Swaps incorrect config values

Swaps incorrect move delays since I got them backwards somehow, oopsies.

* Adds suggested ?. operator

Compactifies two if statements using the ?. operator instead.
This commit is contained in:
Frenjo
2023-03-04 22:28:10 +00:00
committed by GitHub
parent 633e8c6dd8
commit 20cdc4b676
27 changed files with 110 additions and 115 deletions

View File

@@ -0,0 +1,3 @@
// Move intent decl helpers.
#define IS_WALKING(X) istype(X.move_intent, /decl/move_intent/walk)
#define IS_RUNNING(X) istype(X.move_intent, /decl/move_intent/run)

View File

@@ -12,7 +12,7 @@
using.name = "mov_intent"
using.set_dir(SOUTHWEST)
using.icon = HUD.ui_style
using.icon_state = (m_intent == "run" ? "running" : "walking")
using.icon_state = move_intent.hud_icon_state
using.screen_loc = ui_acti
using.layer = HUD_LAYER
HUD.adding += using

View File

@@ -14,7 +14,7 @@
var/other = list()
var/hotkeybuttons = list()
var/slot_info = list()
HUD.adding = adding
HUD.other = other
HUD.hotkeybuttons = hotkeybuttons //These can be disabled for hotkey users
@@ -132,7 +132,7 @@
using = new /obj/screen()
using.name = "mov_intent"
using.icon = HUD.ui_style
using.icon_state = (m_intent == "run" ? "running" : "walking")
using.icon_state = move_intent.hud_icon_state
using.screen_loc = ui_movi
using.color = HUD.ui_color
using.alpha = HUD.ui_alpha
@@ -351,4 +351,4 @@
/obj/screen/wizard/energy
name = "energy"
icon_state = "wiz_energy"
icon_state = "wiz_energy"

View File

@@ -274,42 +274,16 @@
L.resist()
if("mov_intent")
if(isliving(usr))
if(iscarbon(usr))
var/mob/living/carbon/C = usr
if(C.legcuffed)
to_chat(C, "<span class='notice'>You are legcuffed! You cannot run until you get [C.legcuffed] removed!</span>")
C.m_intent = "walk" //Just incase
C.hud_used.move_intent.icon_state = "walking"
return 1
var/mob/living/L = usr
switch(L.m_intent)
if("run")
L.m_intent = "walk"
L.hud_used.move_intent.icon_state = "walking"
if("walk")
L.m_intent = "run"
L.hud_used.move_intent.icon_state = "running"
if("m_intent")
if(!usr.m_int)
switch(usr.m_intent)
if("run")
usr.m_int = "13,14"
if("walk")
usr.m_int = "14,14"
if("face")
usr.m_int = "15,14"
else
usr.m_int = null
if("walk")
usr.m_intent = "walk"
usr.m_int = "14,14"
if("face")
usr.m_intent = "face"
usr.m_int = "15,14"
if("run")
usr.m_intent = "run"
usr.m_int = "13,14"
if(iscarbon(usr))
var/mob/living/carbon/C = usr
if(C.legcuffed)
to_chat(C, "<span class='notice'>You are legcuffed! You cannot run until you get [C.legcuffed] removed!</span>")
C.set_move_intent(/decl/move_intent/walk) // Just incase.
return 1
else
var/next_move_intent = next_in_list(C.move_intent.type, C.move_intents)
C.set_move_intent(next_move_intent)
if("Reset Machine")
usr.unset_machine()
if("internal")

View File

@@ -0,0 +1,22 @@
/decl/move_intent
var/name
var/move_delay = 1
var/hud_icon_state
// Walking
/decl/move_intent/walk
name = "Walk"
hud_icon_state = "walking"
/decl/move_intent/walk/Initialize()
. = ..()
move_delay = config.walk_speed
// Running
/decl/move_intent/run
name = "Run"
hud_icon_state = "running"
/decl/move_intent/run/Initialize()
. = ..()
move_delay = config.run_speed

View File

@@ -386,7 +386,7 @@ var/global/list/mob/living/forced_ambiance_list = new
L.lastarea = get_area(L.loc)
var/area/newarea = get_area(L.loc)
var/area/oldarea = L.lastarea
if((oldarea.has_gravity == 0) && (newarea.has_gravity == 1) && (L.m_intent == "run")) // Being ready when you change areas gives you a chance to avoid falling all together.
if((oldarea.has_gravity == 0) && (newarea.has_gravity == 1) && IS_RUNNING(L)) // Being ready when you change areas gives you a chance to avoid falling all together.
thunk(L)
L.update_floating( L.Check_Dense_Object() )
@@ -447,7 +447,7 @@ var/global/list/mob/living/forced_ambiance_list = new
if(istype(H.shoes, /obj/item/clothing/shoes/magboots) && (H.shoes.item_flags & NOSLIP))
return
if(H.m_intent == "run")
if(IS_RUNNING(H))
H.AdjustStunned(6)
H.AdjustWeakened(6)
else

View File

@@ -42,13 +42,13 @@
to_chat(src, "<span class='notice'>We may move at our normal speed while hidden.</span>")
if(must_walk)
H.set_m_intent("walk")
H.set_move_intent(/decl/move_intent/walk)
var/remain_cloaked = TRUE
while(remain_cloaked) //This loop will keep going until the player uncloaks.
sleep(1 SECOND) // Sleep at the start so that if something invalidates a cloak, it will drop immediately after the check and not in one second.
if(H.m_intent != "walk" && must_walk) // Moving too fast uncloaks you.
if(!IS_WALKING(H) && must_walk) // Moving too fast uncloaks you.
remain_cloaked = 0
if(!H.mind.changeling.cloaked)
remain_cloaked = 0
@@ -66,8 +66,8 @@
H.invisibility = initial(invisibility)
visible_message("<span class='warning'>[src] suddenly fades in, seemingly from nowhere!</span>",
"<span class='notice'>We revert our camouflage, revealing ourselves.</span>")
H.set_m_intent("run")
H.set_move_intent(/decl/move_intent/run)
H.mind.changeling.cloaked = 0
H.mind.changeling.chem_recharge_rate = old_regen_rate
animate(src,alpha = 10, alpha = 255, time = 10)
animate(src,alpha = 10, alpha = 255, time = 10)

View File

@@ -98,7 +98,7 @@
if(iscarbon(AM))
var/mob/living/carbon/M = AM
if(M.m_intent != "walk")
if(!IS_WALKING(M))
flash()
/obj/machinery/flasher/portable/attackby(obj/item/W as obj, mob/user as mob)
@@ -110,7 +110,7 @@
user.show_message(text("<span class='warning'>[src] can now be moved.</span>"))
cut_overlays()
unsense_proximity(callback = /atom/proc/HasProximity)
else if(anchored)
user.show_message(text("<span class='warning'>[src] is now secured.</span>"))
add_overlay("[base_state]-s")
@@ -140,4 +140,4 @@
icon_state = "launcherbtt"
active = 0
return
return

View File

@@ -340,7 +340,7 @@
return
if((ishuman(H))) //i guess carp and shit shouldn't set them off
var/mob/living/carbon/M = H
if(M.m_intent == "run")
if(IS_RUNNING(M))
to_chat(M, "<span class='warning'>You step on the snap pop!</span>")
var/datum/effect_system/spark_spread/s = new /datum/effect_system/spark_spread

View File

@@ -273,19 +273,15 @@ var/global/last_chew = 0
lcuffs.loc = target
target.legcuffed = lcuffs
target.update_inv_legcuffed()
if(target.m_intent != "walk")
target.m_intent = "walk"
if(target.hud_used && target.hud_used.move_intent)
target.hud_used.move_intent.icon_state = "walking"
if(!IS_WALKING(target))
target.set_move_intent(/decl/move_intent/walk)
return 1
/obj/item/handcuffs/legcuffs/equipped(var/mob/living/user,var/slot)
. = ..()
if(slot == slot_legcuffed)
if(user.m_intent != "walk")
user.m_intent = "walk"
if(user.hud_used && user.hud_used.move_intent)
user.hud_used.move_intent.icon_state = "walking"
if(!IS_WALKING(user))
user.set_move_intent(/decl/move_intent/walk)
/obj/item/handcuffs/legcuffs/bola
@@ -324,8 +320,6 @@ var/global/last_chew = 0
lcuffs.loc = target
target.legcuffed = lcuffs
target.update_inv_legcuffed()
if(target.m_intent != "walk")
target.m_intent = "walk"
if(target.hud_used && target.hud_used.move_intent)
target.hud_used.move_intent.icon_state = "walking"
if(!IS_WALKING(target))
target.set_move_intent(/decl/move_intent/walk)
return 1

View File

@@ -124,7 +124,7 @@
return
if(deployed && isliving(AM))
var/mob/living/L = AM
if(L.m_intent == "run")
if(IS_RUNNING(L))
L.visible_message(
"<span class='danger'>[L] steps on \the [src].</span>",
"<span class='danger'>You step on \the [src]!</span>",
@@ -271,7 +271,7 @@
return
if(anchored && isliving(AM))
var/mob/living/L = AM
if(L.m_intent == "run")
if(IS_RUNNING(L))
L.visible_message(
"<span class='danger'>[L] steps in \the [src].</span>",
"<span class='danger'>You step in \the [src]!</span>",

View File

@@ -44,7 +44,7 @@
add_fingerprint(M)
if(ishuman(M))
var/mob/living/carbon/human/H = M
if(H.m_intent == "walk")
if(IS_WALKING(H))
to_chat(H, "<span class='warning'>You stop at the edge of \the [src.name].</span>")
return FALSE
else

View File

@@ -102,7 +102,7 @@
var/mob/living/carbon/human/H = M
if(istype(H) && istype(H.shoes, /obj/item/clothing/shoes))
var/obj/item/clothing/shoes/S = H.shoes
S.handle_movement(src,(H.m_intent == "run" ? 1 : 0))
S.handle_movement(src, IS_RUNNING(H))
if(S.track_blood && S.blood_DNA)
bloodDNA = S.blood_DNA
bloodcolor=S.blood_color
@@ -121,7 +121,7 @@
if(src.wet)
if(M.buckled || (src.wet == 1 && M.m_intent == "walk"))
if(M.buckled || (src.wet == 1 && IS_WALKING(M)))
return
var/slip_dist = 1

View File

@@ -85,7 +85,7 @@
if(armed)
if(ishuman(AM))
var/mob/living/carbon/H = AM
if(H.m_intent == "run")
if(IS_RUNNING(H))
triggered(H)
H.visible_message("<span class='warning'>[H] accidentally steps on [src].</span>", \
"<span class='warning'>You accidentally step on [src]</span>")
@@ -120,4 +120,4 @@
return
layer = HIDING_LAYER
to_chat(usr, "<span class='notice'>You hide [src].</span>")
to_chat(usr, "<span class='notice'>You hide [src].</span>")

View File

@@ -37,10 +37,10 @@
. = ..()
if(src.nutrition && src.stat != 2)
adjust_nutrition(-DEFAULT_HUNGER_FACTOR / 10)
if(src.m_intent == "run")
if(IS_RUNNING(src))
adjust_nutrition(-DEFAULT_HUNGER_FACTOR / 10)
if((FAT in src.mutations) && src.m_intent == "run" && src.bodytemperature <= 360)
if((FAT in src.mutations) && IS_RUNNING(src) && src.bodytemperature <= 360)
src.bodytemperature += 2
// Moving around increases germ_level faster

View File

@@ -67,7 +67,7 @@
..()
if(statpanel("Status"))
stat("Intent:", "[a_intent]")
stat("Move Mode:", "[m_intent]")
stat("Move Mode:", "[move_intent.name]")
if(emergency_shuttle)
var/eta_status = emergency_shuttle.get_status_panel_eta()
if(eta_status)

View File

@@ -235,17 +235,17 @@
if(!S) return
// Play every 20 steps while walking, for the sneak
if(m_intent == "walk" && step_count++ % 20 != 0)
if(IS_WALKING(src) && step_count++ % 20 != 0)
return
// Play every other step while running
if(m_intent == "run" && step_count++ % 2 != 0)
if(IS_RUNNING(src) && step_count++ % 2 != 0)
return
var/volume = config.footstep_volume
// Reduce volume while walking or barefoot
if(!shoes || m_intent == "walk")
if(!shoes || IS_WALKING(src))
volume *= 0.5
else if(shoes)
var/obj/item/clothing/shoes/feet = shoes

View File

@@ -16,7 +16,7 @@
/mob/living/SelfMove(turf/n, direct, movetime)
// If on walk intent, don't willingly step into hazardous tiles.
// Unless the walker is confused.
if(m_intent == "walk" && confused <= 0)
if(IS_WALKING(src) && confused <= 0)
if(!n.is_safe_to_enter(src))
to_chat(src, span("warning", "\The [n] is dangerous to move into."))
return FALSE // In case any code wants to know if movement happened.
@@ -127,7 +127,7 @@ default behaviour is:
now_pushing = 0
. = ..()
if (!istype(AM, /atom/movable) || AM.anchored)
if(confused && prob(50) && m_intent=="run")
if(confused && prob(50) && IS_RUNNING(src))
Weaken(2)
playsound(src, "punch", 25, 1, -1)
visible_message("<span class='warning'>[src] [pick("ran", "slammed")] into \the [AM]!</span>")

View File

@@ -124,7 +124,7 @@
using = new /obj/screen()
using.name = "mov_intent"
using.icon = ui_style
using.icon_state = (m_intent == "run" ? "running" : "walking")
using.icon_state = move_intent.hud_icon_state
using.screen_loc = ui_movi
using.color = ui_color
using.alpha = ui_alpha

View File

@@ -244,7 +244,7 @@
. = 1
. *= purge
if(m_intent == "walk")
if(IS_WALKING(src))
. *= 1.5
. += config.animal_delay

View File

@@ -34,6 +34,7 @@
zone_sel = null
/mob/Initialize()
move_intent = GET_DECL(/decl/move_intent/run) // Sets the initial move_intent.
mob_list += src
if(stat == DEAD)
dead_mob_list += src

View File

@@ -112,8 +112,13 @@
var/intent = null//Living
var/shakecamera = 0
var/a_intent = I_HELP//Living
var/m_int = null//Living
var/m_intent = "run"//Living
var/decl/move_intent/move_intent = null // Living.
var/list/move_intents = list(
/decl/move_intent/run,
/decl/move_intent/walk
)
var/lastKnownIP = null
var/obj/buckled = null//Living

View File

@@ -12,13 +12,9 @@
. += 5
// Movespeed delay based on movement mode
switch(m_intent)
if("run")
if(drowsyness > 0)
. += 6
. += config.run_speed
if("walk")
. += config.walk_speed
if(IS_RUNNING(src) && drowsyness > 0)
. += 6
. += move_intent.move_delay
/client/proc/client_dir(input, direction=-1)
return turn(input, direction*dir2angle(dir))
@@ -260,13 +256,10 @@
return // No hands to drive your chair? Tough luck!
//drunk wheelchair driving
else if(my_mob.confused)
switch(my_mob.m_intent)
if("run")
if(prob(50))
direct = turn(direct, pick(90, -90))
if("walk")
if(prob(25))
direct = turn(direct, pick(90, -90))
if(IS_RUNNING(my_mob) && prob(50))
direct = turn(direct, pick(90, -90))
else if(IS_WALKING(my_mob) && prob(25))
direct = turn(direct, pick(90, -90))
total_delay += 3
// We are now going to move
@@ -275,15 +268,12 @@
// Confused direction randomization
if(my_mob.confused)
switch(my_mob.m_intent)
if("run")
if(prob(75))
direct = turn(direct, pick(90, -90))
n = get_step(my_mob, direct)
if("walk")
if(prob(25))
direct = turn(direct, pick(90, -90))
n = get_step(my_mob, direct)
if(IS_RUNNING(my_mob) && prob(75))
direct = turn(direct, pick(90, -90))
n = get_step(my_mob, direct)
else if(IS_WALKING(my_mob) && prob(25))
direct = turn(direct, pick(90, -90))
n = get_step(my_mob, direct)
total_delay = DS2NEARESTTICK(total_delay) //Rounded to the next tick in equivalent ds
my_mob.setMoveCooldown(total_delay)

View File

@@ -16,8 +16,8 @@
if (. >= 2)
if(prob(1))
owner.custom_pain("Your abdomen feels like it's tearing itself apart!",1)
owner.m_intent = "walk"
owner.hud_used.move_intent.icon_state = "walking"
if(!IS_WALKING(owner))
owner.set_move_intent(/decl/move_intent/walk)
/obj/item/organ/internal/intestine/xeno
color = "#555555"

View File

@@ -38,8 +38,8 @@
if (. >= 2)
if(prob(1))
owner.custom_pain("You feel extremely tired, like you can't move!",1)
owner.m_intent = "walk"
owner.hud_used.move_intent.icon_state = "walking"
if(!IS_WALKING(owner))
owner.set_move_intent(/decl/move_intent/walk)
/obj/item/organ/internal/kidneys/grey
icon_state = "kidneys_grey"

View File

@@ -57,10 +57,14 @@
if(aimed.len)
trigger_aiming(TARGET_CAN_MOVE)
/mob/living/proc/set_m_intent(var/intent)
if (intent != "walk" && intent != "run")
return 0
m_intent = intent
if(hud_used)
if (hud_used.move_intent)
hud_used.move_intent.icon_state = intent == "walk" ? "walking" : "running"
/mob/living/proc/set_move_intent(decl/move_intent/intent)
if(move_intent.type == intent)
return
var/new_intent = GET_DECL(intent)
if(isnull(new_intent))
return
move_intent = new_intent
if(hud_used?.move_intent)
hud_used.move_intent.icon_state = move_intent.hud_icon_state

View File

@@ -56,6 +56,7 @@
#include "code\__defines\MC.dm"
#include "code\__defines\misc.dm"
#include "code\__defines\mobs.dm"
#include "code\__defines\movement.dm"
#include "code\__defines\objects.dm"
#include "code\__defines\overmap.dm"
#include "code\__defines\pda.dm"
@@ -280,6 +281,7 @@
#include "code\datums\mind.dm"
#include "code\datums\mixed.dm"
#include "code\datums\modules.dm"
#include "code\datums\move_intent.dm"
#include "code\datums\mutable_appearance.dm"
#include "code\datums\orbit.dm"
#include "code\datums\organs.dm"