Skip to content

Commit

Permalink
Slight tweaks to flockdrone AI to prioritise building material deposi…
Browse files Browse the repository at this point in the history
…ts and conversion of walls/doors/closets (stonepillars/goon-flock#24)

* Slight tweaks to AI to prioritise building and conversion of walls/doors/closets

* review code cleanup
  • Loading branch information
amylizzle authored Mar 13, 2022
1 parent e3a66f9 commit b2c8e29
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 7 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 @@ -14,7 +14,7 @@
..()
// populate the list of tasks
transition_tasks += holder.get_instance(/datum/aiTask/sequence/goalbased/replicate, list(holder, src))
transition_tasks += holder.get_instance(/datum/aiTask/sequence/goalbased/build, list(holder, src))
transition_tasks += holder.get_instance(/datum/aiTask/sequence/goalbased/build/drone, list(holder, src))
transition_tasks += holder.get_instance(/datum/aiTask/sequence/goalbased/repair, list(holder, src))
transition_tasks += holder.get_instance(/datum/aiTask/sequence/goalbased/deposit, list(holder, src))
transition_tasks += holder.get_instance(/datum/aiTask/sequence/goalbased/open_container, list(holder, src))
Expand Down
107 changes: 101 additions & 6 deletions code/mob/living/critter/ai/flock/flocktasks.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
// base shared flock AI stuff
// main default "what do we do next" task, run for one tick and then switches to a new task
/datum/aiHolder/flock
//task priorities and preconditions at a glance:
/*
replicate
-weight 6
-precondition: can_afford(100)
building
-weight 5
-precondition: can_afford(20)
building-drone
-weight 1
-precondition: can_afford(20)
repair
-weight 4
-precondition: can_afford(10)
deposit
-weight 7
-procondition: can_afford(10)
open_container
-weight 3
-precondition: none
rumage
-weight 3
precondition: none
harvest
-weight 2
precondition: none
shooting
-weight 10
capture
-weight 15
-precondition: can_afford(15)
butcher
-weight 3
*/

/datum/aiTask/prioritizer/flock
name = "base thinking (should never see this)"
Expand Down Expand Up @@ -127,14 +171,11 @@
// if there's a priority tile we can go for, do it
var/list/priority_turfs = F.flock.getPriorityTurfs(F)
if(length(priority_turfs))
for(var/turf/simulated/PT in priority_turfs)
// if we can get a valid path to the target, include it for consideration
. += PT
. += priority_turfs

// else just go for one nearby
for(var/turf/simulated/T in view(max_dist, holder.owner))
if(istype(T, /turf/simulated/floor) && !istype(T, /turf/simulated/floor/feather) || \
istype(T, /turf/simulated/wall) && !istype(T, /turf/simulated/wall/auto/feather))
if(!isfeathertile(T))
if(F?.flock && !F.flock.isTurfFree(T, F.real_name))
continue // this tile's been claimed by someone else
// if we can get a valid path to the target, include it for consideration
Expand Down Expand Up @@ -176,6 +217,60 @@
if(F?.flock && !failed() && !succeeded())
F.flock.reserveTurf(holder.target, F.real_name)

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// BUILDING GOAL - FLOCKDRONE ONLY
// targets: priority tiles, fetched from holder.owner.flock (with casting)
// or, if they're not available, storage closets, walls and doors
// failing that, nearest tiles
// precondition: 20 resources
/datum/aiTask/sequence/goalbased/build/drone
name = "building"
weight = 1
max_dist = 4 //max dist is higher so we can find walls in bigger rooms

/datum/aiTask/sequence/goalbased/build/drone/precondition()
var/mob/living/critter/flock/F = holder.owner
return F?.can_afford(20)


/datum/aiTask/sequence/goalbased/build/drone/get_targets()
. = list()
var/mob/living/critter/flock/F = holder.owner

if(F?.flock)
// if we can go for a tile we already have reserved, go for it
var/turf/simulated/reserved = F.flock.busy_tiles[F.real_name]
if(istype(reserved) && !isfeathertile(reserved) && get_path_to(holder.owner, reserved, 20, 1))
. += reserved
return
// if there's a priority tile we can go for, do it
var/list/priority_turfs = F.flock.getPriorityTurfs(F)
if(length(priority_turfs))
. += priority_turfs

//as drone, we want to prioritise converting doors and walls and containers
for(var/turf/simulated/T in view(max_dist, holder.owner))
if(!isfeathertile(T) && (
istype(T, /turf/simulated/wall) || \
locate(/obj/machinery/door/airlock) in T || \
locate(/obj/storage) in T))
if(F?.flock && !F.flock.isTurfFree(T, F.real_name))
continue // this tile's been claimed by someone else
// if we can get a valid path to the target, include it for consideration
. += T

// if there are absolutely no walls/doors/closets in view, and no reserved tiles, then fine, you can have a floor tile
if(length(.) == 0)
for(var/turf/simulated/T in view(max_dist, holder.owner))
if(!isfeathertile(T))
if(F?.flock && !F.flock.isTurfFree(T, F.real_name))
continue // this tile's been claimed by someone else
// if we can get a valid path to the target, include it for consideration
. += T
. = get_path_to(holder.owner, ., 60, 1)

////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// REPAIR GOAL
// targets: other flockdrones in the same flock
Expand Down Expand Up @@ -248,7 +343,7 @@
// precondition: 10 resources
/datum/aiTask/sequence/goalbased/deposit
name = "depositing"
weight = 4
weight = 7

/datum/aiTask/sequence/goalbased/deposit/New(parentHolder, transTask)
..(parentHolder, transTask)
Expand Down

0 comments on commit b2c8e29

Please sign in to comment.