Merge pull request #2245 from jonpas/repairHitpointSelections

Custom Hitpoint Repair Positions Framework
This commit is contained in:
Glowbal 2015-08-26 08:33:01 +02:00
commit d97dfce2d3
2 changed files with 43 additions and 10 deletions

View File

@ -334,4 +334,9 @@ class CfgVehicles {
GVAR(canRepair) = 1;
transportRepair = 0;
};
class Quadbike_01_base_F;
class B_Quadbike_01_F: Quadbike_01_base_F {
GVAR(hitpointPositions[]) = { {"HitEngine", {0, 0.5, -0.7}}, {"HitFuel", {0, 0, -0.5}} };
};
};

View File

@ -27,17 +27,13 @@ _initializedClasses = GETMVAR(GVAR(initializedClasses),[]);
// do nothing if the class is already initialized
if (_type in _initializedClasses) exitWith {};
// get all hitpoints
private "_hitPoints";
_hitPoints = [_vehicle] call EFUNC(common,getHitPointsWithSelections) select 0;
// get all hitpoints and selections
([_vehicle] call EFUNC(common,getHitPointsWithSelections)) params ["_hitPoints", "_hitPointsSelections"];
// get hitpoints of wheels with their selections
private ["_wheelHitPointsWithSelections", "_wheelHitPoints", "_wheelHitPointSelections"];
([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitPointSelections"];
_wheelHitPointsWithSelections = [_vehicle] call FUNC(getWheelHitPointsWithSelections);
_wheelHitPoints = _wheelHitPointsWithSelections select 0;
_wheelHitPointSelections = _wheelHitPointsWithSelections select 1;
// add repair events to this vehicle class
{
@ -83,7 +79,7 @@ _wheelHitPointSelections = _wheelHitPointsWithSelections select 1;
// add misc repair action
private ["_name", "_text", "_icon", "_selection", "_condition", "_statement"];
private ["_name", "_text", "_icon", "_selection", "_customSelectionsConfig", "_currentHitpoint", "_condition", "_statement"];
_name = format ["Repair_%1", _x];
@ -96,7 +92,34 @@ _wheelHitPointSelections = _wheelHitPointsWithSelections select 1;
};
_icon = "A3\ui_f\data\igui\cfg\actions\repair_ca.paa";
_selection = "";
// Get custom position if available
_customSelectionsConfig = configFile >> "CfgVehicles" >> _type >> QGVAR(hitpointPositions);
if (isArray _customSelectionsConfig) then {
// Loop through custom hitpoint positions array
_currentHitpoint = _x;
{
_x params ["_hitpoint", "_position"];
// Exit with supplied custom position when same hitpoint name found or print RPT error if it's invalid
if (_hitpoint == _currentHitpoint) exitWith {
if (typeName _position == "ARRAY") exitWith {
_selection = _position; // Position in model space
};
if (typeName _position == "STRING") exitWith {
_selection = _vehicle selectionPosition _position; // Selection name
};
diag_log text format ["[ACE] ERROR: Invalid custom position %1 of hitpoint %2 in vehicle %3", _position, _hitpoint, _vehicle];
};
} forEach (getArray _customSelectionsConfig);
};
// If position still empty (not a position array or selection name) try extracting from model
if (typeName _selection == "STRING" && {_selection == ""}) then {
_selection = _vehicle selectionPosition (_hitPointsSelections select (_hitPoints find _x));
};
_condition = {[_this select 1, _this select 0, _this select 2 select 0, _this select 2 select 1] call DFUNC(canRepair)};
_statement = {[_this select 1, _this select 0, _this select 2 select 0, _this select 2 select 1] call DFUNC(repair)};
@ -112,7 +135,12 @@ _wheelHitPointSelections = _wheelHitPointsWithSelections select 1;
} else {
private "_action";
_action = [_name, _text, _icon, _statement, _condition, {}, [_x, "MiscRepair"], _selection, 4] call EFUNC(interact_menu,createAction);
[_type, 0, ["ACE_MainActions", QGVAR(Repair)], _action] call EFUNC(interact_menu,addActionToClass);
// Put inside main actions if no other position was found above
if (_selection isEqualTo [0, 0, 0]) then {
[_type, 0, ["ACE_MainActions", QGVAR(Repair)], _action] call EFUNC(interact_menu,addActionToClass);
} else {
[_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass);
};
};
};
} forEach _hitPoints;