2015-04-05 06:57:24 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror
|
2015-04-05 22:50:07 +00:00
|
|
|
* Handles player getting into new vehicle. Loads PFEG for mortar display if it is a mortar.
|
2015-04-05 06:57:24 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-04-05 22:50:07 +00:00
|
|
|
* 0:Player <OBJECT>
|
|
|
|
* 1: New Vehicle <OBJECT>
|
2015-04-05 06:57:24 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-04-05 22:50:07 +00:00
|
|
|
* No
|
2015-04-05 06:57:24 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2015-04-06 06:05:28 +00:00
|
|
|
* [bob, mortar] call ace_mk6mortar_fnc_handlePlayerVehicleChanged;
|
2015-04-05 06:57:24 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
PARAMS_2(_player,_newVehicle);
|
|
|
|
|
2015-07-26 21:45:29 +00:00
|
|
|
private["_tubeWeaponName" ,"_fireModes", "_lastFireMode"];
|
2015-07-08 06:00:43 +00:00
|
|
|
|
2015-04-05 06:57:24 +00:00
|
|
|
if (isNull _newVehicle) exitWith {};
|
|
|
|
if (!(_newVehicle isKindOf "Mortar_01_base_F")) exitWith {};
|
|
|
|
|
2015-04-05 19:34:39 +00:00
|
|
|
_tubeWeaponName = (weapons _newVehicle) select 0;
|
|
|
|
_fireModes = getArray (configFile >> "CfgWeapons" >> _tubeWeaponName >> "modes");
|
|
|
|
|
2015-07-14 00:09:55 +00:00
|
|
|
//Restore last firemode:
|
|
|
|
_lastFireMode = _newVehicle getVariable [QGVAR(lastFireMode), -1];
|
|
|
|
if (_lastFireMode != -1) then {
|
|
|
|
_player action ["SwitchWeapon", _newVehicle, _player, _lastFireMode];
|
|
|
|
};
|
|
|
|
|
2015-04-05 06:57:24 +00:00
|
|
|
[{
|
2015-07-08 06:00:43 +00:00
|
|
|
private["_chargeText", "_currentChargeMode", "_currentFireMode", "_display", "_elevDeg", "_elevationDiff", "_lookVector", "_notGunnerView", "_realAzimuth", "_realElevation", "_upVectorDir", "_useMils", "_weaponDir"];
|
2015-04-05 06:57:24 +00:00
|
|
|
PARAMS_2(_args,_pfID);
|
2015-06-14 05:52:30 +00:00
|
|
|
EXPLODE_2_PVT(_args,_mortarVeh,_fireModes);
|
2015-04-05 06:57:24 +00:00
|
|
|
|
2015-04-05 19:34:39 +00:00
|
|
|
if ((vehicle ACE_player) != _mortarVeh) then {
|
2015-04-05 06:57:24 +00:00
|
|
|
[_pfID] call CBA_fnc_removePerFrameHandler;
|
|
|
|
} else {
|
2015-04-05 19:34:39 +00:00
|
|
|
|
2015-04-05 20:00:59 +00:00
|
|
|
_useMils = _mortarVeh getVariable [QGVAR(useMils), true];
|
2015-04-05 22:50:07 +00:00
|
|
|
|
2015-04-05 19:34:39 +00:00
|
|
|
//Compute: 'charge' from weaponstate
|
|
|
|
_currentFireMode = (weaponState [_mortarVeh, [0]]) select 2;
|
|
|
|
_currentChargeMode = _fireModes find _currentFireMode;
|
|
|
|
|
2015-07-14 00:09:55 +00:00
|
|
|
//Save firemode on vehicle:
|
|
|
|
_mortarVeh setVariable [QGVAR(lastFireMode), _currentChargeMode];
|
|
|
|
|
2015-04-05 19:34:39 +00:00
|
|
|
if (shownArtilleryComputer && {!GVAR(allowComputerRangefinder)}) then {
|
2015-04-05 17:40:48 +00:00
|
|
|
//Don't like this solution, but it works
|
2015-04-05 07:27:13 +00:00
|
|
|
closeDialog 0;
|
|
|
|
[parseText "Computer Disabled"] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
2015-04-05 19:34:39 +00:00
|
|
|
|
2015-04-05 06:57:24 +00:00
|
|
|
_display = uiNamespace getVariable ["ACE_Mk6_RscWeaponRangeArtillery", displayNull];
|
2015-04-06 06:05:28 +00:00
|
|
|
if (isNull _display) exitWith {}; //It may be null for the first frame
|
|
|
|
|
2015-06-14 05:52:30 +00:00
|
|
|
_chargeText = format ["<t size='0.8'>%1: %2 <img image='%3'/></t>", (localize LSTRING(rangetable_charge)), _currentChargeMode, QUOTE(PATHTOF(UI\ui_charges.paa))];
|
|
|
|
|
2015-04-06 06:05:28 +00:00
|
|
|
//Hud should hidden in 3rd person
|
|
|
|
_notGunnerView = cameraView != "GUNNER";
|
2015-04-05 06:57:24 +00:00
|
|
|
|
2015-07-08 06:00:43 +00:00
|
|
|
//Calc real azimuth/elevation
|
|
|
|
//(looking at the sky VS looking at ground will radicaly change fire direction because BIS)
|
|
|
|
_realAzimuth = -1;
|
|
|
|
_realElevation = -1;
|
|
|
|
if ((ctrlText (_display displayCtrl 173)) == "--") then {
|
|
|
|
//No range (looking at sky), it will follow weaponDir:
|
|
|
|
_weaponDir = _mortarVeh weaponDirection (currentWeapon _mortarVeh);
|
|
|
|
_realAzimuth = (_weaponDir select 0) atan2 (_weaponDir select 1);
|
|
|
|
_realElevation = asin (_weaponDir select 2);
|
|
|
|
} else {
|
|
|
|
//Valid range, will fire at camera dir
|
2015-07-26 21:45:29 +00:00
|
|
|
_lookVector = ((positionCameraToWorld [0,0,0]) call EFUNC(common,positionToASL)) vectorFromTo ((positionCameraToWorld [0,0,10]) call EFUNC(common,positionToASL));
|
2015-07-08 06:00:43 +00:00
|
|
|
_realAzimuth = ((_lookVector select 0) atan2 (_lookVector select 1));
|
2015-07-12 19:09:27 +00:00
|
|
|
_upVectorDir = (((vectorUp _mortarVeh) select 0) atan2 ((vectorUp _mortarVeh) select 1));
|
|
|
|
_elevationDiff = (cos (_realAzimuth - _upVectorDir)) * acos ((vectorUp _mortarVeh) select 2);
|
|
|
|
_realElevation = ((180 / PI) * (_mortarVeh animationPhase "mainGun")) + 75 - _elevationDiff;
|
2015-07-08 06:00:43 +00:00
|
|
|
};
|
2015-06-14 05:52:30 +00:00
|
|
|
|
|
|
|
//Update Heading Display:
|
|
|
|
if (_notGunnerView || (!GVAR(allowCompass))) then {
|
|
|
|
(_display displayCtrl 80156) ctrlSetText "";
|
|
|
|
} else {
|
|
|
|
if (_useMils) then {
|
2015-07-08 06:00:43 +00:00
|
|
|
(_display displayCtrl 80156) ctrlSetText str (((round (_realAzimuth * 6400 / 360)) + 6400) % 6400);
|
2015-06-14 05:52:30 +00:00
|
|
|
} else {
|
2015-07-08 06:00:43 +00:00
|
|
|
(_display displayCtrl 80156) ctrlSetText str ((round (_realAzimuth + 360)) % 360);
|
2015-06-14 05:52:30 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
//Update CurrentElevation Display and "charge" text
|
2015-04-06 06:05:28 +00:00
|
|
|
if (_notGunnerView) then {
|
2015-06-14 05:52:30 +00:00
|
|
|
(_display displayCtrl 80085) ctrlSetStructuredText parseText "";
|
2015-04-06 06:05:28 +00:00
|
|
|
(_display displayCtrl 80175) ctrlSetText "";
|
2015-04-05 06:57:24 +00:00
|
|
|
} else {
|
2015-06-14 05:52:30 +00:00
|
|
|
(_display displayCtrl 80085) ctrlSetStructuredText parseText _chargeText;
|
|
|
|
|
2015-04-06 06:05:28 +00:00
|
|
|
if (_useMils) then {
|
2015-07-08 06:00:43 +00:00
|
|
|
(_display displayCtrl 80175) ctrlSetText str ((round (_realElevation * 6400 / 360)) % 6400);
|
2015-04-06 06:05:28 +00:00
|
|
|
} else {
|
2015-07-08 06:00:43 +00:00
|
|
|
(_display displayCtrl 80175) ctrlSetText str (((round (_realElevation * 100)) / 100) % 360);
|
2015-04-06 06:05:28 +00:00
|
|
|
};
|
2015-04-05 06:57:24 +00:00
|
|
|
};
|
|
|
|
|
2015-04-05 19:34:39 +00:00
|
|
|
//Update ElevationNeeded Display:
|
2015-04-06 06:05:28 +00:00
|
|
|
if (_notGunnerView || (!GVAR(allowComputerRangefinder))) then {
|
2015-04-05 06:57:24 +00:00
|
|
|
(_display displayCtrl 80176) ctrlSetText "";
|
|
|
|
} else {
|
|
|
|
_elevDeg = parseNumber ctrlText (_display displayCtrl 176);
|
2015-04-06 06:05:28 +00:00
|
|
|
if (_elevDeg <= 0) then { //Bad data means "----" out of range
|
2015-04-05 06:57:24 +00:00
|
|
|
(_display displayCtrl 80176) ctrlSetText (ctrlText (_display displayCtrl 176));
|
|
|
|
} else {
|
2015-07-08 06:00:43 +00:00
|
|
|
_elevDeg = _elevDeg + (_realElevation - (parseNumber ctrlText (_display displayCtrl 175)));
|
2015-04-05 20:00:59 +00:00
|
|
|
if (_useMils) then {
|
2015-06-14 05:52:30 +00:00
|
|
|
(_display displayCtrl 80176) ctrlSetText str round ((round (_elevDeg * 6400 / 360)) % 6400);
|
2015-04-05 06:57:24 +00:00
|
|
|
} else {
|
2015-06-14 05:52:30 +00:00
|
|
|
(_display displayCtrl 80176) ctrlSetText str (((round (_elevDeg * 100)) / 100) % 360);
|
2015-04-05 06:57:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2015-06-14 05:52:30 +00:00
|
|
|
}, 0, [_newVehicle, _fireModes]] call CBA_fnc_addPerFrameHandler;
|