ae1697333453e441ac38ed7d32445556f44b72cc — Phil Hagelberg 1 year, 3 months ago f8e3f3d
Fix issue with team AI selecting new targets.
1 files changed, 9 insertions(+), 6 deletions(-)

M ai.fnl
M ai.fnl => ai.fnl +9 -6
@@ 27,9 27,9 @@

(fn choose-poi-in-zone [zone state limit]
  (assert (< 0 (or limit 1)) "couldn't find target!")
  (assert (< 0 (or limit 1)) "couldn't find target but that's ok")
  (let [target (choose-poi state)]
    (if (in-zone? target zone)
    (if (and target (in-zone? target zone))
        (choose-poi-in-zone zone state (if limit (- limit 1) 128)))))

@@ 71,6 71,7 @@
      (dbg char.name :claimed target.id)
      (set target.properties.claimed? true))
    (when (and old-target old-target.properties)
      (dbg char.name :unclaimed old-target.id)
      (set old-target.properties.claimed? false))
    {:name :walk-to
     :path path

@@ 233,13 234,15 @@

(fn run [dt state char]
  "We shouldn't let bugs in the AI crash the whole game."
  (let [ok? (xpcall #(run-ai dt state char)
                    #(when (not (: $ :match "that's ok"))
                       (dbg $ (debug.traceback))))]
  (let [(ok? msg) (xpcall #(run-ai dt state char)
                          #(when (not (: $ :match "that's ok"))
                             (dbg $ (debug.traceback))))]
    (when (not ok?)
      (dbg "AI error" char.name)
      (dbg "AI error" char.name msg)
      (if char.team?
          (set char.ai.task nil)
          (lume.remove state.characters char)))))

{: make : run : set-follow}