aboutsummaryrefslogtreecommitdiff
path: root/engines/zvision/core/events.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/zvision/core/events.cpp')
-rw-r--r--engines/zvision/core/events.cpp259
1 files changed, 208 insertions, 51 deletions
diff --git a/engines/zvision/core/events.cpp b/engines/zvision/core/events.cpp
index 83d6c17dec..873cdb0df7 100644
--- a/engines/zvision/core/events.cpp
+++ b/engines/zvision/core/events.cpp
@@ -8,12 +8,12 @@
* 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.
@@ -29,6 +29,10 @@
#include "zvision/graphics/render_manager.h"
#include "zvision/scripting/script_manager.h"
#include "zvision/animation/rlf_animation.h"
+#include "zvision/core/menu.h"
+#include "zvision/utility/win_keys.h"
+#include "zvision/core/menu.h"
+#include "zvision/sound/zork_raw.h"
#include "common/events.h"
#include "common/system.h"
@@ -39,26 +43,146 @@
namespace ZVision {
+void ZVision::shortKeys(Common::Event event) {
+ if (event.kbd.hasFlags(Common::KBD_CTRL)) {
+ switch (event.kbd.keycode) {
+ case Common::KEYCODE_s:
+ if (getMenuBarEnable() & menuBar_Save)
+ _scriptManager->changeLocation('g', 'j', 's', 'e', 0);
+ break;
+ case Common::KEYCODE_r:
+ if (getMenuBarEnable() & menuBar_Restore)
+ _scriptManager->changeLocation('g', 'j', 'r', 'e', 0);
+ break;
+ case Common::KEYCODE_p:
+ if (getMenuBarEnable() & menuBar_Settings)
+ _scriptManager->changeLocation('g', 'j', 'p', 'e', 0);
+ break;
+ case Common::KEYCODE_q:
+ if (getMenuBarEnable() & menuBar_Exit)
+ ifQuit();
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+void ZVision::cheatCodes(uint8 key) {
+ pushKeyToCheatBuf(key);
+
+ if (getGameId() == GID_GRANDINQUISITOR) {
+
+ if (checkCode("IMNOTDEAF")) {
+ // Unknow cheat
+ showDebugMsg(Common::String::format("IMNOTDEAF cheat or debug, not implemented"));
+ }
+
+ if (checkCode("3100OPB")) {
+ showDebugMsg(Common::String::format("Current location: %c%c%c%c",
+ _scriptManager->getStateValue(StateKey_World),
+ _scriptManager->getStateValue(StateKey_Room),
+ _scriptManager->getStateValue(StateKey_Node),
+ _scriptManager->getStateValue(StateKey_View)));
+ }
+
+ if (checkCode("KILLMENOW")) {
+ _scriptManager->changeLocation('g', 'j', 'd', 'e', 0);
+ _scriptManager->setStateValue(2201, 35);
+ }
+
+ if (checkCode("MIKESPANTS")) {
+ _scriptManager->changeLocation('g', 'j', 't', 'm', 0);
+ }
+ } else if (getGameId() == GID_NEMESIS) {
+
+ if (checkCode("CHLOE")) {
+ _scriptManager->changeLocation('t', 'm', '2', 'g', 0);
+ _scriptManager->setStateValue(224, 1);
+ }
+
+ if (checkCode("77MASSAVE")) {
+ showDebugMsg(Common::String::format("Current location: %c%c%c%c",
+ _scriptManager->getStateValue(StateKey_World),
+ _scriptManager->getStateValue(StateKey_Room),
+ _scriptManager->getStateValue(StateKey_Node),
+ _scriptManager->getStateValue(StateKey_View)));
+ }
+
+ if (checkCode("IDKFA")) {
+ _scriptManager->changeLocation('t', 'w', '3', 'f', 0);
+ _scriptManager->setStateValue(249, 1);
+ }
+
+ if (checkCode("309NEWDORMA")) {
+ _scriptManager->changeLocation('g', 'j', 'g', 'j', 0);
+ }
+
+ if (checkCode("HELLOSAILOR")) {
+ Location loc = _scriptManager->getCurrentLocation();
+ Audio::AudioStream *soundStream;
+ if (loc.world == 'v' && loc.room == 'b' && loc.node == '1' && loc.view == '0') {
+ soundStream = makeRawZorkStream("v000hpta.raw", this);
+ } else {
+ soundStream = makeRawZorkStream("v000hnta.raw", this);
+ }
+ Audio::SoundHandle handle;
+ _mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream);
+ }
+ }
+
+ if (checkCode("FRAME"))
+ showDebugMsg(Common::String::format("FPS: ???, not implemented"));
+
+ if (checkCode("XYZZY"))
+ _scriptManager->setStateValue(StateKey_DebugCheats, 1 - _scriptManager->getStateValue(StateKey_DebugCheats));
+
+ if (checkCode("COMPUTERARCH"))
+ showDebugMsg(Common::String::format("COMPUTERARCH: var-viewer not implemented"));
+
+ if (_scriptManager->getStateValue(StateKey_DebugCheats) == 1)
+ if (checkCode("GO????"))
+ _scriptManager->changeLocation(getBufferedKey(3),
+ getBufferedKey(2),
+ getBufferedKey(1),
+ getBufferedKey(0), 0);
+}
+
void ZVision::processEvents() {
while (_eventMan->pollEvent(_event)) {
switch (_event.type) {
case Common::EVENT_LBUTTONDOWN:
- onMouseDown(_event.mouse);
+ _cursorManager->cursorDown(true);
+ _scriptManager->setStateValue(StateKey_LMouse, 1);
+ _menu->onMouseDown(_event.mouse);
+ _scriptManager->addEvent(_event);
break;
case Common::EVENT_LBUTTONUP:
- onMouseUp(_event.mouse);
+ _cursorManager->cursorDown(false);
+ _scriptManager->setStateValue(StateKey_LMouse, 0);
+ _menu->onMouseUp(_event.mouse);
+ _scriptManager->addEvent(_event);
break;
case Common::EVENT_RBUTTONDOWN:
- // TODO: Inventory logic
+ _cursorManager->cursorDown(true);
+ _scriptManager->setStateValue(StateKey_RMouse, 1);
+
+ if (getGameId() == GID_NEMESIS)
+ _scriptManager->inventoryCycle();
+ break;
+
+ case Common::EVENT_RBUTTONUP:
+ _cursorManager->cursorDown(false);
+ _scriptManager->setStateValue(StateKey_RMouse, 0);
break;
case Common::EVENT_MOUSEMOVE:
onMouseMove(_event.mouse);
break;
- case Common::EVENT_KEYDOWN:
+ case Common::EVENT_KEYDOWN: {
switch (_event.kbd.keycode) {
case Common::KEYCODE_d:
if (_event.kbd.hasFlags(Common::KBD_CTRL)) {
@@ -67,18 +191,52 @@ void ZVision::processEvents() {
_console->onFrame();
}
break;
- case Common::KEYCODE_q:
- if (_event.kbd.hasFlags(Common::KBD_CTRL))
- quitGame();
+
+ case Common::KEYCODE_LEFT:
+ case Common::KEYCODE_RIGHT:
+ if (_renderManager->getRenderTable()->getRenderState() == RenderTable::PANORAMA)
+ _kbdVelocity = (_event.kbd.keycode == Common::KEYCODE_LEFT ?
+ -_scriptManager->getStateValue(StateKey_KbdRotateSpeed) :
+ _scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2;
+ break;
+
+ case Common::KEYCODE_UP:
+ case Common::KEYCODE_DOWN:
+ if (_renderManager->getRenderTable()->getRenderState() == RenderTable::TILT)
+ _kbdVelocity = (_event.kbd.keycode == Common::KEYCODE_UP ?
+ -_scriptManager->getStateValue(StateKey_KbdRotateSpeed) :
+ _scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2;
break;
+
default:
break;
}
- _scriptManager->onKeyDown(_event.kbd);
- break;
+ uint8 vkKey = VKkey(_event.kbd.keycode);
+
+ _scriptManager->setStateValue(StateKey_KeyPress, vkKey);
+
+ _scriptManager->addEvent(_event);
+ shortKeys(_event);
+ cheatCodes(vkKey);
+ }
+ break;
case Common::EVENT_KEYUP:
- _scriptManager->onKeyUp(_event.kbd);
+ _scriptManager->addEvent(_event);
+ switch (_event.kbd.keycode) {
+ case Common::KEYCODE_LEFT:
+ case Common::KEYCODE_RIGHT:
+ if (_renderManager->getRenderTable()->getRenderState() == RenderTable::PANORAMA)
+ _kbdVelocity = 0;
+ break;
+ case Common::KEYCODE_UP:
+ case Common::KEYCODE_DOWN:
+ if (_renderManager->getRenderTable()->getRenderState() == RenderTable::TILT)
+ _kbdVelocity = 0;
+ break;
+ default:
+ break;
+ }
break;
default:
break;
@@ -86,24 +244,11 @@ void ZVision::processEvents() {
}
}
-void ZVision::onMouseDown(const Common::Point &pos) {
- _cursorManager->cursorDown(true);
-
- Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos));
- _scriptManager->onMouseDown(pos, imageCoord);
-}
-
-void ZVision::onMouseUp(const Common::Point &pos) {
- _cursorManager->cursorDown(false);
-
- Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos));
- _scriptManager->onMouseUp(pos, imageCoord);
-}
-
void ZVision::onMouseMove(const Common::Point &pos) {
+ _menu->onMouseMove(pos);
Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos));
- bool cursorWasChanged = _scriptManager->onMouseMove(pos, imageCoord);
+ bool cursorWasChanged = false;
// Graph of the function governing rotation velocity:
//
@@ -136,50 +281,62 @@ void ZVision::onMouseMove(const Common::Point &pos) {
// ^
if (_workingWindow.contains(pos)) {
+ cursorWasChanged = _scriptManager->onMouseMove(pos, imageCoord);
+
RenderTable::RenderState renderState = _renderManager->getRenderTable()->getRenderState();
if (renderState == RenderTable::PANORAMA) {
if (pos.x >= _workingWindow.left && pos.x < _workingWindow.left + ROTATION_SCREEN_EDGE_OFFSET) {
- // Linear function of distance to the left edge (y = -mx + b)
- // We use fixed point math to get better accuracy
- Common::Rational velocity = (Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.x - _workingWindow.left)) - MAX_ROTATION_SPEED;
- _renderManager->setBackgroundVelocity(velocity.toInt());
- _cursorManager->setLeftCursor();
+
+ int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4;
+ if (mspeed <= 0)
+ mspeed = 400 >> 4;
+ _mouseVelocity = (((pos.x - (ROTATION_SCREEN_EDGE_OFFSET + _workingWindow.left)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;
+
+ _cursorManager->changeCursor(CursorIndex_Left);
cursorWasChanged = true;
} else if (pos.x <= _workingWindow.right && pos.x > _workingWindow.right - ROTATION_SCREEN_EDGE_OFFSET) {
- // Linear function of distance to the right edge (y = mx)
- // We use fixed point math to get better accuracy
- Common::Rational velocity = Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.x - _workingWindow.right + ROTATION_SCREEN_EDGE_OFFSET);
- _renderManager->setBackgroundVelocity(velocity.toInt());
- _cursorManager->setRightCursor();
+
+ int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4;
+ if (mspeed <= 0)
+ mspeed = 400 >> 4;
+ _mouseVelocity = (((pos.x - (_workingWindow.right - ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;
+
+ _cursorManager->changeCursor(CursorIndex_Right);
cursorWasChanged = true;
} else {
- _renderManager->setBackgroundVelocity(0);
+ _mouseVelocity = 0;
}
} else if (renderState == RenderTable::TILT) {
if (pos.y >= _workingWindow.top && pos.y < _workingWindow.top + ROTATION_SCREEN_EDGE_OFFSET) {
- // Linear function of distance to top edge
- // We use fixed point math to get better accuracy
- Common::Rational velocity = (Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.y - _workingWindow.top)) - MAX_ROTATION_SPEED;
- _renderManager->setBackgroundVelocity(velocity.toInt());
- _cursorManager->setUpCursor();
+
+ int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4;
+ if (mspeed <= 0)
+ mspeed = 400 >> 4;
+ _mouseVelocity = (((pos.y - (_workingWindow.top + ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;
+
+ _cursorManager->changeCursor(CursorIndex_UpArr);
cursorWasChanged = true;
} else if (pos.y <= _workingWindow.bottom && pos.y > _workingWindow.bottom - ROTATION_SCREEN_EDGE_OFFSET) {
- // Linear function of distance to the bottom edge (y = mx)
- // We use fixed point math to get better accuracy
- Common::Rational velocity = Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.y - _workingWindow.bottom + ROTATION_SCREEN_EDGE_OFFSET);
- _renderManager->setBackgroundVelocity(velocity.toInt());
- _cursorManager->setDownCursor();
+
+ int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4;
+ if (mspeed <= 0)
+ mspeed = 400 >> 4;
+ _mouseVelocity = (((pos.y - (_workingWindow.bottom - ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;
+
+ _cursorManager->changeCursor(CursorIndex_DownArr);
cursorWasChanged = true;
} else {
- _renderManager->setBackgroundVelocity(0);
+ _mouseVelocity = 0;
}
+ } else {
+ _mouseVelocity = 0;
}
} else {
- _renderManager->setBackgroundVelocity(0);
+ _mouseVelocity = 0;
}
if (!cursorWasChanged) {
- _cursorManager->revertToIdle();
+ _cursorManager->changeCursor(CursorIndex_Idle);
}
}