2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2016-02-06 19:09:48 +00:00
|
|
|
/*
|
|
|
|
* Author: esteldunedain
|
|
|
|
* Unfied handling of weapon fire
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2016-02-06 19:09:48 +00:00
|
|
|
* 0: unit - Object the event handler is assigned to <OBJECT>
|
|
|
|
* 1: weapon - Fired weapon <STRING>
|
|
|
|
* 2: muzzle - Muzzle that was used <STRING>
|
|
|
|
* 3: mode - Current mode of the fired weapon <STRING>
|
|
|
|
* 4: ammo - Ammo used <STRING>
|
|
|
|
* 5: magazine - magazine name which was used <STRING>
|
|
|
|
* 6: projectile - Object of the projectile that was shot <OBJECT>
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2016-02-06 19:09:48 +00:00
|
|
|
* None
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [bob, "gun", "muzzle", "single", "ammo", "magazine", "bullet"] call ace_common_fnc_firedEH
|
|
|
|
*
|
2016-02-06 19:09:48 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
BEGIN_COUNTER(firedEH);
|
|
|
|
|
2016-02-06 19:22:23 +00:00
|
|
|
params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile"];
|
|
|
|
TRACE_7("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectile);
|
2016-02-06 19:09:48 +00:00
|
|
|
|
2016-02-06 19:22:23 +00:00
|
|
|
if (_unit isKindOf "CAManBase") then {
|
2016-02-06 19:09:48 +00:00
|
|
|
// The unit it on foot
|
2016-02-06 19:22:23 +00:00
|
|
|
if (_unit == ACE_player) then {
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_firedPlayer", _this] call CBA_fnc_localEvent;
|
2016-02-06 19:09:48 +00:00
|
|
|
} else {
|
2016-02-06 19:22:23 +00:00
|
|
|
if ([_unit] call EFUNC(common,isPlayer)) then {
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_firedPlayerNonLocal", _this] call CBA_fnc_localEvent;
|
2016-02-06 19:09:48 +00:00
|
|
|
} else {
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_firedNonPlayer", _this] call CBA_fnc_localEvent;
|
2016-02-06 19:09:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// The unit is a vehicle
|
2016-02-06 19:55:36 +00:00
|
|
|
private _vehicle = _unit;
|
2016-02-06 19:49:53 +00:00
|
|
|
|
|
|
|
// Get the gunner and turret path.
|
|
|
|
// Code based on FUNC(getGunner), extracted for efficency.
|
|
|
|
private _gunner = objNull;
|
|
|
|
private _turret = [];
|
|
|
|
{
|
|
|
|
if (_weapon in (_unit weaponsTurret _x)) exitWith {
|
|
|
|
_gunner = _unit turretUnit _x;
|
|
|
|
_turret = _x;
|
|
|
|
};
|
|
|
|
false
|
|
|
|
} count allTurrets [_unit, true];
|
|
|
|
// Ensure that at least the pilot is returned if there is no gunner
|
|
|
|
if (isManualFire _unit && {isNull _gunner}) then {
|
2016-02-13 18:04:43 +00:00
|
|
|
_gunner = effectiveCommander _unit;
|
2016-02-06 19:49:53 +00:00
|
|
|
};
|
|
|
|
|
2016-02-06 19:26:57 +00:00
|
|
|
if (_gunner == ACE_player) then {
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_firedPlayerVehicle", _this] call CBA_fnc_localEvent;
|
2016-02-06 19:09:48 +00:00
|
|
|
} else {
|
2016-02-06 19:26:57 +00:00
|
|
|
if ([_gunner] call EFUNC(common,isPlayer)) then {
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_firedPlayerVehicleNonLocal", _this] call CBA_fnc_localEvent;
|
2016-02-06 19:09:48 +00:00
|
|
|
} else {
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_firedNonPlayerVehicle", _this] call CBA_fnc_localEvent;
|
2016-02-06 19:09:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
END_COUNTER(firedEH);
|