From cbf407bc10a708d96bc61b07c82ec8374a3800ea Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Thu, 13 Nov 2025 14:58:36 -0600 Subject: [PATCH] add conditional filter for missionmarker autospawn --- Engine/source/T3D/missionMarker.cpp | 22 +++++++++++++++++++++- Engine/source/T3D/missionMarker.h | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Engine/source/T3D/missionMarker.cpp b/Engine/source/T3D/missionMarker.cpp index 7290ccc97..69ae9ab81 100644 --- a/Engine/source/T3D/missionMarker.cpp +++ b/Engine/source/T3D/missionMarker.cpp @@ -24,6 +24,7 @@ #include "console/consoleTypes.h" #include "core/color.h" #include "console/engineAPI.h" +#include "console/script.h" extern bool gEditingMission; IMPLEMENT_CO_DATABLOCK_V1(MissionMarkerData); @@ -350,12 +351,30 @@ SpawnSphere::SpawnSphere() mSphereWeight = 100.f; mIndoorWeight = 100.f; mOutdoorWeight = 100.f; + mSpawnIf.clear(); } IMPLEMENT_CALLBACK( SpawnSphere, onAdd, void, ( U32 objectId ), ( objectId ), "Called when the SpawnSphere is being created.\n" "@param objectId The unique SimObjectId generated when SpawnSphere is created (%%this in script)\n" ); +bool SpawnSphere::testCondition() +{ + if (mSpawnIf.isEmpty()) + return true; //we've got no tests to run so just do it + + //test the mapper plugged in condition line + String resVar = getIdString() + String(".result"); + Con::setBoolVariable(resVar.c_str(), false); + String command = resVar + "=" + mSpawnIf + ";"; + Con::evaluatef(command.c_str()); + if (Con::getBoolVariable(resVar.c_str()) == 1) + { + return true; + } + return false; +} + bool SpawnSphere::onAdd() { if(!Parent::onAdd()) @@ -368,7 +387,7 @@ bool SpawnSphere::onAdd() { onAdd_callback( getId()); - if (mAutoSpawn) + if (mAutoSpawn && testCondition()) spawnObject(); } @@ -484,6 +503,7 @@ void SpawnSphere::initPersistFields() "Command to execute immediately after spawning an object. New object id is stored in $SpawnObject. Max 255 characters." ); addField( "autoSpawn", TypeBool, Offset(mAutoSpawn, SpawnSphere), "Flag to spawn object as soon as SpawnSphere is created, true to enable or false to disable." ); + addField("spawnIf", TypeRealString, Offset(mSpawnIf, SpawnSphere), "evaluation condition to spawn (true/false)"); addField( "spawnTransform", TypeBool, Offset(mSpawnTransform, SpawnSphere), "Flag to set the spawned object's transform to the SpawnSphere's transform." ); endGroup( "Spawn" ); diff --git a/Engine/source/T3D/missionMarker.h b/Engine/source/T3D/missionMarker.h index b1d3731c0..a19348114 100644 --- a/Engine/source/T3D/missionMarker.h +++ b/Engine/source/T3D/missionMarker.h @@ -174,6 +174,8 @@ class SpawnSphere : public MissionMarker F32 mSphereWeight; F32 mIndoorWeight; F32 mOutdoorWeight; + String mSpawnIf; + bool testCondition(); SimObject* spawnObject(String additionalProps = String::EmptyString);