ACE3/addons/mk6mortar/functions/fnc_handlePlayerVehicleChanged.sqf
Brandon Danyluk b1d5bbe450 Adds Crew Served Static Weapons (#5652)
* Initial Commit

* Got rid of unneeded translation values

* Updated Strings

* "Fixed" issue where when you deploy the tripid and weapon on slope it freaked out.

* Fixed locality issues. Added timers to relavent functions.

* Added weights to all magazines/tripod. Weights to weapons coming soon when I transfer them to the launcher slot

* Fixed bug regarding localized strings. Created new tripod model

* Added timers for deploying/picking up the tripod. Changed ammo-box model from custom to one already in ARMA. Changed gun-bag model for a more generic one. Created a texture for the tripod and gunbag

* Removed ability to disassemble weapons via the addAction. Added  ACE Action to get in due to a memory point issue. Changed from a static deploy/dismount time to one based in the weapon configs

* Created forward-compatability. Made it so I can define a base plate for any weapon if I ever want to expand from the generic M3 Tripod.

* Fixed bug where tripod wouldn't deploy with the correct times. Fixed bug where if you moved the tripod into the ground it would go flying.

* Added mortar compatability. Will probably shift whole mortar ammo loading to CSW one day

* Added icons to each relavent item

* Added README, possibly fixed bug where if you are in a weapon others cant load/unload ammo. Changed distance you can interact with weapons

* Added checks for when deploying the gun as well as unloading ammo to prevent duplication/deletion of items.

* Added documentation

* Added order to doc

* Explained why things are the way they are

* Remove temp files

* Removed redundant files

* Converted tabs->spaces. Added newlines at end of all files. Changed broken line in fnc_tripodDeploy.sqf.

* 100% newlines at end of file

* Added newlines to files that didnt get the change. Fixed README. Changed from GVAR(cswOptions) to GVAR(options). Changed from tabs to spaces in wiki

* Fixed issue with UAV assembling with enableWeaponDisassembling. Fixed bug where game would crash if you disassembled static weapon with more than 1 magazine

* Tabs->Spaces

* Added CSW options to base StaticWeapon class to allow for easier additions. Switched default mortar away from CSW system due to incompatabilities

* Lazy Evaluations and macros to describe how things work.

* Added newlines to script_component. Fix no-texture issue on tripod. "Fix" 20mm HE saying 40mm HE. Add custom icons to all weapons. Move "Check Ammo" to CSW menu

* abc

* Revert "abc"

This reverts commit bcb4214bd9.

* Update to current commit

* Revert changes to fortify.md

* Updated UI Icon to Crew Served Ammo branch UI

* Added Pabst's CrewServedAmmo to handle ammo loading/unloading instead of my solution

* Fixed bug where currentWeaponTurret returned a blank string when a player hasent entered hte weapon to select the current weapon

* Re-added ammo loading time

* Tabs->Spaces

* Newline at end of files

* Removed replaced functions

* Remove redundant strings. Move ammo handling to appropiate section

* Tabs->Spaces

* Update wiki

* Updated to fix crash with default weapons and disable CSW ability on default static weapons

* Added editor attributes to enable/disable CSW at edit time

* Change how ammo is removed from the CSW. Uses math instead of iteration

* Fix bug where assembled weapon did not get rid of default actions

* Added support for multiple types of ammo in one CSW

* Add tracer magazines for .50 cal

* Fix bug where you could load ammo even if the gun couldnt take any more

* Disable debug and enable compile cache

* Changed weapon deploy/pickup time. Removed custom Titan missiles. Using ACE Dragging now. Added progress bar check for pickupTripod. Updated documentation

* Removed check if CSW is full to unload ammo

* Fix bug where items would spawn underneath other items on wepaon dismount

* Change some things

* Configure base statics, improve returnAmmo

* Add mortar baseplate

* Remove explicit inheritance

* Fix bug where unloading ammo would duplicate it if you had room in your person.

* Tab->Space

* Player couldnt pickup tripod due to legacy code

* Fix GMG_01_base_F inheritce

* Port of ACE 2 tripod + ACE 2 CSW Bag

* Move ACE 2 Data to APL folder

* Adjust weights to make them more accurate to how ARMA uses it and the real life equivalents

* Fix bug where error was thrown on esc from picking up tripod. Tripod rotated 180

* Fix bug where if you called ace_common_claim the weapon could be set to be disassembled even though it may not be wanted via CSW

* Added ability to toggle ammo handling when weaponAssembly is disabled.

* Add Proxy Weapons for all Vanilla static weapons. These serve as a way to allow for realistic ammo reload times without having to modify base classes if you want feautres turned off. Adjusted reload and mount times to be more "realistic"

* Fix Shadow RPT Spam

* Update wiki

* Change order of setDir and setPos

* Change all setDir/setPos orientations. Remove redundant check. Ensure that weapon locked state reflects it with the "getIn" command. Add a way to pass in a specific classname for the weapon assemble type. Add a callback function onDisassemble if user wants to set the state of the new tripod using the old weapon as a reference

* Actually check for the carryWeaponClassname in the deployWeapon check

* Ai Compatiblity

* Add stringtable entries

* Formatting fixes

* Stringtables for settings, fix setMagazineTurretAmmo

* inherit ammo for mags, reorder stringtable

displays correct ammo and descriptionShort

* don't require ace_javelin

* Tweaks, cleanup, localzation, ace_reload changes

change weapon tag to [CSW]
tweak localization strings
minor cleanup
simplify some ace_reload funcs

* delete moved dev func

* Hopefully fix issue where to-be deleted tripod intersects with newly created weapon and vice versa. Remove PBOPREFIX newline

* cleanup/proxyWeapon/mk6 compat
2019-06-07 23:47:39 -05:00

137 lines
6.1 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: PabstMirror
* Handles player getting into new vehicle. Loads PFEG for mortar display if it is a mortar.
*
* Arguments:
* 0: Player <OBJECT>
* 1: New Vehicle <OBJECT>
*
* Return Value:
* None
*
* Example:
* [bob, mortar] call ace_mk6mortar_fnc_handlePlayerVehicleChanged;
*
* Public: No
*/
params ["_player", "_newVehicle"];
if (isNull _newVehicle) exitWith {};
if (!(_newVehicle isKindOf "Mortar_01_base_F")) exitWith {};
private _tubeWeaponName = (weapons _newVehicle) select 0;
private _fireModes = getArray (configFile >> "CfgWeapons" >> _tubeWeaponName >> "modes");
//Restore last firemode:
private _lastFireMode = _newVehicle getVariable [QGVAR(lastFireMode), -1];
if (_lastFireMode != -1) then {
_player action ["SwitchWeapon", _newVehicle, _player, _lastFireMode];
};
[{
params ["_args", "_pfID"];
_args params ["_mortarVeh", "_fireModes"];
if ((vehicle ACE_player) != _mortarVeh) then {
[_pfID] call CBA_fnc_removePerFrameHandler;
} else {
private _useMils = _mortarVeh getVariable [QGVAR(useMils), true];
//Compute: 'charge' from weaponstate
private _currentFireMode = (weaponState [_mortarVeh, [0]]) select 2;
private _currentChargeMode = _fireModes find _currentFireMode;
//Save firemode on vehicle:
_mortarVeh setVariable [QGVAR(lastFireMode), _currentChargeMode];
if (shownArtilleryComputer && {!GVAR(allowComputerRangefinder)}) then {
//Don't like this solution, but it works
closeDialog 0;
[parseText "Computer Disabled"] call EFUNC(common,displayTextStructured);
};
private _display = uiNamespace getVariable ["ACE_Mk6_RscWeaponRangeArtillery", displayNull];
if (isNull _display) exitWith {}; //It may be null for the first frame
private _chargeText = format ["<t size='0.8'>%1: %2 <img image='%3'/></t>", (localize LSTRING(rangetable_charge)), _currentChargeMode, QPATHTOF(UI\ui_charges.paa)];
//Hud should hidden in 3rd person
private _notGunnerView = cameraView != "GUNNER";
//Calc real azimuth/elevation
//(looking at the sky VS looking at ground will radicaly change fire direction because BIS)
private _realAzimuth = -1;
private _realElevation = -1;
private _useRealWeaponDir = (ctrlText (_display displayCtrl 173)) == "--";
if (_useRealWeaponDir && {(_mortarVeh ammo (currentWeapon _mortarVeh)) == 0}) then {
// With no ammo, distance display will be empty, but gun will still fire at wonky angle if aimed at ground
private _testSeekerPosASL = AGLtoASL (positionCameraToWorld [0,0,0]);
private _testSeekerDir = _testSeekerPosASL vectorFromTo (AGLtoASL (positionCameraToWorld [0,0,1]));
private _testPoint = _testSeekerPosASL vectorAdd (_testSeekerDir vectorMultiply viewDistance);
if ((terrainIntersectASL [_testSeekerPosASL, _testPoint]) || {lineIntersects [_testSeekerPosASL, _testPoint]}) then {
_useRealWeaponDir = false; // If we are not looking at infinity (based on viewDistance)
};
};
if (_useRealWeaponDir) then {
//No range (looking at sky), it will follow weaponDir:
private _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
private _lookVector = ((positionCameraToWorld [0,0,0]) call EFUNC(common,positionToASL)) vectorFromTo ((positionCameraToWorld [0,0,10]) call EFUNC(common,positionToASL));
_realAzimuth = ((_lookVector select 0) atan2 (_lookVector select 1));
private _upVectorDir = (((vectorUp _mortarVeh) select 0) atan2 ((vectorUp _mortarVeh) select 1));
private _elevationDiff = (cos (_realAzimuth - _upVectorDir)) * acos ((vectorUp _mortarVeh) select 2);
_realElevation = ((180 / PI) * (_mortarVeh animationPhase "mainGun")) + 75 - _elevationDiff;
};
//Update Heading Display:
if (_notGunnerView || (!GVAR(allowCompass))) then {
(_display displayCtrl 80156) ctrlSetText "";
} else {
if (_useMils) then {
(_display displayCtrl 80156) ctrlSetText str (((round (_realAzimuth * 6400 / 360)) + 6400) % 6400);
} else {
(_display displayCtrl 80156) ctrlSetText str ((round (_realAzimuth + 360)) % 360);
};
};
//Update CurrentElevation Display and "charge" text
if (_notGunnerView) then {
(_display displayCtrl 80085) ctrlSetStructuredText parseText "";
(_display displayCtrl 80175) ctrlSetText "";
} else {
(_display displayCtrl 80085) ctrlSetStructuredText parseText _chargeText;
if (_useMils) then {
(_display displayCtrl 80175) ctrlSetText str ((round (_realElevation * 6400 / 360)) % 6400);
} else {
(_display displayCtrl 80175) ctrlSetText str (((round (_realElevation * 100)) / 100) % 360);
};
};
//Update ElevationNeeded Display:
if (_notGunnerView || (!GVAR(allowComputerRangefinder))) then {
(_display displayCtrl 80176) ctrlSetText "";
} else {
private _elevDeg = parseNumber ctrlText (_display displayCtrl 176);
if (_elevDeg <= 0) then { //Bad data means "----" out of range
(_display displayCtrl 80176) ctrlSetText (ctrlText (_display displayCtrl 176));
} else {
_elevDeg = _elevDeg + (_realElevation - (parseNumber ctrlText (_display displayCtrl 175)));
if (_useMils) then {
(_display displayCtrl 80176) ctrlSetText str round ((round (_elevDeg * 6400 / 360)) % 6400);
} else {
(_display displayCtrl 80176) ctrlSetText str (((round (_elevDeg * 100)) / 100) % 360);
};
};
};
};
}, 0, [_newVehicle, _fireModes]] call CBA_fnc_addPerFrameHandler;