3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
8 * See LICENSING which should be included
9 * along with this file for more details
15 #include "ivancommon.h"
26 class owterrainprototype
;
30 typedef gwterrain
*(*gwterrainspawner
) ();
31 typedef owterrain
*(*owterrainspawner
) (int Config
, int SpecialFlags
);
34 // ////////////////////////////////////////////////////////////////////////// //
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;
52 virtual truth
UsesLongArticle () const { return false; }
53 virtual v2
GetBitmapPos (int) const = 0;
56 wsquare
*WSquareUnder
;
61 // ////////////////////////////////////////////////////////////////////////// //
62 class gwterrainprototype
{
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
; }
74 gwterrainspawner Spawner
;
82 class gwterrain
: public wterrain
, public gterrain
{
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;
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
;
114 festring NameSingular
;
115 truth UsesLongArticle
;
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
{
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; }
160 const owterrainprototype
* Base
;
161 owterraindatabase
** ConfigData
;
162 owterraindatabase
** ConfigTable
[CONFIG_TABLE_SIZE
];
164 owterrainspawner Spawner
;
172 class owterrain
: public wterrain
, public oterrain
{
174 friend class databasecreator
<owterrain
>;
175 friend class owterrainprototype
;
176 typedef owterrainprototype prototype
;
177 typedef owterraindatabase database
;
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
);
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
; }
228 static const prototype ProtoType
;
229 const database
* DataBase
;
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; }
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);
255 #define WTERRAIN_PROTO(name, protobase)
259 #define WTERRAIN(name, base, protobase)\
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)