Skip to content
Snippets Groups Projects
jump_start.py 7.48 KiB
import mtry.cxxi.model.HierarchicalTaskNetwork.GoalContainer as GoalContainer
import UtilityFuncs
import cxxi.model.knowledge.group.holders.NewUnitHolder as NewUnitHolder
from HTNBehaviors import SendEntityEvent
from HTNBehaviors import ConvertToJavaList
from HTNBehaviors import ConvertToJavaListRandom
from HTNBehaviors import GetRandomInt
from HTNBehaviors import GetRandomChance

from SATracker import SATracker

import cxxi.model.objects.playboard.PlayBoard as PlayBoard
import mtry.cxxi.model.MtryLog.LogManager as LogManager

print info.getMyAssignedName(),": JUMP START!"
print state.getCurrentCommander(), ": CMDR"

# initialize all the entities HTN systems
GoalContainer.initAllEntities()

# create some entity specific loggers
LogManager.addSpecificEntityLog("Entity_3")
LogManager.addSpecificEntityLog("RFC")

# create the situational awareness tracker (used for managing observations)
borg.saTracker = SATracker()
borg.saTracker.register(info.getMyAssignedName())
printMessage("SA Inited = "+str(borg.saTracker.retrieveData(info.getMyAssignedName(), "inited")), True)

# create a global parameter to make adding trees easier to change than using the path in trees
borg.goalPath = "HTN/Trees/"

#################################################################################################################################################################
# Scenario Parameters
#################################################################################################################################################################
# will the entities move to attack positions at the end of training?
borg.isAttackRun = False
# red training positions
borg.redDestinations=["TRAINING01", "TRAINING02", "TRAINING03", "TRAINING04", "TRAINING05", "TRAINING06", "TRAINING07", "TRAINING08", "TRAINING09", "TRAINING10", "TRAINING11", "TRAINING12", ]
# red attack positions
borg.redAttackDestinations=["ATTACK01", "ATTACK02", "ATTACK03", "ATTACK04", "ATTACK05", "ATTACK06", "ATTACK07", "ATTACK08", "ATTACK09", "ATTACK10", "ATTACK11", "ATTACK12", ]

# number of setups to perform at each location
# the time at each location equals the number of setups * the time each setup takes
# since that time is random you can't set a fixed time at each location, just a min
# time
borg.params_redNumSetups = 1
# minimum setup time
borg.params_redSetupTimeMin = 10
# amount of random time added to min time
borg.params_redSetupTimeVar = 10


# here you can setup the random speed range
# currently ANY movement will use this random speed
# there is no differentiation between the random speed when 
# moving to assemble vs the random speed when moving to attack
# values are m/s
borg.params_randSpdMin = 10 # this is the miniumum speed
borg.params_randSpdVar = 40 # this is the random amount to add to the minimum
# if this value is greater than zero it will substitute this value for all 
# speeds instead of rolling for a random speed
borg.params_randSpdOverride = -1 

# used to for testing, these are normally all true
# but if you want to just run a single convoy or specific 
# convoys you can turn them on and off here.
# Note that even if they are turned off here though, if the
# isAttackRun is true the ALL convoys that are at base will 
# be sent to attack positions at the end of a scenario 
# regardless of this flag
borg.params_activateConvoyOne = True
borg.params_activateConvoyTwo = False
borg.params_activateConvoyThree = False

# use a background traffic pattern used to add confusion about
# what groups of vehicles are actually convoys. Usually left off
# but you can turn them on here
borg.params_useFakeConvoys = False
# use random background traffic
borg.params_useRandomMovers = False

# this lets you set the number of destinations to use
# if 0 it will be determined randomly how many to use
# between 1 and 3
borg.params_overrideNumDests = 2 # ignored if 0
#################################################################################################################################################################
#
#################################################################################################################################################################

# get bool value for if we're in attack mode or not
# 0.5 maps to a 50% chance of attack mode being true
borg.attackMode = GetRandomChance(0.5)

# list of random background movers
randomMoveVeh = ["Entity_303", "Entity_304", "Entity_305", "Entity_306", "Entity_307",
                 "Entity_308", "Entity_309", "Entity_310", "Entity_311", "Entity_312",
                 "Entity_313", "Entity_314", "Entity_315", "Entity_316", "Entity_317",
                 "Entity_318", "Entity_319", "Entity_320", "Entity_321", "Entity_322",
                 "Entity_323", "Entity_324", "Entity_325", "Entity_326", "Entity_327",
                 "Entity_328", "Entity_329", "Entity_330", "Entity_331", "Entity_332"]
#randomMoveVeh = ["Entity_303"]

# fake convoy groupings
fakeConvoy1 = ["Entity_333", "Entity_334", "Entity_335", "Entity_336", "Entity_337", "Entity_338", 
              "Entity_339", "Entity_340", "Entity_341", "Entity_342", "Entity_343", "Entity_344", 
              "Entity_345", "Entity_346", "Entity_347", "Entity_348", "Entity_349", "Entity_350", 
              "Entity_351", "Entity_352", "Entity_353", "Entity_354", "Entity_355", "Entity_356", 
              "Entity_357", "Entity_358", "Entity_359", "Entity_360", "Entity_361", "Entity_362"]

fakeConvoy2 = ["Entity_363", "Entity_364", "Entity_365", "Entity_366", "Entity_367", "Entity_368",
              "Entity_369", "Entity_370", "Entity_371", "Entity_372", "Entity_373", "Entity_374",
              "Entity_375", "Entity_376", "Entity_377", "Entity_378", "Entity_379", "Entity_380",
              "Entity_381", "Entity_382", "Entity_383", "Entity_384", "Entity_385", "Entity_386",
              "Entity_387", "Entity_388", "Entity_389", "Entity_390", "Entity_391", "Entity_392"]
    
# RFC
UtilityFuncsExp.addGoal(
   "RFC",
   0.5,
   borg.goalPath + "Red/RedForceCoordinator.xml",
   [],
   None)

if borg.params_useFakeConvoys:
    # draw for number of fakeys
    numFakeConvoys = GetRandomInt(0, 2)
    fakeConvoys = []
    if numFakeConvoys==1:
        fakeConvoys.append(fakeConvoy1)
    elif numFakeConvoys==2:
        fakeConvoys.append(fakeConvoy1)
        fakeConvoys.append(fakeConvoy2)

    # create the fake convoys if any
    ctr = 10
    for fakeConvoy in fakeConvoys:
        entityList = ConvertToJavaListRandom(fakeConvoy, 4, 25)
        fakeConvoyLeader = fakeConvoy[0]
        UtilityFuncsExp.addGoal(
            entityList.get(0),
            ctr,
            borg.goalPath + "Red/RandomMove.xml",
            [1, entityList, True],
            None)
        ctr = ctr + 10

# common trees for all entities or entities with specific combos
for entity in PlayBoard.getSingleton().getAllEntities():
    profileName = entity.getProfile().getName()
    if "RADAR" in profileName or "NEBO" in profileName:
        UtilityFuncsExp.addSpecificGoal(
           entity.getAssignedName(),
           0.5,
           borg.goalPath + "Red/RadarTree.xml",
           "RADAR",
           [],
           None)

    UtilityFuncsExp.addSpecificGoal(
       entity.getAssignedName(),
       0.5,
       borg.goalPath + "Red/EntityLogger.xml",
       "LOGGING",
       [],
       None)

if borg.params_useRandomMovers:
    # random movers
    ctr = 10
    for vehicle in randomMoveVeh:
        UtilityFuncsExp.addGoal(
            vehicle,
            ctr,
            borg.goalPath + "Red/RandomMove.xml",
            [-1, None, False],
            None)
        ctr = ctr + 10