AGS: Engine: add hotspot id assertion to GetHotspotProperty

This is made in line with previously added AssertObject().
from upstream 99f94c469636522bd2d89923901659476d816577
This commit is contained in:
Walter Agazzi 2024-03-27 22:30:29 +01:00
parent f09519834c
commit 6c8e783e4a
3 changed files with 15 additions and 0 deletions

View File

@ -139,10 +139,14 @@ void RunHotspotInteraction(int hotspothere, int mood) {
}
int GetHotspotProperty(int hss, const char *property) {
if (!AssertHotspot("GetHotspotProperty", hss))
return 0;
return get_int_property(_GP(thisroom).Hotspots[hss].Properties, _G(croom)->hsProps[hss], property);
}
void GetHotspotPropertyText(int item, const char *property, char *bufer) {
if (!AssertHotspot("GetHotspotPropertyText", item))
return;
get_text_property(_GP(thisroom).Hotspots[item].Properties, _G(croom)->hsProps[item], property, bufer);
}

View File

@ -28,6 +28,7 @@
#include "ags/engine/ac/room.h"
#include "ags/engine/ac/room_status.h"
#include "ags/engine/ac/string.h"
#include "ags/engine/debugging/debug_log.h"
#include "ags/shared/game/room_struct.h"
#include "ags/shared/gfx/bitmap.h"
#include "ags/shared/gui/gui_main.h"
@ -42,6 +43,13 @@ namespace AGS3 {
using namespace AGS::Shared;
bool AssertHotspot(const char *apiname, int hot_id) {
if ((hot_id >= 0) && (static_cast<uint32_t>(hot_id) < _GP(thisroom).HotspotCount))
return true;
debug_script_warn("%s: invalid hotspot id %d (range is 0..%d)", apiname, hot_id, _GP(thisroom).HotspotCount - 1);
return false;
}
void Hotspot_SetEnabled(ScriptHotspot *hss, int newval) {
if (newval)
EnableHotspot(hss->id);

View File

@ -26,6 +26,9 @@
namespace AGS3 {
// Asserts the hotspot ID is valid in the current room,
// if not then prints a warning to the log; returns assertion result
bool AssertHotspot(const char *apiname, int hot_id);
void Hotspot_SetEnabled(ScriptHotspot *hss, int newval);
int Hotspot_GetEnabled(ScriptHotspot *hss);
int Hotspot_GetID(ScriptHotspot *hss);