aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMarisa-Chan2013-12-24 15:11:39 +0700
committerMarisa-Chan2013-12-24 15:11:39 +0700
commit0c7d1d2d3691f93701e33f40cb665d87004e5499 (patch)
tree1663190d707801a4c611d5f883b1b9c0e935d9fb /engines
parentfd325d49f9103408f7d2fc10cc99dae7fab9a0a1 (diff)
downloadscummvm-rg350-0c7d1d2d3691f93701e33f40cb665d87004e5499.tar.gz
scummvm-rg350-0c7d1d2d3691f93701e33f40cb665d87004e5499.tar.bz2
scummvm-rg350-0c7d1d2d3691f93701e33f40cb665d87004e5499.zip
ZVISION: Slot control code.
Diffstat (limited to 'engines')
-rw-r--r--engines/zvision/module.mk3
-rw-r--r--engines/zvision/scr_file_handling.cpp3
-rw-r--r--engines/zvision/slot_control.cpp215
-rw-r--r--engines/zvision/slot_control.h86
4 files changed, 306 insertions, 1 deletions
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index ffdef16335..b5512636c3 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -32,7 +32,8 @@ MODULE_OBJS := \
zork_raw.o \
sidefx.o \
music_node.o \
- inventory_manager.o
+ inventory_manager.o \
+ slot_control.o
MODULE_DIRS += \
engines/zvision
diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp
index f80700cc0d..4f1c3631bd 100644
--- a/engines/zvision/scr_file_handling.cpp
+++ b/engines/zvision/scr_file_handling.cpp
@@ -29,6 +29,7 @@
#include "zvision/actions.h"
#include "zvision/push_toggle_control.h"
#include "zvision/lever_control.h"
+#include "zvision/slot_control.h"
#include "common/textconsole.h"
#include "common/file.h"
@@ -342,6 +343,8 @@ Control *ScriptManager::parseControl(Common::String &line, Common::SeekableReadS
return NULL;
} else if (controlType.equalsIgnoreCase("lever")) {
return new LeverControl(_engine, key, stream);
+ } else if (controlType.equalsIgnoreCase("slot")) {
+ return new SlotControl(_engine, key, stream);
}
return NULL;
}
diff --git a/engines/zvision/slot_control.cpp b/engines/zvision/slot_control.cpp
new file mode 100644
index 0000000000..418aa8fad2
--- /dev/null
+++ b/engines/zvision/slot_control.cpp
@@ -0,0 +1,215 @@
+/* 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/scummsys.h"
+
+#include "zvision/slot_control.h"
+
+#include "zvision/zvision.h"
+#include "zvision/script_manager.h"
+#include "zvision/cursor_manager.h"
+#include "zvision/render_manager.h"
+#include "zvision/utility.h"
+
+#include "common/stream.h"
+
+
+namespace ZVision {
+
+SlotControl::SlotControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream)
+ : Control(engine, key) {
+
+ _rendered_item = 0;
+ _bkg = NULL;
+
+ // Loop until we find the closing brace
+ Common::String line = stream.readLine();
+ trimCommentsAndWhiteSpace(&line);
+ Common::String param;
+ Common::String values;
+ getParams(line, param, values);
+
+ while (!stream.eos() && !line.contains('}')) {
+ if (param.matchString("hotspot", true)) {
+ int x;
+ int y;
+ int width;
+ int height;
+
+ sscanf(values.c_str(), "%d %d %d %d", &x, &y, &width, &height);
+
+ _hotspot = Common::Rect(x, y, width, height);
+ } else if (param.matchString("rectangle", true)) {
+ int x;
+ int y;
+ int width;
+ int height;
+
+ sscanf(values.c_str(), "%d %d %d %d", &x, &y, &width, &height);
+
+ _rectangle = Common::Rect(x, y, width, height);
+ } else if (param.matchString("cursor", true)) {
+ _cursor = _engine->getCursorManager()->getCursorId(values);
+ } else if (param.matchString("distance_id", true)) {
+ sscanf(values.c_str(), "%c", &_distance_id);
+ } else if (param.matchString("venus_id", true)) {
+ _venus_id = atoi(values.c_str());
+ } else if (param.matchString("eligible_objects", true)) {
+ char buf[256];
+ memset(buf, 0, 256);
+ strcpy(buf, values.c_str());
+
+ char *curpos = buf;
+ char *strend = buf + strlen(buf);
+ while (true) {
+ char *st = curpos;
+
+ if (st >= strend)
+ break;
+
+ while (*curpos != ' ' && curpos < strend)
+ curpos++;
+
+ *curpos = 0;
+ curpos++;
+
+ int obj = atoi(st);
+
+ _eligible_objects.push_back(obj);
+ }
+ }
+
+ line = stream.readLine();
+ trimCommentsAndWhiteSpace(&line);
+ getParams(line, param, values);
+ }
+
+ if (_hotspot.isEmpty() || _rectangle.isEmpty()) {
+ warning("Slot %u was parsed incorrectly", key);
+ }
+}
+
+SlotControl::~SlotControl() {
+ // Clear the state value back to 0
+ //_engine->getScriptManager()->setStateValue(_key, 0);
+
+ if (_bkg)
+ delete _bkg;
+}
+
+bool SlotControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) {
+ if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
+ return false;
+
+ if (_hotspot.contains(backgroundImageSpacePos)) {
+ //ctrl_setvenus(ct);
+
+ int item = _engine->getScriptManager()->getStateValue(_key);
+ int mouse_item = _engine->getScriptManager()->getStateValue(StateKey_InventoryItem);
+ if (item != 0) {
+ if (mouse_item != 0) {
+ if (eligeblity(mouse_item)) {
+ _engine->getScriptManager()->invertory_drop(mouse_item);
+ _engine->getScriptManager()->invertory_add(item);
+ _engine->getScriptManager()->setStateValue(_key, mouse_item);
+ }
+ } else {
+ _engine->getScriptManager()->invertory_add(item);
+ _engine->getScriptManager()->setStateValue(_key, 0);
+ }
+ } else if (mouse_item == 0) {
+ if (eligeblity(0)) {
+ _engine->getScriptManager()->invertory_drop(0);
+ _engine->getScriptManager()->setStateValue(_key, 0);
+ }
+ } else if (eligeblity(mouse_item)) {
+ _engine->getScriptManager()->setStateValue(_key, mouse_item);
+ _engine->getScriptManager()->invertory_drop(mouse_item);
+ }
+ }
+ return false;
+}
+
+bool SlotControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) {
+ if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
+ return false;
+
+ if (_hotspot.contains(backgroundImageSpacePos)) {
+ _engine->getCursorManager()->changeCursor(_cursor);
+ return true;
+ }
+
+ return false;
+}
+
+bool SlotControl::process(uint32 deltaTimeInMillis) {
+ if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
+ return false;
+
+ if (_engine->canRender()) {
+ int cur_item = _engine->getScriptManager()->getStateValue(_key);
+ if (cur_item != _rendered_item) {
+ if (_rendered_item == 0) {
+ if (_bkg)
+ delete _bkg;
+
+ _bkg = _engine->getRenderManager()->getBkgRect(_rectangle);
+
+ char buf[16];
+ if (_engine->getGameId() == GID_NEMESIS)
+ sprintf(buf, "%d%cobj.tga", cur_item, _distance_id);
+ else
+ sprintf(buf, "g0z%cu%2.2x1.tga", _distance_id, cur_item);
+
+ Graphics::Surface *srf = _engine->getRenderManager()->loadImage(buf);
+
+ int16 drawx = _rectangle.left;
+ int16 drawy = _rectangle.top;
+
+ if (_rectangle.width() > srf->w)
+ drawx = _rectangle.left + (_rectangle.width() - srf->w) / 2;
+
+ if (_rectangle.height() > srf->h)
+ drawy = _rectangle.top + (_rectangle.height() - srf->h) / 2;
+
+ _engine->getRenderManager()->blitSurfaceToBkg(*srf, drawx, drawy, 0);
+
+ delete srf;
+
+ _rendered_item = cur_item;
+ } else {
+ _engine->getRenderManager()->blitSurfaceToBkg(*_bkg, _rectangle.left, _rectangle.top);
+ _rendered_item = cur_item;
+ }
+ }
+ }
+ return false;
+}
+
+bool SlotControl::eligeblity(int item_id) {
+ for (Common::List<int>::iterator it = _eligible_objects.begin(); it != _eligible_objects.end(); it++)
+ if (*it == item_id)
+ return true;
+ return false;
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/slot_control.h b/engines/zvision/slot_control.h
new file mode 100644
index 0000000000..eec2d04518
--- /dev/null
+++ b/engines/zvision/slot_control.h
@@ -0,0 +1,86 @@
+/* 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 ZVISION_SLOT_CONTROL_H
+#define ZVISION_SLOT_CONTROL_H
+
+#include "zvision/control.h"
+
+#include "graphics/surface.h"
+
+#include "common/rect.h"
+#include "common/list.h"
+
+
+namespace ZVision {
+
+class SlotControl : public Control {
+public:
+ SlotControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream);
+ ~SlotControl();
+
+ /**
+ * Called when LeftMouse is lifted. Calls ScriptManager::setStateValue(_key, 1);
+ *
+ * @param screenSpacePos The position of the mouse in screen space
+ * @param backgroundImageSpacePos The position of the mouse in background image space
+ */
+ bool onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
+ /**
+ * Called on every MouseMove. Tests if the mouse is inside _hotspot, and if so, sets the cursor.
+ *
+ * @param engine The base engine
+ * @param screenSpacePos The position of the mouse in screen space
+ * @param backgroundImageSpacePos The position of the mouse in background image space
+ * @return Was the cursor changed?
+ */
+ bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
+
+ bool process(uint32 deltaTimeInMillis);
+
+private:
+ /**
+ * The area that will trigger the event
+ * This is in image space coordinates, NOT screen space
+ */
+ Common::Rect _rectangle;
+ Common::Rect _hotspot;
+
+ int _cursor;
+ char _distance_id;
+ int _venus_id;
+
+ int _rendered_item;
+
+ Common::List<int> _eligible_objects;
+
+ bool eligeblity(int item_id);
+
+ Graphics::Surface *_bkg;
+
+ /** The cursor to use when hovering over _hotspot */
+ Common::String _hoverCursor;
+};
+
+} // End of namespace ZVision
+
+#endif