22 #ifndef ULTIMA_SHARED_CORE_MAP_H 23 #define ULTIMA_SHARED_CORE_MAP_H 25 #include "common/array.h" 26 #include "common/ptr.h" 27 #include "common/serializer.h" 28 #include "ultima/shared/core/rect.h" 29 #include "ultima/shared/gfx/dungeon_surface.h" 34 #define REGISTER_WIDGET(NAME) if (name == #NAME) return new Widgets::NAME(_game, (Ultima1Map::MapBase *)map) 35 #define DECLARE_WIDGET(NAME) const char *getClassName() const override { return #NAME; } 39 DIR_LEFT = 1, DIR_RIGHT = 2, DIR_UP = 3, DIR_DOWN = 4,
40 DIR_WEST = 1, DIR_EAST = 2, DIR_NORTH = 3, DIR_SOUTH = 4
62 bool _isDoor, _isSecretDoor;
63 bool _isLadderUp, _isLadderDown;
64 bool _isWall, _isHallway, _isBeams;
69 MapTile() : _tileNum(-1), _tileId(-1), _widgetNum(-1), _widget(nullptr), _itemNum(-1),
70 _isDoor(false), _isSecretDoor(false), _isLadderUp(false), _isLadderDown(false), _isWall(false),
71 _isHallway(false), _isBeams(false) {}
86 bool isDoor()
const {
return _isDoor; }
101 bool isSolid()
const {
return !(_isHallway || _isLadderUp || _isLadderDown || _isBeams); }
112 struct ViewportPosition {
120 ViewportPosition() : _topLeft(-1, -1), _mapId(-1) {}
125 bool isValid()
const {
return _mapId != -1; }
131 s.syncAsUint16LE(_topLeft.
x);
132 s.syncAsUint16LE(_topLeft.
y);
138 void reset() { _mapId = -1; }
148 byte &operator[](
int idx) {
return _data[idx]; }
149 byte operator[](
int idx)
const {
return _data[idx]; }
162 ViewportPosition _viewportPos;
167 void setDimensions(
const Point &size);
170 Point _tilesPerOrigTile;
179 MapBase(
Game *game,
Map *map) : _map(map), _playerWidget(nullptr), _mapId(0), _mapIndex(0),
205 virtual void clear();
215 void resetViewport();
220 virtual Point getViewportPosition(
const Point &viewportSize);
225 virtual void load(MapId mapId);
257 Point getPosition()
const;
262 void setPosition(
const Point &pt);
267 Direction getDirection()
const;
272 void setDirection(Direction dir);
277 Point getDirectionDelta()
const;
282 virtual Point getDeltaPosition(
const Point &delta);
297 virtual void shiftViewport(
const Point &delta);
302 virtual void update();
310 Map() : _mapArea(nullptr) {}
320 virtual void load(MapId mapId);
325 virtual void clear();
358 return _mapArea->
width();
366 return _mapArea->
height();
431 return _mapArea->_tilesPerOrigTile;
439 return _mapArea->_name;
447 return _mapArea->_playerWidget;
480 return _mapArea->
update();
493 Direction _direction;
502 _game(game), _map(map), _name(name), _position(pt), _direction(dir) {}
543 enum CanMove { UNSET = 0, YES = 1, NO = 2 };
548 virtual CanMove canMoveTo(
const Point &destPos);
556 virtual void moveTo(
const Point &destPos, Direction dir = DIR_NONE);
Direction getDirection() const
Definition: map.h:388
bool isWallOrSecretDoor() const
Definition: map.h:91
Point getDirectionDelta() const
bool isWallOrDoorway() const
Definition: map.h:96
virtual Point getViewportPosition(const Point &viewportSize)
Point getViewportPosition(const Point &viewportSize)
Definition: map.h:348
void getTileAt(const Point &pt, MapTile *tile)
Definition: map.h:340
Common::String getName() const
Definition: map.h:437
size_t height() const
Definition: map.h:252
void setDirection(Direction dir)
MapTile()
Definition: map.h:69
Point getDirectionDelta() const
Definition: map.h:404
bool changeLevel(int delta)
Definition: map.h:454
virtual ~MapBase()
Definition: map.h:185
virtual bool changeLevel(int delta)
Definition: map.h:232
virtual ~MapTile()
Definition: map.h:76
bool isMapWrapped() const
Definition: map.h:470
Definition: serializer.h:79
Direction getDirection() const
virtual void shiftViewport(const Point &delta)
uint getMapIndex() const
Definition: map.h:292
Definition: detection.h:27
virtual uint getLevel() const
Definition: map.h:237
void shiftViewport(const Point &delta)
Definition: map.h:420
Point getTilesPerOrigTile() const
Definition: map.h:429
MapId getMapId() const
Definition: map.h:287
size_t width() const
Definition: map.h:247
void update()
Definition: map.h:478
void setPosition(const Point &pt)
Definition: map.h:380
void setDirection(Direction dir)
Definition: map.h:396
bool isSolid() const
Definition: map.h:101
MapBase(Game *game, Map *map)
Definition: map.h:179
uint getLevel() const
Definition: map.h:462
virtual void getTileAt(const Point &pt, MapTile *tile)
size_t height() const
Definition: map.h:364
int16 x
Definition: rect.h:46
Map()
Definition: map.h:310
virtual ~Map()
Definition: map.h:315
MapWidget * getPlayerWidget() const
Definition: map.h:445
int16 y
Definition: rect.h:47
Point getDeltaPosition(const Point &delta)
Definition: map.h:412
Point getPosition() const
Definition: map.h:372
Point getPosition() const
bool isDoor() const
Definition: map.h:86
virtual Point getDeltaPosition(const Point &delta)
size_t width() const
Definition: map.h:356
virtual bool isMapWrapped() const
Definition: map.h:242
void setPosition(const Point &pt)