sim.cpp

Engine/source/console/sim.cpp

More...

Namespaces:

namespace

Public Functions

_spawnObject1("@brief Global function used <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> spawning any type of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" "Note: This is separate from <a href="/coding/class/classspawnsphere/#classspawnsphere_1a21edfe9c736cf3533069e655a1e091b2">SpawnSphere::spawnObject</a>(). This function is not called off any " "other class and uses different parameters than the <a href="/coding/class/classspawnsphere/">SpawnSphere</a>'s function. In the source, " "<a href="/coding/class/classspawnsphere/#classspawnsphere_1a21edfe9c736cf3533069e655a1e091b2">SpawnSphere::spawnObject</a>() actually calls this function and passes its properties " "(spawnClass, spawnDatablock, etc).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @param class Mandatory field specifying the object class, such as <a href="/coding/class/classplayer/">Player</a> or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">TSStatic.\n\n</a>" " @param datablock Field specifying the object 's datablock, optional <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> objects such as TSStatic, mandatory <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> game objects like <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Player.\n\n</a>" " @param name Optional field specifying <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> name <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this instance of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" " @param properties Optional set of parameters applied <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the spawn object during <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">creation.\n\n</a>" " @param script Optional command(s) <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> execute when spawning an <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Set the parameters <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the spawn <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">function\n</a>" "% objectClass, <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> , "bool spawnObject(class [, dataBlock, name, properties, script]);" )
ConsoleFunctionGroupBegin(SimFunctions , "Functions relating <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> Sim." )
ConsoleFunctionGroupEnd(SimFunctions )
DefineEngineFunction(cancel , void , (S32 eventId) , "cancel(eventId)" )
DefineEngineFunction(cancelAll , void , (const char *objectId) , "cancelAll(objectId): cancel pending events on the specified object. Events will be automatically cancelled <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> object is deleted." )
DefineEngineFunction(getEventTimeLeft , S32 , (S32 scheduleId) , "getEventTimeLeft(scheduleId) Get the time left in ms until this event will trigger." )
DefineEngineFunction(getScheduleDuration , S32 , (S32 scheduleId) , "getScheduleDuration(%scheduleId);" )
DefineEngineFunction(getTimeSinceStart , S32 , (S32 scheduleId) , "getTimeSinceStart(%scheduleId);" )
DefineEngineFunction(getUniqueInternalName , const char * , (const char *baseName, const char *setString, bool searchChildren) , "( String baseName, <a href="/coding/class/classsimset/">SimSet</a> set, bool searchChildren )\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@brief Returns <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique unused internal name within the <a href="/coding/class/classsimset/">SimSet</a>/Group based on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given base <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">name.\n\n</a>" "@note Currently only used by <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">editors\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Editors\n</a>" "@internal" )
DefineEngineFunction(getUniqueName , const char * , (const char *baseName) , "( String baseName )\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@brief Returns <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique unused <a href="/coding/class/classsimobject/">SimObject</a> name based on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given base <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">name.\n\n</a>" "@baseName Name <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> conver <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique string <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> another instance <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">exists\n</a>" "@note Currently only used by <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">editors\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Editors\n</a>" "@internal" )
DefineEngineFunction(isEventPending , bool , (S32 scheduleId) , "isEventPending(%scheduleId);" )
DefineEngineFunction(isObject , bool , (const char *objectName) , "isObject(object)" )
DefineEngineFunction(isValidObjectName , bool , (const char *name) , "( string name )" "@brief Return true <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the given name makes <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> valid object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">name.\n\n</a>" "@param name Name of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> name is allowed)
DefineEngineFunction(nameToID , S32 , (const char *objectName) , "nameToID(object)" )
DefineEngineFunction(spawnObject , S32 , (const char *spawnClass, const char *spawnDataBlock, const char *spawnName, const char *spawnProperties, const char *spawnScript) , ("","","","") , "spawnObject(class [, dataBlock, name, properties, script])" "@hide" )
DefineEngineStringlyVariadicFunction(schedule , S32 , 4 , 0 , "schedule(time, refobject|0, command, <arg1...argN>)" )

Detailed Description

Public Variables

 MODULE_END 
 MODULE_INIT 
 MODULE_SHUTDOWN 

Public Functions

_spawnObject1("@brief Global function used <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> spawning any type of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" "Note: This is separate from <a href="/coding/class/classspawnsphere/#classspawnsphere_1a21edfe9c736cf3533069e655a1e091b2">SpawnSphere::spawnObject</a>(). This function is not called off any " "other class and uses different parameters than the <a href="/coding/class/classspawnsphere/">SpawnSphere</a>'s function. In the source, " "<a href="/coding/class/classspawnsphere/#classspawnsphere_1a21edfe9c736cf3533069e655a1e091b2">SpawnSphere::spawnObject</a>() actually calls this function and passes its properties " "(spawnClass, spawnDatablock, etc).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @param class Mandatory field specifying the object class, such as <a href="/coding/class/classplayer/">Player</a> or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">TSStatic.\n\n</a>" " @param datablock Field specifying the object 's datablock, optional <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> objects such as TSStatic, mandatory <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> game objects like <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Player.\n\n</a>" " @param name Optional field specifying <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> name <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this instance of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" " @param properties Optional set of parameters applied <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the spawn object during <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">creation.\n\n</a>" " @param script Optional command(s) <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> execute when spawning an <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Set the parameters <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the spawn <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">function\n</a>" "% objectClass, <a href="/coding/file/typesx86unix_8h/#typesx86unix_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> , "bool spawnObject(class [, dataBlock, name, properties, script]);" )

ConsoleFunctionGroupBegin(SimFunctions , "Functions relating <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> Sim." )

ConsoleFunctionGroupEnd(SimFunctions )

DefineEngineFunction(cancel , void , (S32 eventId) , "cancel(eventId)" )

DefineEngineFunction(cancelAll , void , (const char *objectId) , "cancelAll(objectId): cancel pending events on the specified object. Events will be automatically cancelled <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> object is deleted." )

DefineEngineFunction(getEventTimeLeft , S32 , (S32 scheduleId) , "getEventTimeLeft(scheduleId) Get the time left in ms until this event will trigger." )

DefineEngineFunction(getScheduleDuration , S32 , (S32 scheduleId) , "getScheduleDuration(%scheduleId);" )

DefineEngineFunction(getTimeSinceStart , S32 , (S32 scheduleId) , "getTimeSinceStart(%scheduleId);" )

DefineEngineFunction(getUniqueInternalName , const char * , (const char *baseName, const char *setString, bool searchChildren) , "( String baseName, <a href="/coding/class/classsimset/">SimSet</a> set, bool searchChildren )\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@brief Returns <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique unused internal name within the <a href="/coding/class/classsimset/">SimSet</a>/Group based on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given base <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">name.\n\n</a>" "@note Currently only used by <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">editors\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Editors\n</a>" "@internal" )

DefineEngineFunction(getUniqueName , const char * , (const char *baseName) , "( String baseName )\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@brief Returns <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique unused <a href="/coding/class/classsimobject/">SimObject</a> name based on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given base <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">name.\n\n</a>" "@baseName Name <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> conver <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique string <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> another instance <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">exists\n</a>" "@note Currently only used by <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">editors\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Editors\n</a>" "@internal" )

DefineEngineFunction(isEventPending , bool , (S32 scheduleId) , "isEventPending(%scheduleId);" )

DefineEngineFunction(isObject , bool , (const char *objectName) , "isObject(object)" )

DefineEngineFunction(isValidObjectName , bool , (const char *name) , "( string name )" "@brief Return true <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the given name makes <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> valid object <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">name.\n\n</a>" "@param name Name of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> name is allowed)

DefineEngineFunction(nameToID , S32 , (const char *objectName) , "nameToID(object)" )

DefineEngineFunction(spawnObject , S32 , (const char *spawnClass, const char *spawnDataBlock, const char *spawnName, const char *spawnProperties, const char *spawnScript) , ("","","","") , "spawnObject(class [, dataBlock, name, properties, script])" "@hide" )

DefineEngineStringlyVariadicFunction(schedule , S32 , 4 , 0 , "schedule(time, refobject|0, command, <arg1...argN>)" )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "console/console.h"
 25#include "console/engineAPI.h"
 26#include "console/sim.h"
 27#include "console/simEvents.h"
 28#include "console/simObject.h"
 29#include "console/simSet.h"
 30#include "core/module.h"
 31
 32
 33MODULE_BEGIN( Sim )
 34
 35   // Note: tho the SceneGraphs are created after the Manager, delete them after, rather
 36   //  than before to make sure that all the objects are removed from the graph.
 37   MODULE_INIT_AFTER( GFX )
 38   MODULE_SHUTDOWN_BEFORE( GFX )
 39
 40   MODULE_INIT
 41   {
 42      Sim::init();
 43   }
 44   
 45   MODULE_SHUTDOWN
 46   {
 47      Sim::shutdown();
 48   }
 49
 50MODULE_END;
 51
 52
 53
 54namespace Sim
 55{
 56   // Don't forget to InstantiateNamed* in simManager.cc - DMM
 57   ImplementNamedSet(ActiveActionMapSet)
 58   ImplementNamedSet(GhostAlwaysSet)
 59   ImplementNamedSet(WayPointSet)
 60   ImplementNamedSet(fxReplicatorSet)
 61   ImplementNamedSet(fxFoliageSet)
 62   ImplementNamedSet(BehaviorSet)
 63   ImplementNamedSet(MaterialSet)
 64   ImplementNamedSet(SFXSourceSet)
 65   ImplementNamedSet(SFXDescriptionSet)
 66   ImplementNamedSet(SFXTrackSet)
 67   ImplementNamedSet(SFXEnvironmentSet)
 68   ImplementNamedSet(SFXStateSet)
 69   ImplementNamedSet(SFXAmbienceSet)
 70   ImplementNamedSet(TerrainMaterialSet)
 71   ImplementNamedSet(DataBlockSet);
 72   ImplementNamedGroup(ActionMapGroup)
 73   ImplementNamedGroup(ClientGroup)
 74   ImplementNamedGroup(GuiGroup)
 75   ImplementNamedGroup(GuiDataGroup)
 76   ImplementNamedGroup(TCPGroup)
 77   ImplementNamedGroup(SFXParameterGroup);
 78
 79   //groups created on the client
 80   ImplementNamedGroup(ClientConnectionGroup)
 81   ImplementNamedSet(sgMissionLightingFilterSet)
 82}
 83
 84//-----------------------------------------------------------------------------
 85// Console Functions
 86//-----------------------------------------------------------------------------
 87
 88ConsoleFunctionGroupBegin ( SimFunctions, "Functions relating to Sim.");
 89
 90DefineEngineFunction( nameToID, S32, (const char * objectName), ,"nameToID(object)")
 91{
 92   SimObject *obj = Sim::findObject(objectName);
 93   if(obj)
 94      return obj->getId();
 95   else
 96      return -1;
 97}
 98
 99DefineEngineFunction( isObject, bool, (const char * objectName), ,"isObject(object)")
100{
101   if (!String::compare(objectName, "0") || !String::compare(objectName, ""))
102      return false;
103   else
104      return (Sim::findObject(objectName) != NULL);
105}
106
107ConsoleDocFragment _spawnObject1(
108   "@brief Global function used for spawning any type of object.\n\n"
109
110   "Note: This is separate from SpawnSphere::spawnObject(). This function is not called off any "
111   "other class and uses different parameters than the SpawnSphere's function. In the source, "
112   "SpawnSphere::spawnObject() actually calls this function and passes its properties "
113   "(spawnClass, spawnDatablock, etc).\n\n"
114
115   "@param class Mandatory field specifying the object class, such as Player or TSStatic.\n\n"
116   "@param datablock Field specifying the object's datablock, optional for objects such as TSStatic, mandatory for game objects like Player.\n\n"
117   "@param name Optional field specifying a name for this instance of the object.\n\n"
118   "@param properties Optional set of parameters applied to the spawn object during creation.\n\n"
119   "@param script Optional command(s) to execute when spawning an object.\n\n"
120
121   "@tsexample\n"
122      "// Set the parameters for the spawn function\n"
123      "%objectClass = \"Player\";\n"
124      "%objectDatablock = \"DefaultPlayerData\";\n"
125      "%objectName = \"PlayerName\";\n"
126      "%additionalProperties = \"health = \\\"0\\\";\"; // Note the escape sequence \\ in front of quotes\n"
127      "%spawnScript = \"echo(\\\"Player Spawned\\\");\" // Note the escape sequence \\ in front of quotes\n"
128      "// Spawn with the engine's Sim::spawnObject() function\n"
129      "%player = spawnObject(%objectClass, %objectDatablock, %objectName, %additionalProperties, %spawnScript);\n"
130   "@endtsexample\n\n"
131
132   "@ingroup Game",
133   NULL,
134   "bool spawnObject(class [, dataBlock, name, properties, script]);"
135);
136
137DefineEngineFunction( spawnObject, S32, (   const char * spawnClass
138                                         ,   const char * spawnDataBlock
139                                         ,   const char * spawnName
140                                         ,   const char * spawnProperties
141                                         ,   const char * spawnScript 
142                                         ),("","","","") ,"spawnObject(class [, dataBlock, name, properties, script])"
143            "@hide")
144{
145   SimObject* spawnObject = Sim::spawnObject(spawnClass, spawnDataBlock, spawnName, spawnProperties, spawnScript);
146
147   if (spawnObject)
148      return spawnObject->getId();
149   else
150      return -1;
151}
152
153DefineEngineFunction( cancel, void, (S32 eventId), ,"cancel(eventId)")
154{
155   Sim::cancelEvent(eventId);
156}
157
158DefineEngineFunction( cancelAll, void, (const char * objectId), ,"cancelAll(objectId): cancel pending events on the specified object.  Events will be automatically cancelled if object is deleted.")
159{
160   Sim::cancelPendingEvents(Sim::findObject(objectId));
161}
162
163DefineEngineFunction( isEventPending, bool, (S32 scheduleId), ,"isEventPending(%scheduleId);")
164{
165   return Sim::isEventPending(scheduleId);
166}
167
168DefineEngineFunction( getEventTimeLeft, S32, (S32 scheduleId), ,"getEventTimeLeft(scheduleId) Get the time left in ms until this event will trigger.")
169{
170   return Sim::getEventTimeLeft(scheduleId);
171}
172
173DefineEngineFunction( getScheduleDuration, S32, (S32 scheduleId), ,"getScheduleDuration(%scheduleId);" )
174{
175   S32 ret = Sim::getScheduleDuration(scheduleId);
176   return ret;
177}
178
179DefineEngineFunction( getTimeSinceStart, S32, (S32 scheduleId), ,"getTimeSinceStart(%scheduleId);" )
180{
181   S32 ret = Sim::getTimeSinceStart(scheduleId);
182   return ret;
183}
184
185DefineEngineStringlyVariadicFunction(schedule, S32, 4, 0, "schedule(time, refobject|0, command, <arg1...argN>)")
186{
187   U32 timeDelta = U32(dAtof(argv[1]));
188   SimObject *refObject = Sim::findObject(argv[2]);
189   if(!refObject)
190   {
191      if(argv[2][0] != '0')
192         return 0;
193
194      refObject = Sim::getRootGroup();
195   }
196   SimConsoleEvent *evt = new SimConsoleEvent(argc - 3, argv + 3, false);
197
198   S32 ret = Sim::postEvent(refObject, evt, Sim::getCurrentTime() + timeDelta);
199   // #ifdef DEBUG
200   //    Con::printf("ref %s schedule(%s) = %d", argv[2], argv[3], ret);
201   //    Con::executef( "backtrace");
202   // #endif
203   return ret;
204}
205
206DefineEngineFunction( getUniqueName, const char*, (const char * baseName), ,
207   "( String baseName )\n"
208   "@brief Returns a unique unused SimObject name based on a given base name.\n\n"
209   "@baseName Name to conver to a unique string if another instance exists\n"
210   "@note Currently only used by editors\n"
211   "@ingroup Editors\n"
212   "@internal")
213{
214   String outName = Sim::getUniqueName( baseName );
215   
216   if ( outName.isEmpty() )
217      return NULL;
218
219   char *buffer = Con::getReturnBuffer( outName.size() );
220   dStrcpy( buffer, outName, outName.size() );
221
222   return buffer;
223}
224
225DefineEngineFunction( getUniqueInternalName, const char*, (const char * baseName, const char * setString, bool searchChildren), ,
226   "( String baseName, SimSet set, bool searchChildren )\n"
227   "@brief Returns a unique unused internal name within the SimSet/Group based on a given base name.\n\n"
228   "@note Currently only used by editors\n"
229   "@ingroup Editors\n"
230   "@internal")
231{
232   SimSet *set;
233   if ( !Sim::findObject( setString, set ) )
234   {
235      Con::errorf( "getUniqueInternalName() - invalid parameter for SimSet." );
236      return NULL;
237   }
238
239   String outName = Sim::getUniqueInternalName( baseName, set, searchChildren );
240
241   if ( outName.isEmpty() )
242      return NULL;
243
244   char *buffer = Con::getReturnBuffer( outName.size() );
245   dStrcpy( buffer, outName, outName.size() );
246
247   return buffer;
248}
249
250DefineEngineFunction( isValidObjectName, bool, (const char * name), , "( string name )"
251            "@brief Return true if the given name makes for a valid object name.\n\n"
252            "@param name Name of object\n"
253            "@return True if name is allowed, false if denied (usually because it starts with a number, _, or invalid character"
254            "@ingroup Console")
255{
256   return Sim::isValidObjectName( name );
257}
258
259ConsoleFunctionGroupEnd( SimFunctions );
260