1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/widgets/transport.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_tile.h"
#include "ultima/ultima1/maps/map_overworld.h"
#include "common/algorithm.h"
namespace Ultima {
namespace Ultima1 {
namespace Widgets {
TransportOnFoot::TransportOnFoot(Ultima1Game *game, Maps::MapBase *map) : OverworldWidget(game, map) {
_name = game->_res->TRANSPORT_NAMES[0];
}
uint TransportOnFoot::getTileNum() const {
return 8;
}
/*-------------------------------------------------------------------*/
Transport::Transport(Ultima1Game *game, Maps::MapBase *map, uint transportId) :
OverworldWidget(game, map), _transportId(transportId) {
_name = game->_res->TRANSPORT_NAMES[transportId];
}
void Transport::board() {
assert(dynamic_cast<Widgets::TransportOnFoot *>(_map->_playerWidget));
_map->removeWidget(_map->_playerWidget);
_map->_playerWidget = this;
addInfoMsg(Common::String::format(" %s", _name.c_str()));
_game->endOfTurn();
}
void Transport::disembark() {
Maps::U1MapTile tile;
Point pt = _map->getPosition();
Maps::MapOverworld *map = static_cast<Maps::MapOverworld *>(_map);
// WORKAROUND: The original allowed dis-embarking if ground tiles were within two tiles of the transport.
// It makes better sense to only allow if it's within one tile of the transport (i.e. the ground is adjacent)
bool hasGround = false;
for (int deltaY = -1; deltaY <= 1 && !hasGround; ++deltaY) {
for (int deltaX = -1; deltaX <= 1 && !hasGround; ++deltaX) {
_map->getTileAt(pt + Point(deltaX, deltaY), &tile);
hasGround = tile._tileId != Maps::OTILE_OCEAN;
}
}
if (tile._tileId > Maps::OTILE_WOODS || !hasGround) {
addInfoMsg(getGame()->_res->CANT_LEAVE_IT_HERE);
} else {
map->addOnFoot();
}
}
/*-------------------------------------------------------------------*/
EMPTY_MESSAGE_MAP(Horse, Transport);
Horse::Horse(Ultima1Game *game, Maps::MapBase *map) : Transport(game, map, 1) {
}
/*-------------------------------------------------------------------*/
EMPTY_MESSAGE_MAP(Cart, Transport);
Cart::Cart(Ultima1Game *game, Maps::MapBase *map) : Transport(game, map, 2) {
}
/*-------------------------------------------------------------------*/
EMPTY_MESSAGE_MAP(Raft, Transport);
Raft::Raft(Ultima1Game *game, Maps::MapBase *map) : Transport(game, map, 3) {
}
/*-------------------------------------------------------------------*/
EMPTY_MESSAGE_MAP(Frigate, Transport);
Frigate::Frigate(Ultima1Game *game, Maps::MapBase *map) : Transport(game, map, 4) {
}
Common::String Frigate::getWeaponsName() {
Ultima1Game *game = static_cast<Ultima1Game *>(_game);
return game->_res->TRANSPORT_WEAPONS[0];
}
/*-------------------------------------------------------------------*/
EMPTY_MESSAGE_MAP(Aircar, Transport);
Aircar::Aircar(Ultima1Game *game, Maps::MapBase *map) : Transport(game, map, 5) {
}
Common::String Aircar::getWeaponsName() {
Ultima1Game *game = static_cast<Ultima1Game *>(_game);
return game->_res->TRANSPORT_WEAPONS[1];
}
/*-------------------------------------------------------------------*/
EMPTY_MESSAGE_MAP(Shuttle, Transport);
Shuttle::Shuttle(Ultima1Game *game, Maps::MapBase *map) : Transport(game, map, 6),
_space1(1000), _space2(1000) {
}
void Shuttle::synchronize(Common::Serializer &s) {
Transport::synchronize(s);
s.syncAsUint16LE(_space1);
s.syncAsUint16LE(_space2);
}
/*-------------------------------------------------------------------*/
EMPTY_MESSAGE_MAP(TimeMachine, Transport);
TimeMachine::TimeMachine(Ultima1Game *game, Maps::MapBase *map) : Transport(game, map, 7) {
}
void TimeMachine::board() {
// TODO
Transport::board();
}
} // End of namespace Widgets
} // End of namespace Ultima1
} // End of namespace Ultima
|