Thread: [Gcblue-commits] gcb_wx/scripts AI.py,1.6,1.7
Status: Alpha
Brought to you by:
ddcforge
From: <ddc...@us...> - 2004-01-08 23:54:30
|
Update of /cvsroot/gcblue/gcb_wx/scripts In directory sc8-pr-cvs1:/tmp/cvs-serv11677/scripts Modified Files: AI.py Log Message: Index: AI.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/AI.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AI.py 5 Jan 2004 02:48:02 -0000 1.6 --- AI.py 8 Jan 2004 23:54:27 -0000 1.7 *************** *** 15,37 **** return elif (order_name == 'Patrol'): ! targetid = UnitInfo.GetTarget() ! if targetid != 0xFFFFFFFF: ! InterceptTarget(UnitInfo) ! return ! UnitInfo.SetVar(0,0) # set user variable 0 to zero ! # patrol box ! UnitInfo.SetAllSensorState(1) ! heading = UnitInfo.GetHeading() ! heading = heading + 45.0 ! if (heading >= 360.0): ! heading = heading - 360.0 ! UnitInfo.SetHeading(heading) ! UnitInfo.SetUpdate(30.0) ! # engage hostiles in range ! track_id = GetSuitableTarget(UnitInfo) ! if (track_id != 0xFFFFFFFF): ! UnitInfo.SetTarget(track_id) ! UnitInfo.SetHeadingToInterceptTarget() ! UnitInfo.SetUpdate(4.0) elif (order_name == 'Crash'): UnitInfo.SetAlt(0) --- 15,19 ---- return elif (order_name == 'Patrol'): ! Patrol(UnitInfo) elif (order_name == 'Crash'): UnitInfo.SetAlt(0) *************** *** 52,55 **** --- 34,39 ---- UnitInfo.CompletedOrder() AvoidGround(UnitInfo) # adjust altitude to avoid crashing into terrain + elif (order_name == 'ZigZagPatrol'): + ZigZagPatrol(UnitInfo) *************** *** 64,67 **** --- 48,117 ---- + def Patrol(UI): + targetid = UI.GetTarget() + if targetid != 0xFFFFFFFF: + InterceptTarget(UI) + return + UI.SetVar(0,0) # set user variable 0 to zero + # patrol box + UI.SetAllSensorState(1) + heading = UI.GetHeading() + heading = heading + 45.0 + if (heading >= 360.0): + heading = heading - 360.0 + UI.SetHeading(heading) + UI.SetUpdate(30.0) + # engage hostiles in range + track_id = GetSuitableTarget(UI) + if (track_id != 0xFFFFFFFF): + UI.SetTarget(track_id) + UI.SetHeadingToInterceptTarget() + UI.SetUpdate(4.0) + + # Patrols in given direction, zig-zagging along the way + # then reverses path + def ZigZagPatrol(UI): + targetid = UI.GetTarget() + if targetid != 0xFFFFFFFF: + InterceptTarget(UI) + return + call_count = UI.GetVar(0) + call_count = call_count + 1 + UI.SetVar(0, call_count) # increment call count + if (call_count == 1): + UI.SetVar(1, int(UI.GetHeading())) # this heading is used to determine patrol direction + UI.SetAllSensorState(1) + if (UI.Rand() < 0.5): + UI.SetVar(2, 1) + else: + UI.SetVar(2, 0) + + axis_heading = float(UI.GetVar(1)) + go_left = UI.GetVar(2) + if (go_left == 1): + UI.SetHeading(axis_heading - 30) + else: + UI.SetHeading(axis_heading + 30) + + UI.SetUpdate(20.0 + 2*UI.Rand()) + # engage hostiles in range + track_id = GetSuitableTarget(UI) + if (track_id != 0xFFFFFFFF): + UI.SetTarget(track_id) + UI.SetHeadingToInterceptTarget() + UI.SetUpdate(4.0) + + # abs() of difference between two radian headings + def RadianHeadingDiff(h1, h2): + delta = h1 - h2 + if (delta < -3.14159): + delta = delta + 6.28318 + elif (delta > 3.14159): + delta = delta - 6.28318 + if (delta < 0): + delta = -delta + return delta + + # Run from hostile missiles (will run from antiship missiles too!) # return 1 if evading, 0 otherwise *************** *** 69,77 **** if (UI.IsAir()==0): return 0 # only evade with air platforms ! threat_track = UI.GetClosestMissileTrack(100, 3) if (threat_track.IsValid()): - print 'fleeing' - flee_heading = UI.GetInterceptHeadingToTrack(threat_track) + 3.14 UI.SetHeadingRad(flee_heading) # run from missile if (UI.GetFuel() > 0.2): --- 119,146 ---- if (UI.IsAir()==0): return 0 # only evade with air platforms + + max_range = 100 # max range in km to look for missile threats + track_list = UI.GetTrackList(64, max_range, 3) # 64 returns missiles, 3 hostiles + nMissiles = track_list.Size() + closest_range = 10000 + foundThreat = 0 + flee_heading = 0 + for n in range(0, nMissiles): + missile_track = track_list.GetTrack(n) + track_range = UI.GetRangeToTrack(missile_track) + if (track_range < closest_range) or (~foundThreat): + int_heading = UI.GetInterceptHeadingToTrack(missile_track) + heading_diff = RadianHeadingDiff(int_heading, UI.GetHeadingRad()) + diff_thresh = 15/track_range # 90 deg at 10 km + if (heading_diff < diff_thresh): + foundThreat = 1 + closest_range = track_range + flee_heading = int_heading + 3.14 + threat_track = missile_track ! if (foundThreat==0): ! return 0 ! if (threat_track.IsValid()): UI.SetHeadingRad(flee_heading) # run from missile if (UI.GetFuel() > 0.2): *************** *** 79,83 **** else: SetFractionalSpeed(UI, 1.0) ! UI.SetUpdate(4.0) return 1 else: --- 148,152 ---- else: SetFractionalSpeed(UI, 1.0) ! UI.SetUpdate(6.0) return 1 else: |