Merge pull request #1586 from Azaezel/alpha41/missionMarkerFilter
Some checks failed
Linux Build / ${{matrix.config.name}} (map[build_type:Release cc:gcc cxx:g++ generator:Ninja name:Ubuntu Latest GCC]) (push) Has been cancelled
MacOSX Build / ${{matrix.config.name}} (map[build_type:Release cc:clang cxx:clang++ generator:Ninja name:MacOSX Latest Clang]) (push) Has been cancelled
Windows Build / ${{matrix.config.name}} (map[build_type:Release cc:cl cxx:cl environment_script:C:/Program Files (x86)/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat generator:Visual Studio 17 2022 name:Windows Latest MSVC]) (push) Has been cancelled

add conditional filter for missionmarker autospawn
This commit is contained in:
Brian Roberts 2025-11-13 15:24:33 -06:00 committed by GitHub
commit 7e64493dbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

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

View file

@ -174,6 +174,8 @@ class SpawnSphere : public MissionMarker
F32 mSphereWeight;
F32 mIndoorWeight;
F32 mOutdoorWeight;
String mSpawnIf;
bool testCondition();
SimObject* spawnObject(String additionalProps = String::EmptyString);