factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / core / WorldMap.h
blobf8cce256f00960b770584d64c438cee952bbed0f
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 "ie_types.h"
34 #include "AnimationFactory.h"
35 #include "Sprite2D.h"
37 #include <vector>
39 /** Area is visible on WorldMap */
40 #define WMP_ENTRY_VISIBLE 0x1
41 /** Area is visible on WorldMap only when party is in adjacent area */
42 #define WMP_ENTRY_ADJACENT 0x2
43 /** Area can be travelled into from WorldMap */
44 #define WMP_ENTRY_ACCESSIBLE 0x4
45 /** Area has already been visited by party */
46 #define WMP_ENTRY_VISITED 0x8
47 /** Area can be travelled into from WorldMap */
48 #define WMP_ENTRY_WALKABLE (WMP_ENTRY_VISIBLE|WMP_ENTRY_ACCESSIBLE)
49 /** Area can be passed through when travelling directly to some more distant area on WorldMap */
50 #define WMP_ENTRY_PASSABLE (WMP_ENTRY_VISIBLE|WMP_ENTRY_ACCESSIBLE|WMP_ENTRY_VISITED)
52 /** this is the physical order the links appear in WMPAreaEntry */
53 typedef enum ieDirectionType {
54 WMP_NORTH=0,
55 WMP_WEST=1,
56 WMP_SOUTH=2,
57 WMP_EAST=3
58 } ieDirectionType;
60 /**
61 * @class WMPAreaEntry
62 * Holds information about an Area on a WorldMap.
65 class GEM_EXPORT WMPAreaEntry {
66 public:
67 WMPAreaEntry();
68 ~WMPAreaEntry();
69 ieDword GetAreaStatus();
70 void SetAreaStatus(ieDword status, int op);
72 //! return the map icon of this location. Free the sprite afterwards.
73 Sprite2D *GetMapIcon(AnimationFactory *bam);
74 const char* GetCaption();
75 const char* GetTooltip();
76 private:
77 ieDword AreaStatus;
78 Sprite2D *MapIcon;
79 char *StrCaption;
80 char *StrTooltip;
82 void SetPalette(int gradient, Sprite2D *MapIcon);
83 public:
84 ieResRef AreaName;
85 ieResRef AreaResRef;
86 char AreaLongName[32];
87 ieDword IconSeq;
88 ieDword X;
89 ieDword Y;
90 ieStrRef LocCaptionName;
91 ieStrRef LocTooltipName;
92 ieResRef LoadScreenResRef;
93 ieDword AreaLinksIndex[4];
94 ieDword AreaLinksCount[4];
97 /**
98 * @struct WMPAreaLink
99 * Defines connection and travelling between WorldMap areas
102 struct WMPAreaLink {
103 ieDword AreaIndex;
104 char DestEntryPoint[32];
105 ieDword DistanceScale;
106 ieDword DirectionFlags; //where will the player appear on dest. area
107 ieResRef EncounterAreaResRef[5];
108 ieDword EncounterChance;
112 * @class WorldMap
113 * Top level map of the world.
114 * Also defines links between areas, although they are used only when travelling from this map.
117 class GEM_EXPORT WorldMap {
118 public:
119 WorldMap();
120 ~WorldMap();
121 public: //struct members
122 ieResRef MapResRef;
123 ieDword Width;
124 ieDword Height;
125 ieDword MapNumber;
126 ieStrRef AreaName;
127 ieDword unknown1;
128 ieDword unknown2;
129 ieDword AreaEntriesCount;
130 ieDword AreaEntriesOffset;
131 ieDword AreaLinksOffset;
132 ieDword AreaLinksCount;
133 ieResRef MapIconResRef;
135 AnimationFactory *bam;
136 private: //non-struct members
137 Sprite2D* MapMOS;
138 std::vector< WMPAreaEntry*> area_entries;
139 std::vector< WMPAreaLink*> area_links;
140 int *Distances;
141 int *GotHereFrom;
142 public:
143 void SetMapIcons(AnimationFactory *bam);
144 Sprite2D* GetMapMOS() const { return MapMOS; }
145 void SetMapMOS(Sprite2D *newmos);
146 int GetEntryCount() const { return (int) area_entries.size(); }
147 WMPAreaEntry *GetEntry(unsigned int index) { return area_entries[index]; }
148 int GetLinkCount() const { return (int) area_links.size(); }
149 WMPAreaLink *GetLink(unsigned int index) const { return area_links[index]; }
150 WMPAreaEntry *GetNewAreaEntry() const;
151 void SetAreaEntry(unsigned int index, WMPAreaEntry *areaentry);
152 void InsertAreaLink(unsigned int idx, unsigned int dir, WMPAreaLink *arealink);
153 void SetAreaLink(unsigned int index, WMPAreaLink *arealink);
154 void AddAreaEntry(WMPAreaEntry *ae);
155 void AddAreaLink(WMPAreaLink *al);
156 /** Calculates the distances from A, call this when first on an area */
157 int CalculateDistances(const ieResRef A, int direction);
158 /** Returns the precalculated distance to area B */
159 int GetDistance(const ieResRef A) const;
160 /** Returns the link between area A and area B */
161 WMPAreaLink *GetLink(const ieResRef A, const ieResRef B) const;
162 /** Returns the area link we will fall into if we head in B direction */
163 /** If the area name differs it means we are in a random encounter */
164 WMPAreaLink *GetEncounterLink(const ieResRef B, bool &encounter) const;
165 /** Sets area status */
166 void SetAreaStatus(const ieResRef, int Bits, int Op);
167 /** Gets area pointer and index from area name.
168 * also called from WorldMapArray to find the right map */
169 WMPAreaEntry* GetArea(const ieResRef AreaName, unsigned int &i) const;
170 /** Finds an area name closest to the given area */
171 WMPAreaEntry* FindNearestEntry(const ieResRef AreaName, unsigned int &i) const;
172 private:
173 /** updates visibility of adjacent areas, called from CalculateDistances */
174 void UpdateAreaVisibility(const ieResRef AreaName, int direction);
175 /** internal function to calculate the distances from areaindex */
176 void CalculateDistance(int areaindex, int direction);
177 unsigned int WhoseLinkAmI(int link_index) const;
178 /** update reachable areas from worlde.2da */
179 void UpdateReachableAreas();
182 class GEM_EXPORT WorldMapArray {
183 public:
184 WorldMapArray(unsigned int count);
185 ~WorldMapArray();
186 void SetWorldMap(WorldMap *m, unsigned int index);
187 private:
188 WorldMap **all_maps;
189 unsigned int MapCount;
190 unsigned int CurrentMap;
191 bool single;
192 public:
193 bool IsSingle() const { return single; }
194 void SetSingle(bool arg) { single = arg; }
195 unsigned int GetMapCount() const { return MapCount; }
196 unsigned int GetCurrentMapIndex() const { return CurrentMap; }
197 WorldMap *NewWorldMap(unsigned int index);
198 WorldMap *GetWorldMap(unsigned int index) const { return all_maps[index]; }
199 WorldMap *GetCurrentMap() const { return all_maps[CurrentMap]; }
200 void SetWorldMap(unsigned int index);
201 void SetCurrentMap(unsigned int index) { CurrentMap = index; }
202 unsigned int FindAndSetCurrentMap(const ieResRef area);
205 #endif // ! WORLDMAP_H