From 23003f2527435333a2b5df7dc2dc4e3e95d656c9 Mon Sep 17 00:00:00 2001
From: "dereeves@nps.edu" <dereeves@nps.edu>
Date: Tue, 22 Sep 2020 17:12:40 -0700
Subject: [PATCH] * random speeds

---
 scripts/HTN/Trees/Red/ConvoyUnit.xml          | 29 ++++++++++++++-----
 scripts/HTN/Trees/Red/RandomMove.xml          |  7 ++++-
 scripts/HTN/Trees/Red/RedForceCoordinator.xml |  8 ++++-
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/scripts/HTN/Trees/Red/ConvoyUnit.xml b/scripts/HTN/Trees/Red/ConvoyUnit.xml
index 28b6cd9..d6d5618 100644
--- a/scripts/HTN/Trees/Red/ConvoyUnit.xml
+++ b/scripts/HTN/Trees/Red/ConvoyUnit.xml
@@ -68,7 +68,8 @@ goalContainer.getCurrentExecutingStack().addReplanTrigger("GoalTracker_ConvoyPac
 
 printMessage("Assembling...", True)
 
-SendEntityEventDelay(info.getMyAssignedName(), "GoalTracker_MoveToPoint", ["ASSEMBLE", "ASSEMBLY_LOCATION"], 5.0)
+randSpd = state.getLastTriggerParams()[0].get(0)
+SendEntityEventDelay(info.getMyAssignedName(), "GoalTracker_MoveToPoint", ["ASSEMBLE", randSpd, "ASSEMBLY_LOCATION"], 5.0)
 borg.delay=1.0
 
 borg.redUnitStatus[state.getCurrentUnitName()] = 0
@@ -92,18 +93,19 @@ params = state.getLastTriggerParams()[0]
 
 wps = []
 for i in range(params.size()):
-    if i&gt;0:
+    if i&gt;1:
         wps.append(params.get(i))
 
 _gt_activeNode.putVar("moveReason", params.get(0))
-_gt_activeNode.putVar("moveDestination", wps[len(wps)-1])
+_gt_activeNode.putVar("moveDestination", wps[0])
+randSpd = params.get(1)
 
 borg.redConvoysWaiting[state.getCurrentUnit().getName()].append(info.getMyAssignedName())
 
 CreateNetworkMove(
     state.getCurrentLocation(), 
     wps, 
-    3.0, 
+    randSpd, 
     None, 
     info.getMyAssignedName(), 
     info.getMyAssignedName(), 
@@ -111,7 +113,7 @@ CreateNetworkMove(
     "MOVE",
     borg.delay)
 borg.delay+=5.0
-printMessage("Starting move: "+str(wps), True)
+printMessage("Starting move: "+str(wps)+" Spd: "+str(randSpd), True)
 
 #####################################################
 # set activity to log
@@ -131,6 +133,7 @@ if _gt_activeNode.getVar("moveReason") == "CONVOY":
           <Parent>printGoalTrackerEvent</Parent>
           <Code IsFile="false">from HTNBehaviors import SendUnitEventDelay
 from HTNBehaviors import SendEntityEvent
+import cxxi.model.behavior.PythonUtilities as PythonUtilities
 
 borg.redConvoysWaiting[state.getCurrentUnit().getName()].remove(info.getMyAssignedName())
 
@@ -141,8 +144,12 @@ if len(borg.redConvoysWaiting[state.getCurrentUnit().getName()])==0:
 
     if moveReason == "ASSEMBLE":
         # let the unit know TODO: THis should probably come from the RFC
+
+        randSpd = PythonUtilities._py_getRandomNumber("UNIFORM", [0.0, 1.0])
+        randSpd = 10.0 + (40.0 * randSpd)
+
         destName = borg.redConvoyDest[state.getCurrentUnit().getName()]
-        SendUnitEventDelay(state.getCurrentUnit().getName(), "GoalTracker_MoveToPoint", ["CONVOY", destName], borg.delay)
+        SendUnitEventDelay(state.getCurrentUnit().getName(), "GoalTracker_MoveToPoint", ["CONVOY", randSpd, destName], borg.delay)
         borg.delay=1.0
     elif moveReason == "CONVOY":
         # setup off road
@@ -300,13 +307,19 @@ borg.delay=0
           <Parent>isGoalTracker_ConvoyReturn</Parent>
           <Code IsFile="false">printMessage("Need to return", True)
 
+# TODO: This should probably use the moveToPoint methods
+
 borg.redUnitStatus[state.getCurrentUnitName()]=0
 
+
+randSpd = PythonUtilities._py_getRandomNumber("UNIFORM", [0.0, 1.0])
+randSpd = 10.0 + (40.0 * randSpd)
+
 for m in state.getCurrentUnit().getMembers():
     CreateNetworkMove(
         m.getPhysicalState().getGroundTruthLocation(), 
         ["ASSEMBLY_LOCATION"], 
-        3.0, 
+        randSpd, 
         None, 
         m.getAssignedName(), 
         info.getMyAssignedName(), 
@@ -315,6 +328,8 @@ for m in state.getCurrentUnit().getMembers():
         borg.delay)
     borg.delay+=5.0
 
+printMessage("Returning", True)
+
 #####################################################
 # set activity to log
 borg.redUnitActivity[state.getCurrentUnitName()]="RETURN_TO_GARRISON"
diff --git a/scripts/HTN/Trees/Red/RandomMove.xml b/scripts/HTN/Trees/Red/RandomMove.xml
index fc0460f..2c36623 100644
--- a/scripts/HTN/Trees/Red/RandomMove.xml
+++ b/scripts/HTN/Trees/Red/RandomMove.xml
@@ -66,6 +66,7 @@ goalContainer.getCurrentExecutingStack().addReplanTrigger("GoalTracker_SelectNex
         <HTNNode AllowMsg="false" Name="moveToDestination" Type="INTERRUPT">
           <Parent>isGoalTrackerEvent</Parent>
           <Code IsFile="false">from HTNBehaviors import CreateNetworkMove
+import cxxi.model.behavior.PythonUtilities as PythonUtilities
 
 params = state.getLastTriggerParams()[0]
 
@@ -77,10 +78,14 @@ for i in range(params.size()):
 _gt_activeNode.putVar("moveReason", params.get(0))
 _gt_activeNode.putVar("moveDestination", wps[len(wps)-1])
 
+randSpd = PythonUtilities._py_getRandomNumber("UNIFORM", [0.0, 1.0])
+randSpd = 10 + (40 * randSpd)
+printMessage("CIV VEH Random Speed: " + str(randSpd), True)
+
 CreateNetworkMove(
     state.getCurrentLocation(), 
     wps, 
-    3.0, 
+    randSpd, 
     None, 
     info.getMyAssignedName(), 
     info.getMyAssignedName(), 
diff --git a/scripts/HTN/Trees/Red/RedForceCoordinator.xml b/scripts/HTN/Trees/Red/RedForceCoordinator.xml
index a09593a..c7bd049 100644
--- a/scripts/HTN/Trees/Red/RedForceCoordinator.xml
+++ b/scripts/HTN/Trees/Red/RedForceCoordinator.xml
@@ -451,6 +451,7 @@ formName = borg.redFormsByUnit[unit.getName()]
           <Parent>isMoveConvoy</Parent>
           <Code IsFile="false">import cxxi.model.knowledge.group.holders.NewUnitHolder as NewUnitHolder
 from HTNBehaviors import SendUnitEventDelay
+import cxxi.model.behavior.PythonUtilities as PythonUtilities
 
 unitName = state.getLastTriggerParams()[0].get(0)
 formName = state.getLastTriggerParams()[0].get(1)
@@ -467,7 +468,12 @@ borg.redDestinations.append(destName)
 borg.redConvoyDest[tu.getName()] = destName
 borg.redFormsByUnit[tu.getName()] = formName
 
-SendUnitEventDelay(tu.getName(), "GoalTracker_Assemble", [], 1)
+
+randSpd = PythonUtilities._py_getRandomNumber("UNIFORM", [0.0, 1.0])
+randSpd = 10.0 + (40.0 * randSpd)
+
+
+SendUnitEventDelay(tu.getName(), "GoalTracker_Assemble", [randSpd], 1)
 
 printMessage("Convoy move: "+str(tu.getName())+" DEST: "+destName, True)
 </Code>
-- 
GitLab