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
 
int getAtlasCount () const
 
void setAtlas (AtlasResource *const atlas)
 
bool haveAtlas () const
 
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
 
- 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
 
AtlasResourcemAtlas
 
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 71 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 96 of file map.cpp.

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

Referenced by calcMemoryLocal().

100  :
101  Properties(),
102  mWidth(width), mHeight(height),
103  mTileWidth(tileWidth), mTileHeight(tileHeight),
104  mMaxTileHeight(height),
106  mWalkLayer(nullptr),
107  mLayers(),
109  mDrawOverLayers(),
110  mTilesets(),
111  mActors(),
112  mHasWarps(false),
114  mOnClosedList(1),
115  mOnOpenList(2),
116  mBackgrounds(),
117  mForegrounds(),
118  mLastAScrollX(0.0F),
119  mLastAScrollY(0.0F),
121  mMapPortals(),
122  mTileAnimations(),
123  mName(name),
124  mOverlayDetail(config.getIntValue("OverlayDetail")),
125  mOpacity(config.getFloatValue("guialpha")),
126 #ifdef USE_OPENGL
128 #else // USE_OPENGL
130 #endif // USE_OPENGL
131  mPvp(0),
132  mTilesetsIndexed(false),
133  mIndexedTilesets(nullptr),
135  mActorFixX(0),
136  mActorFixY(0),
137  mVersion(0),
138  mSpecialLayer(new SpecialLayer("special layer", width, height)),
139  mTempLayer(new SpecialLayer("temp layer", width, height)),
140  mObjects(new ObjectsLayer(width, height)),
141  mFringeLayer(nullptr),
142  mLastX(-1),
143  mLastY(-1),
144  mLastScrollX(-1),
145  mLastScrollY(-1),
146  mDrawX(-1),
147  mDrawY(-1),
148  mDrawScrollX(-1),
149  mDrawScrollY(-1),
150  mMask(1),
151 #ifdef USE_OPENGL
152  mAtlas(nullptr),
153 #endif // USE_OPENGL
154  mHeights(nullptr),
155  mRedrawMap(true),
156  mBeingOpacity(false),
157 #ifdef USE_OPENGL
162 #else // USE_OPENGL
163  mCachedDraw(false),
164 #endif // USE_OPENGL
165  mCustom(false),
166  mDrawOnlyFringe(false)
167 {
168  config.addListener("OverlayDetail", this);
169  config.addListener("guialpha", this);
170  config.addListener("beingopacity", this);
171 
172  if (mOpacity != 1.0F)
173  mBeingOpacity = config.getBoolValue("beingopacity");
174  else
175  mBeingOpacity = false;
176 }
int mLastScrollY
Definition: map.h:486
const int mTileHeight
Definition: map.h:412
bool mDrawOnlyFringe
Definition: map.h:502
AmbientLayerVector mBackgrounds
Definition: map.h:431
int mLastX
Definition: map.h:483
const MapHeights * mHeights
Definition: map.h:497
Tilesets mTilesets
Definition: map.h:419
int mPvp
Definition: map.h:470
WalkLayer * mWalkLayer
Definition: map.h:415
int mDrawScrollY
Definition: map.h:491
Configuration config
int mOverlayDetail
Definition: map.h:467
int mActorFixY
Definition: map.h:475
SpecialLayer * mSpecialLayer
Definition: map.h:478
int mDrawX
Definition: map.h:488
int getIntValue(const std::string &key) const
float getFloatValue(const std::string &key) const
bool mHasWarps
Definition: map.h:421
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:464
ObjectsLayer * mObjects
Definition: map.h:480
bool mTilesetsIndexed
Definition: map.h:471
void addListener(const std::string &key, ConfigListener *const listener)
const int mTileWidth
Definition: map.h:411
std::vector< MapItem * > mMapPortals
Definition: map.h:462
Layers mLayers
Definition: map.h:416
float mLastAScrollX
Definition: map.h:433
int mLastScrollX
Definition: map.h:485
bool getBoolValue(const std::string &key) const
bool mCustom
Definition: map.h:501
MapTypeT mDrawLayersFlags
Definition: map.h:424
int mActorFixX
Definition: map.h:474
std::string mName
Definition: map.h:466
AmbientLayerVector mForegrounds
Definition: map.h:432
bool mRedrawMap
Definition: map.h:498
int mIndexedTilesetsSize
Definition: map.h:473
RenderType intToRenderType(const int mode)
Definition: renderers.cpp:42
bool mCachedDraw
Definition: map.h:500
int mMaxTileHeight
Definition: map.h:413
const int mHeight
Definition: map.h:410
SpecialLayer * mTempLayer
Definition: map.h:479
MetaTile *const mMetaTiles
Definition: map.h:414
const int mWidth
Definition: map.h:409
unsigned int mOnOpenList
Definition: map.h:428
int mDrawY
Definition: map.h:489
int mLastY
Definition: map.h:484
unsigned int mOnClosedList
Definition: map.h:427
MapLayer * mFringeLayer
Definition: map.h:481
float mLastAScrollY
Definition: map.h:434
const RenderType mOpenGL
Definition: map.h:469
float mOpacity
Definition: map.h:468
Layers mDrawUnderLayers
Definition: map.h:417
int mVersion
Definition: map.h:476
bool mBeingOpacity
Definition: map.h:499
int mDrawScrollX
Definition: map.h:490
Layers mDrawOverLayers
Definition: map.h:418
Tileset ** mIndexedTilesets
Definition: map.h:472
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:460
Actors mActors
Definition: map.h:420
AtlasResource * mAtlas
Definition: map.h:494
int mMask
Definition: map.h:492

◆ ~Map()

Map::~Map ( )

Destructor.

Definition at line 178 of file map.cpp.

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

179 {
180  config.removeListeners(this);
182 
183  if (mWalkLayer != nullptr)
184  {
185  mWalkLayer->decRef();
186  mWalkLayer = nullptr;
187  }
188  mFringeLayer = nullptr;
198 #ifdef USE_OPENGL
199  if (mAtlas != nullptr)
200  {
201  mAtlas->decRef();
202  mAtlas = nullptr;
203  }
204 #endif // USE_OPENGL
206  delete [] mMetaTiles;
207 }
AmbientLayerVector mBackgrounds
Definition: map.h:431
virtual void decRef()
Definition: resource.cpp:49
const MapHeights * mHeights
Definition: map.h:497
Tilesets mTilesets
Definition: map.h:419
WalkLayer * mWalkLayer
Definition: map.h:415
Configuration config
SpecialLayer * mSpecialLayer
Definition: map.h:478
#define delete2(var)
Definition: delete2.h:24
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:464
ObjectsLayer * mObjects
Definition: map.h:480
std::vector< MapItem * > mMapPortals
Definition: map.h:462
Layers mLayers
Definition: map.h:416
void delete_all(Container &c)
Definition: dtor.h:55
AmbientLayerVector mForegrounds
Definition: map.h:432
SpecialLayer * mTempLayer
Definition: map.h:479
MetaTile *const mMetaTiles
Definition: map.h:414
void removeListeners(ConfigListener *const listener)
MapLayer * mFringeLayer
Definition: map.h:481
#define CHECKLISTENERS
Definition: localconsts.h:276
AtlasResource * mAtlas
Definition: map.h:494

Member Function Documentation

◆ addActor()

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

Adds an actor to the map.

Definition at line 817 of file map.cpp.

References mActors.

Referenced by Actor::setMap().

818 {
819  mActors.push_front(actor);
820 // mSpritesUpdated = true;
821  return mActors.begin();
822 }
Actors mActors
Definition: map.h:420

◆ addAnimation()

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

Adds a tile animation to the map

Definition at line 1686 of file map.cpp.

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

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

1688 {
1689  std::map<int, TileAnimation*>::iterator it = mTileAnimations.find(gid);
1690  if (it != mTileAnimations.end())
1691  {
1692  logger->log("duplicate map animation with gid = %d", gid);
1693  delete (*it).second;
1694  }
1695  mTileAnimations[gid] = animation;
1696 }
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:464
Logger * logger
Definition: logger.cpp:88
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ addBlockMask()

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

Definition at line 702 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().

704 {
705  if (type == BlockType::NONE || !contains(x, y))
706  return;
707 
708  const int tileNum = x + y * mWidth;
709 
710  switch (type)
711  {
712  case BlockType::WALL:
714  break;
715  case BlockType::AIR:
716  mMetaTiles[tileNum].blockmask |= BlockMask::AIR;
717  break;
718  case BlockType::WATER:
720  break;
721  case BlockType::GROUND:
723  break;
726  break;
729  break;
732  break;
733  default:
734  case BlockType::NONE:
736  // Do nothing.
737  break;
738  }
739 }
bool contains(const int x, const int y) const
Definition: map.cpp:807
unsigned char blockmask
Definition: metatile.h:51
MetaTile *const mMetaTiles
Definition: map.h:414
const int mWidth
Definition: map.h:409

◆ addExtraLayer()

void Map::addExtraLayer ( )

Definition at line 1137 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().

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

◆ addHeights()

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

Definition at line 1620 of file map.cpp.

References mHeights.

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

1621 {
1622  delete mHeights;
1623  mHeights = heights;
1624 }
const MapHeights * mHeights
Definition: map.h:497

◆ addLayer()

void Map::addLayer ( MapLayer *const  layer)

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

Definition at line 311 of file map.cpp.

References mFringeLayer, and mLayers.

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

312 {
313  mLayers.push_back(layer);
314  if (layer->isFringeLayer() && (mFringeLayer == nullptr))
315  mFringeLayer = layer;
316 }
Layers mLayers
Definition: map.h:416
MapLayer * mFringeLayer
Definition: map.h:481
bool isFringeLayer() const
Definition: maplayer.h:140

◆ 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 1096 of file map.cpp.

References mParticleEffects, x, and y.

Referenced by getTileHeight(), and loadReplaceLayer().

1099 {
1100  ParticleEffectData newEffect(effectFile, x, y, w, h);
1101  mParticleEffects.push_back(newEffect);
1102 }
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:460

◆ 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 1286 of file map.cpp.

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

Referenced by getHasWarps(), and loadReplaceLayer().

1290 {
1291  addPortalTile(name, type, (x / mapTileSize) + (dx / mapTileSize / 2),
1292  (y / mapTileSize) + (dy / mapTileSize / 2));
1293 }
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1295
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 1295 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().

1298 {
1299  if (mSpecialLayer != nullptr)
1300  {
1301  mSpecialLayer->setTile(x, y, new MapItem(type, name, x, y));
1303  }
1304 
1305  mMapPortals.push_back(new MapItem(type, name, x, y));
1306 }
SpecialLayer * mSpecialLayer
Definition: map.h:478
void setTile(const int x, const int y, MapItem *const item)
std::vector< MapItem * > mMapPortals
Definition: map.h:462
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 1274 of file map.cpp.

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

Referenced by getHasWarps(), and loadReplaceLayer().

1278 {
1279  if (mObjects == nullptr)
1280  return;
1281 
1282  mObjects->addObject(name, type, x / mapTileSize, y / mapTileSize,
1283  dx / mapTileSize, dy / mapTileSize);
1284 }
ObjectsLayer * mObjects
Definition: map.h:480
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 318 of file map.cpp.

References mMaxTileHeight, and mTilesets.

Referenced by loadReplaceLayer().

319 {
320  mTilesets.push_back(tileset);
321  const int height = tileset->getHeight();
322  if (height > mMaxTileHeight)
323  mMaxTileHeight = height;
324 }
Tilesets mTilesets
Definition: map.h:419
int mMaxTileHeight
Definition: map.h:413
int getHeight() const
Definition: imageset.h:65

◆ calcMemoryChilds()

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

Reimplemented from MemoryCounter.

Definition at line 1769 of file map.cpp.

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

Referenced by isHeightsPresent().

1770 {
1771  int sz = 0;
1772 
1773  if (mWalkLayer != nullptr)
1774  sz += mWalkLayer->calcMemory(level + 1);
1776  {
1777  sz += (*it)->calcMemory(level + 1);
1778  }
1779  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1780  {
1781  sz += (*it)->calcMemory(level + 1);
1782  }
1784  {
1785  sz += (*it)->calcMemory(level + 1);
1786  }
1788  {
1789  sz += (*it)->calcMemory(level + 1);
1790  }
1791  if (mSpecialLayer != nullptr)
1792  mSpecialLayer->calcMemory(level + 1);
1793  if (mTempLayer != nullptr)
1794  mTempLayer->calcMemory(level + 1);
1795  if (mObjects != nullptr)
1796  mObjects->calcMemory(level + 1);
1797  if (mHeights != nullptr)
1798  mHeights->calcMemory(level + 1);
1799  return sz;
1800 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
AmbientLayerVector mBackgrounds
Definition: map.h:431
const MapHeights * mHeights
Definition: map.h:497
Tilesets mTilesets
Definition: map.h:419
WalkLayer * mWalkLayer
Definition: map.h:415
int calcMemory(const int level) const
SpecialLayer * mSpecialLayer
Definition: map.h:478
ObjectsLayer * mObjects
Definition: map.h:480
Layers mLayers
Definition: map.h:416
Layers::const_iterator LayersCIter
Definition: map.h:62
AmbientLayerVector mForegrounds
Definition: map.h:432
SpecialLayer * mTempLayer
Definition: map.h:479
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:65

◆ calcMemoryLocal()

int Map::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 1751 of file map.cpp.

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

Referenced by isHeightsPresent().

1752 {
1753  return static_cast<int>(sizeof(Map) +
1754  mName.capacity() +
1755  sizeof(MetaTile) * mWidth * mHeight +
1756  sizeof(MapLayer*) * (mLayers.capacity() +
1757  mDrawUnderLayers.capacity() +
1758  mDrawOverLayers.capacity()) +
1759  sizeof(Tileset*) * mTilesets.capacity() +
1760  sizeof(Actor*) * mActors.size() +
1761  sizeof(AmbientLayer*) * (mBackgrounds.capacity()
1762  + mForegrounds.capacity()) +
1763  sizeof(ParticleEffectData) * mParticleEffects.capacity() +
1764  sizeof(MapItem) * mMapPortals.capacity() +
1765  (sizeof(TileAnimation) + sizeof(int)) * mTileAnimations.size() +
1766  sizeof(Tileset*) * mIndexedTilesetsSize);
1767 }
AmbientLayerVector mBackgrounds
Definition: map.h:431
Tilesets mTilesets
Definition: map.h:419
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:464
std::vector< MapItem * > mMapPortals
Definition: map.h:462
Layers mLayers
Definition: map.h:416
std::string mName
Definition: map.h:466
AmbientLayerVector mForegrounds
Definition: map.h:432
int mIndexedTilesetsSize
Definition: map.h:473
const int mHeight
Definition: map.h:410
const int mWidth
Definition: map.h:409
Definition: actor.h:40
Layers mDrawUnderLayers
Definition: map.h:417
Map(const std::string &name, const int width, const int height, const int tileWidth, const int tileHeight)
Definition: map.cpp:96
Layers mDrawOverLayers
Definition: map.h:418
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:460
Actors mActors
Definition: map.h:420

◆ clearIndexedTilesets()

void Map::clearIndexedTilesets ( )

Definition at line 1458 of file map.cpp.

References mIndexedTilesets, mIndexedTilesetsSize, and mTilesetsIndexed.

Referenced by getObjectsLayer(), and loadReplaceLayer().

1459 {
1460  if (!mTilesetsIndexed)
1461  return;
1462 
1463  mTilesetsIndexed = false;
1464  delete [] mIndexedTilesets;
1466 }
bool mTilesetsIndexed
Definition: map.h:471
int mIndexedTilesetsSize
Definition: map.h:473
Tileset ** mIndexedTilesets
Definition: map.h:472

◆ 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 807 of file map.cpp.

References mHeight, mWidth, x, and y.

Referenced by addBlockMask(), and setBlockMask().

808 {
809  return x >= 0 && y >= 0 && x < mWidth && y < mHeight;
810 }
const int mHeight
Definition: map.h:410
const int mWidth
Definition: map.h:409

◆ 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 337 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().

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

◆ 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 654 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().

657 {
658  BLOCK_START("Map::drawAmbientLayers")
659  // Detail 0 = no ambient effects except background image
660  if (detail <= 0 && type != MapLayerPosition::BACKGROUND_LAYERS)
661  {
662  BLOCK_END("Map::drawAmbientLayers")
663  return;
664  }
665 
666  // find out which layer list to draw
667  const AmbientLayerVector *restrict layers = nullptr;
668  switch (type)
669  {
671  layers = &mForegrounds;
672  break;
674  layers = &mBackgrounds;
675  break;
676  default:
677  return;
678  }
679 
680  // Draw overlays
682  {
683  const AmbientLayer *restrict const layer = *i;
684  // need check mask to draw or not to draw
685  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
686  (layer)->draw(graphics, graphics->mWidth, graphics->mHeight);
687 
688  // Detail 1: only one overlay, higher: all overlays
689  if (detail == 1)
690  break;
691  }
692  BLOCK_END("Map::drawAmbientLayers")
693 }
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:30
AmbientLayerVector mBackgrounds
Definition: map.h:431
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:337
AmbientLayerVector mForegrounds
Definition: map.h:432
int mHeight
Definition: graphics.h:484
#define restrict
Definition: localconsts.h:164
std::vector< AmbientLayer * > AmbientLayerVector
Definition: map.h:64
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:65
int mMask
Definition: map.h:492

◆ 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 564 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.

568 {
569  const int endPixelY = graphics->mHeight + scrollY + mTileHeight - 1;
570  int startX = scrollX / mTileWidth;
571  int startY = scrollY / mTileHeight;
572  int endX = (graphics->mWidth + scrollX + mTileWidth - 1) / mTileWidth;
573  int endY = endPixelY / mTileHeight;
574 
575  if (startX < 0)
576  startX = 0;
577  if (startY < 0)
578  startY = 0;
579  if (endX > mWidth)
580  endX = mWidth;
581  if (endY > mHeight)
582  endY = mHeight;
583 
584  if (drawFlags < MapType::SPECIAL)
585  {
587  graphics->drawNet(
588  startX * mTileWidth - scrollX,
589  startY * mTileHeight - scrollY,
590  endX * mTileWidth - scrollX,
591  endY * mTileHeight - scrollY,
593  }
594 
595  for (int y = startY; y < endY; y++)
596  {
597  const int yWidth = y * mWidth;
598  int tilePtr = startX + yWidth;
599  for (int x = startX; x < endX; x++, tilePtr++)
600  {
601  int width = 0;
602  const int x0 = x;
603 
610  }
611  }
612 }
const int mTileHeight
Definition: map.h:412
#define fillCollision(collision, color)
Definition: map.cpp:541
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:411
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:410
const int mWidth
Definition: map.h:409
static const int mapTileSize
Definition: map.h:26

◆ empty()

bool Map::empty ( ) const
inline

Definition at line 320 of file map.h.

References mLayers.

Referenced by SocialNavigationTab::updateList().

321  { return mLayers.empty(); }
Layers mLayers
Definition: map.h:416

◆ 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 858 of file map.cpp.

References BLOCK_END, BLOCK_START, MetaTile::blockmask, blockWalkMask, CAST_S32, 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().

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

1334 {
1335  FOR_EACH (STD_VECTOR<MapItem*>::const_iterator, it, mMapPortals)
1336  {
1337  if (*it == nullptr)
1338  continue;
1339 
1340  MapItem *restrict const item = *it;
1341  if (item->mX == x && item->mY == y)
1342  return item;
1343  }
1344  return nullptr;
1345 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
std::vector< MapItem * > mMapPortals
Definition: map.h:462
#define restrict
Definition: localconsts.h:164

◆ getActorsCount()

int Map::getActorsCount ( ) const
inline

Definition at line 286 of file map.h.

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

Referenced by MapDebugTab::logic().

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

◆ getAnimationForGid()

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

Gets the tile animation for a specific gid

Definition at line 1347 of file map.cpp.

References mTileAnimations.

Referenced by getPortals().

1348 {
1349  if (mTileAnimations.empty())
1350  return nullptr;
1351 
1352  const TileAnimationMapCIter i = mTileAnimations.find(gid);
1353  return (i == mTileAnimations.end()) ? nullptr : i->second;
1354 }
TileAnimationMap::const_iterator TileAnimationMapCIter
Definition: tileanimation.h:64
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:464

◆ getAtlasCount()

int Map::getAtlasCount ( ) const

Definition at line 1803 of file map.cpp.

References AtlasResource::atlases, CAST_S32, and mAtlas.

Referenced by getTileAnimations(), and MapDebugTab::logic().

1804 {
1805  if (mAtlas == nullptr)
1806  return 0;
1807  return CAST_S32(mAtlas->atlases.size());
1808 }
std::vector< TextureAtlas * > atlases
Definition: atlasresource.h:51
#define CAST_S32
Definition: cast.h:29
AtlasResource * mAtlas
Definition: map.h:494

◆ getBlockMask()

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

Definition at line 791 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().

793 {
794  // You can't walk outside of the map
795  if (x < 0 || y < 0 || x >= mWidth || y >= mHeight)
796  return 0;
797 
798  // Check if the tile is walkable
799  return mMetaTiles[x + y * mWidth].blockmask;
800 }
unsigned char blockmask
Definition: metatile.h:51
const int mHeight
Definition: map.h:410
MetaTile *const mMetaTiles
Definition: map.h:414
const int mWidth
Definition: map.h:409

◆ getCounterName()

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

Reimplemented from MemoryCounter.

Definition at line 372 of file map.h.

References mName.

373  { return mName; }
std::string mName
Definition: map.h:466

◆ getDrawLayersFlags()

MapTypeT Map::getDrawLayersFlags ( ) const
inline

Definition at line 230 of file map.h.

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

231  { return mDrawLayersFlags; }
MapTypeT mDrawLayersFlags
Definition: map.h:424

◆ getFilename()

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

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

Definition at line 843 of file map.cpp.

References fileName, and Properties::getProperty().

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

844 {
845  const std::string fileName = getProperty("_filename", std::string());
846  const size_t lastSlash = fileName.rfind('/') + 1;
847  return fileName.substr(lastSlash, fileName.rfind('.') - lastSlash);
848 }
std::string fileName
Definition: testmain.cpp:38
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 850 of file map.cpp.

References fileName, and Properties::getProperty().

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

851 {
852  const std::string fileName = getProperty("_filename", std::string());
853  const size_t lastSlash = fileName.rfind('/') + 1;
854  return fileName.substr(lastSlash,
855  fileName.rfind('.') - lastSlash).append(".gat");
856 }
std::string fileName
Definition: testmain.cpp:38
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 246 of file map.h.

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

Referenced by Being::drawPortalSpriteAt().

247  { return mHasWarps; }
bool mHasWarps
Definition: map.h:421

◆ getHeight()

int Map::getHeight ( ) const
inline

Returns the height of this map in tiles.

Definition at line 171 of file map.h.

References mHeight.

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

172  { return mHeight; }
const int mHeight
Definition: map.h:410

◆ getHeightOffset()

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

Definition at line 1626 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().

1627 {
1628  if (mHeights == nullptr)
1629  return 0;
1630  return mHeights->getHeight(x, y);
1631 }
const MapHeights * mHeights
Definition: map.h:497
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 812 of file map.cpp.

References mMetaTiles, mWidth, x, and y.

813 {
814  return &mMetaTiles[x + y * mWidth];
815 }
MetaTile *const mMetaTiles
Definition: map.h:414
const int mWidth
Definition: map.h:409

◆ getMetaTiles()

const MetaTile* Map::getMetaTiles ( ) const
inline

Definition at line 343 of file map.h.

References mMetaTiles.

Referenced by NavigationManager::loadWalkLayer().

344  { return mMetaTiles; }
MetaTile *const mMetaTiles
Definition: map.h:414

◆ getMusicFile()

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

Definition at line 830 of file map.cpp.

References Properties::getProperty().

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

831 {
832  return getProperty("music", std::string());
833 }
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 835 of file map.cpp.

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

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

836 {
837  if (hasProperty("name"))
838  return getProperty("name", std::string());
839 
840  return getProperty("mapname", std::string());
841 }
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 1388 of file map.cpp.

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

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

1390 {
1391  if (mObjects == nullptr)
1392  return "";
1393 
1394  MapObjectList *restrict const list = mObjects->getAt(x, y);
1395  if (list == nullptr)
1396  return "";
1397 
1398  STD_VECTOR<MapObject>::const_iterator it = list->objects.begin();
1399  const STD_VECTOR<MapObject>::const_iterator it_end = list->objects.end();
1400  while (it != it_end)
1401  {
1402  if ((*it).type == type)
1403  return (*it).data;
1404  ++ it;
1405  }
1406 
1407  return "";
1408 }
std::vector< MapObject > objects
Definition: mapobjectlist.h:42
ObjectsLayer * mObjects
Definition: map.h:480
MapObjectList * getAt(const unsigned x, const unsigned y) const
#define restrict
Definition: localconsts.h:164

◆ getObjectsLayer()

const ObjectsLayer* Map::getObjectsLayer ( ) const
inline

Definition at line 294 of file map.h.

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

296  { return mObjects; }
ObjectsLayer * mObjects
Definition: map.h:480

◆ getPortals()

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

Definition at line 270 of file map.h.

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

Referenced by SocialNavigationTab::updateList().

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

◆ getPvpMode()

int Map::getPvpMode ( ) const
inline

Definition at line 291 of file map.h.

References mPvp.

Referenced by ActorManager::findNearestPvpPlayer().

292  { return mPvp; }
int mPvp
Definition: map.h:470

◆ getSpecialLayer()

SpecialLayer* Map::getSpecialLayer ( ) const
inline

Definition at line 240 of file map.h.

References mSpecialLayer.

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

241  { return mSpecialLayer; }
SpecialLayer * mSpecialLayer
Definition: map.h:478

◆ getTempLayer()

SpecialLayer* Map::getTempLayer ( ) const
inline

Definition at line 237 of file map.h.

References mTempLayer.

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

238  { return mTempLayer; }
SpecialLayer * mTempLayer
Definition: map.h:479

◆ getTileAnimations()

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

Definition at line 329 of file map.h.

References A_WARN_UNUSED, getAtlasCount(), and mTileAnimations.

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

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

◆ 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 695 of file map.cpp.

References mIndexedTilesets, and mIndexedTilesetsSize.

Referenced by setTile().

696 {
697  if (gid >= 0 && gid < mIndexedTilesetsSize)
698  return mIndexedTilesets[gid];
699  return nullptr;
700 }
int mIndexedTilesetsSize
Definition: map.h:473
Tileset ** mIndexedTilesets
Definition: map.h:472

◆ getTileWidth()

int Map::getTileWidth ( ) const
inline

◆ getUserMapDirectory()

std::string Map::getUserMapDirectory ( ) const

Definition at line 1268 of file map.cpp.

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

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

1269 {
1271  getProperty("_realfilename", std::string()));
1272 }
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 309 of file map.h.

References mVersion.

Referenced by setTile().

310  { return mVersion; }
int mVersion
Definition: map.h:476

◆ 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 780 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().

782 {
783  // You can't walk outside of the map
784  if (x < 0 || y < 0 || x >= mWidth || y >= mHeight)
785  return false;
786 
787  // Check if the tile is walkable
788  return (mMetaTiles[x + y * mWidth].blockmask & blockWalkMask) == 0;
789 }
const int mHeight
Definition: map.h:410
MetaTile *const mMetaTiles
Definition: map.h:414
const int mWidth
Definition: map.h:409

◆ getWalkLayer()

const WalkLayer* Map::getWalkLayer ( ) const
inline

Definition at line 346 of file map.h.

References mWalkLayer.

Referenced by LocalPlayer::isReachable().

347  { return mWalkLayer; }
WalkLayer * mWalkLayer
Definition: map.h:415

◆ getWidth()

int Map::getWidth ( ) const
inline

Returns the width of this map in tiles.

Definition at line 165 of file map.h.

References mWidth.

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

166  { return mWidth; }
const int mWidth
Definition: map.h:409

◆ haveAtlas()

bool Map::haveAtlas ( ) const
inline

Definition at line 339 of file map.h.

References mAtlas.

Referenced by MapReader::readTileset().

340  { return mAtlas != nullptr; }
AtlasResource * mAtlas
Definition: map.h:494

◆ indexTilesets()

void Map::indexTilesets ( )

Definition at line 1410 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().

1411 {
1412  if (mTilesetsIndexed)
1413  return;
1414 
1415  mTilesetsIndexed = true;
1416 
1417  const Tileset *restrict s = nullptr;
1418  size_t sSz = 0;
1419  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1420  {
1421  const size_t sz = (*it)->size();
1422  if ((s == nullptr) || CAST_SIZE(s->getFirstGid()) + sSz
1423  < CAST_SIZE((*it)->getFirstGid()) + sz)
1424  {
1425  s = *it;
1426  sSz = sz;
1427  }
1428  }
1429  if (s == nullptr)
1430  {
1432  mIndexedTilesets = nullptr;
1433  return;
1434  }
1435 
1436  const int size = CAST_S32(s->getFirstGid())
1437  + CAST_S32(s->size());
1439  mIndexedTilesets = new Tileset*[CAST_SIZE(size)];
1440  std::fill_n(mIndexedTilesets, size, static_cast<Tileset*>(nullptr));
1441 
1442  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1443  {
1444  Tileset *restrict const s2 = *it;
1445  if (s2 != nullptr)
1446  {
1447  const int start = s2->getFirstGid();
1448  const int end = start + CAST_S32(s2->size());
1449  for (int f = start; f < end; f ++)
1450  {
1451  if (f < size)
1452  mIndexedTilesets[f] = s2;
1453  }
1454  }
1455  }
1456 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Tilesets mTilesets
Definition: map.h:419
bool mTilesetsIndexed
Definition: map.h:471
#define CAST_S32
Definition: cast.h:29
int mIndexedTilesetsSize
Definition: map.h:473
#define restrict
Definition: localconsts.h:164
#define CAST_SIZE
Definition: cast.h:33
Tileset ** mIndexedTilesets
Definition: map.h:472

◆ initializeAmbientLayers()

void Map::initializeAmbientLayers ( )

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

Definition at line 232 of file map.cpp.

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

Referenced by loadReplaceLayer().

233 {
234  // search for "foreground*" or "overlay*" (old term) in map properties
235  for (int i = 0; /* terminated by a break */; i++)
236  {
237  std::string name;
238  if (hasProperty(std::string("foreground").append(
239  toString(i)).append("image")))
240  {
241  name = "foreground" + toString(i);
242  }
243  else if (hasProperty(std::string("overlay").append(
244  toString(i)).append("image")))
245  {
246  name = "overlay" + toString(i);
247  }
248  else
249  {
250  break; // the FOR loop
251  }
252 
253  Image *restrict const img = Loader::getImage(
254  getProperty(name + "image", std::string()));
255  if (img != nullptr)
256  {
257  int mask = atoi(getProperty(name + "mask", std::string()).c_str());
258  if (mask == 0)
259  mask = 1;
260  const float parallax = getFloatProperty(name + "parallax", 0.0F);
261  mForegrounds.push_back(new AmbientLayer(
262  name,
263  img,
264  getFloatProperty(name + "parallaxX", parallax),
265  getFloatProperty(name + "parallaxY", parallax),
266  getFloatProperty(name + "posX", 0.0F),
267  getFloatProperty(name + "posY", 0.0F),
268  getFloatProperty(name + "scrollX", 0.0F),
269  getFloatProperty(name + "scrollY", 0.0F),
270  getBoolProperty(name + "keepratio", false),
271  mask));
272 
273  // The AmbientLayer takes control over the image.
274  img->decRef();
275  }
276  }
277 
278  // search for "background*" in map properties
279  for (int i = 0; hasProperty(std::string("background").append(
280  toString(i)).append("image")); i ++)
281  {
282  const std::string name("background" + toString(i));
283  Image *restrict const img = Loader::getImage(
284  getProperty(name + "image", std::string()));
285 
286  if (img != nullptr)
287  {
288  int mask = atoi(getProperty(name + "mask", std::string()).c_str());
289  if (mask == 0)
290  mask = 1;
291 
292  const float parallax = getFloatProperty(name + "parallax", 0.0F);
293  mBackgrounds.push_back(new AmbientLayer(
294  name,
295  img,
296  getFloatProperty(name + "parallaxX", parallax),
297  getFloatProperty(name + "parallaxY", parallax),
298  getFloatProperty(name + "posX", 0.0F),
299  getFloatProperty(name + "posY", 0.0F),
300  getFloatProperty(name + "scrollX", 0.0F),
301  getFloatProperty(name + "scrollY", 0.0F),
302  getBoolProperty(name + "keepratio", false),
303  mask));
304 
305  // The AmbientLayer takes control over the image.
306  img->decRef();
307  }
308  }
309 }
bool hasProperty(const std::string &name) const
Definition: properties.h:118
AmbientLayerVector mBackgrounds
Definition: map.h:431
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:432
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:164
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 1104 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().

1105 {
1106  BLOCK_START("Map::initializeParticleEffects")
1107  if (particleEngine == nullptr)
1108  {
1109  BLOCK_END("Map::initializeParticleEffects")
1110  return;
1111  }
1112 
1113  if (config.getBoolValue("particleeffects"))
1114  {
1115  for (STD_VECTOR<ParticleEffectData>::const_iterator
1116  i = mParticleEffects.begin();
1117  i != mParticleEffects.end();
1118  ++i)
1119  {
1120  // +++ add z for map particle effects?
1121  Particle *const p = particleEngine->addEffect(
1122  i->file,
1123  i->x,
1124  i->y,
1125  0);
1126  if ((p != nullptr) &&
1127  i->w > 0 &&
1128  i->h > 0)
1129  {
1130  p->adjustEmitterSize(i->w, i->h);
1131  }
1132  }
1133  }
1134  BLOCK_END("Map::initializeParticleEffects")
1135 }
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:460
void adjustEmitterSize(const int w, const int h)
Definition: particle.cpp:555

◆ isCustom()

bool Map::isCustom ( ) const
inline

Definition at line 326 of file map.h.

References mCustom.

Referenced by LocalPlayer::setRealPos().

327  { return mCustom; }
bool mCustom
Definition: map.h:501

◆ isHeightsPresent()

bool Map::isHeightsPresent ( ) const
inline

Definition at line 361 of file map.h.

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

Referenced by Viewport::getMouseTile().

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

◆ 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 209 of file map.cpp.

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

Referenced by getPortals().

210 {
211  if (value == "OverlayDetail")
212  {
213  mOverlayDetail = config.getIntValue("OverlayDetail");
214  }
215  else if (value == "guialpha")
216  {
217  mOpacity = config.getFloatValue("guialpha");
218  if (mOpacity != 1.0F)
219  mBeingOpacity = config.getBoolValue("beingopacity");
220  else
221  mBeingOpacity = false;
222  }
223  else if (value == "beingopacity")
224  {
225  if (mOpacity != 1.0F)
226  mBeingOpacity = config.getBoolValue("beingopacity");
227  else
228  mBeingOpacity = false;
229  }
230 }
Configuration config
int mOverlayDetail
Definition: map.h:467
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:468
bool mBeingOpacity
Definition: map.h:499

◆ preCacheLayers()

void Map::preCacheLayers ( )

Definition at line 1741 of file map.cpp.

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

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

1742 {
1744  {
1745  MapLayer *restrict const layer = *it;
1746  if (layer != nullptr)
1747  layer->updateCache(mWidth, mHeight);
1748  }
1749 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Layers mLayers
Definition: map.h:416
Layers::const_iterator LayersCIter
Definition: map.h:62
const int mHeight
Definition: map.h:410
const int mWidth
Definition: map.h:409
#define restrict
Definition: localconsts.h:164

◆ redrawMap()

void Map::redrawMap ( )
inline

Definition at line 317 of file map.h.

References mRedrawMap.

318  { mRedrawMap = true; }
bool mRedrawMap
Definition: map.h:498

◆ reduce()

void Map::reduce ( )

Definition at line 1468 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().

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

◆ removeActor()

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

Removes an actor from the map.

Definition at line 824 of file map.cpp.

References mActors.

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

825 {
826  mActors.erase(iterator);
827 // mSpritesUpdated = true;
828 }
Actors mActors
Definition: map.h:420

◆ saveExtraLayer()

void Map::saveExtraLayer ( ) const

Definition at line 1221 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().

1222 {
1223  if (mSpecialLayer == nullptr)
1224  {
1225  logger->log1("No special layer");
1226  return;
1227  }
1228  const std::string mapFileName = pathJoin(getUserMapDirectory(),
1229  "extralayer.txt");
1230  logger->log("saving extra layer: " + mapFileName);
1231 
1232  if (mkdir_r(getUserMapDirectory().c_str()) != 0)
1233  {
1234  logger->log(strprintf("%s doesn't exist and can't be created! "
1235  "Exiting.", getUserMapDirectory().c_str()));
1236  return;
1237  }
1238 
1239  std::ofstream mapFile;
1240  mapFile.open(mapFileName.c_str(), std::ios::binary);
1241  if (!mapFile.is_open())
1242  {
1243  reportAlways("Error opening file for writing: %s",
1244  mapFileName.c_str())
1245  return;
1246  }
1247 
1248  const int width = mSpecialLayer->mWidth;
1249  const int height = mSpecialLayer->mHeight;
1250 
1251  for (int x = 0; x < width; x ++)
1252  {
1253  for (int y = 0; y < height; y ++)
1254  {
1255  const MapItem *restrict const item = mSpecialLayer->getTile(x, y);
1256  if ((item != nullptr) && item->mType != MapItemType::EMPTY
1257  && item->mType != MapItemType::HOME)
1258  {
1259  mapFile << x << " " << y << " "
1260  << CAST_S32(item->mType) << " "
1261  << item->mComment << std::endl;
1262  }
1263  }
1264  }
1265  mapFile.close();
1266 }
void log1(const char *const log_text)
Definition: logger.cpp:233
std::string getUserMapDirectory() const
Definition: map.cpp:1268
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:478
Logger * logger
Definition: logger.cpp:88
#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:164
void log(const char *const log_text,...)
Definition: logger.cpp:264
#define reportAlways(...)
Definition: checkutils.h:252

◆ setActorsFix()

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

Definition at line 1719 of file map.cpp.

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

Referenced by getObjectsLayer(), and loadReplaceLayer().

1720 {
1721  mActorFixX = x;
1722  mActorFixY = y;
1723  if (mFringeLayer != nullptr)
1725 }
int mActorFixY
Definition: map.h:475
void setActorsFix(const int y)
Definition: maplayer.h:169
int mActorFixX
Definition: map.h:474
MapLayer * mFringeLayer
Definition: map.h:481

◆ setAtlas()

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

Definition at line 336 of file map.h.

References mAtlas.

Referenced by loadReplaceLayer().

337  { mAtlas = atlas; }
AtlasResource * mAtlas
Definition: map.h:494

◆ setBlockMask()

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

Definition at line 741 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().

743 {
744  if (type == BlockType::NONE || !contains(x, y))
745  return;
746 
747  const int tileNum = x + y * mWidth;
748 
749  switch (type)
750  {
751  case BlockType::WALL:
753  break;
754  case BlockType::AIR:
756  break;
757  case BlockType::WATER:
759  break;
760  case BlockType::GROUND:
762  break;
765  break;
768  break;
771  break;
772  default:
773  case BlockType::NONE:
775  // Do nothing.
776  break;
777  }
778 }
bool contains(const int x, const int y) const
Definition: map.cpp:807
unsigned char blockmask
Definition: metatile.h:51
MetaTile *const mMetaTiles
Definition: map.h:414
const int mWidth
Definition: map.h:409

◆ setCustom()

void Map::setCustom ( const bool  b)
inline

Definition at line 323 of file map.h.

References mCustom.

Referenced by MapReader::createEmptyMap().

324  { mCustom = b; }
bool mCustom
Definition: map.h:501

◆ setDrawLayersFlags()

void Map::setDrawLayersFlags ( const MapTypeT n)

Definition at line 1698 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().

1699 {
1700  mDrawLayersFlags = n;
1704  {
1705  mDrawOnlyFringe = true;
1706  }
1707  else
1708  {
1709  mDrawOnlyFringe = false;
1710  }
1712  FOR_EACH (Layers::iterator, it, mLayers)
1713  {
1714  MapLayer *restrict const layer = *it;
1715  layer->setDrawLayerFlags(mDrawLayersFlags);
1716  }
1717 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
bool mDrawOnlyFringe
Definition: map.h:502
void updateDrawLayersList()
Definition: map.cpp:1633
Layers mLayers
Definition: map.h:416
MapTypeT mDrawLayersFlags
Definition: map.h:424
#define restrict
Definition: localconsts.h:164

◆ setHasWarps()

void Map::setHasWarps ( const bool  n)
inline

Definition at line 243 of file map.h.

References mHasWarps.

244  { mHasWarps = n; }
bool mHasWarps
Definition: map.h:421

◆ setMask()

void Map::setMask ( const int  mask)

Definition at line 1671 of file map.cpp.

References mMask, mRedrawMap, and updateDrawLayersList().

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

1672 {
1673  if (mask != mMask)
1674  {
1675  mRedrawMap = true;
1676  mMask = mask;
1678  }
1679 }
void updateDrawLayersList()
Definition: map.cpp:1633
bool mRedrawMap
Definition: map.h:498
int mMask
Definition: map.h:492

◆ setMusicFile()

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

Definition at line 1681 of file map.cpp.

References Properties::setProperty().

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

1682 {
1683  setProperty("music", file);
1684 }
void setProperty(const std::string &name, const std::string &value)
Definition: properties.h:127

◆ setPvpMode()

void Map::setPvpMode ( const int  mode)

Definition at line 1356 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().

1357 {
1358  const int oldMode = mPvp;
1359 
1360  if (mode == 0)
1361  mPvp = 0;
1362  else
1363  mPvp |= mode;
1364 
1365  if (mPvp != oldMode && (localPlayer != nullptr))
1366  {
1367  switch (mPvp)
1368  {
1369  case 0:
1371  break;
1372  case 1:
1374  break;
1375  case 2:
1377  break;
1378  case 3:
1380  break;
1381  default:
1383  break;
1384  }
1385  }
1386 }
int mPvp
Definition: map.h:470
void notify(const unsigned int message)
LocalPlayer * localPlayer

◆ setVersion()

void Map::setVersion ( const int  n)
inline

Definition at line 312 of file map.h.

References mVersion, reduce(), and restrict2.

Referenced by loadReplaceLayer().

313  { mVersion = n; }
int mVersion
Definition: map.h:476

◆ setWalk()

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

Definition at line 802 of file map.cpp.

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

Referenced by LocalPlayer::setRealPos().

803 {
805 }
void addBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:702

◆ setWalkLayer()

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

Definition at line 349 of file map.h.

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

Referenced by loadReplaceLayer().

350  { mWalkLayer = layer; }
WalkLayer * mWalkLayer
Definition: map.h:415

◆ update()

void Map::update ( const int  ticks)

Updates animations. Called as needed.

Definition at line 326 of file map.cpp.

References FOR_EACH, mRedrawMap, mTileAnimations, and restrict.

Referenced by Game::logic().

327 {
328  // Update animated tiles
330  {
331  TileAnimation *restrict const tileAni = iAni->second;
332  if ((tileAni != nullptr) && tileAni->update(ticks))
333  mRedrawMap = true;
334  }
335 }
#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:464
bool mRedrawMap
Definition: map.h:498
#define restrict
Definition: localconsts.h:164

◆ 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 614 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().

616 {
617  BLOCK_START("Map::updateAmbientLayers")
618  static int lastTick = tick_time;
619 
620  if (mLastAScrollX == 0.0F && mLastAScrollY == 0.0F)
621  {
622  // First call - initialisation
623  mLastAScrollX = scrollX;
624  mLastAScrollY = scrollY;
625  }
626 
627  // Update Overlays
628  const float dx = scrollX - mLastAScrollX;
629  const float dy = scrollY - mLastAScrollY;
630  const int timePassed = get_elapsed_time(lastTick);
631 
632  // need check mask to update or not to update
633 
635  {
636  AmbientLayer *const layer = *i;
637  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
638  layer->update(timePassed, dx, dy);
639  }
640 
642  {
643  AmbientLayer *const layer = *i;
644  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
645  layer->update(timePassed, dx, dy);
646  }
647 
648  mLastAScrollX = scrollX;
649  mLastAScrollY = scrollY;
650  lastTick = tick_time;
651  BLOCK_END("Map::updateAmbientLayers")
652 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
volatile int tick_time
Definition: timer.cpp:52
AmbientLayerVector mBackgrounds
Definition: map.h:431
#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:433
void update(const int timePassed, const float dx, const float dy)
AmbientLayerVector mForegrounds
Definition: map.h:432
float mLastAScrollY
Definition: map.h:434
AmbientLayerVector::iterator AmbientLayerVectorIter
Definition: map.h:66
int mMask
Definition: map.h:492

◆ updateConditionLayers()

void Map::updateConditionLayers ( )

Definition at line 1727 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().

1728 {
1729  mRedrawMap = true;
1730 
1732  {
1733  MapLayer *restrict const layer = *it;
1734  if ((layer == nullptr) || layer->mTileCondition == -1)
1735  continue;
1736  layer->updateConditionTiles(mMetaTiles,
1737  mWidth, mHeight);
1738  }
1739 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Layers mLayers
Definition: map.h:416
Layers::const_iterator LayersCIter
Definition: map.h:62
bool mRedrawMap
Definition: map.h:498
const int mHeight
Definition: map.h:410
MetaTile *const mMetaTiles
Definition: map.h:414
const int mWidth
Definition: map.h:409
#define restrict
Definition: localconsts.h:164

◆ updateDrawLayersList()

void Map::updateDrawLayersList ( )

Definition at line 1633 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().

1634 {
1635  mDrawUnderLayers.clear();
1636  mDrawOverLayers.clear();
1637 
1638  if (mDrawOnlyFringe)
1639  return;
1640 
1641  LayersCIter layers = mLayers.begin();
1642  const LayersCIter layers_end = mLayers.end();
1643  for (; layers != layers_end; ++ layers)
1644  {
1645  MapLayer *const layer = *layers;
1646  if ((layer->mMask & mMask) == 0)
1647  continue;
1648 
1649  if (layer->isFringeLayer())
1650  {
1651  ++ layers;
1652  break;
1653  }
1654 
1655  mDrawUnderLayers.push_back(layer);
1656  }
1657 
1659  return;
1660 
1661  for (; layers != layers_end; ++ layers)
1662  {
1663  MapLayer *const layer = *layers;
1664  if ((layer->mMask & mMask) == 0)
1665  continue;
1666 
1667  mDrawOverLayers.push_back(layer);
1668  }
1669 }
bool mDrawOnlyFringe
Definition: map.h:502
Layers mLayers
Definition: map.h:416
Layers::const_iterator LayersCIter
Definition: map.h:62
MapTypeT mDrawLayersFlags
Definition: map.h:424
Layers mDrawUnderLayers
Definition: map.h:417
Layers mDrawOverLayers
Definition: map.h:418
int mMask
Definition: maplayer.h:233
int mMask
Definition: map.h:492
bool isFringeLayer() const
Definition: maplayer.h:140

◆ updatePortalTile()

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

Definition at line 1308 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().

1312 {
1314  if (item != nullptr)
1315  {
1316  item->mComment = name;
1317  item->setType(type);
1318  item->mX = x;
1319  item->mY = y;
1320  if (mSpecialLayer != nullptr)
1321  {
1322  item = new MapItem(type, name, x, y);
1323  mSpecialLayer->setTile(x, y, item);
1325  }
1326  }
1327  else if (addNew)
1328  {
1329  addPortalTile(name, type, x, y);
1330  }
1331 }
SpecialLayer * mSpecialLayer
Definition: map.h:478
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:1295
void updateCache()
MapItem * findPortalXY(const int x, const int y) const
Definition: map.cpp:1333
#define restrict
Definition: localconsts.h:164

Friends And Related Function Documentation

◆ Actor

friend class Actor
friend

Definition at line 376 of file map.h.

◆ Minimap

friend class Minimap
friend

Definition at line 377 of file map.h.

Field Documentation

◆ mActorFixX

int Map::mActorFixX
private

Definition at line 474 of file map.h.

Referenced by setActorsFix().

◆ mActorFixY

int Map::mActorFixY
private

Definition at line 475 of file map.h.

Referenced by setActorsFix().

◆ mActors

Actors Map::mActors
private

Definition at line 420 of file map.h.

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

◆ mAtlas

AtlasResource* Map::mAtlas
private

Definition at line 494 of file map.h.

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

◆ mBackgrounds

AmbientLayerVector Map::mBackgrounds
private

◆ mBeingOpacity

bool Map::mBeingOpacity
private

Definition at line 499 of file map.h.

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

◆ mCachedDraw

bool Map::mCachedDraw
private

Definition at line 500 of file map.h.

Referenced by draw().

◆ mCustom

bool Map::mCustom
private

Definition at line 501 of file map.h.

Referenced by isCustom(), and setCustom().

◆ mDrawLayersFlags

MapTypeT Map::mDrawLayersFlags
private

Definition at line 424 of file map.h.

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

◆ mDrawOnlyFringe

bool Map::mDrawOnlyFringe
private

Definition at line 502 of file map.h.

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

◆ mDrawOverLayers

Layers Map::mDrawOverLayers
private

Definition at line 418 of file map.h.

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

◆ mDrawScrollX

int Map::mDrawScrollX
private

Definition at line 490 of file map.h.

Referenced by draw().

◆ mDrawScrollY

int Map::mDrawScrollY
private

Definition at line 491 of file map.h.

Referenced by draw().

◆ mDrawUnderLayers

Layers Map::mDrawUnderLayers
private

Definition at line 417 of file map.h.

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

◆ mDrawX

int Map::mDrawX
private

Definition at line 488 of file map.h.

Referenced by draw().

◆ mDrawY

int Map::mDrawY
private

Definition at line 489 of file map.h.

Referenced by draw().

◆ mForegrounds

AmbientLayerVector Map::mForegrounds
private

◆ mFringeLayer

MapLayer* Map::mFringeLayer
private

Definition at line 481 of file map.h.

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

◆ mHasWarps

bool Map::mHasWarps
private

Definition at line 421 of file map.h.

Referenced by getHasWarps(), and setHasWarps().

◆ mHeight

const int Map::mHeight
private

◆ mHeights

const MapHeights* Map::mHeights
private

Definition at line 497 of file map.h.

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

◆ mIndexedTilesets

Tileset** Map::mIndexedTilesets
private

Definition at line 472 of file map.h.

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

◆ mIndexedTilesetsSize

int Map::mIndexedTilesetsSize
private

Definition at line 473 of file map.h.

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

◆ mLastAScrollX

float Map::mLastAScrollX
private

Definition at line 433 of file map.h.

Referenced by updateAmbientLayers().

◆ mLastAScrollY

float Map::mLastAScrollY
private

Definition at line 434 of file map.h.

Referenced by updateAmbientLayers().

◆ mLastScrollX

int Map::mLastScrollX
private

Definition at line 485 of file map.h.

Referenced by draw().

◆ mLastScrollY

int Map::mLastScrollY
private

Definition at line 486 of file map.h.

Referenced by draw().

◆ mLastX

int Map::mLastX
private

Definition at line 483 of file map.h.

Referenced by draw().

◆ mLastY

int Map::mLastY
private

Definition at line 484 of file map.h.

Referenced by draw().

◆ mLayers

Layers Map::mLayers
private

◆ mMapPortals

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

Definition at line 462 of file map.h.

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

◆ mMask

int Map::mMask
private

Definition at line 492 of file map.h.

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

◆ mMaxTileHeight

int Map::mMaxTileHeight
private

Definition at line 413 of file map.h.

Referenced by addTileset(), and draw().

◆ mMetaTiles

MetaTile* const Map::mMetaTiles
private

◆ mName

std::string Map::mName
private

Definition at line 466 of file map.h.

Referenced by calcMemoryLocal(), and getCounterName().

◆ mObjects

ObjectsLayer* Map::mObjects
private

Definition at line 480 of file map.h.

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

◆ mOnClosedList

unsigned int Map::mOnClosedList
private

Definition at line 427 of file map.h.

Referenced by findPath().

◆ mOnOpenList

unsigned int Map::mOnOpenList
private

Definition at line 428 of file map.h.

Referenced by findPath().

◆ mOpacity

float Map::mOpacity
private

Definition at line 468 of file map.h.

Referenced by Map(), and optionChanged().

◆ mOpenGL

const RenderType Map::mOpenGL
private

Definition at line 469 of file map.h.

Referenced by draw(), and reduce().

◆ mOverlayDetail

int Map::mOverlayDetail
private

Definition at line 467 of file map.h.

Referenced by draw(), and optionChanged().

◆ mParticleEffects

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

Definition at line 460 of file map.h.

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

◆ mPvp

int Map::mPvp
private

Definition at line 470 of file map.h.

Referenced by getPvpMode(), and setPvpMode().

◆ mRedrawMap

bool Map::mRedrawMap
private

Definition at line 498 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 479 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 412 of file map.h.

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

◆ mTilesets

Tilesets Map::mTilesets
private

Definition at line 419 of file map.h.

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

◆ mTilesetsIndexed

bool Map::mTilesetsIndexed
private

Definition at line 471 of file map.h.

Referenced by clearIndexedTilesets(), and indexTilesets().

◆ mTileWidth

const int Map::mTileWidth
private

Definition at line 411 of file map.h.

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

◆ mVersion

int Map::mVersion
private

Definition at line 476 of file map.h.

Referenced by getVersion(), and setVersion().

◆ mWalkLayer

WalkLayer* Map::mWalkLayer
private

Definition at line 415 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: