}
-const Tile &Area::TileAt(const geometry::Vector<int> &offset) const {
+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;
}
}
int Width() const { return width; }
int Height() const { return numTiles / width + (numTiles % width ? 1 : 0); }
geometry::Vector<int> Size() const { return geometry::Vector<int>(Width(), Height()); }
- const Tile &TileAt(const geometry::Vector<int> &) const;
+ const Tile *TileAt(const geometry::Vector<int> &) const;
void Render(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector<int> &offset) const;
void RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector<int> &offset) const;
}
-const Area &Map::AreaAt(const Vector<int> &offset) const {
+const Area *Map::AreaAt(const Vector<int> &offset) const {
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 areas + areaIndex;
}
}
- throw std::out_of_range("area offset out of bounds");
+ return 0;
}
-const Tile &Map::TileAt(const Vector<int> &offset) const {
- const Area &area(AreaAt(offset));
- Vector<int> tileOffset(TileCoordinates(offset) % area.Size());
- return area.TileAt(tileOffset);
+const Tile *Map::TileAt(const Vector<int> &offset) const {
+ const Area *area(AreaAt(offset));
+ if (area) {
+ Vector<int> tileOffset(TileCoordinates(offset) % area->Size());
+ return area->TileAt(tileOffset);
+ } else {
+ return 0;
+ }
}
Trigger *Map::TriggerAt(const geometry::Vector<int> &offset) {
public:
const graphics::Sprite *Tileset() const { return tileset; }
- const Area &AreaAt(const geometry::Vector<int> &) const;
- const Tile &TileAt(const geometry::Vector<int> &) const;
+ const Area *AreaAt(const geometry::Vector<int> &) const;
+ const Tile *TileAt(const geometry::Vector<int> &) const;
Trigger *TriggerAt(const geometry::Vector<int> &);
geometry::Vector<int> TileCoordinates(const geometry::Vector<int> &) const;
}
bool MapState::CheckBlocking() const {
- const Tile &tile(map->TileAt(controlled->Position()));
+ const Tile *tile(map->TileAt(controlled->Position()));
+ if (!tile) {
+ return false;
+ }
Vector<int> nextPosition;
switch (nextDirection) {
case Entity::ORIENTATION_NORTH:
- if (tile.BlocksNorth()) {
+ if (tile->BlocksNorth()) {
return true;
} else {
nextPosition = Vector<int>(
}
break;
case Entity::ORIENTATION_EAST:
- if (tile.BlocksEast()) {
+ if (tile->BlocksEast()) {
return true;
} else {
nextPosition = Vector<int>(
}
break;
case Entity::ORIENTATION_SOUTH:
- if (tile.BlocksSouth()) {
+ if (tile->BlocksSouth()) {
return true;
} else {
nextPosition = Vector<int>(
}
break;
case Entity::ORIENTATION_WEST:
- if (tile.BlocksWest()) {
+ if (tile->BlocksWest()) {
return true;
} else {
nextPosition = Vector<int>(