root/deus/structures.h

Revision 8, 7.1 kB (checked in by pantley2, 4 years ago)

added old DEUS project to SVN

Line 
1 /**
2  * structures.h
3  *
4  * DEUS Director data structures
5  */
6 #pragma warning(disable: 4786)
7 #pragma once
8
9 #include <windows.h>
10
11 #include "GraphIcon.h"
12 #include "mysql.h"
13
14 #include <vector>
15 #include <list>
16 #include <string>
17 #include <map>
18
19 using std::vector;
20 using std::string;
21 using std::list;
22 using std::map;
23
24
25 /************************************************
26  * Game Objects
27  ************************************************/
28 enum GOType {GO_NPC = 0x0, GO_LOCATION, GO_ITEM, GO_LAST};
29
30 /// parent class for anything that can be manipulated in the world
31 class GameObject        // parent class
32 {
33 public:
34         GOType type;
35 };
36
37 class NPC : public GameObject {
38 public:
39         string name;
40
41         int xcoord, ycoord;
42
43         NPC() {type = GO_NPC;}
44
45         map<string, int> attributes;
46         map<std::pair<string, int>, int> relationships;
47 };
48
49 /// All possible types go in this enum.  LOC_LAST must always be the last element
50 enum LocType {LOC_TOWN = 0x0, LOC_FARM, LOC_MARKET, LOC_BAR, LOC_GENERIC, LOC_LAST};
51
52 /// rectangular region of the map
53 class Location : public GameObject
54 {
55 public:
56         string name;
57         /// type of location
58     LocType loc_type;
59
60         Location() {type = GO_LOCATION;}
61
62         /// bounding rectangle
63         int ur_x, ur_y, ll_x, ll_y;
64 };
65
66 class Item : public GameObject
67 {
68 public:
69         Item() {type = GO_ITEM;}
70
71         /// there are currently no items =)
72 };
73
74
75
76 /************************************************
77  * Operators and Conditions
78  ************************************************/
79 // mapping from operator to unique index, starting with 0
80 enum OpCode {OP_CHANGEATTRIBUTE=0x0, OP_MOVENPC, OP_CHANGERELATIONSHIP, OP_NOOP, OP_LAST};
81
82 const int NUM_COND = 10;        // conditions are NUM_COND x num_COND
83
84 /// A condition defines the constraints that the author or some operator needs
85 /// to be satisfied in order to progress.  It may also be used to define the effects
86 /// of an operator.
87 class Condition
88 {
89 public:
90         Condition() {
91                 satisfied = 0;
92                 conditions = new string*[NUM_COND];
93                 for (int i = 0; i < NUM_COND; i++)
94                         conditions[i] = new string[NUM_COND];
95         }
96
97         int satisfied;
98     /// possible bindings for the set of variables.  Each column defines an object,
99     /// while each row defines a possible set of bindings.
100         vector<vector<GameObject *> > vars;
101         /// in custom condition language
102         string ** conditions;
103 };
104
105 /// An Operator object provides the director's means of taking action in the world.
106 /// All reasoning about actions, their effects and conditions that must be satisfied
107 /// to perform those actions is done through use of these objects.
108 class Operator
109 {
110 public:
111         Operator() {code = OP_NOOP;}
112
113     /// defines the type of operator the instance represents
114         OpCode code;
115
116     /// Conjunction that defines the conditions that must be met before this action may be performed
117         Condition PreConds;
118     /// Conjunction that defines the effects this action will have on the world
119         Condition PostConds;
120 };
121
122 /// All known information about the last observed state of the world is found in the World class
123 class World
124 {
125 public:
126         int map_height, map_width;
127         /// regions of the map
128     vector<Location> Locations;
129
130     /// non-player characters
131         vector<NPC> NPCs;
132         vector<Item> Items;
133 };
134
135
136
137
138 /************************************************
139  * Story and Keyframes
140  ************************************************/
141 enum NodeType {NODE_STORY = 0x0, NODE_KEYFRAME, NODE_LAST};
142
143 /// parent class for author defined nodes
144 class AuthorNode {
145 public:
146         NodeType type;
147         string name;
148
149         GraphIcon *icon;
150
151         virtual int save(int story_id, int parent_id) = 0;
152         virtual void del_node() = 0;
153 };
154
155 /// A node in the detailed storyline the author specifies
156 /// This type of node defines conditions that must be met for the story to progress on the larger path.
157 /// The conditions may themselves have preconditions
158 /// As currently implemented, this node is part of a tree defining alternate types of and ways to satisfy preconditions
159 class KeyFrameNode : public AuthorNode
160 {
161 public:
162         KeyFrameNode() {type = NODE_KEYFRAME; name = "NONE"; parent = NULL; icon = new GraphIcon(this); attempted = 0;}
163
164         /// next frame
165     KeyFrameNode* parent;                               
166         /// frames that must be reached before this one
167     vector<KeyFrameNode*> preconds;             
168         /// conditions for current keyframe
169     Condition conditions;                               
170
171     /// number of times the director has tried to achieve this node
172         int attempted;
173    
174     /// impl in AuthorInterface_impl.cpp, returns node_id
175         virtual int save(int story_id, int parent_id);         
176         /// impl in AuthorIntarface_impl.cpp also
177     virtual void del_node();                                                   
178 };
179
180 /// A node in the high level storyline the author specifies
181 /// Each of these breaks down into ministories made up of KeyFrameNodes
182 /// As currectly implemented, this node is to be part of a tree defining possible paths in the story
183 class StoryNode : public AuthorNode
184 {
185 public:
186         StoryNode() {type = NODE_STORY; name = "NONE"; frame = NULL; visited = false;  icon = new GraphIcon(this); parent = NULL;}
187
188         StoryNode* parent;
189         KeyFrameNode* frame;
190         bool visited;
191        
192         vector<StoryNode*> next;
193
194         /// impl in AuthorInterface_impl.cpp, returns node_id
195     virtual int save(int story_id, int parent_id);             
196         /// impl in AuthorIntarface_impl.cpp also
197     virtual void del_node();                                                   
198 };
199
200 /// node in a partial order plan that defines the actions that
201 /// the director intends to execute to achieve some desired goal
202 /// The partial order plan is modeled as an acyclic directed graph
203 class PlanNode
204 {
205 public:
206         PlanNode(const Operator& op, int depth = -1) : Op(op)
207                 {this->depth = depth; icon = new GraphIcon();}
208
209         inline bool isLeaf() {return branches.empty();}
210
211         /// next nodes in the plan
212     vector<PlanNode*> branches;
213     /// previous nodes in the plan
214         vector<PlanNode*> prevs;
215         /// the action that should be executed at this point in the plan
216     Operator Op;
217
218         GraphIcon *icon;
219
220     /// always useful for graph algorithms
221         int num;       
222         /// used for drawing, maybe more
223     int depth; 
224 };
225
226
227
228 /************************************************
229  * Misc declarations
230  ************************************************/
231 int CheckValidOps(string str, int x, int y);
232 int IsInt(string s);
233 std::pair<int,int> GetMapSize();
234 vector<Location> MapGenerator();
235 list<Operator>* GetGregOperators(World* W);
236 void DoOps(World* W, Operator* O);
237 void initRegressionPanes();
238 vector<list<Operator> > GetMeOperators(Condition C, int index);
239 vector<vector<GameObject *> > GetList(string** conds, World* W);
240 vector<vector<GameObject *> > BindList(vector<vector<GameObject*> > Obs, World* W, string** conds, int level);
241 Condition CheckWorldState(World* W, Condition C);
242 int recievedata();
243
244
245 /************************************************
246  * Global Data declarations - definition in director_main.cpp
247  ************************************************/
248 extern StoryNode*                       story_root;
249 extern World*                           real_world;
250 extern MYSQL*                           conn;                   // database connection
251 extern list<Operator>           Ops;
252
253 extern PlanNode*                        forward_root;
254 extern PlanNode*                        regression_root;
255 extern PlanNode*                        current_plan_root;
256 extern list<vector<PlanNode*> > pending_execution;
257
258
Note: See TracBrowser for help on using the browser.