Home   Help Search Login Register  

Author Topic: High accuracy free-fall bombs air attacks  (Read 3040 times)

0 Members and 1 Guest are viewing this topic.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
High accuracy free-fall bombs air attacks
« on: 17 Jun 2006, 20:31:07 »
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.

Code: [Select]
;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.
« Last Edit: 19 Jun 2006, 20:19:45 by Mandoble »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: High accuracy free-fall bombs air attacks
« Reply #1 on: 18 Jun 2006, 00:26:04 »
Script edited above:
- Attacks at very high speed are now possible and accurate (800 kmh low level).
- Now accuracy can be set from 0.0 to 1.0. 0.0 may give errors of up to 100m from the target, 1.0 will hit directly or miss by no more than 1 - 10 meters.
- You may choose between retry the attack against a target if bombs dont destroy it.
- No more limitations against target higher than plane, plane will automatically correct its flying height to be above target level at bomb drop time.

NOTE: do not use high drag bombs types or bombs with braking chutes.

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: High accuracy free-fall bombs air attacks
« Reply #2 on: 18 Jun 2006, 13:52:46 »
thanks for this m8,
          works like a treat with the AV8 B :). with this and arty theres gonna be mahem ;)
I love ofp

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: High accuracy free-fall bombs air attacks
« Reply #3 on: 18 Jun 2006, 16:55:25 »
Just make sure the plane is not enganing any target before executing this script, else the plane will ignore the move commands and will keep trying to attack the current target.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: High accuracy free-fall bombs air attacks
« Reply #4 on: 18 Jun 2006, 17:02:09 »
Different version of the script, in this case the plane will create its own list of targets (only vehicles). Instead of passing an array of targets, this time you provide a trigger for the attacking plane. The trigger should be of type "enemy side" present repeatedly and the radius of the trigger determines how far from the plane targets can be automatically locked.

Code: [Select]
;mandoairstrikeauto.sqs
;By Mandoble, valdelar@terra.es
;
;Executes high accuracy free-fall bombs attacks
;The plane will fly towards the indicated CAS position and then
;will select and attack targets based on passed trigger.
;
;If the plane gets too much damage during the mission, the crew will eject and,
;if alive, the pilot will radio his map coordinates
;
;NOTE: Make sure the plane is not enganging any target before executing this script
;
;
;Arguments:
; striking plane
; CAS initial position from where the plane will start the attacks
; trigger for targets selection (type enemy side present repeatedly)
; Mission time in seconds 120 - 3600, once exceeded the mission will end.
; bombtype (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,getMarkerPos "mk_suppport", mytrigger,600, "LaserGuidedBomb",1.0,0.6,10.0,false,true,true]exec"mandoairstrikeauto.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
_caspos    = _this select 1
_trigger   = _this select 2
_totaltime = _this select 3
_bombtype  = _this select 4
_accuracy  = _this select 5
_maxdmg    = _this select 6
_climbrt   = _this select 7
_retry     = _this select 8
_radio     = _this select 9
_camera    = _this select 10

?(_maxdmg > 0.9)||(_maxdmg < 0.1):_maxdmg = 0.5
?(_accuracy > 1.0)||(_accuracy < 0.0):_accuracy = 0.8
?(_totaltime > 3600.0)||(_totaltime < 120.0):_totaltime = 300
?(_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]
_rangmin      = 2500

_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

_primera = false
_timeini  = time



#cas
_pilot doMove _caspos
~1
@unitReady _pilot

?_radio && !_primera:_pilot sideChat "CAS area reached"
_primera = true

#target
?time - _timeini > _totaltime:goto "fin"
_trigger setPos [getPos _plane select 0, getPos _plane select 1, 0]
~1
_list = []
_list = _list + list _trigger

_tok = -1
_t = 0
"if((damage _x < 0.8)&&(driver _x != _x))then{_tok = _t};_t=_t+1" forEach _list
~1
_trigger setPos [0,0,0]
?_tok == -1:goto "cas"
_target = _list select _tok
?_radio:_pilot sideChat format["Target adquired: %1", typeOf _target]

#start
?_plane distance _target > _rangmin: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)*_rangmin,(getPos _target select 1)+cos(_ang)*_rangmin,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
_bomb1 = _bombtype camCreate[(getPos _plane select 0)+sin(_dir+90)*3, (getPos _plane select 1)+cos(_dir+90)*3,(getPos _plane select 2)-1]
_bomb2 = _bombtype camCreate[(getPos _plane select 0)+sin(_dir-90)*3, (getPos _plane select 1)+cos(_dir-90)*3,(getPos _plane select 2)-1]
_bomb1 setDir _dir
_bomb1 setVelocity _vel
_bomb2 setDir _dir
_bomb2 setVelocity _vel
?_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"
?time - _timeini > _totaltime:goto "fin"
?(damage _target <= 0.8)&& _retry:goto "start"
goto "target"

#fin
?_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

EDITED: Added climb rate parameter. Climb rate in m/s to apply to the plane after releasing bombs to prevent it crashing with own bombs.
« Last Edit: 18 Jun 2006, 20:37:03 by Mandoble »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: High accuracy free-fall bombs air attacks
« Reply #5 on: 18 Jun 2006, 18:36:57 »
Critical update.

Both scripts modified so that doesnt matter whether attacking plane is already enganged or not before executing the scripts. The plane will cancel current target, if any, and proceed with the assigned bombing mission.

Offline subroc

  • Members
  • *
Re: High accuracy free-fall bombs air attacks
« Reply #6 on: 19 Jun 2006, 14:06:16 »
would it also be possible to use a "enemy detected" trigger and make the  plane only attack targets that it detects or detected by player

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: High accuracy free-fall bombs air attacks
« Reply #7 on: 19 Jun 2006, 19:49:19 »
Yes, you may use these kind of triggers for the mandoairstrikeauto.sqs script. But it would be even better to add a minimum "knowsabout" parameter to the script, so the CAS plane enganes only enemy vehicles with at least that minimum "knowsabout" by the plane's pilot.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: High accuracy free-fall bombs air attacks
« Reply #8 on: 19 Jun 2006, 20:23:31 »
mandoairstrike.sqs modified to add bomb type for each wing pilon (right and left), now you may select bomb type or "" if none. This way you may use planes to mark targets with coloured smoke instead of dropping bombs. This is an example:

Code: [Select]
[plane1, [house1, tank1, ship1, tank2, tank3], "SmokeShellGreen","", 1.0, 0.6, 10.0, false, true, true]exec"mandoairstrike.sqs"
« Last Edit: 20 Jun 2006, 00:24:36 by Mandoble »