ASYLUM: Move puzzles handling to Puzzles class (formerly PuzzleData)
This commit is contained in:
parent
f09c34bc51
commit
b1493f5be3
12 changed files with 176 additions and 101 deletions
|
@ -29,22 +29,7 @@
|
|||
#include "asylum/resources/special.h"
|
||||
#include "asylum/resources/worldstats.h"
|
||||
|
||||
#include "asylum/puzzles/boardkeyhidesto.h"
|
||||
#include "asylum/puzzles/boardsalvation.h"
|
||||
#include "asylum/puzzles/boardyouth.h"
|
||||
#include "asylum/puzzles/clock.h"
|
||||
#include "asylum/puzzles/fisherman.h"
|
||||
#include "asylum/puzzles/hivecontrol.h"
|
||||
#include "asylum/puzzles/hivemachine.h"
|
||||
#include "asylum/puzzles/lock.h"
|
||||
#include "asylum/puzzles/morguedoor.h"
|
||||
#include "asylum/puzzles/pipes.h"
|
||||
#include "asylum/puzzles/puzzle11.h"
|
||||
#include "asylum/puzzles/tictactoe.h"
|
||||
#include "asylum/puzzles/timemachine.h"
|
||||
#include "asylum/puzzles/vcr.h"
|
||||
#include "asylum/puzzles/wheel.h"
|
||||
#include "asylum/puzzles/writings.h"
|
||||
#include "asylum/puzzles/puzzles.h"
|
||||
|
||||
#include "asylum/system/cursor.h"
|
||||
#include "asylum/system/savegame.h"
|
||||
|
@ -72,7 +57,6 @@ AsylumEngine::AsylumEngine(OSystem *system, const ADGameDescription *gd) : Engin
|
|||
|
||||
// Init data
|
||||
memset(&_gameFlags, 0, sizeof(_gameFlags));
|
||||
memset(&_puzzles, 0, sizeof(_puzzles));
|
||||
memset(&_sinCosTables, 0, sizeof(_sinCosTables));
|
||||
_introPlayed = false;
|
||||
_tickOffset = 0;
|
||||
|
@ -113,6 +97,7 @@ AsylumEngine::~AsylumEngine() {
|
|||
delete _cursor;
|
||||
delete _scene;
|
||||
delete _encounter;
|
||||
delete _puzzles;
|
||||
delete _reaction;
|
||||
delete _savegame;
|
||||
delete _screen;
|
||||
|
@ -128,10 +113,6 @@ AsylumEngine::~AsylumEngine() {
|
|||
|
||||
_previousScene = NULL;
|
||||
|
||||
// Cleanup puzzles
|
||||
for (uint i = 0; i < ARRAYSIZE(_puzzles); i++)
|
||||
delete _puzzles[i];
|
||||
|
||||
delete _rnd;
|
||||
|
||||
// Zero passed pointers
|
||||
|
@ -152,6 +133,7 @@ Common::Error AsylumEngine::run() {
|
|||
// Create all game classes
|
||||
_encounter = new Encounter(this);
|
||||
_cursor = new Cursor(this);
|
||||
_puzzles = new Puzzles(this);
|
||||
_reaction = new Reaction(this);
|
||||
_savegame = new Savegame(this);
|
||||
_screen = new Screen(this);
|
||||
|
@ -161,7 +143,6 @@ Common::Error AsylumEngine::run() {
|
|||
_speech = new Speech(this);
|
||||
_text = new Text(this);
|
||||
_video = new VideoPlayer(this, _mixer);
|
||||
initPuzzles();
|
||||
|
||||
// Init tables
|
||||
initSinCosTables(80.0, 40, 40);
|
||||
|
@ -269,10 +250,7 @@ void AsylumEngine::reset() {
|
|||
_menu->setGameStarted();
|
||||
|
||||
// Reset puzzles
|
||||
for (uint i = 0; i < ARRAYSIZE(_puzzles); i++)
|
||||
delete _puzzles[i];
|
||||
|
||||
initPuzzles();
|
||||
_puzzles->reset();
|
||||
|
||||
// Reset shared data
|
||||
_data.reset();
|
||||
|
@ -471,35 +449,6 @@ void AsylumEngine::notify(AsylumEventType type, int32 param1, int32 param2) {
|
|||
_handler->handleEvent(evt);
|
||||
}
|
||||
|
||||
EventHandler *AsylumEngine::getPuzzle(uint32 index) const {
|
||||
if (index >= ARRAYSIZE(_puzzles))
|
||||
error("[AsylumEngine::getPuzzleEventHandler] Invalid index (was: %d - max: %d)", index, ARRAYSIZE(_puzzles));
|
||||
|
||||
if (_puzzles[index] == NULL)
|
||||
error("[AsylumEngine::getPuzzleEventHandler] This puzzle doesn't have an event handler! (index: %d)", index);
|
||||
|
||||
return (EventHandler *)_puzzles[index];
|
||||
}
|
||||
|
||||
void AsylumEngine::initPuzzles() {
|
||||
_puzzles[0] = new PuzzleVCR(this);
|
||||
_puzzles[1] = new PuzzlePipes(this);
|
||||
_puzzles[2] = new PuzzleTicTacToe(this);
|
||||
_puzzles[3] = new PuzzleLock(this);
|
||||
_puzzles[4] = NULL;// No event handler for Puzzle 5
|
||||
_puzzles[5] = new PuzzleWheel(this);
|
||||
_puzzles[6] = new PuzzleBoardSalvation(this);
|
||||
_puzzles[7] = new PuzzleBoardYouth(this);
|
||||
_puzzles[8] = new PuzzleBoardKeyHidesTo(this);
|
||||
_puzzles[9] = new PuzzleWritings(this);
|
||||
_puzzles[10] = new Puzzle11(this);
|
||||
_puzzles[11] = new PuzzleMorgueDoor(this);
|
||||
_puzzles[12] = new PuzzleClock(this);
|
||||
_puzzles[13] = new PuzzleTimeMachine(this);
|
||||
_puzzles[14] = new PuzzleFisherman(this);
|
||||
_puzzles[15] = new PuzzleHiveMachine(this);
|
||||
_puzzles[16] = new PuzzleHiveControl(this);
|
||||
}
|
||||
|
||||
void AsylumEngine::initSinCosTables(double a2, int32 a3, int32 a4) {
|
||||
uint32 offset = 0;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#ifndef ASYLUM_ENGINE_H
|
||||
#define ASYLUM_ENGINE_H
|
||||
|
||||
#include "asylum/puzzles/puzzledata.h"
|
||||
#include "asylum/resources/data.h"
|
||||
|
||||
#include "asylum/console.h"
|
||||
|
@ -57,10 +56,10 @@
|
|||
*/
|
||||
namespace Asylum {
|
||||
|
||||
class Puzzle;
|
||||
class Cursor;
|
||||
class Encounter;
|
||||
class Menu;
|
||||
class Puzzles;
|
||||
class Reaction;
|
||||
class ResourceManager;
|
||||
class Savegame;
|
||||
|
@ -153,8 +152,8 @@ public:
|
|||
Text *text() { return _text; }
|
||||
VideoPlayer *video() { return _video; }
|
||||
|
||||
SharedData *data() { return &_data; }
|
||||
PuzzleData *puzzleData() { return &_puzzleData; }
|
||||
SharedData *data() { return &_data; }
|
||||
Puzzles *puzzles() { return _puzzles; }
|
||||
|
||||
// Flags
|
||||
void setGameFlag(GameFlag flag);
|
||||
|
@ -182,15 +181,6 @@ public:
|
|||
*/
|
||||
void notify(AsylumEventType type, int32 param1 = 0, int32 param2 = 0);
|
||||
|
||||
/**
|
||||
* Gets a message handler.
|
||||
*
|
||||
* @param index Zero-based index of the message handler
|
||||
*
|
||||
* @return The message handler.
|
||||
*/
|
||||
EventHandler* getPuzzle(uint32 index) const;
|
||||
|
||||
/**
|
||||
* Updates the reverse stereo scene status from the config
|
||||
*/
|
||||
|
@ -234,15 +224,14 @@ private:
|
|||
|
||||
// Current EventHandler class instance
|
||||
EventHandler *_handler;
|
||||
Puzzle *_puzzles[17];
|
||||
|
||||
// Game data
|
||||
PuzzleData _puzzleData;
|
||||
SharedData _data;
|
||||
int _gameFlags[130];
|
||||
int16 _sinCosTables[72];
|
||||
bool _introPlayed;
|
||||
int32 _tickOffset;
|
||||
Puzzles *_puzzles;
|
||||
SharedData _data;
|
||||
int _gameFlags[130];
|
||||
int16 _sinCosTables[72];
|
||||
bool _introPlayed;
|
||||
int32 _tickOffset;
|
||||
|
||||
void updateMouseCursor();
|
||||
void processDelayedEvents();
|
||||
|
@ -252,11 +241,6 @@ private:
|
|||
*/
|
||||
void playIntro();
|
||||
|
||||
/**
|
||||
* Initializes the puzzles
|
||||
*/
|
||||
void initPuzzles();
|
||||
|
||||
/**
|
||||
* Initializes the sine/cosine tables.
|
||||
*/
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "asylum/console.h"
|
||||
|
||||
#include "asylum/puzzles/puzzles.h"
|
||||
|
||||
#include "asylum/resources/actor.h"
|
||||
#include "asylum/resources/encounters.h"
|
||||
#include "asylum/resources/object.h"
|
||||
|
@ -465,11 +467,11 @@ bool Console::cmdRunPuzzle(int32 argc, const char **argv) {
|
|||
|
||||
// Check index is valid
|
||||
if (index < 0 || index >= ARRAYSIZE(puzzleToScenes)) {
|
||||
DebugPrintf("[Error] Invalid index (was: %d - valid: [0-%d])\n", index, ARRAYSIZE(_vm->_puzzles));
|
||||
DebugPrintf("[Error] Invalid index (was: %d - valid: [0-%d])\n", index, ARRAYSIZE(_vm->_puzzles->_puzzles));
|
||||
return true;
|
||||
}
|
||||
|
||||
EventHandler *puzzle = _vm->getPuzzle((uint32)index);
|
||||
EventHandler *puzzle = getPuzzles()->getPuzzle((uint32)index);
|
||||
if (puzzle == NULL) {
|
||||
DebugPrintf("[Error] This puzzle does not exists (%d)", index);
|
||||
return true;
|
||||
|
|
|
@ -13,6 +13,7 @@ MODULE_OBJS := \
|
|||
puzzles/morguedoor.o \
|
||||
puzzles/pipes.o \
|
||||
puzzles/puzzle.o \
|
||||
puzzles/puzzles.o \
|
||||
puzzles/tictactoe.o \
|
||||
puzzles/timemachine.o \
|
||||
puzzles/puzzle11.o \
|
||||
|
|
|
@ -43,6 +43,10 @@ Puzzle::~Puzzle() {
|
|||
_vm = NULL;
|
||||
}
|
||||
|
||||
void Puzzle::saveLoadWithSerializer(Common::Serializer &s) {
|
||||
// By default, we do not save any data
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Event Handling
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "asylum/shared.h"
|
||||
|
||||
#include "common/rect.h"
|
||||
#include "common/serializer.h"
|
||||
|
||||
namespace Asylum {
|
||||
|
||||
|
@ -38,13 +39,16 @@ class Cursor;
|
|||
class GraphicResource;
|
||||
struct GraphicQueueItem;
|
||||
|
||||
class Puzzle : public EventHandler {
|
||||
class Puzzle : public EventHandler, public Common::Serializable {
|
||||
public:
|
||||
Puzzle(AsylumEngine *engine);
|
||||
virtual ~Puzzle();
|
||||
|
||||
bool handleEvent(const AsylumEvent &evt);
|
||||
|
||||
// Serializable
|
||||
void saveLoadWithSerializer(Common::Serializer &s);
|
||||
|
||||
protected:
|
||||
AsylumEngine *_vm;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ Puzzle11::~Puzzle11() {
|
|||
// Event Handling
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Puzzle11::init(const AsylumEvent &evt) {
|
||||
getPuzzleData()->timeMachineCounter = 0;
|
||||
// FIXME! getPuzzleData()->timeMachineCounter = 0;
|
||||
|
||||
getScreen()->setPalette(getWorld()->graphicResourceIds[12]);
|
||||
getScreen()->setGammaLevel(getWorld()->graphicResourceIds[12]);
|
||||
|
|
105
engines/asylum/puzzles/puzzles.cpp
Normal file
105
engines/asylum/puzzles/puzzles.cpp
Normal file
|
@ -0,0 +1,105 @@
|
|||
/* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "asylum/puzzles/puzzles.h"
|
||||
|
||||
#include "asylum/puzzles/boardkeyhidesto.h"
|
||||
#include "asylum/puzzles/boardsalvation.h"
|
||||
#include "asylum/puzzles/boardyouth.h"
|
||||
#include "asylum/puzzles/clock.h"
|
||||
#include "asylum/puzzles/fisherman.h"
|
||||
#include "asylum/puzzles/hivecontrol.h"
|
||||
#include "asylum/puzzles/hivemachine.h"
|
||||
#include "asylum/puzzles/lock.h"
|
||||
#include "asylum/puzzles/morguedoor.h"
|
||||
#include "asylum/puzzles/pipes.h"
|
||||
#include "asylum/puzzles/puzzle11.h"
|
||||
#include "asylum/puzzles/tictactoe.h"
|
||||
#include "asylum/puzzles/timemachine.h"
|
||||
#include "asylum/puzzles/vcr.h"
|
||||
#include "asylum/puzzles/wheel.h"
|
||||
#include "asylum/puzzles/writings.h"
|
||||
|
||||
#include "asylum/asylum.h"
|
||||
#include "asylum/console.h"
|
||||
#include "asylum/shared.h"
|
||||
|
||||
namespace Asylum {
|
||||
|
||||
Puzzles::Puzzles(AsylumEngine *engine) : _vm(engine) {
|
||||
memset(&_puzzles, 0, sizeof(_puzzles));
|
||||
}
|
||||
|
||||
Puzzles::~Puzzles() {
|
||||
// Cleanup puzzles
|
||||
for (uint i = 0; i < ARRAYSIZE(_puzzles); i++)
|
||||
delete _puzzles[i];
|
||||
|
||||
// Zero passed pointers
|
||||
_vm = NULL;
|
||||
}
|
||||
|
||||
void Puzzles::reset() {
|
||||
for (uint i = 0; i < ARRAYSIZE(_puzzles); i++)
|
||||
delete _puzzles[i];
|
||||
|
||||
initPuzzles();
|
||||
}
|
||||
|
||||
EventHandler *Puzzles::getPuzzle(uint32 index) const {
|
||||
if (index >= ARRAYSIZE(_puzzles))
|
||||
error("[AsylumEngine::getPuzzleEventHandler] Invalid index (was: %d - max: %d)", index, ARRAYSIZE(_puzzles));
|
||||
|
||||
if (_puzzles[index] == NULL)
|
||||
error("[AsylumEngine::getPuzzleEventHandler] This puzzle doesn't have an event handler! (index: %d)", index);
|
||||
|
||||
return (EventHandler *)_puzzles[index];
|
||||
}
|
||||
|
||||
void Puzzles::initPuzzles() {
|
||||
_puzzles[0] = new PuzzleVCR(_vm);
|
||||
_puzzles[1] = new PuzzlePipes(_vm);
|
||||
_puzzles[2] = new PuzzleTicTacToe(_vm);
|
||||
_puzzles[3] = new PuzzleLock(_vm);
|
||||
_puzzles[4] = NULL; // No event handler for Puzzle 5
|
||||
_puzzles[5] = new PuzzleWheel(_vm);
|
||||
_puzzles[6] = new PuzzleBoardSalvation(_vm);
|
||||
_puzzles[7] = new PuzzleBoardYouth(_vm);
|
||||
_puzzles[8] = new PuzzleBoardKeyHidesTo(_vm);
|
||||
_puzzles[9] = new PuzzleWritings(_vm);
|
||||
_puzzles[10] = new Puzzle11(_vm);
|
||||
_puzzles[11] = new PuzzleMorgueDoor(_vm);
|
||||
_puzzles[12] = new PuzzleClock(_vm);
|
||||
_puzzles[13] = new PuzzleTimeMachine(_vm);
|
||||
_puzzles[14] = new PuzzleFisherman(_vm);
|
||||
_puzzles[15] = new PuzzleHiveMachine(_vm);
|
||||
_puzzles[16] = new PuzzleHiveControl(_vm);
|
||||
}
|
||||
|
||||
void Puzzles::saveLoadWithSerializer(Common::Serializer &s) {
|
||||
for (int32 i = 0; i < ARRAYSIZE(_puzzles); i++) {
|
||||
if (_puzzles[i])
|
||||
_puzzles[i]->saveLoadWithSerializer(s);
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Asylum
|
|
@ -20,8 +20,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef ASYLUM_PUZZLE_DATA_H
|
||||
#define ASYLUM_PUZZLE_DATA_H
|
||||
#ifndef ASYLUM_PUZZLES_H
|
||||
#define ASYLUM_PUZZLES_H
|
||||
|
||||
#include "asylum/console.h"
|
||||
#include "asylum/shared.h"
|
||||
|
@ -30,20 +30,44 @@
|
|||
|
||||
namespace Asylum {
|
||||
|
||||
struct PuzzleData : public Common::Serializable {
|
||||
public:
|
||||
uint32 timeMachineCounter;
|
||||
class EventHandler;
|
||||
class Puzzle;
|
||||
|
||||
PuzzleData() {
|
||||
timeMachineCounter = 0;
|
||||
}
|
||||
class Puzzles : public Common::Serializable {
|
||||
public:
|
||||
Puzzles(AsylumEngine *engine);
|
||||
~Puzzles();
|
||||
|
||||
/**
|
||||
* Resets puzzles
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Gets a message handler.
|
||||
*
|
||||
* @param index Zero-based index of the message handler
|
||||
*
|
||||
* @return The message handler.
|
||||
*/
|
||||
EventHandler* getPuzzle(uint32 index) const;
|
||||
|
||||
// Serializable
|
||||
void saveLoadWithSerializer(Common::Serializer &s) {
|
||||
error("[PuzzleData::saveLoadWithSerializer] Not implemented!");
|
||||
}
|
||||
void saveLoadWithSerializer(Common::Serializer &s);
|
||||
|
||||
private:
|
||||
AsylumEngine* _vm;
|
||||
Puzzle *_puzzles[17];
|
||||
|
||||
/**
|
||||
* Initializes the puzzles
|
||||
*/
|
||||
void initPuzzles();
|
||||
|
||||
// Debug
|
||||
friend class Console;
|
||||
};
|
||||
|
||||
} // End of namespace Asylum
|
||||
|
||||
#endif // ASYLUM_PUZZLE_DATA_H
|
||||
#endif // ASYLUM_PUZZLES_H
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "asylum/resources/script.h"
|
||||
|
||||
#include "asylum/puzzles/puzzles.h"
|
||||
|
||||
#include "asylum/resources/actor.h"
|
||||
#include "asylum/resources/encounters.h"
|
||||
#include "asylum/resources/object.h"
|
||||
|
@ -1124,7 +1126,7 @@ IMPLEMENT_OPCODE(RunPuzzle)
|
|||
getScreen()->clear();
|
||||
getScreen()->clearGraphicsInQueue();
|
||||
|
||||
_vm->switchEventHandler(_vm->getPuzzle((uint32)cmd->param1));
|
||||
_vm->switchEventHandler(getPuzzles()->getPuzzle((uint32)cmd->param1));
|
||||
|
||||
_currentQueueEntry->currentLine++;
|
||||
|
||||
|
|
|
@ -669,7 +669,7 @@ enum ObjectFlag {
|
|||
#define getEncounter() _vm->encounter()
|
||||
#define getCursor() _vm->cursor()
|
||||
#define getMenu() _vm->menu()
|
||||
#define getPuzzleData() _vm->puzzleData()
|
||||
#define getPuzzles() _vm->puzzles()
|
||||
#define getReaction() _vm->reaction()
|
||||
#define getResource() _vm->resource()
|
||||
#define getSound() _vm->sound()
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include "asylum/system/savegame.h"
|
||||
|
||||
#include "asylum/puzzles/puzzledata.h"
|
||||
#include "asylum/puzzles/puzzles.h"
|
||||
|
||||
#include "asylum/resources/encounters.h"
|
||||
#include "asylum/resources/script.h"
|
||||
|
@ -279,7 +279,7 @@ bool Savegame::loadData(Common::String filename) {
|
|||
|
||||
read(file, _vm, 1512, 1, "Game Stats");
|
||||
read(file, getWorld(), 951928, 1, "World Stats");
|
||||
read(file, getPuzzleData(), 752, 1, "Blowup Puzzle Data");
|
||||
read(file, getPuzzles(), 752, 1, "Blowup Puzzle Data");
|
||||
read(file, getEncounter()->items(), 109, getEncounter()->items()->size(), "Encounter Data");
|
||||
read(file, getEncounter()->variables(), 2, getEncounter()->variables()->size(), "Encounter Variables");
|
||||
|
||||
|
@ -307,7 +307,7 @@ bool Savegame::saveData(Common::String filename, Common::String name, ChapterInd
|
|||
writeHeader(file);
|
||||
write(file, _vm, 1512, 1, "Game Stats");
|
||||
write(file, getWorld(), 951928, 1, "World Stats");
|
||||
write(file, getPuzzleData(), 752, 1, "Blowup Puzzle Data");
|
||||
write(file, getPuzzles(), 752, 1, "Blowup Puzzle Data");
|
||||
write(file, getEncounter()->items(), 109, getEncounter()->items()->size(), "Encounter Data");
|
||||
write(file, getEncounter()->variables(), 2, getEncounter()->variables()->size(), "Encounter Variables");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue