2015-03-11 14:21:35 +00:00
|
|
|
/*
|
2015-10-28 22:29:11 +00:00
|
|
|
* Author: commy2, SilentSpike
|
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
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
if (!hasInterface) exitWith {};
|
|
|
|
|
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 {};
|
|
|
|
|
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 = [];
|
|
|
|
private _processedHitpoints = [];
|
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
|
|
|
|
|
|
|
// Custom position can be defined via config for associated hitpoint
|
|
|
|
private _hitpointPositions = getArray (configFile >> "CfgVehicles" >> _type >> QGVAR(hitpointPositions));
|
|
|
|
// Associated hitpoints can be grouped via config to produce a single repair action
|
|
|
|
private _hitpointGroups = getArray(configFile >> "CfgVehicles" >> _type >> QGVAR(hitpointGroups));
|
|
|
|
|
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
|
2015-10-28 22:29:11 +00:00
|
|
|
if (_hitpoint in _processedHitpoints) exitWith {TRACE_3("Duplicate Wheel",_hitpoint,_forEachIndex,_selection);};
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _position = compile format ["_target selectionPosition ['%1', 'HitPoints'];", _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 remove the wheel is required
|
2017-10-10 14:39:59 +00:00
|
|
|
private _name = format ["Remove_%1_%2", _forEachIndex, _hitpoint];
|
2017-05-14 19:48:05 +00:00
|
|
|
private _text = localize LSTRING(RemoveWheel);
|
2017-10-10 14:39:59 +00:00
|
|
|
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, nil, FUNC(modifySelectionInteraction)] call EFUNC(interact_menu,createAction);
|
2015-03-27 02:44:04 +00:00
|
|
|
[_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
|
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);
|
2015-03-11 14:21:35 +00:00
|
|
|
} else {
|
2015-10-28 22:29:11 +00:00
|
|
|
// Empty selections don't exist
|
2018-04-19 17:31:00 +00:00
|
|
|
if (_selection isEqualTo "") exitWith { TRACE_3("Skipping Empty Sel",_hitpoint,_forEachIndex,_selection); };
|
2015-10-28 22:29:11 +00:00
|
|
|
// Empty hitpoints don't contain enough information
|
2018-04-19 17:31:00 +00:00
|
|
|
if (_hitpoint isEqualTo "") exitWith { TRACE_3("Skipping Empty Hit",_hitpoint,_forEachIndex,_selection); };
|
|
|
|
// Ignore glass hitpoints
|
|
|
|
if ((_hitPoint find "glass") != -1) exitWith { TRACE_3("Skipping Glass",_hitpoint,_forEachIndex,_selection); };
|
|
|
|
// Ignore hitpoints starting with # (seems to be lights)
|
|
|
|
if ((_hitpoint select [0,1]) == "#") exitWith { TRACE_3("Skipping # hit",_hitpoint,_forEachIndex,_selection); };
|
|
|
|
// Ignore ERA/Slat armor (vanilla uses hitera_/hitslat_, pre-1.82 RHS uses era_)
|
|
|
|
// ToDo: see how community utilizes new armor system, could also check getText (_hitpointConfig >> "simulation")
|
|
|
|
if (((_hitpoint select [0,7]) == "hitera_") || {(_hitpoint select [0,8]) == "hitslat_"} || {(_hitpoint select [0,4]) == "era_"}) exitWith { TRACE_3("Skipping ERA/SLAT",_hitpoint,_forEachIndex,_selection); };
|
|
|
|
|
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
//Depends hitpoints shouldn't be modified directly (will be normalized)
|
2017-06-23 03:58:00 +00:00
|
|
|
// Biki: Clearing 'depends' in case of inheritance cannot be an empty string (rpt warnings), but rather a "0" value.
|
|
|
|
if (!((getText (configFile >> "CfgVehicles" >> _type >> "HitPoints" >> _hitpoint >> "depends")) in ["", "0"])) exitWith {
|
2015-11-10 02:11:48 +00:00
|
|
|
TRACE_3("Skip Depends",_hitpoint,_forEachIndex,_selection);
|
|
|
|
};
|
2015-10-28 22:29:11 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _childHitPoint = false;
|
2018-04-19 17:31:00 +00:00
|
|
|
{
|
2015-08-24 18:03:11 +00:00
|
|
|
{
|
2018-04-19 17:31:00 +00:00
|
|
|
if (_hitpoint == _x) exitWith {
|
|
|
|
_childHitPoint = true;
|
|
|
|
};
|
|
|
|
} forEach (_x select 1);
|
|
|
|
} forEach _hitpointGroups;
|
2015-10-28 22:29:11 +00:00
|
|
|
// If the current selection is associated with a child hitpoint, then skip
|
|
|
|
if (_childHitPoint) exitWith { TRACE_3("childHitpoint",_hitpoint,_forEachIndex,_selection); };
|
|
|
|
|
|
|
|
// 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
|
|
|
|
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
|
|
|
|
if (_hitpoint in _processedHitpoints) 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
|
|
|
|
2018-04-19 17:31:00 +00:00
|
|
|
_processedHitPoints pushBack _hitpoint;
|
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);
|