2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-03-11 14:21:35 +00:00
|
|
|
/*
|
2023-08-17 10:02:17 +00:00
|
|
|
* Author: commy2, kymckay
|
2015-08-16 18:14:54 +00:00
|
|
|
* Checks if the vehicles class already has the actions initialized, otherwise add all available repair options. Calleed from init EH.
|
2015-03-11 14:21:35 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-16 18:14:54 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
2015-03-11 14:21:35 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-16 18:14:54 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [vehicle] call ace_repair_fnc_addRepairActions
|
|
|
|
*
|
|
|
|
* Public: No
|
2015-03-11 14:21:35 +00:00
|
|
|
*/
|
|
|
|
|
2023-07-29 04:53:05 +00:00
|
|
|
if !(EGVAR(common,settingsInitFinished)) exitWith {
|
|
|
|
EGVAR(common,runAtSettingsInitialized) pushBack [FUNC(addRepairActions), _this];
|
|
|
|
};
|
|
|
|
|
|
|
|
if !(hasInterface && {GVAR(enabled)}) exitWith {};
|
2015-11-10 02:11:48 +00:00
|
|
|
|
2015-08-09 06:54:44 +00:00
|
|
|
params ["_vehicle"];
|
2017-10-10 14:39:59 +00:00
|
|
|
private _type = typeOf _vehicle;
|
2018-04-19 17:31:00 +00:00
|
|
|
TRACE_2("addRepairActions", _vehicle,_type);
|
2015-03-11 14:21:35 +00:00
|
|
|
|
|
|
|
// do nothing if the class is already initialized
|
2018-04-19 17:31:00 +00:00
|
|
|
private _initializedClasses = GETMVAR(GVAR(initializedClasses),[]);
|
2015-03-11 14:21:35 +00:00
|
|
|
if (_type in _initializedClasses) exitWith {};
|
|
|
|
|
2023-07-06 03:52:04 +00:00
|
|
|
// get hitPoints to ignore
|
|
|
|
private _hitPointsToIgnore = [_vehicle] call FUNC(getHitPointsToIgnore);
|
|
|
|
|
2015-08-23 23:51:34 +00:00
|
|
|
// get all hitpoints and selections
|
2018-04-12 14:15:57 +00:00
|
|
|
(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitSelections", []]]; // Since 1.82 these are all lower case
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2015-08-23 23:51:34 +00:00
|
|
|
// get hitpoints of wheels with their selections
|
2015-10-28 22:29:11 +00:00
|
|
|
([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"];
|
2015-03-11 14:21:35 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _hitPointsAddedNames = [];
|
|
|
|
private _hitPointsAddedStrings = [];
|
|
|
|
private _hitPointsAddedAmount = [];
|
2019-03-11 02:41:06 +00:00
|
|
|
private _processedSelections = [];
|
2018-05-31 23:11:16 +00:00
|
|
|
private _icon = ["a3\ui_f\data\igui\cfg\actions\repair_ca.paa", "#FFFFFF"];
|
2018-04-19 17:31:00 +00:00
|
|
|
|
2021-10-13 03:20:36 +00:00
|
|
|
private _vehCfg = configOf _vehicle;
|
2018-04-19 17:31:00 +00:00
|
|
|
// Custom position can be defined via config for associated hitpoint
|
2019-12-28 16:26:57 +00:00
|
|
|
private _hitpointPositions = getArray (_vehCfg >> QGVAR(hitpointPositions));
|
|
|
|
// Get turret paths
|
|
|
|
private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehicle, "commander", true])) apply {_x # 3};
|
2018-04-19 17:31:00 +00:00
|
|
|
|
2015-03-11 14:21:35 +00:00
|
|
|
{
|
2017-10-10 14:39:59 +00:00
|
|
|
private _selection = _x;
|
2018-04-12 14:15:57 +00:00
|
|
|
private _hitpoint = toLower (_hitPoints select _forEachIndex);
|
2015-10-28 22:29:11 +00:00
|
|
|
if (_selection in _wheelHitSelections) then {
|
2015-11-10 02:11:48 +00:00
|
|
|
// Wheels should always be unique
|
2019-03-11 02:41:06 +00:00
|
|
|
if (_selection in _processedSelections) exitWith {TRACE_3("Duplicate Wheel",_hitpoint,_forEachIndex,_selection);};
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2023-08-28 12:52:21 +00:00
|
|
|
private _position = compile format ["_target selectionPosition ['%1', 'HitPoints', 'AveragePoint'];", _selection];
|
2015-11-10 02:11:48 +00:00
|
|
|
|
|
|
|
TRACE_3("Adding Wheel Actions",_hitpoint,_forEachIndex,_selection);
|
|
|
|
|
2015-10-28 22:29:11 +00:00
|
|
|
// An action to replace the wheel is required
|
2015-11-10 02:11:48 +00:00
|
|
|
_name = format ["Replace_%1_%2", _forEachIndex, _hitpoint];
|
2015-08-09 06:54:44 +00:00
|
|
|
_text = localize LSTRING(ReplaceWheel);
|
2015-08-09 13:53:52 +00:00
|
|
|
_condition = {[_this select 1, _this select 0, _this select 2 select 0, "ReplaceWheel"] call DFUNC(canRepair)};
|
|
|
|
_statement = {[_this select 1, _this select 0, _this select 2 select 0, "ReplaceWheel"] call DFUNC(repair)};
|
2015-11-10 02:11:48 +00:00
|
|
|
_action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction);
|
2015-03-27 02:44:04 +00:00
|
|
|
[_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass);
|
2023-06-28 10:39:08 +00:00
|
|
|
|
|
|
|
// Create a wheel interaction
|
|
|
|
private _root = format ["Wheel_%1_%2", _forEachIndex, _hitpoint];
|
|
|
|
private _action = [_root, localize LSTRING(Wheel), ["","#FFFFFF"], {}, {true}, {}, [_hitpoint], _position, 2, nil, LINKFUNC(modifySelectionInteraction)] call EFUNC(interact_menu,createAction);
|
|
|
|
[_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
|
|
|
|
// An action to remove the wheel is required
|
|
|
|
private _name = format ["Remove_%1_%2", _forEachIndex, _hitpoint];
|
|
|
|
private _text = localize LSTRING(RemoveWheel);
|
|
|
|
private _condition = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(canRepair)};
|
|
|
|
private _statement = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(repair)};
|
|
|
|
private _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction);
|
|
|
|
[_type, 0, [_root], _action] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
|
|
|
|
// An action to patch the wheel is required.
|
|
|
|
private _name = format ["Patch_%1_%2", _forEachIndex, _hitpoint];
|
|
|
|
private _patchIcon = QPATHTOF(ui\patch_ca.paa);
|
|
|
|
private _text = localize LSTRING(PatchWheel);
|
|
|
|
private _condition = {("vehicle" in GVAR(patchWheelLocation)) && {[_this select 1, _this select 0, _this select 2 select 0, "PatchWheel"] call DFUNC(canRepair)}};
|
|
|
|
private _statement = {[_this select 1, _this select 0, _this select 2 select 0, "PatchWheel"] call DFUNC(repair)};
|
|
|
|
private _action = [_name, _text, _patchIcon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction);
|
|
|
|
[_type, 0, [_root], _action] call EFUNC(interact_menu,addActionToClass);
|
2019-03-11 02:41:06 +00:00
|
|
|
|
|
|
|
_processedSelections pushBack _selection;
|
2015-03-11 14:21:35 +00:00
|
|
|
} else {
|
2023-07-06 03:52:04 +00:00
|
|
|
// Skip ignored hitpoints
|
|
|
|
if (_hitpoint in _hitPointsToIgnore) exitWith {
|
|
|
|
TRACE_3("Skipping ignored hitpoint",_hitpoint,_forEachIndex,_selection);
|
|
|
|
};
|
2018-04-19 17:31:00 +00:00
|
|
|
|
2019-12-28 16:26:57 +00:00
|
|
|
// Some hitpoints do not have a selection but do have an armorComponent value (seems to mainly be RHS)
|
|
|
|
// Ref https://community.bistudio.com/wiki/Arma_3_Damage_Enhancement
|
|
|
|
// this code won't support identically named hitpoints (e.g. commander turret: Duplicate HitPoint name 'HitTurret')
|
|
|
|
private _armorComponent = "";
|
|
|
|
if (_selection == "") then {
|
2023-07-06 03:52:04 +00:00
|
|
|
private _hitpointsCfg = "configName _x == _hitpoint" configClasses (_vehCfg >> "HitPoints");
|
|
|
|
if (_hitpointsCfg isNotEqualTo []) then {
|
|
|
|
_armorComponent = getText (_hitpointsCfg # 0 >> "armorComponent");
|
|
|
|
};
|
|
|
|
if (_armorComponent == "") then {
|
|
|
|
{
|
|
|
|
private _turretHitpointCfg = ([_vehCfg, _x] call CBA_fnc_getTurret) >> "HitPoints";
|
|
|
|
private _hitpointsCfg = "configName _x == _hitpoint" configClasses _turretHitpointCfg;
|
|
|
|
if (_hitpointsCfg isNotEqualTo []) exitWith {
|
|
|
|
TRACE_2("turret hitpoint configFound",_hitpoint,_x);
|
2019-12-28 16:26:57 +00:00
|
|
|
_armorComponent = getText (_hitpointsCfg # 0 >> "armorComponent");
|
|
|
|
};
|
2023-07-06 03:52:04 +00:00
|
|
|
} forEach _turretPaths;
|
2021-10-13 03:20:36 +00:00
|
|
|
};
|
2019-12-28 16:26:57 +00:00
|
|
|
if (_armorComponent != "") then { INFO_3("%1: %2 no selection: using armorComponent %3",_type,_hitpoint,_armorComponent); };
|
|
|
|
};
|
2015-10-28 22:29:11 +00:00
|
|
|
|
|
|
|
// Find the action position
|
2017-10-10 14:39:59 +00:00
|
|
|
private _position = compile format ["_target selectionPosition ['%1', 'HitPoints'];", _selection];
|
2018-04-19 17:31:00 +00:00
|
|
|
{
|
|
|
|
_x params ["_hit", "_pos"];
|
|
|
|
if (_hitpoint == _hit) exitWith {
|
|
|
|
if (_pos isEqualType []) exitWith {
|
|
|
|
_position = _pos; // Position in model space
|
2015-08-24 01:23:37 +00:00
|
|
|
};
|
2018-04-19 17:31:00 +00:00
|
|
|
if (_pos isEqualType "") exitWith {
|
|
|
|
_position = compile format ["_target selectionPosition ['%1', 'HitPoints'];", _pos];
|
|
|
|
};
|
|
|
|
ERROR_3("Invalid custom position %1 of hitpoint %2 in vehicle %3.",_position,_hitpoint,_type);
|
|
|
|
};
|
|
|
|
} forEach _hitpointPositions;
|
2015-08-24 16:17:56 +00:00
|
|
|
|
2019-12-28 16:26:57 +00:00
|
|
|
// if no selection then use the FireLOD to position the action
|
|
|
|
if ((_selection == "") && {_position isEqualTo {_target selectionPosition ['', 'HitPoints'];}}) then {
|
|
|
|
if ((_vehicle selectionPosition [_armorComponent, "FireGeometry"]) isEqualTo [0,0,0]) then {
|
|
|
|
WARNING_3("[%1: %2: %3] armorComponent does not exist?",_type,_hitpoint,_armorComponent);
|
|
|
|
_position = [0,0,0]; // just stick it on mainActions
|
|
|
|
} else {
|
|
|
|
_position = compile format ["_target selectionPosition ['%1', 'FireGeometry'];", _armorComponent];
|
|
|
|
};
|
|
|
|
TRACE_1("using armorComponent position",_position);
|
|
|
|
};
|
|
|
|
|
2018-04-19 17:31:00 +00:00
|
|
|
// Prepare the repair action
|
2017-10-10 14:39:59 +00:00
|
|
|
private _name = format ["Repair_%1_%2", _forEachIndex, _selection];
|
2015-08-24 01:23:37 +00:00
|
|
|
|
2015-10-28 22:29:11 +00:00
|
|
|
// Find localized string and track those added for numerization
|
|
|
|
([_hitpoint, "%1", _hitpoint, [_hitPointsAddedNames, _hitPointsAddedStrings, _hitPointsAddedAmount]] call FUNC(getHitPointString)) params ["_text", "_trackArray"];
|
|
|
|
_hitPointsAddedNames = _trackArray select 0;
|
|
|
|
_hitPointsAddedStrings = _trackArray select 1;
|
|
|
|
_hitPointsAddedAmount = _trackArray select 2;
|
|
|
|
|
|
|
|
if (_hitpoint in TRACK_HITPOINTS) then {
|
|
|
|
// Tracks should always be unique
|
2019-03-11 02:41:06 +00:00
|
|
|
if (_selection in _processedSelections) exitWith {TRACE_3("Duplicate Track",_hitpoint,_forEachIndex,_selection);};
|
2018-07-27 17:24:56 +00:00
|
|
|
_position = compile format ["private _return = _target selectionPosition ['%1', 'HitPoints']; _return set [1, 0]; _return", _selection];
|
2015-11-10 02:11:48 +00:00
|
|
|
TRACE_4("Adding RepairTrack",_hitpoint,_forEachIndex,_selection,_text);
|
2017-10-10 14:39:59 +00:00
|
|
|
private _condition = {[_this select 1, _this select 0, _this select 2 select 0, "RepairTrack"] call DFUNC(canRepair)};
|
|
|
|
private _statement = {[_this select 1, _this select 0, _this select 2 select 0, "RepairTrack"] call DFUNC(repair)};
|
|
|
|
private _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 4] call EFUNC(interact_menu,createAction);
|
2015-08-11 19:35:13 +00:00
|
|
|
[_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
} else {
|
2015-11-10 02:11:48 +00:00
|
|
|
TRACE_4("Adding MiscRepair",_hitpoint,_forEachIndex,_selection,_text);
|
2017-10-10 14:39:59 +00:00
|
|
|
private _condition = {[_this select 1, _this select 0, _this select 2 select 0, "MiscRepair"] call DFUNC(canRepair)};
|
|
|
|
private _statement = {[_this select 1, _this select 0, _this select 2 select 0, "MiscRepair"] call DFUNC(repair)};
|
|
|
|
private _action = [_name, _text, _icon, _statement, _condition, {}, [_forEachIndex], _position, 5] call EFUNC(interact_menu,createAction);
|
2015-08-24 15:58:19 +00:00
|
|
|
// Put inside main actions if no other position was found above
|
2015-10-28 22:29:11 +00:00
|
|
|
if (_position isEqualTo [0,0,0]) then {
|
2015-08-24 15:58:19 +00:00
|
|
|
[_type, 0, ["ACE_MainActions", QGVAR(Repair)], _action] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
} else {
|
|
|
|
[_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
};
|
2015-08-11 19:35:13 +00:00
|
|
|
};
|
2015-10-28 22:29:11 +00:00
|
|
|
|
2019-03-11 02:41:06 +00:00
|
|
|
_processedSelections pushBack _selection;
|
2015-03-11 14:21:35 +00:00
|
|
|
};
|
2015-10-28 22:29:11 +00:00
|
|
|
} forEach _hitSelections;
|
2015-03-11 14:21:35 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _condition = {[_this select 1, _this select 0, "", "fullRepair"] call DFUNC(canRepair)};
|
|
|
|
private _statement = {[_this select 1, _this select 0, "", "fullRepair"] call DFUNC(repair)};
|
|
|
|
private _action = [QGVAR(fullRepair), localize LSTRING(fullRepair), _icon, _statement, _condition, {}, [], "", 4] call EFUNC(interact_menu,createAction);
|
2015-08-14 18:49:51 +00:00
|
|
|
[_type, 0, ["ACE_MainActions", QGVAR(Repair)], _action] call EFUNC(interact_menu,addActionToClass);
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2015-03-11 14:21:35 +00:00
|
|
|
// set class as initialized
|
|
|
|
_initializedClasses pushBack _type;
|
|
|
|
|
|
|
|
SETMVAR(GVAR(initializedClasses),_initializedClasses);
|