VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Simple Plan (simplePlan)

Table of Contents

The Simple Plan example demonstrates the following:

The Simple Plan example is loaded as a plugin and demonstrates plan creation and assignment of this plan to a pre-exisiting entity. It also demonstrates creating and registering a trigger area that adds a trigger statement to the object's plan when the object coincides with the area. Finally, it shows how to create and register a console command to send the plan to the specified object.

How to Run the Example

This example demonstrates how to programatically create a plan for an entity in a plugin.

Usage

In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the simplePlan plugin to load.

To view the new behavior:

  1. Start VR-Forces GUI and SIM.
  2. Load the simplePlan.scnx scenario from the developer_toolkit_examples.
  3. Verify in the GUI that the M1A2 entity does not have a plan assigned.
  4. Type the "sendPlan" command in the SIM console window, and press Enter.
  5. In the GUI, right-click the M1A2 entity to view that the entity has been assigned a plan.
  6. Play the scenario and observe that the M1A2 entity starts executing the plan.
  7. As the entitiy enters the trigger area (Area 2), the triggered action takes place before the entity resumes the original plan.
  Note: In Linux - you should not use the Launcher to start the SIM and the GUI. 
  You need to start the vrfSim and vrfGui, manually - from two separate terminal windows.
  The necessary front-end and back-end command line arguments can be copied from the Launcher UI.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2017 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
// VR-Forces includes
#include "vrfcgf/cgf.h"
//for conditional expression
#include "vrfplan/ifStmt.h"
// VR-Link includes
#include <vlutil/vlPrint.h>
#include <vlutil/vlProcessControl.h>
#include <vl/hostStructs.h>
static DtCgf* theCgf = 0;
/*
sendPlan command should:
-Get a M1A2 tank entity
-Get the area(s)
-Get all waypoints(Alpha, Beta, Gamma)
-Create a simple plan for the tank:
-Set tank's speed
-Add a wait task
-Add a move-to Alpha waypoint (conditional)
-Add a move-to Beta waypoint (conditional)
-Register and add a trigger statement to the plan
-Assign the plan to the tank
*/
class DtSendPlanCommand : public DtConsoleCommand
{
public:
virtual ~DtSendPlanCommand() override { };
//Execute the command.
//\return True on success of the command.
virtual bool execute(const DtString& parameters) override
{
//Object Manager
//Get the tank object
DtUUID myTankName("M1A2 1");
DtSimObjectReference myEntity = objMgr->lookup(myTankName);
//Get Area1 for testing
DtUUID myFirstArea("Area 1");
DtSimObjectReference areaStart = objMgr->lookup(myFirstArea);
//Get Area2 for trigger task
DtUUID myTriggerArea("Area 2");
DtSimObjectReference triggerArea = objMgr->lookup(myTriggerArea);
//Get the Alpha Waypoint
DtUUID myAlpha("Alpha");
DtSimObjectReference alpha = objMgr->lookup(myAlpha);
//Get the Beta Waypoint
DtUUID myBeta("Beta");
DtSimObjectReference beta = objMgr->lookup(myBeta);
//Get the Gamma Waypoint
DtUUID myGamma("Gamma");
DtSimObjectReference gamma = objMgr->lookup(myGamma);
//Create a simple plan for the tank
DtPlanBuilder planBuilder;
//Create blocks for conditional statements
DtPlanBlockBuilder::SharedPlanBlockBuilder thenBlockBuilder, elseBlockBuilder, triggerBlockBuilder;
//Create some plan sets and tasks
//Set tank speed
speedReq.setSpeed(10.0); //Ordered speed, in meters/second
//Wait task
waitTask.setSecondsToWait(10.0);
//Move to Alpha Task
DtMoveToTask moveToAlphaTask;
moveToAlphaTask.setControlPoint(alpha->uuid());
//Move to Beta Task
DtMoveToTask moveToBetaTask;
moveToBetaTask.setControlPoint(beta->uuid());
//Move to Gamma Task
DtMoveToTask moveToGammaTask;
moveToGammaTask.setControlPoint(gamma->uuid());
//Create an "entity in area" conditional expression. The entity has
//already been created within the test area so this expression will
//always return true. To test the "else" condition, try changing the
//initial position of the entity or the area.
DtCeEntInArea conditionalExpression;
conditionalExpression.setArea(areaStart->uuid());
conditionalExpression.setEntity(myEntity->uuid());
//Create an "entity in trigger area" conditional expression.
DtCeEntInArea conditionalExpressionTrigger;
conditionalExpressionTrigger.setArea(triggerArea->uuid());
conditionalExpressionTrigger.setEntity(myEntity->uuid());
DtString triggerAreaDescription = "This trigger causes the entity who passes through the area to reroute to a different waypoint."; //Trigger area description
//Add tasks to the plan
//The plan assumes responsibility for the memory associated with the statements,
//so clone the statements and add them to the plan.
planBuilder.addStatement(speedReq);
planBuilder.addStatement(waitTask);
planBuilder.addIfCondition(conditionalExpression, thenBlockBuilder, elseBlockBuilder);
thenBlockBuilder->addStatement(moveToAlphaTask);
elseBlockBuilder->addStatement(moveToBetaTask);
//Create trigger when entity is within triggerArea
DtUUID triggerAreaUuid = (DtUUID)(triggerArea->uuid());
triggerBlockBuilder = planBuilder.addTriggerStatement(conditionalExpressionTrigger, triggerAreaUuid, triggerAreaDescription, true, "SuspendTask", true);
triggerBlockBuilder->addStatement(moveToGammaTask);
//Assign the plan to the tank. Normally the plan is not sent on the network after assigned. The last flag set to true will send the updated plan onto the
//network
theCgf->assignPlanByUUID(myEntity->uuid(), planBuilder, true);
return true;
}
//\return Some help text for the command.
virtual DtString help(const DtString& parameters) override {
return "Send a message with the given text.";
};
//\return True if this command should show up in the help list.
//If false, than this command will not be presented to the user.
virtual bool showInHelp() const override { return true; };
};
static DtSendPlanCommand* theSendPlanCommand = new DtSendPlanCommand();
extern "C" {
{
info.pluginName = "Simple Plan Sim";
info.pluginDescription = "This is an example of how to send a simple plan to an entity and register a trigger statement.";
info.pluginVersion = "1.00";
info.pluginCreator = "MAK Technologies";
info.pluginCreatorEmail = "sales@mak.com";
info.pluginContactWebPage = "www.mak.com";
info.pluginContactMailingAddress = "10 Fawcett Street, Suite 204, Cambridge, MA 02138 USA";
info.pluginContactPhone = "(617) 876 8085";
}
DT_VRF_DLL_PLUGIN void DtUnloadVrfPlugin(DtCgf* cgf)
{
// Remove command so it is not tried to be deleted during cleanup
delete theSendPlanCommand;
theSendPlanCommand = nullptr;
}
DT_VRF_DLL_PLUGIN bool DtInitializeVrfPlugin(DtCgf* cgf)
{
//Register the creator function for the controller here if needed
return true;
}
DT_VRF_DLL_PLUGIN bool DtPostInitializeVrfPlugin(DtCgf* cgf)
{
//Register the command to trigger sendPlan to <entity>
theCgf = cgf;
return true;
}
}

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)