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.
This commit is contained in:
Bastien Bouclet 2017-08-07 21:26:38 +02:00
parent c278be9f6f
commit 5a4400e390
2 changed files with 33 additions and 24 deletions

View File

@ -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;
}

View File

@ -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;