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
34 #include "AnimationFactory.h"
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
{
62 * Holds information about an Area on a WorldMap.
65 class GEM_EXPORT 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();
82 void SetPalette(int gradient
, Sprite2D
*MapIcon
);
86 char AreaLongName
[32];
90 ieStrRef LocCaptionName
;
91 ieStrRef LocTooltipName
;
92 ieResRef LoadScreenResRef
;
93 ieDword AreaLinksIndex
[4];
94 ieDword AreaLinksCount
[4];
99 * Defines connection and travelling between WorldMap areas
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
;
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
{
121 public: //struct members
129 ieDword AreaEntriesCount
;
130 ieDword AreaEntriesOffset
;
131 ieDword AreaLinksOffset
;
132 ieDword AreaLinksCount
;
133 ieResRef MapIconResRef
;
135 AnimationFactory
*bam
;
136 private: //non-struct members
138 std::vector
< WMPAreaEntry
*> area_entries
;
139 std::vector
< WMPAreaLink
*> area_links
;
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;
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
{
184 WorldMapArray(unsigned int count
);
186 void SetWorldMap(WorldMap
*m
, unsigned int index
);
189 unsigned int MapCount
;
190 unsigned int CurrentMap
;
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