diff options
Diffstat (limited to 'engines/supernova')
-rw-r--r-- | engines/supernova/game-manager.cpp | 919 | ||||
-rw-r--r-- | engines/supernova/game-manager.h | 208 | ||||
-rw-r--r-- | engines/supernova/module.mk | 5 | ||||
-rw-r--r-- | engines/supernova/rooms.cpp | 116 | ||||
-rw-r--r-- | engines/supernova/rooms.h | 100 | ||||
-rw-r--r-- | engines/supernova/state.cpp | 936 | ||||
-rw-r--r-- | engines/supernova/state.h | 232 | ||||
-rw-r--r-- | engines/supernova/supernova.cpp | 4 | ||||
-rw-r--r-- | engines/supernova/supernova.h | 2 |
9 files changed, 1356 insertions, 1166 deletions
diff --git a/engines/supernova/game-manager.cpp b/engines/supernova/game-manager.cpp new file mode 100644 index 0000000000..99d9215649 --- /dev/null +++ b/engines/supernova/game-manager.cpp @@ -0,0 +1,919 @@ +/* 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 "common/system.h" +#include "graphics/cursorman.h" +#include "graphics/palette.h" +#include "gui/message.h" + +#include "supernova/screen.h" +#include "supernova/supernova.h" +#include "supernova/game-manager.h" + +namespace Supernova { + +bool GameManager::serialize(Common::WriteStream *out) { + return false; +} + + +bool GameManager::deserialize(Common::ReadStream *in, int version) { + return false; +} + +void Inventory::add(Object &obj) { + if (_numObjects < kMaxCarry) { + _inventory[_numObjects++] = &obj; + obj.setProperty(CARRIED); + } + + if (getSize() > _inventoryScroll + 8) { + _inventoryScroll = getSize() - 8; + _inventoryScroll += _inventoryScroll % 2; + } +} + +void Inventory::remove(Object &obj) { + for (int i = 0; i < _numObjects; ++i) { + if (_inventory[i] == &obj) { + if (_inventoryScroll >= 2 && getSize() % 2) + _inventoryScroll -= 2; + + --_numObjects; + while (i < _numObjects) { + _inventory[i] = _inventory[i + 1]; + ++i; + } + obj.disableProperty(CARRIED); + } + } +} + +void Inventory::clear() { + for (int i = 0; i < _numObjects; ++i) + _inventory[i]->disableProperty(CARRIED); + _numObjects = 0; + _inventoryScroll = 0; +} + +Object *Inventory::get(int index) const { + if (index < _numObjects) + return _inventory[index]; + + return _nullObject; +} + +Object *Inventory::get(ObjectId id) const { + for (int i = 0; i < _numObjects; ++i) { + if (_inventory[i]->_id == id) + return _inventory[i]; + } + + return _nullObject; +} + + +GuiElement::GuiElement() + : _isHighlighted(false) + , _bgColorNormal(kColorWhite25) + , _bgColorHighlighted(kColorWhite44) + , _bgColor(kColorWhite25) + , _textColorNormal(kColorGreen) + , _textColorHighlighted(kColorLightGreen) + , _textColor(kColorGreen) +{ + memset(_text, 0, sizeof(_text)); +} + +void GuiElement::setText(const char *text) { + strncpy(_text, text, sizeof(_text) - 1); +} + +void GuiElement::setTextPosition(int x, int y) { + _textPosition = Common::Point(x, y); +} + +void GuiElement::setSize(int x1, int y1, int x2, int y2) { + this->left = x1; + this->top = y1; + this->right = x2; + this->bottom = y2; + + _textPosition = Common::Point(x1 + 1, y1 + 1); +} + +void GuiElement::setColor(int bgColor, int textColor, int bgColorHighlighted, int textColorHightlighted) { + _bgColor = bgColor; + _textColor = textColor; + _bgColorNormal = bgColor; + _textColorNormal = textColor; + _bgColorHighlighted = bgColorHighlighted; + _textColorHighlighted = textColorHightlighted; +} + +void GuiElement::setHighlight(bool isHighlighted_) { + if (isHighlighted_) { + _bgColor = _bgColorHighlighted; + _textColor = _textColorHighlighted; + } else { + _bgColor = _bgColorNormal; + _textColor = _textColorNormal; + } +} + +StringId GameManager::guiCommands[] = { + kStringCommandGo, kStringCommandLook, kStringCommandTake, kStringCommandOpen, kStringCommandClose, + kStringCommandPress, kStringCommandPull, kStringCommandUse, kStringCommandTalk, kStringCommandGive +}; + +StringId GameManager::guiStatusCommands[] = { + kStringStatusCommandGo, kStringStatusCommandLook, kStringStatusCommandTake, kStringStatusCommandOpen, kStringStatusCommandClose, + kStringStatusCommandPress, kStringStatusCommandPull, kStringStatusCommandUse, kStringStatusCommandTalk, kStringStatusCommandGive +}; + +GameManager::GameManager(SupernovaEngine *vm, Sound *sound) + : _inventory(&_nullObject, _inventoryScroll) + , _vm(vm) + , _sound(sound) + , _mouseClickType(Common::EVENT_INVALID) { + initGui(); +} + +GameManager::~GameManager() { +} + +void GameManager::destroyRooms() { +} + +void GameManager::initState() { +} + +void GameManager::initRooms() { +} + +void GameManager::initGui() { + int cmdCount = ARRAYSIZE(_guiCommandButton); + int cmdAvailableSpace = 320 - (cmdCount - 1) * 2; + for (int i = 0; i < cmdCount; ++i) { + const Common::String &text = _vm->getGameString(guiCommands[i]); + cmdAvailableSpace -= Screen::textWidth(text); + } + + int commandButtonX = 0; + for (int i = 0; i < ARRAYSIZE(_guiCommandButton); ++i) { + const Common::String &text = _vm->getGameString(guiCommands[i]); + int width; + if (i < cmdCount - 1) { + int space = cmdAvailableSpace / (cmdCount - i); + cmdAvailableSpace -= space; + width = Screen::textWidth(text) + space; + } else + width = 320 - commandButtonX; + + _guiCommandButton[i].setSize(commandButtonX, 150, commandButtonX + width, 159); + _guiCommandButton[i].setText(text.c_str()); + _guiCommandButton[i].setColor(kColorWhite25, kColorDarkGreen, kColorWhite44, kColorGreen); + commandButtonX += width + 2; + } + + for (int i = 0; i < ARRAYSIZE(_guiInventory); ++i) { + int inventoryX = 136 * (i % 2); + int inventoryY = 161 + 10 * (i / 2); + + _guiInventory[i].setSize(inventoryX, inventoryY, inventoryX + 135, inventoryY + 9); + _guiInventory[i].setColor(kColorWhite25, kColorDarkRed, kColorWhite35, kColorRed); + } + _guiInventoryArrow[0].setSize(272, 161, 279, 180); + _guiInventoryArrow[0].setColor(kColorWhite25, kColorDarkRed, kColorWhite35, kColorRed); + _guiInventoryArrow[0].setText("\x82"); + _guiInventoryArrow[0].setTextPosition(273, 166); + _guiInventoryArrow[1].setSize(272, 181, 279, 200); + _guiInventoryArrow[1].setColor(kColorWhite25, kColorDarkRed, kColorWhite35, kColorRed); + _guiInventoryArrow[1].setText("\x83"); + _guiInventoryArrow[1].setTextPosition(273, 186); +} + +bool GameManager::canSaveGameStateCurrently() { + return false; +} + +void GameManager::updateEvents() { +} + +void GameManager::processInput(Common::KeyState &state) { + _key = state; + + switch (state.keycode) { + case Common::KEYCODE_F1: + // help + _vm->showHelpScreen(); + break; + case Common::KEYCODE_F2: + // show game manual + _vm->showTextReader("msn.doc"); + break; + case Common::KEYCODE_F3: + // show game info + _vm->showTextReader("msn.inf"); + break; + case Common::KEYCODE_F4: + _vm->setTextSpeed(); + break; + case Common::KEYCODE_F5: + // load/save + break; + case Common::KEYCODE_x: + if (state.flags & Common::KBD_ALT) { + if (_vm->quitGameDialog()) + _vm->quitGame(); + } + break; + case Common::KEYCODE_d: + if (state.flags & Common::KBD_CTRL) + _vm->_console->attach(); + break; + default: + break; + } +} + +void GameManager::resetInputState() { + setObjectNull(_inputObject[0]); + setObjectNull(_inputObject[1]); + _inputVerb = ACTION_WALK; + _processInput = false; + _mouseClicked = false; + _keyPressed = false; + _key.reset(); + _mouseClickType = Common::EVENT_MOUSEMOVE; + + processInput(); +} + +void GameManager::processInput() { + enum { + onNone, + onObject, + onCmdButton, + onInventory, + onInventoryArrowUp, + onInventoryArrowDown + } mouseLocation; + + if (_mouseField >= 0 && _mouseField < 256) + mouseLocation = onObject; + else if (_mouseField >= 256 && _mouseField < 512) + mouseLocation = onCmdButton; + else if (_mouseField >= 512 && _mouseField < 768) + mouseLocation = onInventory; + else if (_mouseField == 768) + mouseLocation = onInventoryArrowUp; + else if (_mouseField == 769) + mouseLocation = onInventoryArrowDown; + else + mouseLocation = onNone; + + if (_mouseClickType == Common::EVENT_LBUTTONUP) { + if (_vm->_screen->isMessageShown()) { + // Hide the message and consume the event + _vm->removeMessage(); + if (mouseLocation != onCmdButton) + return; + } + + switch(mouseLocation) { + case onObject: + case onInventory: + // Fallthrough + if (_inputVerb == ACTION_GIVE || _inputVerb == ACTION_USE) { + if (isNullObject(_inputObject[0])) { + _inputObject[0] = _currentInputObject; + if (!_inputObject[0]->hasProperty(COMBINABLE)) + _processInput = true; + } else { + _inputObject[1] = _currentInputObject; + _processInput = true; + } + } else { + _inputObject[0] = _currentInputObject; + if (!isNullObject(_currentInputObject)) + _processInput = true; + } + break; + case onCmdButton: + resetInputState(); + _inputVerb = static_cast<Action>(_mouseField - 256); + break; + case onInventoryArrowUp: + if (_inventoryScroll >= 2) + _inventoryScroll -= 2; + break; + case onInventoryArrowDown: + if (_inventoryScroll < _inventory.getSize() - ARRAYSIZE(_guiInventory)) + _inventoryScroll += 2; + break; + case onNone: + break; + } + + } else if (_mouseClickType == Common::EVENT_RBUTTONUP) { + if (_vm->_screen->isMessageShown()) { + // Hide the message and consume the event + _vm->removeMessage(); + return; + } + + if (isNullObject(_currentInputObject)) + return; + + if (mouseLocation == onObject || mouseLocation == onInventory) { + _inputObject[0] = _currentInputObject; + ObjectTypes type = _inputObject[0]->_type; + if (type & OPENABLE) + _inputVerb = (type & OPENED) ? ACTION_CLOSE : ACTION_OPEN; + else if (type & PRESS) + _inputVerb = ACTION_PRESS; + else if (type & TALK) + _inputVerb = ACTION_TALK; + else + _inputVerb = ACTION_LOOK; + + _processInput = true; + } + + } else if (_mouseClickType == Common::EVENT_MOUSEMOVE) { + int field = -1; + int click = -1; + + if ((_mouseY >= _guiCommandButton[0].top) && (_mouseY <= _guiCommandButton[0].bottom)) { + /* command row */ + field = 9; + while (_mouseX < _guiCommandButton[field].left - 1) + field--; + field += 256; + } else if ((_mouseX >= 283) && (_mouseX <= 317) && (_mouseY >= 163) && (_mouseY <= 197)) { + /* exit box */ + field = _exitList[(_mouseX - 283) / 7 + 5 * ((_mouseY - 163) / 7)]; + } else if ((_mouseY >= 161) && (_mouseX <= 270)) { + /* inventory box */ + field = (_mouseX + 1) / 136 + ((_mouseY - 161) / 10) * 2; + if (field + _inventoryScroll < _inventory.getSize()) + field += 512; + else + field = -1; + } else if ((_mouseY >= 161) && (_mouseX >= 271) && (_mouseX < 279)) { + /* inventory arrows */ + field = (_mouseY > 180) ? 769 : 768; + } else { + /* normal item */ + for (int i = 0; (_currentRoom->getObject(i)->_id != INVALIDOBJECT) && + (field == -1) && i < kMaxObject; i++) { + click = _currentRoom->getObject(i)->_click; + const MSNImage *image = _vm->_screen->getCurrentImage(); + if (click != 255 && image) { + const MSNImage::ClickField *clickField = image->_clickField; + do { + if ((_mouseX >= clickField[click].x1) && (_mouseX <= clickField[click].x2) && + (_mouseY >= clickField[click].y1) && (_mouseY <= clickField[click].y2)) + field = i; + + click = clickField[click].next; + } while ((click != 0) && (field == -1)); + } + } + } + + if (_mouseField != field) { + switch (mouseLocation) { + case onInventoryArrowUp: + case onInventoryArrowDown: + // Fallthrough + _guiInventoryArrow[_mouseField - 768].setHighlight(false); + break; + case onInventory: + _guiInventory[_mouseField - 512].setHighlight(false); + break; + case onCmdButton: + _guiCommandButton[_mouseField - 256].setHighlight(false); + break; + case onObject: + case onNone: + // Fallthrough + break; + } + + setObjectNull(_currentInputObject); + + _mouseField = field; + if (_mouseField >= 0 && _mouseField < 256) + mouseLocation = onObject; + else if (_mouseField >= 256 && _mouseField < 512) + mouseLocation = onCmdButton; + else if (_mouseField >= 512 && _mouseField < 768) + mouseLocation = onInventory; + else if (_mouseField == 768) + mouseLocation = onInventoryArrowUp; + else if (_mouseField == 769) + mouseLocation = onInventoryArrowDown; + else + mouseLocation = onNone; + + switch (mouseLocation) { + case onInventoryArrowUp: + case onInventoryArrowDown: + // Fallthrough + _guiInventoryArrow[_mouseField - 768].setHighlight(true); + break; + case onInventory: + _guiInventory[_mouseField - 512].setHighlight(true); + _currentInputObject = _inventory.get(_mouseField - 512 + _inventoryScroll); + break; + case onCmdButton: + _guiCommandButton[_mouseField - 256].setHighlight(true); + break; + case onObject: + _currentInputObject = _currentRoom->getObject(_mouseField); + break; + case onNone: + break; + } + } + } +} + +void GameManager::setObjectNull(Object *&obj) { + obj = &_nullObject; +} + +bool GameManager::isNullObject(Object *obj) { + return obj == &_nullObject; +} + +void GameManager::sentence(int number, bool brightness) { + if (number < 0) + return; + _vm->renderBox(0, 141 + _rowsStart[number] * 10, 320, _rows[number] * 10 - 1, brightness ? kColorWhite44 : kColorWhite25); + if (_texts[_rowsStart[number]] == kStringDialogSeparator) + _vm->renderText(kStringConversationEnd, 1, 142 + _rowsStart[number] * 10, brightness ? kColorRed : kColorDarkRed); + else { + for (int r = _rowsStart[number]; r < _rowsStart[number] + _rows[number]; ++r) + _vm->renderText(_texts[r], 1, 142 + r * 10, brightness ? kColorGreen : kColorDarkGreen); + } +} + +void GameManager::say(StringId textId) { + Common::String str = _vm->getGameString(textId); + if (!str.empty()) + say(str.c_str()); +} + +void GameManager::say(const char *text) { + Common::String t(text); + char *row[6]; + Common::String::iterator p = t.begin(); + uint numRows = 0; + while (*p) { + row[numRows++] = p; + while ((*p != '\0') && (*p != '|')) { + ++p; + } + if (*p == '|') { + *p = 0; + ++p; + } + } + + _vm->renderBox(0, 138, 320, 62, kColorBlack); + _vm->renderBox(0, 141, 320, numRows * 10 - 1, kColorWhite25); + for (uint r = 0; r < numRows; ++r) + _vm->renderText(row[r], 1, 142 + r * 10, kColorDarkGreen); + waitOnInput((t.size() + 20) * _vm->_textSpeed / 10); + _vm->renderBox(0, 138, 320, 62, kColorBlack); +} + +void GameManager::reply(StringId textId, int aus1, int aus2) { + Common::String str = _vm->getGameString(textId); + if (!str.empty()) + reply(str.c_str(), aus1, aus2); +} + +void GameManager::reply(const char *text, int aus1, int aus2) { + if (*text != '|') + _vm->renderMessage(text, kMessageTop); + + for (int z = (strlen(text) + 20) * _vm->_textSpeed / 40; z > 0; --z) { + if (aus1) + _vm->renderImage(aus1); + waitOnInput(2); + if (_keyPressed || _mouseClicked) + z = 1; + if (aus2) + _vm->renderImage(aus2); + waitOnInput(2); + if (_keyPressed || _mouseClicked) + z = 1; + } + if (*text != '|') + _vm->removeMessage(); +} + +int GameManager::dialog(int num, byte rowLength[6], StringId text[6], int number) { + _vm->_allowLoadGame = false; + _guiEnabled = false; + + bool remove[6]; + for (int i = 0; i < 6; ++i) + remove[i] = _currentRoom->sentenceRemoved(i, number); + + _vm->renderBox(0, 138, 320, 62, kColorBlack); + + for (int i = 0; i < 6 ; ++i) + _sentenceNumber[i] = -1; + + int r = 0, rq = 0; + for (int i = 0; i < num; ++i) { + if (!remove[i]) { + _rowsStart[i] = r; + _rows[i] = rowLength[i]; + for (int j = 0; j < _rows[i]; ++j, ++r, ++rq) { + _texts[r] = text[rq]; + _sentenceNumber[r] = i; + } + sentence(i, false); + } else + rq += rowLength[i]; + } + + _currentSentence = -1; + do { + do { + updateEvents(); + mousePosDialog(_mouseX, _mouseY); + g_system->updateScreen(); + g_system->delayMillis(_vm->_delay); + } while (!_mouseClicked && !_vm->shouldQuit()); + } while (_currentSentence == -1 && !_vm->shouldQuit()); + + _vm->renderBox(0, 138, 320, 62, kColorBlack); + + if (number && _currentSentence != -1 && _texts[_rowsStart[_currentSentence]] != kStringDialogSeparator) + _currentRoom->removeSentence(_currentSentence, number); + + _guiEnabled = true; + _vm->_allowLoadGame = true; + + return _currentSentence; +} + +void GameManager::mousePosDialog(int x, int y) { + int a = y < 141 ? -1 : _sentenceNumber[(y - 141) / 10]; + if (a != _currentSentence) { + sentence(_currentSentence, false); + _currentSentence = a; + sentence(_currentSentence, true); + } +} + +void GameManager::takeObject(Object &obj) { + if (obj.hasProperty(CARRIED)) + return; + + if (obj._section != 0) + _vm->renderImage(obj._section); + obj._click = obj._click2 = 255; + _inventory.add(obj); +} + +void GameManager::drawCommandBox() { + for (int i = 0; i < ARRAYSIZE(_guiCommandButton); ++i) { + _vm->renderBox(_guiCommandButton[i]); + int space = (_guiCommandButton[i].width() - Screen::textWidth(_guiCommandButton[i].getText())) / 2; + _vm->renderText(_guiCommandButton[i].getText(), + _guiCommandButton[i].getTextPos().x + space, + _guiCommandButton[i].getTextPos().y, + _guiCommandButton[i].getTextColor()); + } +} + +void GameManager::drawInventory() { + for (int i = 0; i < ARRAYSIZE(_guiInventory); ++i) { + _vm->renderBox(_guiInventory[i]); + _vm->renderText(_inventory.get(i + _inventoryScroll)->_name, + _guiInventory[i].getTextPos().x, + _guiInventory[i].getTextPos().y, + _guiInventory[i].getTextColor()); + } + + _vm->renderBox(_guiInventoryArrow[0]); + _vm->renderBox(_guiInventoryArrow[1]); + if (_inventory.getSize() > ARRAYSIZE(_guiInventory)) { + if (_inventoryScroll != 0) + _vm->renderText(_guiInventoryArrow[0]); + if (_inventoryScroll + ARRAYSIZE(_guiInventory) < _inventory.getSize()) + _vm->renderText(_guiInventoryArrow[1]); + } +} + +int GameManager::getKeyInput() { + while (!_vm->shouldQuit()) { + updateEvents(); + if (_keyPressed) { + return _key.ascii; + } + g_system->updateScreen(); + g_system->delayMillis(_vm->_delay); + } + return 0; +} + +Common::EventType GameManager::getMouseInput() { + while (!_vm->shouldQuit()) { + updateEvents(); + if (_mouseClicked) + return _mouseClickType; + g_system->updateScreen(); + g_system->delayMillis(_vm->_delay); + } + return Common::EVENT_INVALID; +} + +void GameManager::getInput() { + while (!_vm->shouldQuit()) { + updateEvents(); + if (_mouseClicked || _keyPressed) + break; + g_system->updateScreen(); + g_system->delayMillis(_vm->_delay); + } +} + +void GameManager::roomBrightness() { +} + +void GameManager::changeRoom(RoomId id) { + _currentRoom = _rooms[id]; + _newRoom = true; +} + +void GameManager::wait(int ticks) { + int32 end = _time + ticksToMsec(ticks); + do { + g_system->delayMillis(_vm->_delay); + updateEvents(); + g_system->updateScreen(); + } while (_time < end && !_vm->shouldQuit()); +} + +void GameManager::waitOnInput(int ticks) { + int32 end = _time + ticksToMsec(ticks); + do { + g_system->delayMillis(_vm->_delay); + updateEvents(); + g_system->updateScreen(); + } while (_time < end && !_vm->shouldQuit() && !_keyPressed && !_mouseClicked); +} + +bool GameManager::waitOnInput(int ticks, Common::KeyCode &keycode) { + keycode = Common::KEYCODE_INVALID; + int32 end = _time + ticksToMsec(ticks); + do { + g_system->delayMillis(_vm->_delay); + updateEvents(); + g_system->updateScreen(); + if (_keyPressed) { + keycode = _key.keycode; + _key.reset(); + return true; + } else if (_mouseClicked) + return true; + } while (_time < end && !_vm->shouldQuit()); + return false; +} + +void GameManager::setAnimationTimer(int ticks) { + _animationTimer = ticksToMsec(ticks); +} + +void GameManager::handleTime() { +} + +void GameManager::pauseTimer(bool pause) { + if (pause == _timerPaused) + return; + + if (pause) { + _timerPaused = true; + int32 delta = g_system->getMillis() - _oldTime; + _timePaused = _time + delta; + } else { + _time = _timePaused; + _oldTime = g_system->getMillis(); + _timerPaused = false; + } +} + +void GameManager::loadTime() { +} + +void GameManager::saveTime() { +} + +void GameManager::screenShake() { + for (int i = 0; i < 12; ++i) { + _vm->_system->setShakePos(8); + wait(1); + _vm->_system->setShakePos(0); + wait(1); + } +} + +void GameManager::showMenu() { + _vm->renderBox(0, 138, 320, 62, 0); + _vm->renderBox(0, 140, 320, 9, kColorWhite25); + drawCommandBox(); + _vm->renderBox(281, 161, 39, 39, kColorWhite25); + drawInventory(); +} + +void GameManager::drawMapExits() { +} + +void GameManager::animationOff() { + _animationEnabled = false; +} + +void GameManager::animationOn() { + _animationEnabled = true; +} + +void GameManager::edit(Common::String &input, int x, int y, uint length) { + bool isEditing = true; + uint cursorIndex = input.size(); + // NOTE: Pixels for char needed = kFontWidth + 2px left and right side bearing + int overdrawWidth = ((int)((length + 1) * (kFontWidth + 2)) > (kScreenWidth - x)) ? + kScreenWidth - x : (length + 1) * (kFontWidth + 2); + + _guiEnabled = false; + while (isEditing) { + _vm->_screen->setTextCursorPos(x, y); + _vm->_screen->setTextCursorColor(kColorWhite99); + Color background = kColorBlack; + if (_vm->_MSPart == 1) + background = kColorDarkBlue; + else if (_vm->_MSPart == 2) + background = kColorWhite35; + _vm->renderBox(x, y - 1, overdrawWidth, 9, background); + for (uint i = 0; i < input.size(); ++i) { + // Draw char highlight depending on cursor position + if (i == cursorIndex) { + _vm->renderBox(_vm->_screen->getTextCursorPos().x, y - 1, + Screen::textWidth(input[i]), 9, kColorWhite99); + _vm->_screen->setTextCursorColor(background); + _vm->renderText(input[i]); + _vm->_screen->setTextCursorColor(kColorWhite99); + } else + _vm->renderText(input[i]); + } + + if (cursorIndex == input.size()) { + _vm->renderBox(_vm->_screen->getTextCursorPos().x + 1, y - 1, 6, 9, background); + _vm->renderBox(_vm->_screen->getTextCursorPos().x, y - 1, 1, 9, kColorWhite99); + } + + getKeyInput(); + if (_vm->shouldQuit()) + break; + switch (_key.keycode) { + case Common::KEYCODE_RETURN: + case Common::KEYCODE_ESCAPE: + isEditing = false; + break; + case Common::KEYCODE_UP: + case Common::KEYCODE_DOWN: + cursorIndex = input.size(); + break; + case Common::KEYCODE_LEFT: + if (cursorIndex != 0) + --cursorIndex; + break; + case Common::KEYCODE_RIGHT: + if (cursorIndex != input.size()) + ++cursorIndex; + break; + case Common::KEYCODE_DELETE: + if (cursorIndex != input.size()) + input.deleteChar(cursorIndex); + break; + case Common::KEYCODE_BACKSPACE: + if (cursorIndex != 0) { + --cursorIndex; + input.deleteChar(cursorIndex); + } + break; + default: + if (Common::isPrint(_key.ascii) && input.size() < length) { + input.insertChar(_key.ascii, cursorIndex); + ++cursorIndex; + } + break; + } + } +} + +void GameManager::takeMoney(int amount) { +} + +void GameManager::drawStatus() { + int index = static_cast<int>(_inputVerb); + _vm->renderBox(0, 140, 320, 9, kColorWhite25); + _vm->renderText(_vm->getGameString(guiStatusCommands[index]), 1, 141, kColorDarkGreen); + + if (isNullObject(_inputObject[0])) + _vm->renderText(_currentInputObject->_name); + else { + _vm->renderText(_inputObject[0]->_name); + if (_inputVerb == ACTION_GIVE) + _vm->renderText(kPhrasalVerbParticleGiveTo); + else if (_inputVerb == ACTION_USE) + _vm->renderText(kPhrasalVerbParticleUseWith); + + _vm->renderText(_currentInputObject->_name); + } +} + +void GameManager::dead(StringId messageId) { + _vm->paletteFadeOut(); + _guiEnabled = false; + if (_vm->_MSPart == 1) + _vm->setCurrentImage(11); + else if (_vm->_MSPart == 2) + _vm->setCurrentImage(43); + _vm->renderImage(0); + _vm->renderMessage(messageId); + _sound->play(kAudioDeath); + _vm->paletteFadeIn(); + getInput(); + _vm->paletteFadeOut(); + _vm->removeMessage(); + + destroyRooms(); + initRooms(); + initState(); + if (_vm->_MSPart == 1) + changeRoom(CABIN_R3); + else if (_vm->_MSPart == 2) + changeRoom(CABIN_R3); + initGui(); + _inventory.clear(); + g_system->fillScreen(kColorBlack); + _vm->paletteFadeIn(); + + _guiEnabled = true; +} + +int GameManager::invertSection(int section) { + if (section < 128) + section += 128; + else + section -= 128; + + return section; +} + +bool GameManager::genericInteract(Action verb, Object &obj1, Object &obj2) { + return false; +} + +void GameManager::handleInput() { +} + +void GameManager::executeRoom() { +} + +void GameManager::drawGUI() { + drawMapExits(); + drawInventory(); + drawStatus(); + drawCommandBox(); +} + +} diff --git a/engines/supernova/game-manager.h b/engines/supernova/game-manager.h new file mode 100644 index 0000000000..585d9d2f82 --- /dev/null +++ b/engines/supernova/game-manager.h @@ -0,0 +1,208 @@ +/* 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. + * + */ + +#ifndef SUPERNOVA_GAME_MANAGER_H +#define SUPERNOVA_GAME_MANAGER_H + +#include "common/events.h" +#include "common/rect.h" +#include "common/keyboard.h" +#include "common/error.h" +#include "supernova/rooms.h" +#include "supernova/sound.h" + +namespace Supernova { + +const int32 kMaxTimerValue = 0x7FFFFFFF; + +enum EventFunction { kNoFn, kSupernovaFn, kGuardReturnedFn, kGuardWalkFn, kTaxiFn, kSearchStartFn, kSoberFn, kPyramidEndFn, kCaughtFn}; + + +class Inventory { +public: + Inventory(Object *nullObject, int &inventoryScroll) + : _numObjects(0) + , _nullObject(nullObject) + , _inventoryScroll(inventoryScroll) { + for (int i = 0; i < kMaxCarry; ++i) + _inventory[i] = nullptr; + } + + void add(Object &obj); + void remove(Object &obj); + void clear(); + Object *get(int index) const; + Object *get(ObjectId id) const; + int getSize() const { return _numObjects; } + +private: + Object *_inventory[kMaxCarry]; + Object *_nullObject; + int &_inventoryScroll; + int _numObjects; +}; + +class GuiElement : public Common::Rect { +public: + GuiElement(); + + void setSize(int x1, int y1, int x2, int y2); + void setText(const char *text); + void setTextPosition(int x, int y); + void setColor(int bgColor, int textColor, int bgColorHighlighted, int textColorHightlighted); + void setHighlight(bool isHighlighted); + + const char *getText() const { + return _text; + } + int getBackgroundColor() const { + return _bgColor; + } + int getTextColor() const { + return _textColor; + } + const Common::Point &getTextPos() const { + return _textPosition; + } + bool isHighlighted() const { + return _isHighlighted; + } + +private: + Common::Point _textPosition; + char _text[128]; + int _bgColor; + int _textColor; + int _bgColorNormal; + int _bgColorHighlighted; + int _textColorNormal; + int _textColorHighlighted; + bool _isHighlighted; +}; + +class GameManager { +public: + GameManager(SupernovaEngine *vm, Sound *sound); + virtual ~GameManager(); + + virtual void updateEvents(); + void processInput(Common::KeyState &state); + void processInput(); + virtual void executeRoom(); + virtual bool serialize(Common::WriteStream *out); + virtual bool deserialize(Common::ReadStream *in, int version); + + static StringId guiCommands[]; + static StringId guiStatusCommands[]; + SupernovaEngine *_vm; + Sound *_sound; + Common::KeyState _key; + Common::EventType _mouseClickType; + bool _mouseClicked; + bool _keyPressed; + int _mouseX; + int _mouseY; + int _mouseField; + Room *_currentRoom; + Room *_lastRoom; + bool _newRoom; + Room *_rooms[NUMROOMS]; + Inventory _inventory; + bool _processInput; + bool _guiEnabled; + bool _animationEnabled; + byte _roomBrightness; + Action _inputVerb; + Object _nullObject; + Object *_currentInputObject; + Object *_inputObject[2]; + int32 _oldTime; + uint _timePaused; + bool _timerPaused; + int32 _messageDuration; + int32 _animationTimer; + int _inventoryScroll; + int _exitList[25]; + GuiElement _guiCommandButton[10]; + GuiElement _guiInventory[8]; + GuiElement _guiInventoryArrow[2]; + // Dialog + int _currentSentence; + int _sentenceNumber[6]; + StringId _texts[6]; + byte _rows[6]; + byte _rowsStart[6]; + int32 _time; + + void takeObject(Object &obj); + void setObjectNull(Object *&obj); + bool isNullObject(Object *obj); + + virtual void initState(); + virtual void initRooms(); + virtual void destroyRooms(); + void initGui(); + virtual bool canSaveGameStateCurrently(); + virtual bool genericInteract(Action verb, Object &obj1, Object &obj2); + Common::EventType getMouseInput(); + int getKeyInput(); + void getInput(); + void wait(int ticks); + void waitOnInput(int ticks); + bool waitOnInput(int ticks, Common::KeyCode &keycode); + void screenShake(); + virtual void roomBrightness(); + void showMenu(); + void animationOff(); + void animationOn(); + void edit(Common::String &input, int x, int y, uint length); + int invertSection(int section); + virtual void drawMapExits(); + void drawStatus(); + void drawCommandBox(); + void drawInventory(); + void drawGUI(); + void changeRoom(RoomId id); + void resetInputState(); + virtual void handleInput(); + virtual void handleTime(); + void pauseTimer(bool pause); + virtual void loadTime(); + virtual void saveTime(); + void setAnimationTimer(int ticks); + void dead(StringId messageId); + int dialog(int num, byte rowLength[6], StringId text[6], int number); + void sentence(int number, bool brightness); + void say(StringId textId); + void say(const char *text); + void reply(StringId textId, int aus1, int aus2); + void reply(const char *text, int aus1, int aus2); + void mousePosDialog(int x, int y); + virtual void takeMoney(int amount); + +private: + int _prevImgId; +}; + +} + +#endif // SUPERNOVA_GAME_MANAGER_H diff --git a/engines/supernova/module.mk b/engines/supernova/module.mk index c9bc1ca0b7..a0750183b4 100644 --- a/engines/supernova/module.mk +++ b/engines/supernova/module.mk @@ -1,14 +1,15 @@ MODULE := engines/supernova MODULE_OBJS := \ + console.o \ detection.o \ - state.o \ graphics.o \ resman.o \ rooms.o \ screen.o \ - console.o \ sound.o \ + game-manager.o \ + state.o \ supernova.o MODULE_DIRS += \ diff --git a/engines/supernova/rooms.cpp b/engines/supernova/rooms.cpp index 10cb988f6b..e6e7dd79b7 100644 --- a/engines/supernova/rooms.cpp +++ b/engines/supernova/rooms.cpp @@ -180,7 +180,7 @@ bool Room::interact(Action verb, Object &obj1, Object &obj2) { } -Intro::Intro(SupernovaEngine *vm, GameManager *gm) { +Intro::Intro(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -606,7 +606,7 @@ void Intro::leaveCutscene() { _vm->_allowLoadGame = true; } -ShipCorridor::ShipCorridor(SupernovaEngine *vm, GameManager *gm) { +ShipCorridor::ShipCorridor(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -655,7 +655,7 @@ bool ShipCorridor::interact(Action verb, Object &obj1, Object &obj2) { return false; } -ShipHall::ShipHall(SupernovaEngine *vm, GameManager *gm) { +ShipHall::ShipHall(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -702,7 +702,7 @@ bool ShipHall::interact(Action verb, Object &obj1, Object &obj2) { return true; } -ShipSleepCabin::ShipSleepCabin(SupernovaEngine *vm, GameManager *gm) { +ShipSleepCabin::ShipSleepCabin(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -844,8 +844,8 @@ bool ShipSleepCabin::interact(Action verb, Object &obj1, Object &obj2) { } _gm->_state._arrivalDaysLeft -= _gm->_state._timeSleep; *energyDaysLeft -= _gm->_state._timeSleep; - _gm->_state._time = ticksToMsec(786520); // 12pm - _gm->_state._alarmOn = (_gm->_state._timeAlarm > _gm->_state._time); + _gm->_time = ticksToMsec(786520); // 12pm + _gm->_state._alarmOn = (_gm->_state._timeAlarm > _gm->_time); if (*energyDaysLeft == 0) { _gm->turnOff(); room = _gm->_rooms[GENERATOR]; @@ -915,7 +915,7 @@ void ShipSleepCabin::onEntrance() { } } -ShipCockpit::ShipCockpit(SupernovaEngine *vm, GameManager *gm) { +ShipCockpit::ShipCockpit(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1000,7 +1000,7 @@ void ShipCockpit::onEntrance() { setRoomSeen(true); } -ShipCabinL1::ShipCabinL1(SupernovaEngine *vm, GameManager *gm) { +ShipCabinL1::ShipCabinL1(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1027,7 +1027,7 @@ ShipCabinL1::ShipCabinL1(SupernovaEngine *vm, GameManager *gm) { _objectState[11] = Object(_id, kStringToilet, kStringDefaultDescription, BATHROOM_DOOR, EXIT, 255, 255, 0, BATHROOM, 22); } -ShipCabinL2::ShipCabinL2(SupernovaEngine *vm, GameManager *gm) { +ShipCabinL2::ShipCabinL2(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1105,7 +1105,7 @@ bool ShipCabinL2::interact(Action verb, Object &obj1, Object &obj2) { return true; } -ShipCabinL3::ShipCabinL3(SupernovaEngine *vm, GameManager *gm) { +ShipCabinL3::ShipCabinL3(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1218,7 +1218,7 @@ bool ShipCabinL3::interact(Action verb, Object &obj1, Object &obj2) { return true; } -ShipCabinR1::ShipCabinR1(SupernovaEngine *vm, GameManager *gm) { +ShipCabinR1::ShipCabinR1(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1239,7 +1239,7 @@ ShipCabinR1::ShipCabinR1(SupernovaEngine *vm, GameManager *gm) { _objectState[8] = Object(_id, kStringToilet,kStringDefaultDescription,BATHROOM_DOOR,EXIT,255,255,0,BATHROOM,22); } -ShipCabinR2::ShipCabinR2(SupernovaEngine *vm, GameManager *gm) { +ShipCabinR2::ShipCabinR2(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1261,7 +1261,7 @@ ShipCabinR2::ShipCabinR2(SupernovaEngine *vm, GameManager *gm) { _objectState[8] = Object(_id, kStringToilet,kStringDefaultDescription,BATHROOM_DOOR,EXIT,255,255,0,BATHROOM,22); } -ShipCabinR3::ShipCabinR3(SupernovaEngine *vm, GameManager *gm) { +ShipCabinR3::ShipCabinR3(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1349,7 +1349,7 @@ void ShipCabinR3::onEntrance() { setRoomSeen(true); } -ShipCabinBathroom::ShipCabinBathroom(SupernovaEngine *vm, GameManager *gm) { +ShipCabinBathroom::ShipCabinBathroom(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1362,7 +1362,7 @@ ShipCabinBathroom::ShipCabinBathroom(SupernovaEngine *vm, GameManager *gm) { _objectState[2] = Object(_id, kStringExit,kStringDefaultDescription,BATHROOM_EXIT,EXIT,255,255,0,CABIN_R3,2); } -ShipAirlock::ShipAirlock(SupernovaEngine *vm, GameManager *gm) { +ShipAirlock::ShipAirlock(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1488,7 +1488,7 @@ void ShipAirlock::onEntrance() { setRoomSeen(true); } -ShipHold::ShipHold(SupernovaEngine *vm, GameManager *gm) { +ShipHold::ShipHold(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1566,7 +1566,7 @@ void ShipHold::onEntrance() { _gm->_rooms[COCKPIT]->setRoomSeen(true); } -ShipLandingModule::ShipLandingModule(SupernovaEngine *vm, GameManager *gm) { +ShipLandingModule::ShipLandingModule(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1680,7 +1680,7 @@ bool ShipLandingModule::interact(Action verb, Object &obj1, Object &obj2) { return true; } -ShipGenerator::ShipGenerator(SupernovaEngine *vm, GameManager *gm) { +ShipGenerator::ShipGenerator(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1847,7 +1847,7 @@ bool ShipGenerator::interact(Action verb, Object &obj1, Object &obj2) { return true; } -ShipOuterSpace::ShipOuterSpace(SupernovaEngine *vm, GameManager *gm) { +ShipOuterSpace::ShipOuterSpace(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1861,7 +1861,7 @@ ShipOuterSpace::ShipOuterSpace(SupernovaEngine *vm, GameManager *gm) { // Arsano -ArsanoRocks::ArsanoRocks(SupernovaEngine *vm, GameManager *gm) { +ArsanoRocks::ArsanoRocks(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1896,7 +1896,7 @@ bool ArsanoRocks::interact(Action verb, Object &obj1, Object &obj2) { return false; } -ArsanoCave::ArsanoCave(SupernovaEngine *vm, GameManager *gm) { +ArsanoCave::ArsanoCave(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1907,7 +1907,7 @@ ArsanoCave::ArsanoCave(SupernovaEngine *vm, GameManager *gm) { _objectState[1] = Object(_id, kStringExit,kStringDefaultDescription,NULLOBJECT,EXIT,255,255,0,MEETUP,2); } -ArsanoMeetup::ArsanoMeetup(SupernovaEngine *vm, GameManager *gm) { +ArsanoMeetup::ArsanoMeetup(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -1998,7 +1998,7 @@ bool ArsanoMeetup::interact(Action verb, Object &obj1, Object &obj2) { return true; } -ArsanoEntrance::ArsanoEntrance(SupernovaEngine *vm, GameManager *gm) { +ArsanoEntrance::ArsanoEntrance(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -2269,7 +2269,7 @@ bool ArsanoEntrance::interact(Action verb, Object &obj1, Object &obj2) { return true; } -ArsanoRemaining::ArsanoRemaining(SupernovaEngine *vm, GameManager *gm) { +ArsanoRemaining::ArsanoRemaining(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -2445,7 +2445,7 @@ void ArsanoRemaining::animation() { _gm->setAnimationTimer(3); } -ArsanoRoger::ArsanoRoger(SupernovaEngine *vm, GameManager *gm) { +ArsanoRoger::ArsanoRoger(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -2575,9 +2575,9 @@ bool ArsanoRoger::interact(Action verb, Object &obj1, Object &obj2) { _vm->removeMessage(); _vm->_screen->setGuiBrightness(0); _vm->paletteBrightness(); - _gm->_state._time += ticksToMsec(125000); // 2 hours - _gm->_state._alarmOn = (_gm->_state._timeAlarm > _gm->_state._time); - _gm->_state._eventTime = _gm->_state._time + ticksToMsec(4000); + _gm->_time += ticksToMsec(125000); // 2 hours + _gm->_state._alarmOn = (_gm->_state._timeAlarm > _gm->_time); + _gm->_state._eventTime = _gm->_time + ticksToMsec(4000); _gm->_state._eventCallback = kSupernovaFn; setSectionVisible(11, false); setSectionVisible(1, false); @@ -2596,7 +2596,7 @@ bool ArsanoRoger::interact(Action verb, Object &obj1, Object &obj2) { return true; } -ArsanoGlider::ArsanoGlider(SupernovaEngine *vm, GameManager *gm) { +ArsanoGlider::ArsanoGlider(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -2695,7 +2695,7 @@ bool ArsanoGlider::interact(Action verb, Object &obj1, Object &obj2) { return true; } -ArsanoMeetup2::ArsanoMeetup2(SupernovaEngine *vm, GameManager *gm) { +ArsanoMeetup2::ArsanoMeetup2(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -2851,7 +2851,7 @@ void ArsanoMeetup2::shipStart() { _vm->renderImage(11 + 128); } -ArsanoMeetup3::ArsanoMeetup3(SupernovaEngine *vm, GameManager *gm) { +ArsanoMeetup3::ArsanoMeetup3(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -2993,7 +2993,7 @@ bool ArsanoMeetup3::interact(Action verb, Object &obj1, Object &obj2) { } // Axacuss -AxacussCell::AxacussCell(SupernovaEngine *vm, GameManager *gm) { +AxacussCell::AxacussCell(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3018,8 +3018,8 @@ AxacussCell::AxacussCell(SupernovaEngine *vm, GameManager *gm) { void AxacussCell::onEntrance() { if (_gm->_state._dream) { _vm->renderMessage(kStringAxacussCell_1); - _gm->_state._time = ticksToMsec(500000); - _gm->_state._alarmOn = (_gm->_state._timeAlarm > _gm->_state._time); + _gm->_time = ticksToMsec(500000); + _gm->_state._alarmOn = (_gm->_state._timeAlarm > _gm->_time); _gm->_state._powerOff = false; _gm->_state._dream = false; } @@ -3188,7 +3188,7 @@ bool AxacussCell::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussCorridor1::AxacussCorridor1(SupernovaEngine *vm, GameManager *gm) { +AxacussCorridor1::AxacussCorridor1(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3212,7 +3212,7 @@ void AxacussCorridor1::onEntrance() { } -AxacussCorridor2::AxacussCorridor2(SupernovaEngine *vm, GameManager *gm) { +AxacussCorridor2::AxacussCorridor2(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3236,7 +3236,7 @@ void AxacussCorridor2::onEntrance() { _gm->corridorOnEntrance(); } -AxacussCorridor3::AxacussCorridor3(SupernovaEngine *vm, GameManager *gm) { +AxacussCorridor3::AxacussCorridor3(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3262,7 +3262,7 @@ void AxacussCorridor4::onEntrance() { _gm->busted(0); } -AxacussCorridor4::AxacussCorridor4(SupernovaEngine *vm, GameManager *gm) { +AxacussCorridor4::AxacussCorridor4(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3317,7 +3317,7 @@ bool AxacussCorridor4::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussCorridor5::AxacussCorridor5(SupernovaEngine *vm, GameManager *gm) { +AxacussCorridor5::AxacussCorridor5(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3434,7 +3434,7 @@ bool AxacussCorridor5::interact(Action verb, Object &obj1, Object &obj2) { return false; } -AxacussCorridor6::AxacussCorridor6(SupernovaEngine *vm, GameManager *gm) { +AxacussCorridor6::AxacussCorridor6(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3474,7 +3474,7 @@ bool AxacussCorridor6::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussCorridor7::AxacussCorridor7(SupernovaEngine *vm, GameManager *gm) { +AxacussCorridor7::AxacussCorridor7(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3497,7 +3497,7 @@ void AxacussCorridor7::onEntrance() { _gm->corridorOnEntrance(); } -AxacussCorridor8::AxacussCorridor8(SupernovaEngine *vm, GameManager *gm) { +AxacussCorridor8::AxacussCorridor8(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3543,7 +3543,7 @@ bool AxacussCorridor8::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussCorridor9::AxacussCorridor9(SupernovaEngine *vm, GameManager *gm) { +AxacussCorridor9::AxacussCorridor9(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3588,7 +3588,7 @@ bool AxacussCorridor9::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussBcorridor::AxacussBcorridor(SupernovaEngine *vm, GameManager *gm) { +AxacussBcorridor::AxacussBcorridor(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3690,7 +3690,7 @@ bool AxacussBcorridor::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussIntersection::AxacussIntersection(SupernovaEngine *vm, GameManager *gm) { +AxacussIntersection::AxacussIntersection(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3740,7 +3740,7 @@ bool AxacussIntersection::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussExit::AxacussExit(SupernovaEngine *vm, GameManager *gm) { +AxacussExit::AxacussExit(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3791,7 +3791,7 @@ bool AxacussExit::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussOffice1::AxacussOffice1(SupernovaEngine *vm, GameManager *gm) { +AxacussOffice1::AxacussOffice1(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3895,7 +3895,7 @@ bool AxacussOffice1::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussOffice2::AxacussOffice2(SupernovaEngine *vm, GameManager *gm) { +AxacussOffice2::AxacussOffice2(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3940,7 +3940,7 @@ bool AxacussOffice2::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussOffice3::AxacussOffice3(SupernovaEngine *vm, GameManager *gm) { +AxacussOffice3::AxacussOffice3(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -3989,7 +3989,7 @@ bool AxacussOffice3::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussOffice4::AxacussOffice4(SupernovaEngine *vm, GameManager *gm) { +AxacussOffice4::AxacussOffice4(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -4031,7 +4031,7 @@ bool AxacussOffice4::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussOffice5::AxacussOffice5(SupernovaEngine *vm, GameManager *gm) { +AxacussOffice5::AxacussOffice5(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -4066,7 +4066,7 @@ bool AxacussOffice5::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussElevator::AxacussElevator(SupernovaEngine *vm, GameManager *gm) { +AxacussElevator::AxacussElevator(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -4132,8 +4132,8 @@ bool AxacussElevator::interact(Action verb, Object &obj1, Object &obj2) { _vm->removeMessage(); _vm->_screen->setGuiBrightness(0); _vm->paletteBrightness(); - _gm->_state._time += ticksToMsec(125000); // 2 hours - _gm->_state._alarmOn = (_gm->_state._timeAlarm > _gm->_state._time); + _gm->_time += ticksToMsec(125000); // 2 hours + _gm->_state._alarmOn = (_gm->_state._timeAlarm > _gm->_time); return false; } else return false; @@ -4141,7 +4141,7 @@ bool AxacussElevator::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussStation::AxacussStation(SupernovaEngine *vm, GameManager *gm) { +AxacussStation::AxacussStation(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -4167,7 +4167,7 @@ bool AxacussStation::interact(Action verb, Object &obj1, Object &obj2) { return true; } -AxacussSign::AxacussSign(SupernovaEngine *vm, GameManager *gm) { +AxacussSign::AxacussSign(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; @@ -4186,7 +4186,7 @@ bool AxacussSign::interact(Action verb, Object &obj1, Object &obj2) { _gm->takeMoney(-180); _vm->renderImage(2); setSectionVisible(1, false); - _gm->_state._eventTime = _gm->_state._time + ticksToMsec(600); + _gm->_state._eventTime = _gm->_time + ticksToMsec(600); _gm->_state._eventCallback = kTaxiFn; return true; } @@ -4194,7 +4194,7 @@ bool AxacussSign::interact(Action verb, Object &obj1, Object &obj2) { } -Outro::Outro(SupernovaEngine *vm, GameManager *gm) { +Outro::Outro(SupernovaEngine *vm, GameManager1 *gm) { _vm = vm; _gm = gm; diff --git a/engines/supernova/rooms.h b/engines/supernova/rooms.h index 801bfc4d80..95e207865e 100644 --- a/engines/supernova/rooms.h +++ b/engines/supernova/rooms.h @@ -34,7 +34,7 @@ class WriteStream; namespace Supernova { -class GameManager; +class GameManager1; class SupernovaEngine; class Room { @@ -68,7 +68,7 @@ protected: Object _objectState[kMaxObject]; RoomId _id; SupernovaEngine *_vm; - GameManager *_gm; + GameManager1 *_gm; private: bool _seen; @@ -77,7 +77,7 @@ private: // Room 0 class Intro : public Room { public: - Intro(SupernovaEngine *vm, GameManager *gm); + Intro(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); private: @@ -99,21 +99,21 @@ private: // Spaceship class ShipCorridor : public Room { public: - ShipCorridor(SupernovaEngine *vm, GameManager *gm); + ShipCorridor(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class ShipHall: public Room { public: - ShipHall(SupernovaEngine *vm, GameManager *gm); + ShipHall(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class ShipSleepCabin: public Room { public: - ShipSleepCabin(SupernovaEngine *vm, GameManager *gm); + ShipSleepCabin(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); virtual void animation(); @@ -125,7 +125,7 @@ private: class ShipCockpit : public Room { public: - ShipCockpit(SupernovaEngine *vm, GameManager *gm); + ShipCockpit(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); virtual void animation(); @@ -137,36 +137,36 @@ private: class ShipCabinL1: public Room { public: - ShipCabinL1(SupernovaEngine *vm, GameManager *gm); + ShipCabinL1(SupernovaEngine *vm, GameManager1 *gm); }; class ShipCabinL2 : public Room { public: - ShipCabinL2(SupernovaEngine *vm, GameManager *gm); + ShipCabinL2(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class ShipCabinL3 : public Room { public: - ShipCabinL3(SupernovaEngine *vm, GameManager *gm); + ShipCabinL3(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class ShipCabinR1 : public Room { public: - ShipCabinR1(SupernovaEngine *vm, GameManager *gm); + ShipCabinR1(SupernovaEngine *vm, GameManager1 *gm); }; class ShipCabinR2 : public Room { public: - ShipCabinR2(SupernovaEngine *vm, GameManager *gm); + ShipCabinR2(SupernovaEngine *vm, GameManager1 *gm); }; class ShipCabinR3 : public Room { public: - ShipCabinR3(SupernovaEngine *vm, GameManager *gm); + ShipCabinR3(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); virtual void onEntrance(); @@ -174,12 +174,12 @@ public: class ShipCabinBathroom : public Room { public: - ShipCabinBathroom(SupernovaEngine *vm, GameManager *gm); + ShipCabinBathroom(SupernovaEngine *vm, GameManager1 *gm); }; class ShipAirlock : public Room { public: - ShipAirlock(SupernovaEngine *vm, GameManager *gm); + ShipAirlock(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); virtual void onEntrance(); @@ -187,7 +187,7 @@ public: class ShipHold : public Room { public: - ShipHold(SupernovaEngine *vm, GameManager *gm); + ShipHold(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); virtual void onEntrance(); @@ -195,28 +195,28 @@ public: class ShipLandingModule : public Room { public: - ShipLandingModule(SupernovaEngine *vm, GameManager *gm); + ShipLandingModule(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class ShipGenerator : public Room { public: - ShipGenerator(SupernovaEngine *vm, GameManager *gm); + ShipGenerator(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class ShipOuterSpace : public Room { public: - ShipOuterSpace(SupernovaEngine *vm, GameManager *gm); + ShipOuterSpace(SupernovaEngine *vm, GameManager1 *gm); }; // Arsano class ArsanoRocks : public Room { public: - ArsanoRocks(SupernovaEngine *vm, GameManager *gm); + ArsanoRocks(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -224,12 +224,12 @@ public: class ArsanoCave : public Room { public: - ArsanoCave(SupernovaEngine *vm, GameManager *gm); + ArsanoCave(SupernovaEngine *vm, GameManager1 *gm); }; class ArsanoMeetup : public Room { public: - ArsanoMeetup(SupernovaEngine *vm, GameManager *gm); + ArsanoMeetup(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual void animation(); @@ -242,7 +242,7 @@ private: class ArsanoEntrance : public Room { public: - ArsanoEntrance(SupernovaEngine *vm, GameManager *gm); + ArsanoEntrance(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); virtual void animation(); @@ -256,7 +256,7 @@ private: class ArsanoRemaining : public Room { public: - ArsanoRemaining(SupernovaEngine *vm, GameManager *gm); + ArsanoRemaining(SupernovaEngine *vm, GameManager1 *gm); virtual void animation(); @@ -267,7 +267,7 @@ private: class ArsanoRoger : public Room { public: - ArsanoRoger(SupernovaEngine *vm, GameManager *gm); + ArsanoRoger(SupernovaEngine *vm, GameManager1 *gm); virtual void animation(); virtual void onEntrance(); @@ -281,7 +281,7 @@ private: class ArsanoGlider : public Room { public: - ArsanoGlider(SupernovaEngine *vm, GameManager *gm); + ArsanoGlider(SupernovaEngine *vm, GameManager1 *gm); virtual void animation(); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -292,7 +292,7 @@ private: class ArsanoMeetup2 : public Room { public: - ArsanoMeetup2(SupernovaEngine *vm, GameManager *gm); + ArsanoMeetup2(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -313,7 +313,7 @@ private: class ArsanoMeetup3 : public Room { public: - ArsanoMeetup3(SupernovaEngine *vm, GameManager *gm); + ArsanoMeetup3(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -329,7 +329,7 @@ private: // Axacuss class AxacussCell : public Room { public: - AxacussCell(SupernovaEngine *vm, GameManager *gm); + AxacussCell(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); virtual void animation(); @@ -338,28 +338,28 @@ public: class AxacussCorridor1 : public Room { public: - AxacussCorridor1(SupernovaEngine *vm, GameManager *gm); + AxacussCorridor1(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); }; class AxacussCorridor2 : public Room { public: - AxacussCorridor2(SupernovaEngine *vm, GameManager *gm); + AxacussCorridor2(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); }; class AxacussCorridor3 : public Room { public: - AxacussCorridor3(SupernovaEngine *vm, GameManager *gm); + AxacussCorridor3(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); }; class AxacussCorridor4 : public Room { public: - AxacussCorridor4(SupernovaEngine *vm, GameManager *gm); + AxacussCorridor4(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual void animation(); @@ -368,7 +368,7 @@ public: class AxacussCorridor5 : public Room { public: - AxacussCorridor5(SupernovaEngine *vm, GameManager *gm); + AxacussCorridor5(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -387,7 +387,7 @@ private: class AxacussCorridor6 : public Room { public: - AxacussCorridor6(SupernovaEngine *vm, GameManager *gm); + AxacussCorridor6(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -395,14 +395,14 @@ public: class AxacussCorridor7 : public Room { public: - AxacussCorridor7(SupernovaEngine *vm, GameManager *gm); + AxacussCorridor7(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); }; class AxacussCorridor8 : public Room { public: - AxacussCorridor8(SupernovaEngine *vm, GameManager *gm); + AxacussCorridor8(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -410,7 +410,7 @@ public: class AxacussCorridor9 : public Room { public: - AxacussCorridor9(SupernovaEngine *vm, GameManager *gm); + AxacussCorridor9(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -418,7 +418,7 @@ public: class AxacussBcorridor : public Room { public: - AxacussBcorridor(SupernovaEngine *vm, GameManager *gm); + AxacussBcorridor(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -426,7 +426,7 @@ public: class AxacussIntersection : public Room { public: - AxacussIntersection(SupernovaEngine *vm, GameManager *gm); + AxacussIntersection(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -436,7 +436,7 @@ private: class AxacussExit : public Room { public: - AxacussExit(SupernovaEngine *vm, GameManager *gm); + AxacussExit(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -446,35 +446,35 @@ private: class AxacussOffice1 : public Room { public: - AxacussOffice1(SupernovaEngine *vm, GameManager *gm); + AxacussOffice1(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class AxacussOffice2 : public Room { public: - AxacussOffice2(SupernovaEngine *vm, GameManager *gm); + AxacussOffice2(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class AxacussOffice3 : public Room { public: - AxacussOffice3(SupernovaEngine *vm, GameManager *gm); + AxacussOffice3(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class AxacussOffice4 : public Room { public: - AxacussOffice4(SupernovaEngine *vm, GameManager *gm); + AxacussOffice4(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class AxacussOffice5 : public Room { public: - AxacussOffice5(SupernovaEngine *vm, GameManager *gm); + AxacussOffice5(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual bool interact(Action verb, Object &obj1, Object &obj2); @@ -482,28 +482,28 @@ public: class AxacussElevator : public Room { public: - AxacussElevator(SupernovaEngine *vm, GameManager *gm); + AxacussElevator(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class AxacussStation : public Room { public: - AxacussStation(SupernovaEngine *vm, GameManager *gm); + AxacussStation(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class AxacussSign : public Room { public: - AxacussSign(SupernovaEngine *vm, GameManager *gm); + AxacussSign(SupernovaEngine *vm, GameManager1 *gm); virtual bool interact(Action verb, Object &obj1, Object &obj2); }; class Outro : public Room { public: - Outro(SupernovaEngine *vm, GameManager *gm); + Outro(SupernovaEngine *vm, GameManager1 *gm); virtual void onEntrance(); virtual void animation(); diff --git a/engines/supernova/state.cpp b/engines/supernova/state.cpp index a0c06a93de..3e0ba6132a 100644 --- a/engines/supernova/state.cpp +++ b/engines/supernova/state.cpp @@ -31,12 +31,12 @@ namespace Supernova { -bool GameManager::serialize(Common::WriteStream *out) { +bool GameManager1::serialize(Common::WriteStream *out) { if (out->err()) return false; // GameState - out->writeSint32LE(_state._time); + out->writeSint32LE(_time); out->writeSint32LE(_state._timeSleep); out->writeSint32LE(_state._timeAlarm); out->writeSint32LE(_state._eventTime); @@ -82,13 +82,12 @@ bool GameManager::serialize(Common::WriteStream *out) { return !out->err(); } - -bool GameManager::deserialize(Common::ReadStream *in, int version) { +bool GameManager1::deserialize(Common::ReadStream *in, int version) { if (in->err()) return false; // GameState - _state._time = in->readSint32LE(); + _time = in->readSint32LE(); _state._timeSleep = in->readSint32LE(); _state._timeAlarm = in->readSint32LE(); _state._eventTime = in->readSint32LE(); @@ -157,106 +156,6 @@ bool GameManager::deserialize(Common::ReadStream *in, int version) { return !in->err(); } -void Inventory::add(Object &obj) { - if (_numObjects < kMaxCarry) { - _inventory[_numObjects++] = &obj; - obj.setProperty(CARRIED); - } - - if (getSize() > _inventoryScroll + 8) { - _inventoryScroll = getSize() - 8; - _inventoryScroll += _inventoryScroll % 2; - } -} - -void Inventory::remove(Object &obj) { - for (int i = 0; i < _numObjects; ++i) { - if (_inventory[i] == &obj) { - if (_inventoryScroll >= 2 && getSize() % 2) - _inventoryScroll -= 2; - - --_numObjects; - while (i < _numObjects) { - _inventory[i] = _inventory[i + 1]; - ++i; - } - obj.disableProperty(CARRIED); - } - } -} - -void Inventory::clear() { - for (int i = 0; i < _numObjects; ++i) - _inventory[i]->disableProperty(CARRIED); - _numObjects = 0; - _inventoryScroll = 0; -} - -Object *Inventory::get(int index) const { - if (index < _numObjects) - return _inventory[index]; - - return _nullObject; -} - -Object *Inventory::get(ObjectId id) const { - for (int i = 0; i < _numObjects; ++i) { - if (_inventory[i]->_id == id) - return _inventory[i]; - } - - return _nullObject; -} - - -GuiElement::GuiElement() - : _isHighlighted(false) - , _bgColorNormal(kColorWhite25) - , _bgColorHighlighted(kColorWhite44) - , _bgColor(kColorWhite25) - , _textColorNormal(kColorGreen) - , _textColorHighlighted(kColorLightGreen) - , _textColor(kColorGreen) -{ - memset(_text, 0, sizeof(_text)); -} - -void GuiElement::setText(const char *text) { - strncpy(_text, text, sizeof(_text) - 1); -} - -void GuiElement::setTextPosition(int x, int y) { - _textPosition = Common::Point(x, y); -} - -void GuiElement::setSize(int x1, int y1, int x2, int y2) { - this->left = x1; - this->top = y1; - this->right = x2; - this->bottom = y2; - - _textPosition = Common::Point(x1 + 1, y1 + 1); -} - -void GuiElement::setColor(int bgColor, int textColor, int bgColorHighlighted, int textColorHightlighted) { - _bgColor = bgColor; - _textColor = textColor; - _bgColorNormal = bgColor; - _textColorNormal = textColor; - _bgColorHighlighted = bgColorHighlighted; - _textColorHighlighted = textColorHightlighted; -} - -void GuiElement::setHighlight(bool isHighlighted_) { - if (isHighlighted_) { - _bgColor = _bgColorHighlighted; - _textColor = _textColorHighlighted; - } else { - _bgColor = _bgColorNormal; - _textColor = _textColorNormal; - } -} - // Used by Look Watch (when it's fixed). Do not remove. static Common::String timeToString(int msec) { char s[9] = " 0:00:00"; @@ -277,32 +176,18 @@ static Common::String timeToString(int msec) { return Common::String(s); } -StringId GameManager::guiCommands[] = { - kStringCommandGo, kStringCommandLook, kStringCommandTake, kStringCommandOpen, kStringCommandClose, - kStringCommandPress, kStringCommandPull, kStringCommandUse, kStringCommandTalk, kStringCommandGive -}; - -StringId GameManager::guiStatusCommands[] = { - kStringStatusCommandGo, kStringStatusCommandLook, kStringStatusCommandTake, kStringStatusCommandOpen, kStringStatusCommandClose, - kStringStatusCommandPress, kStringStatusCommandPull, kStringStatusCommandUse, kStringStatusCommandTalk, kStringStatusCommandGive -}; - -GameManager::GameManager(SupernovaEngine *vm, Sound *sound) - : _inventory(&_nullObject, _inventoryScroll) - , _vm(vm) - , _sound(sound) - , _mouseClickType(Common::EVENT_INVALID) { +GameManager1::GameManager1(SupernovaEngine *vm, Sound *sound) + : GameManager(vm, sound) { initRooms(); changeRoom(INTRO); initState(); - initGui(); } -GameManager::~GameManager() { +GameManager1::~GameManager1() { destroyRooms(); } -void GameManager::destroyRooms() { +void GameManager1::destroyRooms() { delete _rooms[INTRO]; delete _rooms[CORRIDOR]; delete _rooms[HALL]; @@ -355,7 +240,7 @@ void GameManager::destroyRooms() { delete _rooms[OUTRO]; } -void GameManager::initState() { +void GameManager1::initState() { _currentInputObject = &_nullObject; _inputObject[0] = &_nullObject; _inputObject[1] = &_nullObject; @@ -384,7 +269,7 @@ void GameManager::initState() { _rowsStart[i] = 0; } - _state._time = ticksToMsec(916364); // 2 pm + _time = ticksToMsec(916364); // 2 pm _state._timeSleep = 0; _state._timeAlarm = ticksToMsec(458182); // 7 am _state._eventTime = kMaxTimerValue; @@ -411,7 +296,7 @@ void GameManager::initState() { _prevImgId = 0; } -void GameManager::initRooms() { +void GameManager1::initRooms() { _rooms[INTRO] = new Intro(_vm, this); _rooms[CORRIDOR] = new ShipCorridor(_vm, this); _rooms[HALL] = new ShipHall(_vm, this); @@ -464,58 +349,16 @@ void GameManager::initRooms() { _rooms[OUTRO] = new Outro(_vm, this); } -void GameManager::initGui() { - int cmdCount = ARRAYSIZE(_guiCommandButton); - int cmdAvailableSpace = 320 - (cmdCount - 1) * 2; - for (int i = 0; i < cmdCount; ++i) { - const Common::String &text = _vm->getGameString(guiCommands[i]); - cmdAvailableSpace -= Screen::textWidth(text); - } - - int commandButtonX = 0; - for (int i = 0; i < ARRAYSIZE(_guiCommandButton); ++i) { - const Common::String &text = _vm->getGameString(guiCommands[i]); - int width; - if (i < cmdCount - 1) { - int space = cmdAvailableSpace / (cmdCount - i); - cmdAvailableSpace -= space; - width = Screen::textWidth(text) + space; - } else - width = 320 - commandButtonX; - - _guiCommandButton[i].setSize(commandButtonX, 150, commandButtonX + width, 159); - _guiCommandButton[i].setText(text.c_str()); - _guiCommandButton[i].setColor(kColorWhite25, kColorDarkGreen, kColorWhite44, kColorGreen); - commandButtonX += width + 2; - } - - for (int i = 0; i < ARRAYSIZE(_guiInventory); ++i) { - int inventoryX = 136 * (i % 2); - int inventoryY = 161 + 10 * (i / 2); - - _guiInventory[i].setSize(inventoryX, inventoryY, inventoryX + 135, inventoryY + 9); - _guiInventory[i].setColor(kColorWhite25, kColorDarkRed, kColorWhite35, kColorRed); - } - _guiInventoryArrow[0].setSize(272, 161, 279, 180); - _guiInventoryArrow[0].setColor(kColorWhite25, kColorDarkRed, kColorWhite35, kColorRed); - _guiInventoryArrow[0].setText("\x82"); - _guiInventoryArrow[0].setTextPosition(273, 166); - _guiInventoryArrow[1].setSize(272, 181, 279, 200); - _guiInventoryArrow[1].setColor(kColorWhite25, kColorDarkRed, kColorWhite35, kColorRed); - _guiInventoryArrow[1].setText("\x83"); - _guiInventoryArrow[1].setTextPosition(273, 186); -} - -bool GameManager::canSaveGameStateCurrently() { +bool GameManager1::canSaveGameStateCurrently() { return _animationEnabled && _guiEnabled; } -void GameManager::updateEvents() { +void GameManager1::updateEvents() { handleTime(); if (_animationEnabled && !_vm->_screen->isMessageShown() && _animationTimer == 0) _currentRoom->animation(); - if (_state._eventCallback != kNoFn && _state._time >= _state._eventTime) { + if (_state._eventCallback != kNoFn && _time >= _state._eventTime) { _vm->_allowLoadGame = false; _vm->_allowSaveGame = false; _state._eventTime = kMaxTimerValue; @@ -539,13 +382,15 @@ void GameManager::updateEvents() { case kSearchStartFn: searchStartEvent(); break; + default: + break; //shouldn't happen } _vm->_allowLoadGame = true; _vm->_allowSaveGame = true; return; } - if (_state._alarmOn && _state._timeAlarm <= _state._time) { + if (_state._alarmOn && _state._timeAlarm <= _time) { _state._alarmOn = false; alarm(); return; @@ -580,261 +425,12 @@ void GameManager::updateEvents() { } } -void GameManager::processInput(Common::KeyState &state) { - _key = state; - - switch (state.keycode) { - case Common::KEYCODE_F1: - // help - _vm->showHelpScreen(); - break; - case Common::KEYCODE_F2: - // show game manual - _vm->showTextReader("msn.doc"); - break; - case Common::KEYCODE_F3: - // show game info - _vm->showTextReader("msn.inf"); - break; - case Common::KEYCODE_F4: - _vm->setTextSpeed(); - break; - case Common::KEYCODE_F5: - // load/save - break; - case Common::KEYCODE_x: - if (state.flags & Common::KBD_ALT) { - if (_vm->quitGameDialog()) - _vm->quitGame(); - } - break; - case Common::KEYCODE_d: - if (state.flags & Common::KBD_CTRL) - _vm->_console->attach(); - break; - default: - break; - } -} - -void GameManager::resetInputState() { - setObjectNull(_inputObject[0]); - setObjectNull(_inputObject[1]); - _inputVerb = ACTION_WALK; - _processInput = false; - _mouseClicked = false; - _keyPressed = false; - _key.reset(); - _mouseClickType = Common::EVENT_MOUSEMOVE; - - processInput(); -} - -void GameManager::processInput() { - enum { - onNone, - onObject, - onCmdButton, - onInventory, - onInventoryArrowUp, - onInventoryArrowDown - } mouseLocation; - - if (_mouseField >= 0 && _mouseField < 256) - mouseLocation = onObject; - else if (_mouseField >= 256 && _mouseField < 512) - mouseLocation = onCmdButton; - else if (_mouseField >= 512 && _mouseField < 768) - mouseLocation = onInventory; - else if (_mouseField == 768) - mouseLocation = onInventoryArrowUp; - else if (_mouseField == 769) - mouseLocation = onInventoryArrowDown; - else - mouseLocation = onNone; - - if (_mouseClickType == Common::EVENT_LBUTTONUP) { - if (_vm->_screen->isMessageShown()) { - // Hide the message and consume the event - _vm->removeMessage(); - if (mouseLocation != onCmdButton) - return; - } - - switch(mouseLocation) { - case onObject: - case onInventory: - // Fallthrough - if (_inputVerb == ACTION_GIVE || _inputVerb == ACTION_USE) { - if (isNullObject(_inputObject[0])) { - _inputObject[0] = _currentInputObject; - if (!_inputObject[0]->hasProperty(COMBINABLE)) - _processInput = true; - } else { - _inputObject[1] = _currentInputObject; - _processInput = true; - } - } else { - _inputObject[0] = _currentInputObject; - if (!isNullObject(_currentInputObject)) - _processInput = true; - } - break; - case onCmdButton: - resetInputState(); - _inputVerb = static_cast<Action>(_mouseField - 256); - break; - case onInventoryArrowUp: - if (_inventoryScroll >= 2) - _inventoryScroll -= 2; - break; - case onInventoryArrowDown: - if (_inventoryScroll < _inventory.getSize() - ARRAYSIZE(_guiInventory)) - _inventoryScroll += 2; - break; - case onNone: - break; - } - - } else if (_mouseClickType == Common::EVENT_RBUTTONUP) { - if (_vm->_screen->isMessageShown()) { - // Hide the message and consume the event - _vm->removeMessage(); - return; - } - - if (isNullObject(_currentInputObject)) - return; - - if (mouseLocation == onObject || mouseLocation == onInventory) { - _inputObject[0] = _currentInputObject; - ObjectTypes type = _inputObject[0]->_type; - if (type & OPENABLE) - _inputVerb = (type & OPENED) ? ACTION_CLOSE : ACTION_OPEN; - else if (type & PRESS) - _inputVerb = ACTION_PRESS; - else if (type & TALK) - _inputVerb = ACTION_TALK; - else - _inputVerb = ACTION_LOOK; - - _processInput = true; - } - - } else if (_mouseClickType == Common::EVENT_MOUSEMOVE) { - int field = -1; - int click = -1; - - if ((_mouseY >= _guiCommandButton[0].top) && (_mouseY <= _guiCommandButton[0].bottom)) { - /* command row */ - field = 9; - while (_mouseX < _guiCommandButton[field].left - 1) - field--; - field += 256; - } else if ((_mouseX >= 283) && (_mouseX <= 317) && (_mouseY >= 163) && (_mouseY <= 197)) { - /* exit box */ - field = _exitList[(_mouseX - 283) / 7 + 5 * ((_mouseY - 163) / 7)]; - } else if ((_mouseY >= 161) && (_mouseX <= 270)) { - /* inventory box */ - field = (_mouseX + 1) / 136 + ((_mouseY - 161) / 10) * 2; - if (field + _inventoryScroll < _inventory.getSize()) - field += 512; - else - field = -1; - } else if ((_mouseY >= 161) && (_mouseX >= 271) && (_mouseX < 279)) { - /* inventory arrows */ - field = (_mouseY > 180) ? 769 : 768; - } else { - /* normal item */ - for (int i = 0; (_currentRoom->getObject(i)->_id != INVALIDOBJECT) && - (field == -1) && i < kMaxObject; i++) { - click = _currentRoom->getObject(i)->_click; - const MSNImage *image = _vm->_screen->getCurrentImage(); - if (click != 255 && image) { - const MSNImage::ClickField *clickField = image->_clickField; - do { - if ((_mouseX >= clickField[click].x1) && (_mouseX <= clickField[click].x2) && - (_mouseY >= clickField[click].y1) && (_mouseY <= clickField[click].y2)) - field = i; - - click = clickField[click].next; - } while ((click != 0) && (field == -1)); - } - } - } - - if (_mouseField != field) { - switch (mouseLocation) { - case onInventoryArrowUp: - case onInventoryArrowDown: - // Fallthrough - _guiInventoryArrow[_mouseField - 768].setHighlight(false); - break; - case onInventory: - _guiInventory[_mouseField - 512].setHighlight(false); - break; - case onCmdButton: - _guiCommandButton[_mouseField - 256].setHighlight(false); - break; - case onObject: - case onNone: - // Fallthrough - break; - } - - setObjectNull(_currentInputObject); - - _mouseField = field; - if (_mouseField >= 0 && _mouseField < 256) - mouseLocation = onObject; - else if (_mouseField >= 256 && _mouseField < 512) - mouseLocation = onCmdButton; - else if (_mouseField >= 512 && _mouseField < 768) - mouseLocation = onInventory; - else if (_mouseField == 768) - mouseLocation = onInventoryArrowUp; - else if (_mouseField == 769) - mouseLocation = onInventoryArrowDown; - else - mouseLocation = onNone; - - switch (mouseLocation) { - case onInventoryArrowUp: - case onInventoryArrowDown: - // Fallthrough - _guiInventoryArrow[_mouseField - 768].setHighlight(true); - break; - case onInventory: - _guiInventory[_mouseField - 512].setHighlight(true); - _currentInputObject = _inventory.get(_mouseField - 512 + _inventoryScroll); - break; - case onCmdButton: - _guiCommandButton[_mouseField - 256].setHighlight(true); - break; - case onObject: - _currentInputObject = _currentRoom->getObject(_mouseField); - break; - case onNone: - break; - } - } - } -} - -void GameManager::setObjectNull(Object *&obj) { - obj = &_nullObject; -} - -bool GameManager::isNullObject(Object *obj) { - return obj == &_nullObject; -} - -void GameManager::corridorOnEntrance() { +void GameManager1::corridorOnEntrance() { if (_state._corridorSearch) busted(0); } -void GameManager::telomat(int nr) { +void GameManager1::telomat(int nr) { static Common::String name[8] = { "DR. ALAB HANSI", "ALAB HANSI", @@ -946,7 +542,7 @@ void GameManager::telomat(int nr) { waitOnInput(_messageDuration); _vm->removeMessage(); if ((_state._destination == 255) && !_rooms[BCORRIDOR]->isSectionVisible(7)) { - _state._eventTime = _state._time + ticksToMsec(150); + _state._eventTime = _time + ticksToMsec(150); _state._eventCallback = kGuardWalkFn; _state._origin = i; _state._destination = nr; @@ -996,19 +592,19 @@ void GameManager::telomat(int nr) { } while (true); } -void GameManager::startSearch() { +void GameManager1::startSearch() { if ((_currentRoom->getId() >= CORRIDOR1) && (_currentRoom->getId() <= BCORRIDOR)) busted(0); _state._corridorSearch = true; } -void GameManager::search(int time) { - _state._eventTime = _state._time + ticksToMsec(time); +void GameManager1::search(int time) { + _state._eventTime = _time + ticksToMsec(time); _state._eventCallback = kSearchStartFn; } -void GameManager::guardNoticed() { +void GameManager1::guardNoticed() { _vm->paletteFadeOut(); Room *r = _currentRoom; _currentRoom = _rooms[GUARD]; @@ -1028,7 +624,7 @@ void GameManager::guardNoticed() { drawMapExits(); } -void GameManager::busted(int i) { +void GameManager1::busted(int i) { if (i > 0) _vm->renderImage(i); if (i == 0) { @@ -1070,7 +666,7 @@ void GameManager::busted(int i) { shot(0, 0); } -void GameManager::novaScroll() { +void GameManager1::novaScroll() { static byte planet_f[6] = {0xeb,0xec,0xf0,0xed,0xf1,0xf2}; static byte nova_f[13] = {0xea,0xe9,0xf5,0xf3,0xf7,0xf4,0xf6, 0xf9,0xfb,0xfc,0xfd,0xfe,0xfa}; @@ -1112,7 +708,7 @@ void GameManager::novaScroll() { } } -void GameManager::supernovaEvent() { +void GameManager1::supernovaEvent() { _vm->removeMessage(); CursorMan.showMouse(false); if (_currentRoom->getId() <= CAVE) { @@ -1191,7 +787,7 @@ void GameManager::supernovaEvent() { CursorMan.showMouse(true); } -void GameManager::guardReturnedEvent() { +void GameManager1::guardReturnedEvent() { if (_currentRoom->getId() == GUARD) busted(-1); else if ((_currentRoom->getId() == CORRIDOR9) && (_currentRoom->isSectionVisible(27))) @@ -1208,7 +804,7 @@ void GameManager::guardReturnedEvent() { _rooms[CORRIDOR9]->getObject(1)->disableProperty(OPENED); } -void GameManager::walk(int imgId) { +void GameManager1::walk(int imgId) { if (_prevImgId) _vm->renderImage(_prevImgId + 128); _vm->renderImage(imgId); @@ -1216,7 +812,7 @@ void GameManager::walk(int imgId) { wait(3); } -void GameManager::guardWalkEvent() { +void GameManager1::guardWalkEvent() { _prevImgId = 0; bool behind = (!_rooms[BCORRIDOR]->getObject(_state._origin + 4)->hasProperty(OCCUPIED) || _rooms[BCORRIDOR]->getObject(_state._origin + 4)->hasProperty(OPENED)); @@ -1325,7 +921,7 @@ void GameManager::guardWalkEvent() { _vm->renderImage(_prevImgId + 128); _rooms[BCORRIDOR]->getObject(_state._destination + 4)->setProperty(OCCUPIED); SWAP(_state._origin, _state._destination); - _state._eventTime = _state._time + ticksToMsec(60); + _state._eventTime = _time + ticksToMsec(60); _state._eventCallback = kGuardWalkFn; } else { wait(18); @@ -1342,7 +938,7 @@ void GameManager::guardWalkEvent() { if (_currentRoom == _rooms[OFFICE_L1 + _state._destination]) busted(0); SWAP(_state._origin, _state._destination); - _state._eventTime = _state._time + ticksToMsec(60); + _state._eventTime = _time + ticksToMsec(60); _state._eventCallback = kGuardWalkFn; } else { SWAP(_state._origin, _state._destination); @@ -1350,7 +946,7 @@ void GameManager::guardWalkEvent() { } } -void GameManager::taxiEvent() { +void GameManager1::taxiEvent() { if (_currentRoom->getId() == SIGN) { changeRoom(STATION); _vm->renderRoom(*_currentRoom); @@ -1374,13 +970,13 @@ void GameManager::taxiEvent() { _rooms[SIGN]->setSectionVisible(3, true); } -void GameManager::searchStartEvent() { +void GameManager1::searchStartEvent() { if ((_currentRoom >= _rooms[CORRIDOR1]) && (_currentRoom <= _rooms[BCORRIDOR])) busted(0); _state._corridorSearch = true; } -void GameManager::great(uint number) { +void GameManager1::great(uint number) { if (number && (_state._greatFlag & (1 << number))) return; @@ -1388,7 +984,7 @@ void GameManager::great(uint number) { _state._greatFlag |= 1 << number; } -bool GameManager::airless() { +bool GameManager1::airless() { return (_currentRoom->getId() == HOLD || _currentRoom->getId() == LANDINGMODULE || _currentRoom->getId() == GENERATOR || @@ -1401,133 +997,7 @@ bool GameManager::airless() { (_currentRoom->getId() == AIRLOCK && _rooms[AIRLOCK]->getObject(1)->hasProperty(OPENED))); } -void GameManager::sentence(int number, bool brightness) { - if (number < 0) - return; - _vm->renderBox(0, 141 + _rowsStart[number] * 10, 320, _rows[number] * 10 - 1, brightness ? kColorWhite44 : kColorWhite25); - if (_texts[_rowsStart[number]] == kStringDialogSeparator) - _vm->renderText(kStringConversationEnd, 1, 142 + _rowsStart[number] * 10, brightness ? kColorRed : kColorDarkRed); - else { - for (int r = _rowsStart[number]; r < _rowsStart[number] + _rows[number]; ++r) - _vm->renderText(_texts[r], 1, 142 + r * 10, brightness ? kColorGreen : kColorDarkGreen); - } -} - -void GameManager::say(StringId textId) { - Common::String str = _vm->getGameString(textId); - if (!str.empty()) - say(str.c_str()); -} - -void GameManager::say(const char *text) { - Common::String t(text); - char *row[6]; - Common::String::iterator p = t.begin(); - uint numRows = 0; - while (*p) { - row[numRows++] = p; - while ((*p != '\0') && (*p != '|')) { - ++p; - } - if (*p == '|') { - *p = 0; - ++p; - } - } - - _vm->renderBox(0, 138, 320, 62, kColorBlack); - _vm->renderBox(0, 141, 320, numRows * 10 - 1, kColorWhite25); - for (uint r = 0; r < numRows; ++r) - _vm->renderText(row[r], 1, 142 + r * 10, kColorDarkGreen); - waitOnInput((t.size() + 20) * _vm->_textSpeed / 10); - _vm->renderBox(0, 138, 320, 62, kColorBlack); -} - -void GameManager::reply(StringId textId, int aus1, int aus2) { - Common::String str = _vm->getGameString(textId); - if (!str.empty()) - reply(str.c_str(), aus1, aus2); -} - -void GameManager::reply(const char *text, int aus1, int aus2) { - if (*text != '|') - _vm->renderMessage(text, kMessageTop); - - for (int z = (strlen(text) + 20) * _vm->_textSpeed / 40; z > 0; --z) { - _vm->renderImage(aus1); - waitOnInput(2); - if (_keyPressed || _mouseClicked) - z = 1; - _vm->renderImage(aus2); - waitOnInput(2); - if (_keyPressed || _mouseClicked) - z = 1; - } - if (*text != '|') - _vm->removeMessage(); -} - -int GameManager::dialog(int num, byte rowLength[6], StringId text[6], int number) { - _vm->_allowLoadGame = false; - _guiEnabled = false; - - bool remove[6]; - for (int i = 0; i < 5; ++i) - remove[i] = _currentRoom->sentenceRemoved(i, number); - // The original does not initialize remove[5]!!! - // Set it to false/0. But maybe the loop above should use 6 instead of 5? - remove[5] = false; - - _vm->renderBox(0, 138, 320, 62, kColorBlack); - - for (int i = 0; i < 6 ; ++i) - _sentenceNumber[i] = -1; - - int r = 0, rq = 0; - for (int i = 0; i < num; ++i) { - if (!remove[i]) { - _rowsStart[i] = r; - _rows[i] = rowLength[i]; - for (int j = 0; j < _rows[i]; ++j, ++r, ++rq) { - _texts[r] = text[rq]; - _sentenceNumber[r] = i; - } - sentence(i, false); - } else - rq += rowLength[i]; - } - - _currentSentence = -1; - do { - do { - updateEvents(); - mousePosDialog(_mouseX, _mouseY); - g_system->updateScreen(); - g_system->delayMillis(_vm->_delay); - } while (!_mouseClicked && !_vm->shouldQuit()); - } while (_currentSentence == -1 && !_vm->shouldQuit()); - - _vm->renderBox(0, 138, 320, 62, kColorBlack); - - if (number && _currentSentence != -1 && _texts[_rowsStart[_currentSentence]] != kStringDialogSeparator) - _currentRoom->removeSentence(_currentSentence, number); - - _guiEnabled = true; - _vm->_allowLoadGame = true; - - return _currentSentence; -} - -void GameManager::mousePosDialog(int x, int y) { - int a = y < 141 ? -1 : _sentenceNumber[(y - 141) / 10]; - if (a != _currentSentence) { - sentence(_currentSentence, false); - _currentSentence = a; - sentence(_currentSentence, true); - } -} - -void GameManager::turnOff() { +void GameManager1::turnOff() { if (_state._powerOff) return; @@ -1535,7 +1005,7 @@ void GameManager::turnOff() { roomBrightness(); } -void GameManager::turnOn() { +void GameManager1::turnOn() { if (!_state._powerOff) return; @@ -1546,80 +1016,7 @@ void GameManager::turnOn() { _rooms[COCKPIT]->setSectionVisible(22, false); } -void GameManager::takeObject(Object &obj) { - if (obj.hasProperty(CARRIED)) - return; - - if (obj._section != 0) - _vm->renderImage(obj._section); - obj._click = obj._click2 = 255; - _inventory.add(obj); -} - -void GameManager::drawCommandBox() { - for (int i = 0; i < ARRAYSIZE(_guiCommandButton); ++i) { - _vm->renderBox(_guiCommandButton[i]); - int space = (_guiCommandButton[i].width() - Screen::textWidth(_guiCommandButton[i].getText())) / 2; - _vm->renderText(_guiCommandButton[i].getText(), - _guiCommandButton[i].getTextPos().x + space, - _guiCommandButton[i].getTextPos().y, - _guiCommandButton[i].getTextColor()); - } -} - -void GameManager::drawInventory() { - for (int i = 0; i < ARRAYSIZE(_guiInventory); ++i) { - _vm->renderBox(_guiInventory[i]); - _vm->renderText(_inventory.get(i + _inventoryScroll)->_name, - _guiInventory[i].getTextPos().x, - _guiInventory[i].getTextPos().y, - _guiInventory[i].getTextColor()); - } - - _vm->renderBox(_guiInventoryArrow[0]); - _vm->renderBox(_guiInventoryArrow[1]); - if (_inventory.getSize() > ARRAYSIZE(_guiInventory)) { - if (_inventoryScroll != 0) - _vm->renderText(_guiInventoryArrow[0]); - if (_inventoryScroll + ARRAYSIZE(_guiInventory) < _inventory.getSize()) - _vm->renderText(_guiInventoryArrow[1]); - } -} - -int GameManager::getKeyInput() { - while (!_vm->shouldQuit()) { - updateEvents(); - if (_keyPressed) { - return _key.ascii; - } - g_system->updateScreen(); - g_system->delayMillis(_vm->_delay); - } - return 0; -} - -Common::EventType GameManager::getMouseInput() { - while (!_vm->shouldQuit()) { - updateEvents(); - if (_mouseClicked) - return _mouseClickType; - g_system->updateScreen(); - g_system->delayMillis(_vm->_delay); - } - return Common::EVENT_INVALID; -} - -void GameManager::getInput() { - while (!_vm->shouldQuit()) { - updateEvents(); - if (_mouseClicked || _keyPressed) - break; - g_system->updateScreen(); - g_system->delayMillis(_vm->_delay); - } -} - -void GameManager::roomBrightness() { +void GameManager1::roomBrightness() { _roomBrightness = 255; if ((_currentRoom->getId() != OUTSIDE) && (_currentRoom->getId() < ROCKS) && _state._powerOff) _roomBrightness = 153; @@ -1634,59 +1031,15 @@ void GameManager::roomBrightness() { _vm->paletteBrightness(); } -void GameManager::changeRoom(RoomId id) { - _currentRoom = _rooms[id]; - _newRoom = true; -} - -void GameManager::wait(int ticks) { - int32 end = _state._time + ticksToMsec(ticks); - do { - g_system->delayMillis(_vm->_delay); - updateEvents(); - g_system->updateScreen(); - } while (_state._time < end && !_vm->shouldQuit()); -} - -void GameManager::waitOnInput(int ticks) { - int32 end = _state._time + ticksToMsec(ticks); - do { - g_system->delayMillis(_vm->_delay); - updateEvents(); - g_system->updateScreen(); - } while (_state._time < end && !_vm->shouldQuit() && !_keyPressed && !_mouseClicked); -} - -bool GameManager::waitOnInput(int ticks, Common::KeyCode &keycode) { - keycode = Common::KEYCODE_INVALID; - int32 end = _state._time + ticksToMsec(ticks); - do { - g_system->delayMillis(_vm->_delay); - updateEvents(); - g_system->updateScreen(); - if (_keyPressed) { - keycode = _key.keycode; - _key.reset(); - return true; - } else if (_mouseClicked) - return true; - } while (_state._time < end && !_vm->shouldQuit()); - return false; -} - -void GameManager::setAnimationTimer(int ticks) { - _animationTimer = ticksToMsec(ticks); -} - -void GameManager::handleTime() { +void GameManager1::handleTime() { if (_timerPaused) return; int32 newTime = g_system->getMillis(); int32 delta = newTime - _oldTime; - _state._time += delta; - if (_state._time > 86400000) { - _state._time -= 86400000; // 24h wrap around - _state._alarmOn = (_state._timeAlarm > _state._time); + _time += delta; + if (_time > 86400000) { + _time -= 86400000; // 24h wrap around + _state._alarmOn = (_state._timeAlarm > _time); } if (_animationTimer > delta) _animationTimer -= delta; @@ -1696,52 +1049,20 @@ void GameManager::handleTime() { _oldTime = newTime; } -void GameManager::pauseTimer(bool pause) { - if (pause == _timerPaused) - return; - - if (pause) { - _timerPaused = true; - int32 delta = g_system->getMillis() - _oldTime; - _timePaused = _state._time + delta; - } else { - _state._time = _timePaused; - _oldTime = g_system->getMillis(); - _timerPaused = false; - } -} - -void GameManager::loadTime() { +void GameManager1::loadTime() { pauseTimer(false); } -void GameManager::saveTime() { +void GameManager1::saveTime() { pauseTimer(true); } -void GameManager::screenShake() { - for (int i = 0; i < 12; ++i) { - _vm->_system->setShakePos(8); - wait(1); - _vm->_system->setShakePos(0); - wait(1); - } -} - -void GameManager::shock() { +void GameManager1::shock() { _sound->play(kAudioShock); dead(kStringShock); } -void GameManager::showMenu() { - _vm->renderBox(0, 138, 320, 62, 0); - _vm->renderBox(0, 140, 320, 9, kColorWhite25); - drawCommandBox(); - _vm->renderBox(281, 161, 39, 39, kColorWhite25); - drawInventory(); -} - -void GameManager::drawMapExits() { +void GameManager1::drawMapExits() { // TODO: Preload _exitList on room entry instead on every call _vm->renderBox(281, 161, 39, 39, kColorWhite25); @@ -1758,83 +1079,7 @@ void GameManager::drawMapExits() { } } -void GameManager::animationOff() { - _animationEnabled = false; -} - -void GameManager::animationOn() { - _animationEnabled = true; -} - -void GameManager::edit(Common::String &input, int x, int y, uint length) { - bool isEditing = true; - uint cursorIndex = input.size(); - // NOTE: Pixels for char needed = kFontWidth + 2px left and right side bearing - int overdrawWidth = ((int)((length + 1) * (kFontWidth + 2)) > (kScreenWidth - x)) ? - kScreenWidth - x : (length + 1) * (kFontWidth + 2); - - while (isEditing) { - _vm->_screen->setTextCursorPos(x, y); - _vm->_screen->setTextCursorColor(kColorWhite99); - _vm->renderBox(x, y - 1, overdrawWidth, 9, kColorDarkBlue); - for (uint i = 0; i < input.size(); ++i) { - // Draw char highlight depending on cursor position - if (i == cursorIndex) { - _vm->renderBox(_vm->_screen->getTextCursorPos().x, y - 1, - Screen::textWidth(input[i]), 9, kColorWhite99); - _vm->_screen->setTextCursorColor(kColorDarkBlue); - _vm->renderText(input[i]); - _vm->_screen->setTextCursorColor(kColorWhite99); - } else - _vm->renderText(input[i]); - } - - if (cursorIndex == input.size()) { - _vm->renderBox(_vm->_screen->getTextCursorPos().x + 1, y - 1, 6, 9, kColorDarkBlue); - _vm->renderBox(_vm->_screen->getTextCursorPos().x, y - 1, 1, 9, kColorWhite99); - } - - getKeyInput(); - if (_vm->shouldQuit()) - break; - switch (_key.keycode) { - case Common::KEYCODE_RETURN: - case Common::KEYCODE_ESCAPE: - isEditing = false; - break; - case Common::KEYCODE_UP: - case Common::KEYCODE_DOWN: - cursorIndex = input.size(); - break; - case Common::KEYCODE_LEFT: - if (cursorIndex != 0) - --cursorIndex; - break; - case Common::KEYCODE_RIGHT: - if (cursorIndex != input.size()) - ++cursorIndex; - break; - case Common::KEYCODE_DELETE: - if (cursorIndex != input.size()) - input.deleteChar(cursorIndex); - break; - case Common::KEYCODE_BACKSPACE: - if (cursorIndex != 0) { - --cursorIndex; - input.deleteChar(cursorIndex); - } - break; - default: - if (Common::isPrint(_key.ascii) && input.size() < length) { - input.insertChar(_key.ascii, cursorIndex); - ++cursorIndex; - } - break; - } - } -} - -void GameManager::shot(int a, int b) { +void GameManager1::shot(int a, int b) { if (a) _vm->renderImage(a); _sound->play(kAudioGunShot); @@ -1852,7 +1097,7 @@ void GameManager::shot(int a, int b) { dead(kStringShot); } -void GameManager::takeMoney(int amount) { +void GameManager1::takeMoney(int amount) { Object *moneyObject = _rooms[INTRO]->getObject(4); _state._money += amount; _vm->setGameString(kStringInventoryMoney, Common::String::format("%d Xa", _state._money)); @@ -1866,32 +1111,14 @@ void GameManager::takeMoney(int amount) { } } -void GameManager::drawStatus() { - int index = static_cast<int>(_inputVerb); - _vm->renderBox(0, 140, 320, 9, kColorWhite25); - _vm->renderText(_vm->getGameString(guiStatusCommands[index]), 1, 141, kColorDarkGreen); - - if (isNullObject(_inputObject[0])) - _vm->renderText(_currentInputObject->_name); - else { - _vm->renderText(_inputObject[0]->_name); - if (_inputVerb == ACTION_GIVE) - _vm->renderText(kPhrasalVerbParticleGiveTo); - else if (_inputVerb == ACTION_USE) - _vm->renderText(kPhrasalVerbParticleUseWith); - - _vm->renderText(_currentInputObject->_name); - } -} - -void GameManager::openLocker(const Room *room, Object *obj, Object *lock, int section) { +void GameManager1::openLocker(const Room *room, Object *obj, Object *lock, int section) { _vm->renderImage(section); obj->setProperty(OPENED); lock->_click = 255; SWAP(obj->_click, obj->_click2); } -void GameManager::closeLocker(const Room *room, Object *obj, Object *lock, int section) { +void GameManager1::closeLocker(const Room *room, Object *obj, Object *lock, int section) { if (!obj->hasProperty(OPENED)) _vm->renderMessage(kStringCloseLocker_1); else { @@ -1902,40 +1129,7 @@ void GameManager::closeLocker(const Room *room, Object *obj, Object *lock, int s } } -void GameManager::dead(StringId messageId) { - _vm->paletteFadeOut(); - _guiEnabled = false; - _vm->setCurrentImage(11); - _vm->renderImage(0); - _vm->renderMessage(messageId); - _sound->play(kAudioDeath); - _vm->paletteFadeIn(); - getInput(); - _vm->paletteFadeOut(); - _vm->removeMessage(); - - destroyRooms(); - initRooms(); - initState(); - initGui(); - _inventory.clear(); - changeRoom(CABIN_R3); - g_system->fillScreen(kColorBlack); - _vm->paletteFadeIn(); - - _guiEnabled = true; -} - -int GameManager::invertSection(int section) { - if (section < 128) - section += 128; - else - section -= 128; - - return section; -} - -bool GameManager::isHelmetOff() { +bool GameManager1::isHelmetOff() { Object *helmet = _inventory.get(HELMET); if (helmet && helmet->hasProperty(WORN)) { _vm->renderMessage(kStringIsHelmetOff_1); @@ -1945,7 +1139,7 @@ bool GameManager::isHelmetOff() { return true; } -bool GameManager::genericInteract(Action verb, Object &obj1, Object &obj2) { +bool GameManager1::genericInteract(Action verb, Object &obj1, Object &obj2) { if ((verb == ACTION_USE) && (obj1._id == SCHNUCK)) { if (isHelmetOff()) { takeObject(obj1); @@ -2017,7 +1211,7 @@ bool GameManager::genericInteract(Action verb, Object &obj1, Object &obj2) { _vm->renderMessage(obj1._description); obj1._description = kStringKeycard2Description2; } else if ((verb == ACTION_LOOK) && (obj1._id == WATCH)) - _vm->renderMessage(kStringGenericInteract_13, kMessageNormal, timeToString(_state._time), timeToString(_state._timeAlarm)); + _vm->renderMessage(kStringGenericInteract_13, kMessageNormal, timeToString(_time), timeToString(_state._timeAlarm)); else if ((verb == ACTION_PRESS) && (obj1._id == WATCH)) { bool validInput = true; int hours = 0; @@ -2075,7 +1269,7 @@ bool GameManager::genericInteract(Action verb, Object &obj1, Object &obj2) { _vm->restoreScreen(); if (_key.keycode != Common::KEYCODE_ESCAPE) { _state._timeAlarm = (hours * 60 + minutes) * 60 * 1000; - _state._alarmOn = (_state._timeAlarm > _state._time); + _state._alarmOn = (_state._timeAlarm > _time); } } else if ((verb == ACTION_USE) && Object::combine(obj1, obj2, TERMINALSTRIP, WIRE)) { Room *r = _rooms[CABIN_L3]; @@ -2211,7 +1405,7 @@ bool GameManager::genericInteract(Action verb, Object &obj1, Object &obj2) { return true; } -void GameManager::handleInput() { +void GameManager1::handleInput() { bool validCommand = genericInteract(_inputVerb, *_inputObject[0], *_inputObject[1]); if (!validCommand) validCommand = _currentRoom->interact(_inputVerb, *_inputObject[0], *_inputObject[1]); @@ -2304,7 +1498,7 @@ void GameManager::handleInput() { } } -void GameManager::executeRoom() { +void GameManager1::executeRoom() { if (_processInput && !_vm->_screen->isMessageShown() && _guiEnabled) { handleInput(); if (_mouseClicked) { @@ -2341,7 +1535,7 @@ void GameManager::executeRoom() { } } -void GameManager::guardShot() { +void GameManager1::guardShot() { _vm->renderImage(2); _vm->renderImage(5); wait(3); @@ -2359,7 +1553,7 @@ void GameManager::guardShot() { shot(4, 3); } -void GameManager::guard3Shot() { +void GameManager1::guard3Shot() { _vm->renderImage(1); wait(3); _sound->play(kAudioVoiceHalt); // 46/0 @@ -2372,7 +1566,7 @@ void GameManager::guard3Shot() { shot(3,2); } -void GameManager::alarm() { +void GameManager1::alarm() { if (_rooms[INTRO]->getObject(2)->hasProperty(CARRIED)) { alarmSound(); if (_currentRoom->getId() == GUARD) @@ -2402,17 +1596,17 @@ void GameManager::alarm() { _rooms[GUARD]->setSectionVisible(7, true); _rooms[GUARD]->getObject(5)->_click = 4; } - _state._eventTime = _state._time + ticksToMsec(180); + _state._eventTime = _time + ticksToMsec(180); _state._eventCallback = kGuardReturnedFn; } } -void GameManager::alarmSound() { +void GameManager1::alarmSound() { animationOff(); _vm->removeMessage(); _vm->renderMessage(kStringAlarm); - int32 end = _state._time + ticksToMsec(_messageDuration); + int32 end = _time + ticksToMsec(_messageDuration); do { _sound->play(kAudioAlarm); while (_sound->isPlaying()) { @@ -2420,7 +1614,7 @@ void GameManager::alarmSound() { updateEvents(); g_system->updateScreen(); } - } while (_state._time < end && !_vm->shouldQuit()); + } while (_time < end && !_vm->shouldQuit()); _vm->removeMessage(); animationOn(); diff --git a/engines/supernova/state.h b/engines/supernova/state.h index f78f2191f5..51dab06f89 100644 --- a/engines/supernova/state.h +++ b/engines/supernova/state.h @@ -29,209 +29,73 @@ #include "common/keyboard.h" #include "supernova/rooms.h" #include "supernova/sound.h" +#include "supernova/game-manager.h" namespace Supernova { -const int32 kMaxTimerValue = 0x7FFFFFFF; - -enum EventFunction { kNoFn, kSupernovaFn, kGuardReturnedFn, kGuardWalkFn, kTaxiFn, kSearchStartFn }; - -struct GameState { - int32 _time; - int32 _timeSleep; - int32 _timeAlarm; - int32 _eventTime; - EventFunction _eventCallback; - int32 _arrivalDaysLeft; - int32 _shipEnergyDaysLeft; - int32 _landingModuleEnergyDaysLeft; - uint16 _greatFlag; - int16 _timeRobot; - int16 _money; - byte _coins; - byte _shoes; - byte _origin; - byte _destination; - byte _language; - bool _corridorSearch; - bool _alarmOn; - bool _terminalStripConnected; - bool _terminalStripWire; - bool _cableConnected; - bool _powerOff; - bool _dream; - bool _nameSeen[4]; - bool _playerHidden; -}; - -class Inventory { -public: - Inventory(Object *nullObject, int &inventoryScroll) - : _numObjects(0) - , _nullObject(nullObject) - , _inventoryScroll(inventoryScroll) { - for (int i = 0; i < kMaxCarry; ++i) - _inventory[i] = nullptr; - } - - void add(Object &obj); - void remove(Object &obj); - void clear(); - Object *get(int index) const; - Object *get(ObjectId id) const; - int getSize() const { return _numObjects; } - -private: - Object *_inventory[kMaxCarry]; - Object *_nullObject; - int &_inventoryScroll; - int _numObjects; +class GameManager; + +class GameState { + public: + int32 _timeSleep; + int32 _timeAlarm; + int32 _eventTime; + EventFunction _eventCallback; + int32 _arrivalDaysLeft; + int32 _shipEnergyDaysLeft; + int32 _landingModuleEnergyDaysLeft; + uint16 _greatFlag; + int16 _timeRobot; + int16 _money; + byte _coins; + byte _shoes; + byte _origin; + byte _destination; + byte _language; + bool _corridorSearch; + bool _alarmOn; + bool _terminalStripConnected; + bool _terminalStripWire; + bool _cableConnected; + bool _powerOff; + bool _dream; + bool _nameSeen[4]; + bool _playerHidden; }; -class GuiElement : public Common::Rect { +class GameManager1 : public GameManager { public: - GuiElement(); - - void setSize(int x1, int y1, int x2, int y2); - void setText(const char *text); - void setTextPosition(int x, int y); - void setColor(int bgColor, int textColor, int bgColorHighlighted, int textColorHightlighted); - void setHighlight(bool isHighlighted); - - const char *getText() const { - return _text; - } - int getBackgroundColor() const { - return _bgColor; - } - int getTextColor() const { - return _textColor; - } - const Common::Point &getTextPos() const { - return _textPosition; - } - bool isHighlighted() const { - return _isHighlighted; - } - -private: - Common::Point _textPosition; - char _text[128]; - int _bgColor; - int _textColor; - int _bgColorNormal; - int _bgColorHighlighted; - int _textColorNormal; - int _textColorHighlighted; - bool _isHighlighted; -}; - -class GameManager { -public: - GameManager(SupernovaEngine *vm, Sound *sound); - ~GameManager(); - - void updateEvents(); - void processInput(Common::KeyState &state); - void processInput(); - void executeRoom(); - bool serialize(Common::WriteStream *out); - bool deserialize(Common::ReadStream *in, int version); + GameManager1(SupernovaEngine *vm, Sound *sound); + virtual ~GameManager1(); - static StringId guiCommands[]; - static StringId guiStatusCommands[]; - SupernovaEngine *_vm; - Sound *_sound; - Common::KeyState _key; - Common::EventType _mouseClickType; - bool _mouseClicked; - bool _keyPressed; - int _mouseX; - int _mouseY; - int _mouseField; - Room *_currentRoom; - bool _newRoom; - Room *_rooms[NUMROOMS]; - Inventory _inventory; GameState _state; - bool _processInput; - bool _guiEnabled; - bool _animationEnabled; - byte _roomBrightness; - Action _inputVerb; - Object _nullObject; - Object *_currentInputObject; - Object *_inputObject[2]; - int32 _oldTime; - uint _timePaused; - bool _timerPaused; - int32 _messageDuration; - int32 _animationTimer; - int _inventoryScroll; - int _exitList[25]; - GuiElement _guiCommandButton[10]; - GuiElement _guiInventory[8]; - GuiElement _guiInventoryArrow[2]; - // Dialog - int _currentSentence; - int _sentenceNumber[6]; - StringId _texts[6]; - byte _rows[6]; - byte _rowsStart[6]; - void takeObject(Object &obj); - void setObjectNull(Object *&obj); - bool isNullObject(Object *obj); + virtual void updateEvents(); + virtual void executeRoom(); + virtual bool serialize(Common::WriteStream *out); + virtual bool deserialize(Common::ReadStream *in, int version); - void initState(); - void initRooms(); - void destroyRooms(); - void initGui(); - bool canSaveGameStateCurrently(); - bool genericInteract(Action verb, Object &obj1, Object &obj2); + virtual void initState(); + virtual void initRooms(); + virtual void destroyRooms(); + virtual bool canSaveGameStateCurrently(); + virtual bool genericInteract(Action verb, Object &obj1, Object &obj2); bool isHelmetOff(); void great(uint number); bool airless(); void shock(); - Common::EventType getMouseInput(); - int getKeyInput(); - void getInput(); - void wait(int ticks); - void waitOnInput(int ticks); - bool waitOnInput(int ticks, Common::KeyCode &keycode); void turnOff(); void turnOn(); - void screenShake(); - void roomBrightness(); - void showMenu(); - void animationOff(); - void animationOn(); + virtual void roomBrightness(); void openLocker(const Room *room, Object *obj, Object *lock, int section); void closeLocker(const Room *room, Object *obj, Object *lock, int section); - void edit(Common::String &input, int x, int y, uint length); - int invertSection(int section); - void drawMapExits(); - void drawStatus(); - void drawCommandBox(); - void drawInventory(); - void changeRoom(RoomId id); - void resetInputState(); - void handleInput(); - void handleTime(); - void pauseTimer(bool pause); - void loadTime(); - void saveTime(); - void setAnimationTimer(int ticks); - void dead(StringId messageId); - int dialog(int num, byte rowLength[6], StringId text[6], int number); - void sentence(int number, bool brightness); - void say(StringId textId); - void say(const char *text); - void reply(StringId textId, int aus1, int aus2); - void reply(const char *text, int aus1, int aus2); - void mousePosDialog(int x, int y); + virtual void drawMapExits(); + virtual void handleInput(); + virtual void handleTime(); + virtual void loadTime(); + virtual void saveTime(); void shot(int a, int b); - void takeMoney(int amount); + virtual void takeMoney(int amount); void search(int time); void startSearch(); void guardNoticed(); diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp index c07edfadba..79d64cdf5d 100644 --- a/engines/supernova/supernova.cpp +++ b/engines/supernova/supernova.cpp @@ -46,6 +46,7 @@ #include "supernova/sound.h" #include "supernova/supernova.h" #include "supernova/state.h" +#include "supernova/game-manager.h" namespace Supernova { @@ -141,7 +142,8 @@ void SupernovaEngine::init() { _resMan = new ResourceManager(_MSPart); _sound = new Sound(_mixer, _resMan); - _gm = new GameManager(this, _sound); + if (_MSPart == 1) + _gm = new GameManager1(this, _sound); _screen = new Screen(this, _resMan); _console = new Console(this, _gm); diff --git a/engines/supernova/supernova.h b/engines/supernova/supernova.h index afdcf1ccef..9655d005bf 100644 --- a/engines/supernova/supernova.h +++ b/engines/supernova/supernova.h @@ -36,6 +36,7 @@ #include "supernova/rooms.h" #include "supernova/sound.h" #include "supernova/imageid.h" +#include "supernova/game-manager.h" namespace Common { class MemoryReadWriteStream; @@ -58,6 +59,7 @@ class ResourceManager; class Sound; class console; class GameManager; +class GameManager1; class Screen; class SupernovaEngine : public Engine { |