| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name map.h - The map headerfile. */ |
| 11 |
// |
| 12 |
// (c) Copyright 1998-2008 by Vladi Shabanski, Lutz Sammer, and |
| 13 |
// Jimmy Salmon |
| 14 |
// |
| 15 |
// This program is free software; you can redistribute it and/or modify |
| 16 |
// it under the terms of the GNU General Public License as published by |
| 17 |
// the Free Software Foundation; only version 2 of the License. |
| 18 |
// |
| 19 |
// This program is distributed in the hope that it will be useful, |
| 20 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
// GNU General Public License for more details. |
| 23 |
// |
| 24 |
// You should have received a copy of the GNU General Public License |
| 25 |
// along with this program; if not, write to the Free Software |
| 26 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
// 02111-1307, USA. |
| 28 |
|
| 29 |
#ifndef __MAP_H__ |
| 30 |
#define __MAP_H__ |
| 31 |
|
| 32 |
//@{ |
| 33 |
|
| 34 |
/*---------------------------------------------------------------------------- |
| 35 |
-- Documentation |
| 36 |
----------------------------------------------------------------------------*/ |
| 37 |
|
| 38 |
/** |
| 39 |
** @class CMapField map.h |
| 40 |
** |
| 41 |
** \#include "map.h" |
| 42 |
** |
| 43 |
** This class contains all information about a field on map. |
| 44 |
** It contains its look, properties and content. |
| 45 |
** |
| 46 |
** The map-field class members: |
| 47 |
** |
| 48 |
** CMapField::Flags |
| 49 |
** |
| 50 |
** Contains special information of that tile. What units are |
| 51 |
** on this field, what units could be placed on this field. |
| 52 |
** |
| 53 |
** This is the list of all flags currently used: |
| 54 |
** |
| 55 |
** ::MapFieldVisible field is visible. |
| 56 |
** ::MapFieldExplored field is explored. |
| 57 |
** ::MapFieldLandAllowed land units are allowed. |
| 58 |
** ::MapFieldCoastAllowed coast units (transporter) and coast |
| 59 |
** buildings (shipyard) are allowed. |
| 60 |
** ::MapFieldShallowWater small water units allowed. |
| 61 |
** ::MapFieldDeepWater both small and big water units allowed. |
| 62 |
** ::MapFieldNoBuilding no buildings allowed, except neutral (e.g. rocks). |
| 63 |
** ::MapFieldUnpassable field is movement blocked. |
| 64 |
** ::MapFieldLandUnit land unit on field. |
| 65 |
** ::MapFieldAirUnit air unit on field. |
| 66 |
** ::MapFieldSeaUnit water unit on field. |
| 67 |
** ::MapFieldBuilding building on field. |
| 68 |
** |
| 69 |
** Note: We want to add support for more unit-types like under |
| 70 |
** ground units. |
| 71 |
** |
| 72 |
** CMapField::Cost |
| 73 |
** |
| 74 |
** Unit cost to move in this tile. |
| 75 |
** |
| 76 |
** CMapField::Visible[] |
| 77 |
** |
| 78 |
** Counter how many units of the player can see this field. 0 the |
| 79 |
** field is not explored, 1 explored, n-1 unit see it. Currently |
| 80 |
** no more than 253 units can see a field. |
| 81 |
** |
| 82 |
** CMapField::Radar[] |
| 83 |
** |
| 84 |
** Visiblity for radar. |
| 85 |
** |
| 86 |
** CMapField::RadarJammer[] |
| 87 |
** |
| 88 |
** Jamming capabilities. |
| 89 |
*/ |
| 90 |
|
| 91 |
/** |
| 92 |
** @class CMap map.h |
| 93 |
** |
| 94 |
** \#include "map.h" |
| 95 |
** |
| 96 |
** This class contains all information about a Stratagus map. |
| 97 |
** A map is a rectangle of any size. |
| 98 |
** |
| 99 |
** The map class members: |
| 100 |
** |
| 101 |
** CMap::Fields |
| 102 |
** |
| 103 |
** An array CMap::Info::Width * CMap::Info::Height of all fields |
| 104 |
** belonging to this map. |
| 105 |
** |
| 106 |
** CMap::NoFogOfWar |
| 107 |
** |
| 108 |
** Flag if true, the fog of war is disabled. |
| 109 |
** |
| 110 |
** CMap::FogGraphic |
| 111 |
** |
| 112 |
** Graphic for fog of war |
| 113 |
** |
| 114 |
** CMap::Info |
| 115 |
** |
| 116 |
** Descriptive information of the map. See ::CMapInfo. |
| 117 |
*/ |
| 118 |
|
| 119 |
/*---------------------------------------------------------------------------- |
| 120 |
-- Includes |
| 121 |
----------------------------------------------------------------------------*/ |
| 122 |
|
| 123 |
#include <string> |
| 124 |
#include <vector> |
| 125 |
#include "patch_manager.h" |
| 126 |
|
| 127 |
/*---------------------------------------------------------------------------- |
| 128 |
-- Declarations |
| 129 |
----------------------------------------------------------------------------*/ |
| 130 |
|
| 131 |
class CGraphic; |
| 132 |
class CPlayer; |
| 133 |
class CFile; |
| 134 |
class CUnit; |
| 135 |
class CUnitType; |
| 136 |
|
| 137 |
/*---------------------------------------------------------------------------- |
| 138 |
-- Map |
| 139 |
----------------------------------------------------------------------------*/ |
| 140 |
|
| 141 |
#define MaxMapWidth 256 /// max map width supported |
| 142 |
#define MaxMapHeight 256 /// max map height supported |
| 143 |
|
| 144 |
/*---------------------------------------------------------------------------- |
| 145 |
-- Map - field |
| 146 |
----------------------------------------------------------------------------*/ |
| 147 |
|
| 148 |
/// Describes a field of the map |
| 149 |
class CMapField |
| 150 |
{ |
| 151 |
public: |
| 152 |
CMapField() : Flags(0), Cost(0) |
| 153 |
{ |
| 154 |
memset(Visible, 0, sizeof(Visible)); |
| 155 |
memset(Radar, 0, sizeof(Radar)); |
| 156 |
memset(RadarJammer, 0, sizeof(RadarJammer)); |
| 157 |
} |
| 158 |
|
| 159 |
unsigned short Flags; /// field flags |
| 160 |
unsigned char Cost; /// unit cost to move in this tile |
| 161 |
|
| 162 |
unsigned short Visible[PlayerMax]; /// Seen counter 0 unexplored |
| 163 |
unsigned char Radar[PlayerMax]; /// Visiblity for radar. |
| 164 |
unsigned char RadarJammer[PlayerMax]; /// Jamming capabilities. |
| 165 |
}; |
| 166 |
|
| 167 |
#define MapFieldSpeedMask 0x0007 /// Move faster on this tile |
| 168 |
|
| 169 |
#define MapFieldShallowWater 0x0008 /// Small water units allowed |
| 170 |
#define MapFieldLandAllowed 0x0010 /// Land units allowed |
| 171 |
#define MapFieldCoastAllowed 0x0020 /// Coast (transporter) units allowed |
| 172 |
#define MapFieldDeepWater 0x0040 /// Small and big water units allowed |
| 173 |
#define MapFieldNoBuilding 0x0080 /// No buildings allowed, except neutral (e.g. rocks) |
| 174 |
|
| 175 |
#define MapFieldUnpassable 0x0100 /// Field is movement blocked |
| 176 |
#define MapFieldTransparent 0x0200 /// Field is transparent |
| 177 |
|
| 178 |
#define MapFieldPatchMask 0x01FF /// Flags copied from patch to map field |
| 179 |
|
| 180 |
#define MapFieldLandUnit 0x1000 /// Land unit on field |
| 181 |
#define MapFieldAirUnit 0x2000 /// Air unit on field |
| 182 |
#define MapFieldSeaUnit 0x4000 /// Water unit on field |
| 183 |
#define MapFieldBuilding 0x8000 /// Building on field |
| 184 |
|
| 185 |
#define MapFieldNormalSpeed 3 /// Normal CMapField::Flags & MapFieldSpeedMask |
| 186 |
#define MapFieldNormalCost (1 << MapFieldNormalSpeed) /// Normal CMapField::Cost |
| 187 |
|
| 188 |
/*---------------------------------------------------------------------------- |
| 189 |
-- Map info structure |
| 190 |
----------------------------------------------------------------------------*/ |
| 191 |
|
| 192 |
/** |
| 193 |
** Get info about a map. |
| 194 |
*/ |
| 195 |
class CMapInfo |
| 196 |
{ |
| 197 |
public: |
| 198 |
std::string Description; /// Map description |
| 199 |
std::string Filename; /// Map setup filename |
| 200 |
int MapWidth; /// Map width |
| 201 |
int MapHeight; /// Map height |
| 202 |
int PlayerType[PlayerMax]; /// Same player->Type |
| 203 |
int PlayerSide[PlayerMax]; /// Same player->Side |
| 204 |
unsigned int MapUID; /// Unique Map ID (hash) |
| 205 |
}; |
| 206 |
|
| 207 |
/*---------------------------------------------------------------------------- |
| 208 |
-- Map itself |
| 209 |
----------------------------------------------------------------------------*/ |
| 210 |
|
| 211 |
/// Describes the world map |
| 212 |
class CMap |
| 213 |
{ |
| 214 |
public: |
| 215 |
|
| 216 |
/// Alocate and initialise map table. |
| 217 |
void Create(); |
| 218 |
/// Build tables for map |
| 219 |
void Init(); |
| 220 |
/// Clean the map |
| 221 |
void Clean(); |
| 222 |
/// Cleanup memory for fog of war tables |
| 223 |
void CleanFogOfWar(); |
| 224 |
|
| 225 |
/// Find if a tile is visible (with shared vision). |
| 226 |
unsigned short IsTileVisible(const CPlayer *player, int x, int y) const; |
| 227 |
|
| 228 |
/// Check if a field for the user is explored. |
| 229 |
bool IsFieldExplored(const CPlayer *player, int x, int y) const |
| 230 |
{ |
| 231 |
return IsTileVisible(player, x, y) > 0; |
| 232 |
} |
| 233 |
/// Check if a field for the user is visible. |
| 234 |
bool IsFieldVisible(const CPlayer *player, int x, int y) const |
| 235 |
{ |
| 236 |
return IsTileVisible(player, x, y) > 1; |
| 237 |
} |
| 238 |
|
| 239 |
/// Reveal the complete map, make everything known. |
| 240 |
void Reveal(void); |
| 241 |
/// Save the map. |
| 242 |
void Save(CFile *file) const; |
| 243 |
|
| 244 |
/// Get the MapField at location x,y |
| 245 |
inline CMapField *Field(int x, int y) const { |
| 246 |
return &this->Fields[x + y * this->Info.MapWidth]; |
| 247 |
} |
| 248 |
|
| 249 |
// |
| 250 |
// Tile type. |
| 251 |
// |
| 252 |
/// Returns true, if water on the map tile field |
| 253 |
bool WaterOnMap(int x, int y) const; |
| 254 |
/// Returns true, if coast on the map tile field |
| 255 |
bool CoastOnMap(int x, int y) const; |
| 256 |
|
| 257 |
|
| 258 |
private: |
| 259 |
/// Build tables for fog of war |
| 260 |
void InitFogOfWar(void); |
| 261 |
|
| 262 |
public: |
| 263 |
CMapField *Fields; /// fields on map |
| 264 |
unsigned *Visible[PlayerMax]; /// visible bit-field |
| 265 |
|
| 266 |
bool NoFogOfWar; /// fog of war disabled |
| 267 |
|
| 268 |
static CGraphic *FogGraphic; /// graphic for fog of war |
| 269 |
|
| 270 |
CPatchManager PatchManager; |
| 271 |
|
| 272 |
CMapInfo Info; /// descriptive information |
| 273 |
}; |
| 274 |
|
| 275 |
/*---------------------------------------------------------------------------- |
| 276 |
-- Variables |
| 277 |
----------------------------------------------------------------------------*/ |
| 278 |
|
| 279 |
extern CMap Map; /// The current map |
| 280 |
extern char CurrentMapPath[1024]; /// Path to the current map |
| 281 |
|
| 282 |
/// Vision Table to see where to locate goals and vision |
| 283 |
extern unsigned char *VisionTable[3]; |
| 284 |
/// Companion table for fast lookups |
| 285 |
extern int *VisionLookup; |
| 286 |
|
| 287 |
/// Flag must reveal the map |
| 288 |
extern int FlagRevealMap; |
| 289 |
/// Flag must reveal map when in replay |
| 290 |
extern int ReplayRevealMap; |
| 291 |
|
| 292 |
extern int TileSizeX; /// Size of a tile in X |
| 293 |
extern int TileSizeY; /// Size of a tile in Y |
| 294 |
|
| 295 |
/*---------------------------------------------------------------------------- |
| 296 |
-- Functions |
| 297 |
----------------------------------------------------------------------------*/ |
| 298 |
|
| 299 |
// |
| 300 |
// in map_fog.cpp |
| 301 |
// |
| 302 |
/// Function to (un)mark the vision table. |
| 303 |
typedef void MapMarkerFunc(const CPlayer *player, int x, int y); |
| 304 |
|
| 305 |
/// Filter map flags through fog |
| 306 |
extern int MapFogFilterFlags(CPlayer *player, int x, int y, int mask); |
| 307 |
/// Mark a tile for normal sight |
| 308 |
extern MapMarkerFunc MapMarkTileSight; |
| 309 |
/// Unmark a tile for normal sight |
| 310 |
extern MapMarkerFunc MapUnmarkTileSight; |
| 311 |
|
| 312 |
/// Mark sight changes |
| 313 |
extern void MapSight(const CPlayer *player, int x, int y, int w, |
| 314 |
int h, int range, MapMarkerFunc *marker); |
| 315 |
/// Mark tiles with fog of war to be redrawn |
| 316 |
extern void MapUpdateFogOfWar(int x, int y); |
| 317 |
/// Update fog of war |
| 318 |
extern void UpdateFogOfWarChange(void); |
| 319 |
|
| 320 |
/// Builds Vision and Goal Tables |
| 321 |
extern void InitVisionTable(void); |
| 322 |
/// Cleans up Vision and Goal Tables |
| 323 |
extern void FreeVisionTable(void); |
| 324 |
|
| 325 |
// |
| 326 |
// in map_radar.cpp |
| 327 |
// |
| 328 |
|
| 329 |
/// Check if a unit is visible on radar |
| 330 |
extern bool UnitVisibleOnRadar(const CPlayer *pradar, const CUnit *punit); |
| 331 |
/// Check if a tile is visible on radar |
| 332 |
extern unsigned char IsTileRadarVisible(const CPlayer *pradar, const CPlayer *punit, int x, int y); |
| 333 |
/// Mark a tile as radar visible, or incrase radar vision |
| 334 |
extern void MapMarkTileRadar(const CPlayer *player, int x, int y); |
| 335 |
/// Unmark a tile as radar visible, decrease is visible by other radar |
| 336 |
extern void MapUnmarkTileRadar(const CPlayer *player, int x, int y); |
| 337 |
/// Mark a tile as radar jammed, or incrase radar jamming'ness |
| 338 |
extern void MapMarkTileRadarJammer(const CPlayer *player, int x, int y); |
| 339 |
/// Unmark a tile as jammed, decrease is jamming'ness |
| 340 |
extern void MapUnmarkTileRadarJammer(const CPlayer *player, int x, int y); |
| 341 |
|
| 342 |
// |
| 343 |
// in script_map.cpp |
| 344 |
// |
| 345 |
/// register ccl features |
| 346 |
extern void MapCclRegister(void); |
| 347 |
|
| 348 |
// |
| 349 |
// mixed sources |
| 350 |
// |
| 351 |
/// Save a stratagus map (smp format) |
| 352 |
extern int SaveStratagusMap(const std::string &filename, CMap *map); |
| 353 |
|
| 354 |
|
| 355 |
/// Load map presentation |
| 356 |
extern void LoadStratagusMapInfo(const std::string &mapname); |
| 357 |
/// Release info for a map |
| 358 |
extern void FreeMapInfo(CMapInfo *info); |
| 359 |
|
| 360 |
/// Returns true, if the unit-type(mask can enter field with bounds check |
| 361 |
extern bool CheckedCanMoveToMask(int x, int y, int mask); |
| 362 |
/// Returns true, if the unit-type can enter the field |
| 363 |
extern bool UnitTypeCanBeAt(const CUnitType *type, int x, int y); |
| 364 |
/// Returns true, if the unit can enter the field |
| 365 |
extern bool UnitCanBeAt(const CUnit *unit, int x, int y); |
| 366 |
|
| 367 |
// in unit.cpp |
| 368 |
|
| 369 |
/// Mark on vision table the Sight of the unit. |
| 370 |
void MapMarkUnitSight(CUnit *unit); |
| 371 |
/// Unmark on vision table the Sight of the unit. |
| 372 |
void MapUnmarkUnitSight(CUnit *unit); |
| 373 |
|
| 374 |
/*---------------------------------------------------------------------------- |
| 375 |
-- Defines |
| 376 |
----------------------------------------------------------------------------*/ |
| 377 |
|
| 378 |
/// Can a unit with 'mask' enter the field |
| 379 |
inline bool CanMoveToMask(int x, int y, int mask) { |
| 380 |
return !(Map.Field(x, y)->Flags & mask); |
| 381 |
} |
| 382 |
|
| 383 |
inline void MapMarkSight(const CPlayer *player, int x, int y, int w, int h, int range) { |
| 384 |
MapSight(player, x, y, w, h, range, MapMarkTileSight); |
| 385 |
} |
| 386 |
inline void MapUnmarkSight(const CPlayer *player, int x, int y, int w, int h, int range) { |
| 387 |
MapSight(player, x, y, w, h, range, MapUnmarkTileSight); |
| 388 |
} |
| 389 |
|
| 390 |
/// Handle Marking and Unmarking of radar vision |
| 391 |
inline void MapMarkRadar(const CPlayer *player, int x, int y, int w, int h, int range) { |
| 392 |
MapSight(player, x, y, w, h, range, MapMarkTileRadar); |
| 393 |
} |
| 394 |
inline void MapUnmarkRadar(const CPlayer *player, int x, int y, int w, int h, int range) { |
| 395 |
MapSight(player, x, y, w, h, range, MapUnmarkTileRadar); |
| 396 |
} |
| 397 |
/// Handle Marking and Unmarking of radar vision |
| 398 |
inline void MapMarkRadarJammer(const CPlayer *player, int x, int y, int w, int h, int range) { |
| 399 |
MapSight(player, x, y, w, h, range, MapMarkTileRadarJammer); |
| 400 |
} |
| 401 |
inline void MapUnmarkRadarJammer(const CPlayer *player, int x, int y, int w, int h, int range) { |
| 402 |
MapSight(player, x, y, w, h, range, MapUnmarkTileRadarJammer); |
| 403 |
} |
| 404 |
|
| 405 |
//@} |
| 406 |
|
| 407 |
#endif // !__MAP_H__ |