aboutsummaryrefslogtreecommitdiff
path: root/engines/hugo/schedule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/hugo/schedule.cpp')
-rw-r--r--engines/hugo/schedule.cpp155
1 files changed, 141 insertions, 14 deletions
diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp
index b36ce70847..c5d1683a96 100644
--- a/engines/hugo/schedule.cpp
+++ b/engines/hugo/schedule.cpp
@@ -48,13 +48,19 @@
namespace Hugo {
-Scheduler::Scheduler(HugoEngine *vm) : _vm(vm), _actListArr(0), _curTick(0), _oldTime(0), _refreshTimeout(0) {
+Scheduler::Scheduler(HugoEngine *vm) : _vm(vm), _actListArr(0), _curTick(0), _oldTime(0), _refreshTimeout(0), _points(0), _screenActs(0) {
memset(_events, 0, sizeof(_events));
+ _numBonuses = 0;
+ _screenActsSize = 0;
}
Scheduler::~Scheduler() {
}
+void Scheduler::initCypher() {
+ _cypher = getCypher();
+}
+
/**
* Initialise the timer event queue
*/
@@ -142,9 +148,9 @@ uint32 Scheduler::getDosTicks(const bool updateFl) {
void Scheduler::processBonus(const int bonusIndex) {
debugC(1, kDebugSchedule, "processBonus(%d)", bonusIndex);
- if (!_vm->_points[bonusIndex].scoredFl) {
- _vm->adjustScore(_vm->_points[bonusIndex].score);
- _vm->_points[bonusIndex].scoredFl = true;
+ if (!_points[bonusIndex].scoredFl) {
+ _vm->adjustScore(_points[bonusIndex].score);
+ _points[bonusIndex].scoredFl = true;
}
}
@@ -186,7 +192,7 @@ void Scheduler::newScreen(const int screenIndex) {
_vm->readScreenFiles(screenIndex);
// 4. Schedule action list for this screen
- _vm->screenActions(screenIndex);
+ _vm->_scheduler->screenActions(screenIndex);
// 5. Initialise prompt line and status line
_vm->_screen->initNewScreenDisplay();
@@ -245,6 +251,28 @@ void Scheduler::loadAlNewscrIndex(Common::ReadStream &in) {
}
/**
+ * Load Points from Hugo.dat
+ */
+void Scheduler::loadPoints(Common::ReadStream &in) {
+ debugC(6, kDebugSchedule, "loadPoints(&in)");
+
+ for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
+ uint16 numElem = in.readUint16BE();
+ if (varnt == _vm->_gameVariant) {
+ _numBonuses = numElem;
+ _points = (point_t *)malloc(sizeof(point_t) * _numBonuses);
+ for (int i = 0; i < _numBonuses; i++) {
+ _points[i].score = in.readByte();
+ _points[i].scoredFl = false;
+ }
+ } else {
+ for (int i = 0; i < numElem; i++)
+ in.readByte();
+ }
+ }
+}
+
+/**
* Load actListArr from Hugo.dat
*/
void Scheduler::loadActListArr(Common::ReadStream &in) {
@@ -816,9 +844,47 @@ void Scheduler::loadActListArr(Common::ReadStream &in) {
}
}
-void Scheduler::freeActListArr() {
+/**
+ * Read _screenActs
+ */
+void Scheduler::loadScreenAct(Common::ReadStream &in) {
+ for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
+ uint16 numElem = in.readUint16BE();
+
+ uint16 **wrkScreenActs = (uint16 **)malloc(sizeof(uint16 *) * numElem);
+ for (int i = 0; i < numElem; i++) {
+ uint16 numSubElem = in.readUint16BE();
+ if (numSubElem == 0) {
+ wrkScreenActs[i] = 0;
+ } else {
+ wrkScreenActs[i] = (uint16 *)malloc(sizeof(uint16) * numSubElem);
+ for (int j = 0; j < numSubElem; j++)
+ wrkScreenActs[i][j] = in.readUint16BE();
+ }
+ }
+
+ if (varnt == _vm->_gameVariant) {
+ _screenActsSize = numElem;
+ _screenActs = wrkScreenActs;
+ } else {
+ for (int i = 0; i < numElem; i++)
+ free(wrkScreenActs[i]);
+ free(wrkScreenActs);
+ }
+ }
+}
+
+void Scheduler::freeScheduler() {
debugC(6, kDebugSchedule, "freeActListArr()");
+ free(_points);
+
+ if (_screenActs) {
+ for (int i = 0; i < _screenActsSize; i++)
+ free(_screenActs[i]);
+ free(_screenActs);
+ }
+
if (_actListArr) {
for (int i = 0; i < _actListArrSize; i++) {
for (int j = 0; _actListArr[i][j].a0.actType != ANULL; j++) {
@@ -832,6 +898,19 @@ void Scheduler::freeActListArr() {
}
/**
+ * Add action lists for this screen to event queue
+ */
+void Scheduler::screenActions(const int screenNum) {
+ debugC(1, kDebugEngine, "screenActions(%d)", screenNum);
+
+ uint16 *screenAct = _screenActs[screenNum];
+ if (screenAct) {
+ for (int i = 0; screenAct[i]; i++)
+ insertActionList(screenAct[i]);
+ }
+}
+
+/**
* Maze mode is enabled. Check to see whether hero has crossed the maze
* bounding box, if so, go to the next room
*/
@@ -935,10 +1014,16 @@ void Scheduler::restoreActions(Common::ReadStream *f) {
}
}
+int16 Scheduler::calcMaxPoints() const {
+ int16 tmpScore = 0;
+ for (int i = 0; i < _numBonuses; i++)
+ tmpScore += _points[i].score;
+ return tmpScore;
+}
+
/*
* Save the action data in the file with handle f
*/
-
void Scheduler::saveActions(Common::WriteStream* f) const {
for (int i = 0; i < _actListArrSize; i++) {
// write all the sub elems data
@@ -979,6 +1064,27 @@ void Scheduler::findAction(act* action, int16* index, int16* subElem) {
assert(0);
}
+void Scheduler::saveSchedulerData(Common::WriteStream *out) {
+ savePoints(out);
+
+ // Now save current time and all current events in event queue
+ saveEvents(out);
+
+ // Now save current actions
+ saveActions(out);
+}
+
+void Scheduler::restoreSchedulerData(Common::ReadStream *in) {
+ restorePoints(in);
+ _vm->_object->restoreAllSeq();
+
+ // Now restore time of the save and the event queue
+ restoreEvents(in);
+
+ // Now restore actions
+ restoreActions(in);
+}
+
/**
* Restore the event list from file with handle f
*/
@@ -1262,7 +1368,7 @@ event_t *Scheduler::doAction(event_t *curEvent) {
Utils::Box(kBoxOk, "%s", _vm->_file->fetchString(action->a40.stringIndex));
break;
case COND_BONUS: // act41: Perform action if got bonus
- if (_vm->_points[action->a41.BonusIndex].scoredFl)
+ if (_points[action->a41.BonusIndex].scoredFl)
insertActionList(action->a41.actPassIndex);
else
insertActionList(action->a41.actFailIndex);
@@ -1354,6 +1460,9 @@ void Scheduler::delQueue(event_t *curEvent) {
_freeEvent = curEvent;
}
+/**
+ * Delete all the active events of a given type
+ */
void Scheduler::delEventType(const action_t actTypeDel) {
// Note: actions are not deleted here, simply turned into NOPs!
event_t *wrkEvent = _headEvent; // The earliest event
@@ -1367,6 +1476,27 @@ void Scheduler::delEventType(const action_t actTypeDel) {
}
}
+/**
+ * Save the points table
+ */
+void Scheduler::savePoints(Common::WriteStream *out) const {
+ for (int i = 0; i < _numBonuses; i++) {
+ out->writeByte(_points[i].score);
+ out->writeByte((_points[i].scoredFl) ? 1 : 0);
+ }
+}
+
+/**
+ * Restore the points table
+ */
+void Scheduler::restorePoints(Common::ReadStream *in) {
+ // Restore points table
+ for (int i = 0; i < _numBonuses; i++) {
+ _points[i].score = in->readByte();
+ _points[i].scoredFl = (in->readByte() == 1);
+ }
+}
+
Scheduler_v1d::Scheduler_v1d(HugoEngine *vm) : Scheduler(vm) {
}
@@ -1427,11 +1557,9 @@ void Scheduler_v1d::promptAction(act *action) {
void Scheduler_v1d::decodeString(char *line) {
debugC(1, kDebugSchedule, "decodeString(%s)", line);
- static const Common::String cypher = getCypher();
-
uint16 linelength = strlen(line);
for(uint16 i = 0; i < linelength; i++) {
- line[i] = (line[i] + cypher.c_str()[i % cypher.size()]) % '~';
+ line[i] = (line[i] + _cypher.c_str()[i % _cypher.size()]) % '~';
if (line[i] < ' ')
line[i] += ' ';
}
@@ -1480,11 +1608,10 @@ void Scheduler_v2d::promptAction(act *action) {
void Scheduler_v2d::decodeString(char *line) {
debugC(1, kDebugSchedule, "decodeString(%s)", line);
- static const Common::String cypher = getCypher();
-
int16 lineLength = strlen(line);
for (uint16 i = 0; i < lineLength; i++)
- line[i] -= cypher.c_str()[i % cypher.size()];
+ line[i] -= _cypher.c_str()[i % _cypher.size()];
+
debugC(1, kDebugSchedule, "result : %s", line);
}