Update of /cvsroot/gcblue/gcb_wx/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2168/scripts
Added Files:
SubTactics.py
Log Message:
GCB 0.8.0 release
--- NEW FILE: SubTactics.py ---
##########################################
# Sub tactics
##########################################
from UnitCommands import *
# zig-zag patrol task
def SubPatrol(TI):
UI = TI.GetPlatformInterface()
BB = TI.GetBlackboardInterface()
iteration = TI.GetMemoryValue(1) # will return 0 first time
if (iteration == 0): # do initialization
TI.SetMemoryValue(2, UI.GetHeading())
TI.SetMemoryValue(3, 0) # 0 is turn left next zig-zag, 1 turn right
TI.SetMemoryValue(4, 255.0 + 90.0 * UI.Rand()) # random turn interval in seconds
TI.SetMemoryText('Description', 'Perform surveillance along a zig-zag course')
if (not UI.IsSub()):
TI.EndTask()
iteration = iteration + 1
TI.SetMemoryValue(1, iteration)
# activate all passive sensors
# can_radiate = GetSensorControl(BB)
ActivatePassiveSensors(UI)
# return if conn is not available
if (not GetConnControl(BB)):
return
# if at periscope depth and battery is not fully charged, activate snorkel and set speed slow
# if at periscope depth and battery is fully charged, stop snorkeling, and set depth to deep
# if deep and battery is nearly empty, set depth to periscope depth
SI = UI.GetSubInterface() # get sub interface object
bottomDepth = -UI.GetTerrainElevation()
maxPatrolDepth = SI.GetMaxDepth() - 30
if (bottomDepth > 210):
patrolDepth = 300
else:
patrolDepth = bottomDepth - 30
if (patrolDepth > maxPatrolDepth):
patrolDepth = maxPatrolDepth
UI.SetSpeed(5) # default patrol speed
updateInterval = TI.GetMemoryValue(4)
if (SI.IsDieselElectric()):
battery = SI.GetBatteryFraction()
if (SI.IsAtPeriscopeDepth()):
if (battery < 0.99):
SI.SetSnorkelState(1)
UI.SetSpeed(3)
else:
SI.SetSnorkelState(0)
UI.SetSpeed(5)
UI.SetAlt(-patrolDepth)
elif (battery < 0.2):
SI.GoToPeriscopeDepth()
UI.SetSpeed(5)
updateInterval = 0.5 * updateInterval
else: # nuclear sub
UI.SetAlt(-patrolDepth)
if (TI.GetMemoryValue(3) == 0):
new_heading = TI.GetMemoryValue(2) - 30
TI.SetMemoryValue(3, 1)
else:
new_heading = TI.GetMemoryValue(2) + 30
TI.SetMemoryValue(3, 0)
UI.SetHeading(new_heading)
TI.SetUpdateInterval(updateInterval)
UI.SetActionText('Patrol')
# torpedo evasion tactics
def EvadeTorpedoes(TI):
UI = TI.GetPlatformInterface()
BB = TI.GetBlackboardInterface()
iteration = TI.GetMemoryValue(1) # will return 0 first time
if (iteration == 0): # do initialization
TI.SetMemoryText('Description', 'Evade incoming torpedoes')
iteration = iteration + 1
TI.SetMemoryValue(1, iteration)
# find closest torpedo within 12 km (or bearing-only torpedo track with longest track life)
# if any found, take conn control, set depth deep, set speed to max, set course to evade
# (when available) if any found that are within 1 km(?), release countermeasure
# if no torpedoes found and have conn control, release conn control
|