cosmetix
[k8-i-v-a-n.git] / src / game / materia.h
blobb2dbc1bcab85bdb9bdbea1492daf4b3341969ecc
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 __MATERIA_H__
13 #define __MATERIA_H__
15 #include "ivancommon.h"
17 #include "script.h"
18 #include "ivandef.h"
19 #include "festring.h"
21 #define MAKE_MATERIAL material::MakeMaterial
23 class entity;
24 class bodypart;
25 class materialprototype;
26 template <class type> class databasecreator;
28 typedef material* (*materialspawner)(int, sLong, truth);
29 typedef material* (*materialcloner)(cmaterial*);
31 struct materialdatabase : public databasebase
33 typedef materialprototype prototype;
34 void InitDefaults (const materialprototype *NewProtoType, int NewConfig, cfestring &acfgstrname);
35 void PostProcess() { }
36 const prototype* ProtoType;
37 feuLong CategoryFlags;
38 feuLong BodyFlags;
39 feuLong InteractionFlags;
40 int StrengthValue;
41 int ConsumeType;
42 int Density;
43 int Color;
44 int RainColor;
45 sLong PriceModifier;
46 col24 Emitation;
47 int NutritionValue;
48 festring NameStem;
49 festring AdjectiveStem;
50 int Effect;
51 int ConsumeEndMessage;
52 int HitMessage;
53 sLong ExplosivePower;
54 alpha Alpha;
55 int Flexibility;
56 int SpoilModifier;
57 int EffectStrength;
58 int DigProductMaterial;
59 int ConsumeWisdomLimit;
60 int AttachedGod;
61 festring BreatheMessage;
62 int StepInWisdomLimit;
63 int RustModifier;
64 int Acidicity;
65 contentscript<item> NaturalForm;
66 int HardenedMaterial;
67 int SoftenedMaterial;
68 int IntelligenceRequirement;
69 int Stickiness;
70 truth DisablesPanicWhenConsumed;
71 truth BlockESP;
74 class materialprototype
76 public:
77 friend class databasecreator<material>;
79 materialprototype(const materialprototype*, materialspawner, materialcloner, cchar*);
80 virtual ~materialprototype () {}
82 material* Spawn(int Config, sLong Volume = 0) const { return Spawner(Config, Volume, false); }
83 material* SpawnAndLoad(inputfile&) const;
84 material* Clone(cmaterial* Material) const { return Cloner(Material); }
85 cchar* GetClassID() const { return ClassID; }
86 int GetIndex() const { return Index; }
87 const materialprototype* GetBase() const { return Base; }
88 int CreateSpecialConfigurations(materialdatabase**, int Configs, int) { return Configs; }
89 const materialdatabase* ChooseBaseForConfig(materialdatabase** TempConfig, int, int) { return *TempConfig; }
90 const materialdatabase*const* GetConfigData() const { return ConfigData; }
91 int GetConfigSize() const { return ConfigSize; }
92 private:
93 int Index;
94 const materialprototype* Base;
95 materialdatabase** ConfigData;
96 materialdatabase** ConfigTable[CONFIG_TABLE_SIZE];
97 int ConfigSize;
98 materialspawner Spawner;
99 materialcloner Cloner;
100 cchar* ClassID;
102 public:
103 EventHandlerMap mOnEvents;
106 class material
108 public:
109 friend class databasecreator<material>;
110 typedef materialprototype prototype;
111 typedef materialdatabase database;
113 public:
114 material(int NewConfig, sLong InitVolume = 0, truth Load = false) : MotherEntity(0) { Initialize(NewConfig, InitVolume, Load); }
115 material() : MotherEntity(0) { }
116 virtual ~material() { }
118 void AddName(festring&, truth = false, truth = true) const;
119 festring GetName(truth = false, truth = true) const;
120 material* TakeDipVolumeAway();
121 material* TakeAllVolumeAway();
122 virtual void Save(outputfile&) const;
123 virtual void Load(inputfile&);
124 truth Effect(character*, int, sLong);
125 virtual material* EatEffect(character*, sLong);
126 truth HitEffect(character*, bodypart*);
127 virtual col16 GetSkinColor() const { return GetColor(); }
128 virtual void SetSkinColor(int) { }
129 sLong GetRawPrice() const;
130 truth CanBeDug(material* ShovelMaterial) const;
131 virtual truth HasBe() const { return false; }
132 virtual void Be(feuLong) { }
133 int GetType() const { return GetProtoType()->GetIndex(); }
134 virtual void AddConsumeEndMessage(character*) const;
135 DATA_BASE_VALUE(const prototype*, ProtoType);
136 DATA_BASE_VALUE(int, Config);
137 DATA_BASE_VALUE(feuLong, CommonFlags);
138 DATA_BASE_VALUE(feuLong, NameFlags);
139 DATA_BASE_VALUE(feuLong, CategoryFlags);
140 DATA_BASE_VALUE(feuLong, BodyFlags);
141 DATA_BASE_VALUE(feuLong, InteractionFlags);
142 virtual DATA_BASE_VALUE(int, StrengthValue);
143 DATA_BASE_VALUE(int, ConsumeType);
144 DATA_BASE_VALUE(int, Density);
145 DATA_BASE_VALUE(int, Color);
146 DATA_BASE_VALUE(int, RainColor);
147 DATA_BASE_VALUE(sLong, PriceModifier);
148 DATA_BASE_VALUE(col24, Emitation);
149 DATA_BASE_VALUE(int, NutritionValue);
150 DATA_BASE_VALUE(cfestring&, NameStem);
151 DATA_BASE_VALUE(cfestring&, AdjectiveStem);
152 DATA_BASE_VALUE(int, Effect);
153 DATA_BASE_VALUE(int, ConsumeEndMessage);
154 DATA_BASE_VALUE(int, HitMessage);
155 DATA_BASE_VALUE(sLong, ExplosivePower);
156 DATA_BASE_VALUE(alpha, Alpha);
157 DATA_BASE_VALUE(int, Flexibility);
158 DATA_BASE_VALUE(int, SpoilModifier);
159 DATA_BASE_VALUE(int, EffectStrength);
160 DATA_BASE_VALUE(int, DigProductMaterial);
161 DATA_BASE_VALUE(int, ConsumeWisdomLimit);
162 DATA_BASE_VALUE(int, AttachedGod);
163 DATA_BASE_VALUE(int, RustModifier);
164 DATA_BASE_VALUE(int, Acidicity);
165 DATA_BASE_VALUE(const contentscript<item>&, NaturalForm);
166 DATA_BASE_VALUE(int, IntelligenceRequirement);
167 DATA_BASE_VALUE(int, Stickiness);
168 const database* GetDataBase() const { return DataBase; }
169 material* SpawnMore() const { return GetProtoType()->Spawn(GetConfig(), Volume); }
170 material* SpawnMore(sLong Volume) const { return GetProtoType()->Spawn(GetConfig(), Volume); }
171 sLong GetTotalExplosivePower() const;
172 static material* MakeMaterial(int, sLong = 0);
173 virtual truth IsFlesh() const { return false; }
174 virtual truth IsLiquid() const { return false; }
175 virtual cchar* GetConsumeVerb() const;
176 entity* GetMotherEntity() const { return MotherEntity; }
177 void SetMotherEntity(entity* What) { MotherEntity = What; }
178 truth IsSameAs(cmaterial* What) const { return What->GetConfig() == GetConfig(); }
179 truth IsTransparent() const { return GetAlpha() != 255; }
180 virtual sLong GetTotalNutritionValue() const;
181 virtual truth IsVeryCloseToSpoiling() const { return false; }
182 virtual void AddWetness(sLong) { }
183 virtual int GetSpoilLevel() const { return 0; }
184 virtual void ResetSpoiling() { }
185 truth CanBeEatenByAI(ccharacter*) const;
186 virtual void SetSpoilCounter(int) { }
187 DATA_BASE_VALUE(cfestring&, BreatheMessage);
188 truth BreatheEffect(character*);
189 virtual truth SkinColorIsSparkling() const { return IsSparkling(); }
190 virtual void SetSkinColorIsSparkling(truth) { }
191 DATA_BASE_VALUE(int, StepInWisdomLimit);
192 virtual void SetRustLevel(int) { }
193 virtual int GetRustLevel() const { return NOT_RUSTED; }
194 virtual int GetRustData() const { return NOT_RUSTED; }
195 virtual truth TryToRust(sLong, sLong = 0) { return false; }
196 static const database* GetDataBase(int);
197 virtual truth CanSpoil() const { return false; }
198 truth IsSolid() const { return !IsLiquid(); }
199 /* A dummy materialpredicate */
200 truth True() const { return true; }
201 void FinishConsuming(character*);
202 sLong GetVolume() const { return Volume; }
203 sLong GetWeight() const { return Volume ? sLong(double(Volume) * GetDensity() / 1000) : 0; }
204 void EditVolume(sLong What) { SetVolume(Volume + What); }
205 void SetVolume(sLong);
206 void SetVolumeNoSignals(sLong What) { Volume = What; }
207 virtual truth IsPowder() const { return false; }
208 static item* CreateNaturalForm(int, sLong);
209 item* CreateNaturalForm(sLong) const;
210 virtual truth IsInfectedByLeprosy() const { return false; }
211 virtual void SetIsInfectedByLeprosy(truth) { }
212 virtual truth AddRustLevelDescription(festring&, truth) const { return false; }
213 int GetHardenedMaterial(citem*) const;
214 int GetSoftenedMaterial(citem*) const;
215 int GetHardenModifier(citem*) const;
216 virtual int GetSpoilPercentage() const { return 0; }
217 virtual truth Spoils() const { return false; }
218 virtual truth IsExplosive() const;
219 virtual truth IsSparkling() const;
220 material* Duplicate() const { return DataBase->ProtoType->Clone(this); }
221 truth IsStuckTo(ccharacter*) const;
222 DATA_BASE_TRUTH(DisablesPanicWhenConsumed);
223 DATA_BASE_TRUTH(BlockESP);
225 inline cchar *GetClassID () const { return (FindProtoType() ? FindProtoType()->GetClassID() : ""); }
226 virtual const prototype* FindProtoType() const { return &ProtoType; }
228 protected:
229 virtual void PostConstruct() { }
230 void Initialize(int, sLong, truth);
231 static const prototype ProtoType;
232 const database* DataBase;
233 entity* MotherEntity;
234 sLong Volume;
237 template <class type, class base>
238 class materialsysbase : public base
240 public:
241 typedef materialsysbase<type, base> mybase;
242 static type* Spawn(int Config = 0, sLong Volume = 0, truth Load = false)
244 type* M = new type;
245 M->Initialize(Config, Volume, Load);
246 return M;
248 static material* Clone(const type* T) { return new type(*T); }
250 virtual ~materialsysbase () {}
252 inline cchar *GetClassID () const { return (FindProtoType() ? FindProtoType()->GetClassID() : ""); }
253 virtual const materialprototype* FindProtoType() const { return &ProtoType; }
254 static const materialprototype ProtoType;
257 #ifdef __FILE_OF_STATIC_MATERIAL_PROTOTYPE_DEFINITIONS__
258 #define MATERIAL_PROTO(name, base)\
259 template<> const materialprototype\
260 name##sysbase::ProtoType(&base::ProtoType,\
261 (materialspawner)(&name##sysbase::Spawn),\
262 (materialcloner)(&name##sysbase::Clone), #name);
263 #else
264 #define MATERIAL_PROTO(name, base)
265 #endif
267 #define MATERIAL(name, base)\
268 class name;\
269 typedef materialsysbase<name, base> name##sysbase;\
270 MATERIAL_PROTO(name, base)\
271 class name : public name##sysbase
273 #endif