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

@@ -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)