Constificiation.
[gemrb.git] / gemrb / core / WorldMap.h
blobfa4f73f3be5bc6ba32f2d930cdf375c2cd564d84
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 /**
22 * @file WorldMap.h
23 * Declares WorldMap, class describing a top level map of the world.
24 * @author The GemRB Project
28 #ifndef WORLDMAP_H
29 #define WORLDMAP_H
31 #include "exports.h"
32 #include <vector>
33 #include "ie_types.h"
35 #include "Sprite2D.h"
36 #include "AnimationFactory.h"
38 /** Area is visible on WorldMap */
39 #define WMP_ENTRY_VISIBLE 0x1
40 /** Area is visible on WorldMap only when party is in adjacent area */
41 #define WMP_ENTRY_ADJACENT 0x2
42 /** Area can be travelled into from WorldMap */
43 #define WMP_ENTRY_ACCESSIBLE 0x4
44 /** Area has already been visited by party */
45 #define WMP_ENTRY_VISITED 0x8
46 /** Area can be travelled into from WorldMap */
47 #define WMP_ENTRY_WALKABLE (WMP_ENTRY_VISIBLE|WMP_ENTRY_ACCESSIBLE)
48 /** Area can be passed through when travelling directly to some more distant area on WorldMap */
49 #define WMP_ENTRY_PASSABLE (WMP_ENTRY_VISIBLE|WMP_ENTRY_ACCESSIBLE|WMP_ENTRY_VISITED)
51 /** this is the physical order the links appear in WMPAreaEntry */
52 typedef enum ieDirectionType {
53 WMP_NORTH=0,
54 WMP_WEST=1,
55 WMP_SOUTH=2,
56 WMP_EAST=3
57 } ieDirectionType;
59 /**
60 * @class WMPAreaEntry
61 * Holds information about an Area on a WorldMap.
64 class GEM_EXPORT WMPAreaEntry {
65 public:
66 WMPAreaEntry();
67 ~WMPAreaEntry();
68 ieDword GetAreaStatus();
69 void SetAreaStatus(ieDword status, int op);
71 //! return the map icon of this location. Free the sprite afterwards.
72 Sprite2D *GetMapIcon(AnimationFactory *bam);
73 const char* GetCaption();
74 const char* GetTooltip();
75 private:
76 ieDword AreaStatus;
77 Sprite2D *MapIcon;
78 char *StrCaption;
79 char *StrTooltip;
81 void SetPalette(int gradient, Sprite2D *MapIcon);
82 public:
83 ieResRef AreaName;
84 ieResRef AreaResRef;
85 char AreaLongName[32];
86 ieDword IconSeq;
87 ieDword X;
88 ieDword Y;
89 ieStrRef LocCaptionName;
90 ieStrRef LocTooltipName;
91 ieResRef LoadScreenResRef;
92 ieDword AreaLinksIndex[4];
93 ieDword AreaLinksCount[4];
96 /**
97 * @struct WMPAreaLink
98 * Defines connection and travelling between WorldMap areas
101 struct WMPAreaLink {
102 ieDword AreaIndex;
103 char DestEntryPoint[32];
104 ieDword DistanceScale;
105 ieDword DirectionFlags; //where will the player appear on dest. area
106 ieResRef EncounterAreaResRef[5];
107 ieDword EncounterChance;
111 * @class WorldMap
112 * Top level map of the world.
113 * Also defines links between areas, although they are used only when travelling from this map.
116 class GEM_EXPORT WorldMap {
117 public:
118 WorldMap();
119 ~WorldMap();
120 public: //struct members
121 ieResRef MapResRef;
122 ieDword Width;
123 ieDword Height;
124 ieDword MapNumber;
125 ieStrRef AreaName;
126 ieDword unknown1;
127 ieDword unknown2;
128 ieDword AreaEntriesCount;
129 ieDword AreaEntriesOffset;
130 ieDword AreaLinksOffset;
131 ieDword AreaLinksCount;
132 ieResRef MapIconResRef;
134 AnimationFactory *bam;
135 private: //non-struct members
136 Sprite2D* MapMOS;
137 std::vector< WMPAreaEntry*> area_entries;
138 std::vector< WMPAreaLink*> area_links;
139 int *Distances;
140 int *GotHereFrom;
141 public:
142 void SetMapIcons(AnimationFactory *bam);
143 Sprite2D* GetMapMOS() const { return MapMOS; }
144 void SetMapMOS(Sprite2D *newmos);
145 int GetEntryCount() const { return (int) area_entries.size(); }
146 WMPAreaEntry *GetEntry(unsigned int index) { return area_entries[index]; }
147 int GetLinkCount() const { return (int) area_links.size(); }
148 WMPAreaLink *GetLink(unsigned int index) const { return area_links[index]; }
149 WMPAreaEntry *GetNewAreaEntry() const;
150 void SetAreaEntry(unsigned int index, WMPAreaEntry *areaentry);
151 void SetAreaLink(unsigned int index, WMPAreaLink *arealink);
152 void AddAreaEntry(WMPAreaEntry *ae);
153 void AddAreaLink(WMPAreaLink *al);
154 /** Calculates the distances from A, call this when first on an area */
155 int CalculateDistances(const ieResRef A, int direction);
156 /** Returns the precalculated distance to area B */
157 int GetDistance(const ieResRef A) const;
158 /** Returns the link between area A and area B */
159 WMPAreaLink *GetLink(const ieResRef A, const ieResRef B) const;
160 /** Returns the area link we will fall into if we head in B direction */
161 /** If the area name differs it means we are in a random encounter */
162 WMPAreaLink *GetEncounterLink(const ieResRef B, bool &encounter) const;
163 /** Sets area status */
164 void SetAreaStatus(const ieResRef, int Bits, int Op);
165 /** internal function to get area pointer and index from area name.
166 * also called from WorldMapArray to find the right map */
167 WMPAreaEntry* GetArea(const ieResRef AreaName, unsigned int &i) const;
168 private:
169 /** updates visibility of adjacent areas, called from CalculateDistances */
170 void UpdateAreaVisibility(const ieResRef AreaName, int direction);
171 /** internal function to calculate the distances from areaindex */
172 void CalculateDistance(int areaindex, int direction);
173 unsigned int WhoseLinkAmI(int link_index) const;
174 /** update reachable areas from worlde.2da */
175 void UpdateReachableAreas();
178 class GEM_EXPORT WorldMapArray {
179 public:
180 WorldMapArray(unsigned int count);
181 ~WorldMapArray();
182 void SetWorldMap(WorldMap *m, unsigned int index);
183 private:
184 WorldMap **all_maps;
185 unsigned int MapCount;
186 unsigned int CurrentMap;
187 public:
188 unsigned int GetMapCount() const { return MapCount; }
189 unsigned int GetCurrentMapIndex() const { return CurrentMap; }
190 WorldMap *NewWorldMap(unsigned int index);
191 WorldMap *GetWorldMap(unsigned int index) const { return all_maps[index]; }
192 WorldMap *GetCurrentMap() const { return all_maps[CurrentMap]; }
193 void SetWorldMap(unsigned int index);
194 void SetCurrentMap(unsigned int index) { CurrentMap = index; }
195 unsigned int FindAndSetCurrentMap(const ieResRef area);
198 #endif // ! WORLDMAP_H