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 // 11 /**@name tile.h - The map tile headerfile. */ 12 // 13 // (c) Copyright 1998-2008 by Vladi Shabanski, Lutz Sammer, 14 // Jimmy Salmon and Rafal Bursig 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 #ifndef __MAP_TILE_H__ 31 #define __MAP_TILE_H__ 32 33 //@{ 34 35 36 /*---------------------------------------------------------------------------- 37 -- Documentation 38 ----------------------------------------------------------------------------*/ 39 40 /** 41 ** @class CMapField tile.h 42 ** 43 ** \#include "tile.h" 44 ** 45 ** CMapFieldPlayerInfo::SeenTile 46 ** 47 ** This is the tile number, that the player sitting on the computer 48 ** currently knows. Idea: Can be uses for illusions. 49 ** 50 ** CMapFieldPlayerInfo::Visible[] 51 ** 52 ** Counter how many units of the player can see this field. 0 the 53 ** field is not explored, 1 explored, n-1 unit see it. Currently 54 ** no more than 253 units can see a field. 55 ** 56 ** CMapFieldPlayerInfo::VisCloak[] 57 ** 58 ** Visiblity for cloaking. 59 ** 60 ** CMapFieldPlayerInfo::Radar[] 61 ** 62 ** Visiblity for radar. 63 ** 64 ** CMapFieldPlayerInfo::RadarJammer[] 65 ** 66 ** Jamming capabilities. 67 */ 68 69 /** 70 ** @class CMapField tile.h 71 ** 72 ** \#include "tile.h" 73 ** 74 ** This class contains all information about a field on map. 75 ** It contains its look, properties and content. 76 ** 77 ** The map-field class members: 78 ** 79 ** CMapField::Tile 80 ** 81 ** Tile is number defining the graphic image display for the 82 ** map-field. 65535 different tiles are supported. A tile is 83 ** currently 32x32 pixels. In the future is planned to support 84 ** animated tiles. 85 ** 86 ** CMapField::Flags 87 ** 88 ** Contains special information of that tile. What units are 89 ** on this field, what units could be placed on this field. 90 ** 91 ** This is the list of all flags currently used: 92 ** 93 ** ::MapFieldVisible field is visible. 94 ** ::MapFieldExplored field is explored. 95 ** ::MapFieldHuman human player is the owner of the field used for walls. 96 ** ::MapFieldLandAllowed land units are allowed. 97 ** ::MapFieldCoastAllowed coast units (transporter) and coast buildings (shipyard) are allowed. 98 ** ::MapFieldWaterAllowed water units allowed. 99 ** ::MapFieldNoBuilding no buildings allowed. 100 ** ::MapFieldUnpassable field is movement blocked. 101 ** ::MapFieldWall field contains wall. 102 ** ::MapFieldRocks field contains rocks. 103 ** ::MapFieldForest field contains forest. 104 ** ::MapFieldLandUnit land unit on field. 105 ** ::MapFieldAirUnit air unit on field. 106 ** ::MapFieldSeaUnit water unit on field. 107 ** ::MapFieldBuilding building on field. 108 ** 109 ** Note: We want to add support for more unit-types like under 110 ** ground units. 111 ** 112 ** CMapField::Cost 113 ** 114 ** Unit cost to move in this tile. 115 ** 116 ** CMapField::Value 117 ** 118 ** Extra value for each tile. This currently only used for 119 ** walls, contains the remaining hit points of the wall and 120 ** for forest, contains the frames until they grow. 121 ** 122 ** CMapField::UnitCache 123 ** 124 ** Contains a vector of all units currently on this field. 125 ** Note: currently units are only inserted at the insert point. 126 ** This means units of the size of 2x2 fields are inserted at the 127 ** top and right most map coordinate. 128 */ 129 130 131 /*---------------------------------------------------------------------------- 132 -- Includes 133 ----------------------------------------------------------------------------*/ 134 135 #ifndef __UNIT_CACHE_H__ 136 #include "unit_cache.h" 137 #endif 138 139 #include <vec2i.h> 140 141 class CFile; 142 class CPlayer; 143 class CTileset; 144 struct lua_State; 145 146 /*---------------------------------------------------------------------------- 147 -- Map - field 148 ----------------------------------------------------------------------------*/ 149 150 class CMapFieldPlayerInfo 151 { 152 public: CMapFieldPlayerInfo()153 CMapFieldPlayerInfo() : SeenTile(0) 154 { 155 memset(Visible, 0, sizeof(Visible)); 156 memset(VisCloak, 0, sizeof(VisCloak)); 157 memset(Radar, 0, sizeof(Radar)); 158 memset(RadarJammer, 0, sizeof(RadarJammer)); 159 } 160 161 /// Check if a field for the user is explored. 162 bool IsExplored(const CPlayer &player) const; 163 164 /// @note Manage Map.NoFogOfWar 165 bool IsVisible(const CPlayer &player) const; 166 bool IsTeamVisible(const CPlayer &player) const; 167 /** 168 ** Find out how a field is seen (By player, or by shared vision) 169 ** 170 ** @param player Player to check for. 171 ** @note manage fogOfWar (using Map.NoFogOfWar) 172 ** 173 ** @return 0 unexplored, 1 explored, 2 visible. 174 */ 175 unsigned char TeamVisibilityState(const CPlayer &player) const; 176 177 public: 178 unsigned short SeenTile; /// last seen tile (FOW) 179 unsigned short Visible[PlayerMax]; /// Seen counter 0 unexplored 180 unsigned char VisCloak[PlayerMax]; /// Visiblity for cloaking. 181 unsigned char Radar[PlayerMax]; /// Visiblity for radar. 182 unsigned char RadarJammer[PlayerMax]; /// Jamming capabilities. 183 }; 184 185 /// Describes a field of the map 186 class CMapField 187 { 188 public: 189 CMapField(); 190 191 void Save(CFile &file) const; 192 void parse(lua_State *l); 193 194 void setTileIndex(const CTileset &tileset, unsigned int tileIndex, int value); 195 getGraphicTile()196 unsigned int getGraphicTile() const { return tile; } 197 198 /// Check if a field is opaque for field of view 199 bool isOpaque() const; 200 201 /// Check if a field flags. 202 bool CheckMask(int mask) const; 203 204 /// Returns true, if water on the map tile field 205 bool WaterOnMap() const; 206 207 /// Returns true, if coast on the map tile field 208 bool CoastOnMap() const; 209 210 /// Returns true, if water on the map tile field 211 bool ForestOnMap() const; 212 213 /// Returns true, if coast on the map tile field 214 bool RockOnMap() const; 215 216 /// Returns true if the field should not need mixing with the surroundings 217 bool isDecorative() const; 218 219 bool isAWall() const; 220 bool isHuman() const; 221 bool isAHumanWall() const; 222 bool isAOrcWall() const; 223 224 bool IsTerrainResourceOnMap(int resource) const; 225 bool IsTerrainResourceOnMap() const; 226 getCost()227 unsigned char getCost() const { return cost; } getFlag()228 unsigned int getFlag() const { return Flags; } setGraphicTile(unsigned int tile)229 void setGraphicTile(unsigned int tile) { this->tile = tile; } 230 private: 231 #ifdef DEBUG 232 unsigned int tilesetTile; /// tileset tile number 233 #endif 234 unsigned short tile; /// graphic tile number 235 public: 236 unsigned int Flags; /// field flags 237 private: 238 unsigned char cost; /// unit cost to move in this tile 239 public: 240 // FIXME: Value should be removed, walls and regeneration can be handled differently. 241 unsigned char Value; /// HP for walls/ Wood Regeneration 242 CUnitCache UnitCache; /// A unit on the map field. 243 244 CMapFieldPlayerInfo playerInfo; /// stuff related to player 245 }; 246 247 extern PixelSize PixelTileSize; /// Size of a tile in pixels 248 249 //@} 250 251 #endif // !__MAP_TILE_H__ 252 253