completely reworked worldmap generator and configuration; "points of interests" now...
[k8-i-v-a-n.git] / src / game / wterra.h
blob3d304bd7dd50245141961796643f57faf73af610
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #ifndef __WTERRA_H__
13 #define __WTERRA_H__
15 #include "ivancommon.h"
17 #include "cont.h"
18 #include "worldmap.h"
19 #include "terra.h"
20 #include "wsquare.h"
21 #include "festring.h"
24 struct blitdata;
26 class owterrainprototype;
27 class continent;
30 typedef gwterrain *(*gwterrainspawner) ();
31 typedef owterrain *(*owterrainspawner) (int Config, int SpecialFlags);
34 // ////////////////////////////////////////////////////////////////////////// //
35 class wterrain {
36 public:
37 wterrain () : WSquareUnder(0), AnimationFrames(1) {}
38 virtual ~wterrain () {}
40 virtual void Save (outputfile &) const;
41 virtual void Load (inputfile &);
42 v2 GetPos () const { return WSquareUnder->GetPos(); }
43 void SetWSquareUnder (wsquare *What) { WSquareUnder = What; }
44 worldmap *GetWorldMap () const { return WSquareUnder->GetWorldMap(); }
45 void AddName (festring &, int) const;
46 festring GetName (int) const;
47 truth IsAnimated () const { return AnimationFrames > 1; }
48 void SetAnimationFrames (int What) { AnimationFrames = What; }
49 virtual festring GetNameStem () const = 0;
51 protected:
52 virtual truth UsesLongArticle () const { return false; }
53 virtual v2 GetBitmapPos (int) const = 0;
55 protected:
56 wsquare *WSquareUnder;
57 int AnimationFrames;
61 // ////////////////////////////////////////////////////////////////////////// //
62 class gwterrainprototype {
63 public:
64 gwterrainprototype (gwterrainspawner, cchar *);
65 virtual ~gwterrainprototype () {}
67 gwterrain *Spawn () const { return Spawner(); }
68 gwterrain *SpawnAndLoad (inputfile &) const;
69 cchar *GetClassID () const { return ClassID; }
70 int GetIndex () const { return Index; }
72 private:
73 int Index;
74 gwterrainspawner Spawner;
75 cchar *ClassID;
77 public:
78 festring mOnEvents;
82 class gwterrain : public wterrain, public gterrain {
83 public:
84 typedef gwterrainprototype prototype;
86 virtual ~gwterrain () {}
88 virtual void Save (outputfile &) const;
89 void Draw (blitdata &) const;
90 virtual int GetPriority () const = 0;
91 virtual int GetEntryDifficulty () const { return 10; }
92 virtual const prototype *GetProtoType() const = 0;
93 int GetType () const { return GetProtoType()->GetIndex(); }
94 void CalculateNeighbourBitmapPoses ();
95 virtual int GetWalkability () const;
97 protected:
98 std::pair<v2, int> Neighbour[8];
102 // ////////////////////////////////////////////////////////////////////////// //
103 struct owterraindatabase : public databasebase {
104 typedef owterrainprototype prototype;
106 void InitDefaults (const owterrainprototype *NewProtoType, int NewConfig, cfestring &acfgstrname);
107 void PostProcess() {}
109 const prototype *ProtoType;
111 truth IsAbstract;
112 v2 BitmapPos;
113 festring NameStem;
114 festring NameSingular;
115 truth UsesLongArticle;
117 int AttachedDungeon;
118 int AttachedArea;
119 truth CanBeGenerated;
120 int NativeGTerrainType;
121 truth RevealEnvironmentInitially;
122 truth CanBeOnAnyTerrain;
123 int WantContinentWith;
124 int Probability; // in percents
125 truth CanBeSkipped; // if it is impossible to generate such POI, skip it
126 truth PlaceInitially;
130 class owterrainprototype {
131 public:
132 friend class databasecreator<owterrain>;
134 owterrainprototype (const owterrainprototype*, owterrainspawner, cchar *);
135 virtual ~owterrainprototype () {}
137 owterrain *Spawn (int Config, int SpecialFlags=0) const;
138 owterrain *SpawnAndLoad (inputfile &) const;
139 cchar *GetClassID () const { return ClassID; }
140 int GetIndex () const { return Index; }
142 const owterrainprototype *GetBase () const { return Base; }
143 int CreateSpecialConfigurations (owterraindatabase **, int Configs, int) { return Configs; }
144 const owterraindatabase *ChooseBaseForConfig (owterraindatabase **TempConfig, int, int) { return *TempConfig; }
145 const owterraindatabase *const *GetConfigData () const { return ConfigData; }
146 int GetConfigSize () const { return ConfigSize; }
149 virtual int GetAttachedDungeon () const { return 0; }
150 virtual int GetAttachedArea () const { return 0; }
151 virtual int GetNativeGTerrainType () const { return 0; }
152 virtual truth RevealEnvironmentInitially () const { return false; }
153 virtual truth CanBeOnAnyTerrain () const { return false; }
154 virtual int Probability () const { return 100; }
155 virtual truth CanBeSkipped () const { return false; }
158 private:
159 int Index;
160 const owterrainprototype* Base;
161 owterraindatabase** ConfigData;
162 owterraindatabase** ConfigTable[CONFIG_TABLE_SIZE];
163 int ConfigSize;
164 owterrainspawner Spawner;
165 cchar *ClassID;
167 public:
168 festring mOnEvents;
172 class owterrain : public wterrain, public oterrain {
173 public:
174 friend class databasecreator<owterrain>;
175 friend class owterrainprototype;
176 typedef owterrainprototype prototype;
177 typedef owterraindatabase database;
179 public:
180 void Initialize (int NewConfig, int SpecialFlags);
182 owterrain *Clone () const;
184 v2 GetPosition () const { return mPos; }
185 void SetPosition (v2 pos) { mPos = pos; }
187 truth IsGenerated () const { return mGenerated; }
188 void SetGenerated (truth v) { mGenerated = v; }
190 virtual void Save (outputfile &) const;
191 virtual void Load (inputfile &);
192 void Draw (blitdata &) const;
193 int GetType() const { return GetProtoType()->GetIndex(); }
194 virtual int GetAttachedEntry () const;
195 virtual truth Enter (truth) const;
196 virtual int GetWalkability () const;
197 const database *GetDataBase () const { return DataBase; }
199 truth IsRevealed () const { return mRevealed; }
200 void SetRevealed (truth v) { mRevealed = v; }
202 truth IsPlaced () const { return mPlaced; }
203 void SetPlaced (truth v) { mPlaced = v; }
205 DATA_BASE_VALUE(const prototype *, ProtoType);
206 DATA_BASE_VALUE(int, Config);
207 DATA_BASE_VALUE(festring, NameStem);
208 DATA_BASE_VALUE(festring, NameSingular);
209 DATA_BASE_TRUTH(UsesLongArticle);
210 DATA_BASE_VALUE(int, AttachedDungeon);
211 DATA_BASE_VALUE(int, AttachedArea);
212 DATA_BASE_TRUTH(CanBeGenerated);
213 DATA_BASE_VALUE(int, NativeGTerrainType);
214 DATA_BASE_VALUE(int, WantContinentWith);
215 DATA_BASE_TRUTH(RevealEnvironmentInitially);
216 DATA_BASE_TRUTH(CanBeOnAnyTerrain);
217 DATA_BASE_VALUE(int, Probability);
218 DATA_BASE_TRUTH(CanBeSkipped);
219 DATA_BASE_TRUTH(PlaceInitially);
221 protected:
222 virtual v2 GetBitmapPos (int) const { return DataBase->BitmapPos; }
223 //virtual cfestring& GetNameStem () const;
224 virtual void InstallDataBase (int);
225 virtual const prototype* FindProtoType () const { return &ProtoType; }
227 protected:
228 static const prototype ProtoType;
229 const database* DataBase;
231 v2 mPos;
232 truth mRevealed;
233 truth mPlaced;
234 truth mGenerated;
236 public:
237 virtual truth IsSuitableContinent (continent *);
239 virtual truth WantPetrusContinent () const { return true; } // for now they all should want it
240 virtual truth IsAttnam () const { return false; }
241 virtual truth IsHidden () const { return false; }
242 virtual truth IsRevealed () const { return false; }
245 public:
246 festring mOnEvents;
250 // ////////////////////////////////////////////////////////////////////////// //
251 #ifdef __FILE_OF_STATIC_WTERRAIN_PROTOTYPE_DEFINITIONS__
252 #define WTERRAIN_PROTO(name, protobase) \
253 template<> const protobase##prototype name##sysbase::ProtoType((protobase##spawner)(&name##sysbase::Spawn), #name);
254 #else
255 #define WTERRAIN_PROTO(name, protobase)
256 #endif
259 #define WTERRAIN(name, base, protobase)\
260 class name;\
261 typedef simplesysbase<name, base, protobase##prototype> name##sysbase;\
262 WTERRAIN_PROTO(name, protobase)\
263 class name : public name##sysbase
265 #define GWTERRAIN(name, base) WTERRAIN(name, base, gwterrain)
268 #endif