[Gcblue-commits] gcb_wx/scripts AI.py,1.17,1.18 Menu.py,1.10,1.11 UnitCommands.py,1.13,1.14
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-03-02 22:29:26
|
Update of /cvsroot/gcblue/gcb_wx/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15614/scripts Modified Files: AI.py Menu.py UnitCommands.py Log Message: Better sensor ageout behavior, more ai work, misc cleanup Index: AI.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/AI.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** AI.py 18 Feb 2005 17:42:08 -0000 1.17 --- AI.py 2 Mar 2005 22:28:41 -0000 1.18 *************** *** 111,114 **** --- 111,199 ---- UI.SetActionText('Patrol') + def GetMessageParam(BB, messageName): + msg = BB.ReadMessage(messageName) + if (msg == ''): + return 0 + else: + return float(msg) + + # patrol task, roughly circles same point, stays within 10 km of station + def PatrolCircle(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') + + station_lon = GetMessageParam(BB, 'StationLongitude') + station_lat = GetMessageParam(BB, 'StationLatitude') + station_alt = GetMessageParam(BB, 'StationAltitude') + station_speed = GetMessageParam(BB, 'StationSpeed') # in kts + TI.SetMemoryValue(10, station_lon) + TI.SetMemoryValue(11, station_lat) + TI.SetMemoryValue(12, station_alt) + TI.SetMemoryValue(13, station_speed) + + + iteration = iteration + 1 + TI.SetMemoryValue(1, iteration) + + # activate all sensors + can_radiate = GetSensorControl(BB) + if (can_radiate): + ActivateAllSensors(UI) + else: + ActivatePassiveSensors(UI) + + # return if conn is not available + if (not GetConnControl(BB)): + return + + station_lon = TI.GetMemoryValue(10) + station_lat = TI.GetMemoryValue(11) + station_alt = TI.GetMemoryValue(12) + station_speed = TI.GetMemoryValue(13) + + if (UI.IsAir()): + if (station_alt > 0): + UI.SetAlt(station_alt) + + if (station_speed > 0): + UI.SetSpeed(station_speed) + + if ((station_lon != 0) or (station_lat != 0)): + station_range = UI.GetRangeToDatum(station_lon, station_lat) + else: + station_range = 0 # effectively ignore station range if missing station info + + 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('Patrol-Circ') + TI.SetUpdateInterval(TI.GetMemoryValue(4)) + + UI.SetHeading(new_heading) + + + # shoot hostiles and unknowns within range, but do not intercept. *************** *** 182,187 **** ! # returns id of closest target that is in-range, engageable, and not already ! # overwhelmingly engaged # returns -1 if none def GetImmediateTarget(UI): --- 267,272 ---- ! # returns id of closest target that is in-range, engageable, not already ! # overwhelmingly engaged, and not a stale track # returns -1 if none def GetImmediateTarget(UI): *************** *** 198,210 **** track_list = UI.GetTrackList(0x0FFF, 150, 3) nTracks = track_list.Size() best_range = 1e6 best_target = -1 best_launcher = -1 ! for n in range(0, nTracks): track_info = track_list.GetTrack(n) track_id = track_info.ID ! engaged_count = track_info.GetEngagedCount() if (track_info.IsAir() or track_info.IsMissile()): --- 283,296 ---- track_list = UI.GetTrackList(0x0FFF, 150, 3) + current_time = UI.GetTime() nTracks = track_list.Size() best_range = 1e6 best_target = -1 best_launcher = -1 ! for n in range(0, nTracks): track_info = track_list.GetTrack(n) track_id = track_info.ID ! staleness = track_info.Time - current_time engaged_count = track_info.GetEngagedCount() if (track_info.IsAir() or track_info.IsMissile()): *************** *** 213,217 **** max_engaged_count = 6 ! if (engaged_count < max_engaged_count): UI.SetTarget(track_id) launcher_info = UI.GetBestLauncher() --- 299,303 ---- max_engaged_count = 6 ! if ((engaged_count < max_engaged_count) and (staleness < 15.0)): UI.SetTarget(track_id) launcher_info = UI.GetBestLauncher() *************** *** 409,417 **** return 0 ! # modified this to adjust altitude based on altitude of landing ! # site ! def Land(UI,dest_id): ! # 0 - init, 1 - distant, 2 - init approach, 3 - final approach ! land_state = UI.GetVar(0) track_info = UI.GetTrackById(dest_id) --- 495,520 ---- return 0 ! # for non-helo aircraft ! def Land(TI): ! UI = TI.GetPlatformInterface() ! BB = TI.GetBlackboardInterface() ! ! if (not GetConnControl(BB)): ! return ! ! iteration = TI.GetMemoryValue(1) # will return 0 first time ! if (iteration == 0): # do initialization ! TI.SetMemoryText('Description', 'Land at designated airbase') ! TI.SetMemoryValue(2, 0) # 0 - init, 1 - distant, 2 - init approach, 3 - final approach ! dest_name = BB.ReadMessage('LandingTarget') ! dest_id = UI.LookupFriendlyId(dest_name) ! TI.SetMemoryValue(3, dest_id) ! ! iteration = iteration + 1 ! TI.SetMemoryValue(1, iteration) ! ! ! land_state = TI.GetMemoryValue(2) ! dest_id = long(TI.GetMemoryValue(3)) track_info = UI.GetTrackById(dest_id) *************** *** 419,423 **** if (track_info.ID == -1): UI.DisplayMessage('Bad track ID for landing') ! UI.CompletedOrder() return # invalid id --- 522,526 ---- if (track_info.ID == -1): UI.DisplayMessage('Bad track ID for landing') ! TI.EndTask() return # invalid id *************** *** 425,429 **** if (landing_data.ID == -1): UI.DisplayMessage('Invalid landing platform') ! UI.CompletedOrder() return # invalid id --- 528,532 ---- if (landing_data.ID == -1): UI.DisplayMessage('Invalid landing platform') ! TI.EndTask() return # invalid id *************** *** 437,441 **** UI.DisplayMessage('Landing on platform %d' % track_info.ID) UI.SetAlt(1200 + alt_m) ! UI.SetVar(0,1) track_info.Offset(8, landing_data.Heading_rad + 3.1416) # approach from rear for now elif (land_state == 2): --- 540,544 ---- UI.DisplayMessage('Landing on platform %d' % track_info.ID) UI.SetAlt(1200 + alt_m) ! TI.SetMemoryValue(2, 1) track_info.Offset(8, landing_data.Heading_rad + 3.1416) # approach from rear for now elif (land_state == 2): *************** *** 453,462 **** if (TTI <= 4): ! UI.SetVar(0,land_state+1) # move to next landing state ! UI.SetUpdate(4) elif (TTI <= 20): ! UI.SetUpdate(3) else: ! UI.SetUpdate(10) --- 556,565 ---- if (TTI <= 4): ! TI.SetMemoryValue(2, land_state+1) # move to next landing state ! TI.SetUpdateInterval(4) elif (TTI <= 20): ! TI.SetUpdateInterval(3) else: ! TI.SetUpdateInterval(10) Index: UnitCommands.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/UnitCommands.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** UnitCommands.py 11 Dec 2004 01:09:06 -0000 1.13 --- UnitCommands.py 2 Mar 2005 22:28:41 -0000 1.14 *************** *** 1,2 **** --- 1,6 ---- + + def AddEngageAllOrder(UI): + UI.AddTask('EngageAll', 2.0) + def AddWaypointOrderGroup(GI, lon, lat): unit_count = GI.GetUnitCount() *************** *** 6,10 **** def AddWaypointOrder(UI, lon, lat): ! UI.AddNavOrder(lon,lat) --- 10,14 ---- def AddWaypointOrder(UI, lon, lat): ! UI.AddNavWaypoint(lon, lat) *************** *** 16,51 **** def AddPatrolOrder(UI): ! UI.AddOrder('Patrol',0) def AddLandingOrder(UI, dest_id): if (UI.IsHelo()): ! UI.AddOrder('LandHelo', dest_id) else: ! UI.AddOrder('Land', dest_id) ! def ClearOrdersGroup(GI): unit_count = GI.GetUnitCount() for n in range(0, unit_count): UnitInfo = GI.GetPlatformInterface(n) ! ClearOrders(UnitInfo) - def ClearOrders(UI): - UI.ClearOrders() - def EraseLastOrder(UI): - n_orders = UI.GetOrderCount() - if (n_orders > 0): - UI.DeleteOrder(n_orders-1) # clears all orders, moves to location and starts patrol def MoveToAndPatrol(UI, lon, lat): ! ClearOrders(UI) AddWaypointOrder(UI, lon, lat) - AddPatrolOrder(UI) ! def AddCrashOrder(UI): ! UI.AddOrder('Crash',0) def LaunchDatum(UI, lon, lat, launcher_num): --- 20,67 ---- def AddPatrolOrder(UI): ! UI.AddTask('Patrol', 1.0) ! ! def AddPatrolStation(UI, lon, lat): ! UI.AddTask('PatrolCircle', 1.0) ! BB = UI.GetBlackboardInterface() ! BB.Write('StationLongitude', '%f' % lon) ! BB.Write('StationLatitude', '%f' % lat) ! BB.Write('StationAltitude', '%f' % UI.GetAlt()) def AddLandingOrder(UI, dest_id): if (UI.IsHelo()): ! UI.AddTask('LandHelo', 3.0) else: ! UI.AddTask('Land', 3.0) ! ! dest_name = UI.LookupFriendlyName(dest_id) ! BB = UI.GetBlackboardInterface() ! BB.Write('LandingTarget', dest_name) ! def ClearTasksGroup(GI): unit_count = GI.GetUnitCount() for n in range(0, unit_count): UnitInfo = GI.GetPlatformInterface(n) ! ClearTasks(UnitInfo) ! ! def ClearTasks(UI): ! UI.ClearTasks() ! ! def ClearWaypoints(UI): ! UI.DeleteTask('Nav') # clears all orders, moves to location and starts patrol def MoveToAndPatrol(UI, lon, lat): ! ClearTasks(UI) ! UI.AddTask('Patrol', 1.0) ! UI.AddTask('Nav', 2.0) ! UI.AddTask('EngageAll', 3.0) AddWaypointOrder(UI, lon, lat) ! def LaunchDatum(UI, lon, lat, launcher_num): *************** *** 241,249 **** for n in range(0, n_sensors): sens_info = UI.GetSensorInfo(n) ! if (sens_info.type == 0): # 0 is radar, 1 is ESM, 255 is error if (sens_info.isActive): UI.SetSensorState(n, 0) else: UI.SetSensorState(n, 1) ! UI.PlaySound(11) --- 257,267 ---- for n in range(0, n_sensors): sens_info = UI.GetSensorInfo(n) ! ! # 1 radar, 2 ESM, 4 passive sonar, 8 active sonar, 16 optical, 0 error ! if (sens_info.type == 1): if (sens_info.isActive): UI.SetSensorState(n, 0) else: UI.SetSensorState(n, 1) ! UI.PlaySound('Ping') Index: Menu.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/Menu.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Menu.py 5 Dec 2004 02:49:46 -0000 1.10 --- Menu.py 2 Mar 2005 22:28:41 -0000 1.11 *************** *** 46,54 **** # Group orders ! GroupMenu.AddItem('Orders','') GroupMenu.BeginSubMenu() ! GroupMenu.AddItem('Add patrol order','AddPatrolOrderGroup') ! GroupMenu.AddItemUI('Add waypoint order', 'AddWaypointOrderGroup', 'Datum') ! GroupMenu.AddItem('Clear orders','ClearOrdersGroup') GroupMenu.EndSubMenu() --- 46,54 ---- # Group orders ! GroupMenu.AddItem('Tasks','') GroupMenu.BeginSubMenu() ! GroupMenu.AddItem('Zig-zag patrol','AddPatrolOrderGroup') ! GroupMenu.AddItemUI('Add waypoint', 'AddWaypointOrderGroup', 'Datum') ! GroupMenu.AddItem('Clear all tasks','ClearTasksGroup') GroupMenu.EndSubMenu() *************** *** 80,88 **** # Orders test ! UnitMenu.AddItem('Orders','') UnitMenu.BeginSubMenu() ! UnitMenu.AddItem('Add patrol order','AddPatrolOrder') ! UnitMenu.AddItemUI('Add waypoint order', 'AddWaypointOrder', 'Datum') ! UnitMenu.AddItem('Clear orders','ClearOrders') UnitMenu.EndSubMenu() --- 80,91 ---- # Orders test ! UnitMenu.AddItem('Tasks','') UnitMenu.BeginSubMenu() ! UnitMenu.AddItem('ZigZag patrol','AddPatrolOrder') ! UnitMenu.AddItemUI('Patrol station','AddPatrolStation', 'Datum') ! UnitMenu.AddItemUI('Add waypoint', 'AddWaypointOrder', 'Datum') ! UnitMenu.AddItem('EngageAll', 'AddEngageAllOrder') ! UnitMenu.AddItem('Clear waypoints','ClearWaypoints') ! UnitMenu.AddItem('Clear all tasks','ClearTasks') UnitMenu.EndSubMenu() |