The Display AggregateLevel State Data example does the following.
This example shows how to create a VR-Forces sim engine plugin that will install new console commands that can be issued to both print out various data to the console associated with objects in the system and issue plans to the entities in the scenario.
This plugin is designed to be used with the AggregateLevel SMS. Many of the concepts and techniques on display here are also relevant EntityLevel simulation, however the specific state properties and tasks used are specific to AggregateLevel simulation.
This example currently adds the following console commands.
Since this example is loaded as a plugin, it can be used in conjunction with the released VR-Forces application.
In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin.
#include <vlpi/entityType.h>
extern "C" {
{
info.
pluginDescription =
"Adds console commands to allow for the dislpay of state data. Type help-display to get a list of commands.";
}
{
public:
DtStartMovementMissionCommand(
DtCgf* c) : myCgf(c) {};
virtual ~DtStartMovementMissionCommand() override {};
{
{
DtWarn << "Could not find object named " << parameters << std::endl;
return true;
}
{
DtWarn << "Waypoint 1 does not exist. Please create a waypoint called Patrol Point as this example requires a waypoint to move to.";
return true;
}
else
{
if (!runways)
{
DtWarn << parameters << " is not an airbase.\n";
return true;
}
createFlightTask.
setValue(
"Loadout",
"Intercept");
createFlightTask.
setValue(
"CallSign",
"MovementExample");
createFlightTask.
setValue(
"AircraftUnitType", DtEntityType(11, 2, 225, 35, 1, 3, 3));
createFlightTask.
setValue(
"WaitForLaunch",
true);
globalPlanBuilder.addStatement(createFlightTask);
globalPlanBuilder.addTaskCommand(moveToWaypointTask,
DtUUID(
"MovementExample", 0,
true));
myCgf->globalPlanManager()->addOrUpdatePlan(globalPlanBuilder.planCopy());
DtWarn <<
"New movement mission plan assigned to " << obj->
markingText() << std::endl;
}
return true;
}
protected:
};
{
public:
DtStartEscortMissionCommand(
DtCgf* c) : myCgf(c) {};
virtual ~DtStartEscortMissionCommand() override {};
{
globalPlanBuilder.addStatement(waitDuration);
createFlightTask.
setValue(
"Loadout",
"Attack");
createFlightTask.
setValue(
"CallSign",
"AttackExample");
createFlightTask.
setValue(
"AircraftUnitType", DtEntityType(11, 2, 225, 35, 1, 3, 3));
createFlightTask.
setValue(
"WaitForLaunch",
true);
globalPlanBuilder.addStatement(createFlightTask);
const DtLocalObject* targetPoint = myCgf->localObjectManager()->lookup(
DtUUID(
"Attack Point"));
if (!targetPoint)
{
if (ab2)
{
DtEntityType target(16, 0, 0, 2, 0, 0, 0);
targetPoint = myCgf->localObjectManager()->createAndInitVrfObject(
target,
true,
"Attack Point",
DtString::nullString(),
initialPosition,
0,
false,
false,
DtAppearance::nullAppearance(),
"local-vrf-object");
}
}
if (targetPoint && attackRoute.
isValid())
{
attackAirbase.
setValue(
"targetPoint", targetPoint->uuid());
attackAirbase.
setValue(
"ingressRoute", attackRoute->
uuid());
}
globalPlanBuilder.addStatement(issuePlan);
myCgf->globalPlanManager()->addOrUpdatePlan(globalPlanBuilder.planCopy());
}
virtual void createResourcePlan(
const DtSimObject* obj)
{
if (myCgf->localObjectManager()->lookup(
DtUUID(
"Example Resource Assignment Plan")))
{
return;
}
std::map<DtString, int> aircraftMap;
aircraftMap["F-16C"] = 12;
setAssignAircraft.
setValue(
"aircraft", aircraftMap);
setAssignAircraft.
setValue(
"setAsCurrent",
false);
globalPlanBuilder.addSetDataCommand(setAssignAircraft, obj->
uuid());
modProps.addProperty(
new DtRwPropertyInt(
"Initial-Ground-Crew-Size", 100));
setPersonnel.
setProperties(
"Initial-Ground-Crew-Size;Initial-Air-Crew-Size");
globalPlanBuilder.addSetDataCommand(setPersonnel, obj->
uuid());
modProps.clearVariables();
globalPlanBuilder.addSetDataCommand(setSupplies, obj->
uuid());
modProps.clearVariables();
modProps.addProperty(
new DtRwPropertyInt(
"Repair-Hangar-Aircraft-Capacity", 10));
modProps.addProperty(
new DtRwPropertyInt(
"Munition-Storage-Capacity", 10000));
std::map<DtRwString, DtRwPropertiesStructure> runwaysToAssign;
prototype.findAndSetPropertyValue("Length", 1000.0);
prototype.findAndSetPropertyValue("Usable-Length", 1000.0);
prototype.findAndSetPropertyValue("Width", 55.0);
prototype.findAndSetPropertyValue("Main-Direction", 45.0);
key = "Test Runway";
runwaysToAssign[key] = prototype;
setFacilities.
setProperties(
"Runways;Has-Night-Support;ORP-Aircraft-Capacity;Apron-Aircraft-Capacity;Repair-Hangar-Aircraft-Capacity;Aviation-Fuel-Capacity;Munition-Storage-Capacity;Barracks-Capacity");
globalPlanBuilder.addSetDataCommand(setFacilities, obj->
uuid());
myCgf->globalPlanManager()->addOrUpdatePlan(globalPlanBuilder.planCopy());
}
{
createFlightTask.
setValue(
"Loadout",
"Intercept");
createFlightTask.
setValue(
"CallSign",
"EscortExample");
createFlightTask.
setValue(
"AircraftUnitType", DtEntityType(11, 2, 225, 35, 1, 9, 10));
createFlightTask.
setValue(
"WaitForLaunch",
true);
globalPlanBuilder.addStatement(createFlightTask);
{
std::vector<DtUUID> zones;
zones.push_back(zone->
uuid());
setEngagementZone.
setValue(
"engagementZones", zones);
}
escortFlightTask.
setValue(
"LocationToMeet", waypoint->
uuid());
escortFlightTask.
setValue(
"UnitToEscort",
DtUUID(
"AttackExample", 0,
true));
globalPlanBuilder.addStatement(issuePlan);
myCgf->globalPlanManager()->addOrUpdatePlan(globalPlanBuilder.planCopy());
}
{
{
DtWarn << "Could not find object named " << parameters << std::endl;
return true;
}
{
DtWarn << "Waypoint 1 does not exist. Please create a waypoint called Patrol Point as this example requires a waypoint to move to.";
return true;
}
else
{
if (!runways)
{
DtWarn << parameters << " is not an airbase.\n";
return true;
}
createResourcePlan(obj);
createAttackPlan(obj, waypoint);
createEscortPlan(obj, waypoint);
DtWarn <<
"New escort mission plans assigned to " << obj->
markingText() << std::endl;
}
return true;
}
protected:
};
{
public:
DtPrintAirbaseCommand(
DtCgf* c) : myCgf(c) {};
virtual ~DtPrintAirbaseCommand() override {};
{
{
DtWarn << "Could not find object named " << parameters << std::endl;
return true;
}
else
{
if (!runways)
{
DtWarn << parameters << " is not an airbase.\n";
return true;
}
DtWarn << "Runways:\n";
auto iter = runways->
begin();
auto end = runways->
end();
while (iter != end)
{
if (str)
{
boost::optional<double> mainDirection = str->
findPropertyValue<
double>(
"Main-Direction");
DtWarn <<
" " << str->
name().
c_str() <<
" is " << *length <<
" meters in length, " << *width <<
" meters in width and a direction of " << *mainDirection <<
" degrees.\n";
}
++iter;
}
}
return true;
}
protected:
};
{
public:
DtPrintStatusCommand(
DtCgf* c) : myCgf(c) {};
virtual ~DtPrintStatusCommand() override {};
{
if (baseStructure && currentStructure)
{
if (amount && (*amount != 0))
{
const DtRwReal* current = findProperty<DtRwReal>(*currentStructure,
"Amount");
if (current)
{
DtString title = DtReplaceAllSubstrings(val,
"-",
" ");
DtWarn << " " << title << ": " << *current << "/" << *amount << std::endl;
}
}
}
else
{
DtWarn << " No " << val << "\n";
}
}
{
if(ammoRw)
{
auto iter = ammoRw->
begin();
auto end = ammoRw->
end();
for (; iter != end; ++iter)
{
boost::optional<int> count = iter->findPropertyValue<int>("Count");
boost::optional<DtString> type = iter->findPropertyValue<
DtString>(
"Type");
if (count && type)
{
DtWarn << " Ammunition: " << *type << " has " << *count << " units remaining.\n";
}
}
}
else
{
DtWarn << " No Ammunition\n";
}
}
virtual void printPrimaryEquipment(
const DtSimObject* obj)
{
const DtRwPropertiesStructure* currentStructure = findProperty<DtRwPropertiesStructure>(vrfSimulatedSimObjectFacade.stateProperties(),
"Primary-Equipment");
if (currentStructure && baseStructure)
{
if (type && count && baseCount && type->length())
{
DtWarn << " Primary Equipment: " << *type << " has " << *count << " units remaining out of " << *baseCount << "\n";
}
}
else
{
DtWarn << " No Primary Equipment\n";
}
}
{
if (equipment && baseEquipment && baseLoadoutEquipment)
{
DtWarn << " Equipment: " << std::endl;
auto iter = equipment->
begin();
auto end = equipment->
end();
while (iter != end)
{
boost::optional<int> baseCount;
boost::optional<int> baseLoadoutCount;
if (currCount)
{
baseEquipment->findItem(currEquip->
name().
c_str()));
if (baseEquip)
{
}
baseLoadoutEquipment->findItem(currEquip->
name().
c_str()));
if (baseLoadoutEquip)
{
}
int totalBaseCount = 0;
if (baseCount)
{
totalBaseCount += *baseCount;
}
if (baseLoadoutCount)
{
totalBaseCount += *baseLoadoutCount;
}
DtWarn <<
" " << currEquip->
name() <<
": " << *currCount <<
" out of " << totalBaseCount << std::endl;
}
++iter;
}
}
else
{
DtWarn << " No Equipment\n";
}
}
virtual void printEngagementHistory(
const DtSimObject* obj)
{
const DtRwPropertiesMap* engagementHistory = findProperty<DtRwPropertiesMap>(vrfSimulatedSimObjectFacade.stateProperties(),
"Engagement-History");
if (engagementHistory)
{
std::vector<DtReaderWriterRegistryData *>::const_iterator iter = engagementHistory->
registry().
registryData().begin();
std::vector<DtReaderWriterRegistryData *>::const_iterator end = engagementHistory->
registry().
registryData().end();
DtWarn << " Engagement History: " << std::endl;
while (iter != end)
{
boost::optional<bool> isAttack = engagementEvent->
findPropertyValue<
bool>(
"IsAttack");
boost::optional<double> hitFactor = engagementEvent->
findPropertyValue<
double>(
"HitFactor");
boost::optional<double> defenseFactor = engagementEvent->
findPropertyValue<
double>(
"DefenseFactor");
boost::optional<double> timeStarted = engagementEvent->
findPropertyValue<
double>(
"TimeStarted");
boost::optional<double> timeCompleted = engagementEvent->
findPropertyValue<
double>(
"TimeComplete");
boost::optional<int> damageTaken = engagementEvent->
findPropertyValue<
int>(
"DamageTaken");
boost::optional<double> pHit = engagementEvent->
findPropertyValue<
double>(
"ProbabilityHit");
boost::optional<double> draw = engagementEvent->
findPropertyValue<
double>(
"RandomDraw");
if (enemy && weaponType && isAttack && hitFactor && defenseFactor && timeStarted &&
timeCompleted && damageTaken && pHit && draw)
{
{
}
if (*isAttack)
{
DtWarn << " Fired at " << enemyName << " with " << *weaponType << "." << std::endl;
DtWarn << " Hit Factor: " << *hitFactor << std::endl;
}
else
{
DtWarn << " Shot at by " << enemyName << " with " << *weaponType << ". ";
if (*damageTaken > 0)
{
DtWarn << "Hit! Took " << *damageTaken << " damage." << std::endl;
}
else
{
DtWarn << "Miss!" << std::endl;
}
DtWarn << " Hit Factor: " << *hitFactor << ", Defense Factor: "
<< *defenseFactor << ", P(hit): " << *pHit << ", Draw: " << *draw
<< std::endl;
}
DtWarn << " Time: " << *timeStarted << " to " << *timeCompleted << std::endl;
if (details)
{
DtWarn << " Details: " << std::endl;
for (; iter != end; ++iter)
{
if (detailText)
{
DtWarn << " " << *detailText << std::endl;
}
}
}
}
++iter;
}
}
else
{
DtWarn << " No Engagement History\n";
}
}
{
if (parameters == "ALL")
{
while (iter != end)
{
boost::optional<int> health =
vrfSimulatedSimObjectFacade.stateProperties().findPropertyValue<int>("Health");
if (health)
{
printStatus(*iter);
DtWarn << std::endl;
}
++iter;
}
}
else
{
{
DtWarn << "Could not find object named " << parameters << std::endl;
return true;
}
else
{
printStatus(obj);
}
}
return true;
}
{
DtWarn <<
"Current status for " << obj->
markingText() << std::endl;
boost::optional<int> health =
vrfSimulatedSimObjectFacade.stateProperties().findPropertyValue<int>("Health");
boost::optional<int> baseHealth =
vrfSimulatedSimObjectFacade.parameterProperties().findPropertyValue<int>("Base-Health");
if (health && baseHealth)
{
DtWarn << " Health: " << *health << "/" << *baseHealth << std::endl;
}
printFuelIfExists(obj, "Aviation-Fuel");
printFuelIfExists(obj, "Diesel-Fuel");
printPrimaryEquipment(obj);
printEquipment(obj);
printAmmunition(obj);
printEngagementHistory(obj);
}
protected:
};
{
public:
virtual ~DtHelpDisplayCommand() override {};
{
DtWarn << "print-airbase <name> - prints airbase specific data. If the object is not an airbase a warning will be issued.\n";
DtWarn << "start-movement-mission <name> - Starts a move to waypoint mission using F-16C aircraft at the supplied air base. If the object is not an airbase a warning will be issued.\n";
DtWarn << "start-escort-mission <name> - Starts an escort mission using F-16C aircraft at the supplied air base. If the object is not an airbase a warning will be issued. You will need to add more F16 aircraft to the airbase in order to use this feature.\n";
DtWarn << "print-status <name | ALL> - prints various status (health, fuel, equipment, weapon stores). If the object is not an airbase a warning will be issued. Use ALL to print out all aggregates.\n";
DtWarn << "help-display - prints this list.\n";
return true;
}
};
{
public:
DtSurfaceAttackCommand(
DtCgf* c)
: myCgf(c) {};
virtual ~DtSurfaceAttackCommand() {};
{
attackTask->
setValue(
"initialPointEnabled",
false);
(*weaponsVec)[0] = "gunA";
return attackTask;
}
{
{
DtWarn << "Could not find object named " << parameters << std::endl;
return true;
}
{
DtWarn << "Waypoint 1 does not exist.";
return true;
}
DtSimTask* attackTask = createAttackTask(obj, waypoint);
myCgf->simulationServices()->simInternalCommunicationManager()->deliverMessage(
dynamic_cast<DtVrfObjectMessage*>(&taskMessage));
delete taskMessage.
task();
return true;
}
protected:
};
static DtHelpDisplayCommand* theHelpDisplayCommand = 0;
static DtPrintAirbaseCommand* thePrintAirbaseCommand = 0;
static DtPrintStatusCommand* thePrintStatusCommand = 0;
static DtStartMovementMissionCommand* theStartMovementMissionCommand = 0;
static DtStartEscortMissionCommand* theStartEscortMissionCommand = 0;
{
return true;
}
{
delete theHelpDisplayCommand;
theHelpDisplayCommand = nullptr;
delete thePrintAirbaseCommand;
thePrintAirbaseCommand = nullptr;
delete thePrintStatusCommand;
thePrintStatusCommand = nullptr;
delete theStartMovementMissionCommand;
theStartMovementMissionCommand = nullptr;
delete theStartEscortMissionCommand;
theStartEscortMissionCommand = nullptr;
}
{
theHelpDisplayCommand = new DtHelpDisplayCommand;
thePrintAirbaseCommand = new DtPrintAirbaseCommand(cgf);
thePrintStatusCommand = new DtPrintStatusCommand(cgf);
theStartMovementMissionCommand = new DtStartMovementMissionCommand(cgf);
theStartEscortMissionCommand = new DtStartEscortMissionCommand(cgf);
theHelpDisplayCommand);
thePrintAirbaseCommand);
thePrintStatusCommand);
theStartMovementMissionCommand);
theStartEscortMissionCommand);
}
}