X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;ds=inline;f=src%2Fmap%2FMap.cpp;h=a9e11df7e9064627cb4388b0696e78eada8c92b8;hb=978ccdf2644bc445c864dbe581ead365b238cff8;hp=b87cd03cb5674a2333f3b78315d1e4c03e01cf5d;hpb=d7694cc492924fad379e8886e9e23606960717c1;p=l2e.git diff --git a/src/map/Map.cpp b/src/map/Map.cpp index b87cd03..a9e11df 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -8,6 +8,7 @@ #include "Map.h" #include "Area.h" +#include "Tile.h" #include "Trigger.h" #include "../graphics/Sprite.h" @@ -19,31 +20,60 @@ namespace map { Map::Map() : tileset(0) +, battlebg(0) , areas(0) , numAreas(0) , triggers(0) , numTriggers(0) +, entities(0) +, numEntities(0) , width(0) { } -const Area &Map::AreaAt(const Vector &offset) const { +Area *Map::AreaAt(const Vector &offset) { if (numAreas > 0) { Vector coords(TileCoordinates(offset)); Vector areaOffset(coords / areas[0].Size()); int areaIndex(areaOffset.Index(width)); if (areaIndex < numAreas) { - return areas[areaIndex]; + return areas + areaIndex; } } - throw std::out_of_range("area offset out of bounds"); + return 0; } -const Tile &Map::TileAt(const Vector &offset) const { - const Area &area(AreaAt(offset)); - Vector tileOffset(TileCoordinates(offset) % area.Size()); - return area.TileAt(tileOffset); +const Area *Map::AreaAt(const Vector &offset) const { + if (numAreas > 0) { + Vector coords(TileCoordinates(offset)); + Vector areaOffset(coords / areas[0].Size()); + int areaIndex(areaOffset.Index(width)); + if (areaIndex < numAreas) { + return areas + areaIndex; + } + } + return 0; +} + +Tile *Map::TileAt(const Vector &offset) { + Area *area(AreaAt(offset)); + if (area) { + Vector tileOffset(TileCoordinates(offset) % area->Size()); + return area->TileAt(tileOffset); + } else { + return 0; + } +} + +const Tile *Map::TileAt(const Vector &offset) const { + const Area *area(AreaAt(offset)); + if (area) { + Vector tileOffset(TileCoordinates(offset) % area->Size()); + return area->TileAt(tileOffset); + } else { + return 0; + } } Trigger *Map::TriggerAt(const geometry::Vector &offset) { @@ -57,6 +87,18 @@ Trigger *Map::TriggerAt(const geometry::Vector &offset) { return 0; } +SDL_Surface *Map::BattleBackgroundAt(const geometry::Vector &position) { + Tile *tile(TileAt(position)); + if (tile && tile->BattleBackground()) { + return tile->BattleBackground(); + } + Area *area(AreaAt(position)); + if (area && area->BattleBackground()) { + return area->BattleBackground(); + } + return battlebg; +} + Vector Map::TileCoordinates(const Vector &position) const { return position / tileset->Size(); }