[Gcblue-commits] gcb_wx/scripts AirMissions.py, NONE, 1.1 AI.py, 1.29, 1.30 GCBcommon.py, 1.1, 1.2
Status: Alpha
Brought to you by:
ddcforge
From: Dewitt C. <ddc...@us...> - 2006-10-24 01:34:39
|
Update of /cvsroot/gcblue/gcb_wx/scripts In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv8966/scripts Modified Files: AI.py GCBcommon.py HotKey.py Landing.py Menu.py UnitCommands.py Added Files: AirMissions.py Log Message: Index: GCBcommon.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/GCBcommon.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GCBcommon.py 18 Jun 2006 00:47:42 -0000 1.1 --- GCBcommon.py 24 Oct 2006 01:34:37 -0000 1.2 *************** *** 1,4 **** --- 1,5 ---- import math + deg_to_rad = 0.01745329252 def GetMessageParam(BB, messageName): *************** *** 24,26 **** - --- 25,26 ---- Index: UnitCommands.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/UnitCommands.py,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** UnitCommands.py 28 Sep 2006 02:01:52 -0000 1.30 --- UnitCommands.py 24 Oct 2006 01:34:37 -0000 1.31 *************** *** 62,66 **** BB = UI.GetBlackboardInterface() current_time = UI.GetTime() ! BB.Write('Home', home_name) BB.Write('Bingo', '%f' % bingo_fuel) BB.Write('RTBtime', '%f' % (current_time + rtb_time)) --- 62,67 ---- BB = UI.GetBlackboardInterface() current_time = UI.GetTime() ! if (not BB.KeyExists('Home')): ! BB.Write('Home', home_name) BB.Write('Bingo', '%f' % bingo_fuel) BB.Write('RTBtime', '%f' % (current_time + rtb_time)) *************** *** 144,147 **** --- 145,197 ---- + + # gets info on closest (known) enemy or unknown platform within search range + def ClosestOfType(UI, class_mask, search_range_km): + track_list = UI.GetTrackList(class_mask, search_range_km, 3) + + current_time = UI.GetTime() + nTracks = track_list.Size() + closest_range = 1e6 + closest_id = -1 + + for n in range(0, nTracks): + track_info = track_list.GetTrack(n) + track_id = track_info.ID + staleness = current_time - track_info.Time + range_km = UI.GetRangeToTrack(track_info) + + if ((staleness <= 15.0) and (range_km < closest_range)): + closest_range = range_km + closest_id = track_id + + return (closest_id, closest_range) + + + # gets info on closest (known) enemy or unknown platform within search range + def ClosestOfTypeUnengaged(UI, class_mask, search_range_km): + track_list = UI.GetTrackList(class_mask, search_range_km, 3) + + current_time = UI.GetTime() + nTracks = track_list.Size() + closest_range = 1e6 + closest_id = -1 + closest_bearing = 0 + + for n in range(0, nTracks): + track_info = track_list.GetTrack(n) + track_id = track_info.ID + nEngaged = track_info.GetEngagedCount() + staleness = current_time - track_info.Time + range_km = UI.GetRangeToTrack(track_info) + + if ((nEngaged == 0) and (staleness <= 15.0) and (range_km < closest_range)): + closest_range = range_km + closest_id = track_id + closest_bearing = UI.GetHeadingToDatum(track_info.Lon, track_info.Lat) + + + return (closest_id, closest_range, closest_bearing) + + # clears all orders, moves to location and starts patrol *************** *** 427,435 **** ! def AddCAPMission(UI): if (not UI.HasFlightPort()): return FP = UI.GetFlightPortInfo() ! FP.AddCAPMission() --- 477,485 ---- ! def AddCAPMission(UI, lon, lat): if (not UI.HasFlightPort()): return FP = UI.GetFlightPortInfo() ! FP.AddCAPMission(lon, lat) --- NEW FILE: AirMissions.py --- from GCBcommon import * from UnitCommands import * import math # patrol relative to airbase or carrier location def CAP(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) # 1 is heading to station, 0 patroling TI.SetMemoryValue(4, 30.0 + 15.0 * UI.Rand()) # random turn interval in seconds TI.SetMemoryText('Description', 'Perform surveillance along a zig-zag course') patrol_range_km = GetMessageParam(BB, 'PatrolRange_km') patrol_az_rad = deg_to_rad * GetMessageParam(BB, 'PatrolAzimuth_deg') # rel to north anchor_id = GetMessageParam(BB, 'AnchorPlatformId') # platform id to center patrol about TI.SetMemoryValue(10, patrol_range_km) TI.SetMemoryValue(11, patrol_az_rad) TI.SetMemoryValue(12, anchor_id) iteration = iteration + 1 TI.SetMemoryValue(1, iteration) # if low on fuel or out of ammo, rtb if ((UI.GetFuel() < 0.1) or (not UI.IsEquippedForTargetType(0x0020))): UI.DeleteTask('EngageAll') TI.EndTask() AddRTBtask(UI, '', 0.1, 0) return # activate all sensors can_radiate = GetSensorControl(BB) if (can_radiate and not UI.IsSub()): ActivateAllSensors(UI) else: ActivatePassiveSensors(UI) # return if conn is not available if (not GetConnControl(BB)): return # check for nearby air target intercept_target = 0 closest_id, closest_range, closest_bearing = ClosestOfTypeUnengaged(UI, 0x0020, 120) if (closest_id != -1): intercept_target = 1 UI.SetHeading(closest_bearing) # lag intercept if (UI.GetFuel() > 0.5): UI.SetThrottle(1.1) else: UI.SetThrottle(1.0) UI.SetActionText('Intercept %d' % closest_id) return patrol_range_km = TI.GetMemoryValue(10) patrol_az_rad = TI.GetMemoryValue(11) anchor_id = TI.GetMemoryValue(12) if (UI.IsAir()): if (UI.GetAlt() < 6000): UI.SetThrottle(1.1) UI.SetAlt(6000) else: UI.SetThrottle(0.8) # calculate station point anchor_track = UI.GetTrackById(long(anchor_id)) anchor_track.Offset(patrol_range_km, patrol_az_rad) if (not anchor_track.IsValid()): TI.EndTask() return station_lon = anchor_track.Lon station_lat = anchor_track.Lat station_range = UI.GetRangeToDatum(station_lon, station_lat) isTravelingToStation = TI.GetMemoryValue(3) if (isTravelingToStation): range_thresh = 1.0 UI.SetSpeedToMax() else: range_thresh = 10.0 if (UI.IsAir()): range_thresh = range_thresh * 4.0 if (station_range > range_thresh): new_heading = UI.GetHeadingToDatum(station_lon, station_lat) TI.SetMemoryValue(3, 1) # to indicate traveling to station UI.SetActionText('-> Station') TI.SetUpdateInterval(10.0) else: new_heading = UI.GetHeading() + 30 TI.SetMemoryValue(3, 0) # to indicate traveling to station UI.SetActionText('CAP') TI.SetUpdateInterval(TI.GetMemoryValue(4)) UI.SetHeading(new_heading) Index: HotKey.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/HotKey.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** HotKey.py 24 Sep 2006 19:50:20 -0000 1.10 --- HotKey.py 24 Oct 2006 01:34:37 -0000 1.11 *************** *** 68,71 **** --- 68,78 ---- # e.g. flags == 6 indicates ctrl and alt were pressed during dclick def ProcessDoubleClickHook(UnitInfo, flags): + # in multiplayer try to take control of available unit first + ## if (UnitInfo.IsMultiplayerActive()): + ## if (not UnitInfo.IsPlayerControlled()): + ## if (UnitInfo.IsAvailable()): + ## UnitInfo.SendCommand('TakeControl') + ## return + # for units with aircraft show the flight panel unless shift is pressed # otherwise show the platform panel Index: AI.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/AI.py,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** AI.py 16 Sep 2006 14:01:24 -0000 1.29 --- AI.py 24 Oct 2006 01:34:37 -0000 1.30 *************** *** 3,6 **** --- 3,8 ---- from Landing import * from AirManagement import * + from AirMissions import * + import math *************** *** 467,491 **** - - # gets info on closest (known) enemy or unknown platform within search range - def ClosestOfType(UI, class_mask, search_range_km): - track_list = UI.GetTrackList(class_mask, search_range_km, 3) - - current_time = UI.GetTime() - nTracks = track_list.Size() - closest_range = 1e6 - closest_id = -1 - - for n in range(0, nTracks): - track_info = track_list.GetTrack(n) - track_id = track_info.ID - staleness = current_time - track_info.Time - range_km = UI.GetRangeToTrack(track_info) - - if ((staleness <= 15.0) and (range_km < closest_range)): - closest_range = range_km - closest_id = track_id - - return (closest_id, closest_range) --- 469,472 ---- *************** *** 945,948 **** --- 926,935 ---- # attack target + can_radiate = GetSensorControl(BB) + if (can_radiate and not UI.IsSub()): + ActivateAllSensors(UI) + else: + ActivatePassiveSensors(UI) + range_km = 0.0 Index: Landing.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/Landing.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Landing.py 27 Aug 2006 21:28:54 -0000 1.2 --- Landing.py 24 Oct 2006 01:34:37 -0000 1.3 *************** *** 22,25 **** --- 22,29 ---- dest_name = BB.ReadMessage('LandTarget') dest_id = UI.LookupFriendlyId(dest_name) + if (dest_id == -1): + UI.DisplayMessage('Bad landing target (%s)' % dest_name) + TI.EndTask() + return TI.SetMemoryValue(3, dest_id) *************** *** 34,38 **** alt_m = track_info.Alt if (track_info.ID == -1): ! UI.DisplayMessage('Bad track ID for landing') TI.EndTask() return # invalid id --- 38,43 ---- alt_m = track_info.Alt if (track_info.ID == -1): ! dest_name = BB.ReadMessage('LandTarget') ! UI.DisplayMessage('Bad track ID for landing (%d, %s)' % (dest_id, dest_name)) TI.EndTask() return # invalid id *************** *** 198,202 **** if ((fuel <= bingo_fuel) or (time >= rtb_time)): home_base = BB.ReadMessage('Home') ! BB.Write('LandTarget', home_base) UI.AddTask('Land', 2.0, 0) TI.EndTask() --- 203,213 ---- if ((fuel <= bingo_fuel) or (time >= rtb_time)): home_base = BB.ReadMessage('Home') ! dest_id = UI.LookupFriendlyId(home_base) ! if (dest_id == -1): ! UI.DisplayMessage('Bad base for rtb (%s)' % home_base) ! TI.EndTask() ! return ! BB_global = UI.GetBlackboardInterface() # so msg isn't erased on endtask ! BB_global.Write('LandTarget', home_base) UI.AddTask('Land', 2.0, 0) TI.EndTask() Index: Menu.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/Menu.py,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Menu.py 28 Sep 2006 02:01:52 -0000 1.27 --- Menu.py 24 Oct 2006 01:34:37 -0000 1.28 *************** *** 157,161 **** UnitMenu.AddItem('Add mission', '') UnitMenu.BeginSubMenu() ! UnitMenu.AddItem('CAP test', 'AddCAPMission') UnitMenu.EndSubMenu() --- 157,161 ---- UnitMenu.AddItem('Add mission', '') UnitMenu.BeginSubMenu() ! UnitMenu.AddItemUI('CAP', 'AddCAPMission', 'Datum') UnitMenu.EndSubMenu() |