ManaPlus
Data Structures | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
Map Class Reference

#include <map.h>

Inheritance diagram for Map:
Properties ConfigListener MemoryCounter

Data Structures

struct  ParticleEffectData
 

Public Member Functions

 Map (const std::string &name, const int width, const int height, const int tileWidth, const int tileHeight)
 
 ~Map ()
 
void initializeAmbientLayers ()
 
void update (const int ticks)
 
void draw (Graphics *const graphics, int scrollX, int scrollY)
 
void drawCollision (Graphics *const graphics, const int scrollX, const int scrollY, const MapTypeT drawFlags) const
 
void addLayer (MapLayer *const layer)
 
void addTileset (Tileset *const tileset)
 
const TilesetgetTilesetWithGid (const int gid) const
 
const MetaTilegetMetaTile (const int x, const int y) const
 
void addBlockMask (const int x, const int y, const BlockTypeT type)
 
void setBlockMask (const int x, const int y, const BlockTypeT type)
 
bool getWalk (const int x, const int y, const unsigned char blockWalkMask) const
 
void setWalk (const int x, const int y)
 
unsigned char getBlockMask (const int x, const int y) const
 
int getWidth () const
 
int getHeight () const
 
int getTileWidth () const
 
int getTileHeight () const
 
const std::string getMusicFile () const
 
void setMusicFile (const std::string &file)
 
const std::string getName () const
 
const std::string getFilename () const
 
const std::string getGatName () const
 
Path findPath (const int startX, const int startY, const int destX, const int destY, const unsigned char blockWalkmask, const int maxCost)
 
void addParticleEffect (const std::string &effectFile, const int x, const int y, const int w, const int h)
 
void initializeParticleEffects () const
 
void addAnimation (const int gid, TileAnimation *const animation)
 
void setDrawLayersFlags (const MapTypeT &n)
 
MapTypeT getDrawLayersFlags () const
 
void addExtraLayer ()
 
void saveExtraLayer () const
 
SpecialLayergetTempLayer () const
 
SpecialLayergetSpecialLayer () const
 
void setHasWarps (const bool n)
 
bool getHasWarps () const
 
std::string getUserMapDirectory () const
 
void addPortal (const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
 
void addRange (const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
 
void addPortalTile (const std::string &name, const int type, const int x, const int y)
 
void updatePortalTile (const std::string &name, const int type, const int x, const int y, const bool addNew)
 
const std::vector< MapItem * > & getPortals () const
 
const TileAnimationgetAnimationForGid (const int gid) const
 
void optionChanged (const std::string &value)
 
MapItemfindPortalXY (const int x, const int y) const
 
int getActorsCount () const
 
void setPvpMode (const int mode)
 
int getPvpMode () const
 
const ObjectsLayergetObjectsLayer () const
 
std::string getObjectData (const unsigned x, const unsigned y, const int type) const
 
void indexTilesets ()
 
void clearIndexedTilesets ()
 
void setActorsFix (const int x, const int y)
 
int getVersion () const
 
void setVersion (const int n)
 
void reduce ()
 
void redrawMap ()
 
bool empty () const
 
void setCustom (const bool b)
 
bool isCustom () const
 
const std::map< int, TileAnimation * > & getTileAnimations () const
 
void setAtlas (Resource *const atlas)
 
const MetaTilegetMetaTiles () const
 
const WalkLayergetWalkLayer () const
 
void setWalkLayer (WalkLayer *const layer)
 
void addHeights (const MapHeights *const heights)
 
uint8_t getHeightOffset (const int x, const int y) const
 
void setMask (const int mask)
 
void updateDrawLayersList ()
 
bool isHeightsPresent () const
 
void updateConditionLayers ()
 
void preCacheLayers ()
 
int calcMemoryLocal () const
 
int calcMemoryChilds (const int level) const
 
std::string getCounterName () const
 
bool haveAtlas () const
 
- Public Member Functions inherited from Properties
 Properties ()
 
virtual ~Properties ()
 
const std::string getProperty (const std::string &name, const std::string &def) const
 
float getFloatProperty (const std::string &name, const float def) const
 
bool getBoolProperty (const std::string &name, const bool def) const
 
bool hasProperty (const std::string &name) const
 
void setProperty (const std::string &name, const std::string &value)
 
- Public Member Functions inherited from ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 

Protected Member Functions

Actors::iterator addActor (Actor *const actor)
 
void removeActor (const Actors::iterator &iterator)
 

Private Member Functions

void updateAmbientLayers (const float scrollX, const float scrollY)
 
void drawAmbientLayers (Graphics *const graphics, const MapLayerPositionT type, const int detail) const
 
bool contains (const int x, const int y) const
 

Private Attributes

const int mWidth
 
const int mHeight
 
const int mTileWidth
 
const int mTileHeight
 
int mMaxTileHeight
 
MetaTile *const mMetaTiles
 
WalkLayermWalkLayer
 
Layers mLayers
 
Layers mDrawUnderLayers
 
Layers mDrawOverLayers
 
Tilesets mTilesets
 
Actors mActors
 
bool mHasWarps
 
MapTypeT mDrawLayersFlags
 
unsigned int mOnClosedList
 
unsigned int mOnOpenList
 
AmbientLayerVector mBackgrounds
 
AmbientLayerVector mForegrounds
 
float mLastAScrollX
 
float mLastAScrollY
 
std::vector< ParticleEffectDatamParticleEffects
 
std::vector< MapItem * > mMapPortals
 
std::map< int, TileAnimation * > mTileAnimations
 
std::string mName
 
int mOverlayDetail
 
float mOpacity
 
const RenderType mOpenGL
 
int mPvp
 
bool mTilesetsIndexed
 
Tileset ** mIndexedTilesets
 
int mIndexedTilesetsSize
 
int mActorFixX
 
int mActorFixY
 
int mVersion
 
SpecialLayermSpecialLayer
 
SpecialLayermTempLayer
 
ObjectsLayermObjects
 
MapLayermFringeLayer
 
int mLastX
 
int mLastY
 
int mLastScrollX
 
int mLastScrollY
 
int mDrawX
 
int mDrawY
 
int mDrawScrollX
 
int mDrawScrollY
 
int mMask
 
ResourcemAtlas
 
const MapHeightsmHeights
 
bool mRedrawMap
 
bool mBeingOpacity
 
bool mCachedDraw
 
bool mCustom
 
bool mDrawOnlyFringe
 

Friends

class Actor
 
class Minimap
 

Detailed Description

A tile map.

Definition at line 68 of file map.h.

Constructor & Destructor Documentation

◆ Map()

Map::Map ( const std::string &  name,
const int  width,
const int  height,
const int  tileWidth,
const int  tileHeight 
)

Constructor, taking map and tile size as parameters.

Definition at line 93 of file map.cpp.

References Configuration::addListener(), config, Configuration::getBoolValue(), mBeingOpacity, and mOpacity.

Referenced by calcMemoryLocal().

97  :
98  Properties(),
99  mWidth(width), mHeight(height),
100  mTileWidth(tileWidth), mTileHeight(tileHeight),
101  mMaxTileHeight(height),
103  mWalkLayer(nullptr),
104  mLayers(),
106  mDrawOverLayers(),
107  mTilesets(),
108  mActors(),
109  mHasWarps(false),
111  mOnClosedList(1),
112  mOnOpenList(2),
113  mBackgrounds(),
114  mForegrounds(),
115  mLastAScrollX(0.0F),
116  mLastAScrollY(0.0F),
118  mMapPortals(),
119  mTileAnimations(),
120  mName(name),
121  mOverlayDetail(config.getIntValue("OverlayDetail")),
122  mOpacity(config.getFloatValue("guialpha")),
123 #ifdef USE_OPENGL
125 #else // USE_OPENGL
127 #endif // USE_OPENGL
128  mPvp(0),
129  mTilesetsIndexed(false),
130  mIndexedTilesets(nullptr),
132  mActorFixX(0),
133  mActorFixY(0),
134  mVersion(0),
135  mSpecialLayer(new SpecialLayer("special layer", width, height)),
136  mTempLayer(new SpecialLayer("temp layer", width, height)),
137  mObjects(new ObjectsLayer(width, height)),
138  mFringeLayer(nullptr),
139  mLastX(-1),
140  mLastY(-1),
141  mLastScrollX(-1),
142  mLastScrollY(-1),
143  mDrawX(-1),
144  mDrawY(-1),
145  mDrawScrollX(-1),
146  mDrawScrollY(-1),
147  mMask(1),
148  mAtlas(nullptr),
149  mHeights(nullptr),
150  mRedrawMap(true),
151  mBeingOpacity(false),
152 #ifdef USE_OPENGL
157 #else // USE_OPENGL
158  mCachedDraw(false),
159 #endif // USE_OPENGL
160  mCustom(false),
161  mDrawOnlyFringe(false)
162 {
163  config.addListener("OverlayDetail", this);
164  config.addListener("guialpha", this);
165  config.addListener("beingopacity", this);
166 
167  if (mOpacity != 1.0F)
168  mBeingOpacity = config.getBoolValue("beingopacity");
169  else
170  mBeingOpacity = false;
171 }
int mLastScrollY
Definition: map.h:479
Resource * mAtlas
Definition: map.h:486
const int mTileHeight
Definition: map.h:405
bool mDrawOnlyFringe
Definition: map.h:492
AmbientLayerVector mBackgrounds
Definition: map.h:424
int mLastX
Definition: map.h:476
const MapHeights * mHeights
Definition: map.h:487
Tilesets mTilesets
Definition: map.h:412
int mPvp
Definition: map.h:463
WalkLayer * mWalkLayer
Definition: map.h:408
int mDrawScrollY
Definition: map.h:484
Configuration config
int mOverlayDetail
Definition: map.h:460
int mActorFixY
Definition: map.h:468
SpecialLayer * mSpecialLayer
Definition: map.h:471
int mDrawX
Definition: map.h:481
int getIntValue(const std::string &key) const
float getFloatValue(const std::string &key) const
bool mHasWarps
Definition: map.h:414
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:457
ObjectsLayer * mObjects
Definition: map.h:473
bool mTilesetsIndexed
Definition: map.h:464
void addListener(const std::string &key, ConfigListener *const listener)
const int mTileWidth
Definition: map.h:404
std::vector< MapItem * > mMapPortals
Definition: map.h:455
Layers mLayers
Definition: map.h:409
float mLastAScrollX
Definition: map.h:426
int mLastScrollX
Definition: map.h:478
bool getBoolValue(const std::string &key) const
bool mCustom
Definition: map.h:491
MapTypeT mDrawLayersFlags
Definition: map.h:417
int mActorFixX
Definition: map.h:467
std::string mName
Definition: map.h:459
AmbientLayerVector mForegrounds
Definition: map.h:425
bool mRedrawMap
Definition: map.h:488
int mIndexedTilesetsSize
Definition: map.h:466
RenderType intToRenderType(const int mode)
Definition: renderers.cpp:42
bool mCachedDraw
Definition: map.h:490
int mMaxTileHeight
Definition: map.h:406
const int mHeight
Definition: map.h:403
SpecialLayer * mTempLayer
Definition: map.h:472
MetaTile *const mMetaTiles
Definition: map.h:407
const int mWidth
Definition: map.h:402
unsigned int mOnOpenList
Definition: map.h:421
int mDrawY
Definition: map.h:482
int mLastY
Definition: map.h:477
unsigned int mOnClosedList
Definition: map.h:420
MapLayer * mFringeLayer
Definition: map.h:474
float mLastAScrollY
Definition: map.h:427
const RenderType mOpenGL
Definition: map.h:462
float mOpacity
Definition: map.h:461
Layers mDrawUnderLayers
Definition: map.h:410
int mVersion
Definition: map.h:469
bool mBeingOpacity
Definition: map.h:489
int mDrawScrollX
Definition: map.h:483
Layers mDrawOverLayers
Definition: map.h:411
Tileset ** mIndexedTilesets
Definition: map.h:465
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:453
Actors mActors
Definition: map.h:413
int mMask
Definition: map.h:485

◆ ~Map()

Map::~Map ( )

Destructor.

Definition at line 173 of file map.cpp.

References CHECKLISTENERS, config, Resource::decRef(), delete2, delete_all(), mAtlas, mBackgrounds, mForegrounds, mFringeLayer, mHeights, mLayers, mMapPortals, mMetaTiles, mObjects, mSpecialLayer, mTempLayer, mTileAnimations, mTilesets, mWalkLayer, and Configuration::removeListeners().

174 {
175  config.removeListeners(this);
177 
178  if (mWalkLayer != nullptr)
179  {
180  mWalkLayer->decRef();
181  mWalkLayer = nullptr;
182  }
183  mFringeLayer = nullptr;
191  delete2(mObjects);
193  if (mAtlas != nullptr)
194  {
195  mAtlas->decRef();
196  mAtlas = nullptr;
197  }
198  delete2(mHeights);
199  delete [] mMetaTiles;
200 }
Resource * mAtlas
Definition: map.h:486
AmbientLayerVector mBackgrounds
Definition: map.h:424
virtual void decRef()
Definition: resource.cpp:49
const MapHeights * mHeights
Definition: map.h:487
Tilesets mTilesets
Definition: map.h:412
WalkLayer * mWalkLayer
Definition: map.h:408
Configuration config
SpecialLayer * mSpecialLayer
Definition: map.h:471
#define delete2(var)
Definition: delete2.h:24
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:457
ObjectsLayer * mObjects
Definition: map.h:473
std::vector< MapItem * > mMapPortals
Definition: map.h:455
Layers mLayers
Definition: map.h:409
void delete_all(Container &c)
Definition: dtor.h:55
AmbientLayerVector mForegrounds
Definition: map.h:425
SpecialLayer * mTempLayer
Definition: map.h:472
MetaTile *const mMetaTiles
Definition: map.h:407
void removeListeners(ConfigListener *const listener)
MapLayer * mFringeLayer
Definition: map.h:474
#define CHECKLISTENERS
Definition: localconsts.h:305

Member Function Documentation

◆ addActor()

Actors::iterator Map::addActor ( Actor *const  actor)
protected

Adds an actor to the map.

Definition at line 810 of file map.cpp.

References mActors.

Referenced by Actor::setMap().

811 {
812  mActors.push_front(actor);
813 // mSpritesUpdated = true;
814  return mActors.begin();
815 }
Actors mActors
Definition: map.h:413

◆ addAnimation()

void Map::addAnimation ( const int  gid,
TileAnimation *const  animation 
)

Adds a tile animation to the map

Definition at line 1679 of file map.cpp.

References Logger::log(), logger, and mTileAnimations.

Referenced by getTileHeight(), and MapReader::readTileset().

1681 {
1682  std::map<int, TileAnimation*>::iterator it = mTileAnimations.find(gid);
1683  if (it != mTileAnimations.end())
1684  {
1685  logger->log("duplicate map animation with gid = %d", gid);
1686  delete (*it).second;
1687  }
1688  mTileAnimations[gid] = animation;
1689 }
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:457
Logger * logger
Definition: logger.cpp:95
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ addBlockMask()

void Map::addBlockMask ( const int  x,
const int  y,
const BlockTypeT  type 
)

Definition at line 695 of file map.cpp.

References BlockMask::AIR, BlockType::AIR, MetaTile::blockmask, contains(), BlockType::GROUND, BlockMask::GROUND, BlockMask::GROUNDTOP, BlockType::GROUNDTOP, mMetaTiles, BlockMask::MONSTERWALL, BlockType::MONSTERWALL, mWidth, BlockType::NB_BLOCKTYPES, BlockType::NONE, BlockMask::PLAYERWALL, BlockType::PLAYERWALL, BlockMask::WALL, BlockType::WALL, BlockMask::WATER, BlockType::WATER, x, and y.

Referenced by setTile(), and setWalk().

697 {
698  if (type == BlockType::NONE || !contains(x, y))
699  return;
700 
701  const int tileNum = x + y * mWidth;
702 
703  switch (type)
704  {
705  case BlockType::WALL:
707  break;
708  case BlockType::AIR:
709  mMetaTiles[tileNum].blockmask |= BlockMask::AIR;
710  break;
711  case BlockType::WATER:
713  break;
714  case BlockType::GROUND:
716  break;
719  break;
722  break;
725  break;
726  default:
727  case BlockType::NONE:
729  // Do nothing.
730  break;
731  }
732 }
bool contains(const int x, const int y) const
Definition: map.cpp:800
unsigned char blockmask
Definition: metatile.h:51
MetaTile *const mMetaTiles
Definition: map.h:407
const int mWidth
Definition: map.h:402

◆ addExtraLayer()

void Map::addExtraLayer ( )

Definition at line 1129 of file map.cpp.

References addPortalTile(), MapItemType::ARROW_RIGHT, MapItemType::ARROW_UP, BLOCK_END, BLOCK_START, getUserMapDirectory(), MapItemType::HOME, Logger::log(), Logger::log1(), logger, mSpecialLayer, pathJoin(), MapItemType::PORTAL, ServerCommandType::str, updatePortalTile(), x, and y.

Referenced by Game::changeMap(), and getDrawLayersFlags().

1130 {
1131  BLOCK_START("Map::addExtraLayer")
1132  if (mSpecialLayer == nullptr)
1133  {
1134  logger->log1("No special layer");
1135  BLOCK_END("Map::addExtraLayer")
1136  return;
1137  }
1138  const std::string mapFileName = pathJoin(getUserMapDirectory(),
1139  "extralayer.txt");
1140  logger->log("loading extra layer: " + mapFileName);
1141  struct stat statbuf;
1142  if (stat(mapFileName.c_str(), &statbuf) == 0 &&
1143  S_ISREG(statbuf.st_mode))
1144  {
1145  std::ifstream mapFile;
1146  mapFile.open(mapFileName.c_str(), std::ios::in);
1147  if (!mapFile.is_open())
1148  {
1149  mapFile.close();
1150  BLOCK_END("Map::addExtraLayer")
1151  return;
1152  }
1153  char line[201];
1154 
1155  while (mapFile.getline(line, 200))
1156  {
1157  std::string buf;
1158  std::string str = line;
1159  if (!str.empty())
1160  {
1161  std::string x;
1162  std::string y;
1163  std::string type1;
1164  std::string comment;
1165  std::stringstream ss(str);
1166  ss >> x;
1167  ss >> y;
1168  ss >> type1;
1169  ss >> comment;
1170  while (ss >> buf)
1171  comment.append(" ").append(buf);
1172 
1173  const int type = atoi(type1.c_str());
1174 
1175  if (comment.empty())
1176  {
1177  if (type < MapItemType::ARROW_UP
1178  || type > MapItemType::ARROW_RIGHT)
1179  {
1180  comment = "unknown";
1181  }
1182  }
1183  if (type == MapItemType::PORTAL)
1184  {
1185  updatePortalTile(comment,
1186  type,
1187  atoi(x.c_str()),
1188  atoi(y.c_str()),
1189  false);
1190  }
1191  else if (type == MapItemType::HOME)
1192  {
1193  updatePortalTile(comment,
1194  type,
1195  atoi(x.c_str()),
1196  atoi(y.c_str()),
1197  true);
1198  }
1199  else
1200  {
1201  addPortalTile(comment,
1202  type,
1203  atoi(x.c_str()),
1204  atoi(y.c_str()));
1205  }
1206  }
1207  }
1208  mapFile.close();
1209  }
1210  BLOCK_END("Map::addExtraLayer")
1211 }
void updatePortalTile(const std::string &name, const int type, const int x, const int y, const bool addNew)
Definition: map.cpp:1300
void log1(const char *const log_text)
Definition: logger.cpp:222
std::string getUserMapDirectory() const
Definition: map.cpp:1260
std::string pathJoin(std::string str1, const std::string &str2)
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
SpecialLayer * mSpecialLayer
Definition: map.h:471
#define BLOCK_END(name)
Definition: perfomance.h:79
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1287
Logger * logger
Definition: logger.cpp:95

◆ addHeights()

void Map::addHeights ( const MapHeights *const  heights)

Definition at line 1613 of file map.cpp.

References mHeights.

Referenced by MapReader::readLayer(), and setWalkLayer().

1614 {
1615  delete mHeights;
1616  mHeights = heights;
1617 }
const MapHeights * mHeights
Definition: map.h:487

◆ addLayer()

void Map::addLayer ( MapLayer *const  layer)

Adds a layer to this map. The map takes ownership of the layer.

Definition at line 304 of file map.cpp.

References mFringeLayer, and mLayers.

Referenced by MapReader::createEmptyMap(), and MapReader::readLayer().

305 {
306  mLayers.push_back(layer);
307  if (layer->isFringeLayer() && (mFringeLayer == nullptr))
308  mFringeLayer = layer;
309 }
Layers mLayers
Definition: map.h:409
MapLayer * mFringeLayer
Definition: map.h:474
bool isFringeLayer() const
Definition: maplayer.h:137

◆ addParticleEffect()

void Map::addParticleEffect ( const std::string &  effectFile,
const int  x,
const int  y,
const int  w,
const int  h 
)

Adds a particle effect

Definition at line 1088 of file map.cpp.

References mParticleEffects, x, and y.

Referenced by getTileHeight(), and loadReplaceLayer().

1091 {
1092  ParticleEffectData newEffect(effectFile, x, y, w, h);
1093  mParticleEffects.push_back(newEffect);
1094 }
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:453

◆ addPortal()

void Map::addPortal ( const std::string &  name,
const int  type,
const int  x,
const int  y,
const int  dx,
const int  dy 
)

Definition at line 1278 of file map.cpp.

References addPortalTile(), mapTileSize, x, and y.

Referenced by getHasWarps(), and loadReplaceLayer().

1282 {
1283  addPortalTile(name, type, (x / mapTileSize) + (dx / mapTileSize / 2),
1284  (y / mapTileSize) + (dy / mapTileSize / 2));
1285 }
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1287
static const int mapTileSize
Definition: map.h:26

◆ addPortalTile()

void Map::addPortalTile ( const std::string &  name,
const int  type,
const int  x,
const int  y 
)

Definition at line 1287 of file map.cpp.

References mMapPortals, mSpecialLayer, SpecialLayer::setTile(), SpecialLayer::updateCache(), x, and y.

Referenced by addExtraLayer(), addPortal(), getHasWarps(), Ea::BeingRecv::processNameResponse(), LocalPlayer::updateNavigateList(), and updatePortalTile().

1290 {
1291  if (mSpecialLayer != nullptr)
1292  {
1293  mSpecialLayer->setTile(x, y, new MapItem(type, name, x, y));
1295  }
1296 
1297  mMapPortals.push_back(new MapItem(type, name, x, y));
1298 }
SpecialLayer * mSpecialLayer
Definition: map.h:471
void setTile(const int x, const int y, MapItem *const item)
std::vector< MapItem * > mMapPortals
Definition: map.h:455
void updateCache()

◆ addRange()

void Map::addRange ( const std::string &  name,
const int  type,
const int  x,
const int  y,
const int  dx,
const int  dy 
)

Definition at line 1266 of file map.cpp.

References ObjectsLayer::addObject(), mapTileSize, mObjects, x, and y.

Referenced by getHasWarps(), and loadReplaceLayer().

1270 {
1271  if (mObjects == nullptr)
1272  return;
1273 
1274  mObjects->addObject(name, type, x / mapTileSize, y / mapTileSize,
1275  dx / mapTileSize, dy / mapTileSize);
1276 }
ObjectsLayer * mObjects
Definition: map.h:473
void addObject(const std::string &name, const int type, const unsigned x, const unsigned y, unsigned dx, unsigned dy)
static const int mapTileSize
Definition: map.h:26

◆ addTileset()

void Map::addTileset ( Tileset *const  tileset)

Adds a tileset to this map. The map takes ownership of the tileset.

Definition at line 311 of file map.cpp.

References mMaxTileHeight, and mTilesets.

Referenced by loadReplaceLayer().

312 {
313  mTilesets.push_back(tileset);
314  const int height = tileset->getHeight();
315  if (height > mMaxTileHeight)
316  mMaxTileHeight = height;
317 }
Tilesets mTilesets
Definition: map.h:412
int mMaxTileHeight
Definition: map.h:406
int getHeight() const
Definition: imageset.h:65

◆ calcMemoryChilds()

int Map::calcMemoryChilds ( const int  level) const
virtual

Reimplemented from MemoryCounter.

Definition at line 1762 of file map.cpp.

References MemoryCounter::calcMemory(), FOR_EACH, mBackgrounds, mForegrounds, mHeights, mLayers, mObjects, mSpecialLayer, mTempLayer, mTilesets, and mWalkLayer.

Referenced by isHeightsPresent().

1763 {
1764  int sz = 0;
1765 
1766  if (mWalkLayer != nullptr)
1767  sz += mWalkLayer->calcMemory(level + 1);
1769  {
1770  sz += (*it)->calcMemory(level + 1);
1771  }
1772  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1773  {
1774  sz += (*it)->calcMemory(level + 1);
1775  }
1777  {
1778  sz += (*it)->calcMemory(level + 1);
1779  }
1781  {
1782  sz += (*it)->calcMemory(level + 1);
1783  }
1784  if (mSpecialLayer != nullptr)
1785  mSpecialLayer->calcMemory(level + 1);
1786  if (mTempLayer != nullptr)
1787  mTempLayer->calcMemory(level + 1);
1788  if (mObjects != nullptr)
1789  mObjects->calcMemory(level + 1);
1790  if (mHeights != nullptr)
1791  mHeights->calcMemory(level + 1);
1792  return sz;
1793 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
AmbientLayerVector mBackgrounds
Definition: map.h:424
const MapHeights * mHeights
Definition: map.h:487
Tilesets mTilesets
Definition: map.h:412
WalkLayer * mWalkLayer
Definition: map.h:408
int calcMemory(const int level) const
SpecialLayer * mSpecialLayer
Definition: map.h:471
ObjectsLayer * mObjects
Definition: map.h:473
Layers mLayers
Definition: map.h:409
Layers::const_iterator LayersCIter
Definition: map.h:59
AmbientLayerVector mForegrounds
Definition: map.h:425
SpecialLayer * mTempLayer
Definition: map.h:472
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:62

◆ calcMemoryLocal()

int Map::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 1744 of file map.cpp.

References mActors, Map(), mBackgrounds, mDrawOverLayers, mDrawUnderLayers, mForegrounds, mHeight, mIndexedTilesetsSize, mLayers, mMapPortals, mName, mParticleEffects, mTileAnimations, mTilesets, and mWidth.

Referenced by isHeightsPresent().

1745 {
1746  return static_cast<int>(sizeof(Map) +
1747  mName.capacity() +
1748  sizeof(MetaTile) * mWidth * mHeight +
1749  sizeof(MapLayer*) * (mLayers.capacity() +
1750  mDrawUnderLayers.capacity() +
1751  mDrawOverLayers.capacity()) +
1752  sizeof(Tileset*) * mTilesets.capacity() +
1753  sizeof(Actor*) * mActors.size() +
1754  sizeof(AmbientLayer*) * (mBackgrounds.capacity()
1755  + mForegrounds.capacity()) +
1756  sizeof(ParticleEffectData) * mParticleEffects.capacity() +
1757  sizeof(MapItem) * mMapPortals.capacity() +
1758  (sizeof(TileAnimation) + sizeof(int)) * mTileAnimations.size() +
1759  sizeof(Tileset*) * mIndexedTilesetsSize);
1760 }
AmbientLayerVector mBackgrounds
Definition: map.h:424
Tilesets mTilesets
Definition: map.h:412
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:457
std::vector< MapItem * > mMapPortals
Definition: map.h:455
Layers mLayers
Definition: map.h:409
std::string mName
Definition: map.h:459
AmbientLayerVector mForegrounds
Definition: map.h:425
int mIndexedTilesetsSize
Definition: map.h:466
const int mHeight
Definition: map.h:403
const int mWidth
Definition: map.h:402
Definition: actor.h:40
Layers mDrawUnderLayers
Definition: map.h:410
Map(const std::string &name, const int width, const int height, const int tileWidth, const int tileHeight)
Definition: map.cpp:93
Layers mDrawOverLayers
Definition: map.h:411
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:453
Actors mActors
Definition: map.h:413

◆ clearIndexedTilesets()

void Map::clearIndexedTilesets ( )

Definition at line 1450 of file map.cpp.

References mIndexedTilesets, mIndexedTilesetsSize, and mTilesetsIndexed.

Referenced by getObjectsLayer(), and loadReplaceLayer().

1451 {
1452  if (!mTilesetsIndexed)
1453  return;
1454 
1455  mTilesetsIndexed = false;
1456  delete [] mIndexedTilesets;
1458 }
bool mTilesetsIndexed
Definition: map.h:464
int mIndexedTilesetsSize
Definition: map.h:466
Tileset ** mIndexedTilesets
Definition: map.h:465

◆ contains()

bool Map::contains ( const int  x,
const int  y 
) const
private

Tells whether the given coordinates fall within the map boundaries.

Definition at line 800 of file map.cpp.

References mHeight, mWidth, x, and y.

Referenced by addBlockMask(), and setBlockMask().

801 {
802  return x >= 0 && y >= 0 && x < mWidth && y < mHeight;
803 }
const int mHeight
Definition: map.h:403
const int mWidth
Definition: map.h:402

◆ draw()

void Map::draw ( Graphics *const  graphics,
int  scrollX,
int  scrollY 
)

Draws the map to the given graphics output. This method draws all layers, actors and overlay effects.

Definition at line 330 of file map.cpp.

References actorCompare, MapLayerPosition::BACKGROUND_LAYERS, MapType::BLACKWHITE, BLOCK_END, BLOCK_START, drawAmbientLayers(), MapLayer::drawFringe(), FOR_EACH, MapLayerPosition::FOREGROUND_LAYERS, UserPalette::getColorWithAlpha(), localPlayer, mActors, mBeingOpacity, mCachedDraw, mDrawLayersFlags, mDrawOnlyFringe, mDrawOverLayers, mDrawScrollX, mDrawScrollY, mDrawUnderLayers, mDrawX, mDrawY, mFringeLayer, mLastScrollX, mLastScrollY, mLastX, mLastY, mMaxTileHeight, mOpenGL, mOverlayDetail, mRedrawMap, mSpecialLayer, mTempLayer, mTileHeight, mTileWidth, RENDER_SOFTWARE, restrict, MapLayer::setSpecialLayer(), MapLayer::setTempLayer(), updateAmbientLayers(), userPalette, UserColorId::WALKABLE_HIGHLIGHT, x, and y.

Referenced by drawAmbientLayers().

332 {
333  if (localPlayer == nullptr)
334  return;
335 
336  BLOCK_START("Map::draw")
337  // Calculate range of tiles which are on-screen
338  const int endPixelY = graphics->mHeight + scrollY + mTileHeight - 1
340  const int startX = scrollX / mTileWidth - 2;
341  const int startY = scrollY / mTileHeight;
342  const int endX = (graphics->mWidth + scrollX + mTileWidth - 1)
343  / mTileWidth + 1;
344  const int endY = endPixelY / mTileHeight + 1;
345 
346  // Make sure actors are sorted ascending by Y-coordinate
347  // so that they overlap correctly
348  BLOCK_START("Map::draw sort")
349  mActors.sort(actorCompare);
350  BLOCK_END("Map::draw sort")
351 
352  // update scrolling of all ambient layers
353  updateAmbientLayers(static_cast<float>(scrollX),
354  static_cast<float>(scrollY));
355 
356  // Draw backgrounds
357  drawAmbientLayers(graphics,
360 
361  if (mDrawLayersFlags == MapType::BLACKWHITE && (userPalette != nullptr))
362  {
363  graphics->setColor(userPalette->getColorWithAlpha(
365 
366  graphics->fillRectangle(Rect(0, 0,
367  graphics->mWidth, graphics->mHeight));
368  }
369 
370 #ifdef USE_OPENGL
371  int updateFlag = 0;
372 
373  if (mCachedDraw)
374  {
375  if (mLastX != startX || mLastY != startY || mLastScrollX != scrollX
376  || mLastScrollY != scrollY)
377  { // player moving
378  mLastX = startX;
379  mLastY = startY;
380  mLastScrollX = scrollX;
381  mLastScrollY = scrollY;
382  updateFlag = 2;
383  }
384  else if (mRedrawMap || startX != mDrawX || startY != mDrawY ||
385  scrollX != mDrawScrollX || scrollY != mDrawScrollY)
386  { // player mode to new position
387  mRedrawMap = false;
388  mDrawX = startX;
389  mDrawY = startY;
390  mDrawScrollX = scrollX;
391  mDrawScrollY = scrollY;
392  updateFlag = 1;
393  }
394  }
395 #endif // USE_OPENGL
396 
397  if (mDrawOnlyFringe)
398  {
399  if (mFringeLayer != nullptr)
400  {
403  mFringeLayer->drawFringe(graphics,
404  startX, startY,
405  endX, endY,
406  scrollX, scrollY,
407  mActors);
408  }
409  }
410  else
411  {
412 #ifdef USE_OPENGL
413  if (mCachedDraw)
414  {
415  if (updateFlag != 0)
416  {
417  FOR_EACH (Layers::iterator, it, mDrawUnderLayers)
418  {
419  (*it)->updateOGL(graphics,
420  startX, startY,
421  endX, endY,
422  scrollX, scrollY);
423  }
424  FOR_EACH (Layers::iterator, it, mDrawOverLayers)
425  {
426  (*it)->updateOGL(graphics,
427  startX, startY,
428  endX, endY,
429  scrollX, scrollY);
430  }
431  }
432 
433  FOR_EACH (Layers::iterator, it, mDrawUnderLayers)
434  (*it)->drawOGL(graphics);
435 
436  if (mFringeLayer != nullptr)
437  {
440  mFringeLayer->drawFringe(graphics,
441  startX, startY,
442  endX, endY,
443  scrollX, scrollY,
444  mActors);
445  }
446 
447  FOR_EACH (Layers::iterator, it, mDrawOverLayers)
448  (*it)->drawOGL(graphics);
449  }
450  else
451 #endif // USE_OPENGL
452  {
453  FOR_EACH (Layers::iterator, it, mDrawUnderLayers)
454  {
455  (*it)->draw(graphics,
456  startX, startY,
457  endX, endY,
458  scrollX, scrollY);
459  }
460 
461  if (mFringeLayer != nullptr)
462  {
465  mFringeLayer->drawFringe(graphics,
466  startX, startY,
467  endX, endY,
468  scrollX, scrollY,
469  mActors);
470  }
471 
472  FOR_EACH (Layers::iterator, it, mDrawOverLayers)
473  {
474  (*it)->draw(graphics, startX, startY,
475  endX, endY,
476  scrollX, scrollY);
477  }
478  }
479  }
480 
481  // Don't draw if gui opacity == 1
482  if (mBeingOpacity)
483  {
484  // Draws beings with a lower opacity to make them visible
485  // even when covered by a wall or some other elements...
486  ActorsCIter ai = mActors.begin();
487  const ActorsCIter ai_end = mActors.end();
488 
489  if (mOpenGL == RENDER_SOFTWARE)
490  {
491  while (ai != ai_end)
492  {
493  if (Actor *restrict const actor = *ai)
494  {
495  const int x = actor->getTileX();
496  const int y = actor->getTileY();
497  if (x < startX || x > endX || y < startY || y > endY)
498  {
499  ++ai;
500  continue;
501  }
502  // For now, just draw actors with only one layer.
503  if (actor->getNumberOfLayers() == 1)
504  {
505  actor->setAlpha(0.3F);
506  actor->draw(graphics, -scrollX, -scrollY);
507  actor->setAlpha(1.0F);
508  }
509  }
510  ++ai;
511  }
512  }
513  else
514  {
515  while (ai != ai_end)
516  {
517  if (Actor *const actor = *ai)
518  {
519  actor->setAlpha(0.3F);
520  actor->draw(graphics, -scrollX, -scrollY);
521  actor->setAlpha(1.0F);
522  }
523  ++ai;
524  }
525  }
526  }
527 
528  drawAmbientLayers(graphics,
530  mOverlayDetail);
531  BLOCK_END("Map::draw")
532 }
int mLastScrollY
Definition: map.h:479
const int mTileHeight
Definition: map.h:405
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
bool mDrawOnlyFringe
Definition: map.h:492
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:199
int mLastX
Definition: map.h:476
Definition: rect.h:72
int mDrawScrollY
Definition: map.h:484
#define BLOCK_START(name)
Definition: perfomance.h:78
int mOverlayDetail
Definition: map.h:460
if(!vert) return
SpecialLayer * mSpecialLayer
Definition: map.h:471
int mDrawX
Definition: map.h:481
#define BLOCK_END(name)
Definition: perfomance.h:79
void updateAmbientLayers(const float scrollX, const float scrollY)
Definition: map.cpp:607
UserPalette * userPalette
Definition: userpalette.cpp:33
const int mTileWidth
Definition: map.h:404
void draw(Graphics *const graphics, int scrollX, int scrollY)
Definition: map.cpp:330
void drawFringe(Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY, const Actors &actors) const
Definition: maplayer.cpp:431
int mLastScrollX
Definition: map.h:478
MapTypeT mDrawLayersFlags
Definition: map.h:417
LocalPlayer * localPlayer
void setTempLayer(const SpecialLayer *const val)
Definition: maplayer.h:143
bool mRedrawMap
Definition: map.h:488
bool mCachedDraw
Definition: map.h:490
class ActorFunctuator actorCompare
int mMaxTileHeight
Definition: map.h:406
const int mHeight
Definition: map.h:403
Definition: map.h:68
void setSpecialLayer(const SpecialLayer *const val)
Definition: maplayer.h:140
SpecialLayer * mTempLayer
Definition: map.h:472
const int mWidth
Definition: map.h:402
int mDrawY
Definition: map.h:482
int mLastY
Definition: map.h:477
MapLayer * mFringeLayer
Definition: map.h:474
Definition: actor.h:40
const RenderType mOpenGL
Definition: map.h:462
#define restrict
Definition: localconsts.h:176
Layers mDrawUnderLayers
Definition: map.h:410
Actors::const_iterator ActorsCIter
Definition: actor.h:38
bool mBeingOpacity
Definition: map.h:489
int mDrawScrollX
Definition: map.h:483
Layers mDrawOverLayers
Definition: map.h:411
void drawAmbientLayers(Graphics *const graphics, const MapLayerPositionT type, const int detail) const
Definition: map.cpp:647
Actors mActors
Definition: map.h:413

◆ drawAmbientLayers()

void Map::drawAmbientLayers ( Graphics *const  graphics,
const MapLayerPositionT  type,
const int  detail 
) const
private

Draws the foreground or background layers to the given graphics output.

Definition at line 647 of file map.cpp.

References MapLayerPosition::BACKGROUND_LAYERS, BLOCK_END, BLOCK_START, draw(), FOR_EACHP, MapLayerPosition::FOREGROUND_LAYERS, mBackgrounds, mForegrounds, mMask, and restrict.

Referenced by draw().

650 {
651  BLOCK_START("Map::drawAmbientLayers")
652  // Detail 0 = no ambient effects except background image
653  if (detail <= 0 && type != MapLayerPosition::BACKGROUND_LAYERS)
654  {
655  BLOCK_END("Map::drawAmbientLayers")
656  return;
657  }
658 
659  // find out which layer list to draw
660  const AmbientLayerVector *restrict layers = nullptr;
661  switch (type)
662  {
664  layers = &mForegrounds;
665  break;
667  layers = &mBackgrounds;
668  break;
669  default:
670  return;
671  }
672 
673  // Draw overlays
675  {
676  const AmbientLayer *restrict const layer = *i;
677  // need check mask to draw or not to draw
678  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
679  (layer)->draw(graphics, graphics->mWidth, graphics->mHeight);
680 
681  // Detail 1: only one overlay, higher: all overlays
682  if (detail == 1)
683  break;
684  }
685  BLOCK_END("Map::drawAmbientLayers")
686 }
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:30
AmbientLayerVector mBackgrounds
Definition: map.h:424
int mWidth
Definition: graphics.h:483
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
void draw(Graphics *const graphics, int scrollX, int scrollY)
Definition: map.cpp:330
AmbientLayerVector mForegrounds
Definition: map.h:425
int mHeight
Definition: graphics.h:484
#define restrict
Definition: localconsts.h:176
std::vector< AmbientLayer * > AmbientLayerVector
Definition: map.h:61
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:62
int mMask
Definition: map.h:485

◆ drawCollision()

void Map::drawCollision ( Graphics *const  graphics,
const int  scrollX,
const int  scrollY,
const MapTypeT  drawFlags 
) const

Visualizes collision layer for debugging

Definition at line 557 of file map.cpp.

References BlockMask::AIR, UserColorId::AIR_COLLISION_HIGHLIGHT, UserColorId::COLLISION_HIGHLIGHT, fillCollision, UserPalette::getColorWithAlpha(), BlockMask::GROUNDTOP, UserColorId::GROUNDTOP_COLLISION_HIGHLIGHT, mapTileSize, mHeight, UserColorId::MONSTER_COLLISION_HIGHLIGHT, BlockMask::MONSTERWALL, mTileHeight, mTileWidth, mWidth, UserColorId::NET, BlockMask::PLAYERWALL, MapType::SPECIAL, userPalette, BlockMask::WALL, BlockMask::WATER, UserColorId::WATER_COLLISION_HIGHLIGHT, x, and y.

561 {
562  const int endPixelY = graphics->mHeight + scrollY + mTileHeight - 1;
563  int startX = scrollX / mTileWidth;
564  int startY = scrollY / mTileHeight;
565  int endX = (graphics->mWidth + scrollX + mTileWidth - 1) / mTileWidth;
566  int endY = endPixelY / mTileHeight;
567 
568  if (startX < 0)
569  startX = 0;
570  if (startY < 0)
571  startY = 0;
572  if (endX > mWidth)
573  endX = mWidth;
574  if (endY > mHeight)
575  endY = mHeight;
576 
577  if (drawFlags < MapType::SPECIAL)
578  {
580  graphics->drawNet(
581  startX * mTileWidth - scrollX,
582  startY * mTileHeight - scrollY,
583  endX * mTileWidth - scrollX,
584  endY * mTileHeight - scrollY,
586  }
587 
588  for (int y = startY; y < endY; y++)
589  {
590  const int yWidth = y * mWidth;
591  int tilePtr = startX + yWidth;
592  for (int x = startX; x < endX; x++, tilePtr++)
593  {
594  int width = 0;
595  const int x0 = x;
596 
603  }
604  }
605 }
const int mTileHeight
Definition: map.h:405
#define fillCollision(collision, color)
Definition: map.cpp:534
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:199
int mWidth
Definition: graphics.h:483
UserPalette * userPalette
Definition: userpalette.cpp:33
const int mTileWidth
Definition: map.h:404
virtual void drawNet(const int x1, const int y1, const int x2, const int y2, const int width, const int height)
Definition: graphics.cpp:652
virtual void setColor(const Color &color)
Definition: graphics.h:319
int mHeight
Definition: graphics.h:484
const int mHeight
Definition: map.h:403
const int mWidth
Definition: map.h:402
static const int mapTileSize
Definition: map.h:26

◆ empty()

bool Map::empty ( ) const
inline

Definition at line 317 of file map.h.

References mLayers.

Referenced by SocialNavigationTab::updateList().

318  { return mLayers.empty(); }
Layers mLayers
Definition: map.h:409

◆ findPath()

Path Map::findPath ( const int  startX,
const int  startY,
const int  destX,
const int  destY,
const unsigned char  blockWalkmask,
const int  maxCost 
)

Find a path from one location to the next.

Definition at line 851 of file map.cpp.

References BLOCK_END, BLOCK_START, MetaTile::blockmask, blockWalkMask, MetaTile::Fcost, MetaTile::Gcost, getWalk(), MetaTile::Hcost, mHeight, mMetaTiles, mOnClosedList, mOnOpenList, mWidth, MetaTile::parentX, MetaTile::parentY, CastType::Position, ServerCommandType::size, Location::tile, BlockMask::WALL, MetaTile::whichList, Location::x, x, Location::y, and y.

Referenced by LocalPlayer::fixAttackTarget(), LocalPlayer::getPathLength(), getTileHeight(), LocalPlayer::isReachable(), LocalPlayer::moveToTarget(), LocalPlayer::navigateTo(), LocalPlayer::pickUp(), and Being::setDestination().

855 {
856  BLOCK_START("Map::findPath")
857  // The basic walking cost of a tile.
858  static const int basicCost = 100;
859  const int basicCost2 = 100 * 362 / 256;
860  const float basicCostF = 100.0 * 362 / 256;
861 
862  // Path to be built up (empty by default)
863  Path path;
864 
865  if (startX >= mWidth || startY >= mHeight || startX < 0 || startY < 0)
866  {
867  BLOCK_END("Map::findPath")
868  return path;
869  }
870 
871  // Return when destination not walkable
872  if (!getWalk(destX, destY, blockWalkMask))
873  {
874  BLOCK_END("Map::findPath")
875  return path;
876  }
877 
878  // Reset starting tile's G cost to 0
879  MetaTile *const startTile = &mMetaTiles[startX + startY * mWidth];
880  if (startTile == nullptr)
881  {
882  BLOCK_END("Map::findPath")
883  return path;
884  }
885 
886  startTile->Gcost = 0;
887 
888  // Declare open list, a list with open tiles sorted on F cost
889  std::priority_queue<Location> openList;
890 
891  // Add the start point to the open list
892  openList.push(Location(startX, startY, startTile));
893 
894  bool foundPath = false;
895 
896  // Keep trying new open tiles until no more tiles to try or target found
897  while (!openList.empty() && !foundPath)
898  {
899  // Take the location with the lowest F cost from the open list.
900  const Location curr = openList.top();
901  openList.pop();
902 
903  const MetaTile *const tile = curr.tile;
904 
905  // If the tile is already on the closed list, this means it has already
906  // been processed with a shorter path to the start point (lower G cost)
907  if (tile->whichList == mOnClosedList)
908  continue;
909 
910  // Put the current tile on the closed list
911  curr.tile->whichList = mOnClosedList;
912 
913  const int curWidth = curr.y * mWidth;
914  const int tileGcost = tile->Gcost;
915 
916  // Check the adjacent tiles
917  for (int dy = -1; dy <= 1; dy++)
918  {
919  const int y = curr.y + dy;
920  if (y < 0 || y >= mHeight)
921  continue;
922 
923  const int yWidth = y * mWidth;
924  const int dy1 = std::abs(y - destY);
925 
926  for (int dx = -1; dx <= 1; dx++)
927  {
928  // Calculate location of tile to check
929  const int x = curr.x + dx;
930 
931  // Skip if if we're checking the same tile we're leaving from,
932  // or if the new location falls outside of the map boundaries
933  if ((dx == 0 && dy == 0) || x < 0 || x >= mWidth)
934  continue;
935 
936  MetaTile *const newTile = &mMetaTiles[x + yWidth];
937 
938  // Skip if the tile is on the closed list or is not walkable
939  // unless its the destination tile
940  // +++ probably here "newTile->blockmask & BlockMask::WALL"
941  // can be removed. It left here only for protect from
942  // walk on wall in any case
943  if (newTile->whichList == mOnClosedList ||
944  (((newTile->blockmask & blockWalkMask) != 0)
945  && !(x == destX && y == destY))
946  || ((newTile->blockmask & BlockMask::WALL) != 0))
947  {
948  continue;
949  }
950 
951  // When taking a diagonal step, verify that we can skip the
952  // corner.
953  if (dx != 0 && dy != 0)
954  {
955  const MetaTile *const t1 = &mMetaTiles[curr.x +
956  (curr.y + dy) * mWidth];
957  const MetaTile *const t2 = &mMetaTiles[curr.x +
958  dx + curWidth];
959 
960  // on player abilities.
961  if (((t1->blockmask | t2->blockmask) & blockWalkMask) != 0)
962  continue;
963  }
964 
965  // Calculate G cost for this route, ~sqrt(2) for moving diagonal
966  int Gcost = tileGcost + (dx == 0 || dy == 0
967  ? basicCost : basicCost2);
968 
969  /* Demote an arbitrary direction to speed pathfinding by
970  adding a defect
971  Important: as long as the total defect along any path is
972  less than the basicCost, the pathfinder will still find one
973  of the shortest paths! */
974  if (dx == 0 || dy == 0)
975  {
976  // Demote horizontal and vertical directions, so that two
977  // consecutive directions cannot have the same Fcost.
978  ++Gcost;
979  }
980 
981 /*
982  // It costs extra to walk through a being (needs to be enough
983  // to make it more attractive to walk around).
984  if (occupied(x, y))
985  {
986  Gcost += 3 * basicCost;
987  }
988 */
989 
990  // Skip if Gcost becomes too much
991  // Warning: probably not entirely accurate
992  if (maxCost > 0 && Gcost > maxCost * basicCost)
993  continue;
994 
995  if (newTile->whichList != mOnOpenList)
996  {
997  // Found a new tile (not on open nor on closed list)
998 
999  /* Update Hcost of the new tile. The pathfinder does not
1000  work reliably if the heuristic cost is higher than the
1001  real cost. In particular, using Manhattan distance is
1002  forbidden here. */
1003  const int dx1 = std::abs(x - destX);
1004  newTile->Hcost = std::abs(dx1 - dy1) * basicCost +
1005  std::min(dx1, dy1) * (basicCostF);
1006 
1007  // Set the current tile as the parent of the new tile
1008  newTile->parentX = curr.x;
1009  newTile->parentY = curr.y;
1010 
1011  // Update Gcost and Fcost of new tile
1012  newTile->Gcost = Gcost;
1013  newTile->Fcost = Gcost + newTile->Hcost;
1014 
1015  if (x != destX || y != destY)
1016  {
1017  // Add this tile to the open list
1018  newTile->whichList = mOnOpenList;
1019  openList.push(Location(x, y, newTile));
1020  }
1021  else
1022  {
1023  // Target location was found
1024  foundPath = true;
1025  }
1026  }
1027  else if (Gcost < newTile->Gcost)
1028  {
1029  // Found a shorter route.
1030  // Update Gcost and Fcost of the new tile
1031  newTile->Gcost = Gcost;
1032  newTile->Fcost = Gcost + newTile->Hcost;
1033 
1034  // Set the current tile as the parent of the new tile
1035  newTile->parentX = curr.x;
1036  newTile->parentY = curr.y;
1037 
1038  // Add this tile to the open list (it's already
1039  // there, but this instance has a lower F score)
1040  openList.push(Location(x, y, newTile));
1041  }
1042  }
1043  }
1044  }
1045 
1046  // Two new values to indicate whether a tile is on the open or closed list,
1047  // this way we don't have to clear all the values between each pathfinding.
1048  if (mOnOpenList > UINT_MAX - 2)
1049  {
1050  // We reset the list memebers value.
1051  mOnClosedList = 1;
1052  mOnOpenList = 2;
1053 
1054  // Clean up the metaTiles
1055  const int size = mWidth * mHeight;
1056  for (int i = 0; i < size; ++i)
1057  mMetaTiles[i].whichList = 0;
1058  }
1059  else
1060  {
1061  mOnClosedList += 2;
1062  mOnOpenList += 2;
1063  }
1064 
1065  // If a path has been found, iterate backwards using the parent locations
1066  // to extract it.
1067  if (foundPath)
1068  {
1069  int pathX = destX;
1070  int pathY = destY;
1071 
1072  while (pathX != startX || pathY != startY)
1073  {
1074  // Add the new path node to the start of the path list
1075  path.push_front(Position(pathX, pathY));
1076 
1077  // Find out the next parent
1078  const MetaTile *const tile = &mMetaTiles[pathX + pathY * mWidth];
1079  pathX = tile->parentX;
1080  pathY = tile->parentY;
1081  }
1082  }
1083 
1084  BLOCK_END("Map::findPath")
1085  return path;
1086 }
int x
Definition: location.h:56
bool empty() const
Definition: map.h:317
int Gcost
Definition: metatile.h:46
int Fcost
Definition: metatile.h:45
#define BLOCK_START(name)
Definition: perfomance.h:78
MetaTile * tile
Definition: location.h:57
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
int Hcost
Definition: metatile.h:47
unsigned char blockmask
Definition: metatile.h:51
bool getWalk(const int x, const int y, const unsigned char blockWalkMask) const
Definition: map.cpp:773
const int mHeight
Definition: map.h:403
int parentX
Definition: metatile.h:49
MetaTile *const mMetaTiles
Definition: map.h:407
const int mWidth
Definition: map.h:402
unsigned int mOnOpenList
Definition: map.h:421
unsigned int mOnClosedList
Definition: map.h:420
int y
Definition: location.h:56
int parentY
Definition: metatile.h:50
std::list< Position > Path
Definition: position.h:48
unsigned whichList
Definition: metatile.h:48

◆ findPortalXY()

MapItem * Map::findPortalXY ( const int  x,
const int  y 
) const

Definition at line 1325 of file map.cpp.

References FOR_EACH, ServerCommandType::item, mMapPortals, restrict, x, and y.

Referenced by RenameListener::action(), SocialNavigationTab::addPortal(), getPortals(), AvatarListBox::mousePressed(), SocialNavigationTab::updateNames(), and updatePortalTile().

1326 {
1327  FOR_EACH (STD_VECTOR<MapItem*>::const_iterator, it, mMapPortals)
1328  {
1329  if (*it == nullptr)
1330  continue;
1331 
1332  MapItem *restrict const item = *it;
1333  if (item->mX == x && item->mY == y)
1334  return item;
1335  }
1336  return nullptr;
1337 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
std::vector< MapItem * > mMapPortals
Definition: map.h:455
#define restrict
Definition: localconsts.h:176

◆ getActorsCount()

int Map::getActorsCount ( ) const
inline

Definition at line 283 of file map.h.

References CAST_S32, mActors, restrict2, and setPvpMode().

Referenced by MapDebugTab::logic().

284  { return CAST_S32(mActors.size()); }
#define CAST_S32
Definition: cast.h:29
Actors mActors
Definition: map.h:413

◆ getAnimationForGid()

const TileAnimation * Map::getAnimationForGid ( const int  gid) const

Gets the tile animation for a specific gid

Definition at line 1339 of file map.cpp.

References mTileAnimations.

Referenced by getPortals().

1340 {
1341  if (mTileAnimations.empty())
1342  return nullptr;
1343 
1344  const TileAnimationMapCIter i = mTileAnimations.find(gid);
1345  return (i == mTileAnimations.end()) ? nullptr : i->second;
1346 }
TileAnimationMap::const_iterator TileAnimationMapCIter
Definition: tileanimation.h:64
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:457

◆ getBlockMask()

unsigned char Map::getBlockMask ( const int  x,
const int  y 
) const

Definition at line 784 of file map.cpp.

References MetaTile::blockmask, mHeight, mMetaTiles, mWidth, x, and y.

Referenced by Being::getAttackAction(), Being::getCastAction(), Being::getMoveAction(), Being::getSitAction(), Being::getStandAction(), Being::getWeaponAttackAction(), and Being::nextTile().

786 {
787  // You can't walk outside of the map
788  if (x < 0 || y < 0 || x >= mWidth || y >= mHeight)
789  return 0;
790 
791  // Check if the tile is walkable
792  return mMetaTiles[x + y * mWidth].blockmask;
793 }
unsigned char blockmask
Definition: metatile.h:51
const int mHeight
Definition: map.h:403
MetaTile *const mMetaTiles
Definition: map.h:407
const int mWidth
Definition: map.h:402

◆ getCounterName()

std::string Map::getCounterName ( ) const
inlinevirtual

Reimplemented from MemoryCounter.

Definition at line 362 of file map.h.

References mName.

363  { return mName; }
std::string mName
Definition: map.h:459

◆ getDrawLayersFlags()

MapTypeT Map::getDrawLayersFlags ( ) const
inline

Definition at line 227 of file map.h.

References addExtraLayer(), mDrawLayersFlags, restrict2, and saveExtraLayer().

228  { return mDrawLayersFlags; }
MapTypeT mDrawLayersFlags
Definition: map.h:417

◆ getFilename()

const std::string Map::getFilename ( ) const

Gives the map id based on filepath (ex: 009-1)

Definition at line 836 of file map.cpp.

References fileName, and Properties::getProperty().

Referenced by getTileHeight(), and Minimap::setMap().

837 {
838  const std::string fileName = getProperty("_filename", std::string());
839  const size_t lastSlash = fileName.rfind('/') + 1;
840  return fileName.substr(lastSlash, fileName.rfind('.') - lastSlash);
841 }
std::string fileName
Definition: testmain.cpp:36
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58

◆ getGatName()

const std::string Map::getGatName ( ) const

Definition at line 843 of file map.cpp.

References fileName, and Properties::getProperty().

Referenced by getTileHeight(), and Ea::MapRecv::processSetTilesType().

844 {
845  const std::string fileName = getProperty("_filename", std::string());
846  const size_t lastSlash = fileName.rfind('/') + 1;
847  return fileName.substr(lastSlash,
848  fileName.rfind('.') - lastSlash).append(".gat");
849 }
std::string fileName
Definition: testmain.cpp:36
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58

◆ getHasWarps()

bool Map::getHasWarps ( ) const
inline

Definition at line 243 of file map.h.

References A_WARN_UNUSED, addPortal(), addPortalTile(), addRange(), getUserMapDirectory(), mHasWarps, restrict, restrict2, and updatePortalTile().

Referenced by Being::drawPortalSpriteAt().

244  { return mHasWarps; }
bool mHasWarps
Definition: map.h:414

◆ getHeight()

int Map::getHeight ( ) const
inline

Returns the height of this map in tiles.

Definition at line 168 of file map.h.

References mHeight.

Referenced by NavigationManager::loadWalkLayer(), Ea::PlayerRecv::processPlayerWarp(), MapReader::readLayer(), Minimap::setMap(), and Viewport::updateMaxVars().

169  { return mHeight; }
const int mHeight
Definition: map.h:403

◆ getHeightOffset()

uint8_t Map::getHeightOffset ( const int  x,
const int  y 
) const

Definition at line 1619 of file map.cpp.

References MapHeights::getHeight(), mHeights, x, and y.

Referenced by Viewport::getMouseTile(), Being::nextTile(), FloorItem::postInit(), Being::setMap(), Being::setTileCoords(), and setWalkLayer().

1620 {
1621  if (mHeights == nullptr)
1622  return 0;
1623  return mHeights->getHeight(x, y);
1624 }
const MapHeights * mHeights
Definition: map.h:487
uint8_t getHeight(const int x, const int y) const
Definition: mapheights.h:43

◆ getMetaTile()

const MetaTile * Map::getMetaTile ( const int  x,
const int  y 
) const

Get tile reference.

Definition at line 805 of file map.cpp.

References mMetaTiles, mWidth, x, and y.

806 {
807  return &mMetaTiles[x + y * mWidth];
808 }
MetaTile *const mMetaTiles
Definition: map.h:407
const int mWidth
Definition: map.h:402

◆ getMetaTiles()

const MetaTile* Map::getMetaTiles ( ) const
inline

Definition at line 333 of file map.h.

References mMetaTiles.

Referenced by NavigationManager::loadWalkLayer().

334  { return mMetaTiles; }
MetaTile *const mMetaTiles
Definition: map.h:407

◆ getMusicFile()

const std::string Map::getMusicFile ( ) const

Definition at line 823 of file map.cpp.

References Properties::getProperty().

Referenced by Setup_Audio::apply(), Game::changeMap(), getTileHeight(), and LocalPlayer::updateMusic().

824 {
825  return getProperty("music", std::string());
826 }
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58

◆ getName()

const std::string Map::getName ( ) const

Definition at line 828 of file map.cpp.

References Properties::getProperty(), and Properties::hasProperty().

Referenced by getTileHeight(), and Minimap::setMap().

829 {
830  if (hasProperty("name"))
831  return getProperty("name", std::string());
832 
833  return getProperty("mapname", std::string());
834 }
bool hasProperty(const std::string &name) const
Definition: properties.h:118
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58

◆ getObjectData()

std::string Map::getObjectData ( const unsigned  x,
const unsigned  y,
const int  type 
) const

Definition at line 1380 of file map.cpp.

References ObjectsLayer::getAt(), mObjects, MapObjectList::objects, restrict, x, and y.

Referenced by getObjectsLayer(), and LocalPlayer::updateMusic().

1382 {
1383  if (mObjects == nullptr)
1384  return "";
1385 
1386  MapObjectList *restrict const list = mObjects->getAt(x, y);
1387  if (list == nullptr)
1388  return "";
1389 
1390  STD_VECTOR<MapObject>::const_iterator it = list->objects.begin();
1391  const STD_VECTOR<MapObject>::const_iterator it_end = list->objects.end();
1392  while (it != it_end)
1393  {
1394  if ((*it).type == type)
1395  return (*it).data;
1396  ++ it;
1397  }
1398 
1399  return "";
1400 }
std::vector< MapObject > objects
Definition: mapobjectlist.h:42
ObjectsLayer * mObjects
Definition: map.h:473
MapObjectList * getAt(const unsigned x, const unsigned y) const
#define restrict
Definition: localconsts.h:176

◆ getObjectsLayer()

const ObjectsLayer* Map::getObjectsLayer ( ) const
inline

Definition at line 291 of file map.h.

References A_WARN_UNUSED, clearIndexedTilesets(), getObjectData(), indexTilesets(), mObjects, restrict2, and setActorsFix().

293  { return mObjects; }
ObjectsLayer * mObjects
Definition: map.h:473

◆ getPortals()

const std::vector<MapItem*>& Map::getPortals ( ) const
inline

Definition at line 267 of file map.h.

References A_WARN_UNUSED, findPortalXY(), getAnimationForGid(), mMapPortals, optionChanged(), and restrict.

Referenced by SocialNavigationTab::updateList().

269  { return mMapPortals; }
std::vector< MapItem * > mMapPortals
Definition: map.h:455

◆ getPvpMode()

int Map::getPvpMode ( ) const
inline

Definition at line 288 of file map.h.

References mPvp.

Referenced by ActorManager::findNearestPvpPlayer().

289  { return mPvp; }
int mPvp
Definition: map.h:463

◆ getSpecialLayer()

SpecialLayer* Map::getSpecialLayer ( ) const
inline

Definition at line 237 of file map.h.

References mSpecialLayer.

Referenced by RenameListener::action(), Viewport::getMouseTile(), PopupMenu::handleLink(), LocalPlayer::setHome(), and SocialNavigationTab::updateList().

238  { return mSpecialLayer; }
SpecialLayer * mSpecialLayer
Definition: map.h:471

◆ getTempLayer()

SpecialLayer* Map::getTempLayer ( ) const
inline

Definition at line 234 of file map.h.

References mTempLayer.

Referenced by LocalPlayer::navigateClean(), LocalPlayer::navigateTo(), LocalPlayer::setRealPos(), and LocalPlayer::updateCoords().

235  { return mTempLayer; }
SpecialLayer * mTempLayer
Definition: map.h:472

◆ getTileAnimations()

const std::map<int, TileAnimation*>& Map::getTileAnimations ( ) const
inline

Definition at line 326 of file map.h.

References mTileAnimations.

Referenced by MapReader::readBase64Layer(), MapReader::readCsvLayer(), and MapReader::readLayer().

328  { return mTileAnimations; }
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:457

◆ getTileHeight()

int Map::getTileHeight ( ) const
inline

◆ getTilesetWithGid()

const Tileset * Map::getTilesetWithGid ( const int  gid) const

Finds the tile set that a tile with the given global id is part of.

Definition at line 688 of file map.cpp.

References mIndexedTilesets, and mIndexedTilesetsSize.

Referenced by setTile().

689 {
690  if (gid >= 0 && gid < mIndexedTilesetsSize)
691  return mIndexedTilesets[gid];
692  return nullptr;
693 }
int mIndexedTilesetsSize
Definition: map.h:466
Tileset ** mIndexedTilesets
Definition: map.h:465

◆ getTileWidth()

int Map::getTileWidth ( ) const
inline

◆ getUserMapDirectory()

std::string Map::getUserMapDirectory ( ) const

Definition at line 1260 of file map.cpp.

References Properties::getProperty(), pathJoin(), Settings::serverConfigDir, and settings.

Referenced by addExtraLayer(), getHasWarps(), and saveExtraLayer().

1261 {
1263  getProperty("_realfilename", std::string()));
1264 }
std::string pathJoin(std::string str1, const std::string &str2)
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58
Settings settings
Definition: settings.cpp:31
std::string serverConfigDir
Definition: settings.h:115

◆ getVersion()

int Map::getVersion ( ) const
inline

Definition at line 306 of file map.h.

References mVersion.

Referenced by setTile().

307  { return mVersion; }
int mVersion
Definition: map.h:469

◆ getWalk()

bool Map::getWalk ( const int  x,
const int  y,
const unsigned char  blockWalkMask 
) const

Gets walkability for a tile with a blocking bitmask. When called without walkmask, only blocks against colliding tiles.

Definition at line 773 of file map.cpp.

References blockWalkMask, mHeight, mMetaTiles, mWidth, x, and y.

Referenced by Being::botFixOffset(), CrazyMoves::crazyMove8(), findPath(), Viewport::getMouseTile(), Being::moveBotTo(), Being::nextTile(), and LocalPlayer::startWalking().

775 {
776  // You can't walk outside of the map
777  if (x < 0 || y < 0 || x >= mWidth || y >= mHeight)
778  return false;
779 
780  // Check if the tile is walkable
781  return (mMetaTiles[x + y * mWidth].blockmask & blockWalkMask) == 0;
782 }
const int mHeight
Definition: map.h:403
MetaTile *const mMetaTiles
Definition: map.h:407
const int mWidth
Definition: map.h:402

◆ getWalkLayer()

const WalkLayer* Map::getWalkLayer ( ) const
inline

Definition at line 336 of file map.h.

References mWalkLayer.

Referenced by LocalPlayer::isReachable().

337  { return mWalkLayer; }
WalkLayer * mWalkLayer
Definition: map.h:408

◆ getWidth()

int Map::getWidth ( ) const
inline

Returns the width of this map in tiles.

Definition at line 162 of file map.h.

References mWidth.

Referenced by Actions::changeRelation(), NavigationManager::loadWalkLayer(), Ea::PlayerRecv::processPlayerWarp(), MapReader::readLayer(), Minimap::setMap(), and Viewport::updateMaxVars().

163  { return mWidth; }
const int mWidth
Definition: map.h:402

◆ haveAtlas()

bool Map::haveAtlas ( ) const
inline

Definition at line 365 of file map.h.

References mAtlas.

Referenced by MapReader::readTileset().

366  { return mAtlas != nullptr; }
Resource * mAtlas
Definition: map.h:486

◆ indexTilesets()

void Map::indexTilesets ( )

Definition at line 1402 of file map.cpp.

References CAST_S32, CAST_SIZE, FOR_EACH, mIndexedTilesets, mIndexedTilesetsSize, mTilesets, mTilesetsIndexed, restrict, ServerCommandType::size, and anonymous_namespace{stringutils.cpp}::start.

Referenced by getObjectsLayer(), and MapReader::readLayer().

1403 {
1404  if (mTilesetsIndexed)
1405  return;
1406 
1407  mTilesetsIndexed = true;
1408 
1409  const Tileset *restrict s = nullptr;
1410  size_t sSz = 0;
1411  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1412  {
1413  const size_t sz = (*it)->size();
1414  if ((s == nullptr) || CAST_SIZE(s->getFirstGid()) + sSz
1415  < CAST_SIZE((*it)->getFirstGid()) + sz)
1416  {
1417  s = *it;
1418  sSz = sz;
1419  }
1420  }
1421  if (s == nullptr)
1422  {
1424  mIndexedTilesets = nullptr;
1425  return;
1426  }
1427 
1428  const int size = CAST_S32(s->getFirstGid())
1429  + CAST_S32(s->size());
1431  mIndexedTilesets = new Tileset*[CAST_SIZE(size)];
1432  std::fill_n(mIndexedTilesets, size, static_cast<Tileset*>(nullptr));
1433 
1434  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1435  {
1436  Tileset *restrict const s2 = *it;
1437  if (s2 != nullptr)
1438  {
1439  const int start = s2->getFirstGid();
1440  const int end = start + CAST_S32(s2->size());
1441  for (int f = start; f < end; f ++)
1442  {
1443  if (f < size)
1444  mIndexedTilesets[f] = s2;
1445  }
1446  }
1447  }
1448 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Tilesets mTilesets
Definition: map.h:412
bool mTilesetsIndexed
Definition: map.h:464
#define CAST_S32
Definition: cast.h:29
int mIndexedTilesetsSize
Definition: map.h:466
#define restrict
Definition: localconsts.h:176
#define CAST_SIZE
Definition: cast.h:33
Tileset ** mIndexedTilesets
Definition: map.h:465

◆ initializeAmbientLayers()

void Map::initializeAmbientLayers ( )

Initialize ambient layers. Has to be called after all the properties are set.

Definition at line 225 of file map.cpp.

References Properties::getBoolProperty(), Properties::getFloatProperty(), Loader::getImage(), Properties::getProperty(), Properties::hasProperty(), mBackgrounds, mForegrounds, restrict, and Catch::toString().

Referenced by loadReplaceLayer().

226 {
227  // search for "foreground*" or "overlay*" (old term) in map properties
228  for (int i = 0; /* terminated by a break */; i++)
229  {
230  std::string name;
231  if (hasProperty(std::string("foreground").append(
232  toString(i)).append("image")))
233  {
234  name = "foreground" + toString(i);
235  }
236  else if (hasProperty(std::string("overlay").append(
237  toString(i)).append("image")))
238  {
239  name = "overlay" + toString(i);
240  }
241  else
242  {
243  break; // the FOR loop
244  }
245 
246  Image *restrict const img = Loader::getImage(
247  getProperty(name + "image", std::string()));
248  if (img != nullptr)
249  {
250  int mask = atoi(getProperty(name + "mask", std::string()).c_str());
251  if (mask == 0)
252  mask = 1;
253  const float parallax = getFloatProperty(name + "parallax", 0.0F);
254  mForegrounds.push_back(new AmbientLayer(
255  name,
256  img,
257  getFloatProperty(name + "parallaxX", parallax),
258  getFloatProperty(name + "parallaxY", parallax),
259  getFloatProperty(name + "posX", 0.0F),
260  getFloatProperty(name + "posY", 0.0F),
261  getFloatProperty(name + "scrollX", 0.0F),
262  getFloatProperty(name + "scrollY", 0.0F),
263  getBoolProperty(name + "keepratio", false),
264  mask));
265 
266  // The AmbientLayer takes control over the image.
267  img->decRef();
268  }
269  }
270 
271  // search for "background*" in map properties
272  for (int i = 0; hasProperty(std::string("background").append(
273  toString(i)).append("image")); i ++)
274  {
275  const std::string name("background" + toString(i));
276  Image *restrict const img = Loader::getImage(
277  getProperty(name + "image", std::string()));
278 
279  if (img != nullptr)
280  {
281  int mask = atoi(getProperty(name + "mask", std::string()).c_str());
282  if (mask == 0)
283  mask = 1;
284 
285  const float parallax = getFloatProperty(name + "parallax", 0.0F);
286  mBackgrounds.push_back(new AmbientLayer(
287  name,
288  img,
289  getFloatProperty(name + "parallaxX", parallax),
290  getFloatProperty(name + "parallaxY", parallax),
291  getFloatProperty(name + "posX", 0.0F),
292  getFloatProperty(name + "posY", 0.0F),
293  getFloatProperty(name + "scrollX", 0.0F),
294  getFloatProperty(name + "scrollY", 0.0F),
295  getBoolProperty(name + "keepratio", false),
296  mask));
297 
298  // The AmbientLayer takes control over the image.
299  img->decRef();
300  }
301  }
302 }
bool hasProperty(const std::string &name) const
Definition: properties.h:118
AmbientLayerVector mBackgrounds
Definition: map.h:424
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58
float getFloatProperty(const std::string &name, const float def) const
Definition: properties.h:74
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
AmbientLayerVector mForegrounds
Definition: map.h:425
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Definition: image.h:61
#define restrict
Definition: localconsts.h:176
bool getBoolProperty(const std::string &name, const bool def) const
Definition: properties.h:96

◆ initializeParticleEffects()

void Map::initializeParticleEffects ( ) const

Initializes all added particle effects

Definition at line 1096 of file map.cpp.

References ParticleEngine::addEffect(), Particle::adjustEmitterSize(), BLOCK_END, BLOCK_START, config, Configuration::getBoolValue(), mParticleEffects, and particleEngine.

Referenced by Game::changeMap(), and getTileHeight().

1097 {
1098  BLOCK_START("Map::initializeParticleEffects")
1099  if (particleEngine == nullptr)
1100  {
1101  BLOCK_END("Map::initializeParticleEffects")
1102  return;
1103  }
1104 
1105  if (config.getBoolValue("particleeffects"))
1106  {
1107  for (STD_VECTOR<ParticleEffectData>::const_iterator
1108  i = mParticleEffects.begin();
1109  i != mParticleEffects.end();
1110  ++i)
1111  {
1112  // +++ add z for map particle effects?
1113  Particle *const p = particleEngine->addEffect(
1114  i->file,
1115  i->x,
1116  i->y,
1117  0);
1118  if ((p != nullptr) &&
1119  i->w > 0 &&
1120  i->h > 0)
1121  {
1122  p->adjustEmitterSize(i->w, i->h);
1123  }
1124  }
1125  }
1126  BLOCK_END("Map::initializeParticleEffects")
1127 }
Particle * addEffect(const std::string &particleEffectFile, const int pixelX, const int pixelY, const int rotation)
#define BLOCK_START(name)
Definition: perfomance.h:78
ParticleEngine * particleEngine
Configuration config
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:453
void adjustEmitterSize(const int w, const int h)
Definition: particle.cpp:555

◆ isCustom()

bool Map::isCustom ( ) const
inline

Definition at line 323 of file map.h.

References mCustom.

Referenced by LocalPlayer::setRealPos().

324  { return mCustom; }
bool mCustom
Definition: map.h:491

◆ isHeightsPresent()

bool Map::isHeightsPresent ( ) const
inline

Definition at line 351 of file map.h.

References calcMemoryChilds(), calcMemoryLocal(), mHeights, preCacheLayers(), restrict2, and updateConditionLayers().

Referenced by Viewport::getMouseTile().

352  { return mHeights != nullptr; }
const MapHeights * mHeights
Definition: map.h:487

◆ optionChanged()

void Map::optionChanged ( const std::string &  name)
virtual

Called when an option changed. The config listener will have to be registered to the option name first.

Implements ConfigListener.

Definition at line 202 of file map.cpp.

References config, Configuration::getBoolValue(), Configuration::getFloatValue(), Configuration::getIntValue(), mBeingOpacity, mOpacity, and mOverlayDetail.

Referenced by getPortals().

203 {
204  if (value == "OverlayDetail")
205  {
206  mOverlayDetail = config.getIntValue("OverlayDetail");
207  }
208  else if (value == "guialpha")
209  {
210  mOpacity = config.getFloatValue("guialpha");
211  if (mOpacity != 1.0F)
212  mBeingOpacity = config.getBoolValue("beingopacity");
213  else
214  mBeingOpacity = false;
215  }
216  else if (value == "beingopacity")
217  {
218  if (mOpacity != 1.0F)
219  mBeingOpacity = config.getBoolValue("beingopacity");
220  else
221  mBeingOpacity = false;
222  }
223 }
Configuration config
int mOverlayDetail
Definition: map.h:460
int getIntValue(const std::string &key) const
float getFloatValue(const std::string &key) const
bool getBoolValue(const std::string &key) const
float mOpacity
Definition: map.h:461
bool mBeingOpacity
Definition: map.h:489

◆ preCacheLayers()

void Map::preCacheLayers ( )

Definition at line 1734 of file map.cpp.

References FOR_EACH, mHeight, mLayers, mWidth, and restrict.

Referenced by MapReader::addLayerToList(), MapReader::createEmptyMap(), isHeightsPresent(), and Ea::MapRecv::processSetTilesType().

1735 {
1737  {
1738  MapLayer *restrict const layer = *it;
1739  if (layer != nullptr)
1740  layer->updateCache(mWidth, mHeight);
1741  }
1742 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Layers mLayers
Definition: map.h:409
Layers::const_iterator LayersCIter
Definition: map.h:59
const int mHeight
Definition: map.h:403
const int mWidth
Definition: map.h:402
#define restrict
Definition: localconsts.h:176

◆ redrawMap()

void Map::redrawMap ( )
inline

Definition at line 314 of file map.h.

References mRedrawMap.

315  { mRedrawMap = true; }
bool mRedrawMap
Definition: map.h:488

◆ reduce()

void Map::reduce ( )

Definition at line 1460 of file map.cpp.

References CAST_SIZE, config, FOR_EACH, Configuration::getBoolValue(), Logger::log(), logger, mapTileSize, mFringeLayer, mHeight, SubImage::mInternalBounds, mLayers, mOpenGL, mWidth, RENDER_SOFTWARE, restrict, x, and y.

Referenced by loadReplaceLayer(), and setVersion().

1461 {
1462 #ifndef USE_SDL2
1463  if ((mFringeLayer == nullptr) ||
1464  mOpenGL != RENDER_SOFTWARE ||
1465  !config.getBoolValue("enableMapReduce"))
1466  {
1467  return;
1468  }
1469 
1470  int cnt = 0;
1471  for (int x = 0; x < mWidth; x ++)
1472  {
1473  for (int y = 0; y < mHeight; y ++)
1474  {
1475  bool correct(true);
1476  bool dontHaveAlpha(false);
1477 
1478  FOR_EACH (LayersCIter, layeri, mLayers)
1479  {
1480  const MapLayer *restrict const layer = *layeri;
1481  if (x >= layer->mWidth || y >= layer->mHeight)
1482  continue;
1483 
1484  // skip layers with flags
1485  if (layer->mTileCondition != -1 || layer->mMask != 1)
1486  continue;
1487 
1488  Image *restrict const img =
1489  layer->mTiles[x + y * layer->mWidth].image;
1490  if (img != nullptr)
1491  {
1492  if (img->hasAlphaChannel() && img->isAlphaCalculated())
1493  {
1494  if (!img->isAlphaVisible())
1495  {
1496  dontHaveAlpha = true;
1497  img->setAlphaVisible(false);
1498  }
1499  }
1500  else if (img->mBounds.w > mapTileSize
1501  || img->mBounds.h > mapTileSize)
1502  {
1503  correct = false;
1504  img->setAlphaVisible(true);
1505  break;
1506  }
1507  else if (!img->isHasAlphaChannel())
1508  {
1509  dontHaveAlpha = true;
1510  img->setAlphaVisible(false);
1511  }
1512  else if (img->hasAlphaChannel())
1513  {
1514  const uint8_t *restrict const arr =
1515  img->SDLgetAlphaChannel();
1516  if (arr == nullptr)
1517  continue;
1518 
1519  bool bad(false);
1520  bool stop(false);
1521  int width;
1522  const SubImage *restrict const subImg
1523  = dynamic_cast<SubImage*>(img);
1524  if (subImg != nullptr)
1525  width = subImg->mInternalBounds.w;
1526  else
1527  width = img->mBounds.w;
1528 
1529  for (int f = img->mBounds.x;
1530  f < img->mBounds.x + img->mBounds.w; f ++)
1531  {
1532  for (int d = img->mBounds.y;
1533  d < img->mBounds.y + img->mBounds.h; d ++)
1534  {
1535  const uint8_t chan = arr[f + d * width];
1536  if (chan != 255)
1537  {
1538  bad = true;
1539  stop = true;
1540  break;
1541  }
1542  }
1543  if (stop)
1544  break;
1545  }
1546  if (!bad)
1547  {
1548  dontHaveAlpha = true;
1549  img->setAlphaVisible(false);
1550  }
1551  else
1552  {
1553  img->setAlphaVisible(true);
1554  }
1555  }
1556  img->setAlphaCalculated(true);
1557  }
1558  }
1559  if (!correct || !dontHaveAlpha)
1560  continue;
1561 
1562  Layers::reverse_iterator ri = mLayers.rbegin();
1563  while (ri != mLayers.rend())
1564  {
1565  const MapLayer *restrict const layer = *ri;
1566  if (x >= layer->mWidth || y >= layer->mHeight)
1567  {
1568  ++ ri;
1569  continue;
1570  }
1571 
1572  // skip layers with flags
1573  if (layer->mTileCondition != -1 || layer->mMask != 1)
1574  {
1575  ++ ri;
1576  continue;
1577  }
1578 
1579  const Image *restrict img =
1580  layer->mTiles[x + y * layer->mWidth].image;
1581  if ((img != nullptr) && !img->isAlphaVisible())
1582  { // removing all down tiles
1583  ++ ri;
1584  while (ri != mLayers.rend())
1585  {
1586  MapLayer *restrict const layer2 = *ri;
1587  // skip layers with flags
1588  if (layer2->mTileCondition != -1 || layer2->mMask != 1)
1589  {
1590  ++ ri;
1591  continue;
1592  }
1593  const size_t pos = CAST_SIZE(
1594  x + y * layer2->mWidth);
1595  img = layer2->mTiles[pos].image;
1596  if (img != nullptr)
1597  {
1598  layer2->mTiles[pos].image = nullptr;
1599  cnt ++;
1600  }
1601  ++ ri;
1602  }
1603  break;
1604  }
1605  ++ ri;
1606  }
1607  }
1608  }
1609  logger->log("tiles reduced: %d", cnt);
1610 #endif // USE_SDL2
1611 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Configuration config
SDL_Rect mInternalBounds
Definition: subimage.h:78
Logger * logger
Definition: logger.cpp:95
Layers mLayers
Definition: map.h:409
bool getBoolValue(const std::string &key) const
Layers::const_iterator LayersCIter
Definition: map.h:59
const int mHeight
Definition: map.h:403
const int mWidth
Definition: map.h:402
MapLayer * mFringeLayer
Definition: map.h:474
Definition: image.h:61
const RenderType mOpenGL
Definition: map.h:462
static const int mapTileSize
Definition: map.h:26
#define restrict
Definition: localconsts.h:176
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ removeActor()

void Map::removeActor ( const Actors::iterator &  iterator)
protected

Removes an actor from the map.

Definition at line 817 of file map.cpp.

References mActors.

Referenced by Actor::setMap(), and Actor::~Actor().

818 {
819  mActors.erase(iterator);
820 // mSpritesUpdated = true;
821 }
Actors mActors
Definition: map.h:413

◆ saveExtraLayer()

void Map::saveExtraLayer ( ) const

Definition at line 1213 of file map.cpp.

References CAST_S32, MapItemType::EMPTY, SpecialLayer::getTile(), getUserMapDirectory(), MapItemType::HOME, ServerCommandType::item, Logger::log(), Logger::log1(), logger, SpecialLayer::mHeight, mkdir_r(), mSpecialLayer, SpecialLayer::mWidth, pathJoin(), reportAlways, restrict, strprintf(), x, and y.

Referenced by QuitDialog::action(), Game::changeMap(), getDrawLayersFlags(), and Game::slowLogic().

1214 {
1215  if (mSpecialLayer == nullptr)
1216  {
1217  logger->log1("No special layer");
1218  return;
1219  }
1220  const std::string mapFileName = pathJoin(getUserMapDirectory(),
1221  "extralayer.txt");
1222  logger->log("saving extra layer: " + mapFileName);
1223 
1224  if (mkdir_r(getUserMapDirectory().c_str()) != 0)
1225  {
1226  logger->log(strprintf("%s doesn't exist and can't be created! "
1227  "Exiting.", getUserMapDirectory().c_str()));
1228  return;
1229  }
1230 
1231  std::ofstream mapFile;
1232  mapFile.open(mapFileName.c_str(), std::ios::binary);
1233  if (!mapFile.is_open())
1234  {
1235  reportAlways("Error opening file for writing: %s",
1236  mapFileName.c_str());
1237  return;
1238  }
1239 
1240  const int width = mSpecialLayer->mWidth;
1241  const int height = mSpecialLayer->mHeight;
1242 
1243  for (int x = 0; x < width; x ++)
1244  {
1245  for (int y = 0; y < height; y ++)
1246  {
1247  const MapItem *restrict const item = mSpecialLayer->getTile(x, y);
1248  if ((item != nullptr) && item->mType != MapItemType::EMPTY
1249  && item->mType != MapItemType::HOME)
1250  {
1251  mapFile << x << " " << y << " "
1252  << CAST_S32(item->mType) << " "
1253  << item->mComment << std::endl;
1254  }
1255  }
1256  }
1257  mapFile.close();
1258 }
void log1(const char *const log_text)
Definition: logger.cpp:222
std::string getUserMapDirectory() const
Definition: map.cpp:1260
std::string pathJoin(std::string str1, const std::string &str2)
int mkdir_r(const char *const pathname)
Create a directory, making leading components first if necessary.
Definition: mkdir.cpp:108
SpecialLayer * mSpecialLayer
Definition: map.h:471
Logger * logger
Definition: logger.cpp:95
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
MapItem * getTile(const int x, const int y) const
#define restrict
Definition: localconsts.h:176
void log(const char *const log_text,...)
Definition: logger.cpp:243
#define reportAlways(...)
Definition: checkutils.h:252

◆ setActorsFix()

void Map::setActorsFix ( const int  x,
const int  y 
)

Definition at line 1712 of file map.cpp.

References mActorFixX, mActorFixY, mFringeLayer, MapLayer::setActorsFix(), x, and y.

Referenced by getObjectsLayer(), and loadReplaceLayer().

1713 {
1714  mActorFixX = x;
1715  mActorFixY = y;
1716  if (mFringeLayer != nullptr)
1718 }
int mActorFixY
Definition: map.h:468
void setActorsFix(const int y)
Definition: maplayer.h:157
int mActorFixX
Definition: map.h:467
MapLayer * mFringeLayer
Definition: map.h:474

◆ setAtlas()

void Map::setAtlas ( Resource *const  atlas)
inline

Definition at line 330 of file map.h.

References mAtlas.

Referenced by loadReplaceLayer().

331  { mAtlas = atlas; }
Resource * mAtlas
Definition: map.h:486

◆ setBlockMask()

void Map::setBlockMask ( const int  x,
const int  y,
const BlockTypeT  type 
)

Definition at line 734 of file map.cpp.

References BlockMask::AIR, BlockType::AIR, MetaTile::blockmask, contains(), BlockType::GROUND, BlockMask::GROUND, BlockMask::GROUNDTOP, BlockType::GROUNDTOP, mMetaTiles, BlockMask::MONSTERWALL, BlockType::MONSTERWALL, mWidth, BlockType::NB_BLOCKTYPES, BlockType::NONE, BlockMask::PLAYERWALL, BlockType::PLAYERWALL, BlockMask::WALL, BlockType::WALL, BlockMask::WATER, BlockType::WATER, x, and y.

Referenced by Ea::MapRecv::processSetTilesType().

736 {
737  if (type == BlockType::NONE || !contains(x, y))
738  return;
739 
740  const int tileNum = x + y * mWidth;
741 
742  switch (type)
743  {
744  case BlockType::WALL:
746  break;
747  case BlockType::AIR:
749  break;
750  case BlockType::WATER:
752  break;
753  case BlockType::GROUND:
755  break;
758  break;
761  break;
764  break;
765  default:
766  case BlockType::NONE:
768  // Do nothing.
769  break;
770  }
771 }
bool contains(const int x, const int y) const
Definition: map.cpp:800
unsigned char blockmask
Definition: metatile.h:51
MetaTile *const mMetaTiles
Definition: map.h:407
const int mWidth
Definition: map.h:402

◆ setCustom()

void Map::setCustom ( const bool  b)
inline

Definition at line 320 of file map.h.

References mCustom.

Referenced by MapReader::createEmptyMap().

321  { mCustom = b; }
bool mCustom
Definition: map.h:491

◆ setDrawLayersFlags()

void Map::setDrawLayersFlags ( const MapTypeT n)

Definition at line 1691 of file map.cpp.

References MapType::BLACKWHITE, FOR_EACH, mDrawLayersFlags, mDrawOnlyFringe, mLayers, restrict, MapType::SPECIAL3, MapType::SPECIAL4, and updateDrawLayersList().

Referenced by Viewport::getMouseTile(), getTileHeight(), and GameModifiers::resetModifiers().

1692 {
1693  mDrawLayersFlags = n;
1697  {
1698  mDrawOnlyFringe = true;
1699  }
1700  else
1701  {
1702  mDrawOnlyFringe = false;
1703  }
1705  FOR_EACH (Layers::iterator, it, mLayers)
1706  {
1707  MapLayer *restrict const layer = *it;
1708  layer->setDrawLayerFlags(mDrawLayersFlags);
1709  }
1710 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
bool mDrawOnlyFringe
Definition: map.h:492
void updateDrawLayersList()
Definition: map.cpp:1626
Layers mLayers
Definition: map.h:409
MapTypeT mDrawLayersFlags
Definition: map.h:417
#define restrict
Definition: localconsts.h:176

◆ setHasWarps()

void Map::setHasWarps ( const bool  n)
inline

Definition at line 240 of file map.h.

References mHasWarps.

241  { mHasWarps = n; }
bool mHasWarps
Definition: map.h:414

◆ setMask()

void Map::setMask ( const int  mask)

Definition at line 1664 of file map.cpp.

References mMask, mRedrawMap, and updateDrawLayersList().

Referenced by Ea::PlayerRecv::processMapMask(), and setWalkLayer().

1665 {
1666  if (mask != mMask)
1667  {
1668  mRedrawMap = true;
1669  mMask = mask;
1671  }
1672 }
void updateDrawLayersList()
Definition: map.cpp:1626
bool mRedrawMap
Definition: map.h:488
int mMask
Definition: map.h:485

◆ setMusicFile()

void Map::setMusicFile ( const std::string &  file)

Definition at line 1674 of file map.cpp.

References Properties::setProperty().

Referenced by getTileHeight(), and Ea::PlayerRecv::processMapMusic().

1675 {
1676  setProperty("music", file);
1677 }
void setProperty(const std::string &name, const std::string &value)
Definition: properties.h:127

◆ setPvpMode()

void Map::setPvpMode ( const int  mode)

Definition at line 1348 of file map.cpp.

References NotifyTypes::GVG_ON, localPlayer, mPvp, NotifyManager::notify(), NotifyTypes::PVP_OFF_GVG_OFF, NotifyTypes::PVP_ON, NotifyTypes::PVP_ON_GVG_ON, and NotifyTypes::PVP_UNKNOWN.

Referenced by getActorsCount(), EAthena::BeingRecv::processMapTypeProperty(), and Ea::BeingRecv::processPvpMapMode().

1349 {
1350  const int oldMode = mPvp;
1351 
1352  if (mode == 0)
1353  mPvp = 0;
1354  else
1355  mPvp |= mode;
1356 
1357  if (mPvp != oldMode && (localPlayer != nullptr))
1358  {
1359  switch (mPvp)
1360  {
1361  case 0:
1363  break;
1364  case 1:
1366  break;
1367  case 2:
1369  break;
1370  case 3:
1372  break;
1373  default:
1375  break;
1376  }
1377  }
1378 }
int mPvp
Definition: map.h:463
void notify(const unsigned int message)
LocalPlayer * localPlayer

◆ setVersion()

void Map::setVersion ( const int  n)
inline

Definition at line 309 of file map.h.

References mVersion, reduce(), and restrict2.

Referenced by loadReplaceLayer().

310  { mVersion = n; }
int mVersion
Definition: map.h:469

◆ setWalk()

void Map::setWalk ( const int  x,
const int  y 
)

Definition at line 795 of file map.cpp.

References addBlockMask(), BlockType::GROUNDTOP, x, and y.

Referenced by LocalPlayer::setRealPos().

796 {
798 }
void addBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:695

◆ setWalkLayer()

void Map::setWalkLayer ( WalkLayer *const  layer)
inline

Definition at line 339 of file map.h.

References A_NONNULL, addHeights(), getHeightOffset(), mWalkLayer, restrict, restrict2, setMask(), and updateDrawLayersList().

Referenced by loadReplaceLayer().

340  { mWalkLayer = layer; }
WalkLayer * mWalkLayer
Definition: map.h:408

◆ update()

void Map::update ( const int  ticks)

Updates animations. Called as needed.

Definition at line 319 of file map.cpp.

References FOR_EACH, mRedrawMap, mTileAnimations, and restrict.

Referenced by Game::logic().

320 {
321  // Update animated tiles
323  {
324  TileAnimation *restrict const tileAni = iAni->second;
325  if ((tileAni != nullptr) && tileAni->update(ticks))
326  mRedrawMap = true;
327  }
328 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
TileAnimationMap::const_iterator TileAnimationMapCIter
Definition: tileanimation.h:64
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:457
bool mRedrawMap
Definition: map.h:488
#define restrict
Definition: localconsts.h:176

◆ updateAmbientLayers()

void Map::updateAmbientLayers ( const float  scrollX,
const float  scrollY 
)
private

Updates scrolling of ambient layers. Has to be called each game tick.

Definition at line 607 of file map.cpp.

References BLOCK_END, BLOCK_START, FOR_EACH, get_elapsed_time(), mBackgrounds, mForegrounds, mLastAScrollX, mLastAScrollY, AmbientLayer::mMask, mMask, tick_time, and AmbientLayer::update().

Referenced by draw().

609 {
610  BLOCK_START("Map::updateAmbientLayers")
611  static int lastTick = tick_time;
612 
613  if (mLastAScrollX == 0.0F && mLastAScrollY == 0.0F)
614  {
615  // First call - initialisation
616  mLastAScrollX = scrollX;
617  mLastAScrollY = scrollY;
618  }
619 
620  // Update Overlays
621  const float dx = scrollX - mLastAScrollX;
622  const float dy = scrollY - mLastAScrollY;
623  const int timePassed = get_elapsed_time(lastTick);
624 
625  // need check mask to update or not to update
626 
628  {
629  AmbientLayer *const layer = *i;
630  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
631  layer->update(timePassed, dx, dy);
632  }
633 
635  {
636  AmbientLayer *const layer = *i;
637  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
638  layer->update(timePassed, dx, dy);
639  }
640 
641  mLastAScrollX = scrollX;
642  mLastAScrollY = scrollY;
643  lastTick = tick_time;
644  BLOCK_END("Map::updateAmbientLayers")
645 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
volatile int tick_time
Definition: timer.cpp:52
AmbientLayerVector mBackgrounds
Definition: map.h:424
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
int get_elapsed_time(const int startTime)
Definition: timer.cpp:93
float mLastAScrollX
Definition: map.h:426
void update(const int timePassed, const float dx, const float dy)
AmbientLayerVector mForegrounds
Definition: map.h:425
float mLastAScrollY
Definition: map.h:427
AmbientLayerVector::iterator AmbientLayerVectorIter
Definition: map.h:63
int mMask
Definition: map.h:485

◆ updateConditionLayers()

void Map::updateConditionLayers ( )

Definition at line 1720 of file map.cpp.

References FOR_EACH, mHeight, mLayers, mMetaTiles, mRedrawMap, mWidth, and restrict.

Referenced by MapReader::addLayerToList(), MapReader::createEmptyMap(), isHeightsPresent(), and Ea::MapRecv::processSetTilesType().

1721 {
1722  mRedrawMap = true;
1723 
1725  {
1726  MapLayer *restrict const layer = *it;
1727  if ((layer == nullptr) || layer->mTileCondition == -1)
1728  continue;
1729  layer->updateConditionTiles(mMetaTiles,
1730  mWidth, mHeight);
1731  }
1732 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Layers mLayers
Definition: map.h:409
Layers::const_iterator LayersCIter
Definition: map.h:59
bool mRedrawMap
Definition: map.h:488
const int mHeight
Definition: map.h:403
MetaTile *const mMetaTiles
Definition: map.h:407
const int mWidth
Definition: map.h:402
#define restrict
Definition: localconsts.h:176

◆ updateDrawLayersList()

void Map::updateDrawLayersList ( )

Definition at line 1626 of file map.cpp.

References MapLayer::isFringeLayer(), mDrawLayersFlags, mDrawOnlyFringe, mDrawOverLayers, mDrawUnderLayers, mLayers, MapLayer::mMask, mMask, and MapType::SPECIAL2.

Referenced by MapReader::createEmptyMap(), loadReplaceLayer(), setDrawLayersFlags(), setMask(), and setWalkLayer().

1627 {
1628  mDrawUnderLayers.clear();
1629  mDrawOverLayers.clear();
1630 
1631  if (mDrawOnlyFringe)
1632  return;
1633 
1634  LayersCIter layers = mLayers.begin();
1635  const LayersCIter layers_end = mLayers.end();
1636  for (; layers != layers_end; ++ layers)
1637  {
1638  MapLayer *const layer = *layers;
1639  if ((layer->mMask & mMask) == 0)
1640  continue;
1641 
1642  if (layer->isFringeLayer())
1643  {
1644  ++ layers;
1645  break;
1646  }
1647 
1648  mDrawUnderLayers.push_back(layer);
1649  }
1650 
1652  return;
1653 
1654  for (; layers != layers_end; ++ layers)
1655  {
1656  MapLayer *const layer = *layers;
1657  if ((layer->mMask & mMask) == 0)
1658  continue;
1659 
1660  mDrawOverLayers.push_back(layer);
1661  }
1662 }
bool mDrawOnlyFringe
Definition: map.h:492
Layers mLayers
Definition: map.h:409
Layers::const_iterator LayersCIter
Definition: map.h:59
MapTypeT mDrawLayersFlags
Definition: map.h:417
Layers mDrawUnderLayers
Definition: map.h:410
Layers mDrawOverLayers
Definition: map.h:411
int mMask
Definition: maplayer.h:221
int mMask
Definition: map.h:485
bool isFringeLayer() const
Definition: maplayer.h:137

◆ updatePortalTile()

void Map::updatePortalTile ( const std::string &  name,
const int  type,
const int  x,
const int  y,
const bool  addNew 
)

Definition at line 1300 of file map.cpp.

References addPortalTile(), findPortalXY(), ServerCommandType::item, mSpecialLayer, restrict, SpecialLayer::setTile(), SpecialLayer::updateCache(), x, and y.

Referenced by addExtraLayer(), getHasWarps(), and LocalPlayer::setHome().

1304 {
1306  if (item != nullptr)
1307  {
1308  item->mComment = name;
1309  item->setType(type);
1310  item->mX = x;
1311  item->mY = y;
1312  if (mSpecialLayer != nullptr)
1313  {
1314  item = new MapItem(type, name, x, y);
1315  mSpecialLayer->setTile(x, y, item);
1317  }
1318  }
1319  else if (addNew)
1320  {
1321  addPortalTile(name, type, x, y);
1322  }
1323 }
SpecialLayer * mSpecialLayer
Definition: map.h:471
void setTile(const int x, const int y, MapItem *const item)
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1287
void updateCache()
MapItem * findPortalXY(const int x, const int y) const
Definition: map.cpp:1325
#define restrict
Definition: localconsts.h:176

Friends And Related Function Documentation

◆ Actor

friend class Actor
friend

Definition at line 369 of file map.h.

◆ Minimap

friend class Minimap
friend

Definition at line 370 of file map.h.

Field Documentation

◆ mActorFixX

int Map::mActorFixX
private

Definition at line 467 of file map.h.

Referenced by setActorsFix().

◆ mActorFixY

int Map::mActorFixY
private

Definition at line 468 of file map.h.

Referenced by setActorsFix().

◆ mActors

Actors Map::mActors
private

Definition at line 413 of file map.h.

Referenced by addActor(), calcMemoryLocal(), draw(), getActorsCount(), and removeActor().

◆ mAtlas

Resource* Map::mAtlas
private

Definition at line 486 of file map.h.

Referenced by haveAtlas(), setAtlas(), and ~Map().

◆ mBackgrounds

AmbientLayerVector Map::mBackgrounds
private

◆ mBeingOpacity

bool Map::mBeingOpacity
private

Definition at line 489 of file map.h.

Referenced by draw(), Map(), and optionChanged().

◆ mCachedDraw

bool Map::mCachedDraw
private

Definition at line 490 of file map.h.

Referenced by draw().

◆ mCustom

bool Map::mCustom
private

Definition at line 491 of file map.h.

Referenced by isCustom(), and setCustom().

◆ mDrawLayersFlags

MapTypeT Map::mDrawLayersFlags
private

Definition at line 417 of file map.h.

Referenced by draw(), getDrawLayersFlags(), setDrawLayersFlags(), and updateDrawLayersList().

◆ mDrawOnlyFringe

bool Map::mDrawOnlyFringe
private

Definition at line 492 of file map.h.

Referenced by draw(), setDrawLayersFlags(), and updateDrawLayersList().

◆ mDrawOverLayers

Layers Map::mDrawOverLayers
private

Definition at line 411 of file map.h.

Referenced by calcMemoryLocal(), draw(), and updateDrawLayersList().

◆ mDrawScrollX

int Map::mDrawScrollX
private

Definition at line 483 of file map.h.

Referenced by draw().

◆ mDrawScrollY

int Map::mDrawScrollY
private

Definition at line 484 of file map.h.

Referenced by draw().

◆ mDrawUnderLayers

Layers Map::mDrawUnderLayers
private

Definition at line 410 of file map.h.

Referenced by calcMemoryLocal(), draw(), and updateDrawLayersList().

◆ mDrawX

int Map::mDrawX
private

Definition at line 481 of file map.h.

Referenced by draw().

◆ mDrawY

int Map::mDrawY
private

Definition at line 482 of file map.h.

Referenced by draw().

◆ mForegrounds

AmbientLayerVector Map::mForegrounds
private

◆ mFringeLayer

MapLayer* Map::mFringeLayer
private

Definition at line 474 of file map.h.

Referenced by addLayer(), draw(), reduce(), setActorsFix(), and ~Map().

◆ mHasWarps

bool Map::mHasWarps
private

Definition at line 414 of file map.h.

Referenced by getHasWarps(), and setHasWarps().

◆ mHeight

const int Map::mHeight
private

◆ mHeights

const MapHeights* Map::mHeights
private

Definition at line 487 of file map.h.

Referenced by addHeights(), calcMemoryChilds(), getHeightOffset(), isHeightsPresent(), and ~Map().

◆ mIndexedTilesets

Tileset** Map::mIndexedTilesets
private

Definition at line 465 of file map.h.

Referenced by clearIndexedTilesets(), getTilesetWithGid(), and indexTilesets().

◆ mIndexedTilesetsSize

int Map::mIndexedTilesetsSize
private

Definition at line 466 of file map.h.

Referenced by calcMemoryLocal(), clearIndexedTilesets(), getTilesetWithGid(), and indexTilesets().

◆ mLastAScrollX

float Map::mLastAScrollX
private

Definition at line 426 of file map.h.

Referenced by updateAmbientLayers().

◆ mLastAScrollY

float Map::mLastAScrollY
private

Definition at line 427 of file map.h.

Referenced by updateAmbientLayers().

◆ mLastScrollX

int Map::mLastScrollX
private

Definition at line 478 of file map.h.

Referenced by draw().

◆ mLastScrollY

int Map::mLastScrollY
private

Definition at line 479 of file map.h.

Referenced by draw().

◆ mLastX

int Map::mLastX
private

Definition at line 476 of file map.h.

Referenced by draw().

◆ mLastY

int Map::mLastY
private

Definition at line 477 of file map.h.

Referenced by draw().

◆ mLayers

Layers Map::mLayers
private

◆ mMapPortals

std::vector<MapItem*> Map::mMapPortals
private

Definition at line 455 of file map.h.

Referenced by addPortalTile(), calcMemoryLocal(), findPortalXY(), getPortals(), and ~Map().

◆ mMask

int Map::mMask
private

Definition at line 485 of file map.h.

Referenced by drawAmbientLayers(), setMask(), updateAmbientLayers(), and updateDrawLayersList().

◆ mMaxTileHeight

int Map::mMaxTileHeight
private

Definition at line 406 of file map.h.

Referenced by addTileset(), and draw().

◆ mMetaTiles

MetaTile* const Map::mMetaTiles
private

◆ mName

std::string Map::mName
private

Definition at line 459 of file map.h.

Referenced by calcMemoryLocal(), and getCounterName().

◆ mObjects

ObjectsLayer* Map::mObjects
private

Definition at line 473 of file map.h.

Referenced by addRange(), calcMemoryChilds(), getObjectData(), getObjectsLayer(), and ~Map().

◆ mOnClosedList

unsigned int Map::mOnClosedList
private

Definition at line 420 of file map.h.

Referenced by findPath().

◆ mOnOpenList

unsigned int Map::mOnOpenList
private

Definition at line 421 of file map.h.

Referenced by findPath().

◆ mOpacity

float Map::mOpacity
private

Definition at line 461 of file map.h.

Referenced by Map(), and optionChanged().

◆ mOpenGL

const RenderType Map::mOpenGL
private

Definition at line 462 of file map.h.

Referenced by draw(), and reduce().

◆ mOverlayDetail

int Map::mOverlayDetail
private

Definition at line 460 of file map.h.

Referenced by draw(), and optionChanged().

◆ mParticleEffects

std::vector<ParticleEffectData> Map::mParticleEffects
private

Definition at line 453 of file map.h.

Referenced by addParticleEffect(), calcMemoryLocal(), and initializeParticleEffects().

◆ mPvp

int Map::mPvp
private

Definition at line 463 of file map.h.

Referenced by getPvpMode(), and setPvpMode().

◆ mRedrawMap

bool Map::mRedrawMap
private

Definition at line 488 of file map.h.

Referenced by draw(), redrawMap(), setMask(), update(), and updateConditionLayers().

◆ mSpecialLayer

SpecialLayer* Map::mSpecialLayer
private

◆ mTempLayer

SpecialLayer* Map::mTempLayer
private

Definition at line 472 of file map.h.

Referenced by calcMemoryChilds(), draw(), getTempLayer(), and ~Map().

◆ mTileAnimations

std::map<int, TileAnimation*> Map::mTileAnimations
private

◆ mTileHeight

const int Map::mTileHeight
private

Definition at line 405 of file map.h.

Referenced by draw(), drawCollision(), and getTileHeight().

◆ mTilesets

Tilesets Map::mTilesets
private

Definition at line 412 of file map.h.

Referenced by addTileset(), calcMemoryChilds(), calcMemoryLocal(), indexTilesets(), and ~Map().

◆ mTilesetsIndexed

bool Map::mTilesetsIndexed
private

Definition at line 464 of file map.h.

Referenced by clearIndexedTilesets(), and indexTilesets().

◆ mTileWidth

const int Map::mTileWidth
private

Definition at line 404 of file map.h.

Referenced by draw(), drawCollision(), and getTileWidth().

◆ mVersion

int Map::mVersion
private

Definition at line 469 of file map.h.

Referenced by getVersion(), and setVersion().

◆ mWalkLayer

WalkLayer* Map::mWalkLayer
private

Definition at line 408 of file map.h.

Referenced by calcMemoryChilds(), getWalkLayer(), setWalkLayer(), and ~Map().

◆ mWidth

const int Map::mWidth
private

The documentation for this class was generated from the following files: