[Gcblue-commits] gcb_wx/scripts AI.py,1.21,1.22 Menu.py,1.13,1.14 UnitCommands.py,1.18,1.19
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-07-02 16:51:20
|
Update of /cvsroot/gcblue/gcb_wx/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24188/scripts Modified Files: AI.py Menu.py UnitCommands.py Log Message: Index: AI.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/AI.py,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** AI.py 29 Mar 2005 00:12:25 -0000 1.21 --- AI.py 2 Jul 2005 16:51:11 -0000 1.22 *************** *** 1,3 **** --- 1,4 ---- from UnitCommands import * + import math # test AI script, these need a lot of work *************** *** 310,313 **** --- 311,443 ---- # for duration of engagement + # Adjust heading toward target, maintain altitude and speed to release point, + # release ALL bombs at release point, and then reverse course + def BombTarget(TI): + UI = TI.GetPlatformInterface() + BB = TI.GetBlackboardInterface() + + iteration = TI.GetMemoryValue(1) # will return 0 first time + if (iteration == 0): # do initialization + TI.SetMemoryText('Description', 'Head to and bomb target') + TI.SetMemoryValue(2, 1) # state: 1 - fly to release, 2 - release + + iteration = iteration + 1 + TI.SetMemoryValue(1, iteration) + + if (not GetConnControl(BB)): + return + + bomb_state = TI.GetMemoryValue(2) + if (bomb_state == 2): + DropAllBombs(UI) + UI.SetHeading(UI.GetHeading() + 160) + UI.SetActionText('') + TI.EndTask() + return + + + track_info = UI.GetTargetTrackInfo() + tgt_lat = track_info.Lat + tgt_lon = track_info.Lon + tgt_alt = UI.GetMapTerrainElevation(tgt_lon, tgt_lat) # since we're bombing a ground target (does track have same altitude value?) + + # adjust heading to target + tgt_bearing = UI.GetHeadingToDatum(tgt_lon,tgt_lat) + UI.SetHeading(tgt_bearing) + + tgt_range_m = 1000 * UI.GetRangeToTrack(track_info) # horizontal range in m + own_speed_mps = 0.51444444 * UI.GetSpeed() # get speed in m/s + own_alt_m = UI.GetAlt() + d_alt_m = own_alt_m - tgt_alt + if (d_alt_m < 0): + TI.EndTask() + return + + t_flight = math.sqrt(0.20394324 * (own_alt_m - tgt_alt)) + release_range_m = t_flight * own_speed_mps + range_left_m = tgt_range_m - release_range_m + if (range_left_m < 0): + DisplayMessage('Bomb run failed. Too close, too fast or too high') + TI.EndTask() + return + + # calculate time to release + t_release = range_left_m / own_speed_mps + if (t_release < 10): + TI.SetUpdateInterval(t_release) + TI.SetMemoryValue(2, 2) # release all bombs next update + UI.SetActionText('Away %.0f s' % t_release) + else: + TI.SetUpdateInterval(9.0) + UI.SetActionText('Bomb %.0f s' % t_release) + + + # Version that bombs a datum without requiring a target based on a sensor map track + def BombDatum(TI): + UI = TI.GetPlatformInterface() + BB = TI.GetBlackboardInterface() + + iteration = TI.GetMemoryValue(1) # will return 0 first time + if (iteration == 0): # do initialization + TI.SetMemoryText('Description', 'Head to and bomb datum') + TI.SetMemoryValue(2, 1) # state: 1 - fly to release, 2 - release + datum_lon = GetMessageParam(BB, 'DatumLongitude') + datum_lat = GetMessageParam(BB, 'DatumLatitude') + TI.SetMemoryValue(10, datum_lon) + TI.SetMemoryValue(11, datum_lat) + + iteration = iteration + 1 + TI.SetMemoryValue(1, iteration) + + if (not GetConnControl(BB)): + return + + bomb_state = TI.GetMemoryValue(2) + if (bomb_state == 2): + DropAllBombs(UI) + UI.SetHeading(UI.GetHeading() + 160) + UI.SetActionText('') + TI.EndTask() + return + + + tgt_lon = TI.GetMemoryValue(10) + tgt_lat = TI.GetMemoryValue(11) + tgt_alt = UI.GetMapTerrainElevation(tgt_lon, tgt_lat) # since we're bombing a ground target (does track have same altitude value?) + + # adjust heading to target + tgt_bearing = UI.GetHeadingToDatum(tgt_lon, tgt_lat) + UI.SetHeading(tgt_bearing) + + tgt_range_m = 1000 * UI.GetRangeToDatum(tgt_lon, tgt_lat) # horizontal range in m + own_speed_mps = 0.51444444 * UI.GetSpeed() # get speed in m/s + own_alt_m = UI.GetAlt() + d_alt_m = own_alt_m - tgt_alt + if (d_alt_m < 0): + TI.EndTask() + return + + t_flight = math.sqrt(0.20394324 * (own_alt_m - tgt_alt)) + release_range_m = t_flight * own_speed_mps + range_left_m = tgt_range_m - release_range_m + if (range_left_m < 0): + DisplayMessage('Bomb run failed. Too close, too fast or too high') + TI.EndTask() + return + + # calculate time to release + t_release = range_left_m / own_speed_mps + if (t_release < 10): + TI.SetUpdateInterval(t_release) + TI.SetMemoryValue(2, 2) # release all bombs next update + UI.SetActionText('Away %.0f s' % t_release) + else: + TI.SetUpdateInterval(9.0) + UI.SetActionText('Bomb %.0f s' % t_release) + + + + + # gets info on closest (known) enemy or unknown platform within search range *************** *** 333,337 **** ! # returns id of closest target that is in-range, engageable, not already --- 463,485 ---- ! def DropAllBombs(UI): ! UI.DisplayMessage('Dropping all bombs') ! ! track_info = UI.GetTargetTrackInfo() ! ! tgt_lat = track_info.Lat ! tgt_lon = track_info.Lon ! tgt_alt = UI.GetMapTerrainElevation(tgt_lon, tgt_lat) ! ! nLaunchers = UI.GetLauncherCount() ! ! for n in range(0, nLaunchers): ! launcher_info = UI.GetLauncherInfo(n) ! if (launcher_info.LaunchMode == 2): ! UI.SendDatumToLauncher(tgt_lon,tgt_lat,tgt_alt,n) ! UI.Launch(n, 32) ! ! ! # returns id of closest target that is in-range, engageable, not already *************** *** 903,907 **** range_km = 0.0 ! launch_mode = launcher_info.LaunchMode # 0 - datum, 1 - seeker, 2 - other if target_info.IsAir(): --- 1051,1055 ---- range_km = 0.0 ! launch_mode = launcher_info.LaunchMode # 0 - datum, 1 - seeker, 2 - bomb, 3 - other if target_info.IsAir(): *************** *** 939,943 **** return ! launch_mode = launcher_info.LaunchMode # 0 - datum, 1 - seeker, 2 - other target_info = UI.GetTargetTrackInfo() --- 1087,1091 ---- return ! launch_mode = launcher_info.LaunchMode # 0 - datum, 1 - seeker, 2 - bomb, 3 - other target_info = UI.GetTargetTrackInfo() *************** *** 959,963 **** UI.Launch(launcher, launch_qty) UI.SetActionText('Datum launch') ! else: # handoff to active seeker target_accepted = UI.HandoffTargetToLauncher(launcher) if (target_accepted): --- 1107,1111 ---- UI.Launch(launcher, launch_qty) UI.SetActionText('Datum launch') ! elif launch_mode == 1: # handoff to active seeker target_accepted = UI.HandoffTargetToLauncher(launcher) if (target_accepted): Index: UnitCommands.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/UnitCommands.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** UnitCommands.py 11 Jun 2005 21:01:44 -0000 1.18 --- UnitCommands.py 2 Jul 2005 16:51:11 -0000 1.19 *************** *** 15,18 **** --- 15,26 ---- UI.AddTask('EngageAll', 2.0) + def AddBombTargetTask(UI): + UI.AddTask('BombTarget', 3.0) + + def AddBombDatumTask(UI, lon, lat): + BB = UI.GetBlackboardInterface() + BB.Write('DatumLongitude', '%f' % lon) + BB.Write('DatumLatitude', '%f' % lat) + UI.AddTask('BombDatum', 3.0) Index: Menu.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/Menu.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Menu.py 17 May 2005 00:20:40 -0000 1.13 --- Menu.py 2 Jul 2005 16:51:11 -0000 1.14 *************** *** 181,185 **** UnitMenu.AddItemUIWithParam('%s [%d]' % (weap_name, weap_qty), 'LaunchDatum', 'Datum', n) UnitMenu.EndSubMenu() ! # "Engage target with" menu lists launchers that are effective vs. selected target target_id = UnitInfo.GetTarget() --- 181,186 ---- UnitMenu.AddItemUIWithParam('%s [%d]' % (weap_name, weap_qty), 'LaunchDatum', 'Datum', n) UnitMenu.EndSubMenu() ! UnitMenu.AddItemUI('Bomb datum', 'AddBombDatumTask', 'Datum') ! # "Engage target with" menu lists launchers that are effective vs. selected target target_id = UnitInfo.GetTarget() *************** *** 194,197 **** --- 195,199 ---- UnitMenu.AddItemWithParam('%s [%d]' % (weap_name, weap_qty), 'LaunchTarget', n) UnitMenu.EndSubMenu() + UnitMenu.AddItem('Bomb target', 'AddBombTargetTask') # "Quick engage with" allows user to click on target and then automatically launch |