Skip to content

Commit

Permalink
ZVISION: Implement action:restore_game
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa-Chan committed Nov 8, 2014
1 parent 19e2251 commit ea8cc34
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
17 changes: 17 additions & 0 deletions engines/zvision/scripting/actions.cpp
Expand Up @@ -42,6 +42,7 @@
#include "zvision/graphics/effects/fog.h"
#include "zvision/graphics/effects/light.h"
#include "zvision/graphics/effects/wave.h"
#include "zvision/core/save_manager.h"

#include "common/file.h"

Expand Down Expand Up @@ -721,6 +722,22 @@ bool ActionRandom::execute() {
return true;
}

//////////////////////////////////////////////////////////////////////////////
// ActionRestoreGame
//////////////////////////////////////////////////////////////////////////////

ActionRestoreGame::ActionRestoreGame(ZVision *engine, int32 slotkey, const Common::String &line) :
ResultAction(engine, slotkey) {
char buf[128];
sscanf(line.c_str(), "%s", buf);
_fileName = Common::String(buf);
}

bool ActionRestoreGame::execute() {
_engine->getSaveManager()->loadGame(_fileName);
return false;
}

//////////////////////////////////////////////////////////////////////////////
// ActionRotateTo
//////////////////////////////////////////////////////////////////////////////
Expand Down
9 changes: 9 additions & 0 deletions engines/zvision/scripting/actions.h
Expand Up @@ -385,6 +385,15 @@ class ActionRandom : public ResultAction {
ValueSlot *_max;
};

class ActionRestoreGame : public ResultAction {
public:
ActionRestoreGame(ZVision *engine, int32 slotkey, const Common::String &line);
bool execute();

private:
Common::String _fileName;
};

class ActionRotateTo : public ResultAction {
public:
ActionRotateTo(ZVision *engine, int32 slotkey, const Common::String &line);
Expand Down
2 changes: 1 addition & 1 deletion engines/zvision/scripting/scr_file_handling.cpp
Expand Up @@ -268,7 +268,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis
} else if (act.matchString("region", true)) {
actionList.push_back(new ActionRegion(_engine, slot, args));
} else if (act.matchString("restore_game", true)) {
// TODO: Implement ActionRestoreGame
actionList.push_back(new ActionRestoreGame(_engine, slot, args));
} else if (act.matchString("rotate_to", true)) {
actionList.push_back(new ActionRotateTo(_engine, slot, args));
} else if (act.matchString("save_game", true)) {
Expand Down
40 changes: 21 additions & 19 deletions engines/zvision/scripting/script_manager.cpp
Expand Up @@ -79,14 +79,18 @@ void ScriptManager::update(uint deltaTimeMillis) {
do_changeLocation();

updateNodes(deltaTimeMillis);
execScope(nodeview);
execScope(room);
execScope(world);
execScope(universe);
if (! execScope(nodeview))
return;
if (! execScope(room))
return;
if (! execScope(world))
return;
if (! execScope(universe))
return;
updateControls(deltaTimeMillis);
}

void ScriptManager::execScope(script_scope &scope) {
bool ScriptManager::execScope(script_scope &scope) {
// Swap queues
PuzzleList *tmp = scope.exec_queue;
scope.exec_queue = scope.scope_queue;
Expand All @@ -98,15 +102,18 @@ void ScriptManager::execScope(script_scope &scope) {

if (scope.proc_count < 2 || getStateValue(StateKey_ExecScopeStyle)) {
for (PuzzleList::iterator PuzzleIter = scope._puzzles.begin(); PuzzleIter != scope._puzzles.end(); ++PuzzleIter)
checkPuzzleCriteria(*PuzzleIter, scope.proc_count);
if (!checkPuzzleCriteria(*PuzzleIter, scope.proc_count))
return false;
} else {
for (PuzzleList::iterator PuzzleIter = scope.exec_queue->begin(); PuzzleIter != scope.exec_queue->end(); ++PuzzleIter)
checkPuzzleCriteria(*PuzzleIter, scope.proc_count);
if (!checkPuzzleCriteria(*PuzzleIter, scope.proc_count))
return false;
}

if (scope.proc_count < 2) {
scope.proc_count++;
}
return true;
}

void ScriptManager::referenceTableAddPuzzle(uint32 key, puzzle_ref ref) {
Expand Down Expand Up @@ -185,16 +192,16 @@ void ScriptManager::updateControls(uint deltaTimeMillis) {
break;
}

void ScriptManager::checkPuzzleCriteria(Puzzle *puzzle, uint counter) {
bool ScriptManager::checkPuzzleCriteria(Puzzle *puzzle, uint counter) {
// Check if the puzzle is already finished
// Also check that the puzzle isn't disabled
if (getStateValue(puzzle->key) == 1 || (getStateFlag(puzzle->key) & Puzzle::DISABLED) == Puzzle::DISABLED) {
return;
return true;
}

// Check each Criteria
if (counter == 0 && (getStateFlag(puzzle->key) & Puzzle::DO_ME_NOW) == 0)
return;
return true;

bool criteriaMet = false;
for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = puzzle->criteriaList.begin(); criteriaIter != puzzle->criteriaList.end(); ++criteriaIter) {
Expand Down Expand Up @@ -243,18 +250,13 @@ void ScriptManager::checkPuzzleCriteria(Puzzle *puzzle, uint counter) {
// Set the puzzle as completed
setStateValue(puzzle->key, 1);

bool shouldContinue = true;
for (Common::List<ResultAction *>::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); ++resultIter) {
shouldContinue = shouldContinue && (*resultIter)->execute();
if (!shouldContinue) {
break;
}
}

if (!shouldContinue) {
return;
if (!(*resultIter)->execute())
return false;
}
}

return true;
}

void ScriptManager::cleanStateTable() {
Expand Down
4 changes: 2 additions & 2 deletions engines/zvision/scripting/script_manager.h
Expand Up @@ -253,10 +253,10 @@ class ScriptManager {
void addPuzzlesToReferenceTable(script_scope &scope);
void updateNodes(uint deltaTimeMillis);
void updateControls(uint deltaTimeMillis);
void checkPuzzleCriteria(Puzzle *puzzle, uint counter);
bool checkPuzzleCriteria(Puzzle *puzzle, uint counter);
void cleanStateTable();
void cleanScriptScope(script_scope &scope);
void execScope(script_scope &scope);
bool execScope(script_scope &scope);

/** Perform change location */
void do_changeLocation();
Expand Down

0 comments on commit ea8cc34

Please sign in to comment.