VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
13.3 - Managing Plans

Table of Contents

A DtPlan object represents the plan for an individual DtVrfObject.

In VR-Forces, there is one DtPlan created for each DtVrfObject that needs one. If a simulation object does not have a plan, no DtPlan gets created. The plan for a unit is associated with the DtVrfObject of the unit, and individual members of the unit might not have plans of their own.

The DtCgf class provides member functions for performing some of the more common operations for managing plans. These include functions for loading and saving scenarios (plans are implicitly loaded and saved as part of these functions), and a member function for assigning new plans to simulation objects. If you require more control over plans, you can access the Plan Manager for an object by calling DtVrfObject::vrfObjectPlanManager().

13.3.1 Loading a Plan File

To load a plan file into the Plan Manager, call DtVrfObjectPlanAdministrator::readPlanFile(). This instantiates a DtPlan object for each plan in the file and assigns it to the object’s DtVrfObjectPlanManager. This is call should generally only be made from DtCgf::loadScenario().

13.3.2 Saving Plans to a File

To save the plans to file, call DtVrfObjectPlanAdministrator::writePlanFile(). This call should generally only be made from DtCgf::saveScenario(). When you save a scenario, a plan file is one of the files that gets saved as part of the scenario. The name of the plan file is referenced in the scenario file.

13.3.3 Creating a New Plan Using API Calls

The Simple Plan (simplePlan) example (in ./examples/simplePlan) demonstrates how to create and assign a plan to a simulation object. In main.cxx, a simple plan consisting of a Set Speed request, a Wait Duration task, and a Move To Waypoint task, is created and assigned to a tank.

13.3.3.1 Creating and Initializing a New DtPlan

To create a new DtPlan, you can call the DtPlan constructor with no arguments. You can use this form of constructor when assigning plans through the DtCgf class. The name of the object passed into DtCgf::assignPlanByName() gets assigned to the DtPlan. You must call DtPlan::init() before you can use any other member functions in the DtPlan class. The init() function completes construction of the DtPlan object.

13.3.3.2 Adding Statements to a DtPlan

Plan statements are the individual items that get executed in a DtPlan. Statements represent tasks for the simulation object to perform, set data requests, or control-flow statements such as if(conditional expression)-then-else and when(conditional expression). They are derived from the DtSimStatement class (simStmt.h). In the simplePlan example, we create task and set data request statements. To create these kinds of statements, we first created the content for the statement (a derived type of DtSimTask or DtSetDataRequest), and then assigned it to a newly created corresponding DtTaskStmt or DtSetDataRequestStmt class.

A DtPlan contains a DtPlanBlock, which is the list of DtSimStatements in a plan. To add our new statements to the plan, we first obtained a pointer to the DtPlan’s main block of statements, and then added the statements to it. Because the plan assumes responsibility for deleting the memory associated with the plan statements, we cloned in the statements before adding them.

13.3.3.3 Assigning a DtPlan

Once you have created a DtPlan, you need to assign it to a particular DtVrfObject. The assignPlanByName() function associates the given DtPlan with the given DtVrfObject, referenced by name. The DtPlan will get executed as its DtVrfObjectPlanManager gets ticked.

13.3.4 Accessing the Plan for an Object

To look up the plan for an object, use the DtVrfObjectPlanManager::plan() accessor. If the object has not been assigned a plan, a NULL pointer is returned. For example, given a pointer to a DtVrfObject "myObject", the following code prints a message if the plan is complete. For information about accessing a certain DtVrfObject, please see 3.5.5 Looking Up Individual Objects.

DtPlan* plan = myObject->vrfObjectPlanManager()->plan();
if (plan && plan->isComplete())
{
DtInfo("Plan completed\n")'
}

[<< The Plan Manager] [Home] [Top of Page] [The Plan Administrator >>]


Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)