mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 18:53:06 +00:00
Replaced the critter AI recursion with a proper loop, this seems to have fixed profiling.
This commit is contained in:
@@ -8,81 +8,83 @@
|
|||||||
process()
|
process()
|
||||||
set background = 1
|
set background = 1
|
||||||
if (!src.alive) return
|
if (!src.alive) return
|
||||||
switch(task)
|
|
||||||
if("thinking")
|
// use a loop to avoid weird benchmarking phenomenons caused by
|
||||||
src.attack = 0
|
// recursion
|
||||||
src.target = null
|
while(1)
|
||||||
sleep(thinkspeed)
|
switch(task)
|
||||||
walk_to(src,0)
|
if("thinking")
|
||||||
if (src.aggressive) seek_target()
|
src.attack = 0
|
||||||
if (src.wanderer && !src.target) src.task = "wandering"
|
|
||||||
if("chasing")
|
|
||||||
if (src.frustration >= max_frustration)
|
|
||||||
src.target = null
|
src.target = null
|
||||||
src.last_found = world.time
|
sleep(thinkspeed)
|
||||||
src.frustration = 0
|
|
||||||
src.task = "thinking"
|
|
||||||
walk_to(src,0)
|
walk_to(src,0)
|
||||||
if (target)
|
if (src.aggressive) seek_target()
|
||||||
if (get_dist(src, src.target) <= 1)
|
if (src.wanderer && !src.target) src.task = "wandering"
|
||||||
var/mob/living/carbon/M = src.target
|
if("chasing")
|
||||||
ChaseAttack()
|
if (src.frustration >= max_frustration)
|
||||||
src.task = "attacking"
|
src.target = null
|
||||||
if(chasestate)
|
src.last_found = world.time
|
||||||
icon_state = chasestate
|
src.frustration = 0
|
||||||
src.anchored = 1
|
src.task = "thinking"
|
||||||
src.target_lastloc = M.loc
|
walk_to(src,0)
|
||||||
else
|
if (target)
|
||||||
var/turf/olddist = get_dist(src, src.target)
|
if (get_dist(src, src.target) <= 1)
|
||||||
walk_to(src, src.target,1,chasespeed)
|
var/mob/living/carbon/M = src.target
|
||||||
if ((get_dist(src, src.target)) >= (olddist))
|
ChaseAttack()
|
||||||
src.frustration++
|
src.task = "attacking"
|
||||||
|
if(chasestate)
|
||||||
|
icon_state = chasestate
|
||||||
|
src.anchored = 1
|
||||||
|
src.target_lastloc = M.loc
|
||||||
else
|
else
|
||||||
src.frustration = 0
|
var/turf/olddist = get_dist(src, src.target)
|
||||||
sleep(5)
|
walk_to(src, src.target,1,chasespeed)
|
||||||
else src.task = "thinking"
|
if ((get_dist(src, src.target)) >= (olddist))
|
||||||
if("attacking")
|
src.frustration++
|
||||||
// see if he got away
|
else
|
||||||
if ((get_dist(src, src.target) > 1) || ((src.target:loc != src.target_lastloc)))
|
src.frustration = 0
|
||||||
src.anchored = 0
|
sleep(5)
|
||||||
src.task = "chasing"
|
else src.task = "thinking"
|
||||||
if(chasestate)
|
if("attacking")
|
||||||
icon_state = chasestate
|
// see if he got away
|
||||||
else
|
if ((get_dist(src, src.target) > 1) || ((src.target:loc != src.target_lastloc)))
|
||||||
if (get_dist(src, src.target) <= 1)
|
|
||||||
var/mob/living/carbon/M = src.target
|
|
||||||
if(!src.attacking) RunAttack()
|
|
||||||
if(!src.aggressive)
|
|
||||||
src.task = "thinking"
|
|
||||||
src.target = null
|
|
||||||
src.anchored = 0
|
|
||||||
src.last_found = world.time
|
|
||||||
src.frustration = 0
|
|
||||||
src.attacking = 0
|
|
||||||
else
|
|
||||||
if(M!=null)
|
|
||||||
if(ismob(src.target))
|
|
||||||
if(M.health < config.health_threshold_crit)
|
|
||||||
src.task = "thinking"
|
|
||||||
src.target = null
|
|
||||||
src.anchored = 0
|
|
||||||
src.last_found = world.time
|
|
||||||
src.frustration = 0
|
|
||||||
src.attacking = 0
|
|
||||||
else
|
|
||||||
src.anchored = 0
|
src.anchored = 0
|
||||||
src.attacking = 0
|
|
||||||
src.task = "chasing"
|
src.task = "chasing"
|
||||||
if(chasestate)
|
if(chasestate)
|
||||||
icon_state = chasestate
|
icon_state = chasestate
|
||||||
if("wandering")
|
else
|
||||||
if(chasestate)
|
if (get_dist(src, src.target) <= 1)
|
||||||
icon_state = initial(icon_state)
|
var/mob/living/carbon/M = src.target
|
||||||
patrol_step()
|
if(!src.attacking) RunAttack()
|
||||||
sleep(wanderspeed)
|
if(!src.aggressive)
|
||||||
spawn(8)
|
src.task = "thinking"
|
||||||
process()
|
src.target = null
|
||||||
return
|
src.anchored = 0
|
||||||
|
src.last_found = world.time
|
||||||
|
src.frustration = 0
|
||||||
|
src.attacking = 0
|
||||||
|
else
|
||||||
|
if(M!=null)
|
||||||
|
if(ismob(src.target))
|
||||||
|
if(M.health < config.health_threshold_crit)
|
||||||
|
src.task = "thinking"
|
||||||
|
src.target = null
|
||||||
|
src.anchored = 0
|
||||||
|
src.last_found = world.time
|
||||||
|
src.frustration = 0
|
||||||
|
src.attacking = 0
|
||||||
|
else
|
||||||
|
src.anchored = 0
|
||||||
|
src.attacking = 0
|
||||||
|
src.task = "chasing"
|
||||||
|
if(chasestate)
|
||||||
|
icon_state = chasestate
|
||||||
|
if("wandering")
|
||||||
|
if(chasestate)
|
||||||
|
icon_state = initial(icon_state)
|
||||||
|
patrol_step()
|
||||||
|
sleep(wanderspeed)
|
||||||
|
sleep(8)
|
||||||
|
|
||||||
|
|
||||||
patrol_step()
|
patrol_step()
|
||||||
@@ -115,7 +117,7 @@
|
|||||||
|
|
||||||
seek_target()
|
seek_target()
|
||||||
if(!prob(aggression)) return // make them attack depending on aggression levels
|
if(!prob(aggression)) return // make them attack depending on aggression levels
|
||||||
|
|
||||||
src.anchored = 0
|
src.anchored = 0
|
||||||
var/T = null
|
var/T = null
|
||||||
for(var/mob/living/C in view(src.seekrange,src))//TODO: mess with this
|
for(var/mob/living/C in view(src.seekrange,src))//TODO: mess with this
|
||||||
|
|||||||
Reference in New Issue
Block a user