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 SetAreaLink(unsigned int index
, WMPAreaLink
*arealink
);
153 void AddAreaEntry(WMPAreaEntry
*ae
);
154 void AddAreaLink(WMPAreaLink
*al
);
155 /** Calculates the distances from A, call this when first on an area */
156 int CalculateDistances(const ieResRef A
, int direction
);
157 /** Returns the precalculated distance to area B */
158 int GetDistance(const ieResRef A
) const;
159 /** Returns the link between area A and area B */
160 WMPAreaLink
*GetLink(const ieResRef A
, const ieResRef B
) const;
161 /** Returns the area link we will fall into if we head in B direction */
162 /** If the area name differs it means we are in a random encounter */
163 WMPAreaLink
*GetEncounterLink(const ieResRef B
, bool &encounter
) const;
164 /** Sets area status */
165 void SetAreaStatus(const ieResRef
, int Bits
, int Op
);
166 /** internal function to get area pointer and index from area name.
167 * also called from WorldMapArray to find the right map */
168 WMPAreaEntry
* GetArea(const ieResRef AreaName
, unsigned int &i
) const;
170 /** updates visibility of adjacent areas, called from CalculateDistances */
171 void UpdateAreaVisibility(const ieResRef AreaName
, int direction
);
172 /** internal function to calculate the distances from areaindex */
173 void CalculateDistance(int areaindex
, int direction
);
174 unsigned int WhoseLinkAmI(int link_index
) const;
175 /** update reachable areas from worlde.2da */
176 void UpdateReachableAreas();
179 class GEM_EXPORT WorldMapArray
{
181 WorldMapArray(unsigned int count
);
183 void SetWorldMap(WorldMap
*m
, unsigned int index
);
186 unsigned int MapCount
;
187 unsigned int CurrentMap
;
189 unsigned int GetMapCount() const { return MapCount
; }
190 unsigned int GetCurrentMapIndex() const { return CurrentMap
; }
191 WorldMap
*NewWorldMap(unsigned int index
);
192 WorldMap
*GetWorldMap(unsigned int index
) const { return all_maps
[index
]; }
193 WorldMap
*GetCurrentMap() const { return all_maps
[CurrentMap
]; }
194 void SetWorldMap(unsigned int index
);
195 void SetCurrentMap(unsigned int index
) { CurrentMap
= index
; }
196 unsigned int FindAndSetCurrentMap(const ieResRef area
);
199 #endif // ! WORLDMAP_H