'g'o should not miss items in corners anymore
[k8-i-v-a-n.git] / src / game / lterra.h
blobf590267072ebfc3f449f09070b68800aa8567675
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 __LTERRA_H__
13 #define __LTERRA_H__
15 #include "ivancommon.h"
17 #include "object.h"
18 #include "terra.h"
19 #include "script.h"
20 #include "festring.h"
23 class glterrain;
24 class olterrain;
25 class item;
26 class level;
27 class lsquare;
28 class stack;
29 class room;
30 class liquid;
31 class materialscript;
32 class glterrainprototype;
33 class olterrainprototype;
34 template <class type> class databasecreator;
35 struct blitdata;
37 typedef glterrain* (*glterrainspawner)(int, int);
38 typedef olterrain* (*olterrainspawner)(int, int);
40 struct lterraindatabase : public databasebase
42 void PostProcess() { }
43 v2 BitmapPos;
44 truth UsesLongArticle;
45 festring Adjective;
46 truth UsesLongAdjectiveArticle;
47 festring NameSingular;
48 festring NamePlural;
49 festring PostFix;
50 int ArticleMode;
51 fearray<sLong> MainMaterialConfig;
52 fearray<sLong> SecondaryMaterialConfig;
53 fearray<sLong> MaterialConfigChances;
54 sLong MaterialConfigChanceSum;
55 int OKVisualEffects;
56 col16 MaterialColorB;
57 col16 MaterialColorC;
58 col16 MaterialColorD;
59 festring SitMessage;
60 int AttachedGod;
61 int Walkability;
62 truth IsAbstract;
63 truth ShowMaterial;
64 truth HasSecondaryMaterial;
65 truth UseBorderTiles;
66 int BorderTilePriority;
69 class lterrain : public object
71 public:
72 lterrain() : LSquareUnder(0) { }
73 virtual ~lterrain () {}
75 virtual void Load(inputfile&);
76 virtual truth Open(character*) { return false; }
77 virtual truth Close(character*) { return false; }
78 v2 GetPos() const;
79 virtual truth CanBeOpened() const { return false; }
80 virtual truth CanBeClosed() const { return false; }
81 virtual truth AcceptsOffers() const { return false; }
82 virtual truth ReceiveVomit(character*, liquid*) { return false; }
83 virtual truth CanBeOpenedByAI() { return false; }
84 virtual truth Polymorph(character*) { return false; }
85 virtual truth DipInto(item*, character*) { return false; }
86 virtual truth IsDipDestination() const { return false; }
87 virtual truth TryKey(item*, character*) { return false; }
88 truth CanBeSeenByPlayer() const;
89 truth CanBeSeenBy(character*) const;
90 virtual cfestring& GetSitMessage() const = 0;
91 virtual truth SitOn(character*);
92 virtual square* GetSquareUnderEntity(int = 0) const;
93 void SetLSquareUnder(lsquare* What) { LSquareUnder = What; }
94 lsquare* GetLSquareUnder() const { return LSquareUnder; }
95 level* GetLevel() const;
96 lsquare* GetNearLSquare(v2) const;
97 lsquare* GetNearLSquare(int, int) const;
98 virtual void CalculateAll() { CalculateEmitation(); }
99 virtual void SignalEmitationIncrease(col24);
100 virtual void SignalEmitationDecrease(col24);
101 virtual truth HasKeyHole() const { return CanBeOpened(); }
102 virtual truth IsOnGround() const { return true; }
103 room* GetRoom() const;
104 virtual void SignalRustLevelChange();
105 virtual void TryToRust(sLong);
106 virtual void ReceiveAcid(material*, sLong) { }
107 void InitMaterials(material*, truth = true);
108 void SetMainMaterial(material*, int = 0);
109 void ChangeMainMaterial(material*, int = 0);
110 virtual void GenerateMaterials();
111 virtual void InitMaterials(const materialscript*, const materialscript*, truth);
112 virtual const fearray<sLong>& GetMainMaterialConfig() const = 0;
113 virtual void SurviveEffect(character*) { }
114 virtual void RestoreHP() { }
115 virtual void AddLocationDescription(festring&) const;
116 protected:
117 void Initialize(int, int);
118 virtual void PostConstruct() { }
119 virtual void InstallDataBase(int) = 0;
120 lsquare* LSquareUnder;
123 struct glterraindatabase : public lterraindatabase
125 typedef glterrainprototype prototype;
126 void InitDefaults (const glterrainprototype *NewProtoType, int NewConfig, cfestring &acfgstrname);
127 truth AllowRandomInstantiation() const { return true; }
128 const prototype* ProtoType;
131 class glterrainprototype
133 public:
134 friend class databasecreator<glterrain>;
136 glterrainprototype(const glterrainprototype*, glterrainspawner, cchar*);
137 virtual ~glterrainprototype () {}
139 glterrain* Spawn(int Config = 0, int SpecialFlags = 0) const { return Spawner(Config, SpecialFlags); }
140 glterrain* SpawnAndLoad(inputfile&) const;
141 cchar* GetClassID() const { return ClassID; }
142 int GetIndex() const { return Index; }
143 inline cchar *GetTypeID () const { return ClassID; }
144 inline truth IsOfType (cchar *tname) const { return (tname ? (strcmp(tname, ClassID) == 0) : false); }
145 inline truth IsOfType (cfestring &tname) const { return (tname.Compare(ClassID) == 0); }
146 const glterrainprototype* GetBase() const { return Base; }
147 int CreateSpecialConfigurations(glterraindatabase**, int Configs, int) { return Configs; }
148 const glterraindatabase* ChooseBaseForConfig(glterraindatabase** TempConfig, int, int) { return *TempConfig; }
149 const glterraindatabase*const* GetConfigData() const { return ConfigData; }
150 int GetConfigSize() const { return ConfigSize; }
151 private:
152 int Index;
153 const glterrainprototype* Base;
154 glterraindatabase** ConfigData;
155 glterraindatabase** ConfigTable[CONFIG_TABLE_SIZE];
156 int ConfigSize;
157 glterrainspawner Spawner;
158 cchar* ClassID;
160 public:
161 EventHandlerMap mOnEvents;
164 class glterrain : public lterrain, public gterrain
166 public:
167 friend class databasecreator<glterrain>;
168 typedef glterrainprototype prototype;
169 typedef glterraindatabase database;
171 virtual ~glterrain () {}
173 virtual void Save(outputfile&) const;
174 virtual void Load(inputfile&);
175 virtual int GetEntryDifficulty() const { return 1; }
176 int GetType() const { return GetProtoType()->GetIndex(); }
177 inline cchar *GetTypeID () const { return GetProtoType()->GetClassID(); }
178 inline truth IsOfType (cchar *tname) const { return (tname ? (strcmp(tname, GetProtoType()->GetClassID()) == 0) : false); }
179 inline truth IsOfType (cfestring &tname) const { return (tname.Compare(GetProtoType()->GetClassID()) == 0); }
180 const database* GetDataBase() const { return DataBase; }
181 DATA_BASE_VALUE(const prototype*, ProtoType);
182 DATA_BASE_VALUE(int, Config);
183 DATA_BASE_TRUTH(UsesLongArticle);
184 DATA_BASE_VALUE(cfestring&, Adjective);
185 DATA_BASE_TRUTH(UsesLongAdjectiveArticle);
186 DATA_BASE_VALUE(cfestring&, NameSingular);
187 DATA_BASE_VALUE(cfestring&, NamePlural);
188 DATA_BASE_VALUE(cfestring&, PostFix);
189 DATA_BASE_VALUE(int, ArticleMode);
190 virtual DATA_BASE_VALUE(const fearray<sLong>&, MainMaterialConfig);
191 DATA_BASE_VALUE(const fearray<sLong>&, SecondaryMaterialConfig);
192 virtual DATA_BASE_VALUE(const fearray<sLong>&, MaterialConfigChances);
193 virtual DATA_BASE_VALUE(sLong, MaterialConfigChanceSum);
194 DATA_BASE_VALUE(int, OKVisualEffects);
195 virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorB, int);
196 virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorC, int);
197 virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorD, int);
198 virtual DATA_BASE_VALUE(cfestring&, SitMessage);
199 DATA_BASE_TRUTH(ShowMaterial);
200 DATA_BASE_VALUE(int, Walkability);
201 DATA_BASE_TRUTH(UseBorderTiles);
202 DATA_BASE_VALUE(int, BorderTilePriority);
203 virtual int GetAttachedGod() const;
204 virtual int GetTheoreticalWalkability() const { return DataBase->Walkability; }
205 void Draw(blitdata&) const;
206 virtual truth IsAnimated() const;
208 inline cchar *GetClassID () const { return (FindProtoType() ? FindProtoType()->GetClassID() : ""); }
209 virtual const prototype* FindProtoType() const { return &ProtoType; }
211 protected:
212 virtual void InstallDataBase(int);
213 virtual int GetGraphicsContainerIndex() const;
214 virtual v2 GetBitmapPos(int) const;
215 v2 GetBorderBitmapPos(v2, int) const;
216 virtual void ModifyAnimationFrames(int&) const;
217 static const prototype ProtoType;
218 const database* DataBase;
221 struct olterraindatabase : public lterraindatabase
223 typedef olterrainprototype prototype;
224 void InitDefaults (const olterrainprototype *NewProtoType, int NewConfig, cfestring &acfgstrname);
225 truth AllowRandomInstantiation() const;
226 const prototype* ProtoType;
227 festring DigMessage;
228 int RestModifier;
229 festring RestMessage;
230 sLong StorageVolume;
231 int HPModifier;
232 v2 OpenBitmapPos;
233 v2 WindowBitmapPos;
234 fearray<contentscript<item> > LeftOverItems;
235 truth CreateDivineConfigurations;
236 truth CanBeDestroyed;
237 truth IsUpLink;
238 truth CreateLockConfigurations;
239 truth IsAlwaysTransparent;
240 truth ShowThingsUnder;
241 truth IsWall;
242 truth CreateWindowConfigurations;
243 truth IsSafeToCreateDoor;
246 class olterrainprototype
248 public:
249 friend class databasecreator<olterrain>;
251 olterrainprototype(const olterrainprototype*, olterrainspawner, cchar*);
252 virtual ~olterrainprototype () {}
254 olterrain* Spawn(int Config = 0, int SpecialFlags = 0) const { return Spawner(Config, SpecialFlags); }
255 olterrain* SpawnAndLoad(inputfile&) const;
256 cchar* GetClassID() const { return ClassID; }
257 int GetIndex() const { return Index; }
258 inline cchar *GetTypeID () const { return ClassID; }
259 inline truth IsOfType (cchar *tname) const { return (tname ? (strcmp(tname, ClassID) == 0) : false); }
260 inline truth IsOfType (cfestring &tname) const { return (tname.Compare(ClassID) == 0); }
261 const olterrainprototype* GetBase() const { return Base; }
262 int CreateSpecialConfigurations(olterraindatabase**, int, int);
263 const olterraindatabase* ChooseBaseForConfig(olterraindatabase** TempConfig, int, int) { return *TempConfig; }
264 const olterraindatabase*const* GetConfigData() const { return ConfigData; }
265 int GetConfigSize() const { return ConfigSize; }
266 private:
267 int Index;
268 const olterrainprototype* Base;
269 olterraindatabase** ConfigData;
270 olterraindatabase** ConfigTable[CONFIG_TABLE_SIZE];
271 int ConfigSize;
272 olterrainspawner Spawner;
273 cchar* ClassID;
275 public:
276 EventHandlerMap mOnEvents;
279 class olterrain : public lterrain, public oterrain
281 public:
282 friend class databasecreator<olterrain>;
283 typedef olterrainprototype prototype;
284 typedef olterraindatabase database;
286 virtual ~olterrain () {}
288 virtual void Save(outputfile&) const;
289 virtual void Load(inputfile&);
290 virtual truth Enter(truth) const;
291 virtual void BeKicked(character*, int, int);
292 virtual truth IsDoor() const { return false; }
293 virtual truth HasEatEffect() const { return false; }
294 virtual truth HasDrinkEffect() const { return false; }
295 virtual truth Eat(character*) { return false; }
296 virtual truth Drink(character*) { return false; }
297 virtual void Lock() { }
298 virtual truth IsLocked() const { return false; }
299 virtual void CreateBoobyTrap() { }
300 virtual void HasBeenHitByItem(character*, item*, int) { }
301 virtual void Break();
302 int GetHP() const { return HP; }
303 void EditHP(int What) { HP += What; }
304 virtual void ReceiveDamage(character*, int, int);
305 int GetType() const { return GetProtoType()->GetIndex(); }
306 inline cchar *GetTypeID () const { return GetProtoType()->GetClassID(); }
307 inline truth IsOfType (cchar *tname) const { return (tname ? (strcmp(tname, GetProtoType()->GetClassID()) == 0) : false); }
308 inline truth IsOfType (cfestring &tname) const { return (tname.Compare(GetProtoType()->GetClassID()) == 0); }
309 const database* GetDataBase() const { return DataBase; }
310 void ShowRestMessage(character*) const;
311 DATA_BASE_VALUE(const prototype*, ProtoType);
312 DATA_BASE_VALUE(int, Config);
313 DATA_BASE_TRUTH(UsesLongArticle);
314 DATA_BASE_VALUE(cfestring&, Adjective);
315 DATA_BASE_TRUTH(UsesLongAdjectiveArticle);
316 DATA_BASE_VALUE(cfestring&, NameSingular);
317 DATA_BASE_VALUE(cfestring&, NamePlural);
318 DATA_BASE_VALUE(cfestring&, PostFix);
319 DATA_BASE_VALUE(int, ArticleMode);
320 virtual DATA_BASE_VALUE(const fearray<sLong>&, MainMaterialConfig);
321 DATA_BASE_VALUE(const fearray<sLong>&, SecondaryMaterialConfig);
322 virtual DATA_BASE_VALUE(const fearray<sLong>&, MaterialConfigChances);
323 virtual DATA_BASE_VALUE(sLong, MaterialConfigChanceSum);
324 DATA_BASE_VALUE(int, OKVisualEffects);
325 virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorB, int);
326 virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorC, int);
327 virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorD, int);
328 virtual DATA_BASE_VALUE(cfestring&, SitMessage);
329 DATA_BASE_TRUTH(ShowMaterial);
330 DATA_BASE_VALUE(cfestring&, DigMessage);
331 truth CanBeDestroyed() const;
332 DATA_BASE_VALUE(int, RestModifier);
333 DATA_BASE_VALUE(cfestring&, RestMessage);
334 DATA_BASE_TRUTH(IsUpLink);
335 DATA_BASE_VALUE(sLong, StorageVolume);
336 DATA_BASE_VALUE(int, HPModifier);
337 DATA_BASE_TRUTH(IsSafeToCreateDoor);
338 DATA_BASE_VALUE_WITH_PARAMETER(v2, OpenBitmapPos, int);
339 DATA_BASE_TRUTH(UseBorderTiles);
340 DATA_BASE_VALUE(int, BorderTilePriority);
341 virtual DATA_BASE_VALUE(int, Walkability);
342 DATA_BASE_TRUTH(IsAlwaysTransparent);
343 DATA_BASE_TRUTH(CreateWindowConfigurations);
344 DATA_BASE_VALUE(v2, WindowBitmapPos);
345 DATA_BASE_VALUE(const fearray<contentscript<item> >&, LeftOverItems);
346 DATA_BASE_TRUTH(IsWall);
347 virtual void SetAttachedArea(int) { }
348 virtual void SetAttachedEntry(int) { }
349 virtual int GetAttachedArea () const { return 0; }
350 virtual int GetAttachedEntry () const { return 0; }
351 virtual void SetText(cfestring&) { }
352 virtual festring GetText() const;
353 virtual void SetItemsInside(const fearray<contentscript<item> >&, int) { }
354 int GetStrengthValue() const;
355 virtual void SignalVolumeAndWeightChange() { HP = CalculateMaxHP(); }
356 int CalculateMaxHP();
357 virtual int GetAttachedGod() const;
358 void SetConfig(int, int = 0);
359 god* GetMasterGod() const;
360 virtual truth IsTransparent() const;
361 virtual void Draw(blitdata&) const;
362 virtual int GetTheoreticalWalkability() const { return DataBase->Walkability; }
363 virtual void BeDestroyed() { Break(); }
364 virtual void ReceiveAcid(material*, sLong);
365 virtual void SignalRustLevelChange();
366 virtual truth IsFountainWithWater() const { return false; }
367 truth ShowThingsUnder() const;
368 truth WillBeDestroyedBy(ccharacter*) const;
369 virtual void PreProcessForBone() { }
370 virtual void PostProcessForBone() { }
371 virtual void FinalProcessForBone() { }
372 virtual void RestoreHP() { HP = CalculateMaxHP(); }
373 virtual truth IsAnimated() const;
374 virtual truth VomitingIsDangerous(ccharacter*) const { return false; }
375 virtual void AddSpecialCursors() { }
376 virtual truth IsWard() const { return false; }
378 inline cchar *GetClassID () const { return (FindProtoType() ? FindProtoType()->GetClassID() : ""); }
379 virtual const prototype* FindProtoType() const { return &ProtoType; }
381 protected:
382 virtual v2 GetBitmapPos(int) const;
383 v2 GetBorderBitmapPos(v2, int) const;
384 virtual void ModifyAnimationFrames(int&) const;
385 virtual void InstallDataBase(int);
386 virtual int GetGraphicsContainerIndex() const;
387 static const prototype ProtoType;
388 const database* DataBase;
389 int HP;
392 #ifdef __FILE_OF_STATIC_LTERRAIN_PROTOTYPE_DEFINITIONS__
393 #define LTERRAIN_PROTO(name, base, protobase)\
394 template<> const protobase##prototype\
395 name##sysbase::ProtoType(&base::ProtoType,\
396 (protobase##spawner)(&name##sysbase::Spawn),\
397 #name);
398 #else
399 #define LTERRAIN_PROTO(name, base, protobase)
400 #endif
402 #define LTERRAIN(name, base, protobase)\
403 class name;\
404 typedef sysbase<name, base, protobase##prototype> name##sysbase;\
405 LTERRAIN_PROTO(name, base, protobase)\
406 class name : public name##sysbase
408 #define GLTERRAIN(name, base) LTERRAIN(name, base, glterrain)
409 #define OLTERRAIN(name, base) LTERRAIN(name, base, olterrain)
412 #endif