VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
retreatCtrl.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2000 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 //
7 //class DtRetreatController
8 //
9 //The retreating behavior of this controller was not intended to be
10 //intelligent; it is meant to be an example of a controller invoked by a
11 //DtUserTask. Because the currentTarget is used to determine which way to
12 //flee, the behavior is best demonstrated tank vs. tank. Vehicles which do not
13 //target other vehicles, such as utility vehicles, will simply flee towards
14 //their current heading. Tanks will not flee from entities which they do
15 //not target, such as helicopters.
16 //
17 //The retreat DtUserTask takes one argument from the "Argument 1" box
18 //of the DtUserTask dialog. If it is set to "hold ground", entities set to
19 //retreat will not start moving untill their underFire flag is set.
20 //
21 //To enable an entity to retreat, there must be an entry for
22 //"retreat-controller" in its controller list in the object parameters
23 //database. The following sample can be used:
24 //
25 // (controllers
26 // ...
27 // (retreat
28 // (component-descriptor-type "component-descriptor")
29 // (component-type "retreat-controller")
30 // )
31 // ...
32 // )
33 //
34 // (connections
35 // ....
36 // (connect retreat:automotive-control powertrain:automotive-control)
37 // ...
38 // )
39 //
40 
43 
44 //String which uniquely identifies this controller
45 const char TestRetreatControllerType[] = "retreat-controller";
46 
48 {
49 public:
50  //constructor
53  DtReaderWriterRegistry * parentRegistry = 0);
54 
55  //destructor
56  virtual ~DtRetreatController() override;
57 
58  //copy constructor
60 
61  //assignment operator
63 
64  //This returns the string TestRetreatControllerType (defined above),
65  //used to uniquely identify the type of component.
66  virtual const char* type() const override;
67 
68  //Register a callback for notification of DtUserTask tasks.
69  virtual void registerTaskMsgCallbacks() override;
70 
71  //Callback function (registered in registerTaskMsgCallbacks()) for
72  //DtRetreat task messages. Calls processRetreatTask() to actually handle
73  //the task.
74  static void retreatTaskCallback(DtSimMessage * msg, void * usr);
75 
76  //Callback function (registered in registerTaskMsgCallbacks()) for
77  //DtUserTask messages. Calls processUserTask() to actually handle
78  //the task.
79  static void userTaskCallback(DtSimMessage * msg, void * usr);
80 
81  //Called by retreatTaskCallback() when a new DtRetreatTask message is
82  //received.
83  virtual void processRetreatTask(DtSimMessage * msg);
84 
85  //Called by userTaskCallback() when a new DtRetreatTask message is
86  //received.
87  virtual void processUserTask(DtSimMessage * msg);
88 
89  //Update control values
90  virtual void tick() override;
91 
92  //This is called by the factory
93  static DtSimComponent* creator(const DtString & name, DtLocalObject* owner,
94  DtSimulationServices * simManager, DtComponentDescriptor* desc,
95  DtReaderWriterRegistry * parentRegistry);
96 
97  //Determine which way to flee based on the current target
98  virtual double getHeading();
99 
100  //Returns the amount of fuel left. If no fuel left, can no longer retreat
101  virtual double fuelLeft() const;
102 
103 protected:
105  //determined by DtUserTask arg1, see above
107 };
108 
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *parentRegistry)
static void userTaskCallback(DtSimMessage *msg, void *usr)
virtual void processUserTask(DtSimMessage *msg)
virtual double fuelLeft() const
DtRetreatController & operator=(const DtRetreatController &orig)
A readable, writable type whose name is the name of a component and that has a list of component name...
Definition: componentDescriptor.h:49
virtual void tick() override
This gives the thread of control to the component. The component is ticked once each simulation from ...
Definition: readerWriterRegistry.h:39
Definition: retreatCtrl.h:47
const char TestRetreatControllerType[]
Definition: retreatCtrl.h:45
static void retreatTaskCallback(DtSimMessage *msg, void *usr)
bool myHoldGround
Definition: retreatCtrl.h:106
virtual const char * type() const override
Returns a string identifies the class type of component. Type values are defined in compTypes...
DtReal myCurrentHeading
Definition: retreatCtrl.h:104
File: simMsg.h.
Definition: simMessage.h:35
DtRetreatController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=NULL, DtReaderWriterRegistry *parentRegistry=0)
virtual void processRetreatTask(DtSimMessage *msg)
virtual void registerTaskMsgCallbacks() override
Central access point of all non-object-specific the services and managers that are available for use ...
Definition: simulationServices.h:96
The DtSimComponent class is the base class for the entire simulation model component hierarchy...
Definition: simComponent.h:89
VRF4API_METHOD const DtSimulationServices * simManager() const
This is the deprecated API that can be used as a reference to migrate 4.X code to 5...
Definition: simComponent.h:583
virtual ~DtRetreatController() override
virtual DtSymbolString name() const
Accessor for name of this readable/writable object.
virtual double getHeading()
DtGroundAutoControllerComponent is a base controller that holds capabilitites common to all automotiv...
Definition: groundAutoControllerComponent.h:34
A locally simulated VRF object.
Definition: localObject.h:98

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)