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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
/* 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/ultima4/map/annotation.h"
#include "ultima/ultima4/map/location.h"
#include "ultima/ultima4/map/mapmgr.h"
#include "ultima/ultima4/map/shrine.h"
#include "ultima/ultima4/controllers/read_choice_controller.h"
#include "ultima/ultima4/controllers/read_string_controller.h"
#include "ultima/ultima4/controllers/wait_controller.h"
#include "ultima/ultima4/core/config.h"
#include "ultima/ultima4/core/settings.h"
#include "ultima/ultima4/core/types.h"
#include "ultima/ultima4/events/event_handler.h"
#include "ultima/ultima4/filesys/u4file.h"
#include "ultima/ultima4/game/context.h"
#include "ultima/ultima4/game/game.h"
#include "ultima/ultima4/game/creature.h"
#include "ultima/ultima4/game/names.h"
#include "ultima/ultima4/game/player.h"
#include "ultima/ultima4/game/portal.h"
#include "ultima/ultima4/gfx/imagemgr.h"
#include "ultima/ultima4/gfx/screen.h"
#include "ultima/ultima4/map/tileset.h"
#include "ultima/ultima4/sound/music.h"
#include "ultima/ultima4/ultima4.h"
namespace Ultima {
namespace Ultima4 {
Shrines *g_shrines;
Shrines::Shrines() : _cycles(0), _completedCycles(0) {
g_shrines = this;
}
Shrines::~Shrines() {
g_shrines = nullptr;
}
void Shrines::loadAdvice() {
_advice = u4read_stringtable("shrines");
}
/*-------------------------------------------------------------------*/
bool shrineCanEnter(const Portal *p) {
Shrine *shrine = dynamic_cast<Shrine *>(mapMgr->get(p->_destid));
assert(shrine);
if (!g_context->_party->canEnterShrine(shrine->getVirtue())) {
g_screen->screenMessage("Thou dost not bear the rune of entry! A strange force keeps you out!\n");
return 0;
}
return 1;
}
bool isShrine(Map *punknown) {
Shrine *ps;
if ((ps = dynamic_cast<Shrine *>(punknown)) != nullptr)
return true;
else
return false;
}
/*-------------------------------------------------------------------*/
Shrine::Shrine() : _virtue(VIRT_HONESTY) {}
Common::String Shrine::getName() {
if (_name.empty()) {
_name = "Shrine of ";
_name += getVirtueName(_virtue);
}
return _name;
}
Virtue Shrine::getVirtue() const {
return _virtue;
}
Common::String Shrine::getMantra() const {
return _mantra;
}
void Shrine::setVirtue(Virtue v) {
_virtue = v;
}
void Shrine::setMantra(const Common::String &m) {
_mantra = m;
}
void Shrine::enter() {
if (!g_shrines->isAdviceLoaded())
g_shrines->loadAdvice();
#ifdef IOS_ULTIMA4
U4IOS::IOSHideGameControllerHelper hideControllsHelper;
#endif
if (settings._enhancements && settings._enhancementsOptions._u5Shrines)
enhancedSequence();
else
g_screen->screenMessage("You enter the ancient shrine and sit before the altar...");
g_screen->screenMessage("\nUpon which virtue dost thou meditate?\n");
Common::String virtue;
#ifdef IOS_ULTIMA4
{
U4IOS::IOSConversationHelper inputVirture;
inputVirture.beginConversation(U4IOS::UIKeyboardTypeDefault, "Upon which virtue dost thou meditate?");
#endif
virtue = ReadStringController::get(32, TEXT_AREA_X + g_context->_col, TEXT_AREA_Y + g_context->_line);
#ifdef IOS_ULTIMA4
}
#endif
int choice;
g_screen->screenMessage("\n\nFor how many Cycles (0-3)? ");
#ifdef IOS_ULTIMA4
{
U4IOS::IOSConversationChoiceHelper cyclesChoice;
cyclesChoice.updateChoices("0123 \015\033");
#endif
choice = ReadChoiceController::get("0123\015\033");
#ifdef IOS_ULTIMA4
}
#endif
if (choice == '\033' || choice == '\015')
g_shrines->_cycles = 0;
else
g_shrines->_cycles = choice - '0';
g_shrines->_completedCycles = 0;
g_screen->screenMessage("\n\n");
// ensure the player chose the right virtue and entered a valid number for cycles
if (scumm_strnicmp(virtue.c_str(), getVirtueName(getVirtue()), 6) != 0 || g_shrines->_cycles == 0) {
g_screen->screenMessage("Thou art unable to focus thy thoughts on this subject!\n");
eject();
return;
}
if (((g_ultima->_saveGame->_moves / SHRINE_MEDITATION_INTERVAL) >= 0x10000) ||
(((g_ultima->_saveGame->_moves / SHRINE_MEDITATION_INTERVAL) & 0xffff) != g_ultima->_saveGame->_lastMeditation)) {
g_screen->screenMessage("Begin Meditation\n");
meditationCycle();
} else {
g_screen->screenMessage("Thy mind is still weary from thy last Meditation!\n");
eject();
}
}
void Shrine::enhancedSequence() {
// Replace the 'static' avatar tile with grass
_annotations->add(Coords(5, 6, g_context->_location->_coords.z), _tileSet->getByName("grass")->getId(), false, true);
g_screen->screenDisableCursor();
g_screen->screenMessage("You approach\nthe ancient\nshrine...\n");
gameUpdateScreen();
EventHandler::wait_cycles(settings._gameCyclesPerSecond);
Object *obj = addCreature(creatureMgr->getById(BEGGAR_ID), Coords(5, 10, g_context->_location->_coords.z));
obj->setTile(_tileSet->getByName("avatar")->getId());
gameUpdateScreen();
EventHandler::wait_msecs(400);
g_context->_location->_map->move(obj, DIR_NORTH);
gameUpdateScreen();
EventHandler::wait_msecs(400);
g_context->_location->_map->move(obj, DIR_NORTH);
gameUpdateScreen();
EventHandler::wait_msecs(400);
g_context->_location->_map->move(obj, DIR_NORTH);
gameUpdateScreen();
EventHandler::wait_msecs(400);
g_context->_location->_map->move(obj, DIR_NORTH);
gameUpdateScreen();
EventHandler::wait_msecs(800);
obj->setTile(creatureMgr->getById(BEGGAR_ID)->getTile());
gameUpdateScreen();
g_screen->screenMessage("\n...and kneel before the altar.\n");
EventHandler::wait_cycles(settings._gameCyclesPerSecond);
g_screen->screenEnableCursor();
}
void Shrine::meditationCycle() {
// Find our interval for meditation
int interval = (settings._shrineTime * 1000) / MEDITATION_MANTRAS_PER_CYCLE;
interval -= (interval % settings._eventTimerGranularity);
interval /= settings._eventTimerGranularity;
if (interval <= 0)
interval = 1;
g_ultima->_saveGame->_lastMeditation = (g_ultima->_saveGame->_moves / SHRINE_MEDITATION_INTERVAL) & 0xffff;
g_screen->screenDisableCursor();
for (int i = 0; i < MEDITATION_MANTRAS_PER_CYCLE; i++) {
WaitController controller(interval);
eventHandler->pushController(&controller);
controller.wait();
g_screen->screenMessage(".");
g_screen->update();
}
askMantra();
}
void Shrine::askMantra() {
g_screen->screenEnableCursor();
g_screen->screenMessage("\nMantra: ");
g_screen->update(); // FIXME: needed?
Common::String mantra;
#ifdef IOS_ULTIMA4
{
U4IOS::IOSConversationHelper mantraHelper;
mantraHelper.beginConversation(U4IOS::UIKeyboardTypeASCIICapable, "Mantra?");
#endif
mantra = ReadStringController::get(4, TEXT_AREA_X + g_context->_col, TEXT_AREA_Y + g_context->_line);
g_screen->screenMessage("\n");
#ifdef IOS_ULTIMA4
}
#endif
if (scumm_stricmp(mantra.c_str(), getMantra().c_str()) != 0) {
g_context->_party->adjustKarma(KA_BAD_MANTRA);
g_screen->screenMessage("Thou art not able to focus thy thoughts with that Mantra!\n");
eject();
} else if (--g_shrines->_cycles > 0) {
g_shrines->_completedCycles++;
g_context->_party->adjustKarma(KA_MEDITATION);
meditationCycle();
} else {
g_shrines->_completedCycles++;
g_context->_party->adjustKarma(KA_MEDITATION);
bool elevated = g_shrines->_completedCycles == 3 && g_context->_party->attemptElevation(getVirtue());
if (elevated)
g_screen->screenMessage("\nThou hast achieved partial Avatarhood in the Virtue of %s\n\n",
getVirtueName(getVirtue()));
else
g_screen->screenMessage("\nThy thoughts are pure. "
"Thou art granted a vision!\n");
#ifdef IOS_ULTIMA4
U4IOS::IOSConversationChoiceHelper choiceDialog;
choiceDialog.updateChoices(" ");
U4IOS::testFlightPassCheckPoint(Common::String("Gained avatarhood in: ")
+ getVirtueName(getVirtue()));
#endif
ReadChoiceController::get("");
showVision(elevated);
ReadChoiceController::get("");
gameSetViewMode(VIEW_NORMAL);
eject();
}
}
void Shrine::showVision(bool elevated) {
static const char *visionImageNames[] = {
BKGD_SHRINE_HON, BKGD_SHRINE_COM, BKGD_SHRINE_VAL, BKGD_SHRINE_JUS,
BKGD_SHRINE_SAC, BKGD_SHRINE_HNR, BKGD_SHRINE_SPI, BKGD_SHRINE_HUM
};
if (elevated) {
g_screen->screenMessage("Thou art granted a vision!\n");
gameSetViewMode(VIEW_RUNE);
g_screen->screenDrawImageInMapArea(visionImageNames[getVirtue()]);
} else {
g_screen->screenMessage("\n%s", g_shrines->_advice[
getVirtue() * 3 + g_shrines->_completedCycles - 1].c_str());
}
}
void Shrine::eject() {
g_game->exitToParentMap();
g_music->playMapMusic();
g_context->_location->_turnCompleter->finishTurn();
}
} // End of namespace Ultima4
} // End of namespace Ultima
|