ULTIMA1: Splitting up classes into separate files, widget hierarchy improvements

This commit is contained in:
dreammaster 2020-01-21 05:49:55 +00:00 committed by Paul Gilbert
parent 026f5f9cd9
commit 561ca5b255
73 changed files with 2151 additions and 492 deletions

View File

@ -47,7 +47,12 @@ MODULE_OBJS += \
shared/gfx/viewport_map.o \
shared/gfx/visual_container.o \
shared/gfx/visual_item.o \
shared/gfx/visual_surface.o
shared/gfx/visual_surface.o \
shared/maps/map.o \
shared/maps/map_base.o \
shared/maps/map_tile.o \
shared/maps/map_widget.o \
shared/maps/creature.o
endif
ifdef ENABLE_ULTIMA1
@ -60,10 +65,12 @@ MODULE_OBJS += \
ultima1/actions/enter.o \
ultima1/actions/move.o \
ultima1/core/resources.o \
ultima1/map/map.o \
ultima1/map/map_city_castle.o \
ultima1/map/map_dungeon.o \
ultima1/map/map_overworld.o \
ultima1/maps/map.o \
ultima1/maps/map_base.o \
ultima1/maps/map_city_castle.o \
ultima1/maps/map_dungeon.o \
ultima1/maps/map_overworld.o \
ultima1/maps/map_tile.o \
ultima1/u1gfx/drawing_support.o \
ultima1/u1gfx/info.o \
ultima1/u1gfx/sprites.o \
@ -88,6 +95,7 @@ MODULE_OBJS += \
ultima1/widgets/princess.o \
ultima1/widgets/transport.o \
ultima1/widgets/urban_player.o \
ultima1/widgets/urban_widget.o \
ultima1/widgets/wench.o \
ultima1/game.o
endif

View File

@ -22,7 +22,7 @@
#include "ultima/shared/actions/action.h"
#include "ultima/shared/early/game.h"
#include "ultima/shared/core/map.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/gfx/visual_item.h"
#include "ultima/shared/engine/messages.h"
@ -39,8 +39,8 @@ Game *Action::getGame() {
return static_cast<Game *>(TreeItem::getGame());
}
Map *Action::getMap() {
return static_cast<Map *>(getGame()->getMap());
Maps::Map *Action::getMap() {
return static_cast<Maps::Map *>(getGame()->getMap());
}
void Action::addInfoMsg(const Common::String &text, bool newLine) {

View File

@ -29,10 +29,16 @@ namespace Ultima {
namespace Shared {
class Game;
namespace Maps {
class Map;
}
namespace Actions {
/**
* Base class for implementing the various actions the player can do, such as moving, climbing, entering, etc.
*/
class Action : public TreeItem {
public:
/**
@ -53,7 +59,7 @@ public:
/**
* Return the game's map
*/
Map *getMap();
Maps::Map *getMap();
/**
* Adds a text string to the info area

View File

@ -273,7 +273,7 @@ public:
/**
* Set the current direction
*/
void setDirection(Shared::Direction dir);
void setDirection(Direction dir);
/**
* Returns a delta for the cell in front of the player based on the direction they're facing
@ -336,7 +336,7 @@ public:
/**
* Instantiates a widget type by name
*/
virtual MapWidget *createWidget(Shared::Map::MapBase *map, const Common::String &name) = 0;
virtual MapWidget *createWidget(Map::MapBase *map, const Common::String &name) = 0;
/**
* Gets a tile at a given position
@ -389,7 +389,7 @@ public:
/**
* Get the current direction
*/
Shared::Direction getDirection() const {
Direction getDirection() const {
assert(_mapArea);
return _mapArea->getDirection();
}
@ -397,7 +397,7 @@ public:
/**
* Set the current direction
*/
void setDirection(Shared::Direction dir) {
void setDirection(Direction dir) {
assert(_mapArea);
_mapArea->setDirection(dir);
}

View File

@ -45,14 +45,14 @@ Game *TreeItem::getGame() {
return dynamic_cast<Game *>(treeItem);
}
const Shared::Game *TreeItem::getGame() const {
const Game *TreeItem::getGame() const {
const TreeItem *treeItem = this;
while (treeItem->getParent()) {
treeItem = treeItem->getParent();
}
return dynamic_cast<const Shared::Game *>(treeItem);
return dynamic_cast<const Game *>(treeItem);
}
TreeItem *TreeItem::getLastSibling() {

View File

@ -32,6 +32,10 @@ namespace Gfx {
class VisualItem;
} // End of namespace Gfx
namespace Maps {
class Map;
} // End of namespace Maps
class Game;
class GameManager;
class GameState;
@ -105,7 +109,7 @@ public:
/**
* Jumps up through the parents to find the root game
*/
const Shared::Game *getGame() const;
const Game *getGame() const;
/**
* Returns the currently active game view

View File

@ -22,7 +22,7 @@
#include "ultima/shared/early/game.h"
#include "ultima/shared/early/font_resources.h"
#include "ultima/shared/core/map.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/early/ultima_early.h"
#include "ultima/shared/gfx/font.h"
#include "ultima/shared/gfx/screen.h"

View File

@ -33,6 +33,10 @@ class GameView;
class GameState;
class FontResources;
namespace Maps {
class Map;
}
/**
* Party definition
*/
@ -96,7 +100,7 @@ public:
/**
* Pointer to the map manager for the game
*/
Map *_map;
Maps::Map *_map;
/**
* The number of hit points to generate when a dungeon is left
@ -144,7 +148,7 @@ public:
/**
* Returns the map
*/
virtual Shared::Map *getMap() const override { return _map; }
virtual Maps::Map *getMap() const override { return _map; }
/**
* Handles loading and saving games

View File

@ -37,12 +37,16 @@ class UltimaEngine;
class GameState;
namespace Gfx {
class Dialog;
class Font;
class TextCursor;
class TextInput;
class VisualItem;
}
class Dialog;
class Font;
class TextCursor;
class TextInput;
class VisualItem;
} // End of namespace Gfx
namespace Maps {
class Map;
} // End of namespace Maps
/**
* Base class for the game implementations
@ -157,7 +161,7 @@ public:
/**
* Returns the map
*/
virtual Shared::Map *getMap() const { return nullptr; }
virtual Maps::Map *getMap() const { return nullptr; }
/**
* Gets a random number

View File

@ -21,7 +21,7 @@
*/
#include "ultima/shared/gfx/dungeon_surface.h"
#include "ultima/shared/core/map.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/early/game.h"
namespace Ultima {

View File

@ -21,8 +21,10 @@
*/
#include "ultima/shared/gfx/viewport_dungeon.h"
#include "ultima/shared/core/widgets.h"
#include "ultima/shared/core/map.h"
#include "ultima/shared/maps/dungeon_widget.h"
#include "ultima/shared/maps/dungeon_creature.h"
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/early/game.h"
namespace Ultima {
@ -36,24 +38,24 @@ void ViewportDungeon::draw() {
s.clear();
// Get the position delta for the facing direction, and the cells to the left and right of that
Map *map = getGame()->getMap();
Maps::Map *map = getGame()->getMap();
Point delta = map->getDirectionDelta();
Point leftDelta, rightDelta;
switch (map->getDirection()) {
case DIR_LEFT:
case Maps::DIR_LEFT:
leftDelta.y = 1;
rightDelta.y = -1;
break;
case DIR_RIGHT:
case Maps::DIR_RIGHT:
leftDelta.y = -1;
rightDelta.y = 1;
break;
case DIR_UP:
case Maps::DIR_UP:
leftDelta.x = -1;
rightDelta.x = 1;
break;
case DIR_DOWN:
case Maps::DIR_DOWN:
leftDelta.x = 1;
rightDelta.x = -1;
break;
@ -61,7 +63,7 @@ void ViewportDungeon::draw() {
break;
}
MapTile tile, deltaTile, leftTile, rightTile, backTile;
Maps::MapTile tile, deltaTile, leftTile, rightTile, backTile;
Point currentPos = map->getPosition();
map->getTileAt(currentPos, &tile);
map->getTileAt(currentPos + delta, &deltaTile);
@ -143,7 +145,7 @@ void ViewportDungeon::draw() {
}
}
DungeonWidget *widget = dynamic_cast<DungeonWidget *>(tile._widget);
Maps::DungeonWidget *widget = dynamic_cast<Maps::DungeonWidget *>(tile._widget);
if (isDoor && widget) {
widget->draw(s, 0);
}
@ -158,10 +160,10 @@ uint ViewportDungeon::distanceToOccupiedCell(const Point &delta) {
}
bool ViewportDungeon::isCellOccupied(const Point &delta) {
Map *map = getGame()->getMap();
Maps::Map *map = getGame()->getMap();
Point pt = map->getPosition() + delta;
MapTile tile;
Maps::MapTile tile;
map->getTileAt(pt, &tile);
if (tile.isWallOrDoorway())
return true;
@ -170,21 +172,21 @@ bool ViewportDungeon::isCellOccupied(const Point &delta) {
}
bool ViewportDungeon::isMonsterBlocking(const Point &pt) {
MapTile tile;
Maps::MapTile tile;
getGame()->getMap()->getTileAt(pt, &tile);
DungeonCreature *monster = dynamic_cast<DungeonCreature *>(tile._widget);
Maps::DungeonCreature *monster = dynamic_cast<Maps::DungeonCreature *>(tile._widget);
return monster != nullptr && monster->isBlockingView();
}
void ViewportDungeon::drawCell(uint distance, const Point &pt) {
Game *game = getGame();
DungeonSurface s = getSurface();
Map *map = game->getMap();
Maps::Map *map = game->getMap();
MapTile tile;
Maps::MapTile tile;
map->getTileAt(pt, &tile);
DungeonCreature *monster = dynamic_cast<DungeonCreature *>(tile._widget);
Maps::DungeonCreature *monster = dynamic_cast<Maps::DungeonCreature *>(tile._widget);
if (monster) {
// Draw a monster
if (tile.isWallOrDoorway())
@ -210,7 +212,7 @@ void ViewportDungeon::drawCell(uint distance, const Point &pt) {
break;
case 6:
// Ladder down
if (map->getDirection() == DIR_UP || map->getDirection() == DIR_DOWN) {
if (map->getDirection() == Maps::DIR_UP || map->getDirection() == Maps::DIR_DOWN) {
s.drawLadderDownFaceOn(distance + 1);
} else {
s.drawLadderDownSideOn(distance + 1);
@ -218,7 +220,7 @@ void ViewportDungeon::drawCell(uint distance, const Point &pt) {
break;
case 7:
// Ladder up
if (map->getDirection() == DIR_UP || map->getDirection() == DIR_DOWN) {
if (map->getDirection() == Maps::DIR_UP || map->getDirection() == Maps::DIR_DOWN) {
s.drawLadderUpFaceOn(distance + 1);
} else {
s.drawLadderUpSideOn(distance + 1);
@ -234,12 +236,12 @@ void ViewportDungeon::drawCell(uint distance, const Point &pt) {
}
// Draw any item at that distance
DungeonWidget *widget = dynamic_cast<DungeonWidget *>(tile._widget);
Maps::DungeonWidget *widget = dynamic_cast<Maps::DungeonWidget *>(tile._widget);
if (widget)
widget->draw(s, distance);
}
void ViewportDungeon::drawLeftCell(uint distance, const MapTile &tile) {
void ViewportDungeon::drawLeftCell(uint distance, const Maps::MapTile &tile) {
DungeonSurface s = getSurface();
if (tile.isDoor())
@ -250,7 +252,7 @@ void ViewportDungeon::drawLeftCell(uint distance, const MapTile &tile) {
s.drawLeftBlank(distance);
}
void ViewportDungeon::drawRightCell(uint distance, const MapTile &tile) {
void ViewportDungeon::drawRightCell(uint distance, const Maps::MapTile &tile) {
DungeonSurface s = getSurface();
if (tile.isDoor())

View File

@ -25,7 +25,7 @@
#include "ultima/shared/gfx/visual_item.h"
#include "ultima/shared/gfx/dungeon_surface.h"
#include "ultima/shared/core/map.h"
#include "ultima/shared/maps/map_tile.h"
namespace Ultima {
namespace Shared {
@ -56,12 +56,12 @@ private:
/**
* Draw a cell to the left
*/
void drawLeftCell(uint distance, const MapTile &tile);
void drawLeftCell(uint distance, const Maps::MapTile &tile);
/**
* Draw a cell to the left
*/
void drawRightCell(uint distance, const MapTile &tile);
void drawRightCell(uint distance, const Maps::MapTile &tile);
protected:
/**
* Returns the surface for rendering the dungeon

View File

@ -21,7 +21,7 @@
*/
#include "ultima/shared/gfx/viewport_map.h"
#include "ultima/shared/core/map.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/early/game.h"
namespace Ultima {
@ -39,11 +39,11 @@ void ViewportMap::draw() {
const Point visibleTiles(_bounds.width() / spriteSize.x, _bounds.height() / spriteSize.y);
// Get a reference to the map and get the starting tile position
Map *map = getGame()->getMap();
Maps::Map *map = getGame()->getMap();
const Point topLeft = map->getViewportPosition(visibleTiles);
// Iterate through drawing the map
MapTile tile;
Maps::MapTile tile;
for (int y = 0; y < visibleTiles.y; ++y) {
for (int x = 0; x < visibleTiles.x; ++x) {
Point drawPos(x * spriteSize.x, y * spriteSize.y);

View File

@ -0,0 +1,42 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ultima/shared/maps/creature.h"
#include "ultima/shared/early/game.h"
namespace Ultima {
namespace Shared {
namespace Maps {
void Creature::update(bool isPreUpdate) {
if (isPreUpdate) {
// Check whether creature can attack
movement();
_isAttacking = attackDistance() != 0;
} else if (_isAttacking && !_gameRef->_party.isDead()) {
attack();
}
}
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima

View File

@ -0,0 +1,99 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_SHARED_WIDGETS_CREATURE_H
#define ULTIMA_SHARED_WIDGETS_CREATURE_H
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/maps/map.h"
#include "common/serializer.h"
namespace Ultima {
namespace Shared {
class Game;
class Map;
namespace Maps {
/**
* Base class for creatures that can be killed
*/
class Creature {
private:
Game *_gameRef;
MapBase *_mapRef;
protected:
int _hitPoints;
bool _isAttacking;
protected:
/**
* Returns either the maximum attack distance for a monster, or 0 if the monster is beyond
* that distance from the player
*/
virtual uint attackDistance() const { return 0; }
/**
* Handles moving creatures
*/
virtual void movement() {}
/**
* Handles attacks
*/
virtual void attack() {}
public:
/**
* Constructor
*/
Creature(Game *game, MapBase *map) : _gameRef(game), _mapRef(map), _hitPoints(0), _isAttacking(false) {}
Creature(Game *game, MapBase *map, int hitPoints) : _gameRef(game), _mapRef(map),
_hitPoints(hitPoints), _isAttacking(false) {}
/**
* Destructor
*/
virtual ~Creature() {}
/**
* Handles loading and saving games
*/
void synchronize(Common::Serializer &s);
/**
* Called to update the widget at the end of a turn
* @param isPreUpdate Update is called twice in succesion during the end of turn update.
* Once with true for all widgets, then with it false
*/
virtual void update(bool isPreUpdate);
/**
* True true if the creature is dead
*/
bool isDead() const { return _hitPoints <= 0; }
};
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima
#endif

View File

@ -0,0 +1,67 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_SHARED_MAPS_DUNGEON_CREATURE_H
#define ULTIMA_SHARED_MAPS_DUNGEON_CREATURE_H
#include "ultima/shared/maps/creature.h"
namespace Ultima {
namespace Shared {
class Game;
class Map;
namespace Maps {
/**
* Stub class for dungeon creatures
*/
class DungeonCreature : public Creature {
public:
/**
* Constructor
*/
DungeonCreature(Game *game, MapBase *map) : Creature(game, map) {}
DungeonCreature(Game *game, MapBase *map, int hitPoints) : Creature(game, map, hitPoints) {}
/**
* Destructor
*/
virtual ~DungeonCreature() {}
/**
* Returns true if a monster blocks the background behind him
*/
virtual bool isBlockingView() const = 0;
/**
* Draw a monster
*/
virtual void draw(DungeonSurface &s, uint distance) = 0;
};
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima
#endif

View File

@ -0,0 +1,68 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_SHARED_MAPS_DUNGEON_WIDGET_H
#define ULTIMA_SHARED_MAPS_DUNGEON_WIDGET_H
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/gfx/dungeon_surface.h"
#include "common/serializer.h"
#include "common/str.h"
namespace Ultima {
namespace Shared {
class Game;
class Map;
namespace Maps {
/**
* Base class for things that appear within the dungeons
*/
class DungeonWidget : public MapWidget {
public:
/**
* Constructor
*/
DungeonWidget(Game *game, Maps::MapBase *map) : MapWidget(game, map) {}
DungeonWidget(Game *game, Maps::MapBase *map, const Point &pt, Direction dir = DIR_NONE) : MapWidget(game, map, pt, dir) {}
DungeonWidget(Game *game, Maps::MapBase *map, const Common::String &name, const Point &pt, Direction dir = DIR_NONE) :
MapWidget(game, map, name, pt, dir) {}
/**
* Destructor
*/
virtual ~DungeonWidget() {}
/**
* Draws an item
*/
virtual void draw(DungeonSurface &s, uint distance) = 0;
};
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima
#endif

View File

@ -0,0 +1,59 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ultima/shared/maps/map.h"
#include "ultima/shared/early/game.h"
#include "ultima/shared/gfx/visual_item.h"
namespace Ultima {
namespace Shared {
namespace Maps {
void Map::clear() {
if (_mapArea)
_mapArea->clear();
_mapArea = nullptr;
}
void Map::load(MapId mapId) {
_mapArea = nullptr;
}
void Map::synchronize(Common::Serializer &s) {
int mapId;
if (s.isSaving()) {
// Saving
mapId = _mapArea->getMapId();
s.syncAsUint16LE(mapId);
} else {
// Loading
s.syncAsUint16LE(mapId);
load(mapId);
}
_mapArea->synchronize(s);
}
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima

View File

@ -0,0 +1,232 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_SHARED_MAPS_MAP_H
#define ULTIMA_SHARED_MAPS_MAP_H
#include "common/array.h"
#include "common/serializer.h"
#include "ultima/shared/core/rect.h"
#include "ultima/shared/maps/map_base.h"
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/maps/map_tile.h"
namespace Ultima {
namespace Shared {
class Game;
namespace Maps {
#define REGISTER_WIDGET(NAME) if (name == #NAME) return new Widgets::NAME(_game, (MapBase *)map)
#define DECLARE_WIDGET(NAME) virtual const char *getClassName() const override { return #NAME; }
/**
* Base class for managing maps within the game
*/
class Map {
protected:
MapBase *_mapArea;
public:
/**
* Constructor
*/
Map() : _mapArea(nullptr) {}
/**
* Destructor
*/
virtual ~Map() {}
/**
* Load a given map
*/
virtual void load(MapId mapId);
/**
* Clears all map data
*/
virtual void clear();
/**
* Handles loading and saving the map's data
*/
virtual void synchronize(Common::Serializer &s);
/**
* Instantiates a widget type by name
*/
virtual MapWidget *createWidget(MapBase *map, const Common::String &name) = 0;
/**
* Gets a tile at a given position
*/
void getTileAt(const Point &pt, MapTile *tile) {
assert(_mapArea);
return _mapArea->getTileAt(pt, tile);
}
/**
* Get the viewport position
*/
Point getViewportPosition(const Point &viewportSize) {
assert(_mapArea);
return _mapArea->getViewportPosition(viewportSize);
}
/**
* Return the width of the map
*/
size_t width() const {
assert(_mapArea);
return _mapArea->width();
}
/**
* Return the height of the map
*/
size_t height() const {
assert(_mapArea);
return _mapArea->height();
}
/**
* Return the current position
*/
Point getPosition() const {
assert(_mapArea);
return _mapArea->getPosition();
}
/**
* Set the position
*/
void setPosition(const Point &pt) {
assert(_mapArea);
_mapArea->setPosition(pt);
}
/**
* Get the current direction
*/
Direction getDirection() const {
assert(_mapArea);
return _mapArea->getDirection();
}
/**
* Set the current direction
*/
void setDirection(Direction dir) {
assert(_mapArea);
_mapArea->setDirection(dir);
}
/**
* Returns a delta for the cell in front of the player based on the direction they're facing
*/
Point getDirectionDelta() const {
assert(_mapArea);
return _mapArea->getDirectionDelta();
}
/**
* Gets a point relative to the current position
*/
Point getDeltaPosition(const Point &delta) {
assert(_mapArea);
return _mapArea->getDeltaPosition(delta);
}
/**
* Shifts the viewport by a given delta
*/
void shiftViewport(const Point &delta) {
assert(_mapArea);
_mapArea->shiftViewport(delta);
}
/**
* Returns the number of tiles in the map there are for each tile in the original game.
* This allows for more detailed maps in the enhanced game modes
*/
Point getTilesPerOrigTile() const {
assert(_mapArea);
return _mapArea->_tilesPerOrigTile;
}
/**
* Return the name of the map
*/
Common::String getName() const {
assert(_mapArea);
return _mapArea->_name;
}
/**
* Returns the currently active widget that the player is controlling
*/
MapWidget *getPlayerWidget() const {
assert(_mapArea);
return _mapArea->_playerWidget;
}
/**
* @param delta Delta to change dungeon level by
* @returns False if dungeon left, true if still within dungeon
*/
bool changeLevel(int delta) {
assert(_mapArea);
return _mapArea->changeLevel(delta);
}
/**
* Get the current map level
*/
uint getLevel() const {
assert(_mapArea);
return _mapArea->getLevel();
}
/**
* Returns whether the map wraps around to the other side at it's edges (i.e. the overworld)
*/
bool isMapWrapped() const {
assert(_mapArea);
return _mapArea->isMapWrapped();
}
/**
* Updates the map at the end of a turn
*/
void update() {
assert(_mapArea);
return _mapArea->update();
}
};
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima
#endif

View File

@ -0,0 +1,200 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ultima/shared/maps/map_base.h"
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/early/game.h"
#include "ultima/shared/gfx/visual_item.h"
namespace Ultima {
namespace Shared {
namespace Maps {
void MapBase::clear() {
_mapId = 0;
_data.clear();
_widgets.clear();
}
void MapBase::load(MapId mapId) {
_mapId = mapId;
}
void MapBase::synchronize(Common::Serializer &s) {
_viewportPos.synchronize(s);
uint size;
int transportIndex = -1;
Common::String name;
if (s.isSaving()) {
// Save widgets
size = 0;
for (uint idx = 0; idx < _widgets.size(); ++idx) {
if (_widgets[idx]->getClassName())
++size;
if (_playerWidget == _widgets[idx].get())
transportIndex = (int)idx;
}
assert(transportIndex >= 0);
s.syncAsUint16LE(size);
for (uint idx = 0; idx < _widgets.size(); ++idx) {
name = _widgets[idx]->getClassName();
if (!name.empty()) {
s.syncString(name);
_widgets[idx]->synchronize(s);
}
}
s.syncAsUint16LE(transportIndex);
} else {
// Load widgets
s.syncAsUint16LE(size);
_widgets.clear();
for (uint idx = 0; idx < size; ++idx) {
s.syncString(name);
MapWidget *w = _map->createWidget(this, name);
w->synchronize(s);
addWidget(w);
}
s.syncAsUint16LE(transportIndex);
_playerWidget = _widgets[transportIndex].get();
}
}
void MapBase::setDimensions(const Point &size) {
_data.resize(size.y);
for (int y = 0; y < size.y; ++y)
_data[y].resize(size.x);
_size = size;
}
Point MapBase::getDirectionDelta() const {
switch (_playerWidget->_direction) {
case DIR_LEFT:
return Point(-1, 0);
case DIR_RIGHT:
return Point(1, 0);
case DIR_UP:
return Point(0, -1);
default:
return Point(0, 1);
}
}
Point MapBase::getDeltaPosition(const Point &delta) {
return _playerWidget->_position + delta;
}
void MapBase::resetViewport() {
// Reset the viewport, so it's position will get recalculated
_viewportPos.reset();
}
Point MapBase::getViewportPosition(const Point &viewportSize) {
Point &topLeft = _viewportPos._topLeft;
if (!_viewportPos.isValid() || _viewportPos._size != viewportSize) {
// Calculate the new position
topLeft.x = _playerWidget->_position.x - (viewportSize.x - 1) / 2;
topLeft.y = _playerWidget->_position.y - (viewportSize.y - 1) / 2;
// Fixed maps, so constrain top left corner so the map fills the viewport.
// This will accomodate future renderings with more tiles, or greater tile size
topLeft.x = CLIP((int)topLeft.x, 0, (int)(width() - viewportSize.x));
topLeft.y = CLIP((int)topLeft.y, 0, (int)(height() - viewportSize.y));
}
return topLeft;
}
void MapBase::shiftViewport(const Point &delta) {
Point &topLeft = _viewportPos._topLeft;
topLeft += delta;
// Shift the viewport, but constraining the map to fill up the screen
topLeft.x = CLIP(topLeft.x, (int16)0, (int16)(width() - _viewportPos._size.x));
topLeft.y = CLIP(topLeft.y, (int16)0, (int16)(height() - _viewportPos._size.y));
}
void MapBase::addWidget(MapWidget *widget) {
_widgets.push_back(MapWidgetPtr(widget));
}
void MapBase::removeWidget(MapWidget *widget) {
for (uint idx = 0; idx < _widgets.size(); ++idx) {
if (_widgets[idx].get() == widget) {
_widgets.remove_at(idx);
break;
}
}
}
void MapBase::getTileAt(const Point &pt, MapTile *tile) {
tile->clear();
// Get the base tile
tile->_tileNum = tile->_tileId = _data[pt.y][pt.x];
// Check for any widget on that map tile
for (int idx = (int)_widgets.size() - 1; idx >= 0; --idx) {
MapWidget *widget = _widgets[idx].get();
if (widget->_position == pt) {
tile->_widgetNum = idx;
tile->_widget = widget;
break;
}
}
}
void MapBase::update() {
// Call the update method of each widget, to allow for things like npc movement, etc.
for (uint idx = 0; idx < _widgets.size(); ++idx)
_widgets[idx].get()->update(true);
// Call the update method of each widget, to allow for things like npc movement, etc.
for (uint idx = 0; idx < _widgets.size(); ++idx)
_widgets[idx].get()->update(false);
}
Point MapBase::getPosition() const {
return _playerWidget->_position;
}
void MapBase::setPosition(const Point &pt) {
_playerWidget->_position = pt;
}
Direction MapBase::getDirection() const {
return _playerWidget->_direction;
}
void MapBase::setDirection(Direction dir) {
_playerWidget->_direction = dir;
}
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima

View File

@ -0,0 +1,251 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_SHARED_MAPS_MAP_BASE_H
#define ULTIMA_SHARED_MAPS_MAP_BASE_H
#include "common/array.h"
#include "common/serializer.h"
#include "ultima/shared/core/rect.h"
#include "ultima/shared/maps/map_widget.h"
namespace Ultima {
namespace Shared {
class Game;
namespace Maps {
typedef int MapId;
typedef byte MapCell;
class Map;
class MapTile;
/**
* Base class for specific map types
*/
class MapBase {
/**
* Internal class used for storing the data for a row
*/
struct MapCellsRow {
private:
Common::Array<MapCell> _data;
public:
byte &operator[](int idx) { return _data[idx]; }
byte operator[](int idx) const { return _data[idx]; }
/**
* Resize the row
*/
void resize(size_t newSize) { _data.resize(newSize); }
};
/**
* Stores state about the current viewport being displayed. It's kept as part of the Map class
* as a convenience to be alongside the current party position
*/
struct ViewportPosition {
Point _topLeft; // Top, left tile position for viewport
Point _size; // Size of the viewport. Just in case we ever allow it to change
MapId _mapId; // Maze the viewport is for. Used to detect when the map changes
/**
* Constructor
*/
ViewportPosition() : _topLeft(-1, -1), _mapId(-1) {}
/**
* Returns true if the viewport is in a valid state
*/
bool isValid() const { return _mapId != -1; }
/**
* Handles loading and saving viewport
*/
void synchronize(Common::Serializer &s) {
s.syncAsUint16LE(_topLeft.x);
s.syncAsUint16LE(_topLeft.y);
}
/**
* Resets the viewport position, so it'll get recalculated the next call to getViewportPosition
*/
void reset() { _mapId = -1; }
};
private:
Map *_map; // Map manager reference
Game *_game; // Game reference
protected:
MapId _mapId; // The map Id
uint _mapIndex; // Index of map within the group of same maps
uint _mapStyle; // Map style category for towns & castles
ViewportPosition _viewportPos; // Viewport position
protected:
/**
* Set the size of the map
*/
void setDimensions(const Point &size);
public:
Point _size; // X, Y size of the map
Point _tilesPerOrigTile; // For enhanced modes, number of tiles per original game tile
Common::String _name; // Name of map, if applicable
MapWidget *_playerWidget; // Current means of transport, even if on foot
Common::Array<MapWidgetPtr> _widgets; // Party, monsteres, transports, etc.
Common::Array<MapCellsRow> _data; // Data for the map
public:
/**
* Constructor
*/
MapBase(Game *game, Map *map) : _game(game), _map(map), _playerWidget(nullptr), _mapId(0), _mapIndex(0),
_mapStyle(0) {}
/**
* Destructor
*/
virtual ~MapBase() {}
/**
* Handles loading and saving the map's data
*/
virtual void synchronize(Common::Serializer &s);
/**
* Adds a widget to the map
*/
void addWidget(MapWidget *widget);
/**
* Removes a widget from the map
*/
void removeWidget(MapWidget *widget);
/**
* Clears all map data
*/
virtual void clear();
/**
* Gets a tile at a given position
*/
virtual void getTileAt(const Point &pt, MapTile *tile);
/**
* Resets the viewport when the viewport changes
*/
void resetViewport();
/**
* Get the viewport position
*/
virtual Point getViewportPosition(const Point &viewportSize);
/**
* Load the map
*/
virtual void load(MapId mapId);
/**
* Changes the level. Only applicable to dungeon maps which have levels
* @param delta Delta to change dungeon level by
* @returns False if dungeon left, true if still within dungeon
*/
virtual bool changeLevel(int delta) { return true; }
/**
* Get the current map level
*/
virtual uint getLevel() const { return 0; }
/**
* Returns whether the map wraps around to the other side at it's edges (i.e. the overworld)
*/
virtual bool isMapWrapped() const { return false; }
/**
* Returns the width of the map
*/
size_t width() const { return _size.x; }
/**
* Returns the height of the map
*/
size_t height() const { return _size.y; }
/**
* Get the current position
*/
Point getPosition() const;
/**
* Set the current position
*/
void setPosition(const Point &pt);
/**
* Get the current direction
*/
Direction getDirection() const;
/**
* Set the current direction
*/
void setDirection(Direction dir);
/**
* Returns a delta for the cell in front of the player based on the direction they're facing
*/
Point getDirectionDelta() const;
/**
* Gets a point relative to the current position
*/
virtual Point getDeltaPosition(const Point &delta);
/**
* Returns the map Id
*/
MapId getMapId() const { return _mapId; }
/**
* Gets the map Index
*/
uint getMapIndex() const { return _mapIndex; }
/**
* Shifts the viewport by a given delta
*/
virtual void shiftViewport(const Point &delta);
/**
* Updates the map at the end of a turn
*/
virtual void update();
};
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima
#endif

View File

@ -0,0 +1,42 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ultima/shared/maps/map_tile.h"
#include "ultima/shared/maps/map_widget.h"
namespace Ultima {
namespace Shared {
namespace Maps {
void MapTile::clear() {
_tileId = _tileNum = -1;
_widgetNum = -1;
_widget = nullptr;
_itemNum = -1;
_isDoor = _isSecretDoor = false;
_isLadderUp = _isLadderDown = false;
_isWall = _isHallway = _isBeams = false;
}
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima

View File

@ -0,0 +1,89 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_SHARED_MAPS_MAP_TILE_H
#define ULTIMA_SHARED_MAPS_MAP_TILE_H
namespace Ultima {
namespace Shared {
namespace Maps {
class MapWidget;
/**
* Contains data about a given position within the map
*/
class MapTile {
public:
int _tileId; // Tile Id
int _tileNum; // Tile number to display. Normally equals Tile Id, but can differ in rare cases
int _widgetNum; // Widget number, if any
MapWidget *_widget; // Widget pointer
int _itemNum; // Item number, if any
// Dungeon tile flags
bool _isDoor, _isSecretDoor;
bool _isLadderUp, _isLadderDown;
bool _isWall, _isHallway, _isBeams;
public:
/**
* Constructor
*/
MapTile() : _tileNum(-1), _tileId(-1), _widgetNum(-1), _widget(0), _itemNum(-1),
_isDoor(false), _isSecretDoor(false), _isLadderUp(false), _isLadderDown(false), _isWall(false),
_isHallway(false), _isBeams(false) {}
/**
* Destructor
*/
virtual ~MapTile() {}
/**
* Clears the map tile information
*/
virtual void clear();
/**
* Returns true if the tile is a door in a dungeon
*/
bool isDoor() const { return _isDoor; }
/**
* Returns true if the tile is a wall or secret door in a dungeon
*/
bool isWallOrSecretDoor() const { return _isWall || _isSecretDoor; }
/**
* Returns true if the tile in a dungeon is a type that has walls on it: walls, doors, or secret doors
*/
bool isWallOrDoorway() const { return _isWall || _isDoor || _isSecretDoor; }
/**
* Returns true if a tile is a solid type within a dungeon
*/
bool isSolid() const { return !(_isHallway || _isLadderUp || _isLadderDown || _isBeams); }
};
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima
#endif

View File

@ -0,0 +1,93 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/maps/map_base.h"
#include "ultima/shared/maps/map_tile.h"
#include "ultima/shared/early/game.h"
#include "ultima/shared/gfx/visual_item.h"
namespace Ultima {
namespace Shared {
namespace Maps {
void MapWidget::synchronize(Common::Serializer &s) {
s.syncAsUint16LE(_position.x);
s.syncAsSint16LE(_position.y);
s.syncAsByte(_direction);
s.syncString(_name);
}
void MapWidget::addInfoMsg(const Common::String &text, bool newLine) {
CInfoMsg msg(text, newLine);
msg.execute(_game->getView());
}
MapWidget::CanMove MapWidget::canMoveTo(const Point &destPos) {
if (destPos.x < 0 || destPos.y < 0 || destPos.x >= (int)_map->width() || destPos.y >= (int)_map->height()) {
// If the map is fixed, allow moving beyond it's edges so it can be left
if (!_map->isMapWrapped())
return YES;
}
// Get the details of the position
MapTile destTile;
_map->getTileAt(destPos, &destTile);
// If there's a widget blocking the tile, return false
if (destTile._widget && destTile._widget->isBlocking())
return NO;
return UNSET;
}
void MapWidget::moveTo(const Point &destPos, Direction dir) {
// If no direction is specified, we'll need to figure it out relative to the old position
if (dir == DIR_NONE) {
Point delta = destPos - _position;
if (ABS(delta.x) > ABS(delta.y))
_direction = delta.x > 0 ? DIR_EAST : DIR_WEST;
else if (delta.y != 0)
_direction = delta.y > 0 ? DIR_SOUTH : DIR_NORTH;
} else {
_direction = dir;
}
// Set new location
_position = destPos;
// Handle wrap around if need be on maps that wrap
if (_map->isMapWrapped()) {
if (_position.x < 0)
_position.x += _map->width();
else if (_position.x >= (int)_map->width())
_position.x -= _map->width();
if (_position.y < 0)
_position.y += _map->height();
else if (_position.y >= (int)_map->height())
_position.y -= _map->height();
}
}
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima

View File

@ -0,0 +1,127 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_SHARED_MAPS_MAP_WIDGET_H
#define ULTIMA_SHARED_MAPS_MAP_WIDGET_H
#include "common/ptr.h"
#include "common/serializer.h"
#include "common/str.h"
#include "ultima/shared/core/rect.h"
namespace Ultima {
namespace Shared {
class Game;
namespace Maps {
enum Direction {
DIR_NONE = 0,
DIR_LEFT = 1, DIR_RIGHT = 2, DIR_UP = 3, DIR_DOWN = 4,
DIR_WEST = 1, DIR_EAST = 2, DIR_NORTH = 3, DIR_SOUTH = 4
};
class MapBase;
/**
* Base class for things that appear within a map, such as monsters, transports, or people
*/
class MapWidget {
protected:
Game *_game; // Game reference
MapBase *_map; // Map reference
public:
Point _position; // Position within the map
Direction _direction; // Direction
Common::String _name; // Name of widget
public:
/**
* Constructor
*/
MapWidget(Game *game, MapBase *map) : _game(game), _map(map) {}
MapWidget(Game *game, MapBase *map, const Point &pt, Direction dir = DIR_NONE) : _game(game), _map(map), _position(pt), _direction(dir) {}
MapWidget(Game *game, MapBase *map, const Common::String &name, const Point &pt, Direction dir = DIR_NONE) :
_game(game), _map(map), _name(name), _position(pt), _direction(dir) {}
/**
* Destructor
*/
virtual ~MapWidget() {}
/**
* Return a name for a widget class if it can be synchronized to savegames
*/
virtual const char *getClassName() const { return nullptr; }
/**
* Handles loading and saving games
*/
virtual void synchronize(Common::Serializer &s);
/**
* Adds a text string to the info area
* @param text Text to add
* @param newLine Whether to apply a newline at the end
*/
void addInfoMsg(const Common::String &text, bool newLine = true);
/**
* Get the tile for the widget
*/
virtual uint getTileNum() const { return 0; }
/**
* Returns true if the player can move onto a tile the widget occupies
*/
virtual bool isBlocking() const { return false; }
/**
* Called to update the widget at the end of a turn
* @param isPreUpdate Update is called twice in succesion during the end of turn update.
* Once with true for all widgets, then with it false
*/
virtual void update(bool isPreUpdate) {}
enum CanMove { UNSET = 0, YES = 1, NO = 2 };
/**
* Returns true if the given widget can move to a given position on the map
*/
virtual CanMove canMoveTo(const Point &destPos);
/**
* Moves the widget to a given position
* @param destPos Specified new position
* @param dir Optional explicit direction to set. If not specified,
* the direction will be set relative to the position moved from
*/
virtual void moveTo(const Point &destPos, Direction dir = DIR_NONE);
};
typedef Common::SharedPtr<MapWidget> MapWidgetPtr;
} // End of namespace Maps
} // End of namespace Shared
} // End of namespace Ultima
#endif

View File

@ -22,7 +22,7 @@
#include "ultima/ultima1/actions/action.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/shared/gfx/visual_item.h"
#include "ultima/shared/engine/messages.h"
@ -35,8 +35,8 @@ Ultima1Game *Action::getGame() {
return static_cast<Ultima1Game *>(TreeItem::getGame());
}
Map::Ultima1Map *Action::getMap() {
return static_cast<Map::Ultima1Map *>(getGame()->getMap());
Maps::Ultima1Map *Action::getMap() {
return static_cast<Maps::Ultima1Map *>(getGame()->getMap());
}
GameResources *Action::getRes() {

View File

@ -30,7 +30,7 @@ namespace Ultima1 {
class Ultima1Game;
class GameResources;
namespace Map {
namespace Maps {
class Ultima1Map;
}
@ -56,7 +56,7 @@ public:
/**
* Return the game's map
*/
Map::Ultima1Map *getMap();
Maps::Ultima1Map *getMap();
/**
* Gets the data resources for the game

View File

@ -22,7 +22,9 @@
#include "ultima/ultima1/actions/climb.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/map/map_dungeon.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_tile.h"
#include "ultima/ultima1/maps/map_dungeon.h"
#include "ultima/ultima1/core/resources.h"
namespace Ultima {
@ -34,16 +36,16 @@ BEGIN_MESSAGE_MAP(Climb, Action)
END_MESSAGE_MAP()
bool Climb::ClimbMsg(CClimbMsg &msg) {
Map::Ultima1Map *map = getMap();
Map::U1MapTile mapTile;
Maps::Ultima1Map *map = getMap();
Maps::U1MapTile mapTile;
map->getTileAt(map->getPosition(), &mapTile);
if (mapTile._tileNum != Map::DTILE_LADDER_UP && mapTile._tileNum != Map::DTILE_LADDER_DOWN) {
if (mapTile._tileNum != Maps::DTILE_LADDER_UP && mapTile._tileNum != Maps::DTILE_LADDER_DOWN) {
playFX(1);
} else if (map->getDirection() == Shared::DIR_LEFT || map->getDirection() == Shared::DIR_RIGHT) {
} else if (map->getDirection() == Shared::Maps::DIR_LEFT || map->getDirection() == Shared::Maps::DIR_RIGHT) {
playFX(1);
} else if (mapTile._tileNum == Map::DTILE_LADDER_UP) {
} else if (mapTile._tileNum == Maps::DTILE_LADDER_UP) {
ladderUp();
} else {
ladderDown();
@ -53,15 +55,15 @@ bool Climb::ClimbMsg(CClimbMsg &msg) {
}
void Climb::ladderUp() {
Map::Ultima1Map *map = getMap();
Maps::Ultima1Map *map = getMap();
if (!map->changeLevel(-1)) {
map->load(Map::MAPID_OVERWORLD);
map->load(Maps::MAPID_OVERWORLD);
}
}
void Climb::ladderDown() {
Map::Ultima1Map *map = getMap();
Maps::Ultima1Map *map = getMap();
map->changeLevel(1);
}

View File

@ -22,7 +22,8 @@
#include "ultima/ultima1/actions/enter.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_tile.h"
#include "ultima/ultima1/core/resources.h"
namespace Ultima {
@ -35,8 +36,8 @@ END_MESSAGE_MAP()
bool Enter::EnterMsg(CEnterMsg &msg) {
Ultima1Game *game = getGame();
Map::Ultima1Map *map = getMap();
Map::U1MapTile mapTile;
Maps::Ultima1Map *map = getMap();
Maps::U1MapTile mapTile;
map->getTileAt(map->getPosition(), &mapTile);

View File

@ -22,7 +22,7 @@
#include "ultima/ultima1/actions/move.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/widgets/transport.h"
#include "ultima/ultima1/core/resources.h"
@ -35,47 +35,47 @@ BEGIN_MESSAGE_MAP(Move, Action)
END_MESSAGE_MAP()
bool Move::MoveMsg(CMoveMsg &msg) {
Map::Ultima1Map *map = getMap();
Maps::Ultima1Map *map = getMap();
if (map->_mapType == Map::MAP_DUNGEON) {
if (map->_mapType == Maps::MAP_DUNGEON) {
switch (msg._direction) {
case Shared::DIR_LEFT:
case Shared::Maps::DIR_LEFT:
dungeonTurnLeft();
break;
case Shared::DIR_RIGHT:
case Shared::Maps::DIR_RIGHT:
dungeonTurnRight();
break;
case Shared::DIR_DOWN:
case Shared::Maps::DIR_DOWN:
dungeonTurnAround();
break;
case Shared::DIR_UP:
case Shared::Maps::DIR_UP:
dungeonMoveForward();
break;
}
} else {
Shared::MapWidget *player = map->getPlayerWidget();
Shared::Maps::MapWidget *player = map->getPlayerWidget();
assert(player);
// Figure out the new position
Point delta;
switch (msg._direction) {
case Shared::DIR_LEFT:
case Shared::Maps::DIR_WEST:
delta = Point(-1, 0);
break;
case Shared::DIR_RIGHT:
case Shared::Maps::DIR_EAST:
delta = Point(1, 0);
break;
case Shared::DIR_UP:
case Shared::Maps::DIR_NORTH:
delta = Point(0, -1);
break;
case Shared::DIR_DOWN:
case Shared::Maps::DIR_SOUTH:
delta = Point(0, 1);
break;
}
// Check if the player's widget type can move to the new position
Point newPos = map->getDeltaPosition(delta);
if (player->canMoveTo(newPos) == Shared::MapWidget::YES) {
if (player->canMoveTo(newPos) == Shared::Maps::MapWidget::YES) {
// Shift the viewport
map->shiftViewport(delta);
@ -93,87 +93,87 @@ bool Move::MoveMsg(CMoveMsg &msg) {
}
void Move::dungeonTurnLeft() {
Map::Ultima1Map *map = getMap();
Maps::Ultima1Map *map = getMap();
switch (map->getDirection()) {
case Shared::DIR_LEFT:
map->setDirection(Shared::DIR_DOWN);
case Shared::Maps::DIR_LEFT:
map->setDirection(Shared::Maps::DIR_DOWN);
break;
case Shared::DIR_RIGHT:
map->setDirection(Shared::DIR_UP);
case Shared::Maps::DIR_RIGHT:
map->setDirection(Shared::Maps::DIR_UP);
break;
case Shared::DIR_DOWN:
map->setDirection(Shared::DIR_RIGHT);
case Shared::Maps::DIR_DOWN:
map->setDirection(Shared::Maps::DIR_RIGHT);
break;
case Shared::DIR_UP:
map->setDirection(Shared::DIR_LEFT);
case Shared::Maps::DIR_UP:
map->setDirection(Shared::Maps::DIR_LEFT);
break;
default:
break;
}
addInfoMsg(getGame()->_res->DUNGEON_MOVES[Shared::DIR_LEFT - 1]);
addInfoMsg(getGame()->_res->DUNGEON_MOVES[Shared::Maps::DIR_LEFT - 1]);
}
void Move::dungeonTurnRight() {
Map::Ultima1Map *map = getMap();
Maps::Ultima1Map *map = getMap();
switch (map->getDirection()) {
case Shared::DIR_LEFT:
map->setDirection(Shared::DIR_UP);
case Shared::Maps::DIR_LEFT:
map->setDirection(Shared::Maps::DIR_UP);
break;
case Shared::DIR_RIGHT:
map->setDirection(Shared::DIR_DOWN);
case Shared::Maps::DIR_RIGHT:
map->setDirection(Shared::Maps::DIR_DOWN);
break;
case Shared::DIR_DOWN:
map->setDirection(Shared::DIR_LEFT);
case Shared::Maps::DIR_DOWN:
map->setDirection(Shared::Maps::DIR_LEFT);
break;
case Shared::DIR_UP:
map->setDirection(Shared::DIR_RIGHT);
case Shared::Maps::DIR_UP:
map->setDirection(Shared::Maps::DIR_RIGHT);
break;
default:
break;
}
addInfoMsg(getGame()->_res->DUNGEON_MOVES[Shared::DIR_RIGHT - 1]);
addInfoMsg(getGame()->_res->DUNGEON_MOVES[Shared::Maps::DIR_RIGHT - 1]);
}
void Move::dungeonTurnAround() {
Map::Ultima1Map *map = getMap();
Maps::Ultima1Map *map = getMap();
switch (map->getDirection()) {
case Shared::DIR_LEFT:
map->setDirection(Shared::DIR_RIGHT);
case Shared::Maps::DIR_LEFT:
map->setDirection(Shared::Maps::DIR_RIGHT);
break;
case Shared::DIR_RIGHT:
map->setDirection(Shared::DIR_LEFT);
case Shared::Maps::DIR_RIGHT:
map->setDirection(Shared::Maps::DIR_LEFT);
break;
case Shared::DIR_DOWN:
map->setDirection(Shared::DIR_UP);
case Shared::Maps::DIR_DOWN:
map->setDirection(Shared::Maps::DIR_UP);
break;
case Shared::DIR_UP:
map->setDirection(Shared::DIR_DOWN);
case Shared::Maps::DIR_UP:
map->setDirection(Shared::Maps::DIR_DOWN);
break;
default:
break;
}
addInfoMsg(getGame()->_res->DUNGEON_MOVES[Shared::DIR_DOWN - 1]);
addInfoMsg(getGame()->_res->DUNGEON_MOVES[Shared::Maps::DIR_DOWN - 1]);
}
void Move::dungeonMoveForward() {
Map::Ultima1Map *map = getMap();
Maps::Ultima1Map *map = getMap();
Point delta = map->getDirectionDelta();
Shared::MapWidget *player = map->getPlayerWidget();
Shared::Maps::MapWidget *player = map->getPlayerWidget();
assert(player);
if (player->canMoveTo(map->getPosition() + delta) == Shared::MapWidget::YES) {
if (player->canMoveTo(map->getPosition() + delta) == Shared::Maps::MapWidget::YES) {
map->setPosition(map->getPosition() + delta);
} else {
playFX(0);
}
addInfoMsg(getGame()->_res->DUNGEON_MOVES[Shared::DIR_UP - 1]);
addInfoMsg(getGame()->_res->DUNGEON_MOVES[Shared::Maps::DIR_UP - 1]);
}
} // End of namespace Actions

View File

@ -22,7 +22,7 @@
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/u1gfx/view_game.h"
#include "ultima/ultima1/u1gfx/view_char_gen.h"
#include "ultima/ultima1/u1gfx/view_title.h"
@ -38,7 +38,7 @@ EMPTY_MESSAGE_MAP(Ultima1Game, Shared::Game);
Ultima1Game::Ultima1Game() : Shared::Game() {
_res = new GameResources();
_map = new Map::Ultima1Map(this);
_map = new Maps::Ultima1Map(this);
_textCursor = new U1Gfx::U1TextCursor(_textColor, _bgColor);
g_vm->_screen->setCursor(_textCursor);

View File

@ -20,13 +20,13 @@
*
*/
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/map/map_city_castle.h"
#include "ultima/ultima1/map/map_dungeon.h"
#include "ultima/ultima1/map/map_overworld.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_city_castle.h"
#include "ultima/ultima1/maps/map_dungeon.h"
#include "ultima/ultima1/maps/map_overworld.h"
#include "ultima/ultima1/maps/map_tile.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/widgets/dungeon_widget.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/widgets/bard.h"
#include "ultima/ultima1/widgets/dungeon_monster.h"
#include "ultima/ultima1/widgets/dungeon_player.h"
@ -40,12 +40,13 @@
#include "ultima/ultima1/widgets/transport.h"
#include "ultima/ultima1/widgets/urban_player.h"
#include "ultima/ultima1/widgets/wench.h"
#include "ultima/ultima1/game.h"
#include "ultima/shared/core/file.h"
#include "ultima/shared/early/ultima_early.h"
namespace Ultima {
namespace Ultima1 {
namespace Map {
namespace Maps {
void SurroundingTotals::load(Ultima1Map *map) {
U1MapTile mapTile;
@ -69,88 +70,7 @@ void SurroundingTotals::load(Ultima1Map *map) {
/*------------------------------------------------------------------------*/
Ultima1Map::MapBase::MapBase(Ultima1Game *game, Ultima1Map *map) : Shared::Map::MapBase(game, map), _game(game) {
}
void Ultima1Map::MapBase::getTileAt(const Point &pt, Shared::MapTile *tile) {
Shared::Map::MapBase::getTileAt(pt, tile);
// Special handling for one of the city/town tile numbers
if (tile->_tileNum >= 51 && dynamic_cast<MapCityCastle *>(this))
tile->_tileNum = 1;
// Setting dungeon flags
if (dynamic_cast<MapDungeon *>(this)) {
tile->_isHallway = tile->_tileNum == DTILE_HALLWAY;
tile->_isDoor = tile->_tileNum == DTILE_DOOR;
tile->_isSecretDoor = tile->_tileNum == DTILE_SECRET_DOOR;
tile->_isWall = tile->_tileNum == DTILE_WALL;
tile->_isLadderUp = tile->_tileNum == DTILE_LADDER_UP;
tile->_isLadderDown = tile->_tileNum == DTILE_LADDER_DOWN;
tile->_isBeams = tile->_tileNum == DTILE_BEAMS;
}
// Extended properties to set if an Ultima 1 map tile structure was passed in
U1MapTile *mapTile = dynamic_cast<U1MapTile *>(tile);
if (mapTile) {
GameResources *res = _game->_res;
mapTile->_map = this;
// Check for a location at the given position
mapTile->_locationNum = -1;
if (dynamic_cast<MapOverworld *>(this)) {
for (int idx = 0; idx < LOCATION_COUNT; ++idx) {
if (pt.x == res->LOCATION_X[idx] && pt.y == res->LOCATION_Y[idx]) {
mapTile->_locationNum = idx + 1;
break;
}
}
}
}
}
/*------------------------------------------------------------------------*/
void U1MapTile::clear() {
_map = nullptr;
_locationNum = -1;
}
bool U1MapTile::isWater() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 0;
}
bool U1MapTile::isGrass() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 1;
}
bool U1MapTile::isWoods() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 2;
}
bool U1MapTile::isOriginalWater() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 0;
}
bool U1MapTile::isOriginalGrass() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 1;
}
bool U1MapTile::isOriginalWoods() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 2;
}
bool U1MapTile::isGround() const {
if (dynamic_cast<MapCityCastle *>(_map) && (_tileId == 1 || _tileId >= 51))
return true;
else if (dynamic_cast<MapOverworld *>(_map))
return _tileId != 0;
return false;
}
/*------------------------------------------------------------------------*/
Ultima1Map::Ultima1Map(Ultima1Game *game) : Shared::Map(), _game(game), _mapType(MAP_UNKNOWN) {
Ultima1Map::Ultima1Map(Ultima1Game *game) : Shared::Maps::Map(), _game(game), _mapType(MAP_UNKNOWN) {
Ultima1Map::clear();
_mapCity = new MapCity(game, this);
_mapCastle = new MapCastle(game, this);
@ -169,12 +89,12 @@ void Ultima1Map::clear() {
_mapType = MAP_UNKNOWN;
}
void Ultima1Map::load(Shared::MapId mapId) {
void Ultima1Map::load(Shared::Maps::MapId mapId) {
// If we're leaving the overworld, update the cached copy of the position in the overworld
if (_mapType == MAP_OVERWORLD)
_worldPos = _mapArea->getPosition();
Shared::Map::load(mapId);
Shared::Maps::Map::load(mapId);
// Switch to the correct map area
if (mapId == MAPID_OVERWORLD) {
@ -198,7 +118,7 @@ void Ultima1Map::load(Shared::MapId mapId) {
}
void Ultima1Map::synchronize(Common::Serializer &s) {
Shared::Map::synchronize(s);
Shared::Maps::Map::synchronize(s);
if (_mapType != MAP_OVERWORLD)
_mapOverworld->synchronize(s);
}
@ -207,7 +127,7 @@ bool Ultima1Map::isLordBritishCastle() const {
return _mapType == MAP_CASTLE && static_cast<MapCityCastle *>(_mapArea)->getMapIndex() == 0;
}
Shared::MapWidget *Ultima1Map::createWidget(Shared::Map::MapBase *map, const Common::String &name) {
Shared::Maps::MapWidget *Ultima1Map::createWidget(Shared::Maps::MapBase *map, const Common::String &name) {
REGISTER_WIDGET(Bard);
REGISTER_WIDGET(DungeonMonster);
REGISTER_WIDGET(DungeonPlayer);
@ -224,6 +144,6 @@ Shared::MapWidget *Ultima1Map::createWidget(Shared::Map::MapBase *map, const Com
error("Unknown widget type '%s'", name.c_str());
}
} // End of namespace Map
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -20,17 +20,18 @@
*
*/
#ifndef ULTIMA_ULTIMA1_CORE_MAP_H
#define ULTIMA_ULTIMA1_CORE_MAP_H
#ifndef ULTIMA_ULTIMA1_MAPS_MAP_H
#define ULTIMA_ULTIMA1_MAPS_MAP_H
#include "ultima/shared/core/map.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/maps/map_widget.h"
namespace Ultima {
namespace Ultima1 {
class Ultima1Game;
namespace Map {
namespace Maps {
enum MapType {
MAP_OVERWORLD = 0, MAP_CITY = 1, MAP_CASTLE = 2, MAP_DUNGEON = 3, MAP_UNKNOWN = 4
@ -40,12 +41,12 @@ enum MapIdent {
MAPID_OVERWORLD = 0
};
class U1MapTile;
class Ultima1Map;
class MapCity;
class MapCastle;
class MapDungeon;
class MapOverworld;
class MapBase;
/**
* Used to hold the total number of tiles surrounding location entrances
@ -69,31 +70,7 @@ struct SurroundingTotals {
/**
* Ultima 1 map manager
*/
class Ultima1Map : public Shared::Map {
public:
/**
* Intermediate base class for Ultima 1 map types
*/
class MapBase : public Shared::Map::MapBase {
protected:
Ultima1Game *_game;
public:
/**
* Constructor
*/
MapBase(Ultima1Game *game, Ultima1Map *map);
/**
* Destructor
*/
virtual ~MapBase() {}
/**
* Gets a tile at a given position
*/
virtual void getTileAt(const Point &pt, Shared::MapTile *tile) override;
};
class Ultima1Map : public Shared::Maps::Map {
private:
Ultima1Game *_game;
MapCity *_mapCity;
@ -122,7 +99,7 @@ public:
/**
* Load a given map
*/
virtual void load(Shared::MapId mapId) override;
virtual void load(Shared::Maps::MapId mapId) override;
/**
* Handles loading and saving the map's data
@ -137,61 +114,10 @@ public:
/**
* Instantiates a widget type by name
*/
virtual Shared::MapWidget *createWidget(Shared::Map::MapBase *map, const Common::String &name) override;
virtual Shared::Maps::MapWidget *createWidget(Shared::Maps::MapBase *map, const Common::String &name) override;
};
/**
* Derived map tile class for Ultima 1 that adds extra properties
*/
class U1MapTile : public Shared::MapTile {
friend class Ultima1Map;
private:
Ultima1Map::MapBase *_map;
public:
int _locationNum;
public:
/**
* Clears tile data
*/
virtual void clear();
/**
* Return true if the tile base is water
*/
bool isWater() const;
/**
* Return true if the tile base is grass
*/
bool isGrass() const;
/**
* Return true if the tile base is woods
*/
bool isWoods() const;
/**
* Return true if the tile base in the original map is water
*/
bool isOriginalWater() const;
/**
* Return true if the tile base in the original map is grass
*/
bool isOriginalGrass() const;
/**
* Return true if the tile base in the original map is woods
*/
bool isOriginalWoods() const;
/**
* Returns true if the tile is a ground type tool
*/
bool isGround() const;
};
} // End of namespace Map
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -0,0 +1,78 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ultima/ultima1/maps/map_base.h"
#include "ultima/ultima1/maps/map_tile.h"
#include "ultima/ultima1/maps/map_dungeon.h"
#include "ultima/ultima1/maps/map_city_castle.h"
#include "ultima/ultima1/maps/map_overworld.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/game.h"
namespace Ultima {
namespace Ultima1 {
namespace Maps {
MapBase::MapBase(Ultima1Game *game, Ultima1Map *map) : Shared::Maps::MapBase(game, map), _game(game) {
}
void MapBase::getTileAt(const Point &pt, Shared::Maps::MapTile *tile) {
Shared::Maps::MapBase::getTileAt(pt, tile);
// Special handling for one of the city/town tile numbers
if (tile->_tileNum >= 51 && dynamic_cast<MapCityCastle *>(this))
tile->_tileNum = 1;
// Setting dungeon flags
if (dynamic_cast<MapDungeon *>(this)) {
tile->_isHallway = tile->_tileNum == DTILE_HALLWAY;
tile->_isDoor = tile->_tileNum == DTILE_DOOR;
tile->_isSecretDoor = tile->_tileNum == DTILE_SECRET_DOOR;
tile->_isWall = tile->_tileNum == DTILE_WALL;
tile->_isLadderUp = tile->_tileNum == DTILE_LADDER_UP;
tile->_isLadderDown = tile->_tileNum == DTILE_LADDER_DOWN;
tile->_isBeams = tile->_tileNum == DTILE_BEAMS;
}
// Extended properties to set if an Ultima 1 map tile structure was passed in
U1MapTile *mapTile = dynamic_cast<U1MapTile *>(tile);
if (mapTile) {
GameResources *res = _game->_res;
mapTile->setMap(this);
// Check for a location at the given position
mapTile->_locationNum = -1;
if (dynamic_cast<MapOverworld *>(this)) {
for (int idx = 0; idx < LOCATION_COUNT; ++idx) {
if (pt.x == res->LOCATION_X[idx] && pt.y == res->LOCATION_Y[idx]) {
mapTile->_locationNum = idx + 1;
break;
}
}
}
}
}
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -0,0 +1,64 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_ULTIMA1_MAPS_MAP_BASE_H
#define ULTIMA_ULTIMA1_MAPS_MAP_BASE_H
#include "ultima/shared/maps/map_base.h"
namespace Ultima {
namespace Ultima1 {
class Ultima1Game;
namespace Maps {
class Ultima1Map;
/**
* Intermediate base class for Ultima 1 maps
*/
class MapBase : public Shared::Maps::MapBase {
protected:
Ultima1Game *_game;
public:
/**
* Constructor
*/
MapBase(Ultima1Game *game, Ultima1Map *map);
/**
* Destructor
*/
virtual ~MapBase() {}
/**
* Gets a tile at a given position
*/
virtual void getTileAt(const Point &pt, Shared::Maps::MapTile *tile) override;
};
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@ -20,7 +20,7 @@
*
*/
#include "ultima/ultima1/map/map_city_castle.h"
#include "ultima/ultima1/maps/map_city_castle.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/widgets/urban_player.h"
@ -33,18 +33,18 @@
namespace Ultima {
namespace Ultima1 {
namespace Map {
namespace Maps {
void MapCityCastle::load(Shared::MapId mapId) {
void MapCityCastle::load(Shared::Maps::MapId mapId) {
clear();
Shared::Map::MapBase::load(mapId);
Shared::Maps::MapBase::load(mapId);
setDimensions(Point(38, 18));
_tilesPerOrigTile = Point(1, 1);
}
void MapCityCastle::clear() {
Shared::Map::MapBase::clear();
Shared::Maps::MapBase::clear();
_guardsHostile = false;
}
@ -119,7 +119,7 @@ void MapCityCastle::loadTownCastleData() {
/*-------------------------------------------------------------------*/
void MapCity::load(Shared::MapId mapId) {
void MapCity::load(Shared::Maps::MapId mapId) {
MapCityCastle::load(mapId);
_mapStyle = (_mapId % 8) + 2;
@ -135,7 +135,7 @@ void MapCity::load(Shared::MapId mapId) {
/*-------------------------------------------------------------------*/
void MapCastle::load(Shared::MapId mapId) {
void MapCastle::load(Shared::Maps::MapId mapId) {
MapCityCastle::load(mapId);
_mapIndex = _mapId - 33;
@ -154,6 +154,6 @@ void MapCastle::load(Shared::MapId mapId) {
setPosition(Common::Point(0, height() / 2)); // Start at center left edge of map
}
} // End of namespace Map
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -23,11 +23,11 @@
#ifndef ULTIMA_ULTIMA1_MAP_MAP_CITY_CASTLE_H
#define ULTIMA_ULTIMA1_MAP_MAP_CITY_CASTLE_H
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map_base.h"
namespace Ultima {
namespace Ultima1 {
namespace Map {
namespace Maps {
enum CityTile {
CTILE_1 = 1, CTILE_51 = 51, CTILE_GATE = 11
@ -36,7 +36,7 @@ enum CityTile {
/**
* Common base class for city and castle maps
*/
class MapCityCastle : public Ultima1Map::MapBase {
class MapCityCastle : public MapBase {
protected:
/**
* Load widget list for the map
@ -53,7 +53,7 @@ public:
/**
* Constructor
*/
MapCityCastle(Ultima1Game *game, Ultima1Map *map) : Ultima1Map::MapBase(game, map), _guardsHostile(false) {}
MapCityCastle(Ultima1Game *game, Ultima1Map *map) : MapBase(game, map), _guardsHostile(false) {}
/**
* Destructor
@ -63,7 +63,7 @@ public:
/**
* Load the map
*/
virtual void load(Shared::MapId mapId) override;
virtual void load(Shared::Maps::MapId mapId) override;
/**
* Clears all map data
@ -94,7 +94,7 @@ public:
/**
* Load the map
*/
virtual void load(Shared::MapId mapId) override;
virtual void load(Shared::Maps::MapId mapId) override;
};
/**
@ -117,10 +117,10 @@ public:
/**
* Load the map
*/
virtual void load(Shared::MapId mapId) override;
virtual void load(Shared::Maps::MapId mapId) override;
};
} // End of namespace Map
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -20,8 +20,9 @@
*
*/
#include "ultima/ultima1/map/map_dungeon.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map_dungeon.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_tile.h"
#include "ultima/ultima1/widgets/dungeon_widget.h"
#include "ultima/ultima1/widgets/dungeon_monster.h"
#include "ultima/ultima1/widgets/dungeon_player.h"
@ -29,16 +30,16 @@
namespace Ultima {
namespace Ultima1 {
namespace Map {
namespace Maps {
void MapDungeon::load(Shared::MapId mapId) {
Shared::Map::MapBase::load(mapId);
void MapDungeon::load(Shared::Maps::MapId mapId) {
Shared::Maps::MapBase::load(mapId);
_tilesPerOrigTile = Point(1, 1);
_dungeonLevel = 1;
changeLevel(0);
_playerWidget->moveTo(Point(1, 1), Shared::DIR_SOUTH);
_playerWidget->moveTo(Point(1, 1), Shared::Maps::DIR_SOUTH);
}
bool MapDungeon::changeLevel(int delta) {
@ -102,7 +103,7 @@ bool MapDungeon::changeLevel(int delta) {
byte currTile = _data[pt.y][pt.x];
if (currTile != DTILE_WALL && currTile != DTILE_SECRET_DOOR && currTile != DTILE_BEAMS) {
_widgets.push_back(Shared::MapWidgetPtr(new Widgets::DungeonWidget(_game, this, pt,
_widgets.push_back(Shared::Maps::MapWidgetPtr(new Widgets::DungeonWidget(_game, this, pt,
(getDeterministicRandomNumber(1, 100) & 1) ? Widgets::DITEM_COFFIN : Widgets::DITEM_CHEST)));
}
}
@ -188,13 +189,13 @@ void MapDungeon::update() {
// Check for a widget at the given position
getTileAt(pt, &tile);
Shared::Creature *creature = dynamic_cast<Shared::Creature *>(tile._widget);
Shared::Maps::Creature *creature = dynamic_cast<Shared::Maps::Creature *>(tile._widget);
if (creature)
creature->update(true);
}
}
}
} // End of namespace Map
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -23,13 +23,13 @@
#ifndef ULTIMA_ULTIMA1_MAP_MAP_DUNGEON_H
#define ULTIMA_ULTIMA1_MAP_MAP_DUNGEON_H
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map_base.h"
#include "ultima/shared/core/rect.h"
#include "common/random.h"
namespace Ultima {
namespace Ultima1 {
namespace Map {
namespace Maps {
#define DUNGEON_WIDTH 11
#define DUNGEON_HEIGHT 11
@ -39,7 +39,7 @@ enum DungeonTile {
DTILE_LADDER_UP = 7, DTILE_BEAMS = 8
};
class MapDungeon : public Ultima1Map::MapBase {
class MapDungeon : public MapBase {
private:
Common::RandomSource _random;
uint _dungeonLevel; // Dungeon level number
@ -60,14 +60,14 @@ private:
*/
void spawnMonsterAt(const Point &pt);
public:
MapDungeon(Ultima1Game *game, Ultima1Map *map) : Ultima1Map::MapBase(game, map), _dungeonLevel(0),
MapDungeon(Ultima1Game *game, Ultima1Map *map) : MapBase(game, map), _dungeonLevel(0),
_random("UltimaDungeons") {}
virtual ~MapDungeon() {}
/**
* Load the map
*/
virtual void load(Shared::MapId mapId);
virtual void load(Shared::Maps::MapId mapId);
/**
* Changes the dungeon level by a given delta amount, and generates a new map
@ -92,7 +92,7 @@ public:
void spawnMonster();
};
} // End of namespace Map
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -20,17 +20,17 @@
*
*/
#include "ultima/ultima1/map/map_overworld.h"
#include "ultima/ultima1/maps/map_overworld.h"
#include "ultima/ultima1/widgets/transport.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/game.h"
namespace Ultima {
namespace Ultima1 {
namespace Map {
namespace Maps {
void MapOverworld::load(Shared::MapId mapId) {
Shared::Map::MapBase::load(mapId);
void MapOverworld::load(Shared::Maps::MapId mapId) {
Shared::Maps::MapBase::load(mapId);
setDimensions(Point(168, 156));
_tilesPerOrigTile = Point(1, 1);
@ -113,6 +113,6 @@ void MapOverworld::shiftViewport(const Point &delta) {
topLeft.y -= height();
}
} // End of namespace Map
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -23,26 +23,26 @@
#ifndef ULTIMA_ULTIMA1_MAP_MAP_OVERWORLD_H
#define ULTIMA_ULTIMA1_MAP_MAP_OVERWORLD_H
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map_base.h"
namespace Ultima {
namespace Ultima1 {
namespace Map {
namespace Maps {
class MapOverworld : public Ultima1Map::MapBase {
class MapOverworld : public MapBase {
private:
/**
* Load widget list for the map
*/
void loadWidgets();
public:
MapOverworld(Ultima1Game *game, Ultima1Map *map) : Ultima1Map::MapBase(game, map) {}
MapOverworld(Ultima1Game *game, Ultima1Map *map) : MapBase(game, map) {}
virtual ~MapOverworld() {}
/**
* Load the map
*/
virtual void load(Shared::MapId mapId);
virtual void load(Shared::Maps::MapId mapId);
/**
* Returns whether the map wraps around to the other side at it's edges (i.e. the overworld)
@ -65,7 +65,7 @@ public:
virtual Point getDeltaPosition(const Point &delta) override;
};
} // End of namespace Map
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -0,0 +1,70 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ultima/ultima1/maps/map_tile.h"
#include "ultima/ultima1/maps/map_overworld.h"
#include "ultima/ultima1/maps/map_city_castle.h"
namespace Ultima {
namespace Ultima1 {
namespace Maps {
void U1MapTile::clear() {
_map = nullptr;
_locationNum = -1;
}
bool U1MapTile::isWater() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 0;
}
bool U1MapTile::isGrass() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 1;
}
bool U1MapTile::isWoods() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 2;
}
bool U1MapTile::isOriginalWater() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 0;
}
bool U1MapTile::isOriginalGrass() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 1;
}
bool U1MapTile::isOriginalWoods() const {
return dynamic_cast<MapOverworld *>(_map) && _tileId == 2;
}
bool U1MapTile::isGround() const {
if (dynamic_cast<MapCityCastle *>(_map) && (_tileId == 1 || _tileId >= 51))
return true;
else if (dynamic_cast<MapOverworld *>(_map))
return _tileId != 0;
return false;
}
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -0,0 +1,94 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_ULTIMA1_MAPS_MAP_TILE_H
#define ULTIMA_ULTIMA1_MAPS_MAP_TILE_H
#include "ultima/shared/maps/map_tile.h"
namespace Ultima {
namespace Ultima1 {
namespace Maps {
class MapBase;
class Ultima1Map;
/**
* Derived map tile class for Ultima 1 that adds extra properties
*/
class U1MapTile : public Shared::Maps::MapTile {
private:
MapBase *_map;
public:
int _locationNum;
public:
/**
* Set the active map
*/
void setMap(MapBase *map) { _map = map; }
/**
* Clears tile data
*/
virtual void clear();
/**
* Return true if the tile base is water
*/
bool isWater() const;
/**
* Return true if the tile base is grass
*/
bool isGrass() const;
/**
* Return true if the tile base is woods
*/
bool isWoods() const;
/**
* Return true if the tile base in the original map is water
*/
bool isOriginalWater() const;
/**
* Return true if the tile base in the original map is grass
*/
bool isOriginalGrass() const;
/**
* Return true if the tile base in the original map is woods
*/
bool isOriginalWoods() const;
/**
* Returns true if the tile is a ground type tool
*/
bool isGround() const;
};
} // End of namespace Maps
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@ -23,11 +23,11 @@
#include "ultima/ultima1/u1gfx/view_char_gen.h"
#include "ultima/ultima1/u1gfx/drawing_support.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/u1gfx/text_cursor.h"
#include "ultima/ultima1/game.h"
#include "ultima/shared/gfx/text_input.h"
#include "ultima/shared/engine/messages.h"
#include "ultima/shared/early/font_resources.h"
#include "ultima/shared/early/ultima_early.h"
namespace Ultima {
@ -378,8 +378,8 @@ bool ViewCharacterGeneration::save() {
game->_randomSeed = game->getRandomNumber(0xfffffff);
// Set the default position
Shared::Map *map = game->_map;
map->load(Ultima1::Map::MAPID_OVERWORLD);
Shared::Maps::Map *map = game->_map;
map->load(Ultima1::Maps::MAPID_OVERWORLD);
map->setPosition(Point(49, 40));
// Set other character properties

View File

@ -23,7 +23,7 @@
#include "ultima/ultima1/u1gfx/view_game.h"
#include "ultima/shared/actions/huh.h"
#include "ultima/shared/actions/pass.h"
#include "ultima/shared/core/map.h"
#include "ultima/shared/maps/map.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/u1gfx/drawing_support.h"
#include "ultima/ultima1/u1gfx/info.h"
@ -34,7 +34,7 @@
#include "ultima/ultima1/actions/climb.h"
#include "ultima/ultima1/actions/enter.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/shared/engine/messages.h"
#include "ultima/shared/early/font_resources.h"
namespace Ultima {
namespace Ultima1 {
@ -84,9 +84,9 @@ void ViewGame::draw() {
if (_status->isDirty())
_status->draw();
Map::Ultima1Map *map = static_cast<Map::Ultima1Map *>(getGame()->getMap());
Maps::Ultima1Map *map = static_cast<Maps::Ultima1Map *>(getGame()->getMap());
switch (map->_mapType) {
case Map::MAP_DUNGEON:
case Maps::MAP_DUNGEON:
_viewportDungeon->draw();
break;
default:
@ -97,12 +97,12 @@ void ViewGame::draw() {
void ViewGame::drawIndicators() {
Ultima1Game *game = static_cast<Ultima1Game *>(getGame());
Map::Ultima1Map *map = static_cast<Map::Ultima1Map *>(game->getMap());
Maps::Ultima1Map *map = static_cast<Maps::Ultima1Map *>(game->getMap());
Shared::Gfx::VisualSurface s = getSurface();
DrawingSupport ds(s);
if (map->_mapType == Map::MAP_DUNGEON) {
if (map->_mapType == Maps::MAP_DUNGEON) {
// Draw the dungeon level indicator
ds.drawRightArrow(TextPoint(15, 0));
s.writeString(game->_res->DUNGEON_LEVEL, TextPoint(16, 0), game->_textColor);
@ -136,25 +136,25 @@ bool ViewGame::KeypressMsg(CKeypressMsg &msg) {
switch (msg._keyState.keycode) {
case Common::KEYCODE_LEFT:
case Common::KEYCODE_KP4: {
Shared::CMoveMsg move(Shared::DIR_LEFT);
Shared::CMoveMsg move(Shared::Maps::DIR_LEFT);
move.execute(this);
break;
}
case Common::KEYCODE_RIGHT:
case Common::KEYCODE_KP6: {
Shared::CMoveMsg move(Shared::DIR_RIGHT);
Shared::CMoveMsg move(Shared::Maps::DIR_RIGHT);
move.execute(this);
break;
}
case Common::KEYCODE_UP:
case Common::KEYCODE_KP8: {
Shared::CMoveMsg move(Shared::DIR_UP);
Shared::CMoveMsg move(Shared::Maps::DIR_UP);
move.execute(this);
break;
}
case Common::KEYCODE_DOWN:
case Common::KEYCODE_KP2: {
Shared::CMoveMsg move(Shared::DIR_DOWN);
Shared::CMoveMsg move(Shared::Maps::DIR_DOWN);
move.execute(this);
break;
}

View File

@ -28,7 +28,7 @@ namespace Ultima {
namespace Ultima1 {
namespace U1Gfx {
ViewportMap::ViewportMap(Shared::TreeItem *parent) : Shared::ViewportMap(parent), _mapType(Map::MAP_OVERWORLD) {
ViewportMap::ViewportMap(TreeItem *parent) : Shared::ViewportMap(parent), _mapType(Maps::MAP_OVERWORLD) {
_sprites = new Sprites(this);
}
@ -36,13 +36,13 @@ ViewportMap::~ViewportMap() {
}
void ViewportMap::draw() {
Map::Ultima1Map *map = static_cast<Map::Ultima1Map *>(getGame()->getMap());
Maps::Ultima1Map *map = static_cast<Maps::Ultima1Map *>(getGame()->getMap());
// If necessary, load the sprites for rendering the map
if (_sprites->empty() || _mapType != map->_mapType) {
_mapType = map->_mapType;
Sprites *sprites = static_cast<Sprites *>(_sprites);
sprites->load(_mapType == Map::MAP_OVERWORLD);
sprites->load(_mapType == Maps::MAP_OVERWORLD);
}
// Draw the map

View File

@ -24,7 +24,7 @@
#define ULTIMA_ULTIMA1_GFX_VIEWPORT_MAP_H
#include "ultima/shared/gfx/viewport_map.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
namespace Ultima {
namespace Ultima1 {
@ -32,7 +32,7 @@ namespace U1Gfx {
class ViewportMap : public Shared::ViewportMap {
private:
Map::MapType _mapType;
Maps::MapType _mapType;
public:
/**
* Constructor

View File

@ -22,7 +22,7 @@
#include "ultima/ultima1/u6gfx/game_view.h"
#include "ultima/shared/actions/pass.h"
#include "ultima/shared/core/map.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/gfx/info.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/u1gfx/drawing_support.h"
@ -33,8 +33,8 @@
#include "ultima/ultima1/actions/climb.h"
#include "ultima/ultima1/actions/enter.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/shared/engine/messages.h"
#include "ultima/shared/gfx/bitmap.h"
#include "ultima/shared/engine/messages.h"
namespace Ultima {
namespace Ultima1 {
@ -105,25 +105,25 @@ bool GameView::KeypressMsg(CKeypressMsg &msg) {
switch (msg._keyState.keycode) {
case Common::KEYCODE_LEFT:
case Common::KEYCODE_KP4: {
Shared::CMoveMsg move(Shared::DIR_LEFT);
Shared::CMoveMsg move(Shared::Maps::DIR_LEFT);
move.execute(this);
break;
}
case Common::KEYCODE_RIGHT:
case Common::KEYCODE_KP6: {
Shared::CMoveMsg move(Shared::DIR_RIGHT);
Shared::CMoveMsg move(Shared::Maps::DIR_RIGHT);
move.execute(this);
break;
}
case Common::KEYCODE_UP:
case Common::KEYCODE_KP8: {
Shared::CMoveMsg move(Shared::DIR_UP);
Shared::CMoveMsg move(Shared::Maps::DIR_UP);
move.execute(this);
break;
}
case Common::KEYCODE_DOWN:
case Common::KEYCODE_KP2: {
Shared::CMoveMsg move(Shared::DIR_DOWN);
Shared::CMoveMsg move(Shared::Maps::DIR_DOWN);
move.execute(this);
break;
}

View File

@ -21,7 +21,7 @@
*/
#include "ultima/ultima1/widgets/bard.h"
#include "ultima/ultima1/map/map_city_castle.h"
#include "ultima/ultima1/maps/map_city_castle.h"
#include "ultima/ultima1/core/resources.h"
namespace Ultima {
@ -69,7 +69,7 @@ bool Bard::stealWeapon() {
}
void Bard::talk() {
if (dynamic_cast<Map::MapCity *>(_map)) {
if (dynamic_cast<Maps::MapCity *>(_map)) {
addInfoMsg(_game->_res->BARD_SPEECH1);
addInfoMsg(_game->_res->BARD_SPEECH2);
} else {

View File

@ -50,13 +50,13 @@ public:
/**
* Constructor
*/
Bard(Ultima1Game *game, Map::Ultima1Map::MapBase *map, int hitPoints) :
Bard(Ultima1Game *game, Maps::MapBase *map, int hitPoints) :
Person(game, map, 19, hitPoints) {}
/**
* Constructor
*/
Bard(Ultima1Game *game, Map::Ultima1Map::MapBase *map) : Person(game, map, 19) {}
Bard(Ultima1Game *game, Maps::MapBase *map) : Person(game, map, 19) {}
/**
* Destructor

View File

@ -21,7 +21,8 @@
*/
#include "ultima/ultima1/widgets/dungeon_monster.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_tile.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/game.h"
#include "ultima/shared/core/utils.h"
@ -76,17 +77,17 @@ void DungeonMonster::movement() {
_position.y += SGN(delta.y);
}
Shared::MapWidget::CanMove DungeonMonster::canMoveTo(const Point &destPos) {
Shared::MapWidget::CanMove result = MapWidget::canMoveTo(destPos);
Shared::Maps::MapWidget::CanMove DungeonMonster::canMoveTo(const Point &destPos) {
Shared::Maps::MapWidget::CanMove result = MapWidget::canMoveTo(destPos);
if (result != UNSET)
return result;
return DungeonMonster::canMoveTo(_map, this, destPos);
}
Shared::MapWidget::CanMove DungeonMonster::canMoveTo(Shared::Map::MapBase *map, MapWidget *widget, const Point &destPos) {
Shared::Maps::MapWidget::CanMove DungeonMonster::canMoveTo(Shared::Maps::MapBase *map, MapWidget *widget, const Point &destPos) {
// Get the details of the position
Shared::MapTile currTile, destTile;
Shared::Maps::MapTile currTile, destTile;
map->getTileAt(map->getPosition(), &currTile);
map->getTileAt(destPos, &destTile);
@ -111,7 +112,7 @@ void DungeonMonster::attack() {
bool isHit = true;
// Get tile details for both the player and the attacking creature
Map::U1MapTile playerTile,creatureTile;
Maps::U1MapTile playerTile,creatureTile;
_map->getTileAt(playerPos, &playerTile);
_map->getTileAt(_position, &creatureTile);

View File

@ -24,6 +24,8 @@
#define ULTIMA_ULTIMA1_WIDGETS_DUNGEON_MONSTER_H
#include "ultima/ultima1/widgets/dungeon_widget.h"
#include "ultima/shared/maps/creature.h"
#include "ultima/shared/maps/dungeon_creature.h"
namespace Ultima {
namespace Ultima1 {
@ -32,7 +34,7 @@ namespace Widgets {
/**
* Implements monsters within the dungeons
*/
class DungeonMonster : public Shared::Creature, public Shared::DungeonCreature {
class DungeonMonster : public Shared::Maps::DungeonWidget, public Shared::Maps::DungeonCreature {
private:
DungeonWidgetId _monsterId;
protected:
@ -44,22 +46,22 @@ public:
/**
* Returns true if the given widget can move to a given position on the map
*/
static Shared::MapWidget::CanMove canMoveTo(Shared::Map::MapBase *map, MapWidget *widget, const Point &destPos);
static Shared::Maps::MapWidget::CanMove canMoveTo(Shared::Maps::MapBase *map, MapWidget *widget, const Point &destPos);
public:
DECLARE_WIDGET(DungeonMonster)
/**
* Constructor
*/
DungeonMonster(Shared::Game *game, Shared::Map::MapBase *map, DungeonWidgetId monsterId, int hitPoints,
const Point &pt, Shared::Direction dir = Shared::DIR_NONE) :
Shared::Creature(game, map, hitPoints, pt, dir), Shared::DungeonCreature(), _monsterId(monsterId) {}
DungeonMonster(Shared::Game *game, Shared::Maps::MapBase *map, DungeonWidgetId monsterId, int hitPoints,
const Point &pt, Shared::Maps::Direction dir = Shared::Maps::DIR_NONE) :
Shared::Maps::DungeonWidget(game, map, pt, dir), Shared::Maps::DungeonCreature(game, map, hitPoints), _monsterId(monsterId) {}
/**
* Constructor
*/
DungeonMonster(Shared::Game *game, Shared::Map::MapBase *map) :
Shared::Creature(game, map), Shared::DungeonCreature(), _monsterId(MONSTER_NONE) {}
DungeonMonster(Shared::Game *game, Shared::Maps::MapBase *map) :
Shared::Maps::DungeonWidget(game, map), Shared::Maps::DungeonCreature(game, map), _monsterId(MONSTER_NONE) {}
/**
* Destructor

View File

@ -22,18 +22,18 @@
#include "ultima/ultima1/widgets/dungeon_player.h"
#include "ultima/ultima1/widgets/dungeon_widget.h"
#include "ultima/ultima1/widgets/dungeon_monster.h"
namespace Ultima {
namespace Ultima1 {
namespace Widgets {
Shared::MapWidget::CanMove DungeonPlayer::canMoveTo(const Point &destPos) {
Shared::MapWidget::CanMove result = MapWidget::canMoveTo(destPos);
if (result != UNSET)
Shared::Maps::MapWidget::CanMove DungeonPlayer::canMoveTo(const Point &destPos) {
Shared::Maps::MapWidget::CanMove result = Shared::Maps::DungeonWidget::canMoveTo(destPos);
if (result != Shared::Maps::DungeonWidget::UNSET)
return result;
return DungeonMonster::canMoveTo(_map, this, destPos);
return Shared::Maps::DungeonWidget::UNSET;
//return Shared::Maps::DungeonWidget::canMoveTo(_map, this, destPos);
}
} // End of namespace Widgets

View File

@ -23,24 +23,25 @@
#ifndef ULTIMA_ULTIMA1_WIDGETS_DUNGEON_PLAYER_H
#define ULTIMA_ULTIMA1_WIDGETS_DUNGEON_PLAYER_H
#include "ultima/shared/core/widgets.h"
#include "ultima/shared/maps/dungeon_widget.h"
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/early/game.h"
namespace Ultima {
namespace Ultima1 {
namespace Widgets {
class DungeonPlayer : public Shared::DungeonWidget {
class DungeonPlayer : public Shared::Maps::DungeonWidget {
public:
DECLARE_WIDGET(DungeonPlayer)
/**
* Constructor
*/
DungeonPlayer(Shared::Game *game, Shared::Map::MapBase *map) : Shared::DungeonWidget(game, map) {}
DungeonPlayer(Shared::Game *game, Shared::Map::MapBase *map, const Point &pt, Shared::Direction dir = Shared::DIR_NONE) : Shared::DungeonWidget(game, map, pt, dir) {}
DungeonPlayer(Shared::Game *game, Shared::Map::MapBase *map, const Common::String &name, const Point &pt, Shared::Direction dir = Shared::DIR_NONE) :
Shared::DungeonWidget(game, map, name, pt, dir) {}
DungeonPlayer(Shared::Game *game, Shared::Maps::MapBase *map) : Shared::Maps::DungeonWidget(game, map) {}
DungeonPlayer(Shared::Game *game, Shared::Maps::MapBase *map, const Point &pt, Shared::Maps::Direction dir = Shared::Maps::DIR_NONE) : Shared::Maps::DungeonWidget(game, map, pt, dir) {}
DungeonPlayer(Shared::Game *game, Shared::Maps::MapBase *map, const Common::String &name, const Point &pt, Shared::Maps::Direction dir = Shared::Maps::DIR_NONE) :
Shared::Maps::DungeonWidget(game, map, name, pt, dir) {}
/**
* Destructor

View File

@ -29,8 +29,8 @@ namespace Ultima {
namespace Ultima1 {
namespace Widgets {
DungeonWidget::DungeonWidget(Shared::Game *game, Shared::Map::MapBase *map, const Point &pt,
DungeonItemId itemId) : Shared::DungeonWidget(game, map, pt), _itemId(itemId) {
DungeonWidget::DungeonWidget(Shared::Game *game, Shared::Maps::MapBase *map, const Point &pt,
DungeonItemId itemId) : Shared::Maps::DungeonWidget(game, map, pt), _itemId(itemId) {
_widgetId = (_itemId == DITEM_CHEST) ? MONSTER_MIMIC : UITEM_COFFIN;
GameResources &res = *static_cast<Ultima1Game *>(game)->_res;

View File

@ -23,7 +23,8 @@
#ifndef ULTIMA_ULTIMA1_WIDGETS_DUNGEON_WIDGET_H
#define ULTIMA_ULTIMA1_WIDGETS_DUNGEON_WIDGET_H
#include "ultima/shared/core/widgets.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/maps/dungeon_widget.h"
namespace Ultima {
namespace Ultima1 {
@ -46,7 +47,7 @@ enum DungeonItemId {
/**
* Encapsulated class for drawing widgets within dungeons
*/
class DungeonWidget : public Shared::DungeonWidget {
class DungeonWidget : public Shared::Maps::DungeonWidget {
private:
DungeonItemId _itemId;
DungeonWidgetId _widgetId;
@ -68,12 +69,12 @@ public:
/**
* Constructor
*/
DungeonWidget(Shared::Game *game, Shared::Map::MapBase *map, const Point &pt, DungeonItemId itemId);
DungeonWidget(Shared::Game *game, Shared::Maps::MapBase *map, const Point &pt, DungeonItemId itemId);
/**
* Constructor
*/
DungeonWidget(Shared::Game *game, Shared::Map::MapBase *map) : Shared::DungeonWidget(game, map) {}
DungeonWidget(Shared::Game *game, Shared::Maps::MapBase *map) : Shared::Maps::DungeonWidget(game, map) {}
/**
* Draws a dungeon widget onto the passed surface

View File

@ -53,13 +53,13 @@ public:
/**
* Constructor
*/
Guard(Ultima1Game *game, Map::Ultima1Map::MapBase *map, int hitPoints) :
Guard(Ultima1Game *game, Maps::MapBase *map, int hitPoints) :
Person(game, map, 17, hitPoints), _moved(false) {}
/**
* Constructor
*/
Guard(Ultima1Game *game, Map::Ultima1Map::MapBase *map) :
Guard(Ultima1Game *game, Maps::MapBase *map) :
Person(game, map, 17), _moved(false) {}
/**

View File

@ -23,18 +23,18 @@
#ifndef ULTIMA_ULTIMA1_WIDGETS_HIT_H
#define ULTIMA_ULTIMA1_WIDGETS_HIT_H
#include "ultima/ultima1/map/map.h"
#include "ultima/shared/maps/map_widget.h"
namespace Ultima {
namespace Ultima1 {
namespace Widgets {
class Hit : public Shared::MapWidget {
class Hit : public Shared::Maps::MapWidget {
public:
/**
* Constructor
*/
Hit(Shared::Game *game, Shared::Map::MapBase *map) : Shared::MapWidget(game, map) {}
Hit(Shared::Game *game, Shared::Maps::MapBase *map) : Shared::Maps::MapWidget(game, map) {}
/**
* Destructor

View File

@ -41,13 +41,13 @@ public:
/**
* Constructor
*/
King(Ultima1Game *game, Map::Ultima1Map::MapBase *map, int hitPoints) :
King(Ultima1Game *game, Maps::MapBase *map, int hitPoints) :
Person(game, map, 20, hitPoints) {}
/**
* Constructor
*/
King(Ultima1Game *game, Map::Ultima1Map::MapBase *map) : Person(game, map, 20) {}
King(Ultima1Game *game, Maps::MapBase *map) : Person(game, map, 20) {}
/**
* Destructor

View File

@ -36,19 +36,19 @@ public:
/**
* Constructor
*/
Merchant(Ultima1Game *game, Map::Ultima1Map::MapBase *map, int hitPoints) :
Merchant(Ultima1Game *game, Maps::MapBase *map, int hitPoints) :
Person(game, map, 50, hitPoints) {}
/**
* Constructor
*/
Merchant(Ultima1Game *game, Map::Ultima1Map::MapBase *map, uint tileNum, int hitPoints) :
Merchant(Ultima1Game *game, Maps::MapBase *map, uint tileNum, int hitPoints) :
Person(game, map, tileNum, hitPoints) {}
/**
* Constructor
*/
Merchant(Ultima1Game *game, Map::Ultima1Map::MapBase *map) : Person(game, map, 50) {}
Merchant(Ultima1Game *game, Maps::MapBase *map) : Person(game, map, 50) {}
/**
* Destructor

View File

@ -24,14 +24,16 @@
#include "ultima/ultima1/widgets/hit.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/game.h"
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/core/utils.h"
namespace Ultima {
namespace Ultima1 {
namespace Widgets {
OverworldMonster::OverworldMonster(Shared::Game *game, Shared::Map::MapBase *map, uint tileNum, int hitPoints,
const Point &pt, Shared::Direction dir) : Shared::Creature(game, map, hitPoints, pt, dir), _tileNum(tileNum) {
OverworldMonster::OverworldMonster(Shared::Game *game, Shared::Maps::MapBase *map, uint tileNum, int hitPoints,
const Point &pt, Shared::Maps::Direction dir) : Shared::Maps::MapWidget(game, map, pt, dir),
Shared::Maps::Creature(game, map, hitPoints), _tileNum(tileNum) {
_monsterId = (OverworldMonsterId)((tileNum - 19) / 2);
Ultima1Game *g = static_cast<Ultima1Game *>(game);
@ -40,10 +42,10 @@ OverworldMonster::OverworldMonster(Shared::Game *game, Shared::Map::MapBase *map
}
void OverworldMonster::synchronize(Common::Serializer &s) {
Shared::Creature::synchronize(s);
s.syncAsUint16LE(_tileNum);
s.syncAsUint16LE(_monsterId);
s.syncAsUint16LE(_attackStrength);
s.syncAsSint16LE(_hitPoints);
}
uint OverworldMonster::attackDistance() const {
@ -66,7 +68,7 @@ void OverworldMonster::attack() {
Point delta(SGN(diff.x), SGN(diff.y));
Point tempDiff;
int maxDistance = attackDistance();
Shared::MapTile mapTile;
Shared::Maps::MapTile mapTile;
Shared::Character *c = _game->_party._currentCharacter;
uint threshold, damage;

View File

@ -23,7 +23,9 @@
#ifndef ULTIMA_ULTIMA1_WIDGETS_OVERWORLD_MONSTER_H
#define ULTIMA_ULTIMA1_WIDGETS_OVERWORLD_MONSTER_H
#include "ultima/shared/core/widgets.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/maps/creature.h"
namespace Ultima {
namespace Ultima1 {
@ -37,7 +39,7 @@ enum OverworldMonsterId {
/**
* Implements monsters on the overworld
*/
class OverworldMonster : public Shared::Creature {
class OverworldMonster : public Shared::Maps::MapWidget, public Shared::Maps::Creature {
private:
uint _tileNum;
OverworldMonsterId _monsterId;
@ -62,21 +64,21 @@ public:
/**
* Returns true if the given widget can move to a given position on the map
*/
static bool canMoveTo(Shared::Map::MapBase *map, MapWidget *widget, const Point &destPos);
static bool canMoveTo(Shared::Maps::MapBase *map, Shared::Maps::MapWidget *widget, const Point &destPos);
public:
DECLARE_WIDGET(OverworldMonster)
/**
* Constructor
*/
OverworldMonster(Shared::Game *game, Shared::Map::MapBase *map, uint tileNum, int hitPoints,
const Point &pt, Shared::Direction dir = Shared::DIR_NONE);
OverworldMonster(Shared::Game *game, Shared::Maps::MapBase *map, uint tileNum, int hitPoints,
const Point &pt, Shared::Maps::Direction dir = Shared::Maps::DIR_NONE);
/**
* Constructor
*/
OverworldMonster(Shared::Game *game, Shared::Map::MapBase *map) : Shared::Creature(game, map),
_tileNum(0), _monsterId(NESS_CREATURE), _attackStrength(0) {}
OverworldMonster(Shared::Game *game, Shared::Maps::MapBase *map) : Shared::Maps::MapWidget(game, map),
Shared::Maps::Creature(game, map), _tileNum(0), _monsterId(NESS_CREATURE), _attackStrength(0) {}
/**
* Destructor

View File

@ -21,14 +21,14 @@
*/
#include "ultima/ultima1/widgets/person.h"
#include "ultima/ultima1/map/map_city_castle.h"
#include "ultima/ultima1/maps/map_city_castle.h"
namespace Ultima {
namespace Ultima1 {
namespace Widgets {
bool Person::areGuardsHostile() const {
Map::MapCityCastle *cityCastle = static_cast<Map::MapCityCastle *>(_map);
Maps::MapCityCastle *cityCastle = static_cast<Maps::MapCityCastle *>(_map);
return cityCastle->_guardsHostile;
}
@ -36,29 +36,6 @@ int Person::getRandomDelta() const {
return _game->getRandomNumber(2) - 1;
}
Shared::MapWidget::CanMove Person::canMoveTo(const Point &destPos) {
Shared::MapWidget::CanMove result = Creature::canMoveTo(destPos);
if (result != UNSET)
return result;
// Get the details of the position
Map::U1MapTile destTile;
_map->getTileAt(destPos, &destTile);
return destTile._tileNum == Map::CTILE_1 || destTile._tileNum == Map::CTILE_51 ? YES : NO;
}
bool Person::moveBy(const Point &delta) {
// TODO: Movement allowed on tile 63.. is this the gate of the princess' cells?
Point newPos = _position + delta;
if (canMoveTo(newPos) == YES) {
_position = newPos;
return true;
} else {
return false;
}
}
} // End of namespace Widgets
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -23,9 +23,11 @@
#ifndef ULTIMA_ULTIMA1_WIDGETS_PERSON_H
#define ULTIMA_ULTIMA1_WIDGETS_PERSON_H
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/widgets/urban_widget.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_base.h"
#include "ultima/ultima1/game.h"
#include "ultima/shared/core/widgets.h"
#include "ultima/shared/maps/creature.h"
namespace Ultima {
namespace Ultima1 {
@ -34,12 +36,12 @@ namespace Widgets {
/**
* Base class for NPC creatures
*/
class Person : public Shared::Creature {
class Person : public UrbanWidget, Shared::Maps::Creature {
private:
uint _tileNum;
protected:
Ultima1Game *_game;
Map::Ultima1Map::MapBase *_map;
Maps::MapBase *_map;
protected:
/**
* Returns true if the guards are currently hostile
@ -57,41 +59,24 @@ protected:
Point getRandomMoveDelta() const {
return Point(getRandomDelta(), getRandomDelta());
}
/**
* Moves by a given delta if the destination is available
* @param delta Delta to move character by
* @returns True if the move was able to be done
*/
bool moveBy(const Point &delta);
public:
/**
* Constructor
*/
Person(Ultima1Game *game, Map::Ultima1Map::MapBase *map, uint tileNum, int hitPoints) :
Shared::Creature(game, map, hitPoints), _game(game), _map(map), _tileNum(tileNum) {}
Person(Ultima1Game *game, Maps::MapBase *map, uint tileNum, int hitPoints) :
UrbanWidget(game, map, tileNum), Shared::Maps::Creature(game, map, hitPoints), _game(game), _map(map) {}
/**
* Constructor
*/
Person(Ultima1Game *game, Map::Ultima1Map::MapBase *map, uint tileNum) :
Shared::Creature(game, map), _game(game), _map(map), _tileNum(tileNum) {}
Person(Ultima1Game *game, Maps::MapBase *map, uint tileNum) :
UrbanWidget(game, map, tileNum), Shared::Maps::Creature(game, map), _game(game), _map(map) {}
/**
* Destructor
*/
virtual ~Person() {}
/**
* Get the tile number for the person
*/
virtual uint getTileNum() const override { return _tileNum; }
/**
* Returns true if the given widget can move to a given position on the map
*/
virtual CanMove canMoveTo(const Point &destPos);
/**
* Talk to an NPC
*/

View File

@ -44,13 +44,13 @@ public:
/**
* Constructor
*/
Princess(Ultima1Game *game, Map::Ultima1Map::MapBase *map, int hitPoints) :
Princess(Ultima1Game *game, Maps::MapBase *map, int hitPoints) :
Wench(game, map, 22, hitPoints) {}
/**
* Constructor
*/
Princess(Ultima1Game *game, Map::Ultima1Map::MapBase *map) : Wench(game, map, 22) {}
Princess(Ultima1Game *game, Maps::MapBase *map) : Wench(game, map, 22) {}
/**
* Destructor

View File

@ -22,9 +22,9 @@
#include "ultima/ultima1/widgets/transport.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/map/map_dungeon.h"
#include "ultima/ultima1/map/map_overworld.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_dungeon.h"
#include "ultima/ultima1/maps/map_overworld.h"
#include "common/algorithm.h"
namespace Ultima {
@ -35,8 +35,8 @@ Ultima1Game *Transport::getGame() const {
return static_cast<Ultima1Game *>(_game);
}
Map::Ultima1Map::MapBase *Transport::getMap() const {
return static_cast<Map::Ultima1Map::MapBase *>(_map);
Maps::MapBase *Transport::getMap() const {
return static_cast<Maps::MapBase *>(_map);
}
/*-------------------------------------------------------------------*/

View File

@ -23,16 +23,22 @@
#ifndef ULTIMA_ULTIMA1_WIDGETS_TRANSPORT_H
#define ULTIMA_ULTIMA1_WIDGETS_TRANSPORT_H
#include "ultima/ultima1/map/map.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/maps/map_base.h"
namespace Ultima {
namespace Ultima1 {
class Ultima1Game;
namespace Maps {
class MapBase;
}
namespace Widgets {
class Transport : public Shared::MapWidget {
class Transport : public Shared::Maps::MapWidget {
protected:
/**
* Gets the Ultima 1 game
@ -42,12 +48,12 @@ protected:
/**
* Gets the Ultima 1 map
*/
Map::Ultima1Map::MapBase *getMap() const;
Maps::MapBase *getMap() const;
public:
/**
* Constructor
*/
Transport(Shared::Game *game, Shared::Map::MapBase *map) : Shared::MapWidget(game, map) {}
Transport(Shared::Game *game, Shared::Maps::MapBase *map) : Shared::Maps::MapWidget(game, map) {}
/**
* Destructor
@ -62,7 +68,7 @@ public:
/**
* Constructor
*/
TransportOnFoot(Shared::Game *game, Shared::Map::MapBase *map) : Transport(game, map) {}
TransportOnFoot(Shared::Game *game, Shared::Maps::MapBase *map) : Transport(game, map) {}
/**
* Destructor

View File

@ -21,16 +21,16 @@
*/
#include "ultima/ultima1/widgets/urban_player.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/game.h"
namespace Ultima {
namespace Ultima1 {
namespace Widgets {
void UrbanPlayer::moveTo(const Point &destPos, Shared::Direction dir) {
void UrbanPlayer::moveTo(const Point &destPos, Shared::Maps::Direction dir) {
Person::moveTo(destPos, dir);
Shared::Map *map = _game->getMap();
Shared::Maps::Map *map = _game->getMap();
if (destPos.x < 0 || destPos.y < 0 || destPos.x >= (int)map->width() || destPos.y >= (int)map->height()) {
// Handling for leaving locations by walking off the edge of the map
@ -38,7 +38,7 @@ void UrbanPlayer::moveTo(const Point &destPos, Shared::Direction dir) {
princessSaved();
// Load the overworld map
map->load(Map::MAP_OVERWORLD);
map->load(Maps::MAP_OVERWORLD);
}
}

View File

@ -49,7 +49,7 @@ public:
/**
* Constructor
*/
UrbanPlayer(Ultima1Game *game, Map::Ultima1Map::MapBase *map) : Person(game, map, 18) {}
UrbanPlayer(Ultima1Game *game, Maps::MapBase *map) : Person(game, map, 18) {}
/**
* Moves to a given position
@ -57,7 +57,7 @@ public:
* @param dir Optional explicit direction to set. If not specified,
* the direction will be set relative to the position moved from
*/
virtual void moveTo(const Point &destPos, Shared::Direction dir = Shared::DIR_NONE) override;
virtual void moveTo(const Point &destPos, Shared::Maps::Direction dir = Shared::Maps::DIR_NONE) override;
};
} // End of namespace Widgets

View File

@ -0,0 +1,56 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ultima/ultima1/widgets/urban_widget.h"
#include "ultima/ultima1/maps/map_city_castle.h"
#include "ultima/ultima1/maps/map_tile.h"
namespace Ultima {
namespace Ultima1 {
namespace Widgets {
Shared::Maps::MapWidget::CanMove UrbanWidget::canMoveTo(const Point &destPos) {
Shared::Maps::MapWidget::CanMove result = Shared::Maps::MapWidget::canMoveTo(destPos);
if (result != UNSET)
return result;
// Get the details of the position
Maps::U1MapTile destTile;
_map->getTileAt(destPos, &destTile);
return destTile._tileNum == Maps::CTILE_1 || destTile._tileNum == Maps::CTILE_51 ? YES : NO;
}
bool UrbanWidget::moveBy(const Point &delta) {
// TODO: Movement allowed on tile 63.. is this the gate of the princess' cells?
Point newPos = _position + delta;
if (canMoveTo(newPos) == YES) {
_position = newPos;
return true;
} else {
return false;
}
}
} // End of namespace Widgets
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -0,0 +1,73 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_ULTIMA1_WIDGETS_URBAN_WIDGET_H
#define ULTIMA_ULTIMA1_WIDGETS_URBAN_WIDGET_H
#include "ultima/shared/maps/map_widget.h"
#include "ultima/ultima1/maps/map.h"
namespace Ultima {
namespace Ultima1 {
namespace Widgets {
/**
* Base class for widgets in urban maps
*/
class UrbanWidget : public Shared::Maps::MapWidget {
private:
uint _tileNum;
protected:
/**
* Moves by a given delta if the destination is available
* @param delta Delta to move character by
* @returns True if the move was able to be done
*/
bool moveBy(const Point &delta);
public:
/**
* Constructor
*/
UrbanWidget(Shared::Game *game, Shared::Maps::MapBase *map, uint tileNum) :
Shared::Maps::MapWidget(game, map), _tileNum(tileNum) {}
/**
* Destructor
*/
virtual ~UrbanWidget() {}
/**
* Get the tile number for the person
*/
virtual uint getTileNum() const override { return _tileNum; }
/**
* Returns true if the given widget can move to a given position on the map
*/
virtual CanMove canMoveTo(const Point &destPos);
};
} // End of namespace Widgets
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@ -21,7 +21,7 @@
*/
#include "ultima/ultima1/widgets/wench.h"
#include "ultima/ultima1/map/map.h"
#include "ultima/ultima1/maps/map.h"
namespace Ultima {
namespace Ultima1 {

View File

@ -41,19 +41,19 @@ public:
/**
* Constructor
*/
Wench(Ultima1Game *game, Map::Ultima1Map::MapBase *map, int hitPoints) :
Wench(Ultima1Game *game, Maps::MapBase *map, int hitPoints) :
Person(game, map, 50, hitPoints) {}
/**
* Constructor
*/
Wench(Ultima1Game *game, Map::Ultima1Map::MapBase *map, uint tileNum, int hitPoints) :
Wench(Ultima1Game *game, Maps::MapBase *map, uint tileNum, int hitPoints) :
Person(game, map, tileNum, hitPoints) {}
/**
* Constructor
*/
Wench(Ultima1Game *game, Map::Ultima1Map::MapBase *map) : Person(game, map, 50) {}
Wench(Ultima1Game *game, Maps::MapBase *map) : Person(game, map, 50) {}
/**
* Destructor