From 23c1b508611d5fa4e7dfc47f8f5ec10a7de177e3 Mon Sep 17 00:00:00 2001 From: Marisa-Chan Date: Wed, 2 Jul 2014 19:50:55 +0000 Subject: ZVISION: Reorgonize source files into directories. --- engines/zvision/scripting/inventory.cpp | 123 ++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 engines/zvision/scripting/inventory.cpp (limited to 'engines/zvision/scripting/inventory.cpp') diff --git a/engines/zvision/scripting/inventory.cpp b/engines/zvision/scripting/inventory.cpp new file mode 100644 index 0000000000..f8b22970c4 --- /dev/null +++ b/engines/zvision/scripting/inventory.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/scripting/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 -- cgit v1.2.3 From 5b352da304931bafcfcddbe08461488335c7ad57 Mon Sep 17 00:00:00 2001 From: Marisa-Chan Date: Thu, 20 Nov 2014 14:48:24 +0600 Subject: ZVISION: More CamelCase and a bit of comments cleanup --- engines/zvision/scripting/inventory.cpp | 68 ++++++++++++++++----------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'engines/zvision/scripting/inventory.cpp') diff --git a/engines/zvision/scripting/inventory.cpp b/engines/zvision/scripting/inventory.cpp index f8b22970c4..98d063395b 100644 --- a/engines/zvision/scripting/inventory.cpp +++ b/engines/zvision/scripting/inventory.cpp @@ -27,95 +27,95 @@ namespace ZVision { -int8 ScriptManager::invertory_getCount() { +int8 ScriptManager::inventoryGetCount() { return getStateValue(StateKey_Inv_Cnt_Slot); } -void ScriptManager::invertory_setCount(int8 cnt) { +void ScriptManager::inventorySetCount(int8 cnt) { setStateValue(StateKey_Inv_Cnt_Slot, cnt); } -int16 ScriptManager::invertory_getItem(int8 id) { +int16 ScriptManager::inventoryGetItem(int8 id) { if (id < 49 && id >= 0) return getStateValue(StateKey_Inv_1_Slot + id); return -1; } -void ScriptManager::invertory_setItem(int8 id, int16 item) { +void ScriptManager::inventorySetItem(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(); +void ScriptManager::inventoryAdd(int16 item) { + int8 cnt = inventoryGetCount(); if (cnt < 49) { - bool not_exist = true; + bool notExist = true; if (cnt == 0) { - invertory_setItem(0, 0); - invertory_setCount(1); // we needed empty item for cycle code + inventorySetItem(0, 0); + inventorySetCount(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; + if (inventoryGetItem(cur) == item) { + notExist = false; break; } - if (not_exist) { + if (notExist) { for (int8 i = cnt; i > 0; i--) - invertory_setItem(i, invertory_getItem(i - 1)); + inventorySetItem(i, inventoryGetItem(i - 1)); - invertory_setItem(0, item); + inventorySetItem(0, item); setStateValue(StateKey_InventoryItem, item); - invertory_setCount(cnt + 1); + inventorySetCount(cnt + 1); } } } -void ScriptManager::invertory_drop(int16 item) { - int8 items_cnt = invertory_getCount(); +void ScriptManager::inventoryDrop(int16 item) { + int8 itemCount = inventoryGetCount(); // if items in inventory > 0 - if (items_cnt != 0) { + if (itemCount != 0) { int8 index = 0; // finding needed item - while (index < items_cnt) { - if (invertory_getItem(index) == item) + while (index < itemCount) { + if (inventoryGetItem(index) == item) break; index++; } // if item in the inventory - if (items_cnt != index) { + if (itemCount != 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)); + for (int8 v = index; v < itemCount - 1 ; v++) + inventorySetItem(v, inventoryGetItem(v + 1)); // del last item - invertory_setItem(items_cnt - 1, 0); - invertory_setCount(invertory_getCount() - 1); + inventorySetItem(itemCount - 1, 0); + inventorySetCount(inventoryGetCount() - 1); - setStateValue(StateKey_InventoryItem, invertory_getItem(0)); + setStateValue(StateKey_InventoryItem, inventoryGetItem(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)); +void ScriptManager::inventoryCycle() { + int8 itemCount = inventoryGetCount(); + int8 curItem = inventoryGetItem(0); + if (itemCount > 1) { + for (int8 i = 0; i < itemCount - 1; i++) + inventorySetItem(i, inventoryGetItem(i + 1)); - invertory_setItem(item_cnt - 1, cur_item); + inventorySetItem(itemCount - 1, curItem); - setStateValue(StateKey_InventoryItem, invertory_getItem(0)); + setStateValue(StateKey_InventoryItem, inventoryGetItem(0)); } } -- cgit v1.2.3