aiConnection.cpp
Engine/source/T3D/aiConnection.cpp
Public Functions
ConsoleDocClass(AIConnection , "@brief Special client connection driven by an AI, rather than <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">human.\n\n</a>" "Unlike other net connections, <a href="/coding/class/classaiconnection/">AIConnection</a> is intended <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> run unmanned. Rather than " "gathering input from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> human using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> device, move events, triggers , and look events " "are driven through functions like <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AIConnection::setMove.\n\n</a>" "In addition <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> having its own set of functions <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> managing client move events, " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> member variable inherited by <a href="/coding/class/classgameconnection/">GameConnection</a> is toggle:mAIControlled. This is useful " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> server <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> determine <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> connection is AI driven via the function <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GameConnection::isAIControlled\n\n</a>" "<a href="/coding/class/classaiconnection/">AIConnection</a> is an alternative <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> manually creating an AI driven game object. When you " "want the server <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> manage AI, you will create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specific one from script using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> " "class like AIPlayer. If you do not want the server managing the AI and wish <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> simulate " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> complete client connection, you will use AIConnection\n\n." "To get more specific, <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> you want <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> strong alternative <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> AIPlayer, consider AIClient. <a href="/coding/class/classaiclient/">AIClient</a> inherits from AIConnection, " "contains quite <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> bit of functionality you will find in AIPlayer, and has its own <a href="/coding/class/classplayer/">Player</a> " "<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>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> AI client <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connection\n</a>" "% botConnection, you can locate this and any other <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AIConnections\n</a>" "//using the isAIControlled <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">function\n</a>" "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a>(%<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1acb559820d9ca11295b4500f179ef6392">i</a>=0;%<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1acb559820d9ca11295b4500f179ef6392">i</a>< ClientGroup.getCount();%<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1acb559820d9ca11295b4500f179ef6392">i</a>++)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " %client=ClientGroup.getObject(%<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1acb559820d9ca11295b4500f179ef6392">i</a>);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a>(%client.isAIControlled())\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "//React <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this AI controlled <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">client\n</a>" " }\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" " @note This is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> legacy class, which you are discouraged from using as it will " "most likely be deprecated in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> future version. For now it has been left in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> " "backwards compatibility with TGE and the old RTS Kit. Use <a href="/coding/class/classgameconnection/">GameConnection</a> " "and <a href="/coding/class/classaiplayer/">AIPlayer</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">instead.\n\n</a>" " @see GameConnection, <a href="/coding/class/classnetconnection/">NetConnection</a> , <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AIClient\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AI\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Networking\n</a>" )
DefineEngineMethod(AIConnection , getAddress , const char * , () , "" )
DefineEngineMethod(AIConnection , getFreeLook , bool , () , "getFreeLook()" "Is freelook on <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the current move?" )
DefineEngineMethod(AIConnection , getMove , F32 , (const char *field) , "(string field)" "Get the given field of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">move.\n\n</a>" "@param field One of {'x','y','z','yaw','pitch','roll'}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@returns The requested field on the current move." )
DefineEngineMethod(AIConnection , getTrigger , bool , (S32 idx) , "(int trigger)" "Is the given trigger set?" )
DefineEngineMethod(AIConnection , setFreeLook , void , (bool isFreeLook) , "(bool isFreeLook)" "Enable/disable freelook on the current move." )
DefineEngineMethod(AIConnection , setMove , void , (const char *field, F32 value) , "(string field, float <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a>)" "Set <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> field on the current <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">move.\n\n</a>" "@param field One of {'x','y','z','yaw','pitch','roll'}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/document_8h/#document_8h_1a071cf97155ba72ac9a1fc4ad7e63d481">Value</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set field to." )
DefineEngineMethod(AIConnection , setTrigger , void , (S32 idx, bool set) , "(int trigger, bool set)" "Set <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> trigger." )
DefineEngineStringlyVariadicFunction(aiConnect , S32 , 2 , 20 , "(...)" "@brief Creates <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> AIConnection, and passes arguments <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> its onConnect script <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">callback.\n\n</a>" " @returns The newly created <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AIConnection\n</a>" " @see <a href="/coding/class/classgameconnection/">GameConnection</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> parameter <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">information\n</a>" " @ingroup AI" )
Construct and connect an AI connection object.
Detailed Description
Public Functions
ConsoleDocClass(AIConnection , "@brief Special client connection driven by an AI, rather than <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">human.\n\n</a>" "Unlike other net connections, <a href="/coding/class/classaiconnection/">AIConnection</a> is intended <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> run unmanned. Rather than " "gathering input from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> human using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> device, move events, triggers , and look events " "are driven through functions like <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AIConnection::setMove.\n\n</a>" "In addition <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> having its own set of functions <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> managing client move events, " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> member variable inherited by <a href="/coding/class/classgameconnection/">GameConnection</a> is toggle:mAIControlled. This is useful " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> server <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> determine <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> connection is AI driven via the function <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GameConnection::isAIControlled\n\n</a>" "<a href="/coding/class/classaiconnection/">AIConnection</a> is an alternative <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> manually creating an AI driven game object. When you " "want the server <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> manage AI, you will create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specific one from script using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> " "class like AIPlayer. If you do not want the server managing the AI and wish <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> simulate " "<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> complete client connection, you will use AIConnection\n\n." "To get more specific, <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> you want <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> strong alternative <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> AIPlayer, consider AIClient. <a href="/coding/class/classaiclient/">AIClient</a> inherits from AIConnection, " "contains quite <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> bit of functionality you will find in AIPlayer, and has its own <a href="/coding/class/classplayer/">Player</a> " "<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>" "//Create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> AI client <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connection\n</a>" "% botConnection, you can locate this and any other <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AIConnections\n</a>" "//using the isAIControlled <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">function\n</a>" "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a>(%<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1acb559820d9ca11295b4500f179ef6392">i</a>=0;%<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1acb559820d9ca11295b4500f179ef6392">i</a>< ClientGroup.getCount();%<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1acb559820d9ca11295b4500f179ef6392">i</a>++)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " %client=ClientGroup.getObject(%<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1acb559820d9ca11295b4500f179ef6392">i</a>);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a>(%client.isAIControlled())\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "//React <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this AI controlled <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">client\n</a>" " }\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" " @note This is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> legacy class, which you are discouraged from using as it will " "most likely be deprecated in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> future version. For now it has been left in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> " "backwards compatibility with TGE and the old RTS Kit. Use <a href="/coding/class/classgameconnection/">GameConnection</a> " "and <a href="/coding/class/classaiplayer/">AIPlayer</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">instead.\n\n</a>" " @see GameConnection, <a href="/coding/class/classnetconnection/">NetConnection</a> , <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AIClient\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AI\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Networking\n</a>" )
DefineEngineMethod(AIConnection , getAddress , const char * , () , "" )
DefineEngineMethod(AIConnection , getFreeLook , bool , () , "getFreeLook()" "Is freelook on <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the current move?" )
DefineEngineMethod(AIConnection , getMove , F32 , (const char *field) , "(string field)" "Get the given field of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">move.\n\n</a>" "@param field One of {'x','y','z','yaw','pitch','roll'}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@returns The requested field on the current move." )
DefineEngineMethod(AIConnection , getTrigger , bool , (S32 idx) , "(int trigger)" "Is the given trigger set?" )
DefineEngineMethod(AIConnection , setFreeLook , void , (bool isFreeLook) , "(bool isFreeLook)" "Enable/disable freelook on the current move." )
DefineEngineMethod(AIConnection , setMove , void , (const char *field, F32 value) , "(string field, float <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a>)" "Set <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> field on the current <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">move.\n\n</a>" "@param field One of {'x','y','z','yaw','pitch','roll'}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/document_8h/#document_8h_1a071cf97155ba72ac9a1fc4ad7e63d481">Value</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set field to." )
DefineEngineMethod(AIConnection , setTrigger , void , (S32 idx, bool set) , "(int trigger, bool set)" "Set <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> trigger." )
DefineEngineStringlyVariadicFunction(aiConnect , S32 , 2 , 20 , "(...)" "@brief Creates <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> AIConnection, and passes arguments <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> its onConnect script <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">callback.\n\n</a>" " @returns The newly created <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AIConnection\n</a>" " @see <a href="/coding/class/classgameconnection/">GameConnection</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> parameter <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">information\n</a>" " @ingroup AI" )
Construct and connect an AI connection object.
IMPLEMENT_CONOBJECT(AIConnection )
moveClamp(F32 v)
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 "T3D/aiConnection.h" 25#include "console/engineAPI.h" 26 27IMPLEMENT_CONOBJECT( AIConnection ); 28 29ConsoleDocClass( AIConnection, 30 "@brief Special client connection driven by an AI, rather than a human.\n\n" 31 32 "Unlike other net connections, AIConnection is intended to run unmanned. Rather than " 33 "gathering input from a human using a device, move events, triggers, and look events " 34 "are driven through functions like AIConnection::setMove.\n\n" 35 36 "In addition to having its own set of functions for managing client move events, " 37 "a member variable inherited by GameConnection is toggle: mAIControlled. This is useful " 38 "for a server to determine if a connection is AI driven via the function GameConnection::isAIControlled\n\n" 39 40 "AIConnection is an alternative to manually creating an AI driven game object. When you " 41 "want the server to manage AI, you will create a specific one from script using a " 42 "class like AIPlayer. If you do not want the server managing the AI and wish to simulate " 43 "a complete client connection, you will use AIConnection\n\n." 44 45 "To get more specific, if you want a strong alternative to AIPlayer (and wish to make use " 46 "of the AIConnection structure), consider AIClient. AIClient inherits from AIConnection, " 47 "contains quite a bit of functionality you will find in AIPlayer, and has its own Player " 48 "object.\n\n" 49 50 "@tsexample\n" 51 "// Create a new AI client connection\n" 52 "%botConnection = aiConnect(\"MasterBlaster\" @ %i, -1, 0.5, false, \"SDF\", 1.0);\n\n" 53 "// In another area of the code, you can locate this and any other AIConnections\n" 54 "// using the isAIControlled function\n" 55 "for(%i = 0; %i < ClientGroup.getCount(); %i++)\n" 56 "{\n" 57 " %client = ClientGroup.getObject(%i);\n" 58 " if(%client.isAIControlled())\n" 59 " {\n" 60 " // React to this AI controlled client\n" 61 " }\n" 62 "}\n" 63 "@endtsexample\n\n" 64 65 "@note This is a legacy class, which you are discouraged from using as it will " 66 "most likely be deprecated in a future version. For now it has been left in for " 67 "backwards compatibility with TGE and the old RTS Kit. Use GameConnection " 68 "and AIPlayer instead.\n\n" 69 70 "@see GameConnection, NetConnection, AIClient\n\n" 71 72 "@ingroup AI\n" 73 "@ingroup Networking\n" 74); 75//----------------------------------------------------------------------------- 76 77AIConnection::AIConnection() { 78 mAIControlled = true; 79 mMove = NullMove; 80} 81 82 83//----------------------------------------------------------------------------- 84 85void AIConnection::clearMoves( U32 ) 86{ 87 // Clear the pending move list. This connection generates moves 88 // on the fly, so there are never any pending moves. 89} 90 91void AIConnection::setMove(Move* m) 92{ 93 mMove = *m; 94} 95 96const Move& AIConnection::getMove() 97{ 98 return mMove; 99} 100 101/// Retrive the pending moves 102/** 103 * The GameConnection base class queues moves for delivery to the 104 * controll object. This function is normally used to retrieve the 105 * queued moves recieved from the client. The AI connection does not 106 * have a connected client and simply generates moves on-the-fly 107 * base on it's current state. 108 */ 109U32 AIConnection::getMoveList( Move **lngMove, U32 *numMoves ) 110{ 111 *numMoves = 1; 112 *lngMove = &mMove; 113 return *numMoves; 114} 115 116 117//----------------------------------------------------------------------------- 118// Console functions & methods 119//----------------------------------------------------------------------------- 120 121//----------------------------------------------------------------------------- 122 123static inline F32 moveClamp(F32 v) 124{ 125 // Support function to convert/clamp the input into a move rotation 126 // which only allows 0 -> M_2PI. 127 F32 a = mClampF(v, -M_2PI_F, M_2PI_F); 128 return (a < 0) ? a + M_2PI_F : a; 129} 130 131 132//----------------------------------------------------------------------------- 133/// Construct and connect an AI connection object 134DefineEngineStringlyVariadicFunction(aiConnect, S32 , 2, 20, "(...)" 135 "@brief Creates a new AIConnection, and passes arguments to its onConnect script callback.\n\n" 136 "@returns The newly created AIConnection\n" 137 "@see GameConnection for parameter information\n" 138 "@ingroup AI") 139{ 140 // Create the connection 141 AIConnection *aiConnection = new AIConnection(); 142 aiConnection->registerObject(); 143 144 // Add the connection to the client group 145 SimGroup *g = Sim::getClientGroup(); 146 g->addObject( aiConnection ); 147 148 // Prep the arguments for the console exec... 149 // Make sure and leav args[1] empty. 150 const char* args[21]; 151 args[0] = "onConnect"; 152 args[1] = NULL; // Filled in later 153 for (S32 i = 1; i < argc; i++) 154 args[i + 1] = argv[i]; 155 156 // Execute the connect console function, this is the same 157 // onConnect function invoked for normal client connections 158 Con::execute(aiConnection, argc + 1, args); 159 return aiConnection->getId(); 160} 161 162 163//----------------------------------------------------------------------------- 164DefineEngineMethod(AIConnection, setMove, void, (const char * field, F32 value), ,"(string field, float value)" 165 "Set a field on the current move.\n\n" 166 "@param field One of {'x','y','z','yaw','pitch','roll'}\n" 167 "@param value Value to set field to.") 168{ 169 Move move = object->getMove(); 170 171 // Ok, a little slow for now, but this is just an example.. 172 if (!dStricmp(field,"x")) 173 move.x = mClampF(value,-1,1); 174 else 175 if (!dStricmp(field,"y")) 176 move.y = mClampF(value,-1,1); 177 else 178 if (!dStricmp(field,"z")) 179 move.z = mClampF(value,-1,1); 180 else 181 if (!dStricmp(field,"yaw")) 182 move.yaw = moveClamp(value); 183 else 184 if (!dStricmp(field,"pitch")) 185 move.pitch = moveClamp(value); 186 else 187 if (!dStricmp(field,"roll")) 188 move.roll = moveClamp(value); 189 190 // 191 object->setMove(&move); 192} 193 194DefineEngineMethod(AIConnection,getMove,F32, (const char * field), ,"(string field)" 195 "Get the given field of a move.\n\n" 196 "@param field One of {'x','y','z','yaw','pitch','roll'}\n" 197 "@returns The requested field on the current move.") 198{ 199 const Move& move = object->getMove(); 200 if (!dStricmp(field,"x")) 201 return move.x; 202 if (!dStricmp(field,"y")) 203 return move.y; 204 if (!dStricmp(field,"z")) 205 return move.z; 206 if (!dStricmp(field,"yaw")) 207 return move.yaw; 208 if (!dStricmp(field,"pitch")) 209 return move.pitch; 210 if (!dStricmp(field,"roll")) 211 return move.roll; 212 return 0; 213} 214 215 216DefineEngineMethod(AIConnection,setFreeLook,void,(bool isFreeLook), ,"(bool isFreeLook)" 217 "Enable/disable freelook on the current move.") 218{ 219 Move move = object->getMove(); 220 move.freeLook = isFreeLook; 221 object->setMove(&move); 222} 223 224DefineEngineMethod(AIConnection, getFreeLook, bool, (), ,"getFreeLook()" 225 "Is freelook on for the current move?") 226{ 227 return object->getMove().freeLook; 228} 229 230 231//----------------------------------------------------------------------------- 232 233DefineEngineMethod(AIConnection,setTrigger,void, (S32 idx, bool set), ,"(int trigger, bool set)" 234 "Set a trigger.") 235{ 236 if (idx >= 0 && idx < MaxTriggerKeys) 237 { 238 Move move = object->getMove(); 239 move.trigger[idx] = set; 240 object->setMove(&move); 241 } 242} 243 244DefineEngineMethod(AIConnection,getTrigger,bool, (S32 idx), ,"(int trigger)" 245 "Is the given trigger set?") 246{ 247 if (idx >= 0 && idx < MaxTriggerKeys) 248 return object->getMove().trigger[idx]; 249 return false; 250} 251 252 253//----------------------------------------------------------------------------- 254 255DefineEngineMethod(AIConnection,getAddress,const char*,(), ,"") 256{ 257 // Override the netConnection method to return to indicate 258 // this is an ai connection. 259 return "ai:local"; 260} 261