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
|
|
|
*/
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2015-03-11 14:21:35 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-09 06:54:44 +00:00
|
|
|
params ["_vehicle"];
|
|
|
|
TRACE_1("params", _vehicle);
|
2015-03-11 14:21:35 +00:00
|
|
|
|
2015-10-28 22:29:11 +00:00
|
|
|
private ["_type", "_initializedClasses", "_condition", "_statement", "_action", "_processedHitPoints", "_hitPointsAddedNames", "_hitPointsAddedStrings", "_hitPointsAddedAmount"];
|
2015-03-11 14:21:35 +00:00
|
|
|
|
|
|
|
_type = typeOf _vehicle;
|
|
|
|
|
|
|
|
_initializedClasses = GETMVAR(GVAR(initializedClasses),[]);
|
|
|
|
|
|
|
|
// do nothing if the class is already initialized
|
|
|
|
if (_type in _initializedClasses) exitWith {};
|
|
|
|
|
2015-08-23 23:51:34 +00:00
|
|
|
// get all hitpoints and selections
|
2015-10-28 22:29:11 +00:00
|
|
|
(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitSelections", []]];
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2015-10-28 22:29:11 +00:00
|
|
|
if (_hitSelections isEqualTo []) exitWith { ACE_LOGERROR_1("No hit selections (%1)", _type); };
|
2015-03-11 14:21: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
|
|
|
|
2015-08-23 23:04:57 +00:00
|
|
|
_hitPointsAddedNames = [];
|
|
|
|
_hitPointsAddedStrings = [];
|
|
|
|
_hitPointsAddedAmount = [];
|
2015-10-28 22:29:11 +00:00
|
|
|
_processedHitpoints = [];
|
2015-08-23 23:04:57 +00:00
|
|
|
|
2015-03-11 14:21:35 +00:00
|
|
|
{
|
2015-10-28 22:29:11 +00:00
|
|
|
_selection = _x;
|
|
|
|
_hitpoint = _hitPoints select _forEachIndex;
|
2015-03-11 14:21:35 +00:00
|
|
|
|
2015-10-28 22:29:11 +00:00
|
|
|
if (_selection in _wheelHitSelections) then {
|
|
|
|
// Wheels should always be unique
|
|
|
|
if (_hitpoint in _processedHitpoints) exitWith {TRACE_3("Duplicate Wheel",_hitpoint,_forEachIndex,_selection);};
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2015-08-09 15:23:32 +00:00
|
|
|
_icon = "A3\ui_f\data\igui\cfg\actions\repair_ca.paa";
|
2015-03-11 14:21:35 +00:00
|
|
|
|
2015-10-28 22:29:11 +00:00
|
|
|
// An action to remove the wheel is required
|
|
|
|
_name = format ["Remove_%1_%2", _forEachIndex, _hitpoint];
|
2015-08-23 23:25:00 +00:00
|
|
|
_text = localize LSTRING(RemoveWheel);
|
2015-10-28 22:29:11 +00:00
|
|
|
TRACE_4("Adding Wheel Actions",_name,_forEachIndex,_selection,_text);
|
2015-08-09 13:53:52 +00:00
|
|
|
_condition = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(canRepair)};
|
|
|
|
_statement = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(repair)};
|
2015-10-28 22:29:11 +00:00
|
|
|
_action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _selection, 2] 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
|
|
|
|
_name = format ["Replace_%1_%2", _forEachIndex, _selection];
|
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-10-28 22:29:11 +00:00
|
|
|
_action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _selection, 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
|
|
|
|
// Empty hitpoints don't contain enough information
|
|
|
|
if (_selection isEqualTo "") exitWith {};
|
|
|
|
if (_hitpoint isEqualTo "") exitWith {};
|
|
|
|
|
|
|
|
// Associated hitpoints can be grouped via config to produce a single repair action
|
|
|
|
_groupsConfig = configFile >> "CfgVehicles" >> _type >> QGVAR(hitpointGroups);
|
|
|
|
if (isArray _groupsConfig) then {
|
|
|
|
_childHitPoint = false;
|
2015-08-24 18:03:11 +00:00
|
|
|
{
|
|
|
|
{
|
2015-10-28 22:29:11 +00:00
|
|
|
if (_hitpoint == _x) exitWith {
|
|
|
|
_childHitPoint = true;
|
2015-08-24 18:03:11 +00:00
|
|
|
};
|
|
|
|
} forEach (_x select 1);
|
2015-10-28 22:29:11 +00:00
|
|
|
} forEach (getArray _groupsConfig);
|
2015-08-24 18:03:11 +00:00
|
|
|
};
|
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
|
|
|
|
_position = _vehicle selectionPosition [_selection,"HitPoints"];
|
|
|
|
// Custom position can be defined via config for associated hitpoint
|
|
|
|
_positionsConfig = configFile >> "CfgVehicles" >> _type >> QGVAR(hitpointPositions);
|
|
|
|
if (isArray _positionsConfig) then {
|
2015-08-24 16:17:56 +00:00
|
|
|
{
|
2015-10-28 22:29:11 +00:00
|
|
|
_x params ["_hit", "_pos"];
|
|
|
|
if (_hitpoint == _hit) exitWith {
|
|
|
|
if (typeName _pos == "ARRAY") exitWith {
|
|
|
|
_position = _pos; // Position in model space
|
2015-08-24 16:17:56 +00:00
|
|
|
};
|
2015-10-28 22:29:11 +00:00
|
|
|
if (typeName _pos == "STRING") exitWith {
|
|
|
|
_position = _vehicle selectionPosition [_pos,"HitPoints"]; // Selection name
|
2015-08-24 16:17:56 +00:00
|
|
|
};
|
2015-10-28 22:29:11 +00:00
|
|
|
ACE_LOGERROR_3("Invalid custom position %1 of hitpoint %2 in vehicle %3.",_position,_hitpoint,_type);
|
2015-08-24 01:23:37 +00:00
|
|
|
};
|
2015-10-28 22:29:11 +00:00
|
|
|
} forEach (getArray _positionsConfig);
|
2015-08-24 01:23:37 +00:00
|
|
|
};
|
2015-08-24 16:17:56 +00:00
|
|
|
|
2015-10-28 22:29:11 +00:00
|
|
|
// Prepair the repair action
|
|
|
|
_name = format ["Repair_%1_%2", _forEachIndex, _selection];
|
|
|
|
_icon = "A3\ui_f\data\igui\cfg\actions\repair_ca.paa";
|
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);};
|
|
|
|
if (_hitpoint == "HitLTrack") then {
|
|
|
|
_position = [-1.75, 0, -1.75];
|
2015-08-11 19:35:13 +00:00
|
|
|
} else {
|
2015-10-28 22:29:11 +00:00
|
|
|
_position = [1.75, 0, -1.75];
|
2015-08-11 19:35:13 +00:00
|
|
|
};
|
2015-10-28 22:29:11 +00:00
|
|
|
TRACE_5("Adding RepairTrack",_name,_forEachIndex,_selection,_text,_position);
|
2015-09-26 04:36:35 +00:00
|
|
|
_condition = {[_this select 1, _this select 0, _this select 2 select 0, "RepairTrack"] call DFUNC(canRepair)};
|
|
|
|
_statement = {[_this select 1, _this select 0, _this select 2 select 0, "RepairTrack"] call DFUNC(repair)};
|
2015-10-28 22:29:11 +00:00
|
|
|
_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-10-28 22:29:11 +00:00
|
|
|
TRACE_5("Adding MiscRepair",_name,_forEachIndex,_selection,_text,_position);
|
2015-09-26 04:36:35 +00:00
|
|
|
_condition = {[_this select 1, _this select 0, _this select 2 select 0, "MiscRepair"] call DFUNC(canRepair)};
|
|
|
|
_statement = {[_this select 1, _this select 0, _this select 2 select 0, "MiscRepair"] call DFUNC(repair)};
|
2015-10-28 22:29:11 +00:00
|
|
|
_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
|
|
|
|
|
|
|
_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
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
_condition = {[_this select 1, _this select 0, "", "fullRepair"] call DFUNC(canRepair)};
|
|
|
|
_statement = {[_this select 1, _this select 0, "", "fullRepair"] call DFUNC(repair)};
|
|
|
|
_action = [QGVAR(fullRepair), localize LSTRING(fullRepair), "A3\ui_f\data\igui\cfg\actions\repair_ca.paa", _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);
|