Browse Source

add conditional filter for missionmarker autospawn

AzaezelX 1 month ago
parent
commit
cbf407bc10
2 changed files with 23 additions and 1 deletions
  1. 21 1
      Engine/source/T3D/missionMarker.cpp
  2. 2 0
      Engine/source/T3D/missionMarker.h

+ 21 - 1
Engine/source/T3D/missionMarker.cpp

@@ -24,6 +24,7 @@
 #include "console/consoleTypes.h"
 #include "console/consoleTypes.h"
 #include "core/color.h"
 #include "core/color.h"
 #include "console/engineAPI.h"
 #include "console/engineAPI.h"
+#include "console/script.h"
 
 
 extern bool gEditingMission;
 extern bool gEditingMission;
 IMPLEMENT_CO_DATABLOCK_V1(MissionMarkerData);
 IMPLEMENT_CO_DATABLOCK_V1(MissionMarkerData);
@@ -350,12 +351,30 @@ SpawnSphere::SpawnSphere()
    mSphereWeight = 100.f;
    mSphereWeight = 100.f;
    mIndoorWeight = 100.f;
    mIndoorWeight = 100.f;
    mOutdoorWeight = 100.f;
    mOutdoorWeight = 100.f;
+   mSpawnIf.clear();
 }
 }
 
 
 IMPLEMENT_CALLBACK( SpawnSphere, onAdd, void, ( U32 objectId ), ( objectId ),
 IMPLEMENT_CALLBACK( SpawnSphere, onAdd, void, ( U32 objectId ), ( objectId ),
    "Called when the SpawnSphere is being created.\n"
    "Called when the SpawnSphere is being created.\n"
    "@param objectId The unique SimObjectId generated when SpawnSphere is created (%%this in script)\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()
 bool SpawnSphere::onAdd()
 {
 {
    if(!Parent::onAdd())
    if(!Parent::onAdd())
@@ -368,7 +387,7 @@ bool SpawnSphere::onAdd()
    {
    {
       onAdd_callback( getId());
       onAdd_callback( getId());
 
 
-      if (mAutoSpawn)
+      if (mAutoSpawn && testCondition())
          spawnObject();
          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." );
       "Command to execute immediately after spawning an object. New object id is stored in $SpawnObject.  Max 255 characters." );
    addField( "autoSpawn", TypeBool, Offset(mAutoSpawn, SpawnSphere),
    addField( "autoSpawn", TypeBool, Offset(mAutoSpawn, SpawnSphere),
       "Flag to spawn object as soon as SpawnSphere is created, true to enable or false to disable." );
       "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),
    addField( "spawnTransform", TypeBool, Offset(mSpawnTransform, SpawnSphere),
       "Flag to set the spawned object's transform to the SpawnSphere's transform." );
       "Flag to set the spawned object's transform to the SpawnSphere's transform." );
    endGroup( "Spawn" );
    endGroup( "Spawn" );

+ 2 - 0
Engine/source/T3D/missionMarker.h

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