2013-06-18 17:52:25 +02:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on the original source code of Lord Avalot d'Argent version 1.3.
|
|
|
|
* Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:08:58 +02:00
|
|
|
#include "avalanche/avalanche.h"
|
|
|
|
|
2013-06-18 17:52:25 +02:00
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/random.h"
|
|
|
|
#include "common/error.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/debug-channels.h"
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/textconsole.h"
|
2013-08-19 18:18:02 +02:00
|
|
|
#include "common/savefile.h"
|
|
|
|
|
2013-06-18 17:52:25 +02:00
|
|
|
#include "engines/util.h"
|
|
|
|
|
2013-08-19 21:14:21 +02:00
|
|
|
#include "gui/saveload.h"
|
2013-08-20 21:26:23 +02:00
|
|
|
#include "graphics/thumbnail.h"
|
2013-07-11 18:02:15 +02:00
|
|
|
|
2013-06-18 17:52:25 +02:00
|
|
|
namespace Avalanche {
|
|
|
|
|
2013-07-24 17:12:46 +02:00
|
|
|
AvalancheEngine *AvalancheEngine::s_Engine = 0;
|
|
|
|
|
|
|
|
AvalancheEngine::AvalancheEngine(OSystem *syst, const AvalancheGameDescription *gd) : Engine(syst), _gameDescription(gd) {
|
|
|
|
_system = syst;
|
2013-07-24 17:52:57 +02:00
|
|
|
s_Engine = this;
|
2013-07-24 17:12:46 +02:00
|
|
|
_console = new AvalancheConsole(this);
|
|
|
|
|
|
|
|
_rnd = new Common::RandomSource("avalanche");
|
2013-09-07 09:00:34 +02:00
|
|
|
_rnd->setSeed(42);
|
2013-07-24 17:52:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AvalancheEngine::~AvalancheEngine() {
|
|
|
|
delete _console;
|
|
|
|
delete _rnd;
|
|
|
|
|
|
|
|
delete _graphics;
|
2013-07-27 21:36:07 +02:00
|
|
|
delete _parser;
|
2013-07-24 18:12:16 +02:00
|
|
|
|
|
|
|
delete _avalot;
|
2013-07-24 18:50:13 +02:00
|
|
|
delete _pingo;
|
2013-07-24 19:43:10 +02:00
|
|
|
delete _scrolls;
|
|
|
|
delete _lucerna;
|
2013-09-19 20:53:47 +02:00
|
|
|
delete _background;
|
2013-07-24 19:43:10 +02:00
|
|
|
delete _sequence;
|
2013-09-08 11:30:23 +02:00
|
|
|
delete _timer;
|
2013-09-07 19:09:06 +02:00
|
|
|
delete _animation;
|
2013-07-24 19:43:10 +02:00
|
|
|
delete _acci;
|
2013-09-18 07:47:52 +02:00
|
|
|
delete _menu;
|
2013-07-24 19:43:10 +02:00
|
|
|
delete _closing;
|
2013-09-05 15:48:30 +02:00
|
|
|
delete _gyro;
|
2013-09-18 23:59:26 +02:00
|
|
|
delete _sound;
|
2013-07-24 17:52:57 +02:00
|
|
|
}
|
2013-07-24 17:12:46 +02:00
|
|
|
|
2013-07-24 17:52:57 +02:00
|
|
|
Common::ErrorCode AvalancheEngine::initialize() {
|
|
|
|
_graphics = new Graphics(this);
|
2013-07-27 21:36:07 +02:00
|
|
|
_parser = new Parser(this);
|
2013-07-24 17:12:46 +02:00
|
|
|
|
2013-07-24 18:12:16 +02:00
|
|
|
_avalot = new Avalot(this);
|
2013-07-24 18:25:07 +02:00
|
|
|
_gyro = new Gyro(this);
|
2013-07-24 18:50:13 +02:00
|
|
|
_pingo = new Pingo(this);
|
2013-07-24 19:43:10 +02:00
|
|
|
_scrolls = new Scrolls(this);
|
|
|
|
_lucerna = new Lucerna(this);
|
2013-09-19 20:53:47 +02:00
|
|
|
_background = new Background(this);
|
2013-07-24 19:43:10 +02:00
|
|
|
_sequence = new Sequence(this);
|
2013-09-08 11:30:23 +02:00
|
|
|
_timer = new Timer(this);
|
2013-09-07 19:09:06 +02:00
|
|
|
_animation = new Animation(this);
|
2013-07-24 19:43:10 +02:00
|
|
|
_acci = new Acci(this);
|
2013-09-18 07:47:52 +02:00
|
|
|
_menu = new Menu(this);
|
2013-07-24 19:43:10 +02:00
|
|
|
_closing = new Closing(this);
|
2013-09-18 23:59:26 +02:00
|
|
|
_sound = new SoundHandler(this);
|
2013-07-24 16:43:34 +02:00
|
|
|
|
2013-07-24 17:52:57 +02:00
|
|
|
_graphics->init();
|
2013-07-24 19:43:10 +02:00
|
|
|
_scrolls->init();
|
|
|
|
_lucerna->init();
|
|
|
|
_acci->init();
|
2013-09-03 17:45:11 +02:00
|
|
|
_parser->init();
|
2013-07-24 17:52:57 +02:00
|
|
|
|
|
|
|
return Common::kNoError;
|
2013-07-24 16:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GUI::Debugger *AvalancheEngine::getDebugger() {
|
|
|
|
return _console;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Platform AvalancheEngine::getPlatform() const {
|
|
|
|
return _platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AvalancheEngine::hasFeature(EngineFeature f) const {
|
2013-08-18 15:08:32 +02:00
|
|
|
return (f == kSupportsSavingDuringRuntime) || (f == kSupportsLoadingDuringRuntime);
|
2013-07-24 16:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *AvalancheEngine::getCopyrightString() const {
|
|
|
|
return "Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.";
|
|
|
|
}
|
|
|
|
|
2013-08-19 18:18:02 +02:00
|
|
|
void AvalancheEngine::synchronize(Common::Serializer &sz) {
|
|
|
|
//blockwrite(f, dna, sizeof(dna));
|
2013-09-13 22:58:24 +02:00
|
|
|
sz.syncAsByte(_animation->_direction);
|
2013-09-13 21:30:03 +02:00
|
|
|
sz.syncAsByte(_gyro->_carryNum);
|
2013-09-16 22:57:38 +02:00
|
|
|
for (int i = 0; i < kObjectNum; i++)
|
2013-09-13 21:30:03 +02:00
|
|
|
sz.syncAsByte(_gyro->_objects[i]);
|
|
|
|
sz.syncAsSint16LE(_gyro->_dnascore);
|
|
|
|
sz.syncAsSint32LE(_gyro->_money);
|
|
|
|
sz.syncAsByte(_gyro->_room);
|
|
|
|
sz.syncAsByte(_gyro->_wearing);
|
|
|
|
sz.syncAsByte(_gyro->_sworeNum);
|
|
|
|
sz.syncAsByte(_gyro->_saveNum);
|
|
|
|
sz.syncBytes(_gyro->_roomCount, 100);
|
|
|
|
sz.syncAsByte(_gyro->_alcoholLevel);
|
|
|
|
sz.syncAsByte(_gyro->_playedNim);
|
|
|
|
sz.syncAsByte(_gyro->_wonNim);
|
|
|
|
sz.syncAsByte(_gyro->_wineState);
|
|
|
|
sz.syncAsByte(_gyro->_cwytalotGone);
|
|
|
|
sz.syncAsByte(_gyro->_passwordNum);
|
|
|
|
sz.syncAsByte(_gyro->_aylesIsAwake);
|
|
|
|
sz.syncAsByte(_gyro->_drawbridgeOpen);
|
|
|
|
sz.syncAsByte(_gyro->_avariciusTalk);
|
|
|
|
sz.syncAsByte(_gyro->_boughtOnion);
|
|
|
|
sz.syncAsByte(_gyro->_rottenOnion);
|
|
|
|
sz.syncAsByte(_gyro->_onionInVinegar);
|
|
|
|
sz.syncAsByte(_gyro->_givenToSpludwick);
|
|
|
|
sz.syncAsByte(_gyro->_brummieStairs);
|
|
|
|
sz.syncAsByte(_gyro->_cardiffQuestionNum);
|
|
|
|
sz.syncAsByte(_gyro->_passedCwytalotInHerts);
|
|
|
|
sz.syncAsByte(_gyro->_avvyIsAwake);
|
|
|
|
sz.syncAsByte(_gyro->_avvyInBed);
|
|
|
|
sz.syncAsByte(_gyro->_userMovesAvvy);
|
2013-09-15 12:44:49 +02:00
|
|
|
sz.syncAsByte(_gyro->_npcFacing);
|
2013-09-13 21:30:03 +02:00
|
|
|
sz.syncAsByte(_gyro->_givenBadgeToIby);
|
|
|
|
sz.syncAsByte(_gyro->_friarWillTieYouUp);
|
|
|
|
sz.syncAsByte(_gyro->_tiedUp);
|
|
|
|
sz.syncAsByte(_gyro->_boxContent);
|
|
|
|
sz.syncAsByte(_gyro->_talkedToCrapulus);
|
|
|
|
sz.syncAsByte(_gyro->_jacquesState);
|
|
|
|
sz.syncAsByte(_gyro->_bellsAreRinging);
|
|
|
|
sz.syncAsByte(_gyro->_standingOnDais);
|
|
|
|
sz.syncAsByte(_gyro->_takenPen);
|
|
|
|
sz.syncAsByte(_gyro->_arrowTriggered);
|
|
|
|
sz.syncAsByte(_gyro->_arrowInTheDoor);
|
2013-08-19 18:18:02 +02:00
|
|
|
|
|
|
|
if (sz.isSaving()) {
|
2013-09-13 21:30:03 +02:00
|
|
|
uint16 like2drinkSize = _gyro->_favouriteDrink.size();
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsUint16LE(like2drinkSize);
|
|
|
|
for (uint16 i = 0; i < like2drinkSize; i++) {
|
2013-09-13 21:30:03 +02:00
|
|
|
char actChr = _gyro->_favouriteDrink[i];
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsByte(actChr);
|
|
|
|
}
|
|
|
|
|
2013-09-13 21:30:03 +02:00
|
|
|
uint16 favourite_songSize = _gyro->_favouriteSong.size();
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsUint16LE(favourite_songSize);
|
|
|
|
for (uint16 i = 0; i < favourite_songSize; i++) {
|
2013-09-13 21:30:03 +02:00
|
|
|
char actChr = _gyro->_favouriteSong[i];
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsByte(actChr);
|
|
|
|
}
|
|
|
|
|
2013-09-13 21:30:03 +02:00
|
|
|
uint16 worst_place_on_earthSize = _gyro->_worstPlaceOnEarth.size();
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsUint16LE(worst_place_on_earthSize);
|
|
|
|
for (uint16 i = 0; i < worst_place_on_earthSize; i++) {
|
2013-09-13 21:30:03 +02:00
|
|
|
char actChr = _gyro->_worstPlaceOnEarth[i];
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsByte(actChr);
|
|
|
|
}
|
|
|
|
|
2013-09-13 21:30:03 +02:00
|
|
|
uint16 spare_eveningSize = _gyro->_spareEvening.size();
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsUint16LE(spare_eveningSize);
|
|
|
|
for (uint16 i = 0; i < spare_eveningSize; i++) {
|
2013-09-13 21:30:03 +02:00
|
|
|
char actChr = _gyro->_spareEvening[i];
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsByte(actChr);
|
|
|
|
}
|
|
|
|
} else {
|
2013-09-13 21:30:03 +02:00
|
|
|
if (!_gyro->_favouriteDrink.empty())
|
|
|
|
_gyro->_favouriteDrink.clear();
|
2013-09-04 16:52:44 +02:00
|
|
|
uint16 like2drinkSize = 0;
|
|
|
|
char actChr = ' ';
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsUint16LE(like2drinkSize);
|
|
|
|
for (uint16 i = 0; i < like2drinkSize; i++) {
|
|
|
|
sz.syncAsByte(actChr);
|
2013-09-13 21:30:03 +02:00
|
|
|
_gyro->_favouriteDrink += actChr;
|
2013-08-19 18:18:02 +02:00
|
|
|
}
|
|
|
|
|
2013-09-13 21:30:03 +02:00
|
|
|
if (!_gyro->_favouriteSong.empty())
|
|
|
|
_gyro->_favouriteSong.clear();
|
2013-09-04 16:52:44 +02:00
|
|
|
uint16 favourite_songSize = 0;
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsUint16LE(favourite_songSize);
|
|
|
|
for (uint16 i = 0; i < favourite_songSize; i++) {
|
|
|
|
sz.syncAsByte(actChr);
|
2013-09-13 21:30:03 +02:00
|
|
|
_gyro->_favouriteSong += actChr;
|
2013-08-19 18:18:02 +02:00
|
|
|
}
|
|
|
|
|
2013-09-13 21:30:03 +02:00
|
|
|
if (!_gyro->_worstPlaceOnEarth.empty())
|
|
|
|
_gyro->_worstPlaceOnEarth.clear();
|
2013-09-04 16:52:44 +02:00
|
|
|
uint16 worst_place_on_earthSize = 0;
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsUint16LE(worst_place_on_earthSize);
|
|
|
|
for (uint16 i = 0; i < worst_place_on_earthSize; i++) {
|
|
|
|
sz.syncAsByte(actChr);
|
2013-09-13 21:30:03 +02:00
|
|
|
_gyro->_worstPlaceOnEarth += actChr;
|
2013-08-19 18:18:02 +02:00
|
|
|
}
|
|
|
|
|
2013-09-13 21:30:03 +02:00
|
|
|
if (!_gyro->_spareEvening.empty())
|
|
|
|
_gyro->_spareEvening.clear();
|
2013-09-04 16:52:44 +02:00
|
|
|
uint16 spare_eveningSize = 0;
|
2013-08-19 18:18:02 +02:00
|
|
|
sz.syncAsUint16LE(spare_eveningSize);
|
|
|
|
for (uint16 i = 0; i < spare_eveningSize; i++) {
|
|
|
|
sz.syncAsByte(actChr);
|
2013-09-13 21:30:03 +02:00
|
|
|
_gyro->_spareEvening += actChr;
|
2013-08-19 18:18:02 +02:00
|
|
|
}
|
|
|
|
}
|
2013-09-07 09:00:34 +02:00
|
|
|
|
2013-09-13 21:30:03 +02:00
|
|
|
sz.syncAsSint32LE(_gyro->_totalTime);
|
|
|
|
sz.syncAsByte(_gyro->_jumpStatus);
|
|
|
|
sz.syncAsByte(_gyro->_mushroomGrowing);
|
|
|
|
sz.syncAsByte(_gyro->_spludwickAtHome);
|
|
|
|
sz.syncAsByte(_gyro->_lastRoom);
|
|
|
|
sz.syncAsByte(_gyro->_lastRoomNotMap);
|
|
|
|
sz.syncAsByte(_gyro->_crapulusWillTell);
|
|
|
|
sz.syncAsByte(_gyro->_enterCatacombsFromLustiesRoom);
|
|
|
|
sz.syncAsByte(_gyro->_teetotal);
|
|
|
|
sz.syncAsByte(_gyro->_malagauche);
|
|
|
|
sz.syncAsByte(_gyro->_drinking);
|
|
|
|
sz.syncAsByte(_gyro->_enteredLustiesRoomAsMonk);
|
|
|
|
sz.syncAsByte(_gyro->_catacombX);
|
|
|
|
sz.syncAsByte(_gyro->_catacombY);
|
|
|
|
sz.syncAsByte(_gyro->_avvysInTheCupboard);
|
|
|
|
sz.syncAsByte(_gyro->_geidaFollows);
|
|
|
|
sz.syncAsByte(_gyro->_geidaSpin);
|
|
|
|
sz.syncAsByte(_gyro->_geidaTime);
|
|
|
|
sz.syncAsByte(_gyro->_nextBell);
|
|
|
|
sz.syncAsByte(_gyro->_givenPotionToGeida);
|
|
|
|
sz.syncAsByte(_gyro->_lustieIsAsleep);
|
|
|
|
sz.syncAsByte(_gyro->_flipToWhere);
|
|
|
|
sz.syncAsByte(_gyro->_flipToPed);
|
|
|
|
sz.syncAsByte(_gyro->_beenTiedUp);
|
|
|
|
sz.syncAsByte(_gyro->_sittingInPub);
|
|
|
|
sz.syncAsByte(_gyro->_spurgeTalkCount);
|
|
|
|
sz.syncAsByte(_gyro->_metAvaroid);
|
|
|
|
sz.syncAsByte(_gyro->_takenMushroom);
|
|
|
|
sz.syncAsByte(_gyro->_givenPenToAyles);
|
|
|
|
sz.syncAsByte(_gyro->_askedDogfoodAboutNim);
|
2013-08-19 18:18:02 +02:00
|
|
|
|
|
|
|
|
2013-09-05 01:48:16 +02:00
|
|
|
#if 0
|
2013-09-16 22:57:38 +02:00
|
|
|
for (int groi = 0; groi < numtr; groi++) {
|
2013-09-05 01:48:16 +02:00
|
|
|
if (tr[groi].quick) {
|
|
|
|
blockwrite(f, groi, 1);
|
|
|
|
tr[groi].savedata(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-04 16:52:44 +02:00
|
|
|
byte spriteNum = 0;
|
2013-08-20 13:37:14 +02:00
|
|
|
if (sz.isSaving()) {
|
2013-09-16 22:57:38 +02:00
|
|
|
for (int i = 0; i < _animation->kSpriteNumbMax; i++) {
|
2013-09-08 12:06:08 +02:00
|
|
|
if (_animation->_sprites[i]._quick)
|
2013-08-20 13:37:14 +02:00
|
|
|
spriteNum++;
|
2013-09-04 16:52:44 +02:00
|
|
|
}
|
2013-08-20 13:37:14 +02:00
|
|
|
}
|
|
|
|
sz.syncAsByte(spriteNum);
|
2013-09-07 09:00:34 +02:00
|
|
|
|
2013-09-04 16:52:44 +02:00
|
|
|
if (sz.isLoading()) {
|
2013-09-16 22:57:38 +02:00
|
|
|
for (int i = 0; i < _animation->kSpriteNumbMax; i++) { // Deallocate sprites.
|
2013-09-14 19:38:52 +02:00
|
|
|
AnimationType *spr = &_animation->_sprites[i];
|
|
|
|
if (spr->_quick)
|
|
|
|
spr->remove();
|
2013-08-20 13:37:14 +02:00
|
|
|
}
|
2013-09-04 16:52:44 +02:00
|
|
|
}
|
2013-08-20 13:37:14 +02:00
|
|
|
|
2013-09-16 22:57:38 +02:00
|
|
|
for (int i = 0; i < spriteNum; i++) {
|
2013-09-14 19:38:52 +02:00
|
|
|
AnimationType *spr = &_animation->_sprites[i];
|
|
|
|
sz.syncAsByte(spr->_id);
|
|
|
|
sz.syncAsByte(spr->_doCheck);
|
2013-09-07 09:00:34 +02:00
|
|
|
|
2013-08-20 13:37:14 +02:00
|
|
|
if (sz.isLoading()) {
|
2013-09-14 19:38:52 +02:00
|
|
|
spr->_quick = true;
|
|
|
|
spr->init(spr->_id, spr->_doCheck, _animation);
|
2013-08-19 18:18:02 +02:00
|
|
|
}
|
|
|
|
|
2013-09-14 19:38:52 +02:00
|
|
|
sz.syncAsByte(spr->_moveX);
|
|
|
|
sz.syncAsByte(spr->_moveY);
|
|
|
|
sz.syncAsByte(spr->_facingDir);
|
|
|
|
sz.syncAsByte(spr->_stepNum);
|
|
|
|
sz.syncAsByte(spr->_visible);
|
|
|
|
sz.syncAsByte(spr->_homing);
|
|
|
|
sz.syncAsByte(spr->_count);
|
|
|
|
sz.syncAsByte(spr->_info._xWidth);
|
|
|
|
sz.syncAsByte(spr->_speedX);
|
|
|
|
sz.syncAsByte(spr->_speedY);
|
|
|
|
sz.syncAsByte(spr->_animCount);
|
|
|
|
sz.syncAsSint16LE(spr->_homingX);
|
|
|
|
sz.syncAsSint16LE(spr->_homingY);
|
|
|
|
sz.syncAsByte(spr->_callEachStepFl);
|
|
|
|
sz.syncAsByte(spr->_eachStepProc);
|
|
|
|
sz.syncAsByte(spr->_vanishIfStill);
|
|
|
|
sz.syncAsSint16LE(spr->_x);
|
|
|
|
sz.syncAsSint16LE(spr->_y);
|
|
|
|
|
|
|
|
if (sz.isLoading() && spr->_visible)
|
|
|
|
spr->appear(spr->_x, spr->_y, spr->_facingDir);
|
2013-08-20 13:37:14 +02:00
|
|
|
}
|
|
|
|
|
2013-08-19 18:18:02 +02:00
|
|
|
//groi = 177;
|
|
|
|
//blockwrite(f, groi, 1);
|
|
|
|
|
|
|
|
//blockwrite(f, times, sizeof(times)); // Timeout.times: Timers.
|
2013-09-16 22:57:38 +02:00
|
|
|
for (int i = 0; i < 7; i++) {
|
2013-09-08 11:30:23 +02:00
|
|
|
sz.syncAsSint32LE(_timer->_times[i]._timeLeft);
|
|
|
|
sz.syncAsByte(_timer->_times[i]._action);
|
|
|
|
sz.syncAsByte(_timer->_times[i]._reason);
|
2013-08-19 18:18:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//blockwrite(f, seq, sizeof(seq)); // Sequencer information.
|
2013-09-08 00:02:20 +02:00
|
|
|
sz.syncBytes(_sequence->_seq, _sequence->kSeqLength);
|
2013-08-19 18:18:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AvalancheEngine::canSaveGameStateCurrently() { // TODO: Refine these!!!
|
2013-09-06 16:23:57 +02:00
|
|
|
return (!_gyro->_seeScroll && _gyro->_alive);
|
2013-08-18 15:08:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error AvalancheEngine::saveGameState(int slot, const Common::String &desc) {
|
2013-08-19 18:18:02 +02:00
|
|
|
return (saveGame(slot, desc) ? Common::kNoError : Common::kWritingFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AvalancheEngine::saveGame(const int16 slot, const Common::String &desc) {
|
2013-08-19 21:14:21 +02:00
|
|
|
Common::String fileName = getSaveFileName(slot);
|
2013-08-19 18:18:02 +02:00
|
|
|
Common::OutSaveFile *f = g_system->getSavefileManager()->openForSaving(fileName);
|
|
|
|
if (!f) {
|
|
|
|
warning("Can't create file '%s', game not saved.", fileName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-04 16:52:44 +02:00
|
|
|
const char *signature = "AVAL";
|
2013-08-19 21:14:21 +02:00
|
|
|
f->write(signature, 4);
|
|
|
|
|
2013-08-20 21:26:23 +02:00
|
|
|
// Write version. We can't restore from obsolete versions.
|
|
|
|
f->writeByte(kSavegameVersion);
|
2013-08-19 21:14:21 +02:00
|
|
|
|
2013-08-20 21:26:23 +02:00
|
|
|
f->writeUint32LE(desc.size());
|
2013-08-19 21:14:21 +02:00
|
|
|
f->write(desc.c_str(), desc.size());
|
2013-08-20 21:26:23 +02:00
|
|
|
::Graphics::saveThumbnail(*f);
|
2013-08-19 21:14:21 +02:00
|
|
|
|
2013-08-20 19:23:24 +02:00
|
|
|
TimeDate t;
|
|
|
|
_system->getTimeAndDate(t);
|
|
|
|
f->writeSint16LE(t.tm_mday);
|
|
|
|
f->writeSint16LE(t.tm_mon);
|
|
|
|
f->writeSint16LE(t.tm_year);
|
|
|
|
|
2013-08-19 18:18:02 +02:00
|
|
|
Common::Serializer sz(NULL, f);
|
|
|
|
synchronize(sz);
|
|
|
|
f->finalize();
|
|
|
|
delete f;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-19 21:14:21 +02:00
|
|
|
Common::String AvalancheEngine::getSaveFileName(const int slot) {
|
|
|
|
Common::String upperName = _targetName;
|
|
|
|
upperName.toUppercase();
|
|
|
|
return upperName+ Common::String::format("-%02d.SAV", slot);
|
|
|
|
}
|
|
|
|
|
2013-08-19 18:18:02 +02:00
|
|
|
bool AvalancheEngine::canLoadGameStateCurrently() { // TODO: Refine these!!!
|
2013-09-06 16:23:57 +02:00
|
|
|
return (!_gyro->_seeScroll);
|
2013-08-18 15:08:32 +02:00
|
|
|
}
|
|
|
|
|
2013-08-19 21:14:21 +02:00
|
|
|
Common::Error AvalancheEngine::loadGameState(int slot) {
|
|
|
|
return (loadGame(slot) ? Common::kNoError : Common::kReadingFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AvalancheEngine::loadGame(const int16 slot) {
|
|
|
|
Common::String fileName = getSaveFileName(slot);
|
|
|
|
Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName);
|
|
|
|
if (!f)
|
|
|
|
return false;
|
2013-08-20 21:26:23 +02:00
|
|
|
|
2013-08-19 21:14:21 +02:00
|
|
|
// Check for our signature.
|
|
|
|
Common::String signature;
|
2013-09-16 22:57:38 +02:00
|
|
|
for (int i = 0; i < 4; i++)
|
2013-08-19 21:14:21 +02:00
|
|
|
signature += f->readByte();
|
|
|
|
if (signature != "AVAL")
|
|
|
|
return false;
|
|
|
|
|
2013-08-20 21:26:23 +02:00
|
|
|
// Check version. We can't restore from obsolete versions.
|
|
|
|
byte saveVersion = f->readByte();
|
|
|
|
if (saveVersion != kSavegameVersion) {
|
|
|
|
warning("Savegame of incompatible version!");
|
|
|
|
delete f;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-20 19:23:24 +02:00
|
|
|
// Read the description.
|
2013-08-19 21:14:21 +02:00
|
|
|
uint32 descSize = f->readUint32LE();
|
2013-08-20 19:23:24 +02:00
|
|
|
Common::String description;
|
|
|
|
for (uint32 i = 0; i < descSize; i++) {
|
|
|
|
char actChar = f->readByte();
|
|
|
|
description += actChar;
|
|
|
|
}
|
|
|
|
|
2013-09-09 23:00:24 +02:00
|
|
|
description.toUppercase();
|
2013-08-20 21:26:23 +02:00
|
|
|
::Graphics::skipThumbnail(*f);
|
|
|
|
|
|
|
|
// Read the time the game was saved.
|
2013-08-20 19:23:24 +02:00
|
|
|
TimeDate t;
|
|
|
|
t.tm_mday = f->readSint16LE();
|
|
|
|
t.tm_mon = f->readSint16LE();
|
|
|
|
t.tm_year = f->readSint16LE();
|
2013-08-19 21:14:21 +02:00
|
|
|
|
|
|
|
Common::Serializer sz(f, NULL);
|
|
|
|
synchronize(sz);
|
|
|
|
delete f;
|
|
|
|
|
2013-09-18 08:00:30 +02:00
|
|
|
_gyro->_isLoaded = true;
|
2013-09-06 16:23:57 +02:00
|
|
|
_gyro->_seeScroll = true; // This prevents display of the new sprites before the new picture is loaded.
|
2013-08-20 13:37:14 +02:00
|
|
|
|
2013-09-06 16:23:57 +02:00
|
|
|
if (_gyro->_holdTheDawn) {
|
|
|
|
_gyro->_holdTheDawn = false;
|
2013-08-20 13:37:14 +02:00
|
|
|
_lucerna->dawn();
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:53:47 +02:00
|
|
|
_background->forgetBackgroundSprites();
|
2013-09-07 15:58:02 +02:00
|
|
|
_lucerna->minorRedraw();
|
2013-09-18 07:47:52 +02:00
|
|
|
_menu->setup();
|
2013-09-15 17:42:32 +02:00
|
|
|
_gyro->_whereIs[Gyro::kPeopleAvalot - 150] = _gyro->_room;
|
2013-09-06 16:23:57 +02:00
|
|
|
_gyro->_alive = true;
|
2013-09-07 15:58:02 +02:00
|
|
|
_lucerna->refreshObjectList();
|
2013-09-08 12:06:08 +02:00
|
|
|
_animation->updateSpeed();
|
2013-09-07 15:58:02 +02:00
|
|
|
_lucerna->drawDirection();
|
2013-09-06 16:23:57 +02:00
|
|
|
_gyro->_onToolbar = false;
|
2013-09-07 20:02:14 +02:00
|
|
|
_animation->animLink();
|
2013-09-19 20:53:47 +02:00
|
|
|
_background->updateBackgroundSprites();
|
2013-09-07 09:00:34 +02:00
|
|
|
|
2013-09-09 23:00:24 +02:00
|
|
|
Common::String tmpStr = Common::String::format("%cLoaded: %c%s.ASG%c%c%c%s%c%csaved on %s.",
|
|
|
|
Scrolls::kControlItalic, Scrolls::kControlRoman, description.c_str(), Scrolls::kControlCenter,
|
2013-09-12 21:44:36 +02:00
|
|
|
Scrolls::kControlNewLine, Scrolls::kControlNewLine, _gyro->_roomnName.c_str(), Scrolls::kControlNewLine,
|
2013-09-09 23:00:24 +02:00
|
|
|
Scrolls::kControlNewLine, expandDate(t.tm_mday, t.tm_mon, t.tm_year).c_str());
|
|
|
|
_scrolls->displayText(tmpStr);
|
2013-08-20 19:23:24 +02:00
|
|
|
|
2013-09-14 19:38:52 +02:00
|
|
|
AnimationType *avvy = &_animation->_sprites[0];
|
|
|
|
if (avvy->_quick && avvy->_visible)
|
2013-09-13 22:58:24 +02:00
|
|
|
_animation->changeDirection(0, _animation->_direction); // We push Avvy in the right direction is he was moving.
|
2013-08-20 19:23:24 +02:00
|
|
|
|
2013-08-19 21:14:21 +02:00
|
|
|
return true;
|
2013-08-18 15:08:32 +02:00
|
|
|
}
|
|
|
|
|
2013-08-20 19:23:24 +02:00
|
|
|
Common::String AvalancheEngine::expandDate(int d, int m, int y) {
|
2013-09-07 23:42:34 +02:00
|
|
|
static const Common::String months[12] = {
|
2013-08-20 19:23:24 +02:00
|
|
|
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
|
|
|
|
};
|
|
|
|
|
|
|
|
Common::String month = months[m];
|
2013-09-06 16:23:57 +02:00
|
|
|
Common::String day = _gyro->intToStr(d);
|
2013-08-20 19:23:24 +02:00
|
|
|
|
|
|
|
if (((1 <= d) && (d <= 9)) || ((21 <= d) && (d <= 31)))
|
|
|
|
switch (d % 10) {
|
|
|
|
case 1:
|
2013-09-09 23:00:24 +02:00
|
|
|
day += "st";
|
2013-08-20 19:23:24 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-09-09 23:00:24 +02:00
|
|
|
day += "nd";
|
2013-08-20 19:23:24 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2013-09-09 23:00:24 +02:00
|
|
|
day += "rd";
|
2013-08-20 19:23:24 +02:00
|
|
|
break;
|
|
|
|
default:
|
2013-09-09 23:00:24 +02:00
|
|
|
day += "th";
|
2013-08-20 19:23:24 +02:00
|
|
|
}
|
|
|
|
|
2013-09-06 16:23:57 +02:00
|
|
|
return day + ' ' + month + ' ' + _gyro->intToStr(y + 1900);
|
2013-08-20 19:23:24 +02:00
|
|
|
}
|
|
|
|
|
2013-07-24 16:43:34 +02:00
|
|
|
void AvalancheEngine::updateEvents() {
|
|
|
|
Common::Event event;
|
|
|
|
|
|
|
|
while (_eventMan->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
2013-08-16 23:02:53 +02:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2013-09-07 18:00:00 +02:00
|
|
|
_lucerna->_holdLeftMouse = true; // Used in Lucerna::checkclick() and Dropdown::menu_link().
|
2013-08-16 23:02:53 +02:00
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
2013-09-07 18:00:00 +02:00
|
|
|
_lucerna->_holdLeftMouse = false; // Same as above.
|
2013-08-16 23:02:53 +02:00
|
|
|
break;
|
2013-07-24 16:43:34 +02:00
|
|
|
case Common::EVENT_KEYDOWN:
|
2013-07-24 18:12:16 +02:00
|
|
|
_avalot->handleKeyDown(event);
|
2013-09-04 16:52:44 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-07-24 12:55:01 +02:00
|
|
|
}
|
|
|
|
}
|
2013-07-24 16:43:34 +02:00
|
|
|
}
|
2013-07-02 15:59:27 +02:00
|
|
|
|
2013-08-06 01:13:25 +02:00
|
|
|
bool AvalancheEngine::getEvent(Common::Event &event) {
|
|
|
|
return _eventMan->pollEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:29:22 +02:00
|
|
|
Common::Point AvalancheEngine::getMousePos() {
|
|
|
|
return _eventMan->getMousePos();
|
|
|
|
}
|
2013-07-02 15:59:27 +02:00
|
|
|
|
2013-07-24 16:43:34 +02:00
|
|
|
Common::Error AvalancheEngine::run() {
|
2013-07-24 17:52:57 +02:00
|
|
|
Common::ErrorCode err = initialize();
|
|
|
|
if (err != Common::kNoError)
|
|
|
|
return err;
|
2013-06-18 17:52:25 +02:00
|
|
|
|
2013-07-24 16:43:34 +02:00
|
|
|
do {
|
2013-09-20 07:35:50 +02:00
|
|
|
_avalot->runAvalot();
|
2013-06-19 16:59:12 +02:00
|
|
|
|
2013-09-21 12:36:19 +02:00
|
|
|
#if 0
|
2013-09-05 21:45:07 +02:00
|
|
|
//switch (_storage._operation) {
|
|
|
|
//case kRunShootemup:
|
|
|
|
// run("seu.avx", kJsb, kBflight, kNormal);
|
|
|
|
// break;
|
|
|
|
//case kRunDosshell:
|
|
|
|
// dosShell();
|
|
|
|
// break;
|
|
|
|
//case kRunGhostroom:
|
|
|
|
// run("g-room.avx", kJsb, kNoBflight, kNormal);
|
|
|
|
// break;
|
|
|
|
//case kRunGolden:
|
|
|
|
// run("golden.avx", kJsb, kBflight, kMusical);
|
|
|
|
// break;
|
|
|
|
//}
|
2013-09-21 12:36:19 +02:00
|
|
|
#endif
|
2013-06-19 16:59:12 +02:00
|
|
|
|
2013-09-16 14:10:31 +02:00
|
|
|
} while (!_gyro->_letMeOut && !shouldQuit());
|
2013-06-19 16:59:12 +02:00
|
|
|
|
2013-09-09 23:00:24 +02:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
2013-06-19 16:59:12 +02:00
|
|
|
|
2013-09-09 23:00:24 +02:00
|
|
|
#if 0
|
2013-09-09 23:34:12 +02:00
|
|
|
void AvalancheEngine::run(Common::String what, bool withJsb, bool withBflight, Elm how) {
|
|
|
|
warning("STUB: run(%s)", what.c_str());
|
|
|
|
// Probably there'll be no need of this function, as all *.AVX-es will become classes.
|
|
|
|
}
|
|
|
|
|
2013-09-09 23:00:24 +02:00
|
|
|
Common::String AvalancheEngine::elmToStr(Elm how) {
|
|
|
|
switch (how) {
|
|
|
|
case kNormal:
|
|
|
|
case kMusical:
|
|
|
|
return Common::String("jsb");
|
|
|
|
case kRegi:
|
|
|
|
return Common::String("REGI");
|
|
|
|
case kElmpoyten:
|
|
|
|
return Common::String("ELMPOYTEN");
|
|
|
|
// Useless, but silent a warning
|
|
|
|
default:
|
|
|
|
return Common::String("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as keypressed1().
|
|
|
|
void AvalancheEngine::flushBuffer() {
|
|
|
|
warning("STUB: flushBuffer()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AvalancheEngine::dosShell() {
|
|
|
|
warning("STUB: dosShell()");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Needed in dos_shell(). TODO: Remove later.
|
|
|
|
Common::String AvalancheEngine::commandCom() {
|
|
|
|
warning("STUB: commandCom()");
|
|
|
|
return ("STUB: commandCom()");
|
|
|
|
}
|
2013-09-07 09:00:34 +02:00
|
|
|
|
2013-09-09 23:00:24 +02:00
|
|
|
// Needed for run_avalot()'s errors. TODO: Remove later.
|
|
|
|
void AvalancheEngine::explain(byte error) {
|
|
|
|
warning("STUB: explain()");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Needed later.
|
|
|
|
void AvalancheEngine::quit() {
|
|
|
|
cursorOn();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2013-06-18 17:52:25 +02:00
|
|
|
|
|
|
|
} // End of namespace Avalanche
|