Skip to content

Commit

Permalink
DRACI: Saving improvements (item in hand and hero position).
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Mar 8, 2014
1 parent da157fb commit 579c343
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
23 changes: 22 additions & 1 deletion engines/draci/game.cpp
Expand Up @@ -926,10 +926,12 @@ void Game::inventoryDraw() {
void Game::inventoryReload() {
// Make sure all items are loaded into memory (e.g., after loading a
// savegame) by re-putting them on the same spot in the inventory.
GameItem *tempItem = _currentItem;
for (uint i = 0; i < kInventorySlots; ++i) {
putItem(_inventory[i], i);
}
setPreviousItemPosition(0);
_currentItem = tempItem;
}

void Game::inventorySwitch(int keycode) {
Expand Down Expand Up @@ -1572,7 +1574,7 @@ Game::~Game() {
delete[] _items;
}

void Game::DoSync(Common::Serializer &s) {
void Game::DoSync(Common::Serializer &s, uint8 saveVersion) {
s.syncAsUint16LE(_currentRoom._roomNum);

for (uint i = 0; i < _info._numObjects; ++i) {
Expand Down Expand Up @@ -1603,6 +1605,25 @@ void Game::DoSync(Common::Serializer &s) {
s.syncAsSint16LE(_dialogueVars[i]);
}

if(saveVersion >= 2) {
setPositionLoaded(true);
if (s.isSaving()) {
s.syncAsSint16LE(_hero.x);
s.syncAsSint16LE(_hero.y);

int handItemID = _currentItem ? _currentItem->_absNum : -1;
s.syncAsSint16LE(handItemID);
} else {
s.syncAsSint16LE(_heroLoading.x);
s.syncAsSint16LE(_heroLoading.y);

int handItemID = -1;
s.syncAsSint16LE(handItemID);
_currentItem = getItem(handItemID);
}
} else {
_currentItem = 0;
}
}

static double real_to_double(byte real[6]) {
Expand Down
7 changes: 6 additions & 1 deletion engines/draci/game.h
Expand Up @@ -215,6 +215,7 @@ class Game {
void walkHero(int x, int y, SightDirection dir); // start walking and leave callback as is
void setHeroPosition(const Common::Point &p);
const Common::Point &getHeroPosition() const { return _hero; }
const Common::Point &getHeroLoadingPosition() const { return _heroLoading; }
void positionAnimAsHero(Animation *anim);
void positionHeroAsAnim(Animation *anim);

Expand Down Expand Up @@ -290,6 +291,8 @@ class Game {
void setExitLoop(bool exit) { _shouldExitLoop = exit; }
bool isReloaded() const { return _isReloaded; }
void setIsReloaded(bool value) { _isReloaded = value; }
bool isPositionLoaded() { return _isPositionLoaded; }
void setPositionLoaded(bool value) { _isPositionLoaded = value; }

void setSpeechTiming(uint tick, uint duration);
void shiftSpeechAndFadeTick(int delta);
Expand Down Expand Up @@ -327,7 +330,7 @@ class Game {
void setEnableSpeedText(bool value) { _enableSpeedText = value; }
bool getEnableSpeedText() const { return _enableSpeedText; }

void DoSync(Common::Serializer &s);
void DoSync(Common::Serializer &s, uint8 saveVersion);

private:
void updateOrdinaryCursor();
Expand All @@ -352,6 +355,7 @@ class Game {
GameInfo _info;

Common::Point _hero;
Common::Point _heroLoading;

int *_variables;
Person *_persons;
Expand Down Expand Up @@ -395,6 +399,7 @@ class Game {
bool _shouldQuit;
bool _shouldExitLoop;
bool _isReloaded;
bool _isPositionLoaded;

uint _speechTick;
uint _speechDuration;
Expand Down
7 changes: 4 additions & 3 deletions engines/draci/saveload.cpp
Expand Up @@ -45,7 +45,8 @@ bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header) {
return false;

header.version = in->readByte();
if (header.version != DRACI_SAVEGAME_VERSION)
// Version 1 is compatible with Version 2
if (header.version > DRACI_SAVEGAME_VERSION)
return false;

// Read in the string
Expand Down Expand Up @@ -106,7 +107,7 @@ Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName,
} else {
// Create the remainder of the savegame
Common::Serializer s(NULL, f);
vm._game->DoSync(s);
vm._game->DoSync(s, header.version);

f->finalize();
delete f;
Expand Down Expand Up @@ -140,7 +141,7 @@ Common::Error loadSavegameData(int saveGameIdx, DraciEngine *vm) {

// Synchronise the remaining data of the savegame
Common::Serializer s(f, NULL);
vm->_game->DoSync(s);
vm->_game->DoSync(s, header.version);
delete f;

// Post-processing
Expand Down
2 changes: 1 addition & 1 deletion engines/draci/saveload.h
Expand Up @@ -29,7 +29,7 @@

namespace Draci {

#define DRACI_SAVEGAME_VERSION 1
#define DRACI_SAVEGAME_VERSION 2

struct DraciSavegameHeader {
uint8 version;
Expand Down
17 changes: 15 additions & 2 deletions engines/draci/script.cpp
Expand Up @@ -634,8 +634,16 @@ void Script::stayOn(const Common::Array<int> &params) {
return;
}

int x = params[0];
int y = params[1];
int x, y;
Common::Point afterLoadingPos = _vm->_game->getHeroLoadingPosition();
if(_vm->_game->isPositionLoaded() == true) {
x = afterLoadingPos.x;
y = afterLoadingPos.y;
}
else {
x = params[0];
y = params[1];
}
SightDirection dir = static_cast<SightDirection> (params[2]);

// Jumps into the given position regardless of the walking map.
Expand Down Expand Up @@ -670,6 +678,11 @@ void Script::walkOnPlay(const Common::Array<int> &params) {
return;
}

if(_vm->_game->isPositionLoaded() == true) {
_vm->_game->setPositionLoaded(false);
return;
}

int x = params[0];
int y = params[1];
SightDirection dir = static_cast<SightDirection> (params[2]);
Expand Down

0 comments on commit 579c343

Please sign in to comment.