WorldSim  inDev
2D tile-based sandbox RPG with procedurally generated fantasy world simulator 🌏
Static_Flora.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef WORLDSIM_STATIC_FLORA_HPP
3 #define WORLDSIM_STATIC_FLORA_HPP
4 
5 /* WorldSim: Static_Flora
6  #include "Static_Flora.hpp" */
7 
36 /*
37  Types of Flora classes:
38 
39  Flora - Each object represents a species of Flora.
40  Flora_Instance - Represents an individual instance of a Flora species.
41  Flora_Abstract - Same as above, but storing only the minimum amount of data, most likely simply a pointer to Flora.
42 
43  During generation the world is populated with Flora_Abstract, and then when interacted with or viewed, it is
44  converted into a Flora_Instance with a generate() function.
45 
46  A Flora_Instance is visible on the World and can be interacted with. If a creature interacts with a Flora_Instance,
47  it recieved a value which represents energy gained from eating it. If a Character interacts with the
48  Flora_Instance, it recieves Ingredients which can then be used for eating/cooking/crafting/alchemy.
49 
50  Harvesting may be done by hand, or with a tool such as a knife.
51 
52  Flora are a type of Static and therefore there may be maximum 1 Flora_Instance per tile and are stored in the
53  statics file for the map.
54 
55  Statics will probably be compressed to a byte lookup table. I think it's unlikely there will ever need to be more
56  than about 16 Flora per Biome, so it shouldn't be a problem reserving this much space for Flora.
57 
58  Trees should probably be regarded largely the same as Flora, with the exeption they may block movement/LOS. As Flora may be harvested with tools, so may Trees be harvested, except of course they need something like an Axe.'
59 
60  For simplicity, a Tree shouldn't return anything except wood products, basically logs or bark. Complications would otherwise arise about whether something can or cannot be reached.
61 
62  Unlike with other Flora, there are a fixed number of Tree types, once again for simplicity. Each Biome probably gets 2 or 3 unique Tree types which are common across all Biomes of that type. Trees cannot be partially chopped or damaged so they can easily be stored as a Static lookup ID.
63 */
64 
65 
66 // Consolidates all Flora info for a biome to save space.
67 // There are max 255 Flora per biome therefore a lookup table is more efficient than a pointer.
68 // flora should just be in a map of values... easy, medium, hard, and current values of each.
69 // 4 bits per value should suffice, but for now we might just go with 1 byte per value
70 
71 // 1 creature may occupy 1 space.
72 // (this is resolved for the player and NPCs by allowing people to swap their position with another person)
73 
74 // Each map loaded should have an array of values for the flora
75 
76 // to simplify things a bit better, a flora will have a single type of food (hard, medium, easy)
77 // all flora will prodide the same nutrition for each type. Additionally replenishment can be random. This means only the flora type needs to be stored on the array, a single value from 1-3.
78 
79 // 00000000 - 111 - Type (multiple/none allowed). 111 - Eaten/not eaten.
80 // Flora will randomly fully replenish.
81 // Extra 2 bits reserved for trees (extra food type and movement blocking)
82 // 1 bit symbolises trees (movement blockers), and the final bit represents if a creature is on the tile.
83 
84 // 00000010 - tree
85 // 00000001 - creature is here
86 // 11111111 - natural feature blocking movement (creature may not be on tree)
87 
88 // grazers - can live off grass (any non-blocked tile, as a final elemant)
89 // speed/energy tradeoff allows multiple types of creatures to survive. Slower creatures get more food for less, but faster creatures can get there first.
90 // creatures breed by bring adjacent with at over 50% energy. Breeding brings energy down to 50%. Old age is not simulated.
91 
92 // more complex ai can be added over time.
93 // Replenishment gives a creature X turns to keep living. This will also occur in full-mode in a similar way..
94 // Therefore each biome can run flora/wildlife simulation with 1 byte per tile (
95 
96 
97 
98 // class FloraAbstract: public Static
99 // {
100  // public:
101  // // this only tracks food amount and for everything else uses a lookup on the Flora type
102  // unsigned char easyFood, mediumFood, hardFood;
103 
104  // Flora* lookup;
105  // //unsigned char biomeLookup;
106 
107 
108  // FloraAbstract()
109  // {
110  // }
111 // };
112 
113 // class FloraDynamic
114 // {
115  // public:
116 
117  // FloraDynamic()
118  // {
119  // }
120 // };
121 
122 // This class sets the stats for a type of flora. Individual instances should use another class.
123 #include <Container/Table/TableInterface.hpp>
124 #include <Container/WordList/WordList.hpp> // for random flora names
125 
126 // ingredient effects
127 // realistically we will probably just have a hardcoded table of effects
128 class Effect
129 {
130  public:
131  std::string name;
132 
133  Effect(std::string _name)
134  {
135  name=_name;
136  }
137 };
138 
140 {
141  WordList wListEffects;
142  public:
143 
145  {
146  wListEffects.add("Death");
147  wListEffects.add("Poison");
148  wListEffects.add("Health");
149  wListEffects.add("Magic");
150  }
151 
153  {
154  auto effect = new Effect(wListEffects.getRandom());
155  return effect;
156  }
157 };
159 
160 
161 #include "Ingredient.hpp"
162 
163 #include <File/FileManager.hpp>
164 
166 {
167  public:
168  std::string name;
169 
170  WordList wListIngredient;
171 
173  {
174  // for now just give random name from small list for testing
175  // Load word lists
176  wListIngredient.loadString(FileManager::getFileAsString("raw/wordlists/ingredient.txt"));
177  RNG_TEST.seed(SEEDER);
178  }
179 
181  {
182  auto ingredient = new Ingredient(wListIngredient.getRandom());
183 
184  //ingredient->name=wListIngredient.getRandom();
185 
186  //std::cout<<"Generated ingredient: "<<ingredient->name<<"\n";
187 
188  return ingredient;
189  }
190 
191 };
192 
194 
195 // todo: track base biome and allow migration between biomes (mutation of 1 trait)
196 
197 #include "World_Biome.hpp"
198 
199 #include <Graphics/Colour/Colour.hpp>
200 
201 class Flora: public Static, public TableInterface
202 {
203  // Easy food: Food which can easily be obtained/eaten such as fruit
204  // Medium food: Food which is moderately easy to obtain/eat such as bark
205  // Hard food: Food which is hard to obtain/eat such as leaves
206  // This should allow a balance of large and slow, and small and fast herbivores
207  // Increment is per 24 hours
208  // 1 food = 1 day of food for 1 herbivore
209  unsigned char easyFood, mediumFood, hardFood;
210 
211  //Vector <unsigned char> vAllowedBiomeTypes;
212 
213  public:
214  Ingredient * ingredient; // Each Flora may contain 1 ingredient.
215  World_Biome * biome; // biome in which this Flora may spawn (Flora are limited to their biome)
216 
217  unsigned short int spawnWeight; // probability of being selected to spawn. higher = more common
218 
219  //Colour colour; // The base colour of the Flora (ingredients may also have their own colour)
220  ColourRGB <unsigned char> colour;
221 
222  Flora(const std::string _name = "Flora", const unsigned short int _spawnWeight=1);
223 
224  void increment(unsigned short int /* nDays */);
225  void setFoodValues(unsigned char /* _maxEasy */, unsigned char /* _maxMedium */, unsigned char /* _maxHard */);
226  void allowBiome(unsigned char /* biomeType */);
227 
228  std::string getColour();
229 
230  virtual Texture* currentTexture() override;
231 
232  std::string getName() override;
233 
234  // TableInterface
235  std::string getColumn(std::string _column) override;
236  // TableInterface
237  std::string getColumnType(std::string _column) override;
238 
239 };
240 
241 #include "Driver_TextureList.hpp"
242 
243 
244 // Trees will be special-case flora because they can block LOS and movement.
245 class Static_Tree: public Flora
246 {
247  public:
248 
250  int growth;
251 
252  Static_Tree(int _growth=100)
253  {
254  chopAmount=100;
255  growth=_growth;
256 
257  if ( growth > 0 )
258  {
259  blockMove = 255;
260  blockLOS = 255;
261  }
262  else
263  {
264  blockMove = 0;
265  blockLOS = 0;
266  }
267  }
268 
269  Texture* currentTexture() override
270  {
271  if (chopAmount==0)
272  { return &TEX_OBJECT_STUMP;
273  }
274  if ( growth==0 )
275  {
277  }
279  }
280 };
281 
282 
283 #include "Static_FloraManager.hpp"
284 #include "Static_FloraGenerator.hpp"
285 #include "Static_FloraGenerator.cpp"
287 #include "Static_FloraManager.cpp"
288 
289 #include "Static_Flora.cpp"
290 
291 
292 
293 
294 #endif
EffectGenerator()
Definition: Static_Flora.hpp:144
RandomLehmer SEEDER
Definition: Driver_GlobalObjects.hpp:9
Texture * currentTexture() override
Definition: Static_Flora.hpp:269
Definition: Static_Flora.hpp:139
Texture TEX_OBJECT_STUMP
Definition: Driver_TextureList.hpp:217
Definition: Static.hpp:24
Definition: Static_Flora.hpp:128
Texture TEX_WORLD_TERRAIN_FOREST_TREE
Definition: Driver_TextureList.hpp:127
Ingredient * generateIngredient()
Definition: Static_Flora.hpp:180
Definition: World_Biome.hpp:46
Texture TEX_WORLD_TERRAIN_FOREST_SAPLING
Definition: Driver_TextureList.hpp:130
IngredientGenerator()
Definition: Static_Flora.hpp:172
IngredientGenerator ingredientGenerator
Definition: Static_Flora.hpp:193
World_Biome * biome
Definition: Static_Flora.hpp:215
Effect(std::string _name)
Definition: Static_Flora.hpp:133
Definition: Ingredient.hpp:20
Ingredient * ingredient
Definition: Static_Flora.hpp:214
ColourRGB< unsigned char > colour
Definition: Static_Flora.hpp:220
Definition: Static_Flora.hpp:201
RandomLehmer RNG_TEST
Definition: Driver_GlobalObjects.hpp:12
Definition: Static_FloraGenerator.hpp:17
FloraGenerator floraGenerator
Definition: Static_Flora.hpp:286
WordList wListIngredient
Definition: Static_Flora.hpp:170
std::string name
Definition: Static_Flora.hpp:131
std::string name
Definition: Static_Flora.hpp:168
EffectGenerator effectGenerator
Definition: Static_Flora.hpp:158
Effect * generate()
Definition: Static_Flora.hpp:152
Definition: Static_Flora.hpp:245
unsigned short int spawnWeight
Definition: Static_Flora.hpp:217
int chopAmount
Definition: Static_Flora.hpp:249
Static_Tree(int _growth=100)
Definition: Static_Flora.hpp:252
Definition: Static_Flora.hpp:165
int growth
Definition: Static_Flora.hpp:250