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"
23 # define LIGHT_BORDER (80)
41 typedef std::vector
<item
*> itemvector
;
42 typedef truth (item::*sorter
)(ccharacter
*) const;
46 emitter(feuLong ID
, col24 Emitation
) : ID(ID
), Emitation(Emitation
) { }
47 explicit emitter() { }
52 inline feuLong
MakeEmitterID(v2 Pos
)
54 return Pos
.X
+ (Pos
.Y
<< 8);
57 inline v2
ExtractPosFromEmitterID(feuLong ID
)
59 return v2(ID
& 0xFF, (ID
>> 8) & 0xFF);
62 typedef std::vector
<emitter
> emittervector
;
64 outputfile
& operator<<(outputfile
&, const emitter
&);
65 inputfile
& operator>>(inputfile
&, emitter
&);
69 static truth
Handler(int, int);
70 static lsquare
*** Map
;
75 static truth
Handler(int, int);
76 static lsquare
*** Map
;
77 static ccharacter
* Character
;
80 struct stackcontroller
82 static lsquare
*** Map
;
83 static lsquare
** Stack
;
84 static sLong StackIndex
;
85 static int LevelXSize
, LevelYSize
;
91 static void PrepareShiftedTick();
93 static feuLong ShiftedTick
[4];
94 static feuLong ShiftedQuadriTick
[4];
97 class lsquare
: public square
101 friend struct loscontroller
;
102 friend struct sunbeamcontroller
;
103 friend struct areacontroller
;
104 friend struct emitationcontroller
;
105 friend struct noxifycontroller
;
111 virtual void AddCharacter(character
*);
112 virtual void RemoveCharacter();
113 stack
* GetStack() const { return Stack
; }
114 void AlterLuminance(feuLong
, col24
);
115 void Emitate() { Emitate(Emitation
); }
116 void Emitate(col24
, feuLong
= 0);
118 truth
Open(character
*);
119 truth
Close(character
*);
120 virtual void Save(outputfile
&) const;
121 virtual void Load(inputfile
&);
122 void SignalEmitationIncrease(col24
);
123 void SignalEmitationDecrease(col24
);
124 col24
GetEmitation() const { return Emitation
; }
125 void Noxify() { Noxify(Emitation
); }
126 void Noxify(col24
, feuLong
= 0);
127 truth
NoxifyEmitter(feuLong
);
128 cchar
* GetEngraved() const { return Engraved
; }
129 truth
Engrave(cfestring
&);
130 void UpdateMemorizedDescription(truth
= false);
131 truth
BeKicked(character
*, item
*, bodypart
*, double, double, int, int, truth
, truth
);
132 int GetDivineMaster() const;
133 void Draw(blitdata
&) const;
134 void UpdateMemorized();
135 truth
CanBeDug() const;
136 virtual gterrain
* GetGTerrain() const { return GLTerrain
; }
137 virtual oterrain
* GetOTerrain() const { return OLTerrain
; }
138 glterrain
* GetGLTerrain() const { return GLTerrain
; }
139 olterrain
* GetOLTerrain() const { return OLTerrain
; }
140 void ChangeLTerrain(glterrain
*, olterrain
*);
141 level
* GetLevel() const { return static_cast<level
*>(AreaUnder
); }
142 void SetLevelUnder(level
* What
) { AreaUnder
= What
; }
143 void ChangeGLTerrain(glterrain
*);
144 void ChangeOLTerrain(olterrain
*);
145 void SetLTerrain(glterrain
*, olterrain
*);
146 void ApplyScript(const squarescript
*, room
*);
147 virtual truth
CanBeSeenByPlayer(truth
= false) const;
148 virtual truth
CanBeSeenFrom(v2
, sLong
, truth
= false) const ;
149 void StepOn(character
*, lsquare
**);
150 uInt
GetRoomIndex() const { return RoomIndex
; }
151 void SetRoomIndex(uInt What
) { RoomIndex
= What
; }
152 void ReceiveVomit(character
*, liquid
*);
153 room
* GetRoom() const { return RoomIndex
? GetLevel()->GetRoom(RoomIndex
) : 0; }
154 void SetTemporaryEmitation(col24
);
155 col24
GetTemporaryEmitation() const { return TemporaryEmitation
; }
156 void ChangeOLTerrainAndUpdateLights(olterrain
*);
157 void DrawParticles(sLong
, truth
= true);
158 v2
DrawLightning(v2
, sLong
, int, truth
= true);
159 truth
DipInto(item
*, character
*);
160 truth
TryKey(item
*, character
*);
161 void SignalSeen(feuLong
);
162 void CalculateLuminance();
163 void DrawStaticContents(blitdata
&) const;
164 void DrawMemorized(blitdata
&) const;
165 void DrawMemorizedCharacter(blitdata
&) const;
166 void SendMemorizedUpdateRequest();
167 lsquare
* GetNeighbourLSquare(int) const;
168 lsquare
* GetNearLSquare(v2 Pos
) const { return static_cast<lsquare
*>(AreaUnder
->GetSquare(Pos
)); }
169 truth
IsDangerous(ccharacter
*) const;
170 truth
IsScary(ccharacter
*) const;
171 stack
* GetStackOfAdjacentSquare(int) const;
172 void KickAnyoneStandingHereAway();
173 truth
IsDark() const;
175 static truth (lsquare::*GetBeamEffect(int))(const beamdata
&);
176 truth
Polymorph(const beamdata
&);
177 truth
Strike(const beamdata
&);
178 truth
FireBall(const beamdata
&);
179 truth
Teleport(const beamdata
&);
180 truth
Haste(const beamdata
&);
181 truth
Slow(const beamdata
&);
182 truth
Confuse(const beamdata
&);
183 truth
Parasitize(const beamdata
&);
184 truth
InstillPanic(const beamdata
&);
185 truth
Resurrect(const beamdata
&);
186 truth
Invisibility(const beamdata
&);
187 truth
Duplicate(const beamdata
&);
188 truth
Lightning(const beamdata
&);
189 truth
DoorCreation(const beamdata
&);
190 truth
AcidRain(const beamdata
&);
191 truth
Necromancy(const beamdata
&);
192 int GetLevelIndex() const { return static_cast<level
*>(AreaUnder
)->GetIndex(); }
193 int GetDungeonIndex() const { return static_cast<level
*>(AreaUnder
)->GetDungeon()->GetIndex(); }
194 dungeon
* GetDungeon() const { return static_cast<level
*>(AreaUnder
)->GetDungeon(); }
195 truth
CheckKick(ccharacter
*) const;
196 void GetHitByExplosion(const explosion
*);
197 int GetSpoiledItems() const;
198 void SortAllItems(const sortdata
&);
199 truth
LowerEnchantment(const beamdata
&);
200 truth
SoftenMaterial(const beamdata
&);
201 void RemoveSmoke(smoke
*);
203 truth
IsFlyable() const { return !OLTerrain
|| (OLTerrain
->GetWalkability() & FLY
); }
204 truth
IsTransparent() const { return Flags
& IS_TRANSPARENT
; }
205 void SignalSmokeAlphaChange(int);
206 void ShowSmokeMessage() const;
207 void DisplaySmokeInfo(festring
&) const;
208 truth
IsDipDestination() const;
209 void ReceiveEarthQuakeDamage();
210 truth
CanBeFeltByPlayer() const;
211 void PreProcessForBone();
212 void PostProcessForBone(double&, int&);
213 void DisplayEngravedInfo(festring
&) const;
214 truth
EngravingsCanBeReadByPlayer();
215 truth
HasEngravings() const { return truth(Engraved
); }
216 void FinalProcessForBone();
217 truth
IsFreezed() const { return Flags
& FREEZED
; }
218 truth
IsDangerousToBreathe(ccharacter
*) const;
219 truth
IsScaryToBreathe(ccharacter
*) const;
220 int GetWalkability() const;
221 int GetTheoreticalWalkability() const { return OLTerrain
? OLTerrain
->GetTheoreticalWalkability() & GLTerrain
->GetTheoreticalWalkability() : GLTerrain
->GetTheoreticalWalkability(); }
222 virtual int GetSquareWalkability() const { return GetWalkability(); }
223 void CalculateGroundBorderPartners();
224 void RequestForGroundBorderPartnerUpdates();
225 void CalculateOverBorderPartners();
226 void RequestForOverBorderPartnerUpdates();
227 void SpillFluid(character
*, liquid
*, truth
= false, truth
= true);
228 void DisplayFluidInfo(festring
&) const;
229 void RemoveFluid(fluid
*);
230 fluid
* AddFluid(liquid
*);
231 void DrawStacks(blitdata
&) const;
232 truth
FluidIsVisible() const { return SmokeAlphaSum
< 175; }
233 void RemoveRain(rain
*);
234 void AddRain(liquid
*, v2
, int, truth
);
235 truth
IsInside() const { return Flags
& INSIDE
; }
236 void RemoveSunLight();
237 void CheckIfIsSecondarySunLightEmitter();
238 void CalculateNeighbourLSquares();
239 const emittervector
& GetEmitter() const { return Emitter
; }
240 void EnableGlobalRain();
241 void DisableGlobalRain();
242 void Freeze() { Flags
|= FREEZED
; }
243 void UnFreeze() { Flags
&= ~FREEZED
; }
245 void GetSideItemDescription(festring
&, truth
= false) const;
246 void AddSunLightEmitter(feuLong
);
247 void SendSunLightSignals();
248 const sunemittervector
& GetSunEmitter() const { return SunEmitter
; }
249 void ZeroReSunEmitatedFlags();
250 virtual truth
HasBeenSeen() const { return (Memorized
!= 0); }
251 truth
CalculateIsTransparent();
252 void CalculateSunLightLuminance(feuLong
);
253 void CreateMemorized();
254 truth
DetectMaterial(cmaterial
*) const;
255 void Reveal(feuLong
, truth
= false);
256 void DestroyMemorized();
257 void SwapMemorized(lsquare
*);
258 truth
HasNoBorderPartners() const;
259 lsquare
* GetRandomAdjacentSquare() const;
260 void SignalPossibleTransparencyChange();
261 truth
AddTrap(trap
*);
262 void RemoveTrap(trap
*);
263 void DisplayTrapInfo(festring
&) const;
264 void FillTrapVector(std::vector
<trap
*>&) const;
265 void ReceiveTrapDamage(character
*, int, int, int = YOURSELF
);
266 truth
HasDangerousTraps(ccharacter
*) const;
267 truth
HasDangerousFluids(ccharacter
*) const;
268 void AddLocationDescription(festring
&) const;
269 truth
VomitingIsDangerous(ccharacter
*) const;
270 bool TeleportAllSmokeAway();
271 bool TeleportAllFluidsAway();
272 bool TeleportAllTrapsAway();
273 void AddSpecialCursors();
274 inline truth
IsGoSeen () const { return mGoSeen
; }
275 inline void SetGoSeen (truth v
) { mGoSeen
= v
; }
277 void ChangeLuminance(col24
&, col24
);
278 void RemoveLuminance(col24
&);
279 void CalculateEmitation();
280 void UpdateStaticContentCache(col24
) const;
281 mutable struct staticcontentcache
283 staticcontentcache() : Bitmap(0), Luminance(0) { }
286 } StaticContentCache
;
291 emittervector Emitter
;
292 sunemittervector SunEmitter
;
293 glterrain
* GLTerrain
;
294 olterrain
* OLTerrain
;
297 bitmap
* FowMemorized
;
299 glterrain
** GroundBorderPartnerTerrain
;
300 feuLong GroundBorderPartnerInfo
;
301 olterrain
** OverBorderPartnerTerrain
;
302 feuLong OverBorderPartnerInfo
;
303 feuLong SquarePartEmitationTick
;
304 feuLong SquarePartLastSeen
;
307 lsquare
* NeighbourLSquare
[8];
308 col24 AmbientLuminance
;
309 col24 SunLightLuminance
;
310 col24 TemporaryEmitation
;
311 col24 SecondarySunLightEmitation
;
312 uShort LastExplosionID
;
317 inline truth
lsquare::IsDark() const
319 col24 Light
= Luminance
;
322 || ((Light
& 0xFF0000) < (LIGHT_BORDER
<< 16)
323 && (Light
& 0x00FF00) < (LIGHT_BORDER
<< 8)
324 && (Light
& 0x0000FF) < LIGHT_BORDER
));
327 inline truth
eyecontroller::Handler(int x
, int y
)
329 return Map
[x
][y
]->IsTransparent();
332 inline lsquare
* lsquare::GetNeighbourLSquare(int I
) const
334 return I
< 8 ? NeighbourLSquare
[I
] : const_cast<lsquare
*>(this);