2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2019-06-08 04:47:39 +00:00
|
|
|
/*
|
2023-08-16 23:18:01 +00:00
|
|
|
* Author: tcvm
|
2024-07-27 17:42:31 +00:00
|
|
|
* Initializes CSW systems on vehicle.
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2024-02-07 23:36:13 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2024-02-07 23:36:13 +00:00
|
|
|
* cursorObject call ace_csw_fnc_initVehicle
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2024-02-07 23:36:13 +00:00
|
|
|
params ["_vehicle"];
|
|
|
|
if (!alive _vehicle) exitWith { WARNING_1("%1 not alive",_vehicle); };
|
|
|
|
if (!simulationEnabled _vehicle) exitWith {
|
|
|
|
[{simulationEnabled _this}, FUNC(initVehicle), _vehicle] call CBA_fnc_waitUntilAndExecute;
|
2024-02-07 23:25:49 +00:00
|
|
|
};
|
2024-02-07 23:36:13 +00:00
|
|
|
|
|
|
|
private _typeOf = typeOf _vehicle;
|
|
|
|
private _configOf = configOf _vehicle;
|
|
|
|
private _configEnabled = (getNumber (_configOf >> QUOTE(ADDON) >> "enabled")) == 1;
|
|
|
|
private _assemblyConfig = _configEnabled && {(getText (_configOf >> QUOTE(ADDON) >> "disassembleWeapon")) != ""};
|
|
|
|
TRACE_4("initVehicle",_vehicle,_typeOf,_configEnabled,_assemblyConfig);
|
2019-06-08 04:47:39 +00:00
|
|
|
|
|
|
|
if (_configEnabled && {GVAR(ammoHandling) == 2}) then {
|
2024-02-07 23:36:13 +00:00
|
|
|
TRACE_1("adding AI fired handler",_vehicle);
|
|
|
|
_vehicle addEventHandler ["Fired", LINKFUNC(ai_handleFired)];
|
|
|
|
_vehicle addEventHandler ["GetIn", LINKFUNC(ai_handleGetIn)]; // handle AI getting inside weapon with no ammo
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
|
|
|
|
2024-02-07 23:36:13 +00:00
|
|
|
TRACE_2("",local _vehicle,_vehicle turretLocal [0]);
|
|
|
|
if (_configEnabled && {_vehicle turretLocal [0]}) then { // if turret is local to us, then handle mags/weapon
|
2019-06-08 04:47:39 +00:00
|
|
|
[{
|
2024-02-07 23:36:13 +00:00
|
|
|
params ["_vehicle"];
|
|
|
|
if (!alive _vehicle) exitWith { TRACE_1("dead/deleted",_vehicle); };
|
2019-07-05 22:57:22 +00:00
|
|
|
// Assembly mode: [0=disabled, 1=enabled, 2=enabled&unload, 3=default]
|
2024-02-07 23:36:13 +00:00
|
|
|
private _assemblyModeIndex = _vehicle getVariable [QGVAR(assemblyMode), 3];
|
2019-07-05 22:57:22 +00:00
|
|
|
private _emptyWeapon = _assemblyModeIndex isEqualTo 2;
|
|
|
|
private _assemblyMode = [false, true, true, GVAR(defaultAssemblyMode)] select _assemblyModeIndex;
|
2024-02-07 23:36:13 +00:00
|
|
|
TRACE_2("turretLocal",_vehicle,_assemblyMode);
|
|
|
|
[_vehicle, [0], _assemblyMode, _emptyWeapon] call FUNC(proxyWeapon);
|
|
|
|
[_vehicle, _assemblyMode, _emptyWeapon] call FUNC(staticWeaponInit_unloadExtraMags);
|
|
|
|
}, [_vehicle]] call CBA_fnc_execNextFrame; // need to wait a frame to allow setting object vars during assembly
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (_assemblyConfig) then {
|
|
|
|
[{
|
2024-02-07 23:36:13 +00:00
|
|
|
params ["_vehicle"];
|
|
|
|
if (!alive _vehicle) exitWith { TRACE_1("dead/deleted",_vehicle); };
|
|
|
|
private _assemblyMode = [false, true, true, GVAR(defaultAssemblyMode)] select (_vehicle getVariable [QGVAR(assemblyMode), 3]);
|
|
|
|
TRACE_2("assemblyConfig present",_vehicle,_assemblyMode);
|
2023-11-23 00:16:42 +00:00
|
|
|
if (_assemblyMode) then { // Disable vanilla assembly if assemblyMode enabled
|
2024-02-07 23:36:13 +00:00
|
|
|
[_vehicle, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
2024-02-07 23:36:13 +00:00
|
|
|
}, [_vehicle]] call CBA_fnc_execNextFrame; // need to wait a frame to allow setting object vars during assembly
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add interactions for players
|
|
|
|
if (hasInterface && {!(_typeOf in GVAR(initializedStaticTypes))}) then {
|
|
|
|
GVAR(initializedStaticTypes) pushBack _typeOf;
|
|
|
|
TRACE_1("Adding Actions",_typeOf);
|
|
|
|
|
|
|
|
if (_assemblyConfig) then {
|
2024-04-02 15:22:45 +00:00
|
|
|
private _disassembleAction = [QGVAR(disassemble), LLSTRING(DisassembleCSW_displayName), "", LINKFUNC(assemble_pickupWeapon), LINKFUNC(assemble_canPickupWeapon)] call EFUNC(interact_menu,createAction);
|
2019-06-08 04:47:39 +00:00
|
|
|
[_typeOf, 0, ["ACE_MainActions"], _disassembleAction] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private _ammoActionPath = [];
|
2022-03-07 18:29:19 +00:00
|
|
|
private _magazineLocation = getText (_configOf >> QUOTE(ADDON) >> "magazineLocation");
|
2019-06-08 04:47:39 +00:00
|
|
|
private _condition = { //IGNORE_PRIVATE_WARNING ["_target", "_player"];
|
|
|
|
// If magazine handling is enabled or weapon assembly/disassembly is enabled we enable ammo handling
|
2019-07-05 22:57:22 +00:00
|
|
|
if ((GVAR(ammoHandling) == 0) && {!([false, true, true, GVAR(defaultAssemblyMode)] select (_target getVariable [QGVAR(assemblyMode), 3]))}) exitWith { false };
|
2019-06-08 04:47:39 +00:00
|
|
|
[_player, _target, ["isNotSwimming", "isNotSitting"]] call EFUNC(common,canInteractWith)
|
|
|
|
};
|
2024-07-27 17:42:31 +00:00
|
|
|
private _childrenCode = {
|
2019-06-08 04:47:39 +00:00
|
|
|
BEGIN_COUNTER(getActions); // can remove for final release
|
2024-02-07 23:36:13 +00:00
|
|
|
private _ret = (call FUNC(getLoadActions)) + (call FUNC(getUnloadActions));
|
2019-06-08 04:47:39 +00:00
|
|
|
END_COUNTER(getActions);
|
|
|
|
_ret
|
|
|
|
};
|
|
|
|
if (_configEnabled && {_magazineLocation != ""}) then {
|
|
|
|
private _positionCode = compile _magazineLocation;
|
2024-07-27 17:42:31 +00:00
|
|
|
private _ammoAction = [QGVAR(magazine), LLSTRING(AmmoHandling_displayName), "", {}, _condition, _childrenCode, [], _positionCode, 4] call EFUNC(interact_menu,createAction);
|
2019-06-08 04:47:39 +00:00
|
|
|
_ammoActionPath = [_typeOf, 0, [], _ammoAction] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
} else {
|
2024-07-27 17:42:31 +00:00
|
|
|
private _ammoAction = [QGVAR(magazine), LLSTRING(AmmoHandling_displayName), "", {}, _condition, _childrenCode] call EFUNC(interact_menu,createAction);
|
2019-06-08 04:47:39 +00:00
|
|
|
_ammoActionPath = [_typeOf, 0, ["ACE_MainActions"], _ammoAction] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
};
|
|
|
|
|
2024-01-01 01:45:01 +00:00
|
|
|
if (["ace_reload"] call EFUNC(common,isModLoaded)) then {
|
2019-06-08 04:47:39 +00:00
|
|
|
// move reload's check ammo action to the ammo handling point (remove and re-add)
|
|
|
|
[_typeOf, 0, ["ACE_MainActions", QEGVAR(reload,CheckAmmo)]] call EFUNC(interact_menu,removeActionFromClass);
|
2024-04-02 15:22:45 +00:00
|
|
|
private _checkAmmoAction = [QGVAR(checkAmmo), LELSTRING(reload,checkAmmo), "", EFUNC(reload,checkAmmo), EFUNC(reload,canCheckAmmo)] call EFUNC(interact_menu,createAction);
|
2019-06-08 04:47:39 +00:00
|
|
|
[_typeOf, 0, _ammoActionPath, _checkAmmoAction] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
};
|
|
|
|
};
|