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.
23 * Declares WorldMap, class describing a top level map of the world.
24 * @author The GemRB Project
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
{
61 * Holds information about an Area on a WorldMap.
64 class GEM_EXPORT 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();
81 void SetPalette(int gradient
, Sprite2D
*MapIcon
);
85 char AreaLongName
[32];
89 ieStrRef LocCaptionName
;
90 ieStrRef LocTooltipName
;
91 ieResRef LoadScreenResRef
;
92 ieDword AreaLinksIndex
[4];
93 ieDword AreaLinksCount
[4];
98 * Defines connection and travelling between WorldMap areas
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
;
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
{
120 public: //struct members
128 ieDword AreaEntriesCount
;
129 ieDword AreaEntriesOffset
;
130 ieDword AreaLinksOffset
;
131 ieDword AreaLinksCount
;
132 ieResRef MapIconResRef
;
134 AnimationFactory
*bam
;
135 private: //non-struct members
137 std::vector
< WMPAreaEntry
*> area_entries
;
138 std::vector
< WMPAreaLink
*> area_links
;
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;
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
{
180 WorldMapArray(unsigned int count
);
182 void SetWorldMap(WorldMap
*m
, unsigned int index
);
185 unsigned int MapCount
;
186 unsigned int CurrentMap
;
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