Planeshift
recipe.h
Go to the documentation of this file.
1 /*
2 * recipe.h
3 *
4 * Copyright (C) 2011 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19 
20 #ifndef __RECIPE_H__
21 #define __RECIPE_H__
22 
23 //=============================================================================
24 // Crystal Space Includes
25 //=============================================================================
26 #include <csutil/array.h>
27 #include <csutil/stringarray.h>
28 #include <csutil/csstring.h>
29 //=============================================================================
30 // Project Includes
31 //=============================================================================
32 #include <util/psdatabase.h>
33 #include <util/psutil.h>
34 //=============================================================================
35 // Local Includes
36 //=============================================================================
37 #include "globals.h"
38 #include "tribe.h"
39 #include "recipetreenode.h"
40 #include "npcbehave.h"
41 
42 
47 class psNPCClient;
48 class EventManager;
49 class RecipeTreeNode;
50 
55 class Recipe
56 {
57 public:
58 
60  typedef enum
61  {
71  static const char* RequirementTypeString[];
72 
74  struct Requirement
75  {
76  RequirementType type;
77  csString name;
78  csString quantity;
79  csString recipe;
80  csString buffer;
81  csString reqText;
82  };
83 
85  Recipe();
86 
88  virtual ~Recipe() { };
89 
91  bool Load(iResultRow &row);
92 
94  void Dump();
95 
97  void DumpAlgorithm();
98 
100  void DumpRequirements();
101 
103  int GetID()
104  {
105  return id;
106  }
107 
109  csString GetName()
110  {
111  return name;
112  }
113 
115  csStringArray GetAlgorithm()
116  {
117  return algorithm;
118  }
119 
122  {
123  return persistence;
124  }
125 
127  csArray<Requirement> GetRequirements()
128  {
129  return requirements;
130  }
131 
132 private:
133  bool persistence;
134  bool unique;
135  int id;
136  csString name;
137  csArray<Requirement> requirements;
138  csStringArray algorithm;
139  int steps;
140 };
141 
149 {
150 public:
152  struct TribeData
153  {
154  int tribeID;
157 
158  // Tribe Traits
159  csString aggressivity;
160  csString brain;
161  csString growth;
162  csString unity;
163  csString sleepPeriod;
164 
165  // Global Tribe NPCType
166  csString global;
167  };
168 
171  {
172  csString function;
173  csStringArray npcOperations;
174  };
175 
177  RecipeManager(psNPCClient* NPCClient, EventManager* eventManager);
178 
180  virtual ~RecipeManager();
181 
192  csString Preparse(csString function, Tribe* tribe);
193 
195  bool LoadRecipes();
196 
206  bool AddTribe(Tribe* tribe);
207 
219  void CreateGlobalNPCType(Tribe* tribe);
220 
232  bool ParseFunction(csString function, Tribe* tribe, csArray<NPC*> &npcs, Recipe* recipe);
233 
245  bool ParseRequirement(const Recipe::Requirement &requirement, Tribe* tribe, Recipe* recipe);
246 
256  int ApplyRecipe(RecipeTreeNode* bestRecipe, Tribe* tribe, int step);
257 
259  Recipe* GetRecipe(int recipeID);
260 
262  Recipe* GetRecipe(csString recipesName);
263 
265  TribeData* GetTribeData(Tribe* tribe);
266 
267 private:
269  void DumpError(csString recipeName, csString functionName, int expectedArgs, int receivedArgs);
270 
271  csArray<Tribe*> tribes;
272  csArray<TribeData> tribeData;
273  csArray<Recipe*> recipes;
274 
276  EventManager* eventmanager;
277 };
278 
281 #endif
psNPCClient * npcclient
Global connection to the NPC Client.
csString quantity
Number needed.
Definition: recipe.h:78
csString buffer
Use this buffer to store name for recipe to use later.
Definition: recipe.h:80
RequirementType
Types of requirements.
Definition: recipe.h:60
void DumpAlgorithm()
Dumps algorithm to console.
csStringArray npcOperations
More than one operation can be applied for a function.
Definition: recipe.h:173
csString GetName()
Getter for Recipe&#39;s Name.
Definition: recipe.h:109
Recipe()
Construct a Recipe object.
Keeps details of all tribes enrolled in the manager.
Definition: recipe.h:152
Keeps details about the matches between script actions and NPC Operations.
Definition: recipe.h:170
void Dump()
Dump all details about the recipe.
virtual ~Recipe()
Destruct a Recipe object.
Definition: recipe.h:88
Class that represents the Recipe Manager of the game.
Definition: recipe.h:148
void DumpRequirements()
Dumps requirements to console.
bool IsPersistent()
Getter for Persistance.
Definition: recipe.h:121
bool Load(iResultRow &row)
Load a recipe.
csString recipe
If requirement isn&#39;t meet use this recipe to get it.
Definition: recipe.h:79
static const char * RequirementTypeString[]
Definition: recipe.h:71
csString global
Holds the parent NPCType available for the whole tribe.
Definition: recipe.h:166
The main NPC Client class holding references to important superclient objects.
Definition: npcclient.h:81
int currentStep
Keeps the step the tribe is currently at in the recipe.
Definition: recipe.h:156
csStringArray GetAlgorithm()
Getter for Recipe&#39;s Algorithm.
Definition: recipe.h:115
Data structure to keep information about requirements.
Definition: recipe.h:74
csString reqText
The unparsed requirment function for this.
Definition: recipe.h:81
csArray< Requirement > GetRequirements()
Getter for Requirements.
Definition: recipe.h:127
int GetID()
Getter for Recipe&#39;s ID.
Definition: recipe.h:103
Recipe * tribalRecipe
Recipe keeping tribe information.
Definition: recipe.h:155
This class represents a leaf in a recipe tree.
csString name
Name of the requirement.
Definition: recipe.h:77
This object represents recipes for the tribe AI.
Definition: recipe.h:55
This class handles all queueing and invoking of timed events, such as combat, spells, NPC dialog responses, range weapons, or NPC respawning.
Definition: eventmanager.h:40
RequirementType type
Type. Can be workforce, resource, item, knowledge.
Definition: recipe.h:76
Holds list of tribe members, position of tribe home Keeps resources and handles tribe perceptions...
Definition: tribe.h:67