From f2f9ed06ae295d1547ef0a8d0d295b32ef5662a0 Mon Sep 17 00:00:00 2001 From: Vsevolod Kremianskii Date: Mon, 16 Nov 2020 00:39:49 +0700 Subject: [PATCH] feat: Implement GetModule and GetTag script functions --- src/game/script/routines.h | 2 ++ src/game/script/routines_kotor.cpp | 4 ++-- src/game/script/routines_objects.cpp | 12 ++++++++++++ src/game/script/routines_tsl.cpp | 4 ++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/game/script/routines.h b/src/game/script/routines.h index b117731f..cf44297e 100644 --- a/src/game/script/routines.h +++ b/src/game/script/routines.h @@ -117,7 +117,9 @@ private: script::Variable getIsObjectValid(const std::vector &args, script::ExecutionContext &ctx); script::Variable getItemInSlot(const std::vector &args, script::ExecutionContext &ctx); script::Variable getLocked(const std::vector &args, script::ExecutionContext &ctx); + script::Variable getModule(const std::vector &args, script::ExecutionContext &ctx); script::Variable getObjectByTag(const std::vector &args, script::ExecutionContext &ctx); + script::Variable getTag(const std::vector &args, script::ExecutionContext &ctx); script::Variable getWaypointByTag(const std::vector &args, script::ExecutionContext &ctx); script::Variable setLocked(const std::vector &args, script::ExecutionContext &ctx); diff --git a/src/game/script/routines_kotor.cpp b/src/game/script/routines_kotor.cpp index 6caf2f77..9c77c1a1 100644 --- a/src/game/script/routines_kotor.cpp +++ b/src/game/script/routines_kotor.cpp @@ -207,7 +207,7 @@ void Routines::addKotorRoutines() { add("EffectMovementSpeedIncrease", Effect, { Int }); add("GetHitDice", Int, { Object }, bind(&Routines::getHitDice, this, _1, _2)); add("ActionForceFollowObject", Void, { Object, Float }); - add("GetTag", String, { Object }); + add("GetTag", String, { Object }, bind(&Routines::getTag, this, _1, _2)); add("ResistForce", Int, { Object, Object }); add("GetEffectType", Int, { Effect }); add("EffectAreaOfEffect", Effect, { Int, String, String, String }); @@ -281,7 +281,7 @@ void Routines::addKotorRoutines() { add("GetStringByStrRef", String, { Int }); add("ActionSpeakStringByStrRef", Void, { Int, Int }); add("DestroyObject", Void, { Object, Float, Int, Float }, bind(&Routines::destroyObject, this, _1, _2)); - add("GetModule", Object, { }); + add("GetModule", Object, { }, bind(&Routines::getModule, this, _1, _2)); add("CreateObject", Object, { Int, String, Location, Int }); add("EventSpellCastAt", Event, { Object, Int, Int }); add("GetLastSpellCaster", Object, { }); diff --git a/src/game/script/routines_objects.cpp b/src/game/script/routines_objects.cpp index 6ad3e5ab..1108a0b8 100644 --- a/src/game/script/routines_objects.cpp +++ b/src/game/script/routines_objects.cpp @@ -167,6 +167,18 @@ Variable Routines::createItemOnObject(const vector &args, ExecutionCon return move(result); } +Variable Routines::getModule(const vector &args, ExecutionContext &ctx) { + Variable result(VariableType::Object); + result.objectId = _game->module()->id(); + return move(result); +} + +Variable Routines::getTag(const vector &args, ExecutionContext &ctx) { + int objectId = args[0].objectId; + shared_ptr object(getObjectById(objectId, ctx)); + return object ? object->tag() : ""; +} + } // namespace game } // namespace reone diff --git a/src/game/script/routines_tsl.cpp b/src/game/script/routines_tsl.cpp index 71cd2f1b..62d8f235 100644 --- a/src/game/script/routines_tsl.cpp +++ b/src/game/script/routines_tsl.cpp @@ -207,7 +207,7 @@ void Routines::addTslRoutines() { add("EffectMovementSpeedIncrease", Effect, { Int }); add("GetHitDice", Int, { Object }, bind(&Routines::getHitDice, this, _1, _2)); add("ActionForceFollowObject", Void, { Object, Float }); - add("GetTag", String, { Object }); + add("GetTag", String, { Object }, bind(&Routines::getTag, this, _1, _2)); add("ResistForce", Int, { Object, Object }); add("GetEffectType", Int, { Effect }); add("EffectAreaOfEffect", Effect, { Int, String, String, String }); @@ -281,7 +281,7 @@ void Routines::addTslRoutines() { add("GetStringByStrRef", String, { Int }); add("ActionSpeakStringByStrRef", Void, { Int, Int }); add("DestroyObject", Void, { Object, Float, Int, Float, Int }, bind(&Routines::destroyObject, this, _1, _2)); - add("GetModule", Object, { }); + add("GetModule", Object, { }, bind(&Routines::getModule, this, _1, _2)); add("CreateObject", Object, { Int, String, Location, Int }); add("EventSpellCastAt", Event, { Object, Int, Int }); add("GetLastSpellCaster", Object, { });