Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doSelectWarhead for ammunition that needs manual lazing and add "topDown" mode selection #435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions addons/main/functions/VehicleAction/fnc_doSelectWarhead.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ if (_muzzle isEqualTo "") then {
{
private _ammo = getText (configFile >> "CfgMagazines" >> _x >> "ammo");
if (_ammo isEqualTo "") then {continue};
if ((toUpperANSI (getText (configFile >> "CfgAmmo" >> _ammo >> "warheadName"))) in _warheadTypes) then {
if ((toUpperANSI (getText (configFile >> "CfgAmmo" >> _ammo >> "warheadName"))) in _warheadTypes && {
// do skip munition that needs a manual lase
!isClass (configFile >> "CfgAmmo" >> _ammo >> "Components" >> "SensorsManagerComponent" >> "Components" >> "LaserSensorComponent")
}) then {
_foundMag = _x;
break;
};
Expand All @@ -94,14 +97,36 @@ if (_muzzle == "this") then {

if (_turret isEqualTo "" || {_muzzle isEqualTo ""}) exitWith {false};

private _weaponState = weaponState [_vehicle, _turretPath, _muzzle];
// load mag type if exists and is not currently loaded
if (_foundMag isNotEqualTo "" && {_foundMag isNotEqualTo ((weaponState [_vehicle, _turretPath, _muzzle]) select 3)}) then {
if (_foundMag isNotEqualTo "" && {_foundMag isNotEqualTo (_weaponState select 3)}) then {
_vehicle loadMagazine [_turretPath, _turret, _foundMag];
if (GVAR(debug_functions)) then {
["%1 loading magazine %2 into turret %3", typeOf _vehicle, _foundMag, _turret] call FUNC(debugLog);
};
};

// switch to muzzle if currently not active
if (_switchMuzzle && {(currentMuzzle _gunner) isNotEqualTo _muzzle}) then {
_gunner selectWeapon _muzzle;
if (_switchMuzzle) then {
private _modes = getArray (configFile >> "CfgWeapons" >> _turret >> "modes");
private _topDownIndex = _modes findIf {(toUpperANSI _x) isEqualTo "TOPDOWN"};

// if muzzle is the same as that it wants to switch to, and if there is a topdown fire mode and it is already selected, skip
if !((currentMuzzle _gunner) isNotEqualTo _muzzle || {
_topDownIndex > -1 && {(_modes select _topDownIndex) isNotEqualTo (_weaponState select 2)}}) exitWith {};
if (_topDownIndex > -1) then {
// if weapon has a topdown mode, use it
// works sadly unreliable, the AI likes to switch firemode right before firing
_gunner selectWeapon [_turret, _muzzle, _modes select _topDownIndex];
if (GVAR(debug_functions)) then {
["%1 switching to muzzle %2 with mode %4 in %3", _gunner, _muzzle, typeOf _vehicle, _modes select _topDownIndex] call FUNC(debugLog);
};
} else {
_gunner selectWeapon _muzzle;
if (GVAR(debug_functions)) then {
["%1 switching to muzzle %2 in %3", _gunner, _muzzle, typeOf _vehicle] call FUNC(debugLog);
};
}
};

true
Loading