X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FArea.cpp;h=e7d6f6635d8b284f7945bc2c5c2729238ccefbef;hb=092a2dd175a4001a495c84ee85211734fb928c83;hp=6b3f9b186373714aa384748e7a3ba10eb8f19b22;hpb=b8b3c5eb15fe990182e76a738953f444ccfbe06c;p=l2e.git diff --git a/src/map/Area.cpp b/src/map/Area.cpp index 6b3f9b1..e7d6f66 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -1,36 +1,45 @@ -/* - * 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 "../math/Vector.h" #include "../sdl/utility.h" #include -using geometry::Vector; +using math::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 &offset) const { +Tile *Area::TileAt(const math::Vector &offset) { + int tileIndex(offset.Y() * width + offset.X()); + if (tileIndex < numTiles) { + return tiles +tileIndex; + } else { + return 0; + } +} + +const Tile *Area::TileAt(const math::Vector &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; } } @@ -76,4 +85,21 @@ void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const } } + +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; +} + }