"catch the spider" subquest (comm., by Clawzfire)
[k8-i-v-a-n.git] / src / game / game.h
blob1b3d9187b2a0f7ab0a2824ab224a703d2fa45f33
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 __GAME_H__
14 #define __GAME_H__
16 #include "ivancommon.h"
18 #include <ctime>
19 #include <map>
20 #include <stack>
21 #include <vector>
23 #include "femath.h"
24 #include "festring.h"
25 #include "ivandef.h"
28 #ifndef LIGHT_BORDER
29 # define LIGHT_BORDER 80
30 #endif
32 #define PLAYER game::GetPlayer()
35 class area;
36 class level;
37 class dungeon;
38 class felist;
39 class team;
40 class character;
41 class gamescript;
42 class item;
43 class outputfile;
44 class inputfile;
45 class worldmap;
46 class god;
47 class square;
48 class wsquare;
49 class lsquare;
50 class bitmap;
51 class festring;
52 class rain;
53 class liquid;
54 class entity;
55 class olterrain;
56 struct explosion;
58 typedef std::map<festring, sLong> valuemap;
59 typedef truth (*stringkeyhandler)(int, festring&);
60 typedef v2 (*positionkeyhandler)(v2, int);
61 typedef void (*positionhandler)(v2);
62 typedef void (*bitmapeditor)(bitmap*, truth);
65 struct homedata {
66 v2 Pos;
67 int Dungeon;
68 int Level;
69 int Room;
72 outputfile& operator<<(outputfile&, const homedata*);
73 inputfile& operator>>(inputfile&, homedata*&);
76 struct configid {
77 configid () {}
78 configid (int Type, int Config) : Type(Type), Config(Config) {}
79 bool operator < (const configid& CI) const { return memcmp(this, &CI, sizeof(configid)) < 0; }
81 int Type NO_ALIGNMENT;
82 int Config NO_ALIGNMENT;
85 outputfile& operator<<(outputfile&, const configid&);
86 inputfile& operator>>(inputfile&, configid&);
89 struct dangerid {
90 dangerid () : NakedDanger(0), EquippedDanger(0) {}
91 dangerid (double NakedDanger, double EquippedDanger) : NakedDanger(NakedDanger), EquippedDanger(EquippedDanger) {}
92 double NakedDanger;
93 double EquippedDanger;
96 outputfile& operator<<(outputfile&, const dangerid&);
97 inputfile& operator>>(inputfile&, dangerid&);
100 struct ivantime {
101 int Day;
102 int Hour;
103 int Min;
107 struct massacreid {
108 massacreid () {}
109 massacreid (int Type, int Config, cfestring &Name) : Type(Type), Config(Config), Name(Name) { }
110 bool operator < (const massacreid &) const;
112 int Type;
113 int Config;
114 festring Name;
117 inline bool massacreid::operator<(const massacreid& MI) const
119 if(Type != MI.Type)
120 return Type < MI.Type;
122 if(Config != MI.Config)
123 return Config < MI.Config;
125 return Name < MI.Name;
128 outputfile& operator<<(outputfile&, const massacreid&);
129 inputfile& operator>>(inputfile&, massacreid&);
132 struct killreason {
133 killreason () {}
134 killreason (cfestring &String, int Amount) : String(String), Amount(Amount) {}
136 festring String;
137 int Amount;
140 outputfile& operator<<(outputfile&, const killreason&);
141 inputfile& operator>>(inputfile&, killreason&);
144 struct killdata {
145 killdata (int Amount=0, double DangerSum=0) : Amount(Amount), DangerSum(DangerSum) {}
147 int Amount;
148 double DangerSum;
149 std::vector<killreason> Reason;
152 outputfile& operator<<(outputfile&, const killdata&);
153 inputfile& operator>>(inputfile&, killdata&);
156 typedef std::map<configid, dangerid> dangermap;
157 typedef std::map<feuLong, character*> characteridmap;
158 typedef std::map<feuLong, item*> itemidmap;
159 typedef std::map<feuLong, entity*> trapidmap;
160 typedef std::map<massacreid, killdata> massacremap;
161 typedef std::map<feuLong, feuLong> boneidmap;
162 typedef std::vector<item*> itemvector;
163 typedef std::vector<itemvector> itemvectorvector;
164 typedef std::vector<character*> charactervector;
167 class quitrequest {};
168 class areachangerequest {};
171 enum ArgTypes {
172 FARG_UNDEFINED,
173 FARG_STRING,
174 FARG_NUMBER
177 struct FuncArg {
178 FuncArg () : type(FARG_UNDEFINED), sval(""), ival(0) {}
179 FuncArg (cfestring &aVal) : type(FARG_STRING), sval(aVal), ival(0) {}
180 FuncArg (sLong aVal) : type(FARG_NUMBER), sval(""), ival(aVal) {}
182 ArgTypes type;
183 festring sval;
184 sLong ival;
188 class game {
189 public:
190 static void InitPlaces ();
191 static truth Init(cfestring& = CONST_S(""));
192 static void DeInit();
193 static void Run();
194 static int GetMoveCommandKey(int);
195 static int MoveVectorToDirection (cv2 &mv); // -1: none
196 static cv2 GetMoveVector(int I) { return MoveVector[I]; }
197 static cv2 GetRelativeMoveVector(int I) { return RelativeMoveVector[I]; }
198 static cv2 GetBasicMoveVector(int I) { return BasicMoveVector[I]; }
199 static cv2 GetLargeMoveVector(int I) { return LargeMoveVector[I]; }
200 static area* GetCurrentArea() { return CurrentArea; }
201 static level* GetCurrentLevel() { return CurrentLevel; }
202 static uChar*** GetLuxTable() { return LuxTable; }
203 static character* GetPlayer() { return Player; }
204 static void SetPlayer(character*);
205 static v2 GetCamera() { return Camera; }
206 static void UpdateCameraX();
207 static void UpdateCameraY();
208 static truth IsLoading() { return Loading; }
209 static void SetIsLoading(truth What) { Loading = What; }
210 static truth ForceJumpToPlayerBe() { return JumpToPlayerBe; }
211 static void SetForceJumpToPlayerBe(truth What) { JumpToPlayerBe = What; }
212 static level* GetLevel(int);
213 static void InitLuxTable();
214 static void DeInitLuxTable();
215 static cchar* Insult();
216 static truth TruthQuestion(cfestring&, int = 0, int = 0);
217 static void DrawEverything();
218 static truth Save(cfestring& = SaveName(""));
219 static int Load(cfestring& = SaveName(""));
220 static truth IsRunning() { return Running; }
221 static void SetIsRunning(truth What) { Running = What; }
222 static void UpdateCameraX(int);
223 static void UpdateCameraY(int);
224 static int GetCurrentLevelIndex() { return CurrentLevelIndex; }
225 static int GetMoveCommandKeyBetweenPoints(v2, v2);
226 static void DrawEverythingNoBlit(truth = false);
227 static god* GetGod(int I) { return God[I]; }
228 static cchar* GetAlignment(int I) { return Alignment[I]; }
229 static void ApplyDivineTick();
230 static void ApplyDivineAlignmentBonuses(god*, int, truth);
231 static v2 GetDirectionVectorForKey(int);
232 static festring SaveName(cfestring& = CONST_S(""));
233 static void ShowLevelMessage();
234 static double GetMinDifficulty();
235 static void TriggerQuestForGoldenEagleShirt();
236 static void CalculateGodNumber();
237 static void IncreaseTick() { ++Tick; }
238 static feuLong GetTick() { return Tick; }
239 static festring GetAutoSaveFileName() { return AutoSaveFileName; }
240 static int DirectionQuestion(cfestring&, truth = true, truth = false);
241 static void RemoveSaves(truth = true);
242 static truth IsInWilderness() { return InWilderness; }
243 static void SetIsInWilderness(truth What) { InWilderness = What; }
244 static worldmap* GetWorldMap() { return WorldMap; }
245 static void SetAreaInLoad(area* What) { AreaInLoad = What; }
246 static void SetSquareInLoad(square* What) { SquareInLoad = What; }
247 static area* GetAreaInLoad() { return AreaInLoad; }
248 static square* GetSquareInLoad() { return SquareInLoad; }
249 static int GetLevels();
250 static dungeon* GetCurrentDungeon() { return Dungeon[CurrentDungeonIndex]; }
251 static dungeon* GetDungeon(int I) { return Dungeon[I]; }
252 static int GetCurrentDungeonIndex() { return CurrentDungeonIndex; }
253 static void InitDungeons();
254 static truth OnScreen(v2);
255 static void DoEvilDeed(int);
256 static void SaveWorldMap(cfestring& = SaveName(""), truth = true);
257 static worldmap* LoadWorldMap(cfestring& = SaveName(""));
258 static void UpdateCamera();
259 static feuLong CreateNewCharacterID(character*);
260 static feuLong CreateNewItemID(item*);
261 static feuLong CreateNewTrapID(entity*);
262 static team* GetTeam(int I) { return Team[I]; }
263 static int GetTeams() { return Teams; }
264 static void Hostility(team*, team*);
265 static void CreateTeams();
266 static festring StringQuestion(cfestring&, col16, festring::sizetype, festring::sizetype, truth, stringkeyhandler = 0);
267 static sLong NumberQuestion(cfestring&, int, truth = false);
268 static feuLong IncreaseLOSTick();
269 static feuLong GetLOSTick() { return LOSTick; }
270 static void SendLOSUpdateRequest() { LOSUpdateRequested = true; }
271 static void RemoveLOSUpdateRequest() { LOSUpdateRequested = false; }
272 static character* GetPetrus() { return Petrus; }
273 static void SetPetrus(character* What) { Petrus = What; }
274 static truth HandleQuitMessage();
275 static int GetDirectionForVector(v2);
276 static cchar* GetVerbalPlayerAlignment();
277 static void CreateGods();
278 static int GetScreenXSize() { return 42; }
279 static int GetScreenYSize() { return 26; }
280 static v2 CalculateScreenCoordinates(v2);
281 static void BusyAnimation();
282 static void BusyAnimation(bitmap*, truth);
283 static v2 PositionQuestion(cfestring&, v2, positionhandler = 0, positionkeyhandler = 0, truth = true);
284 static void LookHandler(v2);
285 static int AskForKeyPress(cfestring&);
286 static void AskForEscPress(cfestring &Topic);
287 static truth AnimationController();
288 static gamescript* GetGameScript() { return GameScript; }
289 static void InitScript();
291 static valuemap& GetGlobalValueMap() { return GlobalValueMap; }
292 static truth HasGlobalValue (cfestring &name);
293 static sLong FindGlobalValue (cfestring &name, sLong defval=-1, truth* found=0);
294 static sLong FindGlobalValue (cfestring &name, truth* found=0);
296 // this will fail if there is no such constant
297 //TODO: cache values
298 static sLong GetGlobalConst (cfestring &name);
300 static void InitGlobalValueMap();
301 static void LoadGlobalValueMap (TextInput &SaveFile);
303 static void TextScreen(cfestring&, v2 = ZERO_V2, col16 = 0xFFFF, truth = true, truth = true, bitmapeditor = 0);
304 static void SetCursorPos(v2 What) { CursorPos = What; }
305 static truth DoZoom() { return Zoom; }
306 static void SetDoZoom(truth What) { Zoom = What; }
307 static int KeyQuestion(cfestring&, int, int, ...);
308 static v2 LookKeyHandler(v2, int);
309 static v2 NameKeyHandler(v2, int);
310 static void End(festring, truth = true, truth = true);
311 static int CalculateRoughDirection(v2);
312 static sLong ScrollBarQuestion(cfestring&, sLong, sLong, sLong, sLong, sLong, col16, col16, col16, void (*)(sLong) = 0);
313 static truth IsGenerating() { return Generating; }
314 static void SetIsGenerating(truth What) { Generating = What; }
315 static void CalculateNextDanger();
316 static int Menu(bitmap*, v2, cfestring&, cfestring&, col16, cfestring& = "", cfestring& = "");
317 static void InitDangerMap();
318 static const dangermap& GetDangerMap();
319 static truth TryTravel(int, int, int, truth = false, truth = true);
320 static truth LeaveArea(charactervector&, truth, truth);
321 static void EnterArea(charactervector&, int, int);
322 static int CompareLights(col24, col24);
323 static int CompareLightToInt(col24, col24);
324 static void CombineLights(col24&, col24);
325 static col24 CombineConstLights(col24, col24);
326 static truth IsDark(col24);
327 static void SetStandardListAttributes(felist&);
328 static double GetAveragePlayerArmStrengthExperience() { return AveragePlayerArmStrengthExperience; }
329 static double GetAveragePlayerLegStrengthExperience() { return AveragePlayerLegStrengthExperience; }
330 static double GetAveragePlayerDexterityExperience() { return AveragePlayerDexterityExperience; }
331 static double GetAveragePlayerAgilityExperience() { return AveragePlayerAgilityExperience; }
332 static void InitPlayerAttributeAverage();
333 static void UpdatePlayerAttributeAverage();
334 static void CallForAttention(v2, int);
335 static character* SearchCharacter(feuLong);
336 static item* SearchItem(feuLong);
337 static entity* SearchTrap(feuLong);
338 static void AddCharacterID(character*, feuLong);
339 static void RemoveCharacterID(feuLong);
340 static void AddItemID(item*, feuLong);
341 static void RemoveItemID(feuLong);
342 static void UpdateItemID(item*, feuLong);
343 static void AddTrapID(entity*, feuLong);
344 static void RemoveTrapID(feuLong);
345 static void UpdateTrapID(entity*, feuLong);
346 static int GetStoryState() { return StoryState; }
347 static void SetStoryState(int What) { StoryState = What; }
348 static int GetXinrochTombStoryState() { return XinrochTombStoryState; }
349 static void SetXinrochTombStoryState(int What) { XinrochTombStoryState = What; }
350 static int GetMondedrPass () { return MondedrPass; }
351 static void SetMondedrPass (int What) { MondedrPass = What; }
352 static int GetRingOfThieves () { return RingOfThieves; }
353 static void SetRingOfThieves (int What) { RingOfThieves = What; }
354 static int GetMasamune () { return Masamune; }
355 static void SetMasamune (int What) { Masamune = What; }
356 static int GetMuramasa () { return Muramasa; }
357 static void SetMuramasa (int What) { Muramasa = What; }
358 static int GetLoricatusHammer () { return LoricatusHammer; }
359 static void SetLoricatusHammer (int What) { LoricatusHammer = What; }
360 static int GetLiberator () { return Liberator; }
361 static void SetLiberator (int What) { Liberator = What; }
362 static int GetOmmelBloodMission() { return OmmelBloodMission; }
363 static void SetOmmelBloodMission(int What) { OmmelBloodMission = What; }
364 static int GetRegiiTalkState() { return RegiiTalkState; }
365 static void SetRegiiTalkState(int What) { RegiiTalkState = What; }
366 static void SetIsInGetCommand(truth What) { InGetCommand = What; }
367 static truth IsInGetCommand() { return InGetCommand; }
368 static festring GetHomeDir();
369 static festring GetSavePath();
370 static festring GetGameDir();
371 static festring GetBonePath();
372 static truth PlayerWasHurtByExplosion() { return PlayerHurtByExplosion; }
373 static void SetPlayerWasHurtByExplosion(truth What) { PlayerHurtByExplosion = What; }
374 static void SetCurrentArea(area* What) { CurrentArea = What; }
375 static void SetCurrentLevel(level* What) { CurrentLevel = What; }
376 static void SetCurrentWSquareMap(wsquare*** What) { CurrentWSquareMap = What; }
377 static void SetCurrentLSquareMap(lsquare*** What) { CurrentLSquareMap = What; }
378 static festring& GetDefaultPolymorphTo() { return DefaultPolymorphTo; }
379 static festring& GetDefaultSummonMonster() { return DefaultSummonMonster; }
380 static festring& GetDefaultChangeMaterial() { return DefaultChangeMaterial; }
381 static festring& GetDefaultDetectMaterial() { return DefaultDetectMaterial; }
382 static festring& GetDefaultTeam() { return DefaultTeam; }
383 static void SignalDeath(ccharacter*, ccharacter*, festring);
384 static void DisplayMassacreLists();
385 static void DisplayMassacreList(const massacremap&, cchar*, sLong);
386 static truth MassacreListsEmpty();
387 #ifdef WIZARD
388 static void ActivateWizardMode() { WizardMode = true; }
389 static void DeactivateWizardMode() { WizardMode = false; }
390 static truth WizardModeIsActive() { return WizardMode; }
391 static void SeeWholeMap();
392 static int GetSeeWholeMapCheatMode() { return SeeWholeMapCheatMode; }
393 static truth GoThroughWallsCheatIsActive() { return GoThroughWallsCheat; }
394 static void GoThroughWalls() { GoThroughWallsCheat = !GoThroughWallsCheat; }
395 #else
396 static truth WizardModeIsActive() { return false; }
397 static int GetSeeWholeMapCheatMode() { return 0; }
398 static truth GoThroughWallsCheatIsActive() { return false; }
399 #endif
400 static truth WizardModeIsReallyActive() { return WizardMode; }
401 static void CreateBone();
402 static int GetQuestMonstersFound() { return QuestMonstersFound; }
403 static void SignalQuestMonsterFound() { ++QuestMonstersFound; }
404 static void SetQuestMonstersFound(int What) { QuestMonstersFound = What; }
405 static truth PrepareRandomBone(int);
406 static boneidmap& GetBoneItemIDMap() { return BoneItemIDMap; }
407 static boneidmap& GetBoneCharacterIDMap() { return BoneCharacterIDMap; }
408 static double CalculateAverageDanger(const charactervector&, character*);
409 static double CalculateAverageDangerOfAllNormalEnemies();
410 static character* CreateGhost();
411 static truth TooGreatDangerFound() { return TooGreatDangerFoundTruth; }
412 static void SetTooGreatDangerFound(truth What) { TooGreatDangerFoundTruth = What; }
413 static void CreateBusyAnimationCache();
414 static sLong GetScore();
415 static truth TweraifIsFree();
416 static truth IsXMas();
417 static int AddToItemDrawVector(const itemvector&);
418 static void ClearItemDrawVector();
419 static void ItemEntryDrawer(bitmap*, v2, uInt);
420 static int AddToCharacterDrawVector(character*);
421 static void ClearCharacterDrawVector();
422 static void CharacterEntryDrawer(bitmap*, v2, uInt);
423 static void GodEntryDrawer(bitmap*, v2, uInt);
424 static itemvectorvector& GetItemDrawVector() { return ItemDrawVector; }
425 static charactervector& GetCharacterDrawVector() { return CharacterDrawVector; }
426 static truth IsSumoWrestling() { return SumoWrestling; }
427 static void SetIsSumoWrestling(truth What) { SumoWrestling = What; }
428 static truth AllowHostilities() { return !SumoWrestling; }
429 static truth AllBodyPartsVanish() { return SumoWrestling; }
430 static truth TryToEnterSumoArena();
431 static truth TryToExitSumoArena();
432 static truth EndSumoWrestling(int);
433 static character* GetSumo();
434 static cfestring& GetPlayerName() { return PlayerName; }
435 static rain* ConstructGlobalRain();
436 static void SetGlobalRainLiquid(liquid* What) { GlobalRainLiquid = What; }
437 static void SetGlobalRainSpeed(v2 What) { GlobalRainSpeed = What; }
438 static truth PlayerIsSumoChampion() { return PlayerSumoChampion; }
439 static truth PlayerIsSolicitusChampion() { return PlayerSolicitusChampion; }
440 static void MakePlayerSolicitusChampion() { PlayerSolicitusChampion = true; }
441 static truth ChildTouristHasSpider () { return TouristHasSpider; }
442 static void SetTouristHasSpider () { TouristHasSpider = true; }
443 static v2 GetSunLightDirectionVector();
444 static int CalculateMinimumEmitationRadius(col24);
445 static feuLong IncreaseSquarePartEmitationTicks();
446 static cint GetLargeMoveDirection(int I) { return LargeMoveDirection[I]; }
447 static bool Wish(character*, cchar*, cchar*, bool canAbort=false);
448 static festring DefaultQuestion(festring, festring&, stringkeyhandler = 0);
449 static void GetTime(ivantime&);
450 static sLong GetTurn() { return Turn; }
451 static void IncreaseTurn() { ++Turn; }
452 static int GetTotalMinutes() { return Tick * 60 / 2000; }
453 static truth PolymorphControlKeyHandler(int, festring&);
454 static feuLong* GetEquipmentMemory() { return EquipmentMemory; }
455 static truth PlayerIsRunning();
456 static void SetPlayerIsRunning(truth What) { PlayerRunning = What; }
457 static truth FillPetVector(cchar*);
458 static truth CommandQuestion();
459 static void NameQuestion();
460 static v2 CommandKeyHandler(v2, int);
461 static void CommandScreen(cfestring&, feuLong, feuLong, feuLong&, feuLong&);
462 static truth CommandAll();
463 static double GetDangerFound() { return DangerFound; }
464 static void SetDangerFound(double What) { DangerFound = What; }
465 static col16 GetAttributeColor(int);
466 static void UpdateAttributeMemory();
467 static void InitAttributeMemory();
468 static void TeleportHandler(v2);
469 static void PetHandler(v2);
470 static truth SelectPet(int);
471 static double GetGameSituationDanger();
472 static olterrain* GetMonsterPortal() { return MonsterPortal; }
473 static void SetMonsterPortal(olterrain* What) { MonsterPortal = What; }
474 static truth GetCausePanicFlag() { return CausePanicFlag; }
475 static void SetCausePanicFlag(truth What) { CausePanicFlag = What; }
476 static sLong GetTimeSpent();
477 static void AddSpecialCursor(v2, int);
478 static void RemoveSpecialCursors();
479 static void LearnAbout(god*);
480 static truth PlayerKnowsAllGods();
481 static void AdjustRelationsToAllGods(int);
482 static void SetRelationsToAllGods(int);
483 static void ShowDeathSmiley(bitmap*, truth);
484 static void SetEnterImage(cbitmap* What) { EnterImage = What; }
485 static void SetEnterTextDisplacement (v2 What) { EnterTextDisplacement = What; }
487 static int ListSelector (int defsel, const cfestring title, ...); // defsel<0: first
488 static int ListSelectorArray (int defsel, cfestring &title, const char *items[]); // defsel<0: first
490 static char GetAbnormalMoveKey (int idx);
491 static void SetAbnormalMoveKey (int idx, char ch);
493 static truth CheckDropLeftover (item *i);
495 static team *FindTeam (cfestring &name);
496 //static team *FindTeam (const char *name);
498 static void ClearEventData ();
499 // return 'true' if event is 'eaten'
500 static truth RunOnEvent (cfestring &ename);
501 static truth RunOnCharEvent (character *who, cfestring &ename);
502 static truth RunOnItemEvent (item *what, cfestring &ename);
504 static truth RunAllowScriptStr (cfestring &str);
506 static festring ldrGetVar (TextInput *fl, cfestring &name);
508 private:
509 static truth RunOnEventStr (cfestring &name, cfestring &str);
510 static truth GetWord (festring &w);
511 static void SkipBlock (truth brcEaten);
512 static void UpdateCameraCoordinate (int &, int, int, int);
513 static truth DoOnEvent (truth brcEaten, truth AllowScript=false);
514 static int ParseFuncArgs (cfestring &types, std::vector<FuncArg> &args, TextInput *fl=0, truth noterm=false);
516 private:
517 static cchar* const Alignment[];
518 static god** God;
519 static int CurrentLevelIndex;
520 static int CurrentDungeonIndex;
521 static cint MoveNormalCommandKey[];
522 static int MoveAbnormalCommandKey[];
523 static cv2 MoveVector[];
524 static cv2 RelativeMoveVector[];
525 static cv2 BasicMoveVector[];
526 static cv2 LargeMoveVector[];
527 static uChar*** LuxTable;
528 static truth Running;
529 static character* Player;
530 static v2 Camera;
531 static feuLong Tick;
532 static festring AutoSaveFileName;
533 static truth InWilderness;
534 static worldmap* WorldMap;
535 static area* AreaInLoad;
536 static square* SquareInLoad;
537 static dungeon** Dungeon;
538 static feuLong NextCharacterID;
539 static feuLong NextItemID;
540 static feuLong NextTrapID;
541 static team** Team;
542 static feuLong LOSTick;
543 static truth LOSUpdateRequested;
544 static character* Petrus;
545 static truth Loading;
546 static truth JumpToPlayerBe;
547 static gamescript* GameScript;
548 static valuemap GlobalValueMap;
549 static v2 CursorPos;
550 static truth Zoom;
551 static truth Generating;
552 static dangermap DangerMap;
553 static int NextDangerIDType;
554 static int NextDangerIDConfigIndex;
555 static double AveragePlayerArmStrengthExperience;
556 static double AveragePlayerLegStrengthExperience;
557 static double AveragePlayerDexterityExperience;
558 static double AveragePlayerAgilityExperience;
559 static characteridmap CharacterIDMap;
560 static itemidmap ItemIDMap;
561 static trapidmap TrapIDMap;
562 static int Teams;
563 static int Dungeons;
564 static int StoryState;
565 static int XinrochTombStoryState;
566 static int MondedrPass;
567 static int RingOfThieves;
568 static int Masamune;
569 static int Muramasa;
570 static int LoricatusHammer;
571 static int Liberator;
572 static int OmmelBloodMission;
573 static int RegiiTalkState;
574 static truth InGetCommand;
575 static truth PlayerHurtByExplosion;
576 static area* CurrentArea;
577 static level* CurrentLevel;
578 static wsquare*** CurrentWSquareMap;
579 static lsquare*** CurrentLSquareMap;
580 static festring DefaultPolymorphTo;
581 static festring DefaultSummonMonster;
582 static festring DefaultWish;
583 static festring DefaultChangeMaterial;
584 static festring DefaultDetectMaterial;
585 static festring DefaultTeam;
586 static massacremap PlayerMassacreMap;
587 static massacremap PetMassacreMap;
588 static massacremap MiscMassacreMap;
589 static sLong PlayerMassacreAmount;
590 static sLong PetMassacreAmount;
591 static sLong MiscMassacreAmount;
592 static truth WizardMode;
593 static int SeeWholeMapCheatMode;
594 static truth GoThroughWallsCheat;
595 static int QuestMonstersFound;
596 static boneidmap BoneItemIDMap;
597 static boneidmap BoneCharacterIDMap;
598 static truth TooGreatDangerFoundTruth;
599 static bitmap* BusyAnimationCache[32];
600 static itemvectorvector ItemDrawVector;
601 static charactervector CharacterDrawVector;
602 static truth SumoWrestling;
603 static festring PlayerName;
604 static liquid* GlobalRainLiquid;
605 static v2 GlobalRainSpeed;
606 static sLong GlobalRainTimeModifier;
607 static truth PlayerSumoChampion;
608 static truth PlayerSolicitusChampion;
609 static truth TouristHasSpider;
610 static feuLong SquarePartEmitationTick;
611 static cint LargeMoveDirection[];
612 static sLong Turn;
613 static feuLong EquipmentMemory[MAX_EQUIPMENT_SLOTS];
614 static truth PlayerRunning;
615 static character* LastPetUnderCursor;
616 static charactervector PetVector;
617 static double DangerFound;
618 static int OldAttribute[ATTRIBUTES];
619 static int NewAttribute[ATTRIBUTES];
620 static int LastAttributeChangeTick[ATTRIBUTES];
621 static int NecroCounter;
622 static int CursorData;
623 static olterrain* MonsterPortal;
624 static truth CausePanicFlag;
625 static time_t TimePlayedBeforeLastLoad;
626 static time_t LastLoad;
627 static time_t GameBegan;
628 static std::vector<v2> SpecialCursorPos;
629 static std::vector<int> SpecialCursorData;
630 static truth PlayerHasReceivedAllGodsKnownBonus;
631 static cbitmap* EnterImage;
632 static v2 EnterTextDisplacement;
634 static std::stack<TextInput *> mFEStack;
636 public:
637 static character *mChar;
638 static ccharacter *mActor;
639 static ccharacter *mSecondActor;
640 static item *mItem;
641 static int mResult;
645 //K8 WARNING! ABSOLUTELY NON-PORTABLE AND CAUSES UB!
646 //#define BCLAMP(c) (((c)&0xff)|(255-((-(int)((c) < 256))>>24)))
647 #define BCLAMP(c) ((c) > 255 ? 255 : (c) < 0 ? 0 : (c))
648 inline void game::CombineLights (col24 &L1, col24 L2) {
649 if (L2) {
650 if (L1) {
651 #if! defined(IVAN_NEW_LIGHTS)
652 # if !defined(IVAN_NEW_INTENSITY)
653 sLong Red1 = (L1&0xFF0000), Red2 = (L2&0xFF0000);
654 sLong New = (Red1 >= Red2 ? Red1 : Red2);
655 sLong Green1 = (L1&0xFF00), Green2 = (L2&0xFF00);
656 New |= (Green1 >= Green2 ? Green1 : Green2);
657 sLong Blue1 = (L1&0xFF), Blue2 = (L2&0xFF);
658 L1 = New|(Blue1 >= Blue2 ? Blue1 : Blue2);
659 # else
660 int l1i = (int)(0.2126*((L1>>16)&0xFF)+0.7152*((L1>>8)&0xFF)+0.0722*(L1&0xFF)+0.5);
661 int l2i = (int)(0.2126*((L2>>16)&0xFF)+0.7152*((L2>>8)&0xFF)+0.0722*(L2&0xFF)+0.5);
662 //if (l2i > l1i) L1 = L2;
663 l1i = BCLAMP(l1i);
664 l2i = BCLAMP(l2i);
665 int r = (int)(((L1>>16)&0xFF)*(l1i/255.0f)+((L2>>16)&0xFF)*(l2i/255.0f));
666 int g = (int)(((L1>>8)&0xFF)*(l1i/255.0f)+((L2>>8)&0xFF)*(l2i/255.0f));
667 int b = (int)((L1&0xFF)*(l1i/255.0f)+(L2&0xFF)*(l2i/255.0f));
668 r = BCLAMP(r);
669 g = BCLAMP(g);
670 b = BCLAMP(b);
671 L1 = (r<<16)|(g<<8)|b;
672 # endif
673 #else
674 # define L_COEFF (0.05f)
675 int r = (int)(((L1>>16)&0xFF)*L_COEFF+((L2>>16)&0xFF)*L_COEFF);
676 int g = (int)(((L1>>8)&0xFF)*L_COEFF+((L2>>8)&0xFF)*L_COEFF);
677 int b = (int)((L1&0xFF)*L_COEFF+(L2&0xFF)*L_COEFF);
678 r = BCLAMP(r);
679 g = BCLAMP(g);
680 b = BCLAMP(b);
681 L1 = (r<<16)|(g<<8)|b;
682 # undef L_COEFF
683 #endif
684 } else {
685 L1 = L2;
689 #undef BCLAMP
692 inline col24 game::CombineConstLights (col24 L1, col24 L2) {
693 CombineLights(L1, L2);
694 return L1;
698 inline truth game::IsDark (col24 Light) {
699 return
700 !Light ||
701 ((Light & 0xFF0000) < (LIGHT_BORDER << 16) &&
702 (Light & 0x00FF00) < (LIGHT_BORDER << 8) &&
703 (Light & 0x0000FF) < LIGHT_BORDER);
706 inline int game::CompareLights (col24 L1, col24 L2) {
707 if (L1) {
708 if ((L1 & 0xFF0000) > (L2 & 0xFF0000) ||
709 (L1 & 0x00FF00) > (L2 & 0x00FF00) ||
710 (L1 & 0x0000FF) > (L2 & 0x0000FF))
711 return 1;
712 if ((L1 & 0xFF0000) == (L2 & 0xFF0000) ||
713 (L1 & 0x00FF00) == (L2 & 0x00FF00) ||
714 (L1 & 0x0000FF) == (L2 & 0x0000FF))
715 return 0;
716 return -1;
718 return -int(!!L2);
722 inline v2 game::CalculateScreenCoordinates (v2 Pos) {
723 return v2((Pos.X-Camera.X+1)<<4, (Pos.Y-Camera.Y+2)<<4);
727 #endif