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
 
void screenResized ()
 
- 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
 
bool mClear
 

Friends

class Actor
 
class Minimap
 

Detailed Description

A tile map.

Definition at line 72 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 97 of file map.cpp.

101  :
102  Properties(),
103  mWidth(width), mHeight(height),
104  mTileWidth(tileWidth), mTileHeight(tileHeight),
105  mMaxTileHeight(height),
107  mWalkLayer(nullptr),
108  mLayers(),
110  mDrawOverLayers(),
111  mTilesets(),
112  mActors(),
113  mHasWarps(false),
115  mOnClosedList(1),
116  mOnOpenList(2),
117  mBackgrounds(),
118  mForegrounds(),
119  mLastAScrollX(0.0F),
120  mLastAScrollY(0.0F),
122  mMapPortals(),
123  mTileAnimations(),
124  mName(name),
125  mOverlayDetail(config.getIntValue("OverlayDetail")),
126  mOpacity(config.getFloatValue("guialpha")),
127 #ifdef USE_OPENGL
129 #else // USE_OPENGL
131 #endif // USE_OPENGL
132  mPvp(0),
133  mTilesetsIndexed(false),
134  mIndexedTilesets(nullptr),
136  mActorFixX(0),
137  mActorFixY(0),
138  mVersion(0),
139  mSpecialLayer(new SpecialLayer("special layer", width, height)),
140  mTempLayer(new SpecialLayer("temp layer", width, height)),
141  mObjects(new ObjectsLayer(width, height)),
142  mFringeLayer(nullptr),
143  mLastX(-1),
144  mLastY(-1),
145  mLastScrollX(-1),
146  mLastScrollY(-1),
147  mDrawX(-1),
148  mDrawY(-1),
149  mDrawScrollX(-1),
150  mDrawScrollY(-1),
151  mMask(1),
152 #ifdef USE_OPENGL
153  mAtlas(nullptr),
154 #endif // USE_OPENGL
155  mHeights(nullptr),
156  mRedrawMap(true),
157  mBeingOpacity(false),
158 #ifdef USE_OPENGL
163 #else // USE_OPENGL
164  mCachedDraw(false),
165 #endif // USE_OPENGL
166  mCustom(false),
167  mDrawOnlyFringe(false),
168  mClear(false)
169 {
170  config.addListener("OverlayDetail", this);
171  config.addListener("guialpha", this);
172  config.addListener("beingopacity", this);
173 
174  if (mOpacity != 1.0F)
175  mBeingOpacity = config.getBoolValue("beingopacity");
176  else
177  mBeingOpacity = false;
178 }
bool getBoolValue(const std::string &key) const
float getFloatValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
int getIntValue(const std::string &key) const
const RenderType mOpenGL
Definition: map.h:472
Layers mLayers
Definition: map.h:419
const int mHeight
Definition: map.h:413
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:467
const MapHeights * mHeights
Definition: map.h:500
int mDrawScrollY
Definition: map.h:494
bool mCustom
Definition: map.h:504
float mOpacity
Definition: map.h:471
bool mRedrawMap
Definition: map.h:501
unsigned int mOnClosedList
Definition: map.h:430
int mMaxTileHeight
Definition: map.h:416
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:463
float mLastAScrollX
Definition: map.h:436
bool mHasWarps
Definition: map.h:424
WalkLayer * mWalkLayer
Definition: map.h:418
Layers mDrawUnderLayers
Definition: map.h:420
int mLastX
Definition: map.h:486
bool mDrawOnlyFringe
Definition: map.h:505
AtlasResource * mAtlas
Definition: map.h:497
const int mTileWidth
Definition: map.h:414
SpecialLayer * mTempLayer
Definition: map.h:482
bool mBeingOpacity
Definition: map.h:502
std::vector< MapItem * > mMapPortals
Definition: map.h:465
bool mClear
Definition: map.h:506
MetaTile *const mMetaTiles
Definition: map.h:417
int mVersion
Definition: map.h:479
Tilesets mTilesets
Definition: map.h:422
MapLayer * mFringeLayer
Definition: map.h:484
Actors mActors
Definition: map.h:423
float mLastAScrollY
Definition: map.h:437
int mDrawScrollX
Definition: map.h:493
unsigned int mOnOpenList
Definition: map.h:431
int mActorFixX
Definition: map.h:477
const int mTileHeight
Definition: map.h:415
Tileset ** mIndexedTilesets
Definition: map.h:475
ObjectsLayer * mObjects
Definition: map.h:483
int mLastScrollY
Definition: map.h:489
SpecialLayer * mSpecialLayer
Definition: map.h:481
int mDrawY
Definition: map.h:492
int mMask
Definition: map.h:495
int mLastY
Definition: map.h:487
int mIndexedTilesetsSize
Definition: map.h:476
int mPvp
Definition: map.h:473
int mDrawX
Definition: map.h:491
AmbientLayerVector mBackgrounds
Definition: map.h:434
int mActorFixY
Definition: map.h:478
bool mTilesetsIndexed
Definition: map.h:474
const int mWidth
Definition: map.h:412
bool mCachedDraw
Definition: map.h:503
int mOverlayDetail
Definition: map.h:470
Layers mDrawOverLayers
Definition: map.h:421
AmbientLayerVector mForegrounds
Definition: map.h:435
std::string mName
Definition: map.h:469
int mLastScrollX
Definition: map.h:488
MapTypeT mDrawLayersFlags
Definition: map.h:427
Configuration config
@ NORMAL
Definition: maptype.h:31
RenderType intToRenderType(const int mode)
Definition: renderers.cpp:43
@ RENDER_GLES2_OPENGL
Definition: rendertype.h:33
@ RENDER_GLES_OPENGL
Definition: rendertype.h:30
@ RENDER_MODERN_OPENGL
Definition: rendertype.h:32
@ RENDER_NORMAL_OPENGL
Definition: rendertype.h:28
@ RENDER_SOFTWARE
Definition: rendertype.h:27

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

Referenced by calcMemoryLocal().

◆ ~Map()

Map::~Map ( )

Destructor.

Definition at line 180 of file map.cpp.

181 {
182  config.removeListeners(this);
184 
185  if (mWalkLayer != nullptr)
186  {
187  mWalkLayer->decRef();
188  mWalkLayer = nullptr;
189  }
190  mFringeLayer = nullptr;
200 #ifdef USE_OPENGL
201  if (mAtlas != nullptr)
202  {
203  mAtlas->decRef();
204  mAtlas = nullptr;
205  }
206 #endif // USE_OPENGL
208  delete [] mMetaTiles;
209 }
void removeListeners(ConfigListener *const listener)
virtual void decRef()
Definition: resource.cpp:50
#define delete2(var)
Definition: delete2.h:25
void delete_all(Container &c)
Definition: dtor.h:56
#define CHECKLISTENERS
Definition: localconsts.h:277

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

Member Function Documentation

◆ addActor()

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

Adds an actor to the map.

Definition at line 822 of file map.cpp.

823 {
824  mActors.push_front(actor);
825 // mSpritesUpdated = true;
826  return mActors.begin();
827 }

Referenced by Actor::setMap().

◆ addAnimation()

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

Adds a tile animation to the map

Definition at line 1691 of file map.cpp.

1693 {
1694  std::map<int, TileAnimation*>::iterator it = mTileAnimations.find(gid);
1695  if (it != mTileAnimations.end())
1696  {
1697  logger->log("duplicate map animation with gid = %d", gid);
1698  delete (*it).second;
1699  }
1700  mTileAnimations[gid] = animation;
1701 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89

References Logger::log(), and logger.

Referenced by MapReader::readTileset().

◆ addBlockMask()

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

Definition at line 707 of file map.cpp.

709 {
710  if (type == BlockType::NONE || !contains(x, y))
711  return;
712 
713  const int tileNum = x + y * mWidth;
714 
715  switch (type)
716  {
717  case BlockType::WALL:
719  break;
720  case BlockType::AIR:
721  mMetaTiles[tileNum].blockmask |= BlockMask::AIR;
722  break;
723  case BlockType::WATER:
725  break;
726  case BlockType::GROUND:
728  break;
731  break;
734  break;
737  break;
738  default:
739  case BlockType::NONE:
741  // Do nothing.
742  break;
743  }
744 }
bool contains(const int x, const int y) const
Definition: map.cpp:812
@ PLAYERWALL
Definition: blockmask.h:36
@ MONSTERWALL
Definition: blockmask.h:37
@ GROUNDTOP
Definition: blockmask.h:35
@ PLAYERWALL
Definition: blocktype.h:37
@ NB_BLOCKTYPES
Definition: blocktype.h:39
@ MONSTERWALL
Definition: blocktype.h:38
@ GROUNDTOP
Definition: blocktype.h:36
unsigned char blockmask
Definition: metatile.h:52

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

Referenced by setTile().

◆ addExtraLayer()

void Map::addExtraLayer ( )

Definition at line 1142 of file map.cpp.

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

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

Referenced by Game::changeMap().

◆ addHeights()

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

Definition at line 1625 of file map.cpp.

1626 {
1627  delete mHeights;
1628  mHeights = heights;
1629 }

Referenced by MapReader::readLayer().

◆ addLayer()

void Map::addLayer ( MapLayer *const  layer)

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

Definition at line 313 of file map.cpp.

314 {
315  mLayers.push_back(layer);
316  if (layer->isFringeLayer() && (mFringeLayer == nullptr))
317  mFringeLayer = layer;
318 }
bool isFringeLayer() const
Definition: maplayer.h:141

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

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

1104 {
1105  ParticleEffectData newEffect(effectFile, x, y, w, h);
1106  mParticleEffects.push_back(newEffect);
1107 }

References x, and y.

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

1295 {
1296  addPortalTile(name, type, (x / mapTileSize) + (dx / mapTileSize / 2),
1297  (y / mapTileSize) + (dy / mapTileSize / 2));
1298 }
static const int mapTileSize
Definition: map.h:27

References mapTileSize, x, and y.

◆ addPortalTile()

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

Definition at line 1300 of file map.cpp.

1303 {
1304  if (mSpecialLayer != nullptr)
1305  {
1306  mSpecialLayer->setTile(x, y, new MapItem(type, name, x, y));
1308  }
1309 
1310  mMapPortals.push_back(new MapItem(type, name, x, y));
1311 }
void setTile(const int x, const int y, MapItem *const item)
void updateCache()

References x, and y.

Referenced by addExtraLayer(), Ea::BeingRecv::processNameResponse(), EAthena::BeingRecv::processNameResponseTitle(), and LocalPlayer::updateNavigateList().

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

1283 {
1284  if (mObjects == nullptr)
1285  return;
1286 
1287  mObjects->addObject(name, type, x / mapTileSize, y / mapTileSize,
1288  dx / mapTileSize, dy / mapTileSize);
1289 }
void addObject(const std::string &name, const int type, const unsigned x, const unsigned y, unsigned dx, unsigned dy)

References mapTileSize, x, and y.

◆ addTileset()

void Map::addTileset ( Tileset *const  tileset)

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

Definition at line 320 of file map.cpp.

321 {
322  mTilesets.push_back(tileset);
323  const int height = tileset->getHeight();
324  if (height > mMaxTileHeight)
325  mMaxTileHeight = height;
326 }
int getHeight() const
Definition: imageset.h:66

◆ calcMemoryChilds()

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

Reimplemented from MemoryCounter.

Definition at line 1774 of file map.cpp.

1775 {
1776  int sz = 0;
1777 
1778  if (mWalkLayer != nullptr)
1779  sz += mWalkLayer->calcMemory(level + 1);
1781  {
1782  sz += (*it)->calcMemory(level + 1);
1783  }
1784  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1785  {
1786  sz += (*it)->calcMemory(level + 1);
1787  }
1789  {
1790  sz += (*it)->calcMemory(level + 1);
1791  }
1793  {
1794  sz += (*it)->calcMemory(level + 1);
1795  }
1796  if (mSpecialLayer != nullptr)
1797  mSpecialLayer->calcMemory(level + 1);
1798  if (mTempLayer != nullptr)
1799  mTempLayer->calcMemory(level + 1);
1800  if (mObjects != nullptr)
1801  mObjects->calcMemory(level + 1);
1802  if (mHeights != nullptr)
1803  mHeights->calcMemory(level + 1);
1804  return sz;
1805 }
int calcMemory(const int level) const
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
Layers::const_iterator LayersCIter
Definition: map.h:63
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:66

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

◆ calcMemoryLocal()

int Map::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 1756 of file map.cpp.

1757 {
1758  return static_cast<int>(sizeof(Map) +
1759  mName.capacity() +
1760  sizeof(MetaTile) * mWidth * mHeight +
1761  sizeof(MapLayer*) * (mLayers.capacity() +
1762  mDrawUnderLayers.capacity() +
1763  mDrawOverLayers.capacity()) +
1764  sizeof(Tileset*) * mTilesets.capacity() +
1765  sizeof(Actor*) * mActors.size() +
1766  sizeof(AmbientLayer*) * (mBackgrounds.capacity()
1767  + mForegrounds.capacity()) +
1768  sizeof(ParticleEffectData) * mParticleEffects.capacity() +
1769  sizeof(MapItem) * mMapPortals.capacity() +
1770  (sizeof(TileAnimation) + sizeof(int)) * mTileAnimations.size() +
1771  sizeof(Tileset*) * mIndexedTilesetsSize);
1772 }
Definition: actor.h:42
Map(const std::string &name, const int width, const int height, const int tileWidth, const int tileHeight)
Definition: map.cpp:97

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

◆ clearIndexedTilesets()

void Map::clearIndexedTilesets ( )

Definition at line 1463 of file map.cpp.

1464 {
1465  if (!mTilesetsIndexed)
1466  return;
1467 
1468  mTilesetsIndexed = false;
1469  delete [] mIndexedTilesets;
1471 }

References mIndexedTilesets, mIndexedTilesetsSize, and mTilesetsIndexed.

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

813 {
814  return x >= 0 && y >= 0 && x < mWidth && y < mHeight;
815 }

References x, and y.

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

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

References actorCompare, MapLayerPosition::BACKGROUND_LAYERS, MapType::BLACKWHITE, BLOCK_END, BLOCK_START, Graphics::clearScreen(), FOR_EACH, MapLayerPosition::FOREGROUND_LAYERS, UserPalette::getColorWithAlpha(), localPlayer, mainGraphics, RENDER_SOFTWARE, restrict, userPalette, UserColorId::WALKABLE_HIGHLIGHT, x, and y.

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

662 {
663  BLOCK_START("Map::drawAmbientLayers")
664  // Detail 0 = no ambient effects except background image
665  if (detail <= 0 && type != MapLayerPosition::BACKGROUND_LAYERS)
666  {
667  BLOCK_END("Map::drawAmbientLayers")
668  return;
669  }
670 
671  // find out which layer list to draw
672  const AmbientLayerVector *restrict layers = nullptr;
673  switch (type)
674  {
676  layers = &mForegrounds;
677  break;
679  layers = &mBackgrounds;
680  break;
681  default:
682  return;
683  }
684 
685  // Draw overlays
687  {
688  const AmbientLayer *restrict const layer = *i;
689  // need check mask to draw or not to draw
690  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
691  (layer)->draw(graphics, graphics->mWidth, graphics->mHeight);
692 
693  // Detail 1: only one overlay, higher: all overlays
694  if (detail == 1)
695  break;
696  }
697  BLOCK_END("Map::drawAmbientLayers")
698 }
int mWidth
Definition: graphics.h:484
int mHeight
Definition: graphics.h:485
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:31
std::vector< AmbientLayer * > AmbientLayerVector
Definition: map.h:65

References MapLayerPosition::BACKGROUND_LAYERS, BLOCK_END, BLOCK_START, FOR_EACHP, MapLayerPosition::FOREGROUND_LAYERS, and restrict.

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

573 {
574  const int endPixelY = graphics->mHeight + scrollY + mTileHeight - 1;
575  int startX = scrollX / mTileWidth;
576  int startY = scrollY / mTileHeight;
577  int endX = (graphics->mWidth + scrollX + mTileWidth - 1) / mTileWidth;
578  int endY = endPixelY / mTileHeight;
579 
580  if (startX < 0)
581  startX = 0;
582  if (startY < 0)
583  startY = 0;
584  if (endX > mWidth)
585  endX = mWidth;
586  if (endY > mHeight)
587  endY = mHeight;
588 
589  if (drawFlags < MapType::SPECIAL)
590  {
592  graphics->drawNet(
593  startX * mTileWidth - scrollX,
594  startY * mTileHeight - scrollY,
595  endX * mTileWidth - scrollX,
596  endY * mTileHeight - scrollY,
598  }
599 
600  for (int y = startY; y < endY; y++)
601  {
602  const int yWidth = y * mWidth;
603  int tilePtr = startX + yWidth;
604  for (int x = startX; x < endX; x++, tilePtr++)
605  {
606  int width = 0;
607  const int x0 = x;
608 
615  }
616  }
617 }
virtual void setColor(const Color &color)
Definition: graphics.h:320
virtual void drawNet(const int x1, const int y1, const int x2, const int y2, const int width, const int height)
Definition: graphics.cpp:653
#define fillCollision(collision, color)
Definition: map.cpp:546
@ SPECIAL
Definition: maptype.h:33
@ AIR_COLLISION_HIGHLIGHT
Definition: usercolorid.h:81
@ MONSTER_COLLISION_HIGHLIGHT
Definition: usercolorid.h:83
@ GROUNDTOP_COLLISION_HIGHLIGHT
Definition: usercolorid.h:84
@ COLLISION_HIGHLIGHT
Definition: usercolorid.h:80
@ WATER_COLLISION_HIGHLIGHT
Definition: usercolorid.h:82

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

◆ empty()

bool Map::empty ( ) const
inline

Definition at line 321 of file map.h.

322  { return mLayers.empty(); }

References mLayers.

Referenced by SocialNavigationTab::updateList().

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

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

References BLOCK_END, BLOCK_START, MetaTile::blockmask, blockWalkMask, CAST_S32, MetaTile::Fcost, MetaTile::Gcost, MetaTile::Hcost, MetaTile::parentX, MetaTile::parentY, CastType::Position, EmoteDB::size(), Location::tile, BlockMask::WALL, MetaTile::whichList, x, Location::x, y, and Location::y.

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

◆ findPortalXY()

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

Definition at line 1338 of file map.cpp.

1339 {
1340  FOR_EACH (STD_VECTOR<MapItem*>::const_iterator, it, mMapPortals)
1341  {
1342  if (*it == nullptr)
1343  continue;
1344 
1345  MapItem *restrict const item = *it;
1346  if (item->mX == x && item->mY == y)
1347  return item;
1348  }
1349  return nullptr;
1350 }

References FOR_EACH, restrict, x, and y.

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

◆ getActorsCount()

int Map::getActorsCount ( ) const
inline

Definition at line 287 of file map.h.

288  { return CAST_S32(mActors.size()); }

References CAST_S32, and mActors.

Referenced by MapDebugTab::logic().

◆ getAnimationForGid()

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

Gets the tile animation for a specific gid

Definition at line 1352 of file map.cpp.

1353 {
1354  if (mTileAnimations.empty())
1355  return nullptr;
1356 
1357  const TileAnimationMapCIter i = mTileAnimations.find(gid);
1358  return (i == mTileAnimations.end()) ? nullptr : i->second;
1359 }
#define nullptr
Definition: localconsts.h:45
TileAnimationMap::const_iterator TileAnimationMapCIter
Definition: tileanimation.h:65

References nullptr.

◆ getAtlasCount()

int Map::getAtlasCount ( ) const

Definition at line 1821 of file map.cpp.

1822 {
1823  if (mAtlas == nullptr)
1824  return 0;
1825  return CAST_S32(mAtlas->atlases.size());
1826 }
std::vector< TextureAtlas * > atlases
Definition: atlasresource.h:52

References AtlasResource::atlases, CAST_S32, and mAtlas.

Referenced by MapDebugTab::logic().

◆ getBlockMask()

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

Definition at line 796 of file map.cpp.

798 {
799  // You can't walk outside of the map
800  if (x < 0 || y < 0 || x >= mWidth || y >= mHeight)
801  return 0;
802 
803  // Check if the tile is walkable
804  return mMetaTiles[x + y * mWidth].blockmask;
805 }

References x, and y.

Referenced by Being::getMoveAction(), Being::getSitAction(), and Being::nextTile().

◆ getCounterName()

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

Reimplemented from MemoryCounter.

Definition at line 373 of file map.h.

374  { return mName; }

References mName.

◆ getDrawLayersFlags()

MapTypeT Map::getDrawLayersFlags ( ) const
inline

Definition at line 231 of file map.h.

232  { return mDrawLayersFlags; }

References mDrawLayersFlags.

◆ getFilename()

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

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

Definition at line 848 of file map.cpp.

849 {
850  const std::string fileName = getProperty("_filename", std::string());
851  const size_t lastSlash = fileName.rfind('/') + 1;
852  return fileName.substr(lastSlash, fileName.rfind('.') - lastSlash);
853 }
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:59
std::string fileName
Definition: testmain.cpp:39

References fileName, and Properties::getProperty().

Referenced by Minimap::setMap().

◆ getGatName()

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

Definition at line 855 of file map.cpp.

856 {
857  const std::string fileName = getProperty("_filename", std::string());
858  const size_t lastSlash = rfindSepatator(fileName) + 1;
859  return fileName.substr(lastSlash,
860  fileName.rfind('.') - lastSlash).append(".gat");
861 }
size_t rfindSepatator(const std::string &str1)

References fileName, Properties::getProperty(), and rfindSepatator().

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

◆ getHasWarps()

bool Map::getHasWarps ( ) const
inline

Definition at line 247 of file map.h.

248  { return mHasWarps; }

References mHasWarps.

◆ getHeight()

int Map::getHeight ( ) const
inline

Returns the height of this map in tiles.

Definition at line 172 of file map.h.

173  { return mHeight; }

References mHeight.

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

◆ getHeightOffset()

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

Definition at line 1631 of file map.cpp.

1632 {
1633  if (mHeights == nullptr)
1634  return 0;
1635  return mHeights->getHeight(x, y);
1636 }
uint8_t getHeight(const int x, const int y) const
Definition: mapheights.h:44

References x, and y.

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

◆ getMetaTile()

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

Get tile reference.

Definition at line 817 of file map.cpp.

818 {
819  return &mMetaTiles[x + y * mWidth];
820 }

References x, and y.

◆ getMetaTiles()

const MetaTile* Map::getMetaTiles ( ) const
inline

Definition at line 344 of file map.h.

345  { return mMetaTiles; }

References mMetaTiles.

Referenced by NavigationManager::loadWalkLayer().

◆ getMusicFile()

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

Definition at line 835 of file map.cpp.

836 {
837  return getProperty("music", std::string());
838 }

References Properties::getProperty().

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

◆ getName()

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

Definition at line 840 of file map.cpp.

841 {
842  if (hasProperty("name"))
843  return getProperty("name", std::string());
844 
845  return getProperty("mapname", std::string());
846 }
bool hasProperty(const std::string &name) const
Definition: properties.h:119

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

Referenced by Minimap::setMap().

◆ getObjectData()

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

Definition at line 1393 of file map.cpp.

1395 {
1396  if (mObjects == nullptr)
1397  return "";
1398 
1399  MapObjectList *restrict const list = mObjects->getAt(x, y);
1400  if (list == nullptr)
1401  return "";
1402 
1403  STD_VECTOR<MapObject>::const_iterator it = list->objects.begin();
1404  const STD_VECTOR<MapObject>::const_iterator it_end = list->objects.end();
1405  while (it != it_end)
1406  {
1407  if ((*it).type == type)
1408  return (*it).data;
1409  ++ it;
1410  }
1411 
1412  return "";
1413 }
std::vector< MapObject > objects
Definition: mapobjectlist.h:43
MapObjectList * getAt(const unsigned x, const unsigned y) const

References restrict, x, and y.

Referenced by LocalPlayer::updateMusic().

◆ getObjectsLayer()

const ObjectsLayer* Map::getObjectsLayer ( ) const
inline

Definition at line 295 of file map.h.

297  { return mObjects; }

References mObjects.

◆ getPortals()

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

Definition at line 271 of file map.h.

273  { return mMapPortals; }

References mMapPortals.

Referenced by SocialNavigationTab::updateList().

◆ getPvpMode()

int Map::getPvpMode ( ) const
inline

Definition at line 292 of file map.h.

293  { return mPvp; }

References mPvp.

Referenced by ActorManager::findNearestPvpPlayer().

◆ getSpecialLayer()

SpecialLayer* Map::getSpecialLayer ( ) const
inline

◆ getTempLayer()

SpecialLayer* Map::getTempLayer ( ) const
inline

Definition at line 238 of file map.h.

239  { return mTempLayer; }

References mTempLayer.

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

◆ getTileAnimations()

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

Definition at line 330 of file map.h.

332  { return mTileAnimations; }

References mTileAnimations.

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

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

701 {
702  if (gid >= 0 && gid < mIndexedTilesetsSize)
703  return mIndexedTilesets[gid];
704  return nullptr;
705 }

Referenced by setTile().

◆ getTileWidth()

int Map::getTileWidth ( ) const
inline

◆ getUserMapDirectory()

std::string Map::getUserMapDirectory ( ) const

Definition at line 1273 of file map.cpp.

1274 {
1276  getProperty("_realfilename", std::string()));
1277 }
std::string serverConfigDir
Definition: settings.h:117
Settings settings
Definition: settings.cpp:32

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

Referenced by addExtraLayer(), and saveExtraLayer().

◆ getVersion()

int Map::getVersion ( ) const
inline

Definition at line 310 of file map.h.

311  { return mVersion; }

References mVersion.

Referenced by setTile().

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

787 {
788  // You can't walk outside of the map
789  if (x < 0 || y < 0 || x >= mWidth || y >= mHeight)
790  return false;
791 
792  // Check if the tile is walkable
793  return (mMetaTiles[x + y * mWidth].blockmask & blockWalkMask) == 0;
794 }

References blockWalkMask, x, and y.

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

◆ getWalkLayer()

const WalkLayer* Map::getWalkLayer ( ) const
inline

Definition at line 347 of file map.h.

348  { return mWalkLayer; }

References mWalkLayer.

Referenced by LocalPlayer::isReachable().

◆ getWidth()

int Map::getWidth ( ) const
inline

Returns the width of this map in tiles.

Definition at line 166 of file map.h.

167  { return mWidth; }

References mWidth.

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

◆ haveAtlas()

bool Map::haveAtlas ( ) const
inline

Definition at line 340 of file map.h.

341  { return mAtlas != nullptr; }

References mAtlas.

Referenced by MapReader::readTileset().

◆ indexTilesets()

void Map::indexTilesets ( )

Definition at line 1415 of file map.cpp.

1416 {
1417  if (mTilesetsIndexed)
1418  return;
1419 
1420  mTilesetsIndexed = true;
1421 
1422  const Tileset *restrict s = nullptr;
1423  size_t sSz = 0;
1424  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1425  {
1426  const size_t sz = (*it)->size();
1427  if ((s == nullptr) || CAST_SIZE(s->getFirstGid()) + sSz
1428  < CAST_SIZE((*it)->getFirstGid()) + sz)
1429  {
1430  s = *it;
1431  sSz = sz;
1432  }
1433  }
1434  if (s == nullptr)
1435  {
1437  mIndexedTilesets = nullptr;
1438  return;
1439  }
1440 
1441  const int size = CAST_S32(s->getFirstGid())
1442  + CAST_S32(s->size());
1445  std::fill_n(mIndexedTilesets, size, static_cast<Tileset*>(nullptr));
1446 
1447  FOR_EACH (Tilesets::const_iterator, it, mTilesets)
1448  {
1449  Tileset *restrict const s2 = *it;
1450  if (s2 != nullptr)
1451  {
1452  const int start = s2->getFirstGid();
1453  const int end = start + CAST_S32(s2->size());
1454  for (int f = start; f < end; f ++)
1455  {
1456  if (f < size)
1457  mIndexedTilesets[f] = s2;
1458  }
1459  }
1460  }
1461 }
#define CAST_SIZE
Definition: cast.h:34

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

Referenced by MapReader::readLayer().

◆ initializeAmbientLayers()

void Map::initializeAmbientLayers ( )

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

Definition at line 234 of file map.cpp.

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

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

◆ initializeParticleEffects()

void Map::initializeParticleEffects ( ) const

Initializes all added particle effects

Definition at line 1109 of file map.cpp.

1110 {
1111  BLOCK_START("Map::initializeParticleEffects")
1112  if (particleEngine == nullptr)
1113  {
1114  BLOCK_END("Map::initializeParticleEffects")
1115  return;
1116  }
1117 
1118  if (config.getBoolValue("particleeffects"))
1119  {
1120  for (STD_VECTOR<ParticleEffectData>::const_iterator
1121  i = mParticleEffects.begin();
1122  i != mParticleEffects.end();
1123  ++i)
1124  {
1125  // +++ add z for map particle effects?
1126  Particle *const p = particleEngine->addEffect(
1127  i->file,
1128  i->x,
1129  i->y,
1130  0);
1131  if ((p != nullptr) &&
1132  i->w > 0 &&
1133  i->h > 0)
1134  {
1135  p->adjustEmitterSize(i->w, i->h);
1136  }
1137  }
1138  }
1139  BLOCK_END("Map::initializeParticleEffects")
1140 }
Particle * addEffect(const std::string &particleEffectFile, const int pixelX, const int pixelY, const int rotation)
void adjustEmitterSize(const int w, const int h)
Definition: particle.cpp:556
ParticleEngine * particleEngine

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

Referenced by Game::changeMap().

◆ isCustom()

bool Map::isCustom ( ) const
inline

Definition at line 327 of file map.h.

328  { return mCustom; }

References mCustom.

Referenced by LocalPlayer::setRealPos().

◆ isHeightsPresent()

bool Map::isHeightsPresent ( ) const
inline

Definition at line 362 of file map.h.

363  { return mHeights != nullptr; }

References mHeights.

Referenced by Viewport::getMouseTile().

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

212 {
213  if (value == "OverlayDetail")
214  {
215  mOverlayDetail = config.getIntValue("OverlayDetail");
216  }
217  else if (value == "guialpha")
218  {
219  mOpacity = config.getFloatValue("guialpha");
220  if (mOpacity != 1.0F)
221  mBeingOpacity = config.getBoolValue("beingopacity");
222  else
223  mBeingOpacity = false;
224  }
225  else if (value == "beingopacity")
226  {
227  if (mOpacity != 1.0F)
228  mBeingOpacity = config.getBoolValue("beingopacity");
229  else
230  mBeingOpacity = false;
231  }
232 }

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

◆ preCacheLayers()

void Map::preCacheLayers ( )

Definition at line 1746 of file map.cpp.

1747 {
1749  {
1750  MapLayer *restrict const layer = *it;
1751  if (layer != nullptr)
1752  layer->updateCache(mWidth, mHeight);
1753  }
1754 }

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

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

◆ redrawMap()

void Map::redrawMap ( )
inline

Definition at line 318 of file map.h.

319  { mRedrawMap = true; }

References mRedrawMap.

◆ reduce()

void Map::reduce ( )

Definition at line 1473 of file map.cpp.

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

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.

◆ removeActor()

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

Removes an actor from the map.

Definition at line 829 of file map.cpp.

830 {
831  mActors.erase(iterator);
832 // mSpritesUpdated = true;
833 }

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

◆ saveExtraLayer()

void Map::saveExtraLayer ( ) const

Definition at line 1226 of file map.cpp.

1227 {
1228  if (mSpecialLayer == nullptr)
1229  {
1230  logger->log1("No special layer");
1231  return;
1232  }
1233  const std::string mapFileName = pathJoin(getUserMapDirectory(),
1234  "extralayer.txt");
1235  logger->log("saving extra layer: " + mapFileName);
1236 
1237  if (mkdir_r(getUserMapDirectory().c_str()) != 0)
1238  {
1239  logger->log(strprintf("%s doesn't exist and can't be created! "
1240  "Exiting.", getUserMapDirectory().c_str()));
1241  return;
1242  }
1243 
1244  std::ofstream mapFile;
1245  mapFile.open(mapFileName.c_str(), std::ios::binary);
1246  if (!mapFile.is_open())
1247  {
1248  reportAlways("Error opening file for writing: %s",
1249  mapFileName.c_str())
1250  return;
1251  }
1252 
1253  const int width = mSpecialLayer->mWidth;
1254  const int height = mSpecialLayer->mHeight;
1255 
1256  for (int x = 0; x < width; x ++)
1257  {
1258  for (int y = 0; y < height; y ++)
1259  {
1260  const MapItem *restrict const item = mSpecialLayer->getTile(x, y);
1261  if ((item != nullptr) && item->mType != MapItemType::EMPTY
1262  && item->mType != MapItemType::HOME)
1263  {
1264  mapFile << x << " " << y << " "
1265  << CAST_S32(item->mType) << " "
1266  << item->mComment << std::endl;
1267  }
1268  }
1269  }
1270  mapFile.close();
1271 }
#define reportAlways(...)
Definition: checkutils.h:253
MapItem * getTile(const int x, const int y) const
int mkdir_r(const char *const pathname)
Create a directory, making leading components first if necessary.
Definition: mkdir.cpp:109
std::string strprintf(const char *const format,...)

References CAST_S32, MapItemType::EMPTY, SpecialLayer::getTile(), getUserMapDirectory(), MapItemType::HOME, 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(), and Game::slowLogic().

◆ screenResized()

void Map::screenResized ( )

Definition at line 1807 of file map.cpp.

1808 {
1809  if (mWidth * mapTileSize < mainGraphics->mWidth ||
1810  mHeight * mapTileSize < mainGraphics->mHeight)
1811  {
1812  mClear = true;
1813  }
1814  else
1815  {
1816  mClear = false;
1817  }
1818 }

References mClear, mHeight, and mWidth.

◆ setActorsFix()

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

Definition at line 1724 of file map.cpp.

1725 {
1726  mActorFixX = x;
1727  mActorFixY = y;
1728  if (mFringeLayer != nullptr)
1730 }
void setActorsFix(const int y)
Definition: maplayer.h:170

References x, and y.

◆ setAtlas()

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

Definition at line 337 of file map.h.

338  { mAtlas = atlas; }

References mAtlas.

◆ setBlockMask()

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

Definition at line 746 of file map.cpp.

748 {
749  if (type == BlockType::NONE || !contains(x, y))
750  return;
751 
752  const int tileNum = x + y * mWidth;
753 
754  switch (type)
755  {
756  case BlockType::WALL:
758  break;
759  case BlockType::AIR:
761  break;
762  case BlockType::WATER:
764  break;
765  case BlockType::GROUND:
767  break;
770  break;
773  break;
776  break;
777  default:
778  case BlockType::NONE:
780  // Do nothing.
781  break;
782  }
783 }

References BlockMask::AIR, BlockType::AIR, Catch::contains(), BlockMask::GROUND, BlockType::GROUND, BlockMask::GROUNDTOP, BlockType::GROUNDTOP, BlockMask::MONSTERWALL, BlockType::MONSTERWALL, 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().

◆ setCustom()

void Map::setCustom ( const bool  b)
inline

Definition at line 324 of file map.h.

325  { mCustom = b; }

References mCustom.

Referenced by MapReader::createEmptyMap().

◆ setDrawLayersFlags()

void Map::setDrawLayersFlags ( const MapTypeT n)

Definition at line 1703 of file map.cpp.

1704 {
1705  mDrawLayersFlags = n;
1709  {
1710  mDrawOnlyFringe = true;
1711  }
1712  else
1713  {
1714  mDrawOnlyFringe = false;
1715  }
1717  FOR_EACH (Layers::iterator, it, mLayers)
1718  {
1719  MapLayer *restrict const layer = *it;
1720  layer->setDrawLayerFlags(mDrawLayersFlags);
1721  }
1722 }
void updateDrawLayersList()
Definition: map.cpp:1638
@ SPECIAL3
Definition: maptype.h:35
@ SPECIAL4
Definition: maptype.h:36

References MapType::BLACKWHITE, FOR_EACH, restrict, MapType::SPECIAL3, and MapType::SPECIAL4.

Referenced by GameModifiers::resetModifiers().

◆ setHasWarps()

void Map::setHasWarps ( const bool  n)
inline

Definition at line 244 of file map.h.

245  { mHasWarps = n; }

References mHasWarps.

◆ setMask()

void Map::setMask ( const int  mask)

Definition at line 1676 of file map.cpp.

1677 {
1678  if (mask != mMask)
1679  {
1680  mRedrawMap = true;
1681  mMask = mask;
1683  }
1684 }

Referenced by Ea::PlayerRecv::processMapMask().

◆ setMusicFile()

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

Definition at line 1686 of file map.cpp.

1687 {
1688  setProperty("music", file);
1689 }
void setProperty(const std::string &name, const std::string &value)
Definition: properties.h:128

Referenced by Ea::PlayerRecv::processMapMusic().

◆ setPvpMode()

void Map::setPvpMode ( const int  mode)

Definition at line 1361 of file map.cpp.

1362 {
1363  const int oldMode = mPvp;
1364 
1365  if (mode == 0)
1366  mPvp = 0;
1367  else
1368  mPvp |= mode;
1369 
1370  if (mPvp != oldMode && (localPlayer != nullptr))
1371  {
1372  switch (mPvp)
1373  {
1374  case 0:
1376  break;
1377  case 1:
1379  break;
1380  case 2:
1382  break;
1383  case 3:
1385  break;
1386  default:
1388  break;
1389  }
1390  }
1391 }
void notify(const unsigned int message)

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

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

◆ setVersion()

void Map::setVersion ( const int  n)
inline

Definition at line 313 of file map.h.

314  { mVersion = n; }

References mVersion.

◆ setWalk()

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

Definition at line 807 of file map.cpp.

808 {
810 }
void addBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:707

References BlockType::GROUNDTOP, x, and y.

Referenced by LocalPlayer::setRealPos().

◆ setWalkLayer()

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

Definition at line 350 of file map.h.

351  { mWalkLayer = layer; }

References mWalkLayer.

◆ update()

void Map::update ( const int  ticks)

Updates animations. Called as needed.

Definition at line 328 of file map.cpp.

329 {
330  // Update animated tiles
332  {
333  TileAnimation *restrict const tileAni = iAni->second;
334  if ((tileAni != nullptr) && tileAni->update(ticks))
335  mRedrawMap = true;
336  }
337 }

References FOR_EACH, and restrict.

Referenced by Game::logic().

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

621 {
622  BLOCK_START("Map::updateAmbientLayers")
623  static int lastTick = tick_time;
624 
625  if (mLastAScrollX == 0.0F && mLastAScrollY == 0.0F)
626  {
627  // First call - initialisation
628  mLastAScrollX = scrollX;
629  mLastAScrollY = scrollY;
630  }
631 
632  // Update Overlays
633  const float dx = scrollX - mLastAScrollX;
634  const float dy = scrollY - mLastAScrollY;
635  const int timePassed = get_elapsed_time(lastTick);
636 
637  // need check mask to update or not to update
638 
640  {
641  AmbientLayer *const layer = *i;
642  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
643  layer->update(timePassed, dx, dy);
644  }
645 
647  {
648  AmbientLayer *const layer = *i;
649  if ((layer != nullptr) && ((layer->mMask & mMask) != 0))
650  layer->update(timePassed, dx, dy);
651  }
652 
653  mLastAScrollX = scrollX;
654  mLastAScrollY = scrollY;
655  lastTick = tick_time;
656  BLOCK_END("Map::updateAmbientLayers")
657 }
void update(const int timePassed, const float dx, const float dy)
volatile int tick_time
Definition: timer.cpp:53
AmbientLayerVector::iterator AmbientLayerVectorIter
Definition: map.h:67
int get_elapsed_time(const int startTime)
Definition: timer.cpp:94

References BLOCK_END, BLOCK_START, FOR_EACH, get_elapsed_time(), AmbientLayer::mMask, tick_time, and AmbientLayer::update().

◆ updateConditionLayers()

void Map::updateConditionLayers ( )

Definition at line 1732 of file map.cpp.

1733 {
1734  mRedrawMap = true;
1735 
1737  {
1738  MapLayer *restrict const layer = *it;
1739  if ((layer == nullptr) || layer->mTileCondition == -1)
1740  continue;
1741  layer->updateConditionTiles(mMetaTiles,
1742  mWidth, mHeight);
1743  }
1744 }

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

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

◆ updateDrawLayersList()

void Map::updateDrawLayersList ( )

Definition at line 1638 of file map.cpp.

1639 {
1640  mDrawUnderLayers.clear();
1641  mDrawOverLayers.clear();
1642 
1643  if (mDrawOnlyFringe)
1644  return;
1645 
1646  LayersCIter layers = mLayers.begin();
1647  const LayersCIter layers_end = mLayers.end();
1648  for (; layers != layers_end; ++ layers)
1649  {
1650  MapLayer *const layer = *layers;
1651  if ((layer->mMask & mMask) == 0)
1652  continue;
1653 
1654  if (layer->isFringeLayer())
1655  {
1656  ++ layers;
1657  break;
1658  }
1659 
1660  mDrawUnderLayers.push_back(layer);
1661  }
1662 
1664  return;
1665 
1666  for (; layers != layers_end; ++ layers)
1667  {
1668  MapLayer *const layer = *layers;
1669  if ((layer->mMask & mMask) == 0)
1670  continue;
1671 
1672  mDrawOverLayers.push_back(layer);
1673  }
1674 }
int mMask
Definition: maplayer.h:234
@ SPECIAL2
Definition: maptype.h:34

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

Referenced by MapReader::createEmptyMap().

◆ updatePortalTile()

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

Definition at line 1313 of file map.cpp.

1317 {
1318  MapItem *restrict item = findPortalXY(x, y);
1319  if (item != nullptr)
1320  {
1321  item->mComment = name;
1322  item->setType(type);
1323  item->mX = x;
1324  item->mY = y;
1325  if (mSpecialLayer != nullptr)
1326  {
1327  item = new MapItem(type, name, x, y);
1328  mSpecialLayer->setTile(x, y, item);
1330  }
1331  }
1332  else if (addNew)
1333  {
1334  addPortalTile(name, type, x, y);
1335  }
1336 }
MapItem * findPortalXY(const int x, const int y) const
Definition: map.cpp:1338

References restrict, x, and y.

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

Friends And Related Function Documentation

◆ Actor

friend class Actor
friend

Definition at line 379 of file map.h.

◆ Minimap

friend class Minimap
friend

Definition at line 380 of file map.h.

Field Documentation

◆ mActorFixX

int Map::mActorFixX
private

Definition at line 477 of file map.h.

◆ mActorFixY

int Map::mActorFixY
private

Definition at line 478 of file map.h.

◆ mActors

Actors Map::mActors
private

Definition at line 423 of file map.h.

Referenced by calcMemoryLocal(), and getActorsCount().

◆ mAtlas

AtlasResource* Map::mAtlas
private

Definition at line 497 of file map.h.

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

◆ mBackgrounds

AmbientLayerVector Map::mBackgrounds
private

Definition at line 434 of file map.h.

Referenced by calcMemoryChilds(), calcMemoryLocal(), initializeAmbientLayers(), and ~Map().

◆ mBeingOpacity

bool Map::mBeingOpacity
private

Definition at line 502 of file map.h.

Referenced by Map().

◆ mCachedDraw

bool Map::mCachedDraw
private

Definition at line 503 of file map.h.

◆ mClear

bool Map::mClear
private

Definition at line 506 of file map.h.

Referenced by screenResized().

◆ mCustom

bool Map::mCustom
private

Definition at line 504 of file map.h.

Referenced by isCustom(), and setCustom().

◆ mDrawLayersFlags

MapTypeT Map::mDrawLayersFlags
private

Definition at line 427 of file map.h.

Referenced by getDrawLayersFlags(), and updateDrawLayersList().

◆ mDrawOnlyFringe

bool Map::mDrawOnlyFringe
private

Definition at line 505 of file map.h.

Referenced by updateDrawLayersList().

◆ mDrawOverLayers

Layers Map::mDrawOverLayers
private

Definition at line 421 of file map.h.

Referenced by calcMemoryLocal(), and updateDrawLayersList().

◆ mDrawScrollX

int Map::mDrawScrollX
private

Definition at line 493 of file map.h.

◆ mDrawScrollY

int Map::mDrawScrollY
private

Definition at line 494 of file map.h.

◆ mDrawUnderLayers

Layers Map::mDrawUnderLayers
private

Definition at line 420 of file map.h.

Referenced by calcMemoryLocal(), and updateDrawLayersList().

◆ mDrawX

int Map::mDrawX
private

Definition at line 491 of file map.h.

◆ mDrawY

int Map::mDrawY
private

Definition at line 492 of file map.h.

◆ mForegrounds

AmbientLayerVector Map::mForegrounds
private

Definition at line 435 of file map.h.

Referenced by calcMemoryChilds(), calcMemoryLocal(), initializeAmbientLayers(), and ~Map().

◆ mFringeLayer

MapLayer* Map::mFringeLayer
private

Definition at line 484 of file map.h.

Referenced by reduce(), and ~Map().

◆ mHasWarps

bool Map::mHasWarps
private

Definition at line 424 of file map.h.

Referenced by getHasWarps(), and setHasWarps().

◆ mHeight

const int Map::mHeight
private

◆ mHeights

const MapHeights* Map::mHeights
private

Definition at line 500 of file map.h.

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

◆ mIndexedTilesets

Tileset** Map::mIndexedTilesets
private

Definition at line 475 of file map.h.

Referenced by clearIndexedTilesets(), and indexTilesets().

◆ mIndexedTilesetsSize

int Map::mIndexedTilesetsSize
private

Definition at line 476 of file map.h.

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

◆ mLastAScrollX

float Map::mLastAScrollX
private

Definition at line 436 of file map.h.

◆ mLastAScrollY

float Map::mLastAScrollY
private

Definition at line 437 of file map.h.

◆ mLastScrollX

int Map::mLastScrollX
private

Definition at line 488 of file map.h.

◆ mLastScrollY

int Map::mLastScrollY
private

Definition at line 489 of file map.h.

◆ mLastX

int Map::mLastX
private

Definition at line 486 of file map.h.

◆ mLastY

int Map::mLastY
private

Definition at line 487 of file map.h.

◆ mLayers

Layers Map::mLayers
private

◆ mMapPortals

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

Definition at line 465 of file map.h.

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

◆ mMask

int Map::mMask
private

Definition at line 495 of file map.h.

Referenced by updateDrawLayersList().

◆ mMaxTileHeight

int Map::mMaxTileHeight
private

Definition at line 416 of file map.h.

◆ mMetaTiles

MetaTile* const Map::mMetaTiles
private

Definition at line 417 of file map.h.

Referenced by getMetaTiles(), Minimap::setMap(), updateConditionLayers(), and ~Map().

◆ mName

std::string Map::mName
private

Definition at line 469 of file map.h.

Referenced by calcMemoryLocal(), and getCounterName().

◆ mObjects

ObjectsLayer* Map::mObjects
private

Definition at line 483 of file map.h.

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

◆ mOnClosedList

unsigned int Map::mOnClosedList
private

Definition at line 430 of file map.h.

◆ mOnOpenList

unsigned int Map::mOnOpenList
private

Definition at line 431 of file map.h.

◆ mOpacity

float Map::mOpacity
private

Definition at line 471 of file map.h.

Referenced by Map().

◆ mOpenGL

const RenderType Map::mOpenGL
private

Definition at line 472 of file map.h.

Referenced by reduce().

◆ mOverlayDetail

int Map::mOverlayDetail
private

Definition at line 470 of file map.h.

◆ mParticleEffects

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

Definition at line 463 of file map.h.

Referenced by calcMemoryLocal(), and initializeParticleEffects().

◆ mPvp

int Map::mPvp
private

Definition at line 473 of file map.h.

Referenced by getPvpMode().

◆ mRedrawMap

bool Map::mRedrawMap
private

Definition at line 501 of file map.h.

Referenced by redrawMap(), and updateConditionLayers().

◆ mSpecialLayer

SpecialLayer* Map::mSpecialLayer
private

Definition at line 481 of file map.h.

Referenced by addExtraLayer(), calcMemoryChilds(), getSpecialLayer(), saveExtraLayer(), and ~Map().

◆ mTempLayer

SpecialLayer* Map::mTempLayer
private

Definition at line 482 of file map.h.

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

◆ mTileAnimations

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

Definition at line 467 of file map.h.

Referenced by calcMemoryLocal(), getTileAnimations(), and ~Map().

◆ mTileHeight

const int Map::mTileHeight
private

Definition at line 415 of file map.h.

Referenced by getTileHeight().

◆ mTilesets

Tilesets Map::mTilesets
private

Definition at line 422 of file map.h.

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

◆ mTilesetsIndexed

bool Map::mTilesetsIndexed
private

Definition at line 474 of file map.h.

Referenced by clearIndexedTilesets(), and indexTilesets().

◆ mTileWidth

const int Map::mTileWidth
private

Definition at line 414 of file map.h.

Referenced by getTileWidth().

◆ mVersion

int Map::mVersion
private

Definition at line 479 of file map.h.

Referenced by getVersion(), and setVersion().

◆ mWalkLayer

WalkLayer* Map::mWalkLayer
private

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