]> git.localhorst.tv Git - l2e.git/blobdiff - src/map/Area.cpp
removed stupid file headers that eclipse put in
[l2e.git] / src / map / Area.cpp
index 84dc8a6a527747fce948b6dffb289bc60ee55f0c..a64dab2a928ea1b479860ee1f1220ff7623bcf76 100644 (file)
@@ -1,35 +1,44 @@
-/*
- * Area.cpp
- *
- *  Created on: Sep 26, 2012
- *      Author: holy
- */
-
 #include "Area.h"
 
 #include "Tile.h"
 #include "../graphics/Sprite.h"
+#include "../loader/TypeDescription.h"
+#include "../loader/Interpreter.h"
+#include "../sdl/utility.h"
 
 #include <stdexcept>
 
 using geometry::Vector;
+using loader::FieldDescription;
+using loader::Interpreter;
+using loader::TypeDescription;
 
 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;
+       } else {
+               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];
+               return tiles +tileIndex;
        } else {
-               throw std::out_of_range("tile index out of range");
+               return 0;
        }
 }
 
@@ -49,16 +58,10 @@ void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const
        destRect.x = inOffset.X();
        destRect.y = inOffset.Y();
        destRect.w = Width() * tileset->Width();
-       destRect.h = 1;
-       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
-       destRect.y += Height() * tileset->Height() - 1;
-       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
-       destRect.y = inOffset.Y();
-       destRect.w = 1;
        destRect.h = Height() * tileset->Height();
-       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
-       destRect.x += Width() * tileset->Width() - 1;
-       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
+       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(
@@ -67,37 +70,35 @@ void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const
                const Tile &tile(tiles[i]);
 
                if (tile.BlocksNorth()) {
-                       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()) {
-                       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()) {
-                       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()) {
-                       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);
                }
        }
 }
 
+
+void Area::CreateTypeDescription() {
+       Area a;
+
+       TypeDescription &td(TypeDescription::Create(TYPE_ID, "Area"));
+       td.SetConstructor(&Construct);
+       td.SetSize(sizeof(Area));
+
+       td.AddField("battlebg", FieldDescription(((char *)&a.battlebg) - ((char *)&a), Interpreter::IMAGE_ID).SetReferenced());
+       td.AddField("tiles", FieldDescription(((char *)&a.tiles) - ((char *)&a), Tile::TYPE_ID).SetReferenced().SetAggregate());
+       td.AddField("width", FieldDescription(((char *)&a.width) - ((char *)&a), Interpreter::NUMBER_ID));
+}
+
+void Area::Construct(void *data) {
+       new (data) Area;
+}
+
 }