behavior3行为树
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

  1. -ifndef(behavior3_h).
  2. -define(behavior3_h, true).
  3. -export_type([bt_uid/0, bt_status/0, bt_node_id/0, bt_state/0, properties/0, uninit_bt_node/0, tree_nodes/0, btree/0, bt_node/0]).
  4. -type bt_uid() :: reference().
  5. -define(BT_SUCCESS, 1).
  6. -define(BT_FAILURE, 2).
  7. -define(BT_RUNNING, 3).
  8. -define(BT_ERROR, 4).
  9. -type bt_status() :: ?BT_SUCCESS|?BT_FAILURE|?BT_RUNNING|?BT_ERROR.
  10. -type bt_node_id() :: string().
  11. -type bt_state() :: #{
  12. '$global_maps' => map(),
  13. '$local_maps' => map(),
  14. term() => term()
  15. }.
  16. -type properties() :: #{atom() => term()}.
  17. %% 未初始化的树节点
  18. -type uninit_bt_node() :: #{
  19. id => bt_node_id(),
  20. name => atom() | bt_node_id(),
  21. category => atom(),
  22. properties => properties(),
  23. children => [bt_node_id()]
  24. }.
  25. -type tree_nodes() :: #{bt_node_id() => uninit_bt_node()}.
  26. %% 行为树
  27. -type btree() :: #{
  28. id => bt_node_id(),
  29. root => bt_node_id(),
  30. properties => properties(),
  31. tree_nodes => tree_nodes()
  32. }.
  33. %% 行为树节点
  34. -type bt_node() :: #{
  35. id := bt_uid(),
  36. bt_node_id := bt_node_id(),
  37. parent_id := bt_uid(),
  38. name := atom(),
  39. category := atom(),
  40. properties := properties(),
  41. children := [bt_uid()]
  42. }.
  43. -define(BI_MOD_LIST, [
  44. error, failer, runner, succeeder, wait,
  45. mem_priority, mem_sequence, priority, sequence,
  46. inverter, limiter, max_time, repeat_until_failure, repeat_until_success, repeater
  47. ]).
  48. -define(BT_LOG(Format), io:format("~w:~w:~w [debug] ~p: " ++ Format ++ "~n", tuple_to_list(time()) ++ [?MODULE])).
  49. -define(BT_LOG(Format, Args), io:format("~w:~w:~w [debug] ~p: " ++ Format ++ "~n", tuple_to_list(time()) ++ [?MODULE | Args])).
  50. -endif.