_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
map.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 1998-2006 by Vladi Shabanski, Lutz Sammer, and
14 // Jimmy Salmon
15 //
16 // This program is free software; you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation; only version 2 of the License.
19 //
20 // This program is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with this program; if not, write to the Free Software
27 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 // 02111-1307, USA.
29 //
30 
31 #ifndef __MAP_H__
32 #define __MAP_H__
33 
35 
36 /*----------------------------------------------------------------------------
37 -- Documentation
38 ----------------------------------------------------------------------------*/
39 
81 /*----------------------------------------------------------------------------
82 -- Includes
83 ----------------------------------------------------------------------------*/
84 
85 #include <string>
86 
87 #ifndef __MAP_TILE_H__
88 #include "tile.h"
89 #endif
90 
91 #include "color.h"
92 #include "vec2i.h"
93 
94 /*----------------------------------------------------------------------------
95 -- Declarations
96 ----------------------------------------------------------------------------*/
97 
98 class CGraphic;
99 class CPlayer;
100 class CFile;
101 class CTileset;
102 class CUnit;
103 class CUnitType;
104 
105 /*----------------------------------------------------------------------------
106 -- Map
107 ----------------------------------------------------------------------------*/
108 
109 #define MaxMapWidth 256
110 #define MaxMapHeight 256
111 
112 /*----------------------------------------------------------------------------
113 -- Map info structure
114 ----------------------------------------------------------------------------*/
115 
119 class CMapInfo
120 {
121 public:
122  bool IsPointOnMap(int x, int y) const
123  {
124  return (x >= 0 && y >= 0 && x < MapWidth && y < MapHeight);
125  }
126 
127  bool IsPointOnMap(const Vec2i &pos) const
128  {
129  return IsPointOnMap(pos.x, pos.y);
130  }
131 
132  void Clear();
133 
134 public:
135  std::string Description;
136  std::string Filename;
137  int MapWidth;
138  int MapHeight;
141  unsigned int MapUID;
142 };
143 
144 /*----------------------------------------------------------------------------
145 -- Map itself
146 ----------------------------------------------------------------------------*/
147 
149 class CMap
150 {
151 public:
152  CMap();
153  ~CMap();
154 
155  unsigned int getIndex(int x, int y) const
156  {
157  return x + y * this->Info.MapWidth;
158  }
159  unsigned int getIndex(const Vec2i &pos) const
160  {
161  return getIndex(pos.x, pos.y);
162  }
163 
164  CMapField *Field(unsigned int index) const
165  {
166  return &this->Fields[index];
167  }
169  CMapField *Field(int x, int y) const
170  {
171  return &this->Fields[x + y * this->Info.MapWidth];
172  }
173  CMapField *Field(const Vec2i &pos) const
174  {
175  return Field(pos.x, pos.y);
176  }
177 
179  void Create();
181  void Init();
183  void Clean();
185  void CleanFogOfWar();
186 
188  void ClearWoodTile(const Vec2i &pos);
190  void ClearRockTile(const Vec2i &pos);
191 
193  Vec2i MapPixelPosToTilePos(const PixelPos &mapPos) const;
195  PixelPos TilePosToMapPixelPos_TopLeft(const Vec2i &tilePos) const;
197  PixelPos TilePosToMapPixelPos_Center(const Vec2i &tilePos) const;
198 
200  void MarkSeenTile(CMapField &mf);
201 
203  void RegenerateForest();
205  void Reveal();
207  void Save(CFile &file) const;
208 
209  //
210  // Wall
211  //
213  void HitWall(const Vec2i &pos, unsigned damage);
215  void RemoveWall(const Vec2i &pos);
217  void SetWall(const Vec2i &pos, bool humanwall);
218 
220  bool WallOnMap(const Vec2i &pos) const;
222  bool HumanWallOnMap(const Vec2i &pos) const;
224  bool OrcWallOnMap(const Vec2i &pos) const;
225 
226  //UnitCache
227 
229  void Insert(CUnit &unit);
230 
232  void Remove(CUnit &unit);
233 
234  void Clamp(Vec2i &pos) const;
235 
236  //Warning: we expect typical usage as xmin = x - range
237  void FixSelectionArea(Vec2i &minpos, Vec2i &maxpos)
238  {
239  minpos.x = std::max<short>(0, minpos.x);
240  minpos.y = std::max<short>(0, minpos.y);
241 
242  maxpos.x = std::min<short>(maxpos.x, Info.MapWidth - 1);
243  maxpos.y = std::min<short>(maxpos.y, Info.MapHeight - 1);
244  }
245 
246 private:
248  void InitFogOfWar();
249 
251  void FixNeighbors(unsigned short type, int seen, const Vec2i &pos);
253  void FixTile(unsigned short type, int seen, const Vec2i &pos);
254 
256  void RegenerateForestTile(const Vec2i &pos);
257 
258 public:
260  bool NoFogOfWar;
261 
263  std::string TileModelsFileName;
266 
268 };
269 
270 
271 /*----------------------------------------------------------------------------
272 -- Variables
273 ----------------------------------------------------------------------------*/
274 
275 extern CMap Map;
276 extern char CurrentMapPath[1024];
277 
279 extern int FogOfWarOpacity;
281 extern CColor FogOfWarColor;
283 extern int ForestRegeneration;
285 extern int FlagRevealMap;
287 extern int ReplayRevealMap;
288 
289 /*----------------------------------------------------------------------------
290 -- Functions
291 ----------------------------------------------------------------------------*/
292 #define MARKER_ON_INDEX
293 //
294 // in map_fog.c
295 //
297 #ifndef MARKER_ON_INDEX
298 typedef void MapMarkerFunc(const CPlayer &player, const Vec2i &pos);
299 #else
300 typedef void MapMarkerFunc(const CPlayer &player, const unsigned int index);
301 #endif
302 
304 extern int MapFogFilterFlags(CPlayer &player, const Vec2i &pos, int mask);
305 extern int MapFogFilterFlags(CPlayer &player, const unsigned int index, int mask);
314 
316 extern void MapSight(const CPlayer &player, const Vec2i &pos, int w,
317  int h, int range, MapMarkerFunc *marker);
319 extern void UpdateFogOfWarChange();
320 
321 //
322 // in map_radar.c
323 //
324 
327 
330 
333 
336 
337 
338 //
339 // in map_wall.c
340 //
342 extern void MapFixSeenWallTile(const Vec2i &pos);
344 extern void MapFixSeenWallNeighbors(const Vec2i &pos);
346 extern void MapFixWallTile(const Vec2i &pos);
347 
348 //
349 // in script_map.cpp
350 //
352 extern void SetTile(unsigned int tile, const Vec2i &pos, int value = 0);
353 inline void SetTile(unsigned int tile, int x, int y, int value = 0)
354 {
355  const Vec2i pos(x, y);
356  SetTile(tile, pos, value);
357 }
358 
360 extern void MapCclRegister();
361 
362 //
363 // mixed sources
364 //
366 extern int SaveStratagusMap(const std::string &filename, CMap &map, int writeTerrain);
367 
368 
370 extern void LoadStratagusMapInfo(const std::string &mapname);
371 
373 extern bool CheckedCanMoveToMask(const Vec2i &pos, int mask);
375 extern bool UnitTypeCanBeAt(const CUnitType &type, const Vec2i &pos);
377 extern bool UnitCanBeAt(const CUnit &unit, const Vec2i &pos);
378 
380 extern void PreprocessMap();
381 
382 // in unit.c
383 
385 void MapMarkUnitSight(CUnit &unit);
387 void MapUnmarkUnitSight(CUnit &unit);
388 
389 /*----------------------------------------------------------------------------
390 -- Defines
391 ----------------------------------------------------------------------------*/
392 
394 inline bool CanMoveToMask(const Vec2i &pos, int mask)
395 {
396  return !Map.Field(pos)->CheckMask(mask);
397 }
398 
400 inline void MapMarkRadar(const CPlayer &player, const Vec2i &pos, int w, int h, int range)
401 {
402  MapSight(player, pos, w, h, range, MapMarkTileRadar);
403 }
404 inline void MapUnmarkRadar(const CPlayer &player, const Vec2i &pos, int w, int h, int range)
405 {
406  MapSight(player, pos, w, h, range, MapUnmarkTileRadar);
407 }
409 inline void MapMarkRadarJammer(const CPlayer &player, const Vec2i &pos, int w, int h, int range)
410 {
411  MapSight(player, pos, w, h, range, MapMarkTileRadarJammer);
412 }
413 inline void MapUnmarkRadarJammer(const CPlayer &player, const Vec2i &pos, int w, int h, int range)
414 {
415  MapSight(player, pos, w, h, range, MapUnmarkTileRadarJammer);
416 }
417 
419 
420 #endif // !__MAP_H__
int FogOfWarOpacity
Path to the current map.
Definition: map_fog.cpp:54
CMapField * Field(int x, int y) const
Get the MapField at location x,y.
Definition: map.h:169
static CGraphic * FogGraphic
graphic for all the tiles
Definition: map.h:265
void RemoveWall(const Vec2i &pos)
Set wall on field.
Definition: map_wall.cpp:215
MapMarkerFunc MapMarkTileRadar
Mark a tile as radar visible, or incrase radar vision.
~CMap()
Definition: map.cpp:316
bool CheckMask(int mask) const
Check if a field flags.
Definition: mapfield.cpp:207
bool UnitCanBeAt(const CUnit &unit, const Vec2i &pos)
Returns true, if the unit can enter the field.
Definition: map.cpp:266
int FlagRevealMap
Flag must reveal the map.
Definition: map.cpp:55
void MapUnmarkRadar(const CPlayer &player, const Vec2i &pos, int w, int h, int range)
Definition: map.h:404
bool WallOnMap(const Vec2i &pos) const
Returns true, if wall on the map tile field.
Definition: map.cpp:188
CMap()
Definition: map.cpp:311
int ReplayRevealMap
Flag must reveal map when in replay.
Definition: map.cpp:56
A platform independent color.
Definition: color.h:39
CMapInfo Info
graphic for fog of war
Definition: map.h:267
MapMarkerFunc MapMarkTileRadarJammer
Mark a tile as radar jammed, or incrase radar jamming'ness.
void MarkSeenTile(CMapField &mf)
Mark a tile as seen by the player.
Definition: map.cpp:69
void Save(CFile &file) const
Save the map.
Definition: map.cpp:368
void MapUnmarkRadarJammer(const CPlayer &player, const Vec2i &pos, int w, int h, int range)
Definition: map.h:413
void CleanFogOfWar()
Cleanup memory for fog of war tables.
Definition: map_fog.cpp:752
T y
Definition: vec2i.h:43
CGraphic * TileGraphic
lua filename that loads all tilemodels
Definition: map.h:264
CTileset * Tileset
fog of war disabled
Definition: map.h:262
char CurrentMapPath[1024]
The current map.
Definition: map.cpp:58
Describes the world map.
Definition: map.h:149
void MapCclRegister()
register ccl features
Definition: script_map.cpp:546
std::string Filename
Map description.
Definition: map.h:136
bool IsPointOnMap(int x, int y) const
Definition: map.h:122
The big unit structure.
Definition: unit.h:119
#define PlayerMax
Definition: stratagus.h:157
MapMarkerFunc MapUnmarkTileRadarJammer
Unmark a tile as jammed, decrease is jamming'ness.
void MapFixWallTile(const Vec2i &pos)
Correct the real wall field, depending on the surrounding.
Definition: map_wall.cpp:167
MapMarkerFunc MapMarkTileSight
Mark a tile for normal sight.
unsigned int MapUID
Same player->Side.
Definition: map.h:141
void SetWall(const Vec2i &pos, bool humanwall)
Set wall on field.
Definition: map_wall.cpp:240
void MapFixSeenWallNeighbors(const Vec2i &pos)
Correct the surrounding seen wall fields.
Definition: map_wall.cpp:153
void ClearWoodTile(const Vec2i &pos)
Remove wood from the map.
Definition: map.cpp:520
bool CanMoveToMask(const Vec2i &pos, int mask)
Can a unit with 'mask' enter the field.
Definition: map.h:394
void Remove(CUnit &unit)
Remove unit from cache.
Definition: unit_cache.cpp:76
Tileset definition.
Definition: tileset.h:118
void HitWall(const Vec2i &pos, unsigned damage)
Wall is hit.
Definition: map_wall.cpp:268
unsigned int getIndex(int x, int y) const
Definition: map.h:155
CColor FogOfWarColor
fog of war color
Definition: map_fog.cpp:56
Definition: video.h:64
Definition: unittype.h:467
Definition: iolib.h:101
CMapField * Field(unsigned int index) const
Definition: map.h:164
MapMarkerFunc MapMarkTileDetectCloak
Mark a tile for cloak detection.
void PreprocessMap()
Preprocess map, for internal use.
Definition: map.cpp:278
int PlayerType[PlayerMax]
Map height.
Definition: map.h:139
void MapFixSeenWallTile(const Vec2i &pos)
Correct the seen wall field, depending on the surrounding.
Definition: map_wall.cpp:123
void SetTile(unsigned int tile, const Vec2i &pos, int value=0)
Set a tile.
Definition: script_map.cpp:339
std::string TileModelsFileName
tileset data
Definition: map.h:263
bool IsPointOnMap(const Vec2i &pos) const
Definition: map.h:127
bool HumanWallOnMap(const Vec2i &pos) const
Returns true, if human wall on the map tile field.
Definition: map.cpp:201
void MapMarkRadar(const CPlayer &player, const Vec2i &pos, int w, int h, int range)
Handle Marking and Unmarking of radar vision.
Definition: map.h:400
void Clamp(Vec2i &pos) const
Definition: unit_cache.cpp:96
bool NoFogOfWar
fields on map
Definition: map.h:260
bool OrcWallOnMap(const Vec2i &pos) const
Returns true, if orc wall on the map tile field.
Definition: map.cpp:214
int SaveStratagusMap(const std::string &filename, CMap &map, int writeTerrain)
Save a stratagus map (smp format)
Definition: game.cpp:616
void MapMarkUnitSight(CUnit &unit)
Mark on vision table the Sight of the unit.
Definition: unit.cpp:827
PixelPos TilePosToMapPixelPos_Center(const Vec2i &tilePos) const
convert tilepos coordonates into map pixel pos (take the center of the tile)
Definition: map.cpp:176
void UpdateFogOfWarChange()
Update fog of war.
Definition: map_fog.cpp:395
PixelPos TilePosToMapPixelPos_TopLeft(const Vec2i &tilePos) const
convert tilepos coordonates into map pixel pos (take the top left of the tile)
Definition: map.cpp:169
void FixSelectionArea(Vec2i &minpos, Vec2i &maxpos)
Definition: map.h:237
int MapFogFilterFlags(CPlayer &player, const Vec2i &pos, int mask)
Filter map flags through fog.
Definition: map_fog.cpp:113
bool CheckedCanMoveToMask(const Vec2i &pos, int mask)
Returns true, if the unit-type(mask can enter field with bounds check.
Definition: map.cpp:228
T x
Definition: vec2i.h:42
Diplomacy states for CommandDiplomacy.
Definition: player.h:79
void RegenerateForest()
Regenerate the forest.
Definition: map.cpp:622
CMap Map
Definition: map.cpp:54
CMapField * Field(const Vec2i &pos) const
Definition: map.h:173
void Clear()
Definition: map.cpp:301
MapMarkerFunc MapUnmarkTileSight
Unmark a tile for normal sight.
void Insert(CUnit &unit)
Insert new unit into cache.
Definition: unit_cache.cpp:52
void LoadStratagusMapInfo(const std::string &mapname)
Load map presentation.
Definition: map.cpp:641
Vec2i MapPixelPosToTilePos(const PixelPos &mapPos) const
convert map pixelpos coordonates into tilepos
Definition: map.cpp:162
bool UnitTypeCanBeAt(const CUnitType &type, const Vec2i &pos)
Returns true, if the unit-type can enter the field.
Definition: map.cpp:241
CMapField * Fields
Definition: map.h:259
MapMarkerFunc MapUnmarkTileRadar
Unmark a tile as radar visible, decrease is visible by other radar.
void MapSight(const CPlayer &player, const Vec2i &pos, int w, int h, int range, MapMarkerFunc *marker)
Mark sight changes.
Definition: map_fog.cpp:330
void Init()
Build tables for map.
Definition: map.cpp:335
void Reveal()
Reveal the complete map, make everything known.
Definition: map.cpp:131
int MapWidth
Map filename.
Definition: map.h:137
int MapHeight
Map width.
Definition: map.h:138
void Create()
Alocate and initialise map table.
Definition: map.cpp:324
std::string Description
Definition: map.h:135
unsigned int getIndex(const Vec2i &pos) const
Definition: map.h:159
MapMarkerFunc MapUnmarkTileDetectCloak
Unmark a tile for cloak detection.
Describes a field of the map.
Definition: tile.h:186
void Clean()
Clean the map.
Definition: map.cpp:343
int PlayerSide[PlayerMax]
Same player->Type.
Definition: map.h:140
int ForestRegeneration
Forest regeneration.
Definition: map.cpp:57
void MapMarkerFunc(const CPlayer &player, const unsigned int index)
Function to (un)mark the vision table.
Definition: map.h:300
void MapUnmarkUnitSight(CUnit &unit)
Unmark on vision table the Sight of the unit.
Definition: unit.cpp:855
void ClearRockTile(const Vec2i &pos)
Remove rock from the map.
Definition: map.cpp:538
void MapMarkRadarJammer(const CPlayer &player, const Vec2i &pos, int w, int h, int range)
Handle Marking and Unmarking of radar vision.
Definition: map.h:409
Definition: map.h:119
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.