`RandomChance` type, and two new item fields: `MagicEffectChance`, `MagicEffectDuration`
[k8-i-v-a-n.git] / src / game / level.h
blobefc228fa1441b7e60e464d9132b05588b3d0992e
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
13 #ifndef __LEVEL_H__
14 #define __LEVEL_H__
16 #include "ivancommon.h"
18 #include <vector>
19 #include <queue>
20 #include <set>
22 #include "area.h"
23 #include "square.h"
24 #include "ivandef.h"
26 class levelscript;
27 class roomscript;
28 class squarescript;
29 class glterrain;
30 class olterrain;
31 class dungeon;
32 class lsquare;
33 class room;
34 class item;
35 class liquid;
36 class gas;
37 class level;
38 class material;
39 class team;
40 struct node;
41 struct emitter;
42 template <class type> struct fearray;
44 struct nodepointerstorer
46 nodepointerstorer(node* Node) : Node(Node) { }
47 bool operator<(const nodepointerstorer&) const;
48 node* Node;
51 struct spawnresult
53 ccharacter* Pioneer;
54 int Seen;
57 typedef std::priority_queue<nodepointerstorer> nodequeue;
58 typedef std::vector<item*> itemvector;
59 typedef std::vector<character*> charactervector;
60 typedef std::vector<emitter> emittervector;
61 typedef std::vector<feuLong> sunemittervector;
62 typedef character* (*characterspawner)(int, int);
64 struct node
66 node(int x, int y, lsquare* Square) : Square(Square), Pos(x, y) { }
67 void CalculateNextNodes();
68 lsquare* Square;
69 node* Last;
70 v2 Pos;
71 sLong Distance;
72 sLong Remaining;
73 sLong TotalDistanceEstimate;
74 sLong Diagonals;
75 truth InNodeQueue;
76 truth Processed;
77 static node*** NodeMap;
78 static int RequiredWalkability;
79 static ccharacter* SpecialMover;
80 static v2 To;
81 static uChar** WalkabilityMap;
82 static int XSize, YSize;
83 static nodequeue* NodeQueue;
86 struct explosion
88 character* Terrorist;
89 festring DeathMsg;
90 v2 Pos;
91 feuLong ID;
92 int Strength;
93 int RadiusSquare;
94 int Size;
95 truth HurtNeutrals;
98 struct beamdata
100 beamdata(character*, cfestring&, int, feuLong);
101 beamdata(character*, cfestring&, v2, col16, int, int, int, feuLong);
102 character* Owner;
103 festring DeathMsg;
104 v2 StartPos;
105 col16 BeamColor;
106 int BeamEffect;
107 int Direction;
108 int Range;
109 feuLong SpecialParameters;
112 inline beamdata::beamdata
114 character* Owner,
115 cfestring& DeathMsg,
116 int Direction,
117 feuLong SpecialParameters
119 Owner(Owner),
120 DeathMsg(DeathMsg),
121 Direction(Direction),
122 SpecialParameters(SpecialParameters)
125 inline beamdata::beamdata
127 character* Owner,
128 cfestring& DeathMsg,
129 v2 StartPos,
130 col16 BeamColor,
131 int BeamEffect,
132 int Direction,
133 int Range,
134 feuLong SpecialParameters
136 Owner(Owner),
137 DeathMsg(DeathMsg),
138 StartPos(StartPos),
139 BeamColor(BeamColor),
140 BeamEffect(BeamEffect),
141 Direction(Direction),
142 Range(Range),
143 SpecialParameters(SpecialParameters)
146 struct maze {
147 maze (int x, int y) : MazeXSize(x+2), MazeYSize(y+2) { MazeVector.resize(MazeXSize*MazeYSize); }
148 void CreateMaze ();
149 void InitializeMaze ();
150 std::vector<truth> MazeKernel; // returns only the mazey bit in the middle (the kernel), without the exterior walls. The kernel size is the input size of maze - 2 for each dimension.
151 void CarveMaze (int, int); // Carves the maze
152 void StripMazeHusk (); // Removes the husk (skin and shell), and populates MazeKernel with the kernel.
153 const uint MazeXSize; // XSize of the MazeVector
154 const uint MazeYSize; // YSize of the MazeVector
155 private:
156 std::vector<truth> MazeVector; // Consists of the outer buffer (empty, called the skin) and the shell wall (next layer in, all full). Together they comprise the husk.
159 class level : public area
161 public:
162 level();
163 virtual ~level();
165 truth Generate(int);
166 v2 GetRandomSquare(ccharacter* = 0, int = 0, const rect* = 0) const;
167 void GenerateMonsters();
168 lsquare* GetLSquare(v2 Pos) const { return Map[Pos.X][Pos.Y]; }
169 lsquare* GetLSquare(int x, int y) const { return Map[x][y]; }
170 void GenerateTunnel(int, int, int, int, truth);
171 void ExpandPossibleRoute(int, int, int, int, truth);
172 void ExpandStillPossibleRoute(int, int, int, int, truth);
173 void Save(outputfile&) const;
174 void Load(inputfile&);
175 void FiatLux();
176 int GetIdealPopulation() const { return IdealPopulation; }
177 double GetDifficulty() const { return Difficulty; }
178 void GenerateNewMonsters(int, truth = true);
179 void AttachPos(int, int);
180 void AttachPos(v2 Pos) { AttachPos(Pos.X, Pos.Y); }
181 void CreateItems(int);
182 truth MakeRoom(const roomscript*);
183 void ParticleTrail(v2, v2);
184 festring GetLevelMessage() { return LevelMessage; }
185 void SetLevelMessage(cfestring& What) { LevelMessage = What; }
186 void SetLevelScript(const levelscript* What) { LevelScript = What; }
187 truth IsOnGround() const;
188 truth EarthquakesAffectTunnels() const;
189 const levelscript* GetLevelScript() const { return LevelScript; }
190 int GetLOSModifier() const;
191 room* GetRoom(int) const;
192 void SetRoom(int, room*);
193 void AddRoom(room*);
194 void Explosion(character*, cfestring&, v2, int, truth = true);
195 truth CollectCreatures(charactervector&, character*, truth);
196 void ApplyLSquareScript(const squarescript*);
197 virtual void Draw(truth) const;
198 v2 GetEntryPos(ccharacter*, int) const;
199 void GenerateRectangularRoom(std::vector<v2>&, std::vector<v2>&, std::vector<v2>&, const roomscript*, room*, v2, v2);
200 void Reveal();
201 static void (level::*GetBeam(int))(beamdata&);
202 void ParticleBeam(beamdata&);
203 void LightningBeam(beamdata&);
204 void ShieldBeam(beamdata&);
205 dungeon* GetDungeon() const { return Dungeon; }
206 void SetDungeon(dungeon* What) { Dungeon = What; }
207 int GetIndex() const { return Index; }
208 void SetIndex(int What) { Index = What; }
209 truth DrawExplosion(const explosion*) const;
210 int TriggerExplosions(int);
211 lsquare*** GetMap() const { return Map; }
212 v2 GetNearestFreeSquare(ccharacter*, v2, truth = true) const;
213 v2 FreeSquareSeeker(ccharacter*, v2, v2, int, truth) const;
214 v2 GetFreeAdjacentSquare(ccharacter*, v2, truth) const;
215 static void (level::*GetBeamEffectVisualizer(int))(const fearray<lsquare*>&, col16) const;
216 void ParticleVisualizer(const fearray<lsquare*>&, col16) const;
217 void LightningVisualizer(const fearray<lsquare*>&, col16) const;
218 truth PreProcessForBone();
219 truth PostProcessForBone();
220 void FinalProcessForBone();
221 truth GenerateDungeon(int);
222 truth GenerateDesert();
223 truth GenerateJungle();
224 truth GenerateSteppe();
225 truth GenerateLeafyForest();
226 truth GenerateEvergreenForest();
227 truth GenerateTundra();
228 truth GenerateGlacier();
229 void CreateTunnelNetwork(int, int, int, int, v2);
230 void SetWalkability(v2 Pos, int What) { WalkabilityMap[Pos.X][Pos.Y] = What; }
231 node* FindRoute(v2, v2, const std::set<v2>&, int, ccharacter* = 0);
232 void AddToAttachQueue(v2);
233 void CollectEverything(itemvector&, charactervector&);
234 void CreateGlobalRain(liquid*, v2);
235 void CheckSunLight();
236 col24 GetSunLightEmitation() const { return SunLightEmitation; }
237 void InitSquarePartEmitationTicks();
238 col24 GetAmbientLuminance() const { return AmbientLuminance; }
239 void ForceEmitterNoxify(const emittervector&) const;
240 void ForceEmitterEmitation(const emittervector&, const sunemittervector&, feuLong = 0) const;
241 void UpdateLOS();
242 void EnableGlobalRain();
243 void DisableGlobalRain();
244 void InitLastSeen();
245 lsquare** GetSquareStack() const { return SquareStack; }
246 col24 GetNightAmbientLuminance() const { return NightAmbientLuminance; }
247 int DetectMaterial(cmaterial*);
248 void BlurMemory();
249 void CalculateLuminances();
250 int AddRadiusToSquareStack(v2, sLong) const;
251 olterrain* GetRandomFountainWithWater(olterrain*) const;
252 int GetEnchantmentMinusChance() { return EnchantmentMinusChance; }
253 int GetEnchantmentPlusChance() { return EnchantmentPlusChance; }
254 void Amnesia(int);
255 spawnresult SpawnMonsters(characterspawner, team*, v2, int = 0, int = 1, truth = false);
256 void AddSpecialCursors();
257 void GasExplosion(gas* GasMaterial, lsquare* Square, character* Terrorist=0);
259 // check for special levels
260 truth IsGCIvanLevel () const;
262 truth IsUTVesanaLevel () const;
263 truth IsGCEnnerLevel () const;
264 truth IsGCElpuriLevel () const; // also nicknamed "dark level"
265 truth IsGCOreeLevel () const;
266 truth IsSolicitusLevel () const;
267 truth IsAlienQueenLevel () const;
270 protected:
271 truth GenerateLanterns(int, int, int) const;
272 truth GenerateWindows(int, int) const;
273 void CreateRoomSquare(glterrain*, olterrain*, int, int, int, int) const;
274 void EmitSunBeams();
275 void EmitSunBeam(v2, feuLong, int) const;
276 void ChangeSunLight();
277 void EmitSunLight(v2);
278 lsquare*** Map;
279 const levelscript* LevelScript;
280 festring LevelMessage;
281 std::vector<v2> Door;
282 std::vector<room*> Room;
283 int IdealPopulation;
284 int MonsterGenerationInterval;
285 double Difficulty;
286 dungeon* Dungeon;
287 int Index;
288 std::vector<explosion*> ExplosionQueue;
289 std::vector<truth> PlayerHurt;
290 node*** NodeMap;
291 uChar** WalkabilityMap;
292 std::vector<v2> AttachQueue;
293 liquid* GlobalRainLiquid;
294 v2 GlobalRainSpeed;
295 col24 SunLightEmitation;
296 v2 SunLightDirection;
297 col24 AmbientLuminance;
298 static feuLong NextExplosionID;
299 lsquare** SquareStack;
300 col24 NightAmbientLuminance;
301 int EnchantmentMinusChance;
302 int EnchantmentPlusChance;
305 outputfile& operator<<(outputfile&, const level*);
306 inputfile& operator>>(inputfile&, level*&);
308 #endif