aboutsummaryrefslogtreecommitdiff
path: root/engines/hdb/ai-use.cpp
diff options
context:
space:
mode:
authorNipun Garg2019-07-03 21:38:43 +0530
committerEugene Sandulenko2019-09-03 17:17:09 +0200
commite3ceb4dfbde8ccf9d0b5b9a584892d6b202f63f3 (patch)
tree2e3570e58cffeb7da2279960fe4aec050f1b9c1d /engines/hdb/ai-use.cpp
parent661ee3b104770ddb801af4aa2ab07df00c494eee (diff)
downloadscummvm-rg350-e3ceb4dfbde8ccf9d0b5b9a584892d6b202f63f3.tar.gz
scummvm-rg350-e3ceb4dfbde8ccf9d0b5b9a584892d6b202f63f3.tar.bz2
scummvm-rg350-e3ceb4dfbde8ccf9d0b5b9a584892d6b202f63f3.zip
HDB: Add Switch functions
Diffstat (limited to 'engines/hdb/ai-use.cpp')
-rw-r--r--engines/hdb/ai-use.cpp56
1 files changed, 47 insertions, 9 deletions
diff --git a/engines/hdb/ai-use.cpp b/engines/hdb/ai-use.cpp
index f63c608b72..fdbaaaf0fd 100644
--- a/engines/hdb/ai-use.cpp
+++ b/engines/hdb/ai-use.cpp
@@ -133,29 +133,67 @@ bool AI::useTarget(int x, int y, int targetX, int targetY, int newTile, int *wor
// Black Door Switch
bool AI::useSwitch(AIEntity *e, int x, int y, int targetX, int targetY, int onTile) {
- warning("STUB: Define useSwitch");
- return false;
+ int worked;
+ if (g_hdb->_map->onScreen(x, y))
+ g_hdb->_sound->playSound(SND_SWITCH_USE);
+ return useTarget(x, y, targetX, targetY, onTile, &worked);
}
bool AI::useSwitchOn(AIEntity *e, int x, int y, int targetX, int targetY, int offTile) {
- warning("STUB: Define useSwitchOn");
- return false;
+ int worked;
+ if (g_hdb->_map->onScreen(x, y))
+ g_hdb->_sound->playSound(SND_SWITCH_USE);
+ return useTarget(x, y, targetX, targetY, offTile, &worked);
}
bool AI::useSwitch2(AIEntity *e, int x, int y, int targetX, int targetY) {
- warning("STUB: Define useSwitch2");
- return false;
+ int i = 10;
+ return true;
}
// Colored Keycard Switch
bool AI::useLockedSwitch(AIEntity *e, int x, int y, int targetX, int targetY, int onTile, AIType item, const char *keyerror) {
- warning("STUB: Define useLockedSwitch");
+ // is the PLAYER next to this thing? No other entities are allowed to unlock anything!
+ if (abs(x - _player->tileX) > 1 || abs(y - _player->tileY) > 1)
+ return false;
+
+ int amount = queryInventoryType(item);
+ int worked;
+ bool rtn;
+
+ if (amount) {
+ rtn = useTarget(x, y, targetX, targetY, onTile, &worked);
+ if (worked) {
+ removeInvItemType(item, 1);
+ if (g_hdb->_map->onScreen(x, y))
+ g_hdb->_sound->playSound(SND_SWITCH_USE);
+ }
+ return rtn;
+ } else {
+ if (g_hdb->_map->onScreen(x, y))
+ g_hdb->_sound->playSound(SND_CELLHOLDER_USE_REJECT);
+ g_hdb->_window->openMessageBar(keyerror, 3);
+ }
return false;
}
bool AI::useLockedSwitchOn(AIEntity *e, int x, int y, int targetX, int targetY, int offTile, AIType item) {
- warning("STUB: Define useLockedSwitchOn");
- return false;
+ // is the PLAYER next to this thing? No other entities are allowed to unlock anything!
+ if (abs(x - _player->tileX) > 1 || abs(y - _player->tileY) > 1)
+ return false;
+
+ int worked;
+ bool rtn;
+ if (getInvAmount() == 10)
+ return false;
+
+ rtn = useTarget(x, y, targetX, targetY, offTile, &worked);
+ if (worked) {
+ addItemToInventory(item, 1, NULL, NULL, NULL);
+ if (g_hdb->_map->onScreen(x, y))
+ g_hdb->_sound->playSound(SND_SWITCH_USE);
+ }
+ return rtn;
}
// Purple Cell Holder Switch