_array = _this select 0
_weapon = _array select 1
_ammoname = _array select 4
_plane = _array select 0


#main
?(_weapon == "BOHm61p_945"): goto "Exit"

_AAM3count = _plane ammo "BOHaam3_4"
_AAM4count = _plane ammo "BOHaam4"

? (_ammoname == "BOHaam4"): goto "AAM4"
? (_ammoname == "BOHaam3"): goto "AAM3"

#AAM4
? (_AAM4count == 3) : goto "AAM4A"
? (_AAM4count == 2) : goto "AAM4B"
? (_AAM4count == 1) : goto "AAM4C"
? (_AAM4count == 0) : goto "AAM4D"

#AAM3
? (_AAM3count == 3) : goto "AAM3A"
? (_AAM3count == 2) : goto "AAM3B"
? (_AAM3count == 1) : goto "AAM3C"
? (_AAM3count == 0) : goto "AAM3D"

#AAM4A
_plane setobjecttexture[14, "\BOHJSDF4\AW\AAM4.paa"]
_plane setobjecttexture[13, "\BOHJSDF4\AW\AAM4.paa"]
_plane setobjecttexture[12, "\BOHJSDF4\AW\AAM4.paa"]
_plane setobjecttexture[11, ""]
_missmove = -1.5
goto "MoveMissile"

#AAM4B
_plane setobjecttexture[14, "\BOHJSDF4\AW\AAM4.paa"]
_plane setobjecttexture[13, "\BOHJSDF4\AW\AAM4.paa"]
_plane setobjecttexture[12, ""]
_plane setobjecttexture[11, ""]
_missmove =  1.5
goto "MoveMissile"

#AAM4C
_plane setobjecttexture[14, "\BOHJSDF4\AW\AAM4.paa"]
_plane setobjecttexture[13, ""]
_plane setobjecttexture[12, ""]
_plane setobjecttexture[11, ""]
_missmove = -1.5
goto "MoveMissile"

#AAM4D
_plane setobjecttexture[14, ""]
_plane setobjecttexture[13, ""]
_plane setobjecttexture[12, ""]
_plane setobjecttexture[11, ""]
_missmove =  1.5
goto "MoveMissile"

#AAM3A
_plane setobjecttexture[18, "\BOHJSDF4\AW\AAM3.paa"]
_plane setobjecttexture[17, "\BOHJSDF4\AW\AAM3.paa"]
_plane setobjecttexture[16, "\BOHJSDF4\AW\AAM3.paa"]
_plane setobjecttexture[15, ""]
_missmove = -3.33
goto "MoveMissile"

#AAM3B
_plane setobjecttexture[18, "\BOHJSDF4\AW\AAM3.paa"]
_plane setobjecttexture[17, "\BOHJSDF4\AW\AAM3.paa"]
_plane setobjecttexture[16, ""]
_plane setobjecttexture[15, ""]
_missmove =  3.33
goto "MoveMissile"

#AAM3C
_plane setobjecttexture[18, "\BOHJSDF4\AW\AAM3.paa"]
_plane setobjecttexture[17, ""]
_plane setobjecttexture[16, ""]
_plane setobjecttexture[15, ""]
_missmove = -2.665
goto "MoveMissile"

#AAM3D
_plane setobjecttexture[18, ""]
_plane setobjecttexture[17, ""]
_plane setobjecttexture[16, ""]
_plane setobjecttexture[15, ""]
_missmove =  2.665
goto "MoveMissile"


#MoveMissile
_missobj = nearestobject[_plane, _ammoname]
_missdir = direction _missobj
_zpos = (getpos _plane select 2) + 1.5
_xpos = ( (getpos _plane) select 0 ) + (_missmove * cos(_missdir))
_ypos = ( (getpos _plane) select 1 ) - (_missmove * sin(_missdir))
_sensor = "EmptyDetector" createVehicle [0,0,0]
_sensor setpos [getpos _plane select 0, getpos _plane select 1]; 
_result = getpos _sensor select 2;
_zpos = _zpos - _result
_missobj setpos[_xpos, _ypos, _zpos]
? (_ammoname == "BOHaam4"): [_plane, _missobj, _ammoname] exec "\BOHCONFIG\scripts\BOH_fuse.sqs"

#Exit
exit
