]> git.localhorst.tv Git - l2e.git/blobdiff - src/map/Map.cpp
closed the gap between battle and map state (yay)
[l2e.git] / src / map / Map.cpp
index fc664c1d7d4e26c0060176bf0283002abfbbe5a6..a9e11df7e9064627cb4388b0696e78eada8c92b8 100644 (file)
@@ -8,6 +8,7 @@
 #include "Map.h"
 
 #include "Area.h"
+#include "Tile.h"
 #include "Trigger.h"
 #include "../graphics/Sprite.h"
 
@@ -19,6 +20,7 @@ namespace map {
 
 Map::Map()
 : tileset(0)
+, battlebg(0)
 , areas(0)
 , numAreas(0)
 , triggers(0)
@@ -30,6 +32,18 @@ Map::Map()
 }
 
 
+Area *Map::AreaAt(const Vector<int> &offset) {
+       if (numAreas > 0) {
+               Vector<int> coords(TileCoordinates(offset));
+               Vector<int> areaOffset(coords / areas[0].Size());
+               int areaIndex(areaOffset.Index(width));
+               if (areaIndex < numAreas) {
+                       return areas + areaIndex;
+               }
+       }
+       return 0;
+}
+
 const Area *Map::AreaAt(const Vector<int> &offset) const {
        if (numAreas > 0) {
                Vector<int> coords(TileCoordinates(offset));
@@ -42,6 +56,16 @@ const Area *Map::AreaAt(const Vector<int> &offset) const {
        return 0;
 }
 
+Tile *Map::TileAt(const Vector<int> &offset) {
+       Area *area(AreaAt(offset));
+       if (area) {
+               Vector<int> tileOffset(TileCoordinates(offset) % area->Size());
+               return area->TileAt(tileOffset);
+       } else {
+               return 0;
+       }
+}
+
 const Tile *Map::TileAt(const Vector<int> &offset) const {
        const Area *area(AreaAt(offset));
        if (area) {
@@ -63,6 +87,18 @@ Trigger *Map::TriggerAt(const geometry::Vector<int> &offset) {
        return 0;
 }
 
+SDL_Surface *Map::BattleBackgroundAt(const geometry::Vector<int> &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<int> Map::TileCoordinates(const Vector<int> &position) const {
        return position / tileset->Size();
 }