WorldSim  inDev
2D tile-based sandbox RPG with procedurally generated fantasy world simulator 🌏
LocalTile.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef WORLDSIM_LOCALTILE_HPP
3 #define WORLDSIM_LOCALTILE_HPP
4 
5 /* WorldSim: LocalTile
6  #include "LocalTile.hpp"
7 
8 LocalTile stores tile info on the local maps. Stuff like objects on that tile, etc.
9 
10 Basic details like heightmap are stored as a seed, to cut down on memory footprint. Tile can be constructed into an array on demand. Modifications to the world are stored seperately.
11 
12 At 1:1 scale a tile is 5km by 5km, ie, 5,000 * 5000 tiles, however we will probably end up using tiles of size 513 because anything larger will have a huge memory footprint without special code.
13 
14 In the future we might have polymorphic classes to distinguish simulated tiles from abstract tiles. Abstract tiles will basically be tiles that nobody has seen, and therefore they don't need data. However this may not be possible if wildlife is to be simulated.
15 
16  A tile may have various things on it:
17  Terrain - All tiles have terrain. It is a fixed set of values.
18  Objects - On a set of vectors, split up to aid search performance.
19  Static - A single Static object which may block movement or line of sight
20  Evidence - Some kind of temporary marking.
21 */
22 
23 #include <Interface/HasTexture.hpp>
24 
25 #include <Game/WorldGenerator/Biome.hpp>
26 
27 class WorldObject;
28 class Item;
29 class Creature;
30 class Creature_Footprint;
31 class Character;
32 class Static;
33 
34 class LocalTile: public HasTexture
35 {
36 public:
37 
38  LocalTile();
39  ~LocalTile();
40 
41  /* Every local tile must have a seed to help determine random things,
42  for example which variant of texture to draw. */
43  // Actually this is probably not necessary.
44  unsigned short int seed;
45  enumBiome baseTerrain;
46  //Base terrain can be overlaid with a floor.
47  // For now just a bool.
48  unsigned char hasFloor;
49 
50  // Walls block movement across them
51  // Bitfield is used to determine the wall orientation.
52  // The first 4 bits control travel OUT from the tile. NESW.
53  // The last 4 bits control travel INTO the tile. NESW.
54  // This allows one-way travel, which would be useful for traps, pits, etc.
55  unsigned char bWall;
56 
57  // same but for cliffs.
58  //unsigned char bCliff;
59  // change this to a simple bool
60  bool bCliff;
61 
62  short int height;
63 
64  bool isLand; /* True if not water */
65  //bool hasGems;
66  //bool hasMetal;
67  bool isCave;
68 
69  unsigned short int nGems;
70  unsigned short int nMetal;
71 
72  // bool isUphill [8]; /* Clockwise starting north */
73 
74 
75  /* INTERACTION STUFF */
76  int nFish; /* How many fish this tile has. Set to -1 if fishing is not possible here */
77 
78  /* RENDER STUFF */
79  bool shotOverlay; /* Show the line of fire highlight for this tile */
80 
81  // Vector of objects on this tile.
82  // This list includes all subclasses.
83  // The reason there are so many duplicates is performance.
84  Vector <WorldObject*> vObject;
85  // Vector of non-specialised WorldObjects.
86  Vector <WorldObject*> vObjectGeneric;
87  // Vector of Items on this tile
88  Vector <Item*> vItem;
89  // Vector of Characters on this tile.
90  Vector <Character*> vCharacter;
91  // Vector of Creatures on this tile.
92  Vector <Creature*> vCreature;
93 
94  Static* objStatic; // Static object (max 1)
95 
96  Creature_Footprint* footprint; // Creature Evidence (max 1)
97 
98  // Generic add/remove automatically sorts into appropriate lists.
99 
100  void add(WorldObject*);
101  void add(Item*);
102  void add(Character*);
103  void add(Creature*);
104 
105  void remove(WorldObject*);
106  void remove(Item*);
107  void remove(Character*);
108  void remove(Creature*);
109 
110 
111  void clearObjects();
112 
113 
114  // This returns the base terrain texture.
115  virtual Texture* currentTexture();
116 
117  // Return vector of all textures to be drawn, to be drawn from index 0 to n-1.
118  virtual Vector <Texture*> * currentTextures();
119 
120  // Returns true is this tile has an object that can block line of sight. */
121  bool hasViewBlocker();
122  // Returns true is this tile has an object that can block movement.
123  bool hasMovementBlocker();
124 
125  std::string getName();
126 
127 
128  bool canTravelNorth();
129  bool canTravelEast();
130  bool canTravelSouth();
131  bool canTravelWest();
132 
133  std::string getAll(int /* max */); // return string listing all objects on this tile (up to max)
134 
135  std::string getSaveData();
136 
137  //Abstract data is just the bare minimum data to run simulations: Collision data and food values for wildlife.
138  std::string getAbstractData();
139  void loadData(std::string);
140 
141 };
142 
143 #endif
Creature_Footprint * footprint
Definition: LocalTile.hpp:96
int nFish
Definition: LocalTile.hpp:76
bool isCave
Definition: LocalTile.hpp:67
unsigned short int nMetal
Definition: LocalTile.hpp:70
Definition: Creature.hpp:34
bool isLand
Definition: LocalTile.hpp:64
virtual Vector< Texture * > * currentTextures()
Definition: LocalTile.cpp:247
enumBiome baseTerrain
Definition: LocalTile.hpp:45
Definition: WorldObject.hpp:18
unsigned char bWall
Definition: LocalTile.hpp:55
unsigned char hasFloor
Definition: LocalTile.hpp:48
bool canTravelNorth()
Definition: LocalTile.cpp:301
Definition: Static.hpp:24
bool canTravelEast()
Definition: LocalTile.cpp:309
bool canTravelSouth()
Definition: LocalTile.cpp:317
Vector< WorldObject * > vObjectGeneric
Definition: LocalTile.hpp:86
Definition: Item.hpp:51
std::string getAll(int)
Definition: LocalTile.cpp:334
Definition: Creature.hpp:137
Vector< Creature * > vCreature
Definition: LocalTile.hpp:92
bool canTravelWest()
Definition: LocalTile.cpp:325
Vector< WorldObject * > vObject
Definition: LocalTile.hpp:84
bool hasMovementBlocker()
Definition: LocalTile.cpp:129
bool bCliff
Definition: LocalTile.hpp:60
Vector< Item * > vItem
Definition: LocalTile.hpp:88
short int height
Definition: LocalTile.hpp:62
void add(WorldObject *)
Definition: LocalTile.cpp:41
std::string getAbstractData()
Definition: LocalTile.cpp:440
LocalTile()
Definition: LocalTile.cpp:15
Definition: Character.hpp:38
std::string getName()
Definition: LocalTile.cpp:147
Static * objStatic
Definition: LocalTile.hpp:94
Definition: LocalTile.hpp:34
void clearObjects()
Definition: LocalTile.cpp:91
virtual Texture * currentTexture()
Definition: LocalTile.cpp:181
unsigned short int nGems
Definition: LocalTile.hpp:69
unsigned short int seed
Definition: LocalTile.hpp:44
bool hasViewBlocker()
Definition: LocalTile.cpp:102
~LocalTile()
Definition: LocalTile.cpp:36
std::string getSaveData()
Definition: LocalTile.cpp:402
bool shotOverlay
Definition: LocalTile.hpp:79
void loadData(std::string)
Definition: LocalTile.cpp:451
Vector< Character * > vCharacter
Definition: LocalTile.hpp:90