69 : mAnimation(std::move(animation))
83 layer->setTile(index, img);
92 mWidth(width), mHeight(height),
93 mIsFringeLayer(isFringeLayer),
112 int startX,
int startY,
114 int scrollX,
int scrollY,
115 const Actors &actors,
int debugFlags)
const
122 if (startX < 0) startX = 0;
123 if (startY < 0) startY = 0;
127 auto ai = actors.begin();
132 for (
int y = startY; y < endY; y++)
140 while (ai != actors.end() && (*ai)->getDrawOrder()
143 (*ai)->draw(
graphics, -scrollX, -scrollY);
150 const int py0 = pixelY + dy;
152 for (
int x = startX; x < endX; x++)
160 const int py = py0 - img->getHeight();
170 width, img->getHeight());
182 for (; ai != actors.end(); ++ai)
184 (*ai)->draw(
graphics, -scrollX, -scrollY);
199 for (
int x = x1 + 1; x < endX; x++)
210Map::Map(
int width,
int height,
int tileWidth,
int tileHeight):
211 mWidth(width), mHeight(height),
212 mTileWidth(tileWidth), mTileHeight(tileHeight),
213 mMaxTileHeight(tileHeight),
214 mMaxTileWidth(tileWidth),
215 mDebugFlags(DEBUG_NONE),
216 mOnClosedList(1), mOnOpenList(2),
217 mLastScrollX(0.0f), mLastScrollY(0.0f)
224 occupation =
new unsigned[size];
225 memset(occupation, 0, size *
sizeof(
unsigned));
245 auto addAmbientLayer = [=](
const std::string &name, std::vector<AmbientLayer> &list)
249 auto &ambientLayer = list.emplace_back(img);
251 ambientLayer.mSpeedX =
getFloatProperty(name +
"scrollX") / MILLISECONDS_IN_A_TICK;
252 ambientLayer.mSpeedY =
getFloatProperty(name +
"scrollY") / MILLISECONDS_IN_A_TICK;
259 for (
int i = 0; ; i++)
304 tileAnimation.update(dt);
334 if ((layer->getMask() &
mMask) == 0)
341 startX, startY, endX, endY,
358 if (actor->drawnWhenBehind())
360 actor->setAlpha(0.3f);
361 actor->draw(
graphics, -scrollX, -scrollY);
362 actor->setAlpha(1.0f);
372 int debugFlags)
const
380 if (startX < 0) startX = 0;
381 if (startY < 0) startY = 0;
385 for (
int y = startY; y < endY; y++)
387 for (
int x = startX; x < endX; x++)
393 graphics->drawRectangle(gcn::Rectangle(
405 graphics->fillRectangle(gcn::Rectangle(
414 graphics->fillRectangle(gcn::Rectangle(
423 graphics->fillRectangle(gcn::Rectangle(
447 if ((background.mMask &
mMask) == 0)
454 if ((foreground.mMask &
mMask) == 0)
464 float scrollX,
float scrollY,
int detail)
470 std::vector<AmbientLayer> *layers;
487 for (
auto &layer : *layers)
489 if ((layer.mMask &
mMask) == 0)
505 if (tileset->getFirstGid() > gid)
518 const int tileNum = x + y *
mWidth;
555 if (actor->getTileX() == x && actor->getTileY() == y &&
569 return tileCenterPos;
609 int lastSlash = fileName.rfind(
"/") + 1;
610 int lastDot = fileName.rfind(
".");
612 return fileName.substr(lastSlash, lastDot - lastSlash);
636 if (!
getWalk(tx - 1, ty - 1, walkMask)
637 && fy < radius && fx < radius)
642 if (!
getWalk(tx + 1, ty - 1, walkMask)
643 && (fy < radius) && fx > (
mTileWidth - radius))
649 if (!
getWalk(tx - 1, ty + 1, walkMask)
656 if (!
getWalk(tx + 1, ty + 1, walkMask)
666 else if (fx < radius && !
getWalk(tx - 1, ty, walkMask))
670 else if (fy < radius && !
getWalk(tx, ty - 1, walkMask))
677 int endPixelY,
unsigned char walkMask,
int maxCost)
688 auto it = myPath.begin();
689 while (it != myPath.end())
702 int radius,
unsigned char walkMask,
int maxCost)
713 float startOffsetX = (startPixelX %
mTileWidth);
721 int changeX = (int)((endOffsetX - startOffsetX) / myPath.size());
722 int changeY = (int)((endOffsetY - startOffsetY) / myPath.size());
726 auto it = myPath.begin();
728 while (it != myPath.end())
733 it->x *
mTileWidth + startOffsetX + changeX * i,
743 endPixelX, endPixelY);
745 myPath.push_back(destination);
751 unsigned char walkmask,
int maxCost)
754 const int basicCost = 100;
760 std::priority_queue<Location> openList;
763 if (!
getWalk(destX, destY, walkmask))
768 startTile->
Gcost = 0;
771 openList.emplace(startX, startY, startTile);
773 bool foundPath =
false;
776 while (!openList.empty() && !foundPath)
791 for (
int dy = -1; dy <= 1; dy++)
793 for (
int dx = -1; dx <= 1; dx++)
796 const int x = curr.
x + dx;
797 const int y = curr.
y + dy;
801 if ((dx == 0 && dy == 0) || !
contains(x, y))
810 && !(x == destX && y == destY)))
817 if (dx != 0 && dy != 0)
828 (dx == 0 || dy == 0 ? basicCost : basicCost * 362 / 256);
837 if (dx == 0 || dy == 0)
850 Gcost += 3 * basicCost;
855 if (Gcost > maxCost * basicCost)
868 int dx = std::abs(x - destX);
869 int dy = std::abs(y - destY);
870 newTile->
Hcost = std::abs(dx - dy) * basicCost +
871 std::min(dx, dy) * (basicCost * 362 / 256);
878 newTile->
Gcost = Gcost;
881 if (x != destX || y != destY)
885 openList.emplace(x, y, newTile);
893 else if (Gcost < newTile->Gcost)
897 newTile->
Gcost = Gcost;
906 openList.emplace(x, y, newTile);
922 for (
int i = 0; i < size; ++i)
938 while (pathX != startX || pathY != startY)
941 path.emplace_front(pathX, pathY);
957 newEffect.
file = effectFile;
974 if (p && particleEffect.w > 0 && particleEffect.h > 0)
984 auto const [
_, inserted] =
mTileAnimations.try_emplace(gid, std::move(animation));
987 Log::warn(
"Duplicate tile animation for gid %d", gid);
std::list< Actor * > Actors
ActorSpriteManager * actorSpriteManager
const ActorSprites & getAll() const
Returns the whole list of beings.
virtual int getDrawOrder() const
Returns the pixel Y coordinate that the actor should be drawn at.
An animation consists of several frames, each with their own delay and offset.
A central point of control for graphics.
virtual void drawImagePattern(const Image *image, int x, int y, int w, int h)
int getHeight() const
Returns the logical height of the screen.
void setColor(const gcn::Color &color) override
bool drawImage(const Image *image, int x, int y)
Blits an image onto the screen.
int getWidth() const
Returns the logical width of the screen.
int getWidth() const
Returns the width of the images in the image set.
int getHeight() const
Returns the height of the images in the image set.
Defines a class for loading and storing images.
int getWidth() const
Returns the width of the image.
static bool SDLisTransparencyDisabled()
static bool useOpenGL()
Tells if the system is using OpenGL or SDL.
Image * getTile(int x, int y) const
Get tile image, with x and y in layer coordinates.
bool mIsFringeLayer
Whether the actors are drawn.
void setTile(int x, int y, Image *img)
Set tile image, with x and y in layer coordinates.
MapLayer(int x, int y, int width, int height, bool isFringeLayer, Map *map)
Constructor, taking layer origin, size and whether this layer is the fringe layer.
int getTileDrawWidth(int x1, int y1, int endX, int &width) const
void draw(Graphics *graphics, int startX, int startY, int endX, int endY, int scrollX, int scrollY, const Actors &actors, int debugFlags) const
Draws this layer to the given graphics context.
std::string getMusicFile() const
Map(int width, int height, int tileWidth, int tileHeight)
Constructor, taking map and tile size as parameters.
Path findPixelPath(int startPixelX, int startPixelY, int destPixelX, int destPixelY, int radius, unsigned char walkmask, int maxCost=20)
Find a pixel path from one location to the next using free offsets.
TileAnimation * getAnimationForGid(int gid)
Gets the tile animation for a specific gid.
void update(int dt)
Updates animations.
std::vector< AmbientLayer > mBackgrounds
std::vector< MapLayer * > mLayers
void draw(Graphics *graphics, int scrollX, int scrollY)
Draws the map to the given graphics output.
void initializeParticleEffects(Particle *particleEngine)
Initializes all added particle effects.
int getTileHeight() const
Returns the tile height used by this map.
void addLayer(MapLayer *layer)
Adds a layer to this map.
void removeActor(Actors::iterator iterator)
Removes an actor from the map.
std::string getName() const
Path findPath(int startX, int startY, int destX, int destY, unsigned char walkmask, int maxCost=20)
Find a path from one location to the next in tile coordinates.
void addAnimation(int gid, TileAnimation animation)
Adds a tile animation to the map.
void updateAmbientLayers(float scrollX, float scrollY)
Updates scrolling of ambient layers.
std::string getFilename() const
Gives the map id based on filepath (ex: 009-1)
MetaTile * getMetaTile(int x, int y) const
Get tile reference.
std::vector< Tileset * > mTilesets
void initializeAmbientLayers()
Initialize ambient layers.
void drawAmbientLayers(Graphics *graphics, LayerType type, float scrollX, float scrollY, int detail)
Draws the foreground or background layers to the given graphics output.
int getTileWidth() const
Returns the tile width of this map.
void drawCollision(Graphics *graphics, int scrollX, int scrollY, int debugFlags) const
Visualizes collision layer for debugging.
bool occupied(int x, int y) const
Tells whether a tile is occupied by a being.
void blockTile(int x, int y, BlockType type)
Marks a tile as occupied.
std::vector< AmbientLayer > mForegrounds
Tileset * getTilesetWithGid(unsigned gid) const
Finds the tile set that a tile with the given global id is part of.
std::list< ParticleEffectData > particleEffects
Position checkNodeOffsets(int radius, unsigned char walkMask, const Position &position) const
Check the current position against surrounding blocking tiles, and correct the position offset within...
bool contains(int x, int y) const
Tells whether the given coordinates fall within the map boundaries.
Vector getTileCenter(int x, int y) const
Returns the tile center position in pixel coordinates.
std::map< int, TileAnimation > mTileAnimations
unsigned * mOccupation[NB_BLOCKTYPES]
Blockmasks for different entities.
void addTileset(Tileset *tileset)
Adds a tileset to this map.
bool getWalk(int x, int y, unsigned char walkmask=BLOCKMASK_WALL) const
Gets walkability for a tile with a blocking bitmask.
Path findTilePath(int startPixelX, int startPixelY, int endPixelX, int endPixelY, unsigned char walkMask, int maxCost=20)
Find a tile-centered path in pixel coordinates from one location to the next.
void addParticleEffect(const std::string &effectFile, int x, int y, int w=0, int h=0)
Adds a particle effect.
Actors::iterator addActor(Actor *actor)
Adds an actor to the map.
A particle spawned by a ParticleEmitter.
Particle * addEffect(const std::string &particleEffectFile, int pixelX, int pixelY, int rotation=0)
Creates a child particle that hosts some emitters described in the particleEffectFile.
void adjustEmitterSize(int w, int h)
Changes the size of the emitters so that the effect fills a rectangle of this size.
std::string getProperty(const std::string &name, const std::string &def=std::string()) const
Get a map property.
bool hasProperty(const std::string &name) const
Returns whether a certain property is available.
float getIntProperty(const std::string &name, int def=0) const
Gets a map property as an int.
float getFloatProperty(const std::string &name, float def=0.0f) const
Gets a map property as a float.
bool getBoolProperty(const std::string &name, bool def=false) const
Gets a map property as a boolean.
A class for loading and managing resources.
static ResourceManager * getInstance()
Returns an instance of the class, creating one if it does not already exist.
ResourceRef< Image > getImage(const std::string &idPath)
Loads the Image resource found at the given identifier path.
Image * getCurrentImage() const
Animation cycle of a tile image which changes the map accordingly.
std::vector< std::pair< MapLayer *, int > > mAffected
TileAnimation(Animation animation)
SimpleAnimation mAnimation
A tileset, which is basically just an image set but it stores a firstgid.
Config config
Global settings (config.xml)
void delete_all(Container &c)
Particle * particleEngine
void warn(const char *log_text,...) LOG_PRINTF_ATTR
ServerType getNetworkType()
unsigned deltaTimeMs()
The time in milliseconds since the last frame, but never more than 1000.
std::list< Position > Path
std::string toString(const T &arg)
Converts the given value to a string using std::stringstream.
A location on a tile map.
Location(int px, int py, MetaTile *ptile)
bool operator<(const Location &loc) const
Comparison operator.
A position along a being's path.