]> git.localhorst.tv Git - l2e.git/blobdiff - src/map/Area.cpp
closed the gap between battle and map state (yay)
[l2e.git] / src / map / Area.cpp
index 0b25a04bd7b512e9ca1f913856ff410f602b5667..985dea2d5462f4aae5ecba7663d6c79651f635d3 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "Tile.h"
 #include "../graphics/Sprite.h"
+#include "../sdl/utility.h"
 
 #include <stdexcept>
 
@@ -17,19 +18,29 @@ using geometry::Vector;
 namespace map {
 
 Area::Area()
-: tiles(0)
+: battlebg(0)
+, tiles(0)
 , numTiles(0)
 , width(0) {
 
 }
 
 
-const Tile &Area::TileAt(const geometry::Vector<int> &offset) const {
+Tile *Area::TileAt(const geometry::Vector<int> &offset) {
        int tileIndex(offset.Y() * width + offset.X());
        if (tileIndex < numTiles) {
-               return tiles[tileIndex];
+               return tiles +tileIndex;
        } else {
-               throw std::out_of_range("tile index out of range");
+               return 0;
+       }
+}
+
+const Tile *Area::TileAt(const geometry::Vector<int> &offset) const {
+       int tileIndex(offset.Y() * width + offset.X());
+       if (tileIndex < numTiles) {
+               return tiles +tileIndex;
+       } else {
+               return 0;
        }
 }
 
@@ -45,6 +56,15 @@ void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vect
 }
 
 void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
+       SDL_Rect destRect;
+       destRect.x = inOffset.X();
+       destRect.y = inOffset.Y();
+       destRect.w = Width() * tileset->Width();
+       destRect.h = Height() * tileset->Height();
+       sdl::OutlineRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
+
+       Uint32 color(SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+
        for (int i(0); i < numTiles; ++i) {
                Vector<int> offset(
                                inOffset.X() + (i % width) * tileset->Width(),
@@ -52,39 +72,16 @@ void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const
                const Tile &tile(tiles[i]);
 
                if (tile.BlocksNorth()) {
-                       SDL_Rect destRect;
-                       destRect.x = offset.X();
-                       destRect.y = offset.Y();
-                       destRect.w = tileset->Width();
-                       destRect.h = 1;
-                       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+                       sdl::HorizontalLine(dest, offset, tileset->Width(), color);
                }
-
                if (tile.BlocksEast()) {
-                       SDL_Rect destRect;
-                       destRect.x = offset.X() + tileset->Width() - 1;
-                       destRect.y = offset.Y();
-                       destRect.w = 1;
-                       destRect.h = tileset->Height();
-                       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+                       sdl::VerticalLine(dest, Vector<int>(offset.X() + tileset->Width() - 1, offset.Y()), tileset->Height(), color);
                }
-
                if (tile.BlocksSouth()) {
-                       SDL_Rect destRect;
-                       destRect.x = offset.X();
-                       destRect.y = offset.Y() + tileset->Height() - 1;
-                       destRect.w = tileset->Width();
-                       destRect.h = 1;
-                       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+                       sdl::HorizontalLine(dest, Vector<int>(offset.X(), offset.Y() + tileset->Height() - 1), tileset->Width(), color);
                }
-
                if (tile.BlocksWest()) {
-                       SDL_Rect destRect;
-                       destRect.x = offset.X();
-                       destRect.y = offset.Y();
-                       destRect.w = 1;
-                       destRect.h = tileset->Height();
-                       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+                       sdl::VerticalLine(dest, offset, tileset->Height(), color);
                }
        }
 }