From 402ac930fe440af42354bd0c635abb07a69cfc4a Mon Sep 17 00:00:00 2001 From: strangerke Date: Tue, 15 Feb 2011 10:15:21 +0100 Subject: HUGO: more refactoring and encapsulation --- engines/hugo/schedule.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 6 deletions(-) (limited to 'engines/hugo/schedule.cpp') diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp index b36ce70847..02f8e48b88 100644 --- a/engines/hugo/schedule.cpp +++ b/engines/hugo/schedule.cpp @@ -48,8 +48,10 @@ 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() { @@ -142,9 +144,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 +188,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(); @@ -244,6 +246,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 */ @@ -831,6 +855,57 @@ 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::freeScreenAct() { + if (_screenActs) { + for (int i = 0; i < _screenActsSize; i++) + free(_screenActs[i]); + free(_screenActs); + } +} + +/** + * 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,6 +1010,13 @@ 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 */ @@ -1262,7 +1344,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 +1436,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 +1452,27 @@ void Scheduler::delEventType(const action_t actTypeDel) { } } +/** + * Save the points table + */ +void Scheduler::savePoints(Common::WriteStream *out) { + 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) { } -- cgit v1.2.3