aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/zvision/actions.cpp49
-rw-r--r--engines/zvision/actions.h9
-rw-r--r--engines/zvision/inventory_manager.cpp123
-rw-r--r--engines/zvision/inventory_manager.h28
-rw-r--r--engines/zvision/module.mk3
-rw-r--r--engines/zvision/scr_file_handling.cpp2
-rw-r--r--engines/zvision/script_manager.h14
7 files changed, 196 insertions, 32 deletions
diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp
index f540e3e34a..5568e39bdb 100644
--- a/engines/zvision/actions.cpp
+++ b/engines/zvision/actions.cpp
@@ -156,6 +156,55 @@ bool ActionEnableControl::execute() {
return true;
}
+//////////////////////////////////////////////////////////////////////////////
+// ActionInventory
+//////////////////////////////////////////////////////////////////////////////
+
+ActionInventory::ActionInventory(ZVision *engine, const Common::String &line) :
+ ResultAction(engine) {
+ char buf[25];
+ sscanf(line.c_str(), "%*[^(](%25s %d)", buf, &_key);
+
+ if (strcmp(buf, "add") == 0) {
+ _type = 0;
+ } else if (strcmp(buf, "addi") == 0) {
+ _type = 1;
+ } else if (strcmp(buf, "drop") == 0) {
+ _type = 2;
+ } else if (strcmp(buf, "dropi") == 0) {
+ _type = 3;
+ } else if (strcmp(buf, "cycle") == 0) {
+ _type = 4;
+ }
+
+}
+
+bool ActionInventory::execute() {
+ switch (_type) {
+ case 0: // add
+ _engine->getScriptManager()->invertory_add(_key);
+ break;
+ case 1: // addi
+ _engine->getScriptManager()->invertory_add(_engine->getScriptManager()->getStateValue(_key));
+ break;
+ case 2: // drop
+ if (_key >= 0)
+ _engine->getScriptManager()->invertory_drop(_key);
+ else
+ _engine->getScriptManager()->invertory_drop(_engine->getScriptManager()->getStateValue(StateKey_InventoryItem));
+ break;
+ case 3: // dropi
+ _engine->getScriptManager()->invertory_drop(_engine->getScriptManager()->getStateValue(_key));
+ break;
+ case 4: // cycle
+ _engine->getScriptManager()->invertory_cycle();
+ break;
+ default:
+ break;
+ }
+ return true;
+}
+
//////////////////////////////////////////////////////////////////////////////
// ActionKill
diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h
index b75c201d99..50224aaaf5 100644
--- a/engines/zvision/actions.h
+++ b/engines/zvision/actions.h
@@ -212,6 +212,15 @@ private:
uint32 _key;
};
+class ActionInventory : public ResultAction {
+public:
+ ActionInventory(ZVision *engine, const Common::String &line);
+ bool execute();
+private:
+ uint8 _type;
+ int32 _key;
+};
+
class ActionKill : public ResultAction {
public:
ActionKill(ZVision *engine, const Common::String &line);
diff --git a/engines/zvision/inventory_manager.cpp b/engines/zvision/inventory_manager.cpp
new file mode 100644
index 0000000000..3924c6b51a
--- /dev/null
+++ b/engines/zvision/inventory_manager.cpp
@@ -0,0 +1,123 @@
+/* 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/script_manager.h"
+
+
+namespace ZVision {
+
+int8 ScriptManager::invertory_getCount() {
+ return getStateValue(StateKey_Inv_Cnt_Slot);
+}
+
+void ScriptManager::invertory_setCount(int8 cnt) {
+ setStateValue(StateKey_Inv_Cnt_Slot, cnt);
+}
+
+int16 ScriptManager::invertory_getItem(int8 id) {
+ if (id < 49 && id >= 0)
+ return getStateValue(StateKey_Inv_1_Slot + id);
+ return -1;
+}
+
+void ScriptManager::invertory_setItem(int8 id, int16 item) {
+ if (id < 49 && id >= 0)
+ setStateValue(StateKey_Inv_1_Slot + id, item);
+}
+
+void ScriptManager::invertory_add(int16 item) {
+ int8 cnt = invertory_getCount();
+
+ if (cnt < 49) {
+ bool not_exist = true;
+
+ if (cnt == 0) {
+ invertory_setItem(0, 0);
+ invertory_setCount(1); // we needed empty item for cycle code
+ cnt = 1;
+ }
+
+ for (int8 cur = 0; cur < cnt; cur++)
+ if (invertory_getItem(cur) == item) {
+ not_exist = false;
+ break;
+ }
+
+ if (not_exist) {
+ for (int8 i = cnt; i > 0; i--)
+ invertory_setItem(i, invertory_getItem(i - 1));
+
+ invertory_setItem(0, item);
+
+ setStateValue(StateKey_InventoryItem, item);
+
+ invertory_setCount(cnt + 1);
+ }
+ }
+}
+
+void ScriptManager::invertory_drop(int16 item) {
+ int8 items_cnt = invertory_getCount();
+
+ // if items in inventory > 0
+ if (items_cnt != 0) {
+ int8 index = 0;
+
+ // finding needed item
+ while (index < items_cnt) {
+ if (invertory_getItem(index) == item)
+ break;
+
+ index++;
+ }
+
+ // if item in the inventory
+ if (items_cnt != index) {
+ // shift all items left with rewrite founded item
+ for (int8 v = index; v < items_cnt - 1 ; v++)
+ invertory_setItem(v, invertory_getItem(v + 1));
+
+ // del last item
+ invertory_setItem(items_cnt - 1, 0);
+ invertory_setCount(invertory_getCount() - 1);
+
+ setStateValue(StateKey_InventoryItem, invertory_getItem(0));
+ }
+ }
+}
+void ScriptManager::invertory_cycle() {
+ int8 item_cnt = invertory_getCount();
+ int8 cur_item = invertory_getItem(0);
+ if (item_cnt > 1) {
+ for (int8 i = 0; i < item_cnt - 1; i++)
+ invertory_setItem(i, invertory_getItem(i + 1));
+
+ invertory_setItem(item_cnt - 1, cur_item);
+
+ setStateValue(StateKey_InventoryItem, invertory_getItem(0));
+
+ }
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/inventory_manager.h b/engines/zvision/inventory_manager.h
deleted file mode 100644
index ae6d116b18..0000000000
--- a/engines/zvision/inventory_manager.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* 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_INVENTORY_MANAGER_H
-#define ZVISION_INVENTORY_MANAGER_H
-
-// TODO: Implement InventoryManager
-
-#endif
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index b66f02da8e..ffdef16335 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -31,7 +31,8 @@ MODULE_OBJS := \
zork_avi_decoder.o \
zork_raw.o \
sidefx.o \
- music_node.o
+ music_node.o \
+ inventory_manager.o
MODULE_DIRS += \
engines/zvision
diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp
index 0df3143a51..769c94921b 100644
--- a/engines/zvision/scr_file_handling.cpp
+++ b/engines/zvision/scr_file_handling.cpp
@@ -197,7 +197,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis
} else if (line.matchString("*:flush_mouse_events*", true)) {
// TODO: Implement ActionFlushMouseEvents
} else if (line.matchString("*:inventory*", true)) {
- // TODO: Implement ActionInventory
+ actionList.push_back(new ActionInventory(_engine, line));
} else if (line.matchString("*:kill*", true)) {
actionList.push_back(new ActionKill(_engine, line));
} else if (line.matchString("*:menu_bar_enable*", true)) {
diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h
index 38d398248e..2f585b6291 100644
--- a/engines/zvision/script_manager.h
+++ b/engines/zvision/script_manager.h
@@ -90,7 +90,7 @@ enum StateKey {
StateKey_EF9_G = 92,
StateKey_EF9_R = 93,
StateKey_EF9_Speed = 94,
- StateKey_Inv_0_Slot = 100,
+ StateKey_Inv_Cnt_Slot = 100,
StateKey_Inv_1_Slot = 101,
StateKey_Inv_49_Slot = 149,
StateKey_Inv_TotalSlots = 150
@@ -248,8 +248,18 @@ private:
/** Perform change location */
void do_changeLocation();
-// TODO: Make this private. It was only made public so Console::cmdParseAllScrFiles() could use it
+ int8 invertory_getCount();
+ void invertory_setCount(int8 cnt);
+ int16 invertory_getItem(int8 id);
+ void invertory_setItem(int8 id, int16 item);
+
+
public:
+ void invertory_add(int16 item);
+ void invertory_drop(int16 item);
+ void invertory_cycle();
+
+ // TODO: Make this private. It was only made public so Console::cmdParseAllScrFiles() could use it
/**
* Parses a script file into triggers and events
*