Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Better wandering (#283)
Browse files Browse the repository at this point in the history
* way better wandering behaviour, plus fix janky old wander code

* tmpturf->T
  • Loading branch information
amylizzle authored May 11, 2022
1 parent 3968982 commit ac0fac9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion code/mob/living/critter/ai/flock/flockdrone.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
transition_tasks += holder.get_instance(/datum/aiTask/sequence/goalbased/flockdrone_capture, list(holder, src))
transition_tasks += holder.get_instance(/datum/aiTask/sequence/goalbased/deconstruct, list(holder, src))
transition_tasks += holder.get_instance(/datum/aiTask/sequence/goalbased/stare, list(holder, src))
transition_tasks += holder.get_instance(/datum/aiTask/timed/wander, list(holder, src))
transition_tasks += holder.get_instance(/datum/aiTask/timed/wander/flock, list(holder, src))

/datum/aiTask/prioritizer/flock/drone/on_reset()
..()
Expand Down
35 changes: 35 additions & 0 deletions code/mob/living/critter/ai/flock/flocktasks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1210,3 +1210,38 @@ butcher
on_reset()
..()
holder.target = src.target

///////////////////////////////////////////////////////////////////////////////////////////////////
/// Wander override for better wandering
/datum/aiTask/timed/wander/flock
minimum_task_ticks = 5
maximum_task_ticks = 7 //you go a lot further with this wandering, so shorten the task time
var/turf/startpos
var/turf/targetpos
var/path

/datum/aiTask/timed/wander/flock/on_tick()
if(!startpos)
startpos = get_turf(holder.owner)
if(targetpos && GET_DIST(holder.owner,targetpos) > 0) //if we have a target and we're not already there
if(!path || !length(path))
path = get_path_to(holder.owner, targetpos, 5, 1) //short search, we don't want this to be expensive
if(length(path))
holder.move_to_with_path(targetpos, path, 0)
return

//pick a random tile that is not space, and not closer to startpos than we are now
var/list/turfs = list()
path = null
targetpos = null
for(var/turf/T in range(holder.owner,2))
if(!istype(T,/turf/space) && !is_blocked_turf(T) && GET_DIST(holder.owner,startpos) <= GET_DIST(T,startpos))
turfs += T
if(!length(turfs))
//oh shit we must be in space, better wander in the direction of the station
turfs += pick_landmark(LANDMARK_LATEJOIN)
if(length(turfs))
targetpos = pick(turfs)
else
//well I guess the station is gone and everyone is dead. Back to default wander behaviour
..()
3 changes: 0 additions & 3 deletions code/mob/living/critter/ai/shared.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@
// thanks byond forums for letting me know that the byond native implentation FUCKING SUCKS
holder.owner.move_dir = pick(alldirs)
holder.owner.process_move()

/datum/aiTask/timed/wander/on_tick()
. = ..()
holder.stop_move()
holder.owner.move_dir = null // clear out direction so it doesn't get latched when client is attached

Expand Down

0 comments on commit ac0fac9

Please sign in to comment.