Enforcing no sleep during mob/Life().

This commit is contained in:
MistakeNot4892
2022-10-24 16:51:32 +11:00
parent 4e1845e099
commit 44160ab8ba
8 changed files with 124 additions and 85 deletions
+51 -32
View File
@@ -37,6 +37,7 @@
var/max_target_dist = 50 // How far we are willing to go
var/max_patrol_dist = 250
var/started_moving_along_path = 0
var/target_patience = 5
var/frustration = 0
var/max_frustration = 0
@@ -70,8 +71,7 @@
SetParalysis(0)
if(on && !client && !busy)
spawn(0)
handleAI()
handleAI()
/mob/living/bot/updatehealth()
if(status_flags & GODMODE)
@@ -158,6 +158,38 @@
/mob/living/bot/emag_act(var/remaining_charges, var/mob/user)
return 0
// Some boilerplate here and below, but this is a quickfix to stop Ater nuking the mob type, so heigh ho.
/mob/living/bot/proc/stepTowardsTarget(var/delay, var/panic_speed_mod)
set waitfor = FALSE
var/started_moving_at = world.time
started_moving_along_path = started_moving_at
if(!wait_if_pulled || !pulledby)
for(var/i = 1 to (target_speed + panic_speed_mod))
sleep(delay)
if(started_moving_along_path != started_moving_at)
return // We have started another move iteration.
stepToTarget() // Calls A*, very expensive; is not necessarily safe. In a perfect world this would
if(TICK_CHECK) // not be behind a set waitfor = FALSE, but we do not live in a perfect world and
break // SSmobs fires too slowly for chases to work using A* without sleeping.
if(started_moving_along_path != started_moving_at)
return // We have started another move iteration.
if(max_frustration && frustration > max_frustration * target_speed)
handleFrustrated(1)
/mob/living/bot/proc/stepAlongPatrol(var/delay, var/panic_speed_mod)
set waitfor = FALSE
var/started_moving_at = world.time
started_moving_along_path = started_moving_at
for(var/i = 1 to (patrol_speed + panic_speed_mod))
sleep(delay)
if(started_moving_along_path != started_moving_at)
return // We have started another move iteration.
handlePatrol() // Does not call A*; is more or less safe.
if(started_moving_along_path != started_moving_at)
return // We have started another move iteration.
if(max_frustration && frustration > max_frustration * patrol_speed)
handleFrustrated(0)
/mob/living/bot/proc/handleAI()
if(ignore_list.len)
for(var/atom/A in ignore_list)
@@ -165,41 +197,28 @@
ignore_list -= A
handleRegular()
var/panic_speed_mod = 0
if(panic_on_alert)
panic_speed_mod = handlePanic()
if(target && confirmTarget(target))
if(Adjacent(target))
handleAdjacentTarget()
else
handleRangedTarget()
if(!wait_if_pulled || !pulledby)
for(var/i = 1 to (target_speed + panic_speed_mod))
sleep(20 / (target_speed + panic_speed_mod + 1))
stepToTarget()
if(max_frustration && frustration > max_frustration * target_speed)
handleFrustrated(1)
else
resetTarget()
lookForTargets()
if(will_patrol && !pulledby && !target)
if(patrol_path && patrol_path.len)
for(var/i = 1 to (patrol_speed + panic_speed_mod))
sleep(20 / (patrol_speed + 1))
handlePatrol()
if(max_frustration && frustration > max_frustration * patrol_speed)
handleFrustrated(0)
else
startPatrol()
else
if((locate(/obj/machinery/door) in loc) && !pulledby) //Don't hang around blocking doors, but don't run off if someone tries to pull us through one.
var/turf/my_turf = get_turf(src)
var/list/can_go = my_turf.CardinalTurfsWithAccess(botcard)
if(LAZYLEN(can_go))
if(step_towards(src, pick(can_go)))
return
var/panic_speed_mod = panic_on_alert ? handlePanic() : 0
stepTowardsTarget(round(20 / (target_speed + panic_speed_mod + 1)), panic_speed_mod)
return
resetTarget()
lookForTargets()
if(will_patrol && !pulledby && !target)
if(patrol_path && patrol_path.len)
stepAlongPatrol(round(20 / (patrol_speed + 1)), (panic_on_alert ? handlePanic() : 0))
return
startPatrol()
return
if((locate(/obj/machinery/door) in loc) && !pulledby) //Don't hang around blocking doors, but don't run off if someone tries to pull us through one.
var/turf/my_turf = get_turf(src)
var/list/can_go = my_turf.CardinalTurfsWithAccess(botcard)
if(!LAZYLEN(can_go) || !step_towards(src, pick(can_go)))
handleIdle()
/mob/living/bot/proc/handleRegular()
@@ -142,7 +142,6 @@
/mob/living/simple_mob/proc/handle_guts()
for(var/obj/item/organ/OR in internal_organs)
OR.process()
for(var/obj/item/organ/OR in organs)
OR.process()
@@ -114,6 +114,52 @@
icon_dead = "ian_dead"
var/turns_since_scan = 0
var/obj/movement_target
var/moving_to_lunch = FALSE
/mob/living/simple_mob/animal/passive/dog/corgi/Ian/proc/move_to_lunch()
set waitfor = FALSE
if(!movement_target || moving_to_lunch)
return
moving_to_lunch = TRUE
step_to(src,movement_target,1)
sleep(3)
if(QDELETED(src) || !movement_target || incapacitated())
moving_to_lunch = FALSE
return
step_to(src,movement_target,1)
sleep(3)
if(QDELETED(src) || !movement_target || incapacitated())
moving_to_lunch = FALSE
return
step_to(src,movement_target,1)
if(QDELETED(src) || !movement_target || incapacitated())
moving_to_lunch = FALSE
return
moving_to_lunch = FALSE
if(movement_target) //Not redundant due to sleeps, Item can be gone in 6 decisecomds
if (movement_target.loc.x < src.x)
set_dir(WEST)
else if (movement_target.loc.x > src.x)
set_dir(EAST)
else if (movement_target.loc.y < src.y)
set_dir(SOUTH)
else if (movement_target.loc.y > src.y)
set_dir(NORTH)
else
set_dir(SOUTH)
if(isturf(movement_target.loc) )
UnarmedAttack(movement_target)
else if(ishuman(movement_target.loc) && prob(20))
visible_emote("stares at the [movement_target] that [movement_target.loc] has with sad puppy eyes.")
/mob/living/simple_mob/animal/passive/dog/corgi/Ian/proc/dance()
set waitfor = FALSE
visible_emote(pick("dances around","chases their tail"))
for(var/i in list(1,2,4,8,4,2,1,2,4,8,4,2,1,2,4,8,4,2))
set_dir(i)
sleep(1)
/mob/living/simple_mob/animal/passive/dog/corgi/Ian/Life()
..()
@@ -134,35 +180,10 @@
movement_target = S
break
if(movement_target)
step_to(src,movement_target,1)
sleep(3)
step_to(src,movement_target,1)
sleep(3)
step_to(src,movement_target,1)
if(movement_target) //Not redundant due to sleeps, Item can be gone in 6 decisecomds
if (movement_target.loc.x < src.x)
set_dir(WEST)
else if (movement_target.loc.x > src.x)
set_dir(EAST)
else if (movement_target.loc.y < src.y)
set_dir(SOUTH)
else if (movement_target.loc.y > src.y)
set_dir(NORTH)
else
set_dir(SOUTH)
if(isturf(movement_target.loc) )
UnarmedAttack(movement_target)
else if(ishuman(movement_target.loc) && prob(20))
visible_emote("stares at the [movement_target] that [movement_target.loc] has with sad puppy eyes.")
move_to_lunch()
if(prob(1))
visible_emote(pick("dances around","chases their tail"))
spawn(0)
for(var/i in list(1,2,4,8,4,2,1,2,4,8,4,2,1,2,4,8,4,2))
set_dir(i)
sleep(1)
dance()
//LISA! SQUEEEEEEEEE~
/mob/living/simple_mob/animal/passive/dog/corgi/Lisa
+1 -2
View File
@@ -142,8 +142,7 @@
return 0
/mob/proc/Life()
// if(organStructure)
// organStructure.ProcessOrgans()
SHOULD_NOT_SLEEP(TRUE)
return
#define UNBUCKLED 0