aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk
diff options
context:
space:
mode:
authorBastien Bouclet2017-08-07 21:26:38 +0200
committerBastien Bouclet2017-08-10 19:02:10 +0200
commit5a4400e390faa9a0ee27b4d7f3207253d1342a2a (patch)
tree52ec4fedd7840ad8e616e79e3cf91d0b9e50a263 /engines/mohawk
parentc278be9f6f4a2f631855f064cdb4c35d880e15c3 (diff)
downloadscummvm-rg350-5a4400e390faa9a0ee27b4d7f3207253d1342a2a.tar.gz
scummvm-rg350-5a4400e390faa9a0ee27b4d7f3207253d1342a2a.tar.bz2
scummvm-rg350-5a4400e390faa9a0ee27b4d7f3207253d1342a2a.zip
MOHAWK: Riven: Stop using varargs to list hotspot names
One call to va_end was missing when returning early. This stuff is too dangerous for me to use.
Diffstat (limited to 'engines/mohawk')
-rw-r--r--engines/mohawk/riven_card.cpp55
-rw-r--r--engines/mohawk/riven_card.h2
2 files changed, 33 insertions, 24 deletions
diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp
index a116d8817f..bb7f617178 100644
--- a/engines/mohawk/riven_card.cpp
+++ b/engines/mohawk/riven_card.cpp
@@ -683,41 +683,56 @@ void RivenCard::playMovie(uint16 index, bool queue) {
}
RivenScriptPtr RivenCard::onKeyAction(RivenKeyAction keyAction) {
- RivenHotspot *directionHotspot = nullptr;
+ static const char *forwardNames[] = {
+ "forward", "forward1", "forward2", "forward3",
+ "opendoor", "openhatch", "opentrap", "opengate", "opengrate",
+ "open", "door", "drop", "go", "enterprison", "exit",
+ "forwardleft", "forwardright", nullptr
+ };
+
+ static const char *forwardLeftNames [] = { "forwardleft", nullptr };
+ static const char *forwardRightNames[] = { "forwardright", nullptr };
+ static const char *leftNames [] = { "left", "afl", "prevpage", nullptr };
+ static const char *rightNames [] = { "right", "afr", "nextpage", nullptr };
+ static const char *backNames [] = { "back", nullptr };
+ static const char *upNames [] = { "up", nullptr };
+ static const char *downNames [] = { "down", nullptr };
+
+ static const char **hotspotNames;
switch (keyAction) {
case kKeyActionMoveForward:
- directionHotspot = findEnabledHotspotByName(17,
- "forward", "forward1", "forward2", "forward3",
- "opendoor", "openhatch", "opentrap", "opengate", "opengrate",
- "open", "door", "drop", "go", "enterprison", "exit",
- "forwardleft", "forwardright"
- );
+ hotspotNames = forwardNames;
break;
case kKeyActionMoveForwardLeft:
- directionHotspot = findEnabledHotspotByName(1, "forwardleft");
+ hotspotNames = forwardLeftNames;
break;
case kKeyActionMoveForwardRight:
- directionHotspot = findEnabledHotspotByName(1, "forwardright");
+ hotspotNames = forwardRightNames;
break;
case kKeyActionMoveLeft:
- directionHotspot = findEnabledHotspotByName(3, "left", "afl", "prevpage");
+ hotspotNames = leftNames;
break;
case kKeyActionMoveRight:
- directionHotspot = findEnabledHotspotByName(3, "right", "afr", "nextpage");
+ hotspotNames = rightNames;
break;
case kKeyActionMoveBack:
- directionHotspot = findEnabledHotspotByName(1, "back");
+ hotspotNames = backNames;
break;
case kKeyActionLookUp:
- directionHotspot = findEnabledHotspotByName(1, "up");
+ hotspotNames = upNames;
break;
case kKeyActionLookDown:
- directionHotspot = findEnabledHotspotByName(1, "down");
+ hotspotNames = downNames;
break;
default:
break;
}
+ if (!hotspotNames) {
+ return RivenScriptPtr(new RivenScript());
+ }
+
+ RivenHotspot *directionHotspot = findEnabledHotspotByName(hotspotNames);
if (!directionHotspot) {
return RivenScriptPtr(new RivenScript());
}
@@ -735,20 +750,14 @@ RivenScriptPtr RivenCard::onKeyAction(RivenKeyAction keyAction) {
return clickScript;
}
-RivenHotspot *RivenCard::findEnabledHotspotByName(uint n, ...) const {
- va_list ap;
- va_start(ap, n);
-
- for (uint i = 0; i < n; i++) {
- const char *name = va_arg(ap, const char *);
- RivenHotspot *hotspot = getHotspotByName(name, true);
+RivenHotspot *RivenCard::findEnabledHotspotByName(const char **names) const {
+ for (uint i = 0; names[i] != nullptr; i++) {
+ RivenHotspot *hotspot = getHotspotByName(names[i], true);
if (hotspot && hotspot->isEnabled()) {
return hotspot;
}
}
- va_end(ap);
-
return nullptr;
}
diff --git a/engines/mohawk/riven_card.h b/engines/mohawk/riven_card.h
index c5a5795eaa..b11363c916 100644
--- a/engines/mohawk/riven_card.h
+++ b/engines/mohawk/riven_card.h
@@ -102,7 +102,7 @@ public:
RivenHotspot *getHotspotByName(const Common::String &name, bool optional = false) const;
/** Find an enabled hotspot with a name matching one of the arguments */
- RivenHotspot *findEnabledHotspotByName(uint n, ...) const;
+ RivenHotspot *findEnabledHotspotByName(const char **names) const;
/** Get the hotspot with the specified BLST id */
RivenHotspot *getHotspotByBlstId(const uint16 blstId) const;