Tramway SDK
ai.h
Go to the documentation of this file.
1// TRAMWAY DRIFT AND DUNGEON EXPLORATION SIMULATOR 2022
2// All rights reserved.
3
4#ifndef TRAM_SDK_EXTENSIONS_KITCHENSINK_AI_H
5#define TRAM_SDK_EXTENSIONS_KITCHENSINK_AI_H
6
7#include <vector>
8#include <framework/core.h>
9#include <framework/uid.h>
10#include <framework/math.h>
11#include <framework/value.h>
12
13namespace tram {
14 class ControllerComponent;
15}
16
17namespace tram::Ext::Kitchensink {
18 class AnimationStateComponent;
19 /*
20
21 if normal:
22
23 if time is morning:
24 return go_eat()
25 if time is day:
26 return go_stand(at_workplace)
27 if time is evening:
28 return go_eat()
29 if time is night:
30 return go_sleep(home)
31
32 if combat:
33
34 if health > 10:
35 return attack
36 if true:
37 return retreat
38
39 inside_params ->
40 attacker
41 attacker_faction
42
43 if normal and attack and victim_faction is self_faction:
44 combat_target =
45 attack
46
47 AIAgent:
48 list<pair<AICondition, AIPackage>> package_queue;
49 name class;
50 package_script
51 list<Value> variables
52 AIClass:
53 name parent_class;
54 package_script;
55 default_variables;
56
57 AIPackage:
58 state = running/finished
59 forced = true/false
60
61 SetAIPackage(AI_ATTACK, [("target", big_chungus)])
62
63 AI_ATTACK
64 AI_SLEEP
65 AI_EAT
66
67
68AI_ATTACK ->
69
70 */
71
72class AIAgent;
73class AIPackage;
74typedef AIPackage* (*ai_package_constr)(valuearray_t);
75
76void InitAI();
77void UpdateAI();
78
79class AIPackage {
80public:
81 virtual bool Process() = 0;
82
83 virtual ~AIPackage() = default;
84
85 static void Register(name_t name, ai_package_constr constr);
86 static AIPackage* Make(name_t name, valuearray_t params);
87protected:
88 AIAgent* parent = nullptr;
89};
90
91struct AIVariable {
93};
94
95class AIAgent {
96public:
97 std::vector<AIPackage*> package_stack;
98 std::vector<AIPackage*> override_stack;
99
101
102 std::vector<AIVariable> variables;
103
105 void Clear();
106
109
110 void Update();
111
112 void SetControllerComponent(ControllerComponent* c) { controllercomponent = c; }
114 ControllerComponent* GetControllerComponent() { return controllercomponent; }
116
117 static AIAgent* Find(id_t id);
118private:
119 ControllerComponent* controllercomponent;
120 AnimationStateComponent* animationstate;
121};
122
123}
124
125#endif // TRAM_SDK_EXTENSIONS_KITCHENSINK_AI_H
Definition: controller.h:16
name_t script
Definition: ai.h:100
std::vector< AIVariable > variables
Definition: ai.h:102
void Update()
Definition: ai.cpp:49
void SetAnimationStateComponent(AnimationStateComponent *c)
Definition: ai.h:113
AnimationStateComponent * GetAnimationStateComponent()
Definition: ai.h:115
void SetControllerComponent(ControllerComponent *c)
Definition: ai.h:112
std::vector< AIPackage * > override_stack
Definition: ai.h:98
void PushOverride(AIPackage *)
static AIAgent * Find(id_t id)
Definition: ai.cpp:65
ControllerComponent * GetControllerComponent()
Definition: ai.h:114
std::vector< AIPackage * > package_stack
Definition: ai.h:97
static void Register(name_t name, ai_package_constr constr)
Definition: ai.cpp:34
AIAgent * parent
Definition: ai.h:88
static AIPackage * Make(name_t name, valuearray_t params)
Definition: ai.cpp:38
Definition: value.h:336
Generic, type-safe union.
Definition: value.h:18
Definition: ai.cpp:16
AIPackage *(* ai_package_constr)(valuearray_t)
Definition: ai.h:74
void UpdateAI()
Definition: ai.cpp:30
void InitAI()
Definition: ai.cpp:21
Definition: api.h:9
uint32_t id_t
Definition: core.h:11
ValueArray valuearray_t
Definition: value.h:347
Value value
Definition: ai.h:92
Definition: uid.h:11