![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2000 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: retreatCtrl.h,v $ $Revision: 1.2 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00009 // 00010 //class DtRetreatController 00011 // 00012 //The retreating behavior of this controller was not intended to be 00013 //intelligent; it is meant to be an example of a controller invoked by a 00014 //DtUserTask. Because the currentTarget is used to determine which way to 00015 //flee, the behavior is best demonstrated tank vs. tank. Vehicles which do not 00016 //target other vehicles, such as utility vehicles, will simply flee towards 00017 //their current heading. Tanks will not flee from entities which they do 00018 //not target, such as helicopters. 00019 // 00020 //The retreat DtUserTask takes one argument from the "Argument 1" box 00021 //of the DtUserTask dialog. If it is set to "hold ground", entities set to 00022 //retreat will not start moving untill their underFire flag is set. 00023 // 00024 //To enable an entity to retreat, there must be an entry for 00025 //"retreat-controller" in its controller list in the object parameters 00026 //database. The following sample can be used: 00027 // 00028 // (controllers 00029 // ... 00030 // (retreat 00031 // (component-descriptor-type "component-descriptor") 00032 // (component-type "retreat-controller") 00033 // ) 00034 // ... 00035 // ) 00036 // 00037 // (connections 00038 // .... 00039 // (connect retreat:automotive-control powertrain:automotive-control) 00040 // ... 00041 // ) 00042 // 00043 00044 #include "vrfobjcore/singleTaskControllerComponent.h" 00045 #include "vrfmodel/gndAutoCntlr.h" 00046 00047 //String which uniquely identifies this controller 00048 const char TestRetreatControllerType[] = "retreat-controller"; 00049 00050 class DtRetreatController : public DtGroundAutoControllerComponent 00051 { 00052 public: 00053 //constructor 00054 DtRetreatController(const DtString & name, DtVrfObject* owner, 00055 DtSimManager * simManager, DtComponentDescriptor* desc = NULL, 00056 DtReaderWriterRegistry * parentRegistry = 0); 00057 00058 //destructor 00059 virtual ~DtRetreatController(); 00060 00061 //copy constructor 00062 DtRetreatController(const DtRetreatController& orig); 00063 00064 //assignment operator 00065 DtRetreatController& operator=(const DtRetreatController& orig); 00066 00067 //This returns the string TestRetreatControllerType (defined above), 00068 //used to uniquely identify the type of component. 00069 virtual DtString type() const; 00070 00071 //Register a callback for notification of DtUserTask tasks. 00072 virtual void registerTaskMsgCallbacks(); 00073 00074 //Callback function (registered in registerTaskMsgCallbacks()) for 00075 //DtRetreat task messages. Calls processRetreatTask() to actually handle 00076 //the task. 00077 static void retreatTaskCallback(DtSimMessage * msg, void * usr); 00078 00079 //Callback function (registered in registerTaskMsgCallbacks()) for 00080 //DtUserTask messages. Calls processUserTask() to actually handle 00081 //the task. 00082 static void userTaskCallback(DtSimMessage * msg, void * usr); 00083 00084 //Called by retreatTaskCallback() when a new DtRetreatTask message is 00085 //received. 00086 virtual void processRetreatTask(DtSimMessage * msg); 00087 00088 //Called by userTaskCallback() when a new DtRetreatTask message is 00089 //received. 00090 virtual void processUserTask(DtSimMessage * msg); 00091 00092 //Update control values 00093 virtual void tick(); 00094 00095 //This is called by the factory 00096 static DtSimComponent* creator(const DtString & name, DtVrfObject* owner, 00097 DtSimManager * simManager, DtComponentDescriptor* desc, 00098 DtReaderWriterRegistry * parentRegistry); 00099 00100 //Determine which way to flee based on the current target 00101 virtual double getHeading(); 00102 00103 //Returns the amount of fuel left. If no fuel left, can no longer retreat 00104 virtual double fuelLeft() const; 00105 00106 protected: 00107 DtReal myCurrentHeading; 00108 //determined by DtUserTask arg1, see above 00109 bool myHoldGround; 00110 }; 00111