The Simple Plan example demonstrates the following:
- How to get objects from a scenario
- How to create plans for objects
- How to register and add a trigger statement to a plan
- How to assign a plan to an object
- How to create and register a console command
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
(Release) simplePlan
(Debug) simplePland
In the Launcher:
-
Set the simplePlan plugin to load.
-
Launch the application.
-
Load the simplePlan.scnx scenario.
To view the new behavior:
-
Enter the "sendPlan" command in the SIM console.
-
In the GUI, right-click the entity to view the plan.
-
Play the scenario. As the entitiy enters the trigger area (Area 2), the triggered action takes place before the entity resumes the original plan.
Plugin Code
#include <vlutil/vlPrint.h>
#include <vlutil/vlProcessControl.h>
#include <vl/hostStructs.h>
static DtSimulationAddress theSimulationAddress(1,3001);
static DtCgf* theCgf = 0;
{
~DtSendPlanCommand() { };
{
conditionalExpressionTrigger.
setArea(triggerArea->
uuid());
DtString triggerAreaDescription =
"This trigger causes the entity who passes through the area to reroute to a different waypoint.";
planBuilder.
addIfCondition(conditionalExpression, thenBlockBuilder, elseBlockBuilder);
thenBlockBuilder->addStatement(moveToAlphaTask);
elseBlockBuilder->addStatement(moveToBetaTask);
triggerBlockBuilder = planBuilder.
addTriggerStatement(conditionalExpressionTrigger, triggerAreaUuid, triggerAreaDescription,
true,
"SuspendTask",
true);
triggerBlockBuilder->addStatement(moveToGammaTask);
return true;
}
{
return "Send a message with the given text.";
};
};
static DtSendPlanCommand* theSendPlanCommand = new DtSendPlanCommand();
extern "C" {
{
info.
pluginDescription =
"This is an example of how to send a simple plan to an entity and register a trigger statement.";
}
{
return true;
}
{
theSimulationAddress = cgf->
exerciseConn()->applicationId();
theCgf = cgf;
return true;
}
}