aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlukaslw2014-07-26 00:54:44 +0200
committerlukaslw2014-07-26 00:54:44 +0200
commiteebedf53aa6e6b7ea298eda0afc3e6fe196416cf (patch)
treebf106ee68033da39f14bb716d02e8664214204af
parent89a680e90a914ff52ec8c2b490bc4eb7420a7d93 (diff)
downloadscummvm-rg350-eebedf53aa6e6b7ea298eda0afc3e6fe196416cf.tar.gz
scummvm-rg350-eebedf53aa6e6b7ea298eda0afc3e6fe196416cf.tar.bz2
scummvm-rg350-eebedf53aa6e6b7ea298eda0afc3e6fe196416cf.zip
PRINCE: Inventory functions - update
-rw-r--r--engines/prince/prince.cpp131
-rw-r--r--engines/prince/prince.h9
-rw-r--r--engines/prince/script.cpp6
3 files changed, 43 insertions, 103 deletions
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp
index bcfb0b960e..dec3bc4b9c 100644
--- a/engines/prince/prince.cpp
+++ b/engines/prince/prince.cpp
@@ -1883,25 +1883,17 @@ void PrinceEngine::pause() {
_system->delayMillis(delay);
}
-void PrinceEngine::addInv(int hero, int item, bool addItemQuiet) {
- switch (hero) {
- case 0:
- if (_mainHero->_inventory.size() < kMaxItems) {
- if (item != 0x7FFF) {
- _mainHero->_inventory.push_back(item);
- }
- if (!addItemQuiet) {
- addInvObj();
- }
- _interpreter->setResult(0);
- } else {
- _interpreter->setResult(1);
- }
- break;
- case 1:
- if (_secondHero->_inventory.size() < kMaxItems) {
+void PrinceEngine::addInv(int heroId, int item, bool addItemQuiet) {
+ Hero *hero = nullptr;
+ if (!heroId) {
+ hero = _mainHero;
+ } else if (heroId == 1) {
+ hero = _secondHero;
+ }
+ if (hero != nullptr) {
+ if (hero->_inventory.size() < kMaxItems) {
if (item != 0x7FFF) {
- _secondHero->_inventory.push_back(item);
+ hero->_inventory.push_back(item);
}
if (!addItemQuiet) {
addInvObj();
@@ -1910,44 +1902,30 @@ void PrinceEngine::addInv(int hero, int item, bool addItemQuiet) {
} else {
_interpreter->setResult(1);
}
- break;
- default:
- error("addInv() - wrong hero slot");
- break;
}
}
-void PrinceEngine::remInv(int hero, int item) {
- switch (hero) {
- case 0:
- for (uint i = 0; i < _mainHero->_inventory.size(); i++) {
- if (_mainHero->_inventory[i] == item) {
- _mainHero->_inventory.remove_at(i);
- _interpreter->setResult(0);
- return;
- }
- }
- _interpreter->setResult(1);
- break;
- case 1:
- for (uint i = 0; i < _secondHero->_inventory.size(); i++) {
- if (_secondHero->_inventory[i] == item) {
- _secondHero->_inventory.remove_at(i);
+void PrinceEngine::remInv(int heroId, int item) {
+ Hero *hero = nullptr;
+ if (!heroId) {
+ hero = _mainHero;
+ } else if (heroId == 1) {
+ hero = _secondHero;
+ }
+ if (hero != nullptr) {
+ for (uint i = 0; i < hero->_inventory.size(); i++) {
+ if (hero->_inventory[i] == item) {
+ hero->_inventory.remove_at(i);
_interpreter->setResult(0);
return;
}
}
- _interpreter->setResult(1);
- break;
- default:
- _interpreter->setResult(1);
- error("remInv() - wrong hero slot");
- break;
}
+ _interpreter->setResult(1);
}
-void PrinceEngine::clearInv(int hero) {
- switch (hero) {
+void PrinceEngine::clearInv(int heroId) {
+ switch (heroId) {
case 0:
_mainHero->_inventory.clear();
break;
@@ -1960,60 +1938,25 @@ void PrinceEngine::clearInv(int hero) {
}
}
-void PrinceEngine::swapInv(int hero) {
+void PrinceEngine::swapInv(int heroId) {
Common::Array<int> tempInv;
- switch (hero) {
- case 0:
- for (uint i = 0; i < _mainHero->_inventory.size(); i++) {
- tempInv.push_back(_mainHero->_inventory[i]);
- }
- for (uint i = 0; i < _mainHero->_inventory2.size(); i++) {
- _mainHero->_inventory.push_back(_mainHero->_inventory2[i]);
- }
- for (uint i = 0; i < tempInv.size(); i++) {
- _mainHero->_inventory2.push_back(tempInv[i]);
- }
- tempInv.clear();
- break;
- case 1:
- for (uint i = 0; i < _secondHero->_inventory.size(); i++) {
- tempInv.push_back(_secondHero->_inventory[i]);
+ Hero *hero = nullptr;
+ if (!heroId) {
+ hero = _mainHero;
+ } else if (heroId == 1) {
+ hero = _secondHero;
+ }
+ if (hero != nullptr) {
+ for (uint i = 0; i < hero->_inventory.size(); i++) {
+ tempInv.push_back(hero->_inventory[i]);
}
- for (uint i = 0; i < _secondHero->_inventory2.size(); i++) {
- _secondHero->_inventory.push_back(_secondHero->_inventory2[i]);
+ for (uint i = 0; i < hero->_inventory2.size(); i++) {
+ hero->_inventory.push_back(hero->_inventory2[i]);
}
for (uint i = 0; i < tempInv.size(); i++) {
- _secondHero->_inventory2.push_back(tempInv[i]);
+ hero->_inventory2.push_back(tempInv[i]);
}
tempInv.clear();
- break;
- default:
- error("clearInv() - wrong hero slot");
- break;
- }
-}
-
-void PrinceEngine::checkInv(int hero, int item) {
- switch (hero) {
- case 0:
- for (uint i = 0; i < _mainHero->_inventory.size(); i++) {
- if (_mainHero->_inventory[i] == item) {
- _interpreter->setResult(0);
- }
- }
- _interpreter->setResult(1);
- break;
- case 1:
- for (uint i = 0; i < _secondHero->_inventory.size(); i++) {
- if (_secondHero->_inventory[i] == item) {
- _interpreter->setResult(0);
- }
- }
- _interpreter->setResult(1);
- break;
- default:
- error("addInv() - wrong hero slot");
- break;
}
}
diff --git a/engines/prince/prince.h b/engines/prince/prince.h
index 3e5e1a9f78..ada6ddf067 100644
--- a/engines/prince/prince.h
+++ b/engines/prince/prince.h
@@ -394,11 +394,10 @@ public:
void prepareInventoryToView();
void drawInvItems();
void displayInventory();
- void addInv(int hero, int item, bool addItemQuiet);
- void remInv(int hero, int item);
- void clearInv(int hero);
- void swapInv(int hero);
- void checkInv(int hero, int item);
+ void addInv(int heroId, int item, bool addItemQuiet);
+ void remInv(int heroId, int item);
+ void clearInv(int heroId);
+ void swapInv(int heroId);
void addInvObj();
void makeInvCursor(int itemNr);
void enableOptions();
diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp
index ddcd376956..fb978c1bcb 100644
--- a/engines/prince/script.cpp
+++ b/engines/prince/script.cpp
@@ -1129,11 +1129,9 @@ void Interpreter::O_FREEPRELOAD() {
error("O_FREEPRELOAD");
}
+// Not used in script
void Interpreter::O_CHECKINV() {
- uint16 hero = readScriptFlagValue();
- uint16 item = readScriptFlagValue();
- _vm->checkInv(hero, item);
- debugInterpreter("O_CHECKINV hero %d, item %d", hero, item);
+ error("O_CHECKINV");
}
void Interpreter::O_TALKHERO() {