$treeview $search $mathjax
Stratagus
2.2.7
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 // _________ __ __ 00002 // / _____// |_____________ _/ |______ ____ __ __ ______ 00003 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00004 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00005 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00006 // \/ \/ \//_____/ \/ 00007 // ______________________ ______________________ 00008 // T H E W A R B E G I N S 00009 // Stratagus - A free fantasy real time strategy game engine 00010 // 00012 // 00013 // (c) Copyright 1998-2006 by Vladi Shabanski, Lutz Sammer, and 00014 // Jimmy Salmon 00015 // 00016 // This program is free software; you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation; only version 2 of the License. 00019 // 00020 // This program is distributed in the hope that it will be useful, 00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 // GNU General Public License for more details. 00024 // 00025 // You should have received a copy of the GNU General Public License 00026 // along with this program; if not, write to the Free Software 00027 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00028 // 02111-1307, USA. 00029 // 00030 00031 #ifndef __MAP_H__ 00032 #define __MAP_H__ 00033 00035 00036 /*---------------------------------------------------------------------------- 00037 -- Documentation 00038 ----------------------------------------------------------------------------*/ 00039 00081 /*---------------------------------------------------------------------------- 00082 -- Includes 00083 ----------------------------------------------------------------------------*/ 00084 00085 #include <string> 00086 00087 #ifndef __TILESET_H__ 00088 #include "tileset.h" 00089 #endif 00090 00091 #ifndef __MAP_TILE_H__ 00092 #include "tile.h" 00093 #endif 00094 00095 #include "vec2i.h" 00096 00097 /*---------------------------------------------------------------------------- 00098 -- Declarations 00099 ----------------------------------------------------------------------------*/ 00100 00101 class CGraphic; 00102 class CPlayer; 00103 class CFile; 00104 class CUnit; 00105 class CUnitType; 00106 00107 /*---------------------------------------------------------------------------- 00108 -- Map 00109 ----------------------------------------------------------------------------*/ 00110 00111 #define MaxMapWidth 256 00112 #define MaxMapHeight 256 00113 00114 // Not used until now: 00115 #define MapFieldSpeedMask 0x0007 00116 00117 #define MapFieldHuman 0x0008 00118 00119 #define MapFieldLandAllowed 0x0010 00120 #define MapFieldCoastAllowed 0x0020 00121 #define MapFieldWaterAllowed 0x0040 00122 #define MapFieldNoBuilding 0x0080 00123 00124 #define MapFieldUnpassable 0x0100 00125 //#define MapFieldWall 0x0200 00126 00127 #define MapFieldLandUnit 0x1000 00128 #define MapFieldAirUnit 0x2000 00129 #define MapFieldSeaUnit 0x4000 00130 #define MapFieldBuilding 0x8000 00131 00132 /*---------------------------------------------------------------------------- 00133 -- Map info structure 00134 ----------------------------------------------------------------------------*/ 00135 00139 class CMapInfo 00140 { 00141 public: 00142 bool IsPointOnMap(int x, int y) const { 00143 return (x >= 0 && y >= 0 && x < MapWidth && y < MapHeight); 00144 } 00145 00146 bool IsPointOnMap(const Vec2i &pos) const { 00147 return IsPointOnMap(pos.x, pos.y); 00148 } 00149 00150 void Clear(); 00151 00152 public: 00153 std::string Description; 00154 std::string Filename; 00155 int MapWidth; 00156 int MapHeight; 00157 int PlayerType[PlayerMax]; 00158 int PlayerSide[PlayerMax]; 00159 unsigned int MapUID; 00160 }; 00161 00162 /*---------------------------------------------------------------------------- 00163 -- Map itself 00164 ----------------------------------------------------------------------------*/ 00165 00167 class CMap 00168 { 00169 public: 00170 inline unsigned int getIndex(int x, int y) const { 00171 return x + y * this->Info.MapWidth; 00172 } 00173 00174 unsigned int getIndex(const Vec2i &pos) const { 00175 return getIndex(pos.x, pos.y); 00176 } 00177 inline CMapField *Field(unsigned int index) const { 00178 return &this->Fields[index]; 00179 } 00180 00182 void Create(); 00184 void Init(); 00186 void Clean(); 00188 void CleanFogOfWar(); 00190 void ClearTile(unsigned short type, const Vec2i &pos); 00191 00193 Vec2i MapPixelPosToTilePos(const PixelPos &mapPos) const; 00195 PixelPos TilePosToMapPixelPos_TopLeft(const Vec2i &tilePos) const; 00197 PixelPos TilePosToMapPixelPos_Center(const Vec2i &tilePos) const; 00198 00208 unsigned short IsTileVisible(const CPlayer &player, const unsigned int index) const; 00209 00211 bool CheckMask(const unsigned int index, const int mask) const { 00212 return (this->Fields[index].Flags & mask) != 0; 00213 } 00214 00215 bool CheckMask(const Vec2i &pos, int mask) const { 00216 return CheckMask(getIndex(pos), mask); 00217 } 00218 00220 bool IsFieldExplored(const CPlayer &player, const unsigned int index) const; 00221 00223 bool IsFieldVisible(const CPlayer &player, const unsigned int index) const { 00224 return IsTileVisible(player, index) > 1; 00225 } 00226 00227 unsigned short IsTileVisible(const CPlayer &player, const Vec2i &pos) const { 00228 return IsTileVisible(player, getIndex(pos)); 00229 } 00230 00232 bool IsFieldExplored(const CPlayer &player, const Vec2i &pos) { 00233 Assert(Info.IsPointOnMap(pos)); 00234 return IsFieldExplored(player, getIndex(pos)); 00235 } 00236 00238 bool IsFieldVisible(const CPlayer &player, const Vec2i &pos) { 00239 return IsTileVisible(player, getIndex(pos)) > 1; 00240 } 00241 00243 void MarkSeenTile(const unsigned int index); 00244 00246 void MarkSeenTile(const Vec2i &pos) { 00247 Assert(Info.IsPointOnMap(pos)); 00248 MarkSeenTile(getIndex(pos)); 00249 } 00250 00252 void RegenerateForest(); 00254 void Reveal(); 00256 void Save(CFile &file) const; 00257 00259 inline CMapField *Field(int x, int y) const { 00260 return &this->Fields[x + y * this->Info.MapWidth]; 00261 } 00262 CMapField *Field(const Vec2i &pos) const { 00263 return Field(pos.x, pos.y); 00264 } 00265 00266 // return true if there is the specified (terrain) resource on map. 00267 bool IsTerrainResourceOnMap(const Vec2i &pos, int resource) const; 00268 bool IsTerrainResourceOnMap(const Vec2i &pos) const; 00269 00270 // 00271 // Wall 00272 // 00274 void HitWall(const Vec2i &pos, unsigned damage); 00276 void RemoveWall(const Vec2i &pos); 00278 void SetWall(const Vec2i &pos, int humanwall); 00279 00281 bool WallOnMap(const Vec2i &pos) const; 00283 bool HumanWallOnMap(const Vec2i &pos) const; 00285 bool OrcWallOnMap(const Vec2i &pos) const; 00286 00287 00288 // 00289 // Tile type. 00290 // 00291 00293 bool WaterOnMap(const unsigned int index) const { 00294 return CheckMask(index, MapFieldWaterAllowed); 00295 }; 00296 00304 bool WaterOnMap(const Vec2i &pos) const { 00305 Assert(Info.IsPointOnMap(pos)); 00306 return WaterOnMap(getIndex(pos)); 00307 } 00308 00310 bool CoastOnMap(const unsigned int index) const { 00311 return CheckMask(index, MapFieldCoastAllowed); 00312 }; 00313 00321 bool CoastOnMap(const Vec2i &pos) const { 00322 Assert(Info.IsPointOnMap(pos)); 00323 return CoastOnMap(getIndex(pos)); 00324 } 00325 00326 //UnitCache 00327 00329 void Insert(CUnit &unit); 00330 00332 void Remove(CUnit &unit); 00333 00334 void Clamp(Vec2i &pos) const; 00335 00336 //Warning: we expect typical usage as xmin = x - range 00337 void FixSelectionArea(Vec2i &minpos, Vec2i &maxpos) { 00338 minpos.x = std::max<short>(0, minpos.x); 00339 minpos.y = std::max<short>(0, minpos.y); 00340 00341 maxpos.x = std::min<short>(maxpos.x, Info.MapWidth - 1); 00342 maxpos.y = std::min<short>(maxpos.y, Info.MapHeight - 1); 00343 } 00344 00345 private: 00346 00348 bool ForestOnMap(const unsigned int index) const { 00349 return CheckMask(index, MapFieldForest); 00350 } 00351 00359 bool ForestOnMap(const Vec2i &pos) const { 00360 Assert(Info.IsPointOnMap(pos)); 00361 return ForestOnMap(getIndex(pos)); 00362 } 00363 00365 bool RockOnMap(const unsigned int index) const { 00366 return CheckMask(index, MapFieldRocks); 00367 } 00368 00376 bool RockOnMap(const Vec2i &pos) const { 00377 Assert(Info.IsPointOnMap(pos)); 00378 return RockOnMap(getIndex(pos)); 00379 } 00380 00382 void InitFogOfWar(); 00383 00385 void FixNeighbors(unsigned short type, int seen, const Vec2i &pos); 00387 void FixTile(unsigned short type, int seen, const Vec2i &pos); 00388 00390 void RegenerateForestTile(const Vec2i &pos); 00391 00392 00393 public: 00394 CMapField *Fields; 00395 00396 bool NoFogOfWar; 00397 00398 CTileset Tileset; 00399 std::string TileModelsFileName; 00400 CGraphic *TileGraphic; 00401 static CGraphic *FogGraphic; 00402 00403 CMapInfo Info; 00404 }; 00405 00406 00407 /*---------------------------------------------------------------------------- 00408 -- Variables 00409 ----------------------------------------------------------------------------*/ 00410 00411 extern CMap Map; 00412 extern char CurrentMapPath[1024]; 00413 00415 extern int FogOfWarOpacity; 00417 extern int FogOfWarColor[3]; 00419 extern int ForestRegeneration; 00421 extern int FlagRevealMap; 00423 extern int ReplayRevealMap; 00424 00425 /*---------------------------------------------------------------------------- 00426 -- Functions 00427 ----------------------------------------------------------------------------*/ 00428 #define MARKER_ON_INDEX 00429 // 00430 // in map_fog.c 00431 // 00433 #ifndef MARKER_ON_INDEX 00434 typedef void MapMarkerFunc(const CPlayer &player, const Vec2i &pos); 00435 #else 00436 typedef void MapMarkerFunc(const CPlayer &player, const unsigned int index); 00437 #endif 00438 00440 extern int MapFogFilterFlags(CPlayer &player, const Vec2i &pos, int mask); 00441 extern int MapFogFilterFlags(CPlayer &player, const unsigned int index, int mask); 00443 extern MapMarkerFunc MapMarkTileSight; 00445 extern MapMarkerFunc MapUnmarkTileSight; 00447 extern MapMarkerFunc MapMarkTileDetectCloak; 00449 extern MapMarkerFunc MapUnmarkTileDetectCloak; 00450 00452 extern void MapSight(const CPlayer &player, const Vec2i &pos, int w, 00453 int h, int range, MapMarkerFunc *marker); 00455 extern void UpdateFogOfWarChange(); 00456 00457 // 00458 // in map_radar.c 00459 // 00460 00462 extern MapMarkerFunc MapMarkTileRadar; 00463 00465 extern MapMarkerFunc MapUnmarkTileRadar; 00466 00468 extern MapMarkerFunc MapMarkTileRadarJammer; 00469 00471 extern MapMarkerFunc MapUnmarkTileRadarJammer; 00472 00473 00474 // 00475 // in map_wall.c 00476 // 00478 extern void MapFixSeenWallTile(const Vec2i &pos); 00480 extern void MapFixSeenWallNeighbors(const Vec2i &pos); 00482 extern void MapFixWallTile(const Vec2i &pos); 00483 00484 // 00485 // in script_map.c 00486 // 00488 extern void SetTile(int tile, const Vec2i &pos, int value = 0); 00489 00490 inline void SetTile(int tile, int x, int y, int value = 0) 00491 { 00492 const Vec2i pos(x, y); 00493 SetTile(tile, pos, value); 00494 } 00495 00497 extern void MapCclRegister(); 00498 00499 // 00500 // mixed sources 00501 // 00503 extern int SaveStratagusMap(const std::string &filename, CMap &map, int writeTerrain); 00504 00505 00507 extern void LoadStratagusMapInfo(const std::string &mapname); 00508 00510 extern bool CheckedCanMoveToMask(const Vec2i &pos, int mask); 00512 extern bool UnitTypeCanBeAt(const CUnitType &type, const Vec2i &pos); 00514 extern bool UnitCanBeAt(const CUnit &unit, const Vec2i &pos); 00515 00517 extern void PreprocessMap(); 00518 00519 // in unit.c 00520 00522 void MapMarkUnitSight(CUnit &unit); 00524 void MapUnmarkUnitSight(CUnit &unit); 00525 00526 /*---------------------------------------------------------------------------- 00527 -- Defines 00528 ----------------------------------------------------------------------------*/ 00529 00531 inline bool CanMoveToMask(const Vec2i &pos, int mask) 00532 { 00533 return !Map.CheckMask(pos, mask); 00534 } 00535 00537 inline void MapMarkRadar(const CPlayer &player, const Vec2i &pos, int w, int h, int range) 00538 { 00539 MapSight(player, pos, w, h, range, MapMarkTileRadar); 00540 } 00541 inline void MapUnmarkRadar(const CPlayer &player, const Vec2i &pos, int w, int h, int range) 00542 { 00543 MapSight(player, pos, w, h, range, MapUnmarkTileRadar); 00544 } 00546 inline void MapMarkRadarJammer(const CPlayer &player, const Vec2i &pos, int w, int h, int range) 00547 { 00548 MapSight(player, pos, w, h, range, MapMarkTileRadarJammer); 00549 } 00550 inline void MapUnmarkRadarJammer(const CPlayer &player, const Vec2i &pos, int w, int h, int range) 00551 { 00552 MapSight(player, pos, w, h, range, MapUnmarkTileRadarJammer); 00553 } 00554 00556 00557 #endif // !__MAP_H__