aboutsummaryrefslogtreecommitdiff
path: root/saga
diff options
context:
space:
mode:
authorAndrew Kurushin2005-05-23 18:53:36 +0000
committerAndrew Kurushin2005-05-23 18:53:36 +0000
commit82b86d495e08608ef902a60f960ca3250bacc205 (patch)
tree2f329314a0a1696840d5c4ce74fcc4c282e62bd1 /saga
parent84b9f4b2e097525bbeebbc704d5196f2a119ea94 (diff)
downloadscummvm-rg350-82b86d495e08608ef902a60f960ca3250bacc205.tar.gz
scummvm-rg350-82b86d495e08608ef902a60f960ca3250bacc205.tar.bz2
scummvm-rg350-82b86d495e08608ef902a60f960ca3250bacc205.zip
saveload WIP
svn-id: r18232
Diffstat (limited to 'saga')
-rw-r--r--saga/actor.cpp8
-rw-r--r--saga/actor.h148
-rw-r--r--saga/game.cpp8
-rw-r--r--saga/interface.cpp50
-rw-r--r--saga/interface.h5
-rw-r--r--saga/saga.cpp3
-rw-r--r--saga/saga.h16
-rw-r--r--saga/saveload.cpp111
8 files changed, 220 insertions, 129 deletions
diff --git a/saga/actor.cpp b/saga/actor.cpp
index 26005fc222..4d39131b89 100644
--- a/saga/actor.cpp
+++ b/saga/actor.cpp
@@ -2305,10 +2305,10 @@ void Actor::drawPathTest() {
#endif
}
-void Actor::saveState(Common::File& out) {
+void Actor::saveState(Common::OutSaveFile *out) {
uint16 i;
- out.writeSint16LE(getProtagState());
+ out->writeSint16LE(getProtagState());
for (i = 0; i < _actorsCount; i++) {
ActorData *a = _actors[i];
@@ -2321,10 +2321,10 @@ void Actor::saveState(Common::File& out) {
}
}
-void Actor::loadState(Common::File& in) {
+void Actor::loadState(Common::InSaveFile *in) {
int32 i;
- setProtagState(in.readSint16LE());
+ setProtagState(in->readSint16LE());
for (i = 0; i < _actorsCount; i++) {
ActorData *a = _actors[i];
diff --git a/saga/actor.h b/saga/actor.h
index d2ddd00d3f..663259d216 100644
--- a/saga/actor.h
+++ b/saga/actor.h
@@ -27,6 +27,7 @@
#define SAGA_ACTOR_H__
#include "common/file.h"
+#include "common/savefile.h"
#include "saga/sprite.h"
#include "saga/itedata.h"
@@ -141,15 +142,15 @@ struct Location {
Location() {
x = y = z = 0;
}
- void saveState(Common::File& out) {
- out.writeSint32LE(x);
- out.writeSint32LE(y);
- out.writeSint32LE(z);
+ void saveState(Common::OutSaveFile *out) {
+ out->writeSint32LE(x);
+ out->writeSint32LE(y);
+ out->writeSint32LE(z);
}
- void loadState(Common::File& in) {
- x = in.readSint32LE();
- y = in.readSint32LE();
- z = in.readSint32LE();
+ void loadState(Common::InSaveFile *in) {
+ x = in->readSint32LE();
+ y = in->readSint32LE();
+ z = in->readSint32LE();
}
int distance(const Location &location) const {
@@ -222,27 +223,27 @@ public:
int32 screenDepth; //
int32 screenScale; //
- void saveState(Common::File& out) {
- out.writeUint16LE(flags);
- out.writeSint32LE(nameIndex);
- out.writeSint32LE(sceneNumber);
- out.writeSint32LE(spriteListResourceId);
+ void saveState(Common::OutSaveFile *out) {
+ out->writeUint16LE(flags);
+ out->writeSint32LE(nameIndex);
+ out->writeSint32LE(sceneNumber);
+ out->writeSint32LE(spriteListResourceId);
location.saveState(out);
- out.writeSint16LE(screenPosition.x);
- out.writeSint16LE(screenPosition.y);
- out.writeSint32LE(screenDepth);
- out.writeSint32LE(screenScale);
- }
- void loadState(Common::File& in) {
- flags = in.readUint16LE();
- nameIndex = in.readSint32LE();
- sceneNumber = in.readSint32LE();
- spriteListResourceId = in.readSint32LE();
+ out->writeSint16LE(screenPosition.x);
+ out->writeSint16LE(screenPosition.y);
+ out->writeSint32LE(screenDepth);
+ out->writeSint32LE(screenScale);
+ }
+ void loadState(Common::InSaveFile *in) {
+ flags = in->readUint16LE();
+ nameIndex = in->readSint32LE();
+ sceneNumber = in->readSint32LE();
+ spriteListResourceId = in->readSint32LE();
location.loadState(in);
- screenPosition.x = in.readSint16LE();
- screenPosition.y = in.readSint16LE();
- screenDepth = in.readSint32LE();
- screenScale = in.readSint32LE();
+ screenPosition.x = in->readSint16LE();
+ screenPosition.y = in->readSint16LE();
+ screenDepth = in->readSint32LE();
+ screenScale = in->readSint32LE();
}
};
@@ -299,73 +300,72 @@ public:
Location partialTarget;
int32 walkFrameSequence;
- void saveState(Common::File& out) {
+ void saveState(Common::OutSaveFile *out) {
CommonObjectData::saveState(out);
- out.writeUint16LE(actorFlags);
- out.writeSint32LE(currentAction);
- out.writeSint32LE(facingDirection);
- out.writeSint32LE(actionDirection);
- out.writeSint32LE(actionCycle);
- out.writeUint16LE(targetObject);
-
- //TODO: write lastZone
- out.writeSint32LE(cycleFrameSequence);
- out.writeByte(cycleDelay);
- out.writeByte(cycleTimeCount);
- out.writeByte(cycleFlags);
- out.writeSint32LE(frameNumber);
-
- out.writeSint32LE(tileDirectionsAlloced);
+ out->writeUint16LE(actorFlags);
+ out->writeSint32LE(currentAction);
+ out->writeSint32LE(facingDirection);
+ out->writeSint32LE(actionDirection);
+ out->writeSint32LE(actionCycle);
+ out->writeUint16LE(targetObject);
+
+ out->writeSint32LE(cycleFrameSequence);
+ out->writeByte(cycleDelay);
+ out->writeByte(cycleTimeCount);
+ out->writeByte(cycleFlags);
+ out->writeSint32LE(frameNumber);
+
+ out->writeSint32LE(tileDirectionsAlloced);
for (int i = 0; i < tileDirectionsAlloced; i++) {
- out.writeByte(tileDirections[i]);
+ out->writeByte(tileDirections[i]);
}
- out.writeSint32LE(walkStepsAlloced);
+ out->writeSint32LE(walkStepsAlloced);
for (int i = 0; i < walkStepsAlloced; i++) {
- out.writeSint16LE(walkStepsPoints[i].x);
- out.writeSint16LE(walkStepsPoints[i].y);
+ out->writeSint16LE(walkStepsPoints[i].x);
+ out->writeSint16LE(walkStepsPoints[i].y);
}
- out.writeSint32LE(walkStepsCount);
- out.writeSint32LE(walkStepIndex);
+ out->writeSint32LE(walkStepsCount);
+ out->writeSint32LE(walkStepIndex);
finalTarget.saveState(out);
partialTarget.saveState(out);
- out.writeSint32LE(walkFrameSequence);
+ out->writeSint32LE(walkFrameSequence);
}
- void loadState(Common::File& in) {
+
+ void loadState(Common::InSaveFile *in) {
CommonObjectData::loadState(in);
- actorFlags = in.readUint16LE();
- currentAction = in.readSint32LE();
- facingDirection = in.readSint32LE();
- actionDirection = in.readSint32LE();
- actionCycle = in.readSint32LE();
- targetObject = in.readUint16LE();
-
- //TODO: read lastZone
+ actorFlags = in->readUint16LE();
+ currentAction = in->readSint32LE();
+ facingDirection = in->readSint32LE();
+ actionDirection = in->readSint32LE();
+ actionCycle = in->readSint32LE();
+ targetObject = in->readUint16LE();
+
lastZone = NULL;
- cycleFrameSequence = in.readSint32LE();
- cycleDelay = in.readByte();
- cycleTimeCount = in.readByte();
- cycleFlags = in.readByte();
- frameNumber = in.readSint32LE();
+ cycleFrameSequence = in->readSint32LE();
+ cycleDelay = in->readByte();
+ cycleTimeCount = in->readByte();
+ cycleFlags = in->readByte();
+ frameNumber = in->readSint32LE();
- setTileDirectionsSize(in.readSint32LE(), true);
+ setTileDirectionsSize(in->readSint32LE(), true);
for (int i = 0; i < tileDirectionsAlloced; i++) {
- tileDirections[i] = in.readByte();
+ tileDirections[i] = in->readByte();
}
- setWalkStepsPointsSize(in.readSint32LE(), true);
+ setWalkStepsPointsSize(in->readSint32LE(), true);
for (int i = 0; i < walkStepsAlloced; i++) {
- walkStepsPoints[i].x = in.readSint16LE();
- walkStepsPoints[i].y = in.readSint16LE();
+ walkStepsPoints[i].x = in->readSint16LE();
+ walkStepsPoints[i].y = in->readSint16LE();
}
- walkStepsCount = in.readSint32LE();
- walkStepIndex = in.readSint32LE();
+ walkStepsCount = in->readSint32LE();
+ walkStepIndex = in->readSint32LE();
finalTarget.loadState(in);
partialTarget.loadState(in);
- walkFrameSequence = in.readSint32LE();
+ walkFrameSequence = in->readSint32LE();
}
void setTileDirectionsSize(int size, bool forceRealloc) {
@@ -499,8 +499,8 @@ public:
return _activeSpeech.stringsCount > 0;
}
- void saveState(Common::File& out);
- void loadState(Common::File& in);
+ void saveState(Common::OutSaveFile *out);
+ void loadState(Common::InSaveFile *in);
void setProtagState(int state);
int getProtagState() { return _protagState; }
diff --git a/saga/game.cpp b/saga/game.cpp
index af0560f60a..a9384ed387 100644
--- a/saga/game.cpp
+++ b/saga/game.cpp
@@ -74,9 +74,15 @@ static PanelButton ITE_ConversePanelButtons[] = {
};
static PanelButton ITE_OptionPanelButtons[] = {
+ {kPanelButtonSlider, 284,19, 13,75, 0,'-',0, 0,0,0}, //slider-scroller
{kPanelButtonOption, 113,18, 45,17, 13,'r',0, 0,0,0}, //read speed
-
+ {kPanelButtonOption, 113,37, 45,17, 16,'m',0, 0,0,0}, //music
+ {kPanelButtonOption, 113,56, 45,17, 16,'n',0, 0,0,0}, //sound-noise
+ {kPanelButtonOption, 13,79, 135,17, 12,'q',0, 0,0,0}, //quit
{kPanelButtonOption, 13,98, 135,17, 17,'c',0, 0,0,0}, //continue
+ {kPanelButtonOption, 164,98, 57,17, 18,'l',0, 0,0,0}, //load
+ {kPanelButtonOption, 241,98, 57,17, 19,'s',0, 0,0,0}, //save
+ {kPanelButtonOption, 166,20, 112,74, 0,'-',0, 0,0,0}, //slider
};
static GameDisplayInfo ITE_DisplayInfo = {
diff --git a/saga/interface.cpp b/saga/interface.cpp
index 5ef8e0357b..8a65268933 100644
--- a/saga/interface.cpp
+++ b/saga/interface.cpp
@@ -254,6 +254,7 @@ void Interface::setMode(int mode, bool force) {
} else {
if (_panelMode == kPanelOption) {
_optionPanel.currentButton = NULL;
+ _vm->fillSaveList();
}
}
}
@@ -279,9 +280,11 @@ bool Interface::processKeyCode(int keyCode) {
//TODO: check input dialog keys
for (i = 0; i < _optionPanel.buttonsCount; i++) {
panelButton = &_optionPanel.buttons[i];
- if (panelButton->keyChar == keyCode) {
- setOption(panelButton);
- return true;
+ if(panelButton->type == kPanelButtonOption) {
+ if (panelButton->keyChar == keyCode) {
+ setOption(panelButton);
+ return true;
+ }
}
}
break;
@@ -445,6 +448,7 @@ void Interface::drawOption() {
SURFACE *backBuffer;
int i;
Point origin;
+ PanelButton *panelButton;
backBuffer = _vm->_gfx->getBackBuffer();
origin.x = _vm->getDisplayInfo().optionPanelXOffset;
@@ -453,23 +457,44 @@ void Interface::drawOption() {
bufToSurface(backBuffer, _optionPanel.image, _optionPanel.imageWidth, _optionPanel.imageHeight, NULL, &origin);
for (i = 0; i < _optionPanel.buttonsCount; i++) {
- drawOptionPanelButtonText(backBuffer, &_optionPanel.buttons[i]);
+ panelButton = &_optionPanel.buttons[i];
+ if(panelButton->type == kPanelButtonOption) {
+ drawOptionPanelButtonText(backBuffer, panelButton);
+ }
}
}
void Interface::handleOptionUpdate(const Point& mousePoint) {
+ int i;
_optionPanel.currentButton = optionHitTest(mousePoint);
+ bool released = (_optionPanel.currentButton != NULL) && (_optionPanel.currentButton->state > 0) && (!_vm->mouseButtonPressed());
+ if (!_vm->mouseButtonPressed()) {
+ for (i = 0; i < _optionPanel.buttonsCount; i++) {
+ _optionPanel.buttons[i].state = 0;
+ }
+ }
+
+ if (released) {
+ setOption(_optionPanel.currentButton);
+ }
+
}
void Interface::handleOptionClick(const Point& mousePoint) {
+ int i;
_optionPanel.currentButton = optionHitTest(mousePoint);
+ for (i = 0; i < _optionPanel.buttonsCount; i++) {
+ _optionPanel.buttons[i].state = 0;
+ }
+
if (_optionPanel.currentButton == NULL) {
return;
}
- setOption(_optionPanel.currentButton); //TODO: do it on mouse up
+ _optionPanel.currentButton->state = 1;
+
}
@@ -478,6 +503,9 @@ void Interface::setOption(PanelButton *panelButton) {
case 'c':
setMode(kPanelMain);
break;
+ case 'q':
+ _vm->shutDown();
+ break;
}
}
@@ -1189,19 +1217,19 @@ void Interface::handleConverseClick(const Point& mousePoint) {
}
-void Interface::saveState(Common::File& out) {
- out.writeUint16LE(_inventoryCount);
+void Interface::saveState(Common::OutSaveFile *out) {
+ out->writeUint16LE(_inventoryCount);
for (int i = 0; i < _inventoryCount; i++) {
- out.writeUint16LE(_inventory[i]);
+ out->writeUint16LE(_inventory[i]);
}
}
-void Interface::loadState(Common::File& in) {
- _inventoryCount = in.readUint16LE();
+void Interface::loadState(Common::InSaveFile *in) {
+ _inventoryCount = in->readUint16LE();
for (int i = 0; i < _inventoryCount; i++) {
- _inventory[i] = in.readUint16LE();
+ _inventory[i] = in->readUint16LE();
}
updateInventory(0);
diff --git a/saga/interface.h b/saga/interface.h
index 57dde525b5..8690d1a1ee 100644
--- a/saga/interface.h
+++ b/saga/interface.h
@@ -27,6 +27,7 @@
#define SAGA_INTERFACE_H__
#include "common/file.h"
+#include "common/savefile.h"
#include "saga/sprite.h"
#include "saga/script.h"
@@ -205,8 +206,8 @@ public:
PanelButton *verbHitTest(const Point& mousePoint){
return _mainPanel.hitTest(mousePoint, kPanelButtonVerb);
}
- void saveState(Common::File& out);
- void loadState(Common::File& in);
+ void saveState(Common::OutSaveFile *out);
+ void loadState(Common::InSaveFile *in);
private:
void handleMainUpdate(const Point& mousePoint); // main panel update
void handleMainClick(const Point& mousePoint); // main panel click
diff --git a/saga/saga.cpp b/saga/saga.cpp
index 4695016518..4e18c25708 100644
--- a/saga/saga.cpp
+++ b/saga/saga.cpp
@@ -115,7 +115,8 @@ namespace Saga {
SagaEngine *_vm = NULL;
SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst)
- : Engine(syst) {
+ : Engine(syst),
+ _targetName(detector->_targetName) {
_leftMouseButtonPressed = _rightMouseButtonPressed = false;
diff --git a/saga/saga.h b/saga/saga.h
index 5e2db072bd..13fa8002a6 100644
--- a/saga/saga.h
+++ b/saga/saga.h
@@ -63,7 +63,12 @@ class Puzzle;
#define SAGA_IMAGE_DATA_OFFSET 776
#define SAGA_IMAGE_HEADER_LEN 8
-#define MAXPATH 512
+#define MAXPATH 512 //TODO: remove
+
+#define SAVE_TITLE_SIZE 28
+#define MAX_SAVES 96
+#define MAX_FILE_NAME 256
+
#define IS_BIG_ENDIAN ((_vm->getFeatures() & GF_BIG_ENDIAN_DATA) != 0)
@@ -146,7 +151,7 @@ enum PanelButtonType {
kPanelButtonConverseText = 4,
kPanelButtonInventory = 8,
kPanelButtonOption = 0x10,
- kPanelButtonReserved2 = 0x20,
+ kPanelButtonSlider = 0x20,
kPanelAllButtons = 0xFFFFF
};
@@ -448,7 +453,6 @@ class SagaEngine : public Engine {
protected:
int go();
int init(GameDetector &detector);
-
public:
SagaEngine(GameDetector * detector, OSystem * syst);
virtual ~SagaEngine();
@@ -462,6 +466,9 @@ public:
}
void save(const char *fileName, const char *saveName);
void load(const char *fileName);
+ void fillSaveList();
+ char *calcSaveFileName(uint slotNumber);
+ char *getSaveFileName(uint idx);
int _soundEnabled;
int _musicEnabled;
@@ -536,6 +543,9 @@ public:
}
private:
+ Common::String _targetName;
+ uint _saveFileNamesCount;
+ char _saveFileNames[MAX_SAVES][SAVE_TITLE_SIZE];
Point _mousePos;
bool _leftMouseButtonPressed;
bool _rightMouseButtonPressed;
diff --git a/saga/saveload.cpp b/saga/saveload.cpp
index 5f4969da4d..67c0266ca8 100644
--- a/saga/saveload.cpp
+++ b/saga/saveload.cpp
@@ -45,89 +45,134 @@ struct SaveGameHeader {
uint32 type;
uint32 size;
uint32 version;
- char name[32];
+ char name[SAVE_TITLE_SIZE];
};
+
+static char emptySlot[] = "[New Save Game]";
+
//TODO:
-// - get savegame list
-// - make/create save filename string
// - delete savegame
+char* SagaEngine::calcSaveFileName(uint slotNumber) {
+ static char name[MAX_FILE_NAME];
+ sprintf(name, "%s.s%02d", _targetName.c_str(), slotNumber);
+ return name;
+}
+
+char *SagaEngine::getSaveFileName(uint idx) {
+ if (idx >= MAX_SAVES) {
+ error("getSaveFileName wrong idx");
+ }
+ return _saveFileNames[idx];
+}
+
+
+void SagaEngine::fillSaveList() {
+ int i;
+ bool marks[MAX_SAVES];
+ Common::InSaveFile *in;
+ SaveGameHeader header;
+ char *name;
+
+ name = calcSaveFileName(MAX_SAVES);
+ name[strlen(name) - 2] = 0;
+ _saveFileMan->listSavefiles(name, marks, MAX_SAVES);
+
+ for (i = 0; i < MAX_SAVES; i++) {
+ _saveFileNames[i][0] = 0;
+ }
+
+ _saveFileNamesCount = 0;
+ i = 0;
+ while (i < MAX_SAVES) {
+ if (marks[i]) {
+ name = calcSaveFileName(i);
+ if (!(in = _saveFileMan->openForLoading(name))) {
+ break;
+ }
+ in->read(&header, sizeof(header));
+
+ if (header.type != MKID('SAGA')) {
+ error("SagaEngine::load wrong format");
+ }
+ strcpy(_saveFileNames[_saveFileNamesCount], header.name);
+ delete in;
+ _saveFileNamesCount++;
+ }
+ i++;
+ }
+}
+
+
void SagaEngine::save(const char *fileName, const char *saveName) {
- Common::File out;
+ Common::OutSaveFile *out;
SaveGameHeader header;
- out.open(fileName, Common::File::kFileWriteMode);
+ if (!(out = _saveFileMan->openForSaving(fileName))) {
+ return;
+ }
header.type = MKID('SAGA');
header.size = 0;
header.version = CURRENT_SAGA_VER;
strcpy(header.name, saveName);
- out.write(&header, sizeof(header));
+ out->write(&header, sizeof(header));
// Surrounding scene
- out.writeSint32LE(_scene->getOutsetSceneNumber());
+ out->writeSint32LE(_scene->getOutsetSceneNumber());
// Inset scene
- out.writeSint32LE(_scene->currentSceneNumber());
-
- uint16 i;
+ out->writeSint32LE(_scene->currentSceneNumber());
_interface->saveState(out);
_actor->saveState(out);
- out.writeSint16LE(_script->_commonBufferSize);
+ out->writeSint16LE(_script->_commonBufferSize);
- for (i = 0; i < _script->_commonBufferSize; i++)
- out.writeByte(_script->_commonBuffer[i]);
+ out->write(_script->_commonBuffer, _script->_commonBufferSize);
- out.writeSint16LE(_isoMap->getMapPosition().x);
- out.writeSint16LE(_isoMap->getMapPosition().y);
+ out->writeSint16LE(_isoMap->getMapPosition().x);
+ out->writeSint16LE(_isoMap->getMapPosition().y);
- out.close();
+ delete out;
}
void SagaEngine::load(const char *fileName) {
- Common::File in;
+ Common::InSaveFile *in;
int commonBufferSize;
int sceneNumber, insetSceneNumber;
int mapx, mapy;
- uint16 i;
SaveGameHeader header;
- in.open(fileName);
-
- if (!in.isOpen())
+ if (!(in = _saveFileMan->openForLoading(fileName))) {
return;
+ }
- in.read(&header, sizeof(header));
+ in->read(&header, sizeof(header));
if (header.type != MKID('SAGA')) {
error("SagaEngine::load wrong format");
}
// Surrounding scene
- sceneNumber = in.readSint32LE();
+ sceneNumber = in->readSint32LE();
// Inset scene
- insetSceneNumber = in.readSint32LE();
+ insetSceneNumber = in->readSint32LE();
- debug(0, "scene: #%d inset scene: #%d", sceneNumber, insetSceneNumber);
-
-
_interface->loadState(in);
_actor->loadState(in);
- commonBufferSize = in.readSint16LE();
- for (i = 0; i < commonBufferSize; i++)
- _script->_commonBuffer[i] = in.readByte();
+ commonBufferSize = in->readSint16LE();
+ in->read(_script->_commonBuffer, commonBufferSize);
- mapx = in.readSint16LE();
- mapy = in.readSint16LE();
+ mapx = in->readSint16LE();
+ mapy = in->readSint16LE();
- in.close();
+ delete in;
_isoMap->setMapPosition(mapx, mapy);