Planeshift
recipetreenode.h
Go to the documentation of this file.
1 /*
2 * recipetreenode.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 __RECIPETREENODE_H__
21 #define __RECIPETREENODE_H__
22 
23 //=============================================================================
24 // Crystal Space Includes
25 //=============================================================================
26 #include <csutil/array.h>
27 //=============================================================================
28 // Project Includes
29 //=============================================================================
30 
31 //=============================================================================
32 // Local Includes
33 //=============================================================================
34 #include "tribe.h"
35 #include "recipe.h"
36 
41 class Recipe;
42 
43 #define CYCLIC_RECIPE_PRIORITY 100
44 
53 {
54 public:
55  typedef enum
56  {
60  static const char* RequirementParseTypeString[];
61 
62 
64  int priority;
65  int wait;
66  int nextStep;
67  int cost;
68 
69  RequirementParseType requirementParseType;
70  int nextReq;
71 
73  csArray<RecipeTreeNode*> children;
74 
76  RecipeTreeNode(Recipe* newRecipe, int newCost, RecipeTreeNode* parent = NULL);
78 
80  void AddChild(RecipeTreeNode* child);
81 
83  bool AddChild(RecipeTreeNode* child, Recipe* parent);
84 
86  bool RemoveChild(RecipeTreeNode* child);
87 
89  bool RemoveChild(Recipe* child);
90 
92  bool IsRoot()
93  {
94  return parent == NULL;
95  };
96 
98  bool IsLeaf()
99  {
100  return children.GetSize() == 0;
101  }
102 
104  RecipeTreeNode* GetTreeRecipe(Recipe* searchRecipe);
105 
111 
113  bool ModifyWait(Recipe* theRecipe, int delta);
114 
116  void UpdateWaitTimes(int delta);
117 
120  {
121  DumpRecipeTree(1);
122  }
123  void DumpRecipeTree(int index);
125  {
127  }
128  void DumpRecipeTreeRecipes(int index);
129 };
130 
133 #endif
void AddChild(RecipeTreeNode *child)
Add a new child.
int nextStep
The next step which needs to be executed.
bool RemoveChild(RecipeTreeNode *child)
Remove a descendant.
csArray< RecipeTreeNode * > children
Link to children nodes.
void UpdateWaitTimes(int delta)
Update wait times.
static const char * RequirementParseTypeString[]
void DumpRecipeTreeRecipes()
RecipeTreeNode * GetNextRecipe()
Gets Next Recipe.
RequirementParseType requirementParseType
Holds the way the Recipe Manager should meet requirements.
int priority
The priority of this recipe. (Level in tree, where root = 0)
void DumpRecipeTree()
Dump tree to console.
Recipe * recipe
The recipe this leaf is about.
int wait
Wait time.
int cost
Computed cost for this recipe. In regard of tribe.
RecipeTreeNode * parent
Link to parent node.
RecipeTreeNode(Recipe *newRecipe, int newCost, RecipeTreeNode *parent=NULL)
Constructor.
bool IsRoot()
Returns true if it&#39;s root.
int nextReq
Next requirement that should be met.
bool ModifyWait(Recipe *theRecipe, int delta)
Updates a wait time on one recipe.
RecipeTreeNode * GetTreeRecipe(Recipe *searchRecipe)
Gets a recipe from this tree.
bool IsLeaf()
Returns true if it&#39;s a leaf.
This class represents a leaf in a recipe tree.
This object represents recipes for the tribe AI.
Definition: recipe.h:55