Planeshift
|
00001 /* 00002 * recipe.h 00003 * 00004 * Copyright (C) 2011 Atomic Blue ([email protected], http://www.atomicblue.org) 00005 * 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation (version 2 of the License) 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * 00018 */ 00019 00020 #ifndef __RECIPE_H__ 00021 #define __RECIPE_H__ 00022 00023 //============================================================================= 00024 // Crystal Space Includes 00025 //============================================================================= 00026 #include <csutil/array.h> 00027 #include <csutil/stringarray.h> 00028 #include <csutil/csstring.h> 00029 //============================================================================= 00030 // Project Includes 00031 //============================================================================= 00032 #include <util/psdatabase.h> 00033 #include <util/psutil.h> 00034 //============================================================================= 00035 // Local Includes 00036 //============================================================================= 00037 #include "globals.h" 00038 #include "tribe.h" 00039 #include "recipetreenode.h" 00040 #include "npcbehave.h" 00041 00042 00047 class psNPCClient; 00048 class EventManager; 00049 class RecipeTreeNode; 00050 00055 class Recipe 00056 { 00057 public: 00058 00060 typedef enum 00061 { 00062 REQ_TYPE_BUILDING, 00063 REQ_TYPE_ITEM, 00064 REQ_TYPE_KNOWLEDGE, 00065 REQ_TYPE_MEMORY, 00066 REQ_TYPE_RECIPE, 00067 REQ_TYPE_RESOURCE, 00068 REQ_TYPE_TRADER, 00069 REQ_TYPE_TRIBESMAN 00070 } RequirementType; 00071 static const char* RequirementTypeString[]; 00072 00074 struct Requirement 00075 { 00076 RequirementType type; 00077 csString name; 00078 csString quantity; 00079 csString recipe; 00080 csString buffer; 00081 csString reqText; 00082 }; 00083 00085 Recipe(); 00086 00088 virtual ~Recipe() { }; 00089 00091 bool Load(iResultRow &row); 00092 00094 void Dump(); 00095 00097 void DumpAlgorithm(); 00098 00100 void DumpRequirements(); 00101 00103 int GetID() 00104 { 00105 return id; 00106 } 00107 00109 csString GetName() 00110 { 00111 return name; 00112 } 00113 00115 csStringArray GetAlgorithm() 00116 { 00117 return algorithm; 00118 } 00119 00121 bool IsPersistent() 00122 { 00123 return persistence; 00124 } 00125 00127 csArray<Requirement> GetRequirements() 00128 { 00129 return requirements; 00130 } 00131 00132 private: 00133 bool persistence; 00134 bool unique; 00135 int id; 00136 csString name; 00137 csArray<Requirement> requirements; 00138 csStringArray algorithm; 00139 int steps; 00140 }; 00141 00148 class RecipeManager 00149 { 00150 public: 00152 struct TribeData 00153 { 00154 int tribeID; 00155 Recipe* tribalRecipe; 00156 int currentStep; 00157 00158 // Tribe Traits 00159 csString aggressivity; 00160 csString brain; 00161 csString growth; 00162 csString unity; 00163 csString sleepPeriod; 00164 00165 // Global Tribe NPCType 00166 csString global; 00167 }; 00168 00170 struct Correspondence 00171 { 00172 csString function; 00173 csStringArray npcOperations; 00174 }; 00175 00177 RecipeManager(psNPCClient* NPCClient, EventManager* eventManager); 00178 00180 virtual ~RecipeManager(); 00181 00192 csString Preparse(csString function, Tribe* tribe); 00193 00195 bool LoadRecipes(); 00196 00206 bool AddTribe(Tribe* tribe); 00207 00219 void CreateGlobalNPCType(Tribe* tribe); 00220 00232 bool ParseFunction(csString function, Tribe* tribe, csArray<NPC*> &npcs, Recipe* recipe); 00233 00245 bool ParseRequirement(const Recipe::Requirement &requirement, Tribe* tribe, Recipe* recipe); 00246 00256 int ApplyRecipe(RecipeTreeNode* bestRecipe, Tribe* tribe, int step); 00257 00259 Recipe* GetRecipe(int recipeID); 00260 00262 Recipe* GetRecipe(csString recipesName); 00263 00265 TribeData* GetTribeData(Tribe* tribe); 00266 00267 private: 00269 void DumpError(csString recipeName, csString functionName, int expectedArgs, int receivedArgs); 00270 00271 csArray<Tribe*> tribes; 00272 csArray<TribeData> tribeData; 00273 csArray<Recipe*> recipes; 00274 00275 psNPCClient* npcclient; 00276 EventManager* eventmanager; 00277 }; 00278 00281 #endif