The following script commands a plane to execute very high accuracy bombs attacks against an array of targets.
The plane will proceed with each target in the array in sequence, attacking the next one once the current target is destroyed.
If the plane gets too much damage during the mission, the crew will eject and, if indicated, the crew will radio its last position in map coordinates.
If you set the camera to follow the plane, the camera will follow also the bombs once dropped until implact, the camera will follow also the crew if ejects.
Works quite well against static targets, will not work against moving targets, uless they stop before the plane enganges.
;mandoairstrike.sqs
;By Mandoble, valdelar@terra.es
;
;Executes high accuracy free-fall bombs attacks
;
;If the plane gets too much damage during the mission, the crew will eject and,
;if alive, the pilot will radio his map coordinates
;
;Arguments:
; striking plane
; target array
; bombtype for right wing pilon or "" if none (ex.: "LaserGuidedBomb")
; bombtype for left wing pilon or "" if none (ex.: "LaserGuidedBomb")
; Accuracy (1.0 max, 0.0 min.) Min accuracy means plane can miss by up to 100m from the target
; Maximum allowabe damage before ejecting crew (0.1-0.9)
; Climb rate in m/s after releasing bombs, this is applied for few secons after dropping bombs
; Retry if bombs fail target (true/false)
; radio on/off (true/false)
; camera on/off (true/false)
;
; Example:
; [plane1,[tank1,bmp1,tank2,tank4],"LaserGuidedBomb","LaserGuidedBomb",1.0,0.6,10.0,false,true,true]exec"mandoairstrike.sqs"
;
;[avion1, [casa, tanque1, barco1, tanque2, tanque3], "SmokeShellGreen","", 1.0, 0.6, 10.0, false, true, true]exec"mandoairstrike.sqs"
_letras1 = ["A","B","C","D","E","F","G","H","I","J"]
_letras2 = ["a","b","c","d","e","f","g","h","i","j"]
_numeros1 = ["9","8","7","6","5","4","3","2","1","0"]
_numeros2 = ["9","8","7","6","5","4","3","2","1","0"]
_maxx1 = 12800
_maxx2 = 1280
_maxy1 = 12800
_maxy2 = 1280
_plane = _this select 0
_targets = _this select 1
_bombtype1 = _this select 2
_bombtype2 = _this select 3
_accuracy = _this select 4
_maxdmg = _this select 5
_climbrt = _this select 6
_retry = _this select 7
_radio = _this select 8
_camera = _this select 9
?(_maxdmg > 0.9)||(_maxdmg < 0.1):_maxdmg = 0.5
?(_accuracy > 1.0)||(_accuracy < 0.0):_accuracy = 0.8
?(_climbrt < 2.0) || (_climbrt > 15.0):_climbrt= 8.0
?_camera:_plane switchCamera "EXTERNAL"
_pilot = driver _plane
_behpilot = behaviour _pilot
_gunner = gunner _plane
_behgunner = behaviour _gunner
_combatpilot = combatMode _pilot
_combatgunner = combatMode _pilot
_det = "EmptyDetector" camCreate [0,0,0]
_log = "logic" camCreate [0,0,0]
_ntargets = count _targets
_pilot setBehaviour "CARELESS"
_gunner setBehaviour "CARELESS"
_pilot setCombatMode "BLUE"
_gunner setCombatMode "BLUE"
_dir = getDir _plane
_log1 = "logic" camCreate [(getPos _plane select 0)+1500*sin(_dir), (getPos _plane select 1)+1500*cos(_dir),80]
~1
_pilot doTarget _log1
_gunner doTarget _log1
~1
deleteVehicle _log1
_t = 0
#target
_target = _targets select _t
#start
?_plane distance _target > 2000:goto "align"
_ang = ((getPos _target select 0)-(getPos _plane select 0)) atan2 ((getPos _target select 1)-(getPos _plane select 1))
_ang = _ang + 180
_pos = [(getPos _target select 0)+sin(_ang)*2000,(getPos _target select 1)+cos(_ang)*2000,0]
_pilot doMove _pos
?_radio: _pilot sideChat "Moving to attack position"
~1
@(unitReady _pilot)|| (damage _plane > _maxdmg)
?damage _plane > _maxdmg:goto "eject"
#align
?_radio: _pilot sideChat "Aligning with the target"
_ang = ((getPos _target select 0)-(getPos _plane select 0)) atan2 ((getPos _target select 1)-(getPos _plane select 1))
_ang = _ang + 180
_pos = [(getPos _target select 0)+sin(_ang)*1000,(getPos _target select 1)+cos(_ang)*1000,0]
_log setPos _pos
_det setPos [getPos _target select 0, getPos _target select 1, 0]
_dst0 = _det distance _target
_det setPos [_pos select 0, _pos select 1, 0]
_dstl = _det distance _log
_delta = _dstl - _dst0
?_delta < 80.0: _plane flyInHeight (80.0 + abs(_delta))
?_delta >= 0.0: _plane flyInHeight 80.0
_posfin = getPos _target
_pilot doMove _posfin
@((_plane distance _target) < 1000) || (damage _plane > _maxdmg)
?damage _plane > _maxdmg:goto "eject"
_ang = ((getPos _target select 0)-(getPos _plane select 0)) atan2 ((getPos _target select 1)-(getPos _plane select 1))
?_radio: _pilot sideChat "Final aproach"
;_dir = getDir _plane
_dir = _ang
_spd = speed _plane
_spd = _spd / 3.6
_det setPos [getPos _plane select 0, getPos _plane select 1, 0]
_dst1 = _det distance _plane
_dst = _dst1 - _dst0
_dst = _dst - 1.0
_log setPos[getPos _target select 0, getPos _target select 1, _dst]
_vfin = sqrt(2*9.8*_dst)
_tim = _vfin / 9.8
_rang = _spd*_tim
_rang = _rang + (1.0-_accuracy)*(100.0 - random 200.0)
_vel = [sin(_dir)*_spd,cos(_dir)*_spd,0]
#aim
_plane setDir _dir
_plane setVelocity _vel
?damage _plane > _maxdmg:goto "eject"
~0.01
?(_log distance _plane) > _rang: goto "aim"
?_radio: _pilot sideChat "Bombs away!"
;Change the following six lines if you need more than two bombs per attack
?_bombtype1 != "":_bomb1 = _bombtype1 camCreate[(getPos _plane select 0)+sin(_dir+90)*3, (getPos _plane select 1)+cos(_dir+90)*3,(getPos _plane select 2)-1]
?_bombtype2 != "":_bomb2 = _bombtype2 camCreate[(getPos _plane select 0)+sin(_dir-90)*3, (getPos _plane select 1)+cos(_dir-90)*3,(getPos _plane select 2)-1]
?_bombtype1 != "":_bomb1 setDir _dir;_bomb1 setVelocity _vel
?_bombtype2 != "":_bomb2 setDir _dir;_bomb2 setVelocity _vel
?(_bombtype1 != "") && _camera:_bomb1 switchCamera "EXTERNAL"
_rang = _rang / 2.0
_vel = [_vel select 0, _vel select 1, _climbrt]
#aim2
_plane setDir _dir
_plane setVelocity _vel
?damage _plane > _maxdmg:goto "eject"
~0.01
?(_log distance _plane) > _rang: goto "aim2"
~(_tim + 4)
?_camera:_plane switchCamera "EXTERNAL"
?_radio && (damage _target > 0.9):_pilot sideChat "Target destroyed!"
?_radio && (damage _target <= 0.8) && _retry:_pilot sideChat "Trying again"
?_radio && (damage _target <= 0.8) && !_retry:_pilot sideChat "Target not destroyed"
?(damage _target <= 0.8)&& _retry:goto "start"
_t = _t + 1
?(_t < _ntargets)&&_radio:_pilot sideChat "Proceeding with next target"
?_t < _ntargets:goto "target"
?_radio:_pilot sideChat "Mission accomplished"
_pilot setBehaviour _behpilot
_gunner setBehaviour _behgunner
_pilot setCombatMode _combatpilot
_gunner setCombatMode _combatgunner
deleteVehicle _det
deleteVehicle _log
?_camera:player switchCamera "EXTERNAL"
exit
#eject
?_radio:_pilot sideChat "We got too much damage, ejecting!"
_crew = crew _plane
"_x action [""eject"",_plane]" forEach _crew
deleteVehicle _det
deleteVehicle _log
~3
?_camera:vehicle _pilot switchCamera "EXTERNAL"
@vehicle _pilot == _pilot
?_camera:_pilot switchCamera "EXTERNAL"
~4
?!alive _pilot && _camera: player switchCamera "EXTERNAL"
?!alive _pilot: exit
_pilot setBehaviour "AWARE"
_pilot setCombatMode "RED"
_gunner setBehaviour "AWARE"
_gunner setCombatMode "RED"
_pilot move getPos _pilot
_xu = getPos vehicle _pilot select 0
_yu = getPos vehicle _pilot select 1
_l1 = 10 * _xu / _maxx1
_l1 = _l1 - (_l1 mod 1)
_n1 = 10 * _yu / _maxy1
_n1 = _n1 - (_n1 mod 1)
_xu = _xu - _l1*_maxx2
_l2 = 10 * _xu / _maxx2
_l2 = _l2 - (_l2 mod 1)
_yu = _yu - _n1*_maxy2
_n2 = 10 * _yu / _maxy2
_n2 = _n2 - (_n2 mod 1)
_coordstr = format["%1%2-%3%4", _letras1 select _l1, _letras2 select _l2, _numeros1 select _n1, _numeros2 select _n2]
_msg = format["We are downed, position %1", _coordstr]
?_radio:_pilot sideChat _msg
?_camera:player switchCamera "EXTERNAL"
exit
EDIT: Changed code so that plane does not engange by its own.
EDIT2: Added climb rate argument in m/s. This climb rate is applied to the plane for few seconds after releasing the bombs to prevent crashing with them.
EDIT3: Added bombtype for left and right wing pilons.