/
always_failure.cljc
26 lines (24 loc) · 1.07 KB
/
always_failure.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(ns cark.behavior-tree.node-defs.always-failure
"The :always-failure node has no specific parameter.
It ticks its child and responds to the result in this way :
- Child is :running -> always-failure is :running
- Child is :success -> always-failure is :failure
- Child is :failure -> alway-failure is :failure"
(:require [cark.behavior-tree.context :as ctx]
[cark.behavior-tree.db :as db]
[cark.behavior-tree.tree :as tree]
[cark.behavior-tree.type :as type]
[cark.behavior-tree.base-nodes :as bn]))
(defn compile-node [tree id tag params [child-id]]
[(fn always-failure-tick [ctx arg]
(let [ctx (ctx/tick ctx child-id)]
(case (db/get-node-status ctx child-id)
(:success :failure) (-> (ctx/set-node-status ctx child-id :fresh)
(db/set-node-status id :failure))
:running (db/set-node-status ctx id :running))))
tree])
(defn register []
(type/register
(bn/decorator
{::type/tag :always-failure
::type/compile-func compile-node})))