/* mando basic missile defense system mando_missileecm.sqf v1.1 Apr 2007 Mandoble The purpose is to add an automatic missile defense system for a unit (chaff or flares). The unit will use them automatically when needed. Parameters: Unit that has the CHAFF or FLARES packs Minimum distance beetween incomming missile and the unit to drop flares or chaff Type: 0 - Chaff, 1 - Flares Number of chaff or flares packs, each usage substracs one to this initial quantity radio: true/false, if unit sends radio messages indicating a missile incomming, chaff or flares dropped, missile evaded, etc. Example AV8B with a chaff system (10 chaff packets): [harrier1, 300, 0, 10, true]execVM"mando_units\mando_missileecm.sqf" */ private ["_unit", "_mindistecm", "_typeecm", "_NumOfCM","_ctrlmode","_radio", "_distlaunch", "_misecm", "_eh"]; _unit = _this select 0; _mindistecm = _this select 1; // Minimun Distance to Deploy CM in Control Mode == Automatic _typeecm = _this select 2; // Chaff(0)for Radar || Flares(1) for IR _NumOfCM = _this select 3; // Number of Counter-Measures _ctrlmode = _this select 4; // Deployment Control Mode: Automatic or Manual _radio = _this select 5; // Internal Cockpit Radio ON(1) or OFF(2) _posu = [0,0,0]; _vdir = [0,0,0]; _post = [0,0,0]; _color = [[0,1,0,1]]; if (((vehicle player) != _unit) && !(local Server)) exitwith { If (ARMA_DEBUG_lvl>1) Then { [1,format ["mando_CM_DefenseSystems.sqf-> Someone Just got in the driver seat of an Air Vehicle and it was not you: _This = %1 Server = %2",_this,(local server)],"server"] call six_fTxRadio; Sleep 0.5; }; }; processInitCommands; If (ARMA_DEBUG_lvl>0) Then { [1,format ["mando_CM_DefenseSystems.sqf->Unit = %1 Server = %2",_unit,(local server)],"server"] call six_fTxRadio; Sleep 0.5; }; //_check = _unit getVariable "mando_CM_Left"; //_STR_check = STR _check; // // Initialize Counter Measures Variables //if (isNil ("_check")) Then { // _unit setVariable ["mando_CM_Left", _NumOfCM]; // Initialize Counter Measures Remaining // mando_vehvar_vehiclew = _unit; // mando_vehvar_w = "mando_CM_Left"; // mando_vehvar_valuew = _NumOfCM; // mando_vehvar_requestw = true; // {publicVariable _x} forEach ["mando_vehvar_vehiclew", "mando_vehvar_w", "mando_vehvar_valuew", "mando_vehvar_requestw"]; // sleep 0.5; // }; _distlaunch = 0; mando_vehvar_vehicler = _unit; mando_vehvar_r = "mando_missileincomming"; mando_vehvar_requestr = true; {publicVariable _x} forEach ["mando_vehvar_vehicler", "mando_vehvar_r", "mando_vehvar_requestr"]; sleep 0.5; mando_vehvar_vehicler = _unit; mando_vehvar_r = "mando_MaxCM"; mando_vehvar_requestr = true; {publicVariable _x} forEach ["mando_vehvar_vehicler", "mando_vehvar_r", "mando_vehvar_requestr"]; sleep 0.5; mando_vehvar_vehicler = _unit; mando_vehvar_r = "mando_CM_Left"; mando_vehvar_requestr = true; {publicVariable _x} forEach ["mando_vehvar_vehicler", "mando_vehvar_r", "mando_vehvar_requestr"]; sleep 0.5; //mando_vehvar_vehicler = _unit; //mando_vehvar_r = "mando_missileincomming"; //mando_vehvar_requestr = true; //{publicVariable _x} forEach ["mando_vehvar_vehicler", "mando_vehvar_r", "mando_vehvar_requestr"]; //sleep 0.5; _missile_warning = false; _misecm = _unit getVariable "mando_missileincomming"; _oldmisecm = objNull; if (isNil ("_misecm")) then {_misecm = objNull;}; _NumOfCM = _unit getVariable "mando_MaxCM"; _misecm = objNull; if(ARMA_DEBUG_lvl>0)then{driver _unit groupChat Format["*Initializing Counter Measures Stores: %1",_unit getVariable "mando_CM_Left"];}; if(ARMA_DEBUG_lvl>1)then{hint format["Mando_CM_DefenseSystems.sqf: Local Variable NumOfCM: %1 Unit: %2 _misecm: %3",_NumOfCM, _unit,_misecm];}; driver _unit groupChat Format["*Current Counter Measures Stores: %1",_unit getVariable "mando_CM_Left"]; _log = "Logic" createVehicleLocal [0,0,0]; mando_planechafftime = dayTime * 3600; //Assigned Keyboard Key for Manual Deployment if (vehicle player == _unit) then { (findDisplay 46) displaySetEventHandler ["KeyDown", "_res = _this execVM""ArmAI_Scripts\CORE\mando_units\mando_chopper_keys.sqf"""]; }; //Debug code - ViperMaul // Driver _unit globalChat "Server Found - mando_CM_DefenseSystems.sqf"; //debug cutText["\n\n-= Missle Defense System Operational =-", "PLAIN DOWN"]; if(ARMA_DEBUG_lvl>1)then{Driver _unit groupChat format["Missle Defense System Operational for %1",_unit];}; //debug //Debug code while {(damage _unit < 0.9) && (_NumOfCM > 0) && (vehicle player)== _unit} do { _vdir = vectorDir _unit; _posu = getPosASL _unit; if (mando_missilerequest) then { if (mando_missiletarget == _unit) then { // Debug if(ARMA_DEBUG_lvl>1)then{ mando_message = format["%1, Counter-Measures REQUESTED BY %2", name player, mando_missiletarget]; publicVariable "mando_message"; }; //Debug END _misecm = mando_missileincomming; mando_missilerequest = false; }; }; if (!isNull _misecm) then { if (!_missile_warning) then { _missile_warning = true; cutText["\n\n****MISSILE INCOMMING !!", "PLAIN DOWN"]; //vehicle player say "mando_noammo1"; playsound "mando_noammo1"; }; _post = getPosASL _misecm; _dir = (_vdir select 0) atan2 (_vdir select 1); _ang = ((_post select 0)-(_posu select 0)) atan2 ((_post select 1)-(_posu select 1)); _log setDir (_ang - _dir); _difh = getDir _log; if (_difh > 180) then {_difh = _difh - 360;}; _altuasl = _posu select 2; _alttasl = _post select 2; _distance = _unit distance _misecm; _angu = asin(_vdir select 2); _angv = asin((_alttasl - _altuasl)/_distance); _difv = _angv - _angu; if ((abs(_difh) < 90) && (abs(_difv) < 90)) then { _rad = (100 min _distance); _pz = (_posu select 2)+sin(_angu + _difv)*_rad; _radh = cos(_angu + _difv)*_rad; _px = (_posu select 0)+sin(_dir + _difh)*_radh; _py = (_posu select 1)+cos(_dir + _difh)*_radh; _posASL = [_px,_py,_pz]; _log setPosASL _posASL; drop ["\ca\data\koulesvetlo","","Billboard",100,0.11,[0,0,0],[0,0,0],0,1.27,1.0,0.05,[2],[[1,0,0,1]],[0],0,0,"","",_log]; }; }; if (((isNull _misecm) || (_oldmisecm != _misecm)) && _missile_warning) then { _missile_warning = false; }; _oldmisecm = _misecm; Sleep(0.1); }; deleteVehicle _log; (findDisplay 46) displaySetEventHandler ["KeyDown", ""]; //Debug code - ViperMaul cutText["\n\nMissle Defense System **OFFLINE**", "PLAIN DOWN"]; if(ARMA_DEBUG_lvl>0)then{Driver _unit groupChat format["Missle Defense System **OFFLINE** for %1",_unit];}; //debug //Debug code Exit; /* ______________________________________________________ if (local _unit) then { _distlaunch = 0; _misecm = objNul; while {(damage _unit < 0.8)&&(_NumOfCM > 0)} do { if (mando_missilerequest) then { if (mando_missiletarget == _unit) then { // mando_message = format["%1, CHAFF REQUESTED BY %2", name player, mando_missiletarget]; // publicVariable "mando_message"; _misecm = mando_missileincomming; mando_missilerequest = false; }; }; if (!isNull _misecm) then { if (_radio) then {driver _unit sideChat "Missile incomming!";}; waitUntil {(isNull _misecm) || ((_misecm distance _unit)<_mindistecm)}; if (!isNull _misecm) then { _NumOfCM = _NumOfCM - 1; [_unit, _typeecm]exec"mando_missiles\mando_chaffflares.sqs"; _distlaunch = _unit distance _misecm; if (_radio && (_typeecm == 0)) then {driver _unit sideChat "CHAFF! CHAFF! CHAFF!";}; if (_radio && (_typeecm == 1)) then {driver _unit sideChat "FLARES! FLARES! FLARES!";}; if (_radio && (_NumOfCM == 0) && (_typeecm == 0)) then {driver _unit sideChat "We ran out of chaff!";}; if (_radio && (_NumOfCM == 0) && (_typeecm == 1)) then {driver _unit sideChat "We ran out of flares!";}; Sleep 4; if ((isNull _misecm) || ((_misecm distance _unit)>_distlaunch)) then { if (_radio && (!isNull _misecm)) then { driver _unit sideChat "Missile evaded!"; Sleep(1); }; _misecm = objNull; }; }; }; Sleep(0.5); }; } else { waitUntil {(damage _unit > 0.8)}; }; _unit removeEventHandler ["IncomingMissile", _eh]; */