From 57464f3dcef2e76d9050488c375d8bc63d0d00a4 Mon Sep 17 00:00:00 2001 From: Walter Agazzi Date: Sat, 14 Sep 2024 13:00:21 +0200 Subject: [PATCH] AGS: Engine: Complete "object interaction events take obj pointer and mode as params" commit This completes cb6cce267d75ccdbca452873693a1ccadf0f688b --- engines/ags/engine/ac/global_character.cpp | 5 ++++- engines/ags/engine/ac/global_hotspot.cpp | 7 ++++--- engines/ags/engine/ac/global_inventory_item.cpp | 6 +++++- engines/ags/engine/ac/global_object.cpp | 5 ++++- engines/ags/engine/ac/global_region.cpp | 5 ++++- engines/ags/engine/script/script.cpp | 2 +- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/engines/ags/engine/ac/global_character.cpp b/engines/ags/engine/ac/global_character.cpp index 9f54edfdbba..94c2ce0534a 100644 --- a/engines/ags/engine/ac/global_character.cpp +++ b/engines/ags/engine/ac/global_character.cpp @@ -41,10 +41,12 @@ #include "ags/engine/ac/properties.h" #include "ags/engine/ac/screen_overlay.h" #include "ags/engine/ac/string.h" +#include "ags/engine/ac/dynobj/cc_character.h" #include "ags/engine/debugging/debug_log.h" #include "ags/shared/game/room_struct.h" #include "ags/engine/main/game_run.h" #include "ags/engine/script/script.h" +#include "ags/globals.h" namespace AGS3 { @@ -388,7 +390,8 @@ void RunCharacterInteraction(int cc, int mood) { _GP(play).usedinv = _G(playerchar)->activeinv; } - const auto obj_evt = ObjectEvent("character%d", cc); + const auto obj_evt = ObjectEvent("character%d", cc, + RuntimeScriptValue().SetScriptObject(&_GP(game).chars[cc], &_GP(ccDynamicCharacter)), mood); if (_G(loaded_game_file_version) > kGameVersion_272) { if ((evnt >= 0) && run_interaction_script(obj_evt, _GP(game).charScripts[cc].get(), evnt, anyclick_evt) < 0) diff --git a/engines/ags/engine/ac/global_hotspot.cpp b/engines/ags/engine/ac/global_hotspot.cpp index 05245976cfe..24e9dfb1883 100644 --- a/engines/ags/engine/ac/global_hotspot.cpp +++ b/engines/ags/engine/ac/global_hotspot.cpp @@ -33,9 +33,11 @@ #include "ags/engine/ac/properties.h" #include "ags/engine/ac/room_status.h" #include "ags/engine/ac/string.h" +#include "ags/engine/ac/dynobj/cc_hotspot.h" #include "ags/engine/debugging/debug_log.h" #include "ags/shared/game/room_struct.h" #include "ags/engine/script/script.h" +#include "ags/globals.h" namespace AGS3 { @@ -118,9 +120,8 @@ void RunHotspotInteraction(int hotspothere, int mood) { else if ((mood != MODE_WALK) && (_GP(play).check_interaction_only == 0)) MoveCharacterToHotspot(_GP(game).playercharacter, hotspothere); - // can't use the setevent functions because this ProcessClick is only - // executed once in a eventlist - const auto obj_evt = ObjectEvent("hotspot%d", hotspothere); + const auto obj_evt = ObjectEvent("hotspot%d", hotspothere, + RuntimeScriptValue().SetScriptObject(&_G(scrHotspot)[hotspothere], &_GP(ccDynamicHotspot)), mood); if (_G(loaded_game_file_version) > kGameVersion_272) { if ((evnt >= 0) && diff --git a/engines/ags/engine/ac/global_inventory_item.cpp b/engines/ags/engine/ac/global_inventory_item.cpp index 2d5c19fe8da..5acdc0703c2 100644 --- a/engines/ags/engine/ac/global_inventory_item.cpp +++ b/engines/ags/engine/ac/global_inventory_item.cpp @@ -30,9 +30,11 @@ #include "ags/engine/ac/inv_window.h" #include "ags/engine/ac/properties.h" #include "ags/engine/ac/string.h" +#include "ags/engine/ac/dynobj/cc_inventory.h" #include "ags/shared/gui/gui_main.h" #include "ags/shared/gui/gui_inv.h" #include "ags/engine/script/script.h" +#include "ags/globals.h" namespace AGS3 { @@ -116,7 +118,9 @@ void RunInventoryInteraction(int iit, int mood) { if (evnt < 0) // on any non-supported mode - use "other-click" evnt = otherclick_evt; - auto obj_evt = ObjectEvent("inventory%d", iit); + const auto obj_evt = ObjectEvent("inventory%d", iit, + RuntimeScriptValue().SetScriptObject(&_G(scrInv)[iit], &_GP(ccDynamicInv)), mood); + if (_G(loaded_game_file_version) > kGameVersion_272) { run_interaction_script(obj_evt, _GP(game).invScripts[iit].get(), evnt); } else { diff --git a/engines/ags/engine/ac/global_object.cpp b/engines/ags/engine/ac/global_object.cpp index 997e7b2237b..3a8850e5b9c 100644 --- a/engines/ags/engine/ac/global_object.cpp +++ b/engines/ags/engine/ac/global_object.cpp @@ -37,6 +37,7 @@ #include "ags/engine/ac/room_object.h" #include "ags/engine/ac/room_status.h" #include "ags/engine/ac/string.h" +#include "ags/engine/ac/dynobj/cc_object.h" #include "ags/engine/ac/view_frame.h" #include "ags/engine/debugging/debug_log.h" #include "ags/engine/main/game_run.h" @@ -433,7 +434,9 @@ void RunObjectInteraction(int aa, int mood) { _GP(play).usedinv = _G(playerchar)->activeinv; } - const auto obj_evt = ObjectEvent("object%d", aa); + const auto obj_evt = ObjectEvent("object%d", aa, + RuntimeScriptValue().SetScriptObject(&_G(scrObj)[aa], &_GP(ccDynamicObject)), mood); + if (_G(loaded_game_file_version) > kGameVersion_272) { if ((evnt >= 0) && run_interaction_script(obj_evt, _GP(thisroom).Objects[aa].EventHandlers.get(), evnt, anyclick_evt) < 0) diff --git a/engines/ags/engine/ac/global_region.cpp b/engines/ags/engine/ac/global_region.cpp index f78844dea26..dce06e561ea 100644 --- a/engines/ags/engine/ac/global_region.cpp +++ b/engines/ags/engine/ac/global_region.cpp @@ -26,6 +26,7 @@ #include "ags/engine/ac/region.h" #include "ags/engine/ac/room.h" #include "ags/engine/ac/room_status.h" +#include "ags/engine/ac/dynobj/cc_region.h" #include "ags/engine/debugging/debug_log.h" #include "ags/shared/game/room_struct.h" #include "ags/shared/gfx/bitmap.h" @@ -145,7 +146,9 @@ void RunRegionInteraction(int regnum, int mood) { // NOTE: for Regions the mode has specific meanings (NOT verbs): // 0 - stands on region, 1 - walks onto region, 2 - walks off region - const auto obj_evt = ObjectEvent("region%d", regnum); + const auto obj_evt = ObjectEvent("region%d", regnum, + RuntimeScriptValue().SetScriptObject(&_G(scrRegion)[regnum], &_GP(ccDynamicRegion)), mood); + if (_G(loaded_game_file_version) > kGameVersion_272) { run_interaction_script(obj_evt, _GP(thisroom).Regions[regnum].EventHandlers.get(), mood); } else { diff --git a/engines/ags/engine/script/script.cpp b/engines/ags/engine/script/script.cpp index 0b9b888f012..de2f73fd1d1 100644 --- a/engines/ags/engine/script/script.cpp +++ b/engines/ags/engine/script/script.cpp @@ -164,7 +164,7 @@ int run_interaction_script(const ObjectEvent &obj_evt, InteractionScripts *nint, return -1; } - int room_was = _GP(play).room_changes; + const int room_was = _GP(play).room_changes; // TODO: find a way to generalize all the following hard-coded behavior