From 4e93b9c72de1a91dae7a0360bb64c11018db5b2e Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 25 Sep 2015 23:36:35 -0500 Subject: [PATCH 1/3] 2307 - Repair sub-turrets Privates Cleanup debug Add repair actions for sub turrets Cleanup Fix Header Error Handling Cleanup setHitpointDamage Fix common ACE_isEngineer to handle scalar or bool Claim and release repair objects (wheel/track) Repair sub-turrets --- .../fnc_getHitPointsWithSelections.sqf | 2 +- addons/common/functions/fnc_isEngineer.sqf | 9 +- addons/repair/ACE_Repair.hpp | 9 +- addons/repair/CfgVehicles.hpp | 3 + addons/repair/XEH_preInit.sqf | 1 + .../repair/functions/fnc_addRepairActions.sqf | 60 ++++++++---- addons/repair/functions/fnc_addSpareParts.sqf | 1 - addons/repair/functions/fnc_canMiscRepair.sqf | 31 ++++-- addons/repair/functions/fnc_canRepair.sqf | 70 ++++++++------ .../repair/functions/fnc_canRepairTrack.sqf | 26 +---- .../repair/functions/fnc_canReplaceTrack.sqf | 27 +----- .../repair/functions/fnc_canReplaceWheel.sqf | 30 +----- addons/repair/functions/fnc_doFullRepair.sqf | 11 +-- addons/repair/functions/fnc_doRepair.sqf | 63 ++++++------ addons/repair/functions/fnc_doRepairTrack.sqf | 38 ++++---- .../repair/functions/fnc_doReplaceTrack.sqf | 42 ++++---- .../repair/functions/fnc_doReplaceWheel.sqf | 38 ++++---- .../repair/functions/fnc_getClaimObjects.sqf | 44 +++++++++ .../fnc_getWheelHitPointsWithSelections.sqf | 96 +++++++++++-------- addons/repair/functions/fnc_isEngineer.sqf | 2 +- .../functions/fnc_moduleAddSpareParts.sqf | 2 +- .../functions/fnc_moduleAssignEngineer.sqf | 2 +- .../fnc_moduleAssignRepairFacility.sqf | 2 +- .../fnc_moduleAssignRepairVehicle.sqf | 2 +- .../functions/fnc_moduleRepairSettings.sqf | 4 +- addons/repair/functions/fnc_repair.sqf | 85 +++++++++------- .../repair/functions/fnc_repair_failure.sqf | 16 +++- .../repair/functions/fnc_repair_success.sqf | 17 +++- .../functions/fnc_setHitPointDamage.sqf | 81 ++++++++-------- addons/repair/functions/fnc_spawnObject.sqf | 2 +- addons/repair/functions/fnc_useItem.sqf | 5 +- addons/repair/functions/fnc_useItems.sqf | 2 +- 32 files changed, 457 insertions(+), 366 deletions(-) create mode 100644 addons/repair/functions/fnc_getClaimObjects.sqf diff --git a/addons/common/functions/fnc_getHitPointsWithSelections.sqf b/addons/common/functions/fnc_getHitPointsWithSelections.sqf index b0b9867cf7..aef415a54f 100644 --- a/addons/common/functions/fnc_getHitPointsWithSelections.sqf +++ b/addons/common/functions/fnc_getHitPointsWithSelections.sqf @@ -24,7 +24,7 @@ _hitPointsWithSelections = getAllHitPointsDamage _vehicle; // get correct format on vehicles without any hitpoints if (_hitPointsWithSelections isEqualTo []) then { - _hitPointsWithSelections = [[],[],[]]; + _hitPointsWithSelections = [[],[],[]]; }; _hitPointsWithSelections resize 2; diff --git a/addons/common/functions/fnc_isEngineer.sqf b/addons/common/functions/fnc_isEngineer.sqf index 9018149c27..738b77e6a3 100644 --- a/addons/common/functions/fnc_isEngineer.sqf +++ b/addons/common/functions/fnc_isEngineer.sqf @@ -8,10 +8,17 @@ * Return Value: * is the unit an engineer * + * Example: + * [player] call ace_common_fnc_isEngineer + * * Public: Yes */ #include "script_component.hpp" params ["_unit"]; -_unit getVariable ["ACE_isEngineer", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "engineer") == 1] // return +local _isEngineer = _unit getVariable ["ACE_isEngineer", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "engineer") == 1]; +//Handle ace_repair modules setting this to a number +if ((typeName _isEngineer) == "SCALAR") then {_isEngineer = _isEngineer > 0}; + +_isEngineer diff --git a/addons/repair/ACE_Repair.hpp b/addons/repair/ACE_Repair.hpp index a8aac18690..251302a93a 100644 --- a/addons/repair/ACE_Repair.hpp +++ b/addons/repair/ACE_Repair.hpp @@ -4,14 +4,15 @@ class ACE_Repair { displayName = CSTRING(ReplaceWheel); displayNameProgress = CSTRING(ReplacingWheel); - locations[] = {"All"}; + repairLocations[] = {"All"}; requiredEngineer = QGVAR(engineerSetting_Wheel); repairingTime = 10; repairingTimeSelfCoef = 1; items = QGVAR(wheelRepairRequiredItems); condition = QUOTE(call FUNC(canReplaceWheel)); itemConsumed = 0; - + claimObjects[] = {{"ACE_Wheel"}}; + callbackSuccess = QUOTE(call FUNC(doReplaceWheel)); callbackFailure = ""; callbackProgress = ""; @@ -27,6 +28,7 @@ class ACE_Repair { displayNameProgress = CSTRING(RemovingWheel); condition = QUOTE(call FUNC(canRemove)); callbackSuccess = QUOTE(call FUNC(doRemoveWheel)); + claimObjects[] = {}; }; class MiscRepair: ReplaceWheel { displayName = CSTRING(Repairing); // let's make empty string an auto generated string @@ -36,6 +38,7 @@ class ACE_Repair { repairingTime = 15; callbackSuccess = QUOTE(call FUNC(doRepair)); items[] = {"ToolKit"}; + claimObjects[] = {}; }; class RepairTrack: MiscRepair { displayName = CSTRING(Repairing); @@ -43,6 +46,7 @@ class ACE_Repair { condition = QUOTE(call FUNC(canRepairTrack)); callbackSuccess = QUOTE(call FUNC(doRepairTrack)); requiredEngineer = QGVAR(engineerSetting_Wheel); + claimObjects[] = {{"ACE_Track"}}; }; class RemoveTrack: MiscRepair { displayName = CSTRING(RemoveTrack); @@ -57,6 +61,7 @@ class ACE_Repair { condition = QUOTE(call FUNC(canReplaceTrack)); callbackSuccess = QUOTE(call FUNC(doReplaceTrack)); requiredEngineer = QGVAR(engineerSetting_Wheel); + claimObjects[] = {{"ACE_Track"}}; }; class FullRepair: MiscRepair { displayName = CSTRING(fullRepair); diff --git a/addons/repair/CfgVehicles.hpp b/addons/repair/CfgVehicles.hpp index 85abce4028..ea15256bf3 100644 --- a/addons/repair/CfgVehicles.hpp +++ b/addons/repair/CfgVehicles.hpp @@ -404,4 +404,7 @@ class CfgVehicles { class B_Quadbike_01_F: Quadbike_01_base_F { GVAR(hitpointPositions[]) = { {"HitEngine", {0, 0.5, -0.7}}, {"HitFuel", {0, 0, -0.5}} }; }; + class Hatchback_01_base_F: Car_F { + GVAR(hitpointPositions[]) = {{"HitBody", {0, 0.7, -0.5}}}; + }; }; diff --git a/addons/repair/XEH_preInit.sqf b/addons/repair/XEH_preInit.sqf index f94c230f29..8efa47e7b3 100644 --- a/addons/repair/XEH_preInit.sqf +++ b/addons/repair/XEH_preInit.sqf @@ -17,6 +17,7 @@ PREP(doRepair); PREP(doRepairTrack); PREP(doReplaceTrack); PREP(doReplaceWheel); +PREP(getClaimObjects); PREP(getHitPointString); PREP(getPostRepairDamage); PREP(getWheelHitPointsWithSelections); diff --git a/addons/repair/functions/fnc_addRepairActions.sqf b/addons/repair/functions/fnc_addRepairActions.sqf index 7ebf978088..23a359efdd 100644 --- a/addons/repair/functions/fnc_addRepairActions.sqf +++ b/addons/repair/functions/fnc_addRepairActions.sqf @@ -13,12 +13,13 @@ * * Public: No */ + #include "script_component.hpp" params ["_vehicle"]; TRACE_1("params", _vehicle); -private ["_type", "_initializedClasses", "_condition", "_statement", "_action"]; +private ["_type", "_initializedClasses", "_condition", "_statement", "_action", "_duplicateHitpointName", "_processedHitPoints", "_selectionName", "_hitPointsAddedNames", "_hitPointsAddedStrings", "_hitPointsAddedAmount"]; _type = typeOf _vehicle; @@ -28,33 +29,43 @@ _initializedClasses = GETMVAR(GVAR(initializedClasses),[]); if (_type in _initializedClasses) exitWith {}; // get all hitpoints and selections -([_vehicle] call EFUNC(common,getHitPointsWithSelections)) params ["_hitPoints", "_hitPointsSelections"]; +(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitPointsSelections", []]]; + +if (_hitPoints isEqualTo []) exitWith {ACE_LOGERROR_1("No Hitpoints on %1", _type);}; // get hitpoints of wheels with their selections ([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitPointSelections"]; - -private ["_hitPointsAddedNames", "_hitPointsAddedStrings", "_hitPointsAddedAmount"]; _hitPointsAddedNames = []; _hitPointsAddedStrings = []; _hitPointsAddedAmount = []; +_processedHitPoints = []; + // add repair events to this vehicle class { + _duplicateHitpointName = (_x in _processedHitPoints); + _processedHitPoints pushBack _x; + _selectionName = _hitPointsSelections select _forEachIndex; + if (_x in _wheelHitPoints) then { // add wheel repair action + if (_duplicateHitpointName) exitWith {TRACE_3("Duplicate Wheel",_x,_forEachIndex,_selectionName);}; //Wheels should always be unique + if (isNil {_vehicle getHit _selectionName}) exitWith {TRACE_3("No Selection",_x,_forEachIndex,_selectionName);}; //Not a real hitpoint + private ["_icon", "_selection", "_name", "_text"]; - _icon = QUOTE(PATHTOF(ui\tire_ca.paa)); + // _icon = QUOTE(PATHTOF(ui\tire_ca.paa)); _icon = "A3\ui_f\data\igui\cfg\actions\repair_ca.paa"; - // textDefault = ""; _selection = _wheelHitPointSelections select (_wheelHitPoints find _x); // remove wheel action - _name = format ["Remove_%1", _x]; + _name = format ["Remove_%1_%2", _forEachIndex, _x]; _text = localize LSTRING(RemoveWheel); + TRACE_5("Adding Wheel Actions",_name,_forEachIndex,_selectionName,_text,_selection); + _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)}; @@ -62,7 +73,7 @@ _hitPointsAddedAmount = []; [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); // replace wheel action - _name = format ["Replace_%1", _x]; + _name = format ["Replace_%1_%2", _forEachIndex, _x]; _text = localize LSTRING(ReplaceWheel); _condition = {[_this select 1, _this select 0, _this select 2 select 0, "ReplaceWheel"] call DFUNC(canRepair)}; @@ -73,7 +84,9 @@ _hitPointsAddedAmount = []; } else { // exit if the hitpoint is in the blacklist, e.g. glasses - if (_x in IGNORED_HITPOINTS) exitWith {}; + if (_x in IGNORED_HITPOINTS) exitWith {TRACE_3("Ignored Hitpoint",_x,_forEachIndex,_selectionName);}; + if (_x == "") exitWith {TRACE_3("Hitpoint Empty",_x,_forEachIndex,_selectionName);}; + if (isNil {_vehicle getHit _selectionName}) exitWith {TRACE_3("No Selection",_x,_forEachIndex,_selectionName);}; //Not a real hitpoint private ["_hitpointGroupConfig", "_inHitpointSubGroup", "_currentHitpoint"]; @@ -93,15 +106,15 @@ _hitPointsAddedAmount = []; }; // Exit if current hitpoint is in sub-group (only main hitpoints get actions) - if (_inHitpointSubGroup) exitWith {}; + if (_inHitpointSubGroup) exitWith {TRACE_3("inHitpointSubGroup",_x,_forEachIndex,_selectionName);}; // exit if the hitpoint is virtual - if (isText (configFile >> "CfgVehicles" >> _type >> "HitPoints" >> _x >> "depends")) exitWith {}; + if (isText (configFile >> "CfgVehicles" >> _type >> "HitPoints" >> _x >> "depends")) exitWith {TRACE_3("Depends",_x,_forEachIndex,_selectionName);}; // add misc repair action private ["_name", "_icon", "_selection", "_customSelectionsConfig"]; - _name = format ["Repair_%1", _x]; + _name = format ["Repair_%1_%2", _forEachIndex, _x]; // Find localized string and track those added for numerization ([_x, "%1", _x, [_hitPointsAddedNames, _hitPointsAddedStrings, _hitPointsAddedAmount]] call FUNC(getHitPointString)) params ["_text", "_trackArray"]; @@ -135,22 +148,26 @@ _hitPointsAddedAmount = []; // 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)); + _selection = _vehicle selectionPosition _selectionName; }; - _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)}; - if (_x in TRACK_HITPOINTS) then { + if (_duplicateHitpointName) exitWith {TRACE_3("Duplicate Track",_x,_forEachIndex,_selectionName);}; //Tracks should always be unique if (_x == "HitLTrack") then { _selection = [-1.75, 0, -1.75]; } else { _selection = [1.75, 0, -1.75]; }; - _action = [_name, _text, _icon, _statement, _condition, {}, [_x, "RepairTrack"], _selection, 4] call EFUNC(interact_menu,createAction); + TRACE_5("Adding RepairTrack",_name,_forEachIndex,_selectionName,_text,_selection); + _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)}; + _action = [_name, _text, _icon, _statement, _condition, {}, [_x], _selection, 4] call EFUNC(interact_menu,createAction); [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); } else { - _action = [_name, _text, _icon, _statement, _condition, {}, [_x, "MiscRepair"], _selection, 4] call EFUNC(interact_menu,createAction); + TRACE_5("Adding MiscRepair",_name,_forEachIndex,_selectionName,_text,_selection); + _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)}; + _action = [_name, _text, _icon, _statement, _condition, {}, [_forEachIndex], _selection, 5] call EFUNC(interact_menu,createAction); // 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); @@ -161,10 +178,11 @@ _hitPointsAddedAmount = []; }; } forEach _hitPoints; -_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)}; -_action = [QGVAR(fullRepair), localize LSTRING(fullRepair), "A3\ui_f\data\igui\cfg\actions\repair_ca.paa", _statement, _condition, {}, ["", "fullRepair"], "", 4] call EFUNC(interact_menu,createAction); +_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); [_type, 0, ["ACE_MainActions", QGVAR(Repair)], _action] call EFUNC(interact_menu,addActionToClass); + // set class as initialized _initializedClasses pushBack _type; diff --git a/addons/repair/functions/fnc_addSpareParts.sqf b/addons/repair/functions/fnc_addSpareParts.sqf index 4d3197c8e8..74ea0d4c10 100644 --- a/addons/repair/functions/fnc_addSpareParts.sqf +++ b/addons/repair/functions/fnc_addSpareParts.sqf @@ -18,7 +18,6 @@ */ #include "script_component.hpp" -private ["_part"]; params ["_vehicle", ["_amount", 1], ["_part", ""], ["_force", false]]; TRACE_2("params",_vehicle,_amount); diff --git a/addons/repair/functions/fnc_canMiscRepair.sqf b/addons/repair/functions/fnc_canMiscRepair.sqf index 0533f9f4fc..7ebfb5c5a8 100644 --- a/addons/repair/functions/fnc_canMiscRepair.sqf +++ b/addons/repair/functions/fnc_canMiscRepair.sqf @@ -5,38 +5,51 @@ * Arguments: * 0: Unit that does the repairing * 1: Vehicle to repair - * 2: Selected hitpoint + * 2: Selected hitpoint INDEX * * Return Value: * Can Misc Repair * * Example: - * [unit, vehicle, "hitpoint", "classname"] call ace_repair_fnc_canMiscRepair + * [unit, vehicle, 5] call ace_repair_fnc_canMiscRepair * * Public: No */ + #include "script_component.hpp" -private ["_hitpointGroupConfig", "_hitpointGroup", "_postRepairDamage", "_return"]; -params ["_caller", "_target", "_hitPoint"]; +private ["_hitpointGroupConfig", "_hitpointGroup", "_postRepairDamage", "_return", "_hitPointClassname", "_subHitIndex"]; +params ["_caller", "_target", "_hitPointIndex"]; -if !([_unit, _target, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith {false}; +(getAllHitPointsDamage _target) params ["_allHitPoints", "", "_allHitPointDamages"]; + +if !([_caller, _target, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith {false}; // Get hitpoint groups if available _hitpointGroupConfig = configFile >> "CfgVehicles" >> typeOf _target >> QGVAR(hitpointGroups); _hitpointGroup = []; if (isArray _hitpointGroupConfig) then { + _hitPointClassname = _allHitPoints select _hitPointIndex; + // Retrieve hitpoint subgroup if current hitpoint is main hitpoint of a group { + _x params ["_masterHitpoint", "_subHitArray"]; // Exit using found hitpoint group if this hitpoint is leader of any - if (_x select 0 == _hitPoint) exitWith { - _hitpointGroup = _x select 1; + if (_masterHitpoint == _hitPointClassname) exitWith { + { + _subHitIndex = _allHitPoints find _x; + if (_subHitIndex == -1) then { + ERROR("Hitpoint Not Found"); + } else { + _hitpointGroup pushBack _subHitIndex; + }; + } forEach _subHitArray; }; } forEach (getArray _hitpointGroupConfig); }; // Add current hitpoint to the group -_hitpointGroup pushBack _hitPoint; +_hitpointGroup pushBack _hitPointIndex; // Get post repair damage _postRepairDamage = [_caller] call FUNC(getPostRepairDamage); @@ -44,7 +57,7 @@ _postRepairDamage = [_caller] call FUNC(getPostRepairDamage); // Return true if damage can be repaired on any hitpoint in the group, else false _return = false; { - if ((_target getHitPointDamage _x) > _postRepairDamage) exitWith { + if ((_allHitPointDamages select _x) > _postRepairDamage) exitWith { _return = true; }; } forEach _hitpointGroup; diff --git a/addons/repair/functions/fnc_canRepair.sqf b/addons/repair/functions/fnc_canRepair.sqf index 8fb2a4938e..6ba7b6b23a 100644 --- a/addons/repair/functions/fnc_canRepair.sqf +++ b/addons/repair/functions/fnc_canRepair.sqf @@ -5,14 +5,14 @@ * Arguments: * 0: Unit that does the repairing * 1: Vehicle to repair - * 2: Selected hitpoint + * 2: Selected hitpoint or hitpointIndex or * 3: Repair Action Classname * * Return Value: * Can Repair * * Example: - * ["something", player] call ace_repair_fnc_canRepair + * [player, car, "HitHull", "MiscRepair"] call ace_repair_fnc_canRepair * * Public: Yes */ @@ -68,37 +68,45 @@ if (getText (_config >> "condition") != "") then { if (!_return) exitwith {false}; -_vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then { - missionNamespace getVariable [getText(_config >> "vehicleStateCondition"), 0] -} else { - getNumber(_config >> "vehicleStateCondition") -}; +// _vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then { + // missionNamespace getVariable [getText(_config >> "vehicleStateCondition"), 0] +// } else { + // getNumber(_config >> "vehicleStateCondition") +// }; // if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitwith {false}; -_locations = getArray (_config >> "repairLocations"); -if ("All" in _locations) exitwith {true}; - -private ["_repairFacility", "_repairVeh"]; -_repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))}; -_repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))}; - -{ - if (_x == "field") exitwith {_return = true;}; - if (_x == "RepairFacility" && _repairFacility) exitwith {_return = true;}; - if (_x == "RepairVehicle" && _repairVeh) exitwith {_return = true;}; - if !(isnil _x) exitwith { - private "_val"; - _val = missionNamespace getVariable _x; - if (typeName _val == "SCALAR") then { - _return = switch (_val) do { - case 0: {true}; //useAnywhere - case 1: {call _repairVeh}; //repairVehicleOnly - case 2: {call _repairFacility}; //repairFacilityOnly - case 3: {(call _repairFacility) || {call _repairVeh}}; //vehicleAndFacility - default {false}; //Disabled +local _repairLocations = getArray (_config >> "repairLocations"); +if (!("All" in _repairLocations)) then { + local _repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))}; + local _repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))}; + { + if (_x == "field") exitwith {_return = true;}; + if (_x == "RepairFacility" && _repairFacility) exitwith {_return = true;}; + if (_x == "RepairVehicle" && _repairVeh) exitwith {_return = true;}; + if !(isnil _x) exitwith { + local _val = missionNamespace getVariable _x; + if (typeName _val == "SCALAR") then { + _return = switch (_val) do { + case 0: {true}; //useAnywhere + case 1: {call _repairVeh}; //repairVehicleOnly + case 2: {call _repairFacility}; //repairFacilityOnly + case 3: {(call _repairFacility) || {call _repairVeh}}; //vehicleAndFacility + default {false}; //Disabled + }; }; }; - }; -} forEach _locations; + } forEach _repairLocations; +}; +if (!_return) exitwith {false}; -_return && alive _target; +//Check that there are required objects nearby +local _requiredObjects = getArray (_config >> "claimObjects"); +if (!(_requiredObjects isEqualTo [])) then { + local _objectsAvailable = [_caller, 5, _requiredObjects] call FUNC(getClaimObjects); + if (_objectsAvailable isEqualTo []) then { + TRACE_2("Missing Required Objects",_requiredObjects,_objectsAvailable); + _return = false + }; +}; + +_return && {alive _target}; diff --git a/addons/repair/functions/fnc_canRepairTrack.sqf b/addons/repair/functions/fnc_canRepairTrack.sqf index 0ba01afb87..e1ff4a5628 100644 --- a/addons/repair/functions/fnc_canRepairTrack.sqf +++ b/addons/repair/functions/fnc_canRepairTrack.sqf @@ -1,6 +1,6 @@ /* * Author: commy2 - * Check if the unit can replace given wheel of the vehicle. + * Check if the unit can replace given track of the vehicle. * * Arguments: * 0: Unit that does the repairing @@ -17,27 +17,11 @@ */ #include "script_component.hpp" -params ["_unit", "_target", "_hitPoint", ["_wheel",false]]; -TRACE_4("params",_unit,_target,_hitPoint,_wheel); -// TODO [_unit, _wheel] call EFUNC(common,claim); on start of action +params ["_unit", "_target", "_hitPoint"]; +TRACE_3("params",_unit,_target,_hitPoint); if !([_unit, _target, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith {false}; -if (typeName _wheel == "OBJECT") then { - // not near interpret as objNull - if !(_wheel in nearestObjects [_unit, ["ACE_Track"], 5]) then { - _wheel = objNull; - }; -} else { - _wheel = objNull; +//check for a near track is handled by claimObjects[] config - { - if ([_unit, _x, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith { - _wheel = _x; - }; - } forEach nearestObjects [_unit, ["ACE_Track"], 5]; -}; - -if (isNull _wheel || damage _wheel >= 1) exitWith {false}; - -alive _target && {_target getHitPointDamage _hitPoint > 0} +(_target getHitPointDamage _hitPoint > 0) diff --git a/addons/repair/functions/fnc_canReplaceTrack.sqf b/addons/repair/functions/fnc_canReplaceTrack.sqf index aec3a9f062..a272a0d176 100644 --- a/addons/repair/functions/fnc_canReplaceTrack.sqf +++ b/addons/repair/functions/fnc_canReplaceTrack.sqf @@ -1,12 +1,11 @@ /* * Author: commy2 - * Check if the unit can replace given wheel of the vehicle. + * Check if the unit can replace given track of the vehicle. * * Arguments: * 0: Unit that does the repairing * 1: Vehicle to repair * 2: Selected hitpoint - * 3: Track / (default: false) * * Return Value: * None @@ -18,27 +17,11 @@ */ #include "script_component.hpp" -params ["_unit", "_target", "_hitPoint", ["_track", false]]; -TRACE_4("params",_unit,_target,_hitPoint,_track); -// TODO [_unit, _track] call EFUNC(common,claim); on start of action +params ["_unit", "_target", "_hitPoint"]; +TRACE_3("params",_unit,_target,_hitPoint); if !([_unit, _target, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith {false}; -if (typeName _track == "OBJECT") then { - // not near interpret as objNull - if !(_track in nearestObjects [_unit, ["ACE_Track"], 5]) then { - _track = objNull; - }; -} else { - _track = objNull; +//check for a near track object is handled by claimObjects[] config - { - if ([_unit, _x, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith { - _track = _x; - }; - } forEach nearestObjects [_unit, ["ACE_Track"], 5]; -}; - -if (isNull _track) exitWith {false}; - -alive _target && {_target getHitPointDamage _hitPoint >= 1} +(_target getHitPointDamage _hitPoint >= 1) diff --git a/addons/repair/functions/fnc_canReplaceWheel.sqf b/addons/repair/functions/fnc_canReplaceWheel.sqf index cf7a047f19..0b7f7ad4e7 100644 --- a/addons/repair/functions/fnc_canReplaceWheel.sqf +++ b/addons/repair/functions/fnc_canReplaceWheel.sqf @@ -6,7 +6,6 @@ * 0: Unit that does the repairing * 1: Vehicle to repair * 2: Selected hitpoint - * 3: Wheel / (default: false) * * Return Value: * None @@ -18,31 +17,12 @@ */ #include "script_component.hpp" -params ["_unit", "_target", "_hitPoint", ["_wheel", false]]; -TRACE_4("params",_unit,_target,_hitPoint,_wheel); -// TODO [_unit, _wheel] call EFUNC(common,claim); on start of action -//if !([_unit, _target, _hitpoint, "ReplaceWheel"] call FUNC(canRepair)) exitwith {false}; +params ["_unit", "_target", "_hitPoint"]; +TRACE_3("params",_unit,_target,_hitPoint); if !([_unit, _target, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith {false}; -//if !([_unit, GVAR(engineerSetting_Wheel)] call FUNC(isEngineer)) exitWith {false}; +//check for GVAR(engineerSetting_Wheel) is handeled by requiredEngineer config +//check for a near wheel object is handled by claimObjects[] config -// check for a near wheel -if (typeName _wheel == "OBJECT") then { - // not near interpret as objNull - if !(_wheel in nearestObjects [_unit, ["ACE_Wheel"], 5]) then { - _wheel = objNull; - }; -} else { - _wheel = objNull; - - { - if ([_unit, _x, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith { - _wheel = _x; - }; - } forEach nearestObjects [_unit, ["ACE_Wheel"], 5]; -}; - -if (isNull _wheel) exitWith {false}; - -alive _target && {_target getHitPointDamage _hitPoint >= 1} +(_target getHitPointDamage _hitPoint >= 1) diff --git a/addons/repair/functions/fnc_doFullRepair.sqf b/addons/repair/functions/fnc_doFullRepair.sqf index 6beec4c4c7..ed67a69e99 100644 --- a/addons/repair/functions/fnc_doFullRepair.sqf +++ b/addons/repair/functions/fnc_doFullRepair.sqf @@ -1,23 +1,22 @@ /* * Author: Glowbal - * Called by repair action / progress bar. Raise events to set the new hitpoint damage. + * Fully repairs vehicle * * Arguments: - * 0: Unit that does the repairing + * 0: Unit that does the repairing (not used) * 1: Vehicle to repair - * 2: Selected hitpoint * * Return Value: * None * * Example: - * [unit, vehicle, "hitpoint"] call ace_repair_fnc_doFullRepair + * [unit, vehicle] call ace_repair_fnc_doFullRepair * * Public: No */ #include "script_component.hpp" -params ["_unit", "_vehicle", "_hitPoint"]; -TRACE_3("params",_unit,_vehicle,_hitPoint); +params ["", "_vehicle"]; +TRACE_1("params",_vehicle); _vehicle setDamage 0; diff --git a/addons/repair/functions/fnc_doRepair.sqf b/addons/repair/functions/fnc_doRepair.sqf index 1cf3f77bca..014adf8af4 100644 --- a/addons/repair/functions/fnc_doRepair.sqf +++ b/addons/repair/functions/fnc_doRepair.sqf @@ -5,61 +5,70 @@ * Arguments: * 0: Unit that does the repairing * 1: Vehicle to repair - * 2: Selected hitpoint + * 2: Selected hitpointIndex * * Return Value: * None * * Example: - * [unit, vehicle, "hitpoint"] call ace_repair_fnc_doRepair + * [unit, vehicle, 6, "MiscRepair"] call ace_repair_fnc_doRepair * * Public: No */ #include "script_component.hpp" -private ["_hitPointDamage", "_text", "_hitpointGroup"]; -params ["_unit", "_vehicle", "_hitPoint"]; -TRACE_3("params",_unit,_vehicle,_hitPoint); +params ["_unit", "_vehicle", "_hitPointIndex"]; +TRACE_3("params",_unit,_vehicle,_hitPointIndex); + +local _postRepairDamageMin = [_unit] call FUNC(getPostRepairDamage); + +(getAllHitPointsDamage _vehicle) params ["_allHitPoints"]; +local _hitPointClassname = _allHitPoints select _hitPointIndex; // get current hitpoint damage -_hitPointDamage = _vehicle getHitPointDamage _hitPoint; +local _hitPointCurDamage = _vehicle getHitIndex _hitPointIndex; -_hitPointDamage = _hitPointDamage - 0.5; -// don't use negative values for damage -_hitPointDamage = _hitPointDamage max ([_unit] call FUNC(getPostRepairDamage)); +// repair a max of 0.5, don't use negative values for damage +local _hitPointNewDamage = (_hitPointCurDamage - 0.5) max _postRepairDamageMin; -// raise event to set the new hitpoint damage -["setVehicleHitPointDamage", _vehicle, [_vehicle, _hitPoint, _hitPointDamage]] call EFUNC(common,targetEvent); +if (_hitPointNewDamage < _hitPointCurDamage) then { + // raise event to set the new hitpoint damage + TRACE_3("repairing main point", _vehicle, _hitPointIndex, _hitPointNewDamage); + ["setVehicleHitPointDamage", _vehicle, [_vehicle, _hitPointIndex, _hitPointNewDamage]] call EFUNC(common,targetEvent); + _hitPointCurDamage = _hitPointNewDamage; +}; // Get hitpoint groups if available -_hitpointGroupConfig = configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(hitpointGroups); -_hitpointGroup = []; +local _hitpointGroupConfig = configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(hitpointGroups); if (isArray _hitpointGroupConfig) then { - // Retrieve group if current hitpoint is leader of any + // Retrieve hitpoint subgroup if current hitpoint is main hitpoint of a group { - if (_x select 0 == _hitPoint) exitWith { - ([_vehicle] call EFUNC(common,getHitPointsWithSelections)) params ["_hitpoints"]; - // Set all sub-group hitpoints' damage to 0, if a hitpoint is invalid print RPT error + _x params ["_masterHitpoint", "_subHitArray"]; + // Exit using found hitpoint group if this hitpoint is leader of any + if (_masterHitpoint == _hitPointClassname) exitWith { { - if (_x in _hitpoints) then { - ["setVehicleHitPointDamage", _vehicle, [_vehicle, _x, 0]] call EFUNC(common,targetEvent); + local _subHitIndex = _allHitPoints find _x; //convert hitpoint classname to index + if (_subHitIndex == -1) then { + ACE_LOGERROR_2("Invalid hitpoint %1 in hitpointGroups of %2",_x,_vehicle); } else { - diag_log text format ["[ACE] ERROR: Invalid hitpoint %1 in hitpointGroups of %2", _x, _vehicle]; + local _subPointCurDamage = _vehicle getHitIndex _hitPointIndex; + local _subPointNewDamage = (_subPointCurDamage - 0.5) max _postRepairDamageMin; + if (_subPointNewDamage < _subPointCurDamage) then { + TRACE_3("repairing sub point", _vehicle, _subHitIndex, _subPointNewDamage); + ["setVehicleHitPointDamage", _vehicle, [_vehicle, _subHitIndex, _subPointNewDamage]] call EFUNC(common,targetEvent); + }; }; - - } forEach (_x select 1); + } forEach _subHitArray; }; } forEach (getArray _hitpointGroupConfig); }; // display text message if enabled if (GVAR(DisplayTextOnRepair)) then { - private ["_textLocalized", "_textDefault"]; - // Find localized string - _textLocalized = localize ([LSTRING(RepairedHitPointFully), LSTRING(RepairedHitPointPartially)] select (_hitPointDamage > 0)); - _textDefault = localize ([LSTRING(RepairedFully), LSTRING(RepairedPartially)] select (_hitPointDamage > 0)); - ([_hitPoint, _textLocalized, _textDefault] call FUNC(getHitPointString)) params ["_text"]; + local _textLocalized = localize ([LSTRING(RepairedHitPointFully), LSTRING(RepairedHitPointPartially)] select (_hitPointCurDamage > 0)); + local _textDefault = localize ([LSTRING(RepairedFully), LSTRING(RepairedPartially)] select (_hitPointCurDamage > 0)); + ([_hitPointClassname, _textLocalized, _textDefault] call FUNC(getHitPointString)) params ["_text"]; // Display text [_text] call EFUNC(common,displayTextStructured); diff --git a/addons/repair/functions/fnc_doRepairTrack.sqf b/addons/repair/functions/fnc_doRepairTrack.sqf index de04e71920..cde22f3dd7 100644 --- a/addons/repair/functions/fnc_doRepairTrack.sqf +++ b/addons/repair/functions/fnc_doRepairTrack.sqf @@ -6,43 +6,39 @@ * 0: Unit that does the repairing * 1: Vehicle to repair * 2: Selected hitpoint - * 3: Repair Action Classname + * 3: Repair Action Classname (Not used) + * 4: (Not used) + * 5: (Not used) + * 6: Required Repair Objects * * Return Value: * None * * Example: - * [unit, vehicle, "hitpoint", "classname"] call ace_repair_fnc_doRepairTrack + * [unit, vehicle, "hitpoint", "RepairTrack", [], [], [aTrack]] call ace_repair_fnc_doRepairTrack * * Public: No */ #include "script_component.hpp" -params ["_unit", "_vehicle", "_hitPoint", "_classname"]; -TRACE_4("params",_unit,_vehicle,_hitPoint,_classname); -// TODO [_unit, _wheel] call EFUNC(common,claim); on start of action +params ["_unit", "_vehicle", "_hitPoint", "", "", "", "_claimedObjects"]; +TRACE_4("params",_unit,_vehicle,_hitPoint,_claimedObjects); -private ["_hitPointDamage", "_newDamage", "_wheel"]; +_claimedObjects params [["_track", objNull]]; +if ((isNull _track) || {!([_unit, _track, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith))}) exitWith { + ACE_LOGERROR_1("Bad Track", _claimedObjects); +}; -_wheel = objNull; - -{ - if ([_unit, _x, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith { - _wheel = _x; - }; -} forEach nearestObjects [_unit, ["ACE_Track"], 5]; -if (isNull _wheel) exitwith {}; +// can't use a destroyed track +if ((damage _track) >= 1) exitWith {}; // get current hitpoint damage +local _hitPointDamage = _vehicle getHitPointDamage _hitPoint; +local _damageRepaired = (1 - (damage _track)) / 4; // require 4 tracks to fully replace one side -_hitPointDamage = _vehicle getHitPointDamage _hitPoint; -_newDamage = (1 - (damage _wheel)) / 4; // require 4 tracks to fully replace one side - -// can't replace a destroyed wheel -if ((damage _wheel) >= 1) exitWith {}; // don't die by spawning / moving the wheel -_hitPointDamage = (_hitPointDamage - _newDamage) min 0; -deleteVehicle _wheel; +_hitPointDamage = (_hitPointDamage - _damageRepaired) min 0; +deleteVehicle _track; // raise event to set the new hitpoint damage ["setWheelHitPointDamage", _vehicle, [_vehicle, _hitPoint, _hitPointDamage]] call EFUNC(common,targetEvent); diff --git a/addons/repair/functions/fnc_doReplaceTrack.sqf b/addons/repair/functions/fnc_doReplaceTrack.sqf index a95a669159..75f7f70723 100644 --- a/addons/repair/functions/fnc_doReplaceTrack.sqf +++ b/addons/repair/functions/fnc_doReplaceTrack.sqf @@ -1,54 +1,50 @@ /* * Author: commy2 - * Called by repair action / progress bar. Raise events to set the new hitpoint damage. + * Replaces a track. * * Arguments: * 0: Unit that does the repairing * 1: Vehicle to repair * 2: Selected hitpoint - * 3: Repair Action Classname + * 3: Repair Action Classname (Not used) + * 4: (Not used) + * 5: (Not used) + * 6: Required Repair Objects * * Return Value: * None * * Example: - * [unit, vehicle, "hitpoint", "classname"] call ace_repair_fnc_doReplaceTrack + * [unit, vehicle, "hitpoint", "ReplaceTrack", [], [], [aTrack]] call ace_repair_fnc_doReplaceTrack * * Public: No */ #include "script_component.hpp" -params ["_unit", "_vehicle", "_hitPoint", "_classname"]; -TRACE_4("params",_unit,_vehicle,_hitPoint,_classname); -// TODO [_unit, _wheel] call EFUNC(common,claim); on start of action +params ["_unit", "_vehicle", "_hitPoint", "", "", "", "_claimedObjects"]; +TRACE_4("params",_unit,_vehicle,_hitPoint,_claimedObjects); -private["_hitPointDamage", "_wheel"]; - -_wheel = objNull; - -{ - if ([_unit, _x, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith { - _wheel = _x; - }; -} forEach nearestObjects [_unit, ["ACE_Track"], 5]; -if (isNull _wheel) exitwith {}; +_claimedObjects params [["_track", objNull]]; +if ((isNull _track) || {!([_unit, _track, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith))}) exitWith { + ACE_LOGERROR_1("Bad Track", _claimedObjects); +}; // get current hitpoint damage -_hitPointDamage = _vehicle getHitPointDamage _hitPoint; +local _hitPointDamage = _vehicle getHitPointDamage _hitPoint; // can't replace not destroyed wheel if (_hitPointDamage < 1) exitWith {}; -// don't die by spawning / moving the wheel -_hitPointDamage = damage _wheel; +// get track's damage +local _newHitPointDamage = damage _track; -// can't replace a destroyed wheel -if (_hitPointDamage >= 1) exitWith {}; +// can't replace with a destroyed wheel +if (_newHitPointDamage >= 1) exitWith {}; -deleteVehicle _wheel; +deleteVehicle _track; // raise event to set the new hitpoint damage -["setWheelHitPointDamage", _vehicle, [_vehicle, _hitPoint, _hitPointDamage]] call EFUNC(common,targetEvent); +["setWheelHitPointDamage", _vehicle, [_vehicle, _hitPoint, _newHitPointDamage]] call EFUNC(common,targetEvent); // display text message if enabled if (GVAR(DisplayTextOnRepair)) then { diff --git a/addons/repair/functions/fnc_doReplaceWheel.sqf b/addons/repair/functions/fnc_doReplaceWheel.sqf index f10712d65d..20bcfe95a3 100644 --- a/addons/repair/functions/fnc_doReplaceWheel.sqf +++ b/addons/repair/functions/fnc_doReplaceWheel.sqf @@ -1,54 +1,50 @@ /* * Author: commy2 - * Called by repair action / progress bar. Raise events to set the new hitpoint damage. + * Repairs a vehicle's wheel with a ACE_wheel spare part object. * * Arguments: * 0: Unit that does the repairing * 1: Vehicle to repair * 2: Selected hitpoint - * 3: Repair Action Classname + * 3: Repair Action Classname (Not used) + * 4: (Not used) + * 5: (Not used) + * 6: Required Repair Objects * * Return Value: * None * * Example: - * [unit, vehicle, "hitpoint", "classname"] call ace_repair_fnc_doReplaceWheel + * [unit, vehicle, "hitpoint", "ReplaceWheel", [], [], [aWheel]] call ace_repair_fnc_doReplaceWheel * * Public: No */ #include "script_component.hpp" -params ["_unit", "_vehicle", "_hitPoint", "_classname"]; -TRACE_4("params",_unit,_vehicle,_hitPoint,_classname); -// TODO [_unit, _wheel] call EFUNC(common,claim); on start of action +params ["_unit", "_vehicle", "_hitPoint", "", "", "", "_claimedObjects"]; +TRACE_4("params",_unit,_vehicle,_hitPoint,_claimedObjects); -private ["_hitPointDamage", "_wheel"]; - -_wheel = objNull; - -{ - if ([_unit, _x, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith { - _wheel = _x; - }; -} forEach nearestObjects [_unit, ["ACE_Wheel"], 5]; -if (isNull _wheel) exitwith {}; +_claimedObjects params [["_wheel", objNull]]; +if ((isNull _wheel) || {!([_unit, _wheel, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith))}) exitWith { + ACE_LOGWARNING_1("Bad Claimed Wheel", _claimedObjects); +}; // get current hitpoint damage -_hitPointDamage = _vehicle getHitPointDamage _hitPoint; +local _hitPointDamage = _vehicle getHitPointDamage _hitPoint; // can't replace not destroyed wheel if (_hitPointDamage < 1) exitWith {}; -// don't die by spawning / moving the wheel -_hitPointDamage = damage _wheel; +// get replacement wheel's damage +local _newHitPointDamage = damage _wheel; // can't replace a destroyed wheel -if (_hitPointDamage >= 1) exitWith {}; +if (_newHitPointDamage >= 1) exitWith {}; deleteVehicle _wheel; // raise event to set the new hitpoint damage -["setWheelHitPointDamage", _vehicle, [_vehicle, _hitPoint, _hitPointDamage]] call EFUNC(common,targetEvent); +["setWheelHitPointDamage", _vehicle, [_vehicle, _hitPoint, _newHitPointDamage]] call EFUNC(common,targetEvent); // display text message if enabled if (GVAR(DisplayTextOnRepair)) then { diff --git a/addons/repair/functions/fnc_getClaimObjects.sqf b/addons/repair/functions/fnc_getClaimObjects.sqf new file mode 100644 index 0000000000..01229f0c9f --- /dev/null +++ b/addons/repair/functions/fnc_getClaimObjects.sqf @@ -0,0 +1,44 @@ +/* + * Author: PabstMirror + * Returns array of required nearby repair objects (wheels/tracks) + * + * Arguments: + * 0: Unit that does the repairing + * 1: Max range to seach from unit (meters) + * 2: Array of arrays of classnames + * + * Return Value: + * Array of objects, or [] if not all available + * + * Example: + * [player, 5, [["Ace_Track"]]] call ace_repair_fnc_getClaimObjects + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit", "_maxRange", "_objectsToClaim"]; +TRACE_3("params",_unit,_maxRange,_objectsToClaim); + +local _return = []; + +{ + local _requiredList = _x; //eg ["ace_track", "ace_track"] + local _ableToAquire = []; //will be array of ojbects + { + local _nearObjects = nearestObjects [_unit, [_x], _maxRange]; + local _canClaimObject = objNull; + { + if ((!(_x in _ableToAquire)) + && {[_unit, _x, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)} + &&{(damage _x) < 1} + ) exitWith { _canClaimObject = _x; }; + } forEach _nearObjects; + if (isNull _canClaimObject) exitWith {}; + _ableToAquire pushBack _canClaimObject; + } forEach _x; + TRACE_2("Check required equals available",_requiredList,_ableToAquire); + if ((count _ableToAquire) == (count _requiredList)) exitWith {_return = _ableToAquire}; +} count _objectsToClaim; + +_return diff --git a/addons/repair/functions/fnc_getWheelHitPointsWithSelections.sqf b/addons/repair/functions/fnc_getWheelHitPointsWithSelections.sqf index 182c6f54f0..c94d40f163 100644 --- a/addons/repair/functions/fnc_getWheelHitPointsWithSelections.sqf +++ b/addons/repair/functions/fnc_getWheelHitPointsWithSelections.sqf @@ -10,7 +10,7 @@ * 1: Wheel hitpoint selections in model coordinates * * Example: - * [unit, vehicle, "hitpoint"] call ace_repair_fnc_getWheelHitPointsWithSelections + * [car1] call ace_repair_fnc_getWheelHitPointsWithSelections * * Public: No */ @@ -19,64 +19,80 @@ params ["_vehicle"]; TRACE_1("params",_vehicle); +private["_bestDist", "_bestIndex", "_wheelBone", "_wheelBoneNameResized", "_wheelCenter", "_wheelCenterPos", "_wheelHitPoint", "_wheelHitPointSelection", "_wheelHitPointSelections", "_wheelHitPoints", "_wheelName", "_xDist", "_xPos"]; + // get the vehicles wheel config private "_wheels"; _wheels = configfile >> "CfgVehicles" >> typeOf _vehicle >> "Wheels"; // exit with nothing if the vehicle has no wheels class -if !(isClass _wheels) exitWith {[[],[]]}; +if !(isClass _wheels) exitWith {TRACE_1("No Wheels",_wheels); [[],[]]}; + +// get all hitpoints and selections +(getAllHitPointsDamage _vehicle) params ["_hitPoints", "_hitPointSelections"]; // get all wheels and read selections from config -private ["_selections", "_bones"]; - _wheels = "true" configClasses _wheels; -_selections = []; -_bones = []; -{ - _selections pushBack getText (_x >> "center"); - - private "_bone"; - _bone = getText (_x >> "boneName"); - - _bone = toArray _bone; - _bone resize count "wheel_X_Y"; // this is a requirement for physx. Should work for all addon vehicles. - _bone = toString _bone; - - _bones pushBack _bone; -} forEach _wheels; - -// get hitpoints with their fire geometry selections -private ["_hitPointsWithSelections", "_hitPoints", "_hitPointSelections"]; - -_hitPointsWithSelections = [_vehicle] call EFUNC(common,getHitPointsWithSelections); - -_hitPoints = _hitPointsWithSelections select 0; -_hitPointSelections = _hitPointsWithSelections select 1; - -// assign hitpoints to correct wheel selection by comparing bone name and fire geometry selection -private ["_wheelHitPoints", "_wheelHitPointSelections"]; - _wheelHitPoints = []; _wheelHitPointSelections = []; + { - private "_bone"; - _bone = _x; + _wheelName = configName _x; + _wheelCenter = getText (_x >> "center"); + _wheelBone = getText (_x >> "boneName"); + _wheelBoneNameResized = _wheelBone select [0, 9]; //ount "wheel_X_Y"; // this is a requirement for physx. Should work for all addon vehicles. - private "_index"; + TRACE_4("",_wheelName,_wheelCenter,_wheelBone,_wheelBoneNameResized); - _index = -1; + _wheelHitPoint = ""; + _wheelHitPointSelection = ""; + + //Commy's orginal method { - if (_bone != "" && {_x find _bone == 0}) exitWith { // same as above. Requirement for physx. - _index = _forEachIndex; + if ((_wheelBoneNameResized != "") && {_x find _wheelBoneNameResized == 0}) exitWith { // same as above. Requirement for physx. + _wheelHitPoint = _hitPoints select _forEachIndex; + _wheelHitPointSelection = _hitPointSelections select _forEachIndex; + TRACE_2("wheel found [Orginal]", _wheelName, _wheelHitPoint); }; } forEach _hitPointSelections; - if (_index != -1) then { - _wheelHitPoints pushBack (_hitPoints select _index); - _wheelHitPointSelections pushBack (_selections select _forEachIndex); + + if (_vehicle isKindOf "Car") then { + //Backup method, search for the closest hitpoint to the wheel's center selection pos. + //Ref #2742 - RHS's HMMWV + if (_wheelHitPoint == "") then { + _wheelCenterPos = _vehicle selectionPosition _wheelCenter; + if (_wheelCenterPos isEqualTo [0,0,0]) exitWith {TRACE_1("no center?",_wheelCenter);}; + + + _bestDist = 99; + _bestIndex = -1; + { + if (_x != "") then { + _xPos = _vehicle selectionPosition _x; + if (_xPos isEqualTo [0,0,0]) exitWith {}; + _xDist = _wheelCenterPos distance _xPos; + if (_xDist < _bestDist) then { + _bestIndex = _forEachIndex; + _bestDist = _xDist; + }; + }; + } forEach _hitPointSelections; + + TRACE_2("closestPoint",_bestDist,_bestIndex); + if (_bestIndex != -1) then { + _wheelHitPoint = _hitPoints select _bestIndex; + _wheelHitPointSelection = _hitPointSelections select _bestIndex; + TRACE_2("wheel found [Backup]", _wheelName, _wheelHitPoint); + }; + }; }; -} forEach _bones; + if ((_wheelHitPoint != "") && {_wheelHitPointSelection != ""}) then { + _wheelHitPoints pushBack _wheelHitPoint; + _wheelHitPointSelections pushBack _wheelHitPointSelection; + }; +} forEach _wheels; [_wheelHitPoints, _wheelHitPointSelections] diff --git a/addons/repair/functions/fnc_isEngineer.sqf b/addons/repair/functions/fnc_isEngineer.sqf index 9d6af3a1ff..9a7a157783 100644 --- a/addons/repair/functions/fnc_isEngineer.sqf +++ b/addons/repair/functions/fnc_isEngineer.sqf @@ -24,6 +24,6 @@ _class = _unit getVariable ["ACE_IsEngineer", getNumber (configFile >> "CfgVehic // This if statement is here for copmatability with the common variant of isEngineer, which requires a bool. // We cannot move this function to common because we require the GVAR(engineerSetting_Repair), which only makes sense to include in the repair module. -if (typeName _class == "BOOL") then {_class = 1}; +if (typeName _class == "BOOL") then {_class = [0, 1] select _class}; _class >= (_engineerN min GVAR(engineerSetting_Repair)); diff --git a/addons/repair/functions/fnc_moduleAddSpareParts.sqf b/addons/repair/functions/fnc_moduleAddSpareParts.sqf index cceb62e10c..0435244dc7 100644 --- a/addons/repair/functions/fnc_moduleAddSpareParts.sqf +++ b/addons/repair/functions/fnc_moduleAddSpareParts.sqf @@ -11,7 +11,7 @@ * None * * Example: - * function = "ace_repair_fnc_moduleAddSpareParts" + * [logic] call ace_repair_fnc_moduleAddSpareParts * * Public: No */ diff --git a/addons/repair/functions/fnc_moduleAssignEngineer.sqf b/addons/repair/functions/fnc_moduleAssignEngineer.sqf index 240a8c3b62..d64573130c 100644 --- a/addons/repair/functions/fnc_moduleAssignEngineer.sqf +++ b/addons/repair/functions/fnc_moduleAssignEngineer.sqf @@ -11,7 +11,7 @@ * None * * Example: - * function = "ace_repair_fnc_moduleAssignEngineer" + * [logic] call ace_repair_fnc_moduleAssignEngineer * * Public: No */ diff --git a/addons/repair/functions/fnc_moduleAssignRepairFacility.sqf b/addons/repair/functions/fnc_moduleAssignRepairFacility.sqf index 7150d0226b..9f01a06afc 100644 --- a/addons/repair/functions/fnc_moduleAssignRepairFacility.sqf +++ b/addons/repair/functions/fnc_moduleAssignRepairFacility.sqf @@ -11,7 +11,7 @@ * None * * Example: - * function = "ace_repair_fnc_moduleAssignRepairFacility" + * [logic] call ace_repair_fnc_moduleAssignRepairFacility * * Public: No */ diff --git a/addons/repair/functions/fnc_moduleAssignRepairVehicle.sqf b/addons/repair/functions/fnc_moduleAssignRepairVehicle.sqf index 647b5fe52c..f5df8d58e2 100644 --- a/addons/repair/functions/fnc_moduleAssignRepairVehicle.sqf +++ b/addons/repair/functions/fnc_moduleAssignRepairVehicle.sqf @@ -11,7 +11,7 @@ * None * * Example: - * function = "ace_repair_fnc_moduleAssignRepairVehicle" + * [logic] call ace_repair_fnc_moduleAssignRepairVehicle * * Public: No */ diff --git a/addons/repair/functions/fnc_moduleRepairSettings.sqf b/addons/repair/functions/fnc_moduleRepairSettings.sqf index 98ff354662..770af07449 100644 --- a/addons/repair/functions/fnc_moduleRepairSettings.sqf +++ b/addons/repair/functions/fnc_moduleRepairSettings.sqf @@ -4,14 +4,12 @@ * * Arguments: * 0: The module logic - * 1: Synchronized units - * 2: Activated * * Return Value: * None * * Example: - * function = "ace_repair_fnc_moduleRepairSettings" + * [logic] call ace_repair_fnc_moduleRepairSettings * * Public: No */ diff --git a/addons/repair/functions/fnc_repair.sqf b/addons/repair/functions/fnc_repair.sqf index fd3b4f032b..fc0c19f914 100644 --- a/addons/repair/functions/fnc_repair.sqf +++ b/addons/repair/functions/fnc_repair.sqf @@ -4,8 +4,8 @@ * * Arguments: * 0: Unit that does the repairing - * 1: Vehicle to repair + * 1: Vehicle to repair + * 2: Selected hitpoint or hitpointIndex or * 3: Repair Action Classname * * Return Value: @@ -21,7 +21,7 @@ params ["_caller", "_target", "_hitPoint", "_className"]; TRACE_4("params",_calller,_target,_hitPoint,_className); -private["_callbackProgress", "_callerAnim", "_calller", "_condition", "_config", "_consumeItems", "_displayText", "_engineerRequired", "_iconDisplayed", "_items", "_locations", "_repairTime", "_repairTimeConfig", "_return", "_usersOfItems", "_vehicleStateCondition", "_wpn", "_settingName", "_settingItemsArray"]; +private["_callbackProgress", "_callerAnim", "_calller", "_condition", "_config", "_consumeItems", "_displayText", "_engineerRequired", "_iconDisplayed", "_items", "_locations", "_repairTime", "_repairTimeConfig", "_return", "_usersOfItems", "_vehicleStateCondition", "_wpn", "_settingName", "_settingItemsArray", "_hitPointClassname"]; _config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className); if !(isClass _config) exitwith {false}; // or go for a default? @@ -67,40 +67,54 @@ if (getText (_config >> "condition") != "") then { }; if (!_return) exitwith {false}; -_vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then { - missionNamespace getVariable [getText(_config >> "vehicleStateCondition"), 0] -} else { - getNumber(_config >> "vehicleStateCondition") -}; +// _vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then { + // missionNamespace getVariable [getText(_config >> "vehicleStateCondition"), 0] +// } else { + // getNumber(_config >> "vehicleStateCondition") +// }; // if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitwith {false}; -_locations = getArray (_config >> "repairLocations"); -if ("All" in _locations) exitwith {true}; - -private ["_repairFacility", "_repairVeh"]; -_repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))}; -_repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))}; - -{ - if (_x == "field") exitwith {_return = true;}; - if (_x == "RepairFacility" && _repairFacility) exitwith {_return = true;}; - if (_x == "RepairVehicle" && _repairVeh) exitwith {_return = true;}; - if !(isnil _x) exitwith { - private "_val"; - _val = missionNamespace getVariable _x; - if (typeName _val == "SCALAR") then { - _return = switch (_val) do { - case 0: {true}; //useAnywhere - case 1: {call _repairVeh}; //repairVehicleOnly - case 2: {call _repairFacility}; //repairFacilityOnly - case 3: {(call _repairFacility) || {call _repairVeh}}; //vehicleAndFacility - default {false}; //Disabled +local _repairLocations = getArray (_config >> "repairLocations"); +if (!("All" in _repairLocations)) then { + local _repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))}; + local _repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))}; + { + if (_x == "field") exitwith {_return = true;}; + if (_x == "RepairFacility" && _repairFacility) exitwith {_return = true;}; + if (_x == "RepairVehicle" && _repairVeh) exitwith {_return = true;}; + if !(isnil _x) exitwith { + local _val = missionNamespace getVariable _x; + if (typeName _val == "SCALAR") then { + _return = switch (_val) do { + case 0: {true}; //useAnywhere + case 1: {call _repairVeh}; //repairVehicleOnly + case 2: {call _repairFacility}; //repairFacilityOnly + case 3: {(call _repairFacility) || {call _repairVeh}}; //vehicleAndFacility + default {false}; //Disabled + }; }; }; + } forEach _repairLocations; +}; + +local _requiredObjects = getArray (_config >> "claimObjects"); +local _claimObjectsAvailable = []; +if (!(_requiredObjects isEqualTo [])) then { + _claimObjectsAvailable = [_caller, 5, _requiredObjects] call FUNC(getClaimObjects); + if (_claimObjectsAvailable isEqualTo []) then { + TRACE_2("Missing Required Objects",_requiredObjects,_claimObjectsAvailable); + _return = false }; -} forEach _locations; +}; if !(_return && alive _target) exitwith {false}; +//Last exitWith: repair_success or repair_failure will be run + +//Claim required objects +{ + TRACE_2("Claiming", _x, (typeOf _x)); + [_caller, _x, false] call EFUNC(common,claim); +} forEach _claimObjectsAvailable; _consumeItems = if (isNumber (_config >> "itemConsumed")) then { getNumber (_config >> "itemConsumed"); @@ -177,13 +191,20 @@ _repairTime = if (isNumber (_config >> "repairingTime")) then { private ["_processText"]; // Find localized string +_hitPointClassname = if ((typeName _hitPoint) == "STRING") then { + _hitPoint +} else { + ((getAllHitPointsDamage _target) select 0) select _hitPoint +}; _processText = getText (_config >> "displayNameProgress"); -([_hitPoint, _processText, _processText] call FUNC(getHitPointString)) params ["_text"]; +([_hitPointClassname, _processText, _processText] call FUNC(getHitPointString)) params ["_text"]; + +TRACE_4("display",_hitPoint,_hitPointClassname,_processText,_text); // Start repair [ _repairTime, - [_caller, _target, _hitPoint, _className, _items, _usersOfItems], + [_caller, _target, _hitPoint, _className, _items, _usersOfItems, _claimObjectsAvailable], DFUNC(repair_success), DFUNC(repair_failure), _text, diff --git a/addons/repair/functions/fnc_repair_failure.sqf b/addons/repair/functions/fnc_repair_failure.sqf index 6e27ab07a7..9e329e1041 100644 --- a/addons/repair/functions/fnc_repair_failure.sqf +++ b/addons/repair/functions/fnc_repair_failure.sqf @@ -6,23 +6,24 @@ * 0: Arguments * 0: Unit that does the repairing * 1: Vehicle to repair + * 2: Selected hitpoint or hitpointIndex or * 3: Repair Action Classname * 4: None * 5: Items available + * 6: Claimed Repair Objects * * Return Value: * None * * Example: - * [[unit, vehicle, "hitpoint", "classname", nil, [items]]] call ace_repair_fnc_repair_failure + * [[unit, vehicle, "hitpoint", "classname", nil, [items], [aWheel]]] call ace_repair_fnc_repair_failure * * Public: No */ #include "script_component.hpp" params ["_args"]; -_args params ["_caller", "_target","_selectionName","_className","","_usersOfItems"]; +_args params ["_caller", "_target","_selectionName","_className","","_usersOfItems", "_claimedObjects"]; TRACE_5("params",_caller,_target,_selectionName,_className,_usersOfItems); private ["_config","_callback", "_usersOfItems", "_weaponSelect"]; @@ -46,6 +47,13 @@ if (_weaponSelect != "") then { (_x select 0) addItem (_x select 1); } forEach _usersOfItems; +//Unclaim repair objects: +{ + TRACE_2("Releasing", _x, (typeOf _x)); + [objNull, _x, false] call EFUNC(common,claim); +} forEach _claimedObjects; + + // Record specific callback _config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className); @@ -58,4 +66,4 @@ if (isNil _callback) then { _args call _callback; -// _args call FUNC(createLitter); +//todo: repair litter? diff --git a/addons/repair/functions/fnc_repair_success.sqf b/addons/repair/functions/fnc_repair_success.sqf index ccad93663f..4c21a40ae5 100644 --- a/addons/repair/functions/fnc_repair_success.sqf +++ b/addons/repair/functions/fnc_repair_success.sqf @@ -6,21 +6,24 @@ * 0: Arguments * 0: Unit that does the repairing * 1: Vehicle to repair + * 2: Selected hitpoint or hitpointIndex or * 3: Repair Action Classname + * 4: Items + * 5: User of Items + * 6: Claimed Repair Objects * * Return Value: * None * * Example: - * [[unit, vehicle, "hitpoint", "classname"]] call ace_repair_fnc_repair_success + * [[unit, vehicle, "hitpoint", "classname", [], [], [aWheel]]] call ace_repair_fnc_repair_success * * Public: No */ #include "script_component.hpp" params ["_args"]; -_args params ["_caller", "_target","_selectionName","_className"]; +_args params ["_caller", "_target","_selectionName","_className","","","_claimedObjects"]; TRACE_4("params",_caller,_target,_selectionName,_className); private ["_config","_callback", "_weaponSelect"]; @@ -40,6 +43,12 @@ if (_weaponSelect != "") then { _caller action ["SwitchWeapon", _caller, _caller, 99]; }; +//Unclaim repair objects: +{ + TRACE_2("Releasing", _x, (typeOf _x)); + [objNull, _x, false] call EFUNC(common,claim); +} forEach _claimedObjects; + // Record specific callback _config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className); @@ -51,4 +60,4 @@ if (isNil _callback) then { }; _args call _callback; -// _args call FUNC(createLitter); +//todo: repair litter? diff --git a/addons/repair/functions/fnc_setHitPointDamage.sqf b/addons/repair/functions/fnc_setHitPointDamage.sqf index a8b4cd347b..399f390767 100644 --- a/addons/repair/functions/fnc_setHitPointDamage.sqf +++ b/addons/repair/functions/fnc_setHitPointDamage.sqf @@ -1,86 +1,83 @@ /* * Author: commy2 * Set the hitpoint damage and change the structural damage acordingly, requires local vehicle. + * Handles the "setVehicleHitPointDamage" event * * Arguments: * 0: Local Vehicle to Damage - * 1: Selected hitpoint + * 1: Selected hitpoint INDEX * 2: Total Damage * * Return Value: * None * * Example: - * [vehicle, "hitpoint", 0.5] call ace_repair_fnc_setHitPointDamage + * [vehicle, 1, 0.5] call ace_repair_fnc_setHitPointDamage * * Public: No */ #include "script_component.hpp" -params ["_vehicle", "_hitPoint", "_hitPointDamage"]; -TRACE_3("params",_vehicle,_hitPoint,_hitPointDamage); +params ["_vehicle", "_hitPointIndex", "_hitPointDamage"]; +TRACE_3("params",_vehicle,_hitPointIndex,_hitPointDamage); + +private["_damageNew", "_damageOld", "_hitPointDamageRepaired", "_hitPointDamageSumOld", "_realHitpointCount", "_selectionName"]; // can't execute all commands if the vehicle isn't local. exit here. -if !(local _vehicle) exitWith {}; +if !(local _vehicle) exitWith {ACE_LOGERROR_1("Vehicle Not Local %1", _vehicle);}; -// get all valid hitpoints -private ["_hitPoints", "_hitPointsWithSelections"]; +//Check for bad typeName (changed from orignal v3.3 that took string) +if ((typeName _hitPointIndex) == "STRING") then { + ACE_DEPRECATED("repair-setHitPointDamage (hit point name ","3.5.0","hit index "); + _hitPointIndex = _allHitPoints find _hitPointIndex; +}; -_hitPoints = [_vehicle] call EFUNC(common,getHitpoints); -_hitPointsWithSelections = [_vehicle] call EFUNC(common,getHitpointsWithSelections) select 0; +// get all hitpoints and selections and damages +(getAllHitPointsDamage _vehicle) params [["_allHitPoints", []], ["_allHitPointsSelections", []], ["_allHitPointDamages", []]]; // exit if the hitpoint is not valid -if !(_hitPoint in _hitPoints) exitWith {systemChat format["NOT A VALID HITPOINT: %1",_hitpoint]}; - -// save array with damage values of all hitpoints -private "_hitPointDamages"; -_hitPointDamages = []; - -{ - _hitPointDamages set [_forEachIndex, (_vehicle getHitPointDamage _x)]; -} forEach _hitPoints; +if ((_hitPointIndex < 0) || {_hitPointIndex >= (count _allHitPoints)}) exitWith {ACE_LOGERROR_2("NOT A VALID HITPOINT: %1-%2", _hitPointIndex,_vehicle);}; // save structural damage and sum of hitpoint damages -private ["_damageOld", "_hitPointDamageSumOld"]; _damageOld = damage _vehicle; +_realHitpointCount = 0; _hitPointDamageSumOld = 0; +_hitPointDamageRepaired = 0; //positive for repairs : newSum = (oldSum - repaired) { - if (!(_x in IGNORED_HITPOINTS) && {!isText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints" >> _x >> "depends")}) then { - _hitPointDamageSumOld = _hitPointDamageSumOld + (_hitPointDamages select (_hitPoints find _x)); + _selectionName = _allHitPointsSelections select _forEachIndex; + //Filter out all the bad hitpoints (HitPoint="" or no selection) + if ((!isNil {_vehicle getHit _selectionName}) && {_x != ""}) then { + _realHitpointCount = _realHitpointCount + 1; + + if ((!(_x in IGNORED_HITPOINTS)) && {!isText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints" >> _x >> "depends")}) then { + _hitPointDamageSumOld = _hitPointDamageSumOld + (_allHitPointDamages select _forEachIndex); + if (_forEachIndex == _hitPointIndex) then { + _hitPointDamageRepaired = (_allHitPointDamages select _forEachIndex) - _hitPointDamage; + }; + }; }; -} forEach _hitPointsWithSelections; +} forEach _allHitPoints; -// set new damage in array -_hitPointDamages set [_hitPoints find _hitPoint, _hitPointDamage]; - -// save sum of new hitpoint damages -private "_hitPointDamageSumNew"; - -_hitPointDamageSumNew = 0; -{ - if (!(_x in IGNORED_HITPOINTS) && {!isText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints" >> _x >> "depends")}) then { - _hitPointDamageSumNew = _hitPointDamageSumNew + (_hitPointDamages select (_hitPoints find _x)); - }; -} forEach _hitPointsWithSelections; - -// calculate new strctural damage -private "_damageNew"; -_damageNew = _hitPointDamageSumNew / count _hitPoints; +// calculate new structural damage +_damageNew = (_hitPointDamageSumOld - _hitPointDamageRepaired) / _realHitpointCount; if (_hitPointDamageSumOld > 0) then { - _damageNew = _damageOld * (_hitPointDamageSumNew / _hitPointDamageSumOld); + _damageNew = _damageOld * ((_hitPointDamageSumOld - _hitPointDamageRepaired) / _hitPointDamageSumOld); }; +TRACE_5("structuralDamage",_damageOld,_damageNew,_hitPointDamageRepaired,_hitPointDamageSumOld,_realHitpointCount); // set new structural damage value _vehicle setDamage _damageNew; -// set the new damage for that hit point +//Repair the hitpoint in the damages array: +_allHitPointDamages set [_hitPointIndex, _hitPointDamage]; +//Set the new damage for all hitpoints { - _vehicle setHitPointDamage [_x, _hitPointDamages select _forEachIndex]; -} forEach _hitPoints; + _vehicle setHitIndex [_forEachIndex, _x]; +} forEach _allHitPointDamages; // normalize hitpoints // [_vehicle] call FUNC(normalizeHitPoints); diff --git a/addons/repair/functions/fnc_spawnObject.sqf b/addons/repair/functions/fnc_spawnObject.sqf index 1ea4b7363a..9c092d9c3a 100644 --- a/addons/repair/functions/fnc_spawnObject.sqf +++ b/addons/repair/functions/fnc_spawnObject.sqf @@ -4,7 +4,7 @@ * * Arguments: * 0: Item classname - * 1: Position + * 1: Position ASL * 2: Damage * * Return Value: diff --git a/addons/repair/functions/fnc_useItem.sqf b/addons/repair/functions/fnc_useItem.sqf index 218a7a1ee4..72619657a2 100644 --- a/addons/repair/functions/fnc_useItem.sqf +++ b/addons/repair/functions/fnc_useItem.sqf @@ -4,10 +4,10 @@ * * Arguments: * 0: Unit - * 2: Item classname + * 1: Item classname * * ReturnValue: - * None + * [Had Item to Use , Unit ] * * Example: * [unit, "classname"] call ace_repair_fnc_useItem @@ -23,4 +23,5 @@ if ([_unit, _item] call EFUNC(common,hasItem)) exitwith { [[_unit, _item], QUOTE(EFUNC(common,useItem)), _unit] call EFUNC(common,execRemoteFnc); /* TODO Replace by event system */ [true, _unit]; }; + [false, objNull]; diff --git a/addons/repair/functions/fnc_useItems.sqf b/addons/repair/functions/fnc_useItems.sqf index f8aa176018..5e5cba0063 100644 --- a/addons/repair/functions/fnc_useItems.sqf +++ b/addons/repair/functions/fnc_useItems.sqf @@ -7,7 +7,7 @@ * 1: Item classnames * * ReturnValue: - * None + * [Had Item to Use , Array of units that used the items ] * * Example: * [unit, ["classname1", "classname2"]] call ace_repair_fnc_useItems From 839c022b8408c74f8b7a2bcf81599c5d6bb03c68 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Wed, 28 Oct 2015 22:29:11 +0000 Subject: [PATCH 2/3] Fix broken repair point selection code Only valid hit selection + hit point combinations are usable for repair points: - Empty hit points mean there isn't enough information to display to the user - Empty hit selections mean that the hit point doesn't actually exist --- .../repair/functions/fnc_addRepairActions.sqf | 167 +++++++----------- 1 file changed, 68 insertions(+), 99 deletions(-) diff --git a/addons/repair/functions/fnc_addRepairActions.sqf b/addons/repair/functions/fnc_addRepairActions.sqf index 23a359efdd..b7be5690c8 100644 --- a/addons/repair/functions/fnc_addRepairActions.sqf +++ b/addons/repair/functions/fnc_addRepairActions.sqf @@ -1,5 +1,5 @@ /* - * Author: commy2 + * Author: commy2, SilentSpike * Checks if the vehicles class already has the actions initialized, otherwise add all available repair options. Calleed from init EH. * * Arguments: @@ -19,7 +19,7 @@ params ["_vehicle"]; TRACE_1("params", _vehicle); -private ["_type", "_initializedClasses", "_condition", "_statement", "_action", "_duplicateHitpointName", "_processedHitPoints", "_selectionName", "_hitPointsAddedNames", "_hitPointsAddedStrings", "_hitPointsAddedAmount"]; +private ["_type", "_initializedClasses", "_condition", "_statement", "_action", "_processedHitPoints", "_hitPointsAddedNames", "_hitPointsAddedStrings", "_hitPointsAddedAmount"]; _type = typeOf _vehicle; @@ -29,154 +29,123 @@ _initializedClasses = GETMVAR(GVAR(initializedClasses),[]); if (_type in _initializedClasses) exitWith {}; // get all hitpoints and selections -(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitPointsSelections", []]]; +(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitSelections", []]]; -if (_hitPoints isEqualTo []) exitWith {ACE_LOGERROR_1("No Hitpoints on %1", _type);}; +if (_hitSelections isEqualTo []) exitWith { ACE_LOGERROR_1("No hit selections (%1)", _type); }; // get hitpoints of wheels with their selections -([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitPointSelections"]; +([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"]; _hitPointsAddedNames = []; _hitPointsAddedStrings = []; _hitPointsAddedAmount = []; +_processedHitpoints = []; -_processedHitPoints = []; - -// add repair events to this vehicle class { - _duplicateHitpointName = (_x in _processedHitPoints); - _processedHitPoints pushBack _x; - _selectionName = _hitPointsSelections select _forEachIndex; + _selection = _x; + _hitpoint = _hitPoints select _forEachIndex; - if (_x in _wheelHitPoints) then { - // add wheel repair action + if (_selection in _wheelHitSelections) then { + // Wheels should always be unique + if (_hitpoint in _processedHitpoints) exitWith {TRACE_3("Duplicate Wheel",_hitpoint,_forEachIndex,_selection);}; - if (_duplicateHitpointName) exitWith {TRACE_3("Duplicate Wheel",_x,_forEachIndex,_selectionName);}; //Wheels should always be unique - if (isNil {_vehicle getHit _selectionName}) exitWith {TRACE_3("No Selection",_x,_forEachIndex,_selectionName);}; //Not a real hitpoint - - private ["_icon", "_selection", "_name", "_text"]; - - // _icon = QUOTE(PATHTOF(ui\tire_ca.paa)); _icon = "A3\ui_f\data\igui\cfg\actions\repair_ca.paa"; - _selection = _wheelHitPointSelections select (_wheelHitPoints find _x); - // remove wheel action - _name = format ["Remove_%1_%2", _forEachIndex, _x]; + // An action to remove the wheel is required + _name = format ["Remove_%1_%2", _forEachIndex, _hitpoint]; _text = localize LSTRING(RemoveWheel); - - TRACE_5("Adding Wheel Actions",_name,_forEachIndex,_selectionName,_text,_selection); - + TRACE_4("Adding Wheel Actions",_name,_forEachIndex,_selection,_text); _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)}; - - _action = [_name, _text, _icon, _statement, _condition, {}, [_x], _selection, 2] call EFUNC(interact_menu,createAction); + _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _selection, 2] call EFUNC(interact_menu,createAction); [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); - // replace wheel action - _name = format ["Replace_%1_%2", _forEachIndex, _x]; + // An action to replace the wheel is required + _name = format ["Replace_%1_%2", _forEachIndex, _selection]; _text = localize LSTRING(ReplaceWheel); - _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)}; - - _action = [_name, _text, _icon, _statement, _condition, {}, [_x], _selection, 2] call EFUNC(interact_menu,createAction); + _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _selection, 2] call EFUNC(interact_menu,createAction); [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); - } else { - // exit if the hitpoint is in the blacklist, e.g. glasses - if (_x in IGNORED_HITPOINTS) exitWith {TRACE_3("Ignored Hitpoint",_x,_forEachIndex,_selectionName);}; - if (_x == "") exitWith {TRACE_3("Hitpoint Empty",_x,_forEachIndex,_selectionName);}; - if (isNil {_vehicle getHit _selectionName}) exitWith {TRACE_3("No Selection",_x,_forEachIndex,_selectionName);}; //Not a real hitpoint + // Empty selections don't exist + // Empty hitpoints don't contain enough information + if (_selection isEqualTo "") exitWith {}; + if (_hitpoint isEqualTo "") exitWith {}; - private ["_hitpointGroupConfig", "_inHitpointSubGroup", "_currentHitpoint"]; - - // Get hitpoint groups if available - _hitpointGroupConfig = configFile >> "CfgVehicles" >> _type >> QGVAR(hitpointGroups); - _inHitpointSubGroup = false; - if (isArray _hitpointGroupConfig) then { - // Set variable if current hitpoint is in a sub-group (to be excluded from adding action) - _currentHitpoint = _x; + // 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; { { - if (_x == _currentHitpoint) exitWith { - _inHitpointSubGroup = true; + if (_hitpoint == _x) exitWith { + _childHitPoint = true; }; } forEach (_x select 1); - } forEach (getArray _hitpointGroupConfig); + } forEach (getArray _groupsConfig); + }; + // 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 { + { + _x params ["_hit", "_pos"]; + if (_hitpoint == _hit) exitWith { + if (typeName _pos == "ARRAY") exitWith { + _position = _pos; // Position in model space + }; + if (typeName _pos == "STRING") exitWith { + _position = _vehicle selectionPosition [_pos,"HitPoints"]; // Selection name + }; + ACE_LOGERROR_3("Invalid custom position %1 of hitpoint %2 in vehicle %3.",_position,_hitpoint,_type); + }; + } forEach (getArray _positionsConfig); }; - // Exit if current hitpoint is in sub-group (only main hitpoints get actions) - if (_inHitpointSubGroup) exitWith {TRACE_3("inHitpointSubGroup",_x,_forEachIndex,_selectionName);}; - - // exit if the hitpoint is virtual - if (isText (configFile >> "CfgVehicles" >> _type >> "HitPoints" >> _x >> "depends")) exitWith {TRACE_3("Depends",_x,_forEachIndex,_selectionName);}; - - // add misc repair action - private ["_name", "_icon", "_selection", "_customSelectionsConfig"]; - - _name = format ["Repair_%1_%2", _forEachIndex, _x]; + // Prepair the repair action + _name = format ["Repair_%1_%2", _forEachIndex, _selection]; + _icon = "A3\ui_f\data\igui\cfg\actions\repair_ca.paa"; // Find localized string and track those added for numerization - ([_x, "%1", _x, [_hitPointsAddedNames, _hitPointsAddedStrings, _hitPointsAddedAmount]] call FUNC(getHitPointString)) params ["_text", "_trackArray"]; + ([_hitpoint, "%1", _hitpoint, [_hitPointsAddedNames, _hitPointsAddedStrings, _hitPointsAddedAmount]] call FUNC(getHitPointString)) params ["_text", "_trackArray"]; _hitPointsAddedNames = _trackArray select 0; _hitPointsAddedStrings = _trackArray select 1; _hitPointsAddedAmount = _trackArray select 2; - _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 - }; - ACE_LOGERROR_3("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 _selectionName; - }; - - if (_x in TRACK_HITPOINTS) then { - if (_duplicateHitpointName) exitWith {TRACE_3("Duplicate Track",_x,_forEachIndex,_selectionName);}; //Tracks should always be unique - if (_x == "HitLTrack") then { - _selection = [-1.75, 0, -1.75]; + 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]; } else { - _selection = [1.75, 0, -1.75]; + _position = [1.75, 0, -1.75]; }; - TRACE_5("Adding RepairTrack",_name,_forEachIndex,_selectionName,_text,_selection); + TRACE_5("Adding RepairTrack",_name,_forEachIndex,_selection,_text,_position); _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)}; - _action = [_name, _text, _icon, _statement, _condition, {}, [_x], _selection, 4] call EFUNC(interact_menu,createAction); + _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 4] call EFUNC(interact_menu,createAction); [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); } else { - TRACE_5("Adding MiscRepair",_name,_forEachIndex,_selectionName,_text,_selection); + TRACE_5("Adding MiscRepair",_name,_forEachIndex,_selection,_text,_position); _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)}; - _action = [_name, _text, _icon, _statement, _condition, {}, [_forEachIndex], _selection, 5] call EFUNC(interact_menu,createAction); + _action = [_name, _text, _icon, _statement, _condition, {}, [_forEachIndex], _position, 5] call EFUNC(interact_menu,createAction); // Put inside main actions if no other position was found above - if (_selection isEqualTo [0, 0, 0]) then { + if (_position 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); }; }; + + _processedHitPoints pushBack _hitPoint; }; -} forEach _hitPoints; +} forEach _hitSelections; _condition = {[_this select 1, _this select 0, "", "fullRepair"] call DFUNC(canRepair)}; _statement = {[_this select 1, _this select 0, "", "fullRepair"] call DFUNC(repair)}; From ab769757d973d7708dd01796418c59efcd704ea8 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Mon, 9 Nov 2015 20:11:48 -0600 Subject: [PATCH 3/3] Skip Depends Hitpoints - Use HitPoints selPos for wheels Stuff Normalize Depends - Skip Glass Repair Fix spawned wheel/track not having correct damage getHitpointString robustness, hatchback fuelHitpoint, fix count errors - Formatting local -> private Fix Stuff --- addons/common/functions/fnc_isEngineer.sqf | 2 +- addons/repair/CfgVehicles.hpp | 2 +- .../repair/functions/fnc_addRepairActions.sqf | 45 ++++++++++------ addons/repair/functions/fnc_canRepair.sqf | 40 +++++++-------- addons/repair/functions/fnc_doRemoveTrack.sqf | 12 ++--- addons/repair/functions/fnc_doRemoveWheel.sqf | 10 ++-- addons/repair/functions/fnc_doRepair.sqf | 20 ++++---- addons/repair/functions/fnc_doRepairTrack.sqf | 4 +- .../repair/functions/fnc_doReplaceTrack.sqf | 4 +- .../repair/functions/fnc_doReplaceWheel.sqf | 4 +- .../repair/functions/fnc_getClaimObjects.sqf | 11 ++-- .../functions/fnc_getHitPointString.sqf | 8 +-- .../functions/fnc_getPostRepairDamage.sqf | 2 +- addons/repair/functions/fnc_hasItems.sqf | 4 +- .../functions/fnc_isInRepairFacility.sqf | 4 +- .../functions/fnc_isNearRepairVehicle.sqf | 2 +- .../repair/functions/fnc_isRepairVehicle.sqf | 2 +- .../functions/fnc_moduleAddSpareParts.sqf | 1 + .../functions/fnc_normalizeHitPoints.sqf | 42 +++++++++------ addons/repair/functions/fnc_repair.sqf | 51 ++++++++++--------- .../functions/fnc_setHitPointDamage.sqf | 8 +-- addons/repair/functions/fnc_spawnObject.sqf | 14 ++--- addons/repair/functions/fnc_useItem.sqf | 2 +- addons/repair/functions/fnc_useItems.sqf | 4 +- addons/repair/script_component.hpp | 2 - 25 files changed, 163 insertions(+), 137 deletions(-) diff --git a/addons/common/functions/fnc_isEngineer.sqf b/addons/common/functions/fnc_isEngineer.sqf index 738b77e6a3..a3c9191c4f 100644 --- a/addons/common/functions/fnc_isEngineer.sqf +++ b/addons/common/functions/fnc_isEngineer.sqf @@ -17,7 +17,7 @@ params ["_unit"]; -local _isEngineer = _unit getVariable ["ACE_isEngineer", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "engineer") == 1]; +private _isEngineer = _unit getVariable ["ACE_isEngineer", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "engineer") == 1]; //Handle ace_repair modules setting this to a number if ((typeName _isEngineer) == "SCALAR") then {_isEngineer = _isEngineer > 0}; diff --git a/addons/repair/CfgVehicles.hpp b/addons/repair/CfgVehicles.hpp index ea15256bf3..3736050543 100644 --- a/addons/repair/CfgVehicles.hpp +++ b/addons/repair/CfgVehicles.hpp @@ -405,6 +405,6 @@ class CfgVehicles { GVAR(hitpointPositions[]) = { {"HitEngine", {0, 0.5, -0.7}}, {"HitFuel", {0, 0, -0.5}} }; }; class Hatchback_01_base_F: Car_F { - GVAR(hitpointPositions[]) = {{"HitBody", {0, 0.7, -0.5}}}; + GVAR(hitpointPositions[]) = {{"HitBody", {0, 0.7, -0.5}}, {"HitFuel", {0, -1.75, -0.75}}}; }; }; diff --git a/addons/repair/functions/fnc_addRepairActions.sqf b/addons/repair/functions/fnc_addRepairActions.sqf index b7be5690c8..3887d9eff7 100644 --- a/addons/repair/functions/fnc_addRepairActions.sqf +++ b/addons/repair/functions/fnc_addRepairActions.sqf @@ -13,13 +13,14 @@ * * Public: No */ - #include "script_component.hpp" -params ["_vehicle"]; -TRACE_1("params", _vehicle); +if (!hasInterface) exitWith {}; -private ["_type", "_initializedClasses", "_condition", "_statement", "_action", "_processedHitPoints", "_hitPointsAddedNames", "_hitPointsAddedStrings", "_hitPointsAddedAmount"]; +params ["_vehicle"]; +TRACE_2("params", _vehicle,typeOf _vehicle); + +private["_action", "_childHitPoint", "_condition", "_groupsConfig", "_hitPoint", "_hitPointsAddedAmount", "_hitPointsAddedNames", "_hitPointsAddedStrings", "_icon", "_initializedClasses", "_name", "_position", "_positionsConfig", "_processedHitPoints", "_selection", "_statement", "_target", "_type"]; _type = typeOf _vehicle; @@ -46,37 +47,48 @@ _processedHitpoints = []; _hitpoint = _hitPoints select _forEachIndex; if (_selection in _wheelHitSelections) then { - // Wheels should always be unique + // Wheels should always be unique if (_hitpoint in _processedHitpoints) exitWith {TRACE_3("Duplicate Wheel",_hitpoint,_forEachIndex,_selection);}; _icon = "A3\ui_f\data\igui\cfg\actions\repair_ca.paa"; + _position = compile format ["_target selectionPosition ['%1', 'HitPoints'];", _selection]; + + TRACE_3("Adding Wheel Actions",_hitpoint,_forEachIndex,_selection); + // An action to remove the wheel is required _name = format ["Remove_%1_%2", _forEachIndex, _hitpoint]; _text = localize LSTRING(RemoveWheel); - TRACE_4("Adding Wheel Actions",_name,_forEachIndex,_selection,_text); _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)}; - _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _selection, 2] call EFUNC(interact_menu,createAction); + _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction); [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); // An action to replace the wheel is required - _name = format ["Replace_%1_%2", _forEachIndex, _selection]; + _name = format ["Replace_%1_%2", _forEachIndex, _hitpoint]; _text = localize LSTRING(ReplaceWheel); _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)}; - _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _selection, 2] call EFUNC(interact_menu,createAction); + _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction); [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); } else { + //Skip glass hitpoints + if (((toLower _hitPoint) find "glass") != -1) exitWith { + TRACE_3("Skipping Glass",_hitpoint,_forEachIndex,_selection); + }; // Empty selections don't exist // Empty hitpoints don't contain enough information - if (_selection isEqualTo "") exitWith {}; - if (_hitpoint isEqualTo "") exitWith {}; + if (_selection isEqualTo "") exitWith { TRACE_3("Selection Empty",_hitpoint,_forEachIndex,_selection); }; + if (_hitpoint isEqualTo "") exitWith { TRACE_3("Hitpoint Empty",_hitpoint,_forEachIndex,_selection); }; + //Depends hitpoints shouldn't be modified directly (will be normalized) + if (isText (configFile >> "CfgVehicles" >> _type >> "HitPoints" >> _hitpoint >> "depends")) exitWith { + TRACE_3("Skip Depends",_hitpoint,_forEachIndex,_selection); + }; // Associated hitpoints can be grouped via config to produce a single repair action _groupsConfig = configFile >> "CfgVehicles" >> _type >> QGVAR(hitpointGroups); + _childHitPoint = false; if (isArray _groupsConfig) then { - _childHitPoint = false; { { if (_hitpoint == _x) exitWith { @@ -89,7 +101,8 @@ _processedHitpoints = []; if (_childHitPoint) exitWith { TRACE_3("childHitpoint",_hitpoint,_forEachIndex,_selection); }; // Find the action position - _position = _vehicle selectionPosition [_selection,"HitPoints"]; + _position = compile format ["_target selectionPosition ['%1', 'HitPoints'];", _selection]; + // Custom position can be defined via config for associated hitpoint _positionsConfig = configFile >> "CfgVehicles" >> _type >> QGVAR(hitpointPositions); if (isArray _positionsConfig) then { @@ -100,7 +113,7 @@ _processedHitpoints = []; _position = _pos; // Position in model space }; if (typeName _pos == "STRING") exitWith { - _position = _vehicle selectionPosition [_pos,"HitPoints"]; // Selection name + _position = compile format ["_target selectionPosition ['%1', 'HitPoints'];", _pos]; }; ACE_LOGERROR_3("Invalid custom position %1 of hitpoint %2 in vehicle %3.",_position,_hitpoint,_type); }; @@ -125,13 +138,13 @@ _processedHitpoints = []; } else { _position = [1.75, 0, -1.75]; }; - TRACE_5("Adding RepairTrack",_name,_forEachIndex,_selection,_text,_position); + TRACE_4("Adding RepairTrack",_hitpoint,_forEachIndex,_selection,_text); _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)}; _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 4] call EFUNC(interact_menu,createAction); [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); } else { - TRACE_5("Adding MiscRepair",_name,_forEachIndex,_selection,_text,_position); + TRACE_4("Adding MiscRepair",_hitpoint,_forEachIndex,_selection,_text); _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)}; _action = [_name, _text, _icon, _statement, _condition, {}, [_forEachIndex], _position, 5] call EFUNC(interact_menu,createAction); diff --git a/addons/repair/functions/fnc_canRepair.sqf b/addons/repair/functions/fnc_canRepair.sqf index 6ba7b6b23a..74a4b07dc6 100644 --- a/addons/repair/functions/fnc_canRepair.sqf +++ b/addons/repair/functions/fnc_canRepair.sqf @@ -21,22 +21,22 @@ params ["_caller", "_target", "_hitPoint", "_className"]; TRACE_4("params",_caller,_target,_hitPoint,_className); -private ["_config", "_engineerRequired", "_items", "_locations", "_return", "_condition", "_vehicleStateCondition", "_settingName", "_settingItemsArray"]; +private ["_config", "_engineerRequired", "_items", "_return", "_condition", "_vehicleStateCondition", "_settingName", "_settingItemsArray"]; _config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className); -if !(isClass _config) exitwith {false}; // or go for a default? -if(isEngineOn _target) exitwith {false}; +if !(isClass _config) exitWith {false}; // or go for a default? +if(isEngineOn _target) exitWith {false}; _engineerRequired = if (isNumber (_config >> "requiredEngineer")) then { getNumber (_config >> "requiredEngineer"); } else { // Check for required class - if (isText (_config >> "requiredEngineer")) exitwith { + if (isText (_config >> "requiredEngineer")) exitWith { missionNamespace getVariable [(getText (_config >> "requiredEngineer")), 0]; }; 0; }; -if !([_caller, _engineerRequired] call FUNC(isEngineer)) exitwith {false}; +if !([_caller, _engineerRequired] call FUNC(isEngineer)) exitWith {false}; //Items can be an array of required items or a string to a ACE_Setting array _items = if (isArray (_config >> "items")) then { @@ -49,12 +49,12 @@ _items = if (isArray (_config >> "items")) then { }; _settingItemsArray select (missionNamespace getVariable _settingName); }; -if (count _items > 0 && {!([_caller, _items] call FUNC(hasItems))}) exitwith {false}; +if (count _items > 0 && {!([_caller, _items] call FUNC(hasItems))}) exitWith {false}; _return = true; if (getText (_config >> "condition") != "") then { _condition = getText (_config >> "condition"); - if (isnil _condition) then { + if (isNil _condition) then { _condition = compile _condition; } else { _condition = missionNamespace getVariable _condition; @@ -66,25 +66,25 @@ if (getText (_config >> "condition") != "") then { }; }; -if (!_return) exitwith {false}; +if (!_return) exitWith {false}; // _vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then { // missionNamespace getVariable [getText(_config >> "vehicleStateCondition"), 0] // } else { // getNumber(_config >> "vehicleStateCondition") // }; -// if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitwith {false}; +// if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitWith {false}; -local _repairLocations = getArray (_config >> "repairLocations"); +private _repairLocations = getArray (_config >> "repairLocations"); if (!("All" in _repairLocations)) then { - local _repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))}; - local _repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))}; + private _repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))}; + private _repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))}; { - if (_x == "field") exitwith {_return = true;}; - if (_x == "RepairFacility" && _repairFacility) exitwith {_return = true;}; - if (_x == "RepairVehicle" && _repairVeh) exitwith {_return = true;}; - if !(isnil _x) exitwith { - local _val = missionNamespace getVariable _x; + if (_x == "field") exitWith {_return = true;}; + if (_x == "RepairFacility" && _repairFacility) exitWith {_return = true;}; + if (_x == "RepairVehicle" && _repairVeh) exitWith {_return = true;}; + if !(isNil _x) exitWith { + private _val = missionNamespace getVariable _x; if (typeName _val == "SCALAR") then { _return = switch (_val) do { case 0: {true}; //useAnywhere @@ -97,12 +97,12 @@ if (!("All" in _repairLocations)) then { }; } forEach _repairLocations; }; -if (!_return) exitwith {false}; +if (!_return) exitWith {false}; //Check that there are required objects nearby -local _requiredObjects = getArray (_config >> "claimObjects"); +private _requiredObjects = getArray (_config >> "claimObjects"); if (!(_requiredObjects isEqualTo [])) then { - local _objectsAvailable = [_caller, 5, _requiredObjects] call FUNC(getClaimObjects); + private _objectsAvailable = [_caller, 5, _requiredObjects] call FUNC(getClaimObjects); if (_objectsAvailable isEqualTo []) then { TRACE_2("Missing Required Objects",_requiredObjects,_objectsAvailable); _return = false diff --git a/addons/repair/functions/fnc_doRemoveTrack.sqf b/addons/repair/functions/fnc_doRemoveTrack.sqf index 68755658ca..d36407b197 100644 --- a/addons/repair/functions/fnc_doRemoveTrack.sqf +++ b/addons/repair/functions/fnc_doRemoveTrack.sqf @@ -19,10 +19,9 @@ params ["_unit", "_vehicle", "_hitPoint"]; TRACE_3("params",_unit,_vehicle,_hitPoint); -// TODO [_unit, _wheel] call EFUNC(common,claim); on start of action + // get current hitpoint damage -private "_hitPointDamage"; -_hitPointDamage = _vehicle getHitPointDamage _hitPoint; +private _hitPointDamage = _vehicle getHitPointDamage _hitPoint; // can't remove destroyed or already removed wheel if (_hitPointDamage >= 1) exitWith {}; @@ -30,10 +29,9 @@ if (_hitPointDamage >= 1) exitWith {}; // don't die by spawning / moving the wheel ["fixCollision", _unit] call EFUNC(common,localEvent); -// spawn wheel -private "_wheel"; -_wheel = ["ACE_Track", getPosASL _unit] call FUNC(spawnObject); -_wheel setdamage _hitPointDamage; +// spawn track +private _newTrack = ["ACE_Track", getPosASL _unit, _hitPointDamage] call FUNC(spawnObject); +TRACE_2("new track created",_newTrack,damage _newTrack); // raise event to set the new hitpoint damage ["setWheelHitPointDamage", _vehicle, [_vehicle, _hitPoint, 1]] call EFUNC(common,targetEvent); diff --git a/addons/repair/functions/fnc_doRemoveWheel.sqf b/addons/repair/functions/fnc_doRemoveWheel.sqf index 0ffeb7ad23..21a152c597 100644 --- a/addons/repair/functions/fnc_doRemoveWheel.sqf +++ b/addons/repair/functions/fnc_doRemoveWheel.sqf @@ -19,10 +19,9 @@ params ["_unit", "_vehicle", "_hitPoint"]; TRACE_3("params",_unit,_vehicle,_hitPoint); -// TODO [_unit, _wheel] call EFUNC(common,claim); on start of action + // get current hitpoint damage -private "_hitPointDamage"; -_hitPointDamage = _vehicle getHitPointDamage _hitPoint; +private _hitPointDamage = _vehicle getHitPointDamage _hitPoint; // can't remove destroyed or already removed wheel if (_hitPointDamage >= 1) exitWith {}; @@ -31,9 +30,8 @@ if (_hitPointDamage >= 1) exitWith {}; ["fixCollision", _unit] call EFUNC(common,localEvent); // spawn wheel -private "_wheel"; -_wheel = ["ACE_Wheel", getPosASL _unit] call FUNC(spawnObject); -_wheel setdamage _hitPointDamage; +private _newWheel = ["ACE_Wheel", getPosASL _unit, _hitPointDamage] call FUNC(spawnObject); +TRACE_2("new wheel created",_newWheel,damage _newWheel); // raise event to set the new hitpoint damage ["setWheelHitPointDamage", _vehicle, [_vehicle, _hitPoint, 1]] call EFUNC(common,targetEvent); diff --git a/addons/repair/functions/fnc_doRepair.sqf b/addons/repair/functions/fnc_doRepair.sqf index 014adf8af4..4c063c6c73 100644 --- a/addons/repair/functions/fnc_doRepair.sqf +++ b/addons/repair/functions/fnc_doRepair.sqf @@ -20,16 +20,16 @@ params ["_unit", "_vehicle", "_hitPointIndex"]; TRACE_3("params",_unit,_vehicle,_hitPointIndex); -local _postRepairDamageMin = [_unit] call FUNC(getPostRepairDamage); +private _postRepairDamageMin = [_unit] call FUNC(getPostRepairDamage); (getAllHitPointsDamage _vehicle) params ["_allHitPoints"]; -local _hitPointClassname = _allHitPoints select _hitPointIndex; +private _hitPointClassname = _allHitPoints select _hitPointIndex; // get current hitpoint damage -local _hitPointCurDamage = _vehicle getHitIndex _hitPointIndex; +private _hitPointCurDamage = _vehicle getHitIndex _hitPointIndex; // repair a max of 0.5, don't use negative values for damage -local _hitPointNewDamage = (_hitPointCurDamage - 0.5) max _postRepairDamageMin; +private _hitPointNewDamage = (_hitPointCurDamage - 0.5) max _postRepairDamageMin; if (_hitPointNewDamage < _hitPointCurDamage) then { // raise event to set the new hitpoint damage @@ -39,7 +39,7 @@ if (_hitPointNewDamage < _hitPointCurDamage) then { }; // Get hitpoint groups if available -local _hitpointGroupConfig = configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(hitpointGroups); +private _hitpointGroupConfig = configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(hitpointGroups); if (isArray _hitpointGroupConfig) then { // Retrieve hitpoint subgroup if current hitpoint is main hitpoint of a group { @@ -47,12 +47,12 @@ if (isArray _hitpointGroupConfig) then { // Exit using found hitpoint group if this hitpoint is leader of any if (_masterHitpoint == _hitPointClassname) exitWith { { - local _subHitIndex = _allHitPoints find _x; //convert hitpoint classname to index + private _subHitIndex = _allHitPoints find _x; //convert hitpoint classname to index if (_subHitIndex == -1) then { ACE_LOGERROR_2("Invalid hitpoint %1 in hitpointGroups of %2",_x,_vehicle); } else { - local _subPointCurDamage = _vehicle getHitIndex _hitPointIndex; - local _subPointNewDamage = (_subPointCurDamage - 0.5) max _postRepairDamageMin; + private _subPointCurDamage = _vehicle getHitIndex _hitPointIndex; + private _subPointNewDamage = (_subPointCurDamage - 0.5) max _postRepairDamageMin; if (_subPointNewDamage < _subPointCurDamage) then { TRACE_3("repairing sub point", _vehicle, _subHitIndex, _subPointNewDamage); ["setVehicleHitPointDamage", _vehicle, [_vehicle, _subHitIndex, _subPointNewDamage]] call EFUNC(common,targetEvent); @@ -66,8 +66,8 @@ if (isArray _hitpointGroupConfig) then { // display text message if enabled if (GVAR(DisplayTextOnRepair)) then { // Find localized string - local _textLocalized = localize ([LSTRING(RepairedHitPointFully), LSTRING(RepairedHitPointPartially)] select (_hitPointCurDamage > 0)); - local _textDefault = localize ([LSTRING(RepairedFully), LSTRING(RepairedPartially)] select (_hitPointCurDamage > 0)); + private _textLocalized = localize ([LSTRING(RepairedHitPointFully), LSTRING(RepairedHitPointPartially)] select (_hitPointCurDamage > 0)); + private _textDefault = localize ([LSTRING(RepairedFully), LSTRING(RepairedPartially)] select (_hitPointCurDamage > 0)); ([_hitPointClassname, _textLocalized, _textDefault] call FUNC(getHitPointString)) params ["_text"]; // Display text diff --git a/addons/repair/functions/fnc_doRepairTrack.sqf b/addons/repair/functions/fnc_doRepairTrack.sqf index cde22f3dd7..46c94c29f9 100644 --- a/addons/repair/functions/fnc_doRepairTrack.sqf +++ b/addons/repair/functions/fnc_doRepairTrack.sqf @@ -33,8 +33,8 @@ if ((isNull _track) || {!([_unit, _track, ["isNotDragging", "isNotCarrying", "is if ((damage _track) >= 1) exitWith {}; // get current hitpoint damage -local _hitPointDamage = _vehicle getHitPointDamage _hitPoint; -local _damageRepaired = (1 - (damage _track)) / 4; // require 4 tracks to fully replace one side +private _hitPointDamage = _vehicle getHitPointDamage _hitPoint; +private _damageRepaired = (1 - (damage _track)) / 4; // require 4 tracks to fully replace one side // don't die by spawning / moving the wheel _hitPointDamage = (_hitPointDamage - _damageRepaired) min 0; diff --git a/addons/repair/functions/fnc_doReplaceTrack.sqf b/addons/repair/functions/fnc_doReplaceTrack.sqf index 75f7f70723..9eafe68c9e 100644 --- a/addons/repair/functions/fnc_doReplaceTrack.sqf +++ b/addons/repair/functions/fnc_doReplaceTrack.sqf @@ -30,13 +30,13 @@ if ((isNull _track) || {!([_unit, _track, ["isNotDragging", "isNotCarrying", "is }; // get current hitpoint damage -local _hitPointDamage = _vehicle getHitPointDamage _hitPoint; +private _hitPointDamage = _vehicle getHitPointDamage _hitPoint; // can't replace not destroyed wheel if (_hitPointDamage < 1) exitWith {}; // get track's damage -local _newHitPointDamage = damage _track; +private _newHitPointDamage = damage _track; // can't replace with a destroyed wheel if (_newHitPointDamage >= 1) exitWith {}; diff --git a/addons/repair/functions/fnc_doReplaceWheel.sqf b/addons/repair/functions/fnc_doReplaceWheel.sqf index 20bcfe95a3..ce5e9220dd 100644 --- a/addons/repair/functions/fnc_doReplaceWheel.sqf +++ b/addons/repair/functions/fnc_doReplaceWheel.sqf @@ -30,13 +30,13 @@ if ((isNull _wheel) || {!([_unit, _wheel, ["isNotDragging", "isNotCarrying", "is }; // get current hitpoint damage -local _hitPointDamage = _vehicle getHitPointDamage _hitPoint; +private _hitPointDamage = _vehicle getHitPointDamage _hitPoint; // can't replace not destroyed wheel if (_hitPointDamage < 1) exitWith {}; // get replacement wheel's damage -local _newHitPointDamage = damage _wheel; +private _newHitPointDamage = damage _wheel; // can't replace a destroyed wheel if (_newHitPointDamage >= 1) exitWith {}; diff --git a/addons/repair/functions/fnc_getClaimObjects.sqf b/addons/repair/functions/fnc_getClaimObjects.sqf index 01229f0c9f..bc15975d1c 100644 --- a/addons/repair/functions/fnc_getClaimObjects.sqf +++ b/addons/repair/functions/fnc_getClaimObjects.sqf @@ -20,14 +20,14 @@ params ["_unit", "_maxRange", "_objectsToClaim"]; TRACE_3("params",_unit,_maxRange,_objectsToClaim); -local _return = []; +private _return = []; { - local _requiredList = _x; //eg ["ace_track", "ace_track"] - local _ableToAquire = []; //will be array of ojbects + private _requiredList = _x; //eg ["ace_track", "ace_track"] + private _ableToAquire = []; //will be array of ojbects { - local _nearObjects = nearestObjects [_unit, [_x], _maxRange]; - local _canClaimObject = objNull; + private _nearObjects = nearestObjects [_unit, [_x], _maxRange]; + private _canClaimObject = objNull; { if ((!(_x in _ableToAquire)) && {[_unit, _x, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)} @@ -39,6 +39,7 @@ local _return = []; } forEach _x; TRACE_2("Check required equals available",_requiredList,_ableToAquire); if ((count _ableToAquire) == (count _requiredList)) exitWith {_return = _ableToAquire}; + false } count _objectsToClaim; _return diff --git a/addons/repair/functions/fnc_getHitPointString.sqf b/addons/repair/functions/fnc_getHitPointString.sqf index 1358e99595..fd108e4b1f 100644 --- a/addons/repair/functions/fnc_getHitPointString.sqf +++ b/addons/repair/functions/fnc_getHitPointString.sqf @@ -13,15 +13,16 @@ * 1: Added Hitpoint (default: []) * * Example: - * [unit, vehicle, "hitpoint"] call ace_repair_fnc_getHitPointString + * ["HitFuel", "Repairing %1 ...", "Repairing HitFuel"] call ace_repair_fnc_getHitPointString * * Public: No */ #include "script_component.hpp" -private ["_track", "_trackNames", "_trackStrings", "_trackAmount", "_text", "_toFind", "_trackIndex", "_combinedString"]; params ["_hitPoint", "_textLocalized", "_textDefault", ["_trackArray", []]]; +private ["_track", "_trackNames", "_trackStrings", "_trackAmount", "_text", "_toFind", "_trackIndex", "_combinedString"]; + _track = if (count _trackArray > 0) then {true} else {false}; _trackNames = []; _trackStrings = []; @@ -37,7 +38,7 @@ if (_track) then { _text = LSTRING(Hit); // Remove "Hit" from hitpoint name if one exists -_toFind = if (_hitPoint find "Hit" == 0) then { +_toFind = if ((toLower _hitPoint) find "hit" == 0) then { [_hitPoint, 3] call CBA_fnc_substr } else { _hitPoint @@ -83,6 +84,7 @@ for "_i" from 0 to (count _hitPoint) do { // Don't display part name if no string is found in stringtable if (_text == LSTRING(Hit)) then { + if (_hitPoint != "") then { ACE_LOGWARNING_1("Hitpoint [%1] - could not be localized", _hitPoint); }; _text = _textDefault; }; diff --git a/addons/repair/functions/fnc_getPostRepairDamage.sqf b/addons/repair/functions/fnc_getPostRepairDamage.sqf index 797f7a4f22..36e4bf39ae 100644 --- a/addons/repair/functions/fnc_getPostRepairDamage.sqf +++ b/addons/repair/functions/fnc_getPostRepairDamage.sqf @@ -19,7 +19,7 @@ params ["_unit"]; TRACE_1("params",_unit); // TODO when near repair station, full repair? -if (([_unit] call FUNC(isInRepairFacility) || {[_unit] call FUNC(isNearRepairVehicle)})) exitwith {0}; +if (([_unit] call FUNC(isInRepairFacility) || {[_unit] call FUNC(isNearRepairVehicle)})) exitWith {0}; if ([_unit, GVAR(engineerSetting_Repair) + 1] call FUNC(isEngineer)) exitWith {GVAR(repairDamageThreshold_Engineer)}; if ([_unit, GVAR(engineerSetting_Repair)] call FUNC(isEngineer)) exitWith {GVAR(repairDamageThreshold)}; diff --git a/addons/repair/functions/fnc_hasItems.sqf b/addons/repair/functions/fnc_hasItems.sqf index 2f070c8bb6..d0030b3c07 100644 --- a/addons/repair/functions/fnc_hasItems.sqf +++ b/addons/repair/functions/fnc_hasItems.sqf @@ -23,10 +23,10 @@ private ["_return"]; _return = true; { - if (typeName _x == "ARRAY" && {({[_unit, _x] call EFUNC(common,hasItem)} count _x == 0)}) exitwith { + if (typeName _x == "ARRAY" && {({[_unit, _x] call EFUNC(common,hasItem)} count _x == 0)}) exitWith { _return = false; }; - if (typeName _x == "STRING" && {!([_unit, _x] call EFUNC(common,hasItem))}) exitwith { + if (typeName _x == "STRING" && {!([_unit, _x] call EFUNC(common,hasItem))}) exitWith { _return = false; }; } forEach _items; diff --git a/addons/repair/functions/fnc_isInRepairFacility.sqf b/addons/repair/functions/fnc_isInRepairFacility.sqf index 0c062ff0b3..b72d8a5985 100644 --- a/addons/repair/functions/fnc_isInRepairFacility.sqf +++ b/addons/repair/functions/fnc_isInRepairFacility.sqf @@ -26,7 +26,7 @@ _repairFacility = []; _objects = (lineIntersectsWith [_object modelToWorldVisual [0, 0, (_position select 2)], _object modelToWorldVisual [0, 0, (_position select 2) +10], _object]); { - if (((typeOf _x) in _repairFacility) || (_x getVariable ["ACE_isRepairFacility",0]) > 0) exitwith { + if (((typeOf _x) in _repairFacility) || (_x getVariable ["ACE_isRepairFacility",0]) > 0) exitWith { _isInBuilding = true; }; } forEach _objects; @@ -34,7 +34,7 @@ _objects = (lineIntersectsWith [_object modelToWorldVisual [0, 0, (_position sel if (!_isInBuilding) then { _objects = position _object nearObjects 7.5; { - if (((typeOf _x) in _repairFacility) || (_x getVariable ["ACE_isRepairFacility",0]) > 0) exitwith { + if (((typeOf _x) in _repairFacility) || (_x getVariable ["ACE_isRepairFacility",0]) > 0) exitWith { _isInBuilding = true; }; } forEach _objects; diff --git a/addons/repair/functions/fnc_isNearRepairVehicle.sqf b/addons/repair/functions/fnc_isNearRepairVehicle.sqf index 677f489a88..463e281faa 100644 --- a/addons/repair/functions/fnc_isNearRepairVehicle.sqf +++ b/addons/repair/functions/fnc_isNearRepairVehicle.sqf @@ -24,7 +24,7 @@ _nearObjects = nearestObjects [_unit, ["Air","LandVehicle"], 20]; _return = false; { - if ([_x] call FUNC(isRepairVehicle)) exitwith {_return = true;}; + if ([_x] call FUNC(isRepairVehicle)) exitWith {_return = true;}; } forEach _nearObjects; _return; diff --git a/addons/repair/functions/fnc_isRepairVehicle.sqf b/addons/repair/functions/fnc_isRepairVehicle.sqf index 121bda0fe3..2c0b5a1e21 100644 --- a/addons/repair/functions/fnc_isRepairVehicle.sqf +++ b/addons/repair/functions/fnc_isRepairVehicle.sqf @@ -18,6 +18,6 @@ params ["_vehicle"]; TRACE_1("params",_vehicle); -if (_vehicle isKindOf "CAManBase") exitwith {false}; +if (_vehicle isKindOf "CAManBase") exitWith {false}; ((_vehicle getVariable ["ACE_isRepairVehicle", getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(canRepair))]) > 0); diff --git a/addons/repair/functions/fnc_moduleAddSpareParts.sqf b/addons/repair/functions/fnc_moduleAddSpareParts.sqf index 0435244dc7..bc2502c0f4 100644 --- a/addons/repair/functions/fnc_moduleAddSpareParts.sqf +++ b/addons/repair/functions/fnc_moduleAddSpareParts.sqf @@ -41,5 +41,6 @@ if (!isNull _logic) then { // Add spare parts { [_x, _amount, _part, true] call FUNC(addSpareParts); + false } count _list; }; diff --git a/addons/repair/functions/fnc_normalizeHitPoints.sqf b/addons/repair/functions/fnc_normalizeHitPoints.sqf index 88c72f4de8..a73dfcfe0d 100644 --- a/addons/repair/functions/fnc_normalizeHitPoints.sqf +++ b/addons/repair/functions/fnc_normalizeHitPoints.sqf @@ -16,33 +16,45 @@ #include "script_component.hpp" params ["_vehicle"]; -TRACE_1("params",_vehicle); +TRACE_2("params",_vehicle, typeOf _vehicle); // Can't execute all commands if the vehicle isn't local, exit if that's so -if !(local _vehicle) exitWith {}; +if !(local _vehicle) exitWith {ACE_LOGERROR_1("Vehicle Not Local %1", _vehicle);}; -private ["_hitPoints", "_config", "_dependentHitPoints", "_dependentHitPointScripts", "_damage"]; +(getAllHitPointsDamage _vehicle) params [["_allHitPoints", []]]; -_hitPoints = [_vehicle] call EFUNC(common,getHitPoints); -_config = configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints"; +private _config = configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints"; -// define global variables. Needed to parse the depends config entries. Also find dependent hitpoints. +private _realHitPoints = []; +private _dependentHitPoints = []; +private _dependentHitPointScripts = []; -_dependentHitPoints = []; -_dependentHitPointScripts = []; +// Find dependent hitpoints +{ + if ((_x != "") && {isClass (_config >> _x)} && {!(_x in _realHitPoints)}) then { + _realHitPoints pushBack _x; + if (isText (_config >> _x >> "depends")) then { + _dependentHitPoints pushBack _x; + _dependentHitPointScripts pushBack compile getText (_config >> _x >> "depends"); + }; + }; +} forEach _allHitPoints; +TRACE_2("",_realHitPoints,_dependentHitPoints); + +// Don't bother setting variables if no depends on vehicle: +if (_dependentHitPoints isEqualTo []) exitWith {}; + + +// Define global variables Total = damage _vehicle; - { missionNamespace setVariable [_x, _vehicle getHitPointDamage _x]; - if (isText (_config >> _x >> "depends")) then { - _dependentHitPoints pushBack _x; - _dependentHitPointScripts pushBack compile getText (_config >> _x >> "depends"); - }; -} forEach _hitPoints; +} forEach _realHitPoints; // apply normalized damage to all dependand hitpoints { - _damage = call (_dependentHitPointScripts select _forEachIndex); + private _damage = call (_dependentHitPointScripts select _forEachIndex); + TRACE_2("setting depend hitpoint", _x, _damage); _vehicle setHitPointDamage [_x, _damage]; } forEach _dependentHitPoints; diff --git a/addons/repair/functions/fnc_repair.sqf b/addons/repair/functions/fnc_repair.sqf index fc0c19f914..09a5ffa27f 100644 --- a/addons/repair/functions/fnc_repair.sqf +++ b/addons/repair/functions/fnc_repair.sqf @@ -21,22 +21,22 @@ params ["_caller", "_target", "_hitPoint", "_className"]; TRACE_4("params",_calller,_target,_hitPoint,_className); -private["_callbackProgress", "_callerAnim", "_calller", "_condition", "_config", "_consumeItems", "_displayText", "_engineerRequired", "_iconDisplayed", "_items", "_locations", "_repairTime", "_repairTimeConfig", "_return", "_usersOfItems", "_vehicleStateCondition", "_wpn", "_settingName", "_settingItemsArray", "_hitPointClassname"]; +private["_callbackProgress", "_callerAnim", "_calller", "_condition", "_config", "_consumeItems", "_displayText", "_engineerRequired", "_iconDisplayed", "_items", "_repairTime", "_repairTimeConfig", "_return", "_usersOfItems", "_vehicleStateCondition", "_wpn", "_settingName", "_settingItemsArray", "_hitPointClassname"]; _config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className); -if !(isClass _config) exitwith {false}; // or go for a default? +if !(isClass _config) exitWith {false}; // or go for a default? _engineerRequired = if (isNumber (_config >> "requiredEngineer")) then { getNumber (_config >> "requiredEngineer"); } else { // Check for required class - if (isText (_config >> "requiredEngineer")) exitwith { + if (isText (_config >> "requiredEngineer")) exitWith { missionNamespace getVariable [(getText (_config >> "requiredEngineer")), 0]; }; 0; }; -if !([_caller, _engineerRequired] call FUNC(isEngineer)) exitwith {false}; -if (isEngineOn _target) exitwith {false}; +if !([_caller, _engineerRequired] call FUNC(isEngineer)) exitWith {false}; +if (isEngineOn _target) exitWith {false}; //Items can be an array of required items or a string to a ACE_Setting array _items = if (isArray (_config >> "items")) then { @@ -49,12 +49,12 @@ _items = if (isArray (_config >> "items")) then { }; _settingItemsArray select (missionNamespace getVariable _settingName); }; -if (count _items > 0 && {!([_caller, _items] call FUNC(hasItems))}) exitwith {false}; +if (count _items > 0 && {!([_caller, _items] call FUNC(hasItems))}) exitWith {false}; _return = true; if (getText (_config >> "condition") != "") then { _condition = getText (_config >> "condition"); - if (isnil _condition) then { + if (isNil _condition) then { _condition = compile _condition; } else { _condition = missionNamespace getVariable _condition; @@ -65,25 +65,25 @@ if (getText (_config >> "condition") != "") then { _return = [_caller, _target, _hitPoint, _className] call _condition; }; }; -if (!_return) exitwith {false}; +if (!_return) exitWith {false}; // _vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then { // missionNamespace getVariable [getText(_config >> "vehicleStateCondition"), 0] // } else { // getNumber(_config >> "vehicleStateCondition") // }; -// if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitwith {false}; +// if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitWith {false}; -local _repairLocations = getArray (_config >> "repairLocations"); +private _repairLocations = getArray (_config >> "repairLocations"); if (!("All" in _repairLocations)) then { - local _repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))}; - local _repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))}; + private _repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))}; + private _repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))}; { - if (_x == "field") exitwith {_return = true;}; - if (_x == "RepairFacility" && _repairFacility) exitwith {_return = true;}; - if (_x == "RepairVehicle" && _repairVeh) exitwith {_return = true;}; - if !(isnil _x) exitwith { - local _val = missionNamespace getVariable _x; + if (_x == "field") exitWith {_return = true;}; + if (_x == "RepairFacility" && _repairFacility) exitWith {_return = true;}; + if (_x == "RepairVehicle" && _repairVeh) exitWith {_return = true;}; + if !(isNil _x) exitWith { + private _val = missionNamespace getVariable _x; if (typeName _val == "SCALAR") then { _return = switch (_val) do { case 0: {true}; //useAnywhere @@ -97,8 +97,8 @@ if (!("All" in _repairLocations)) then { } forEach _repairLocations; }; -local _requiredObjects = getArray (_config >> "claimObjects"); -local _claimObjectsAvailable = []; +private _requiredObjects = getArray (_config >> "claimObjects"); +private _claimObjectsAvailable = []; if (!(_requiredObjects isEqualTo [])) then { _claimObjectsAvailable = [_caller, 5, _requiredObjects] call FUNC(getClaimObjects); if (_claimObjectsAvailable isEqualTo []) then { @@ -107,7 +107,7 @@ if (!(_requiredObjects isEqualTo [])) then { }; }; -if !(_return && alive _target) exitwith {false}; +if !(_return && alive _target) exitWith {false}; //Last exitWith: repair_success or repair_failure will be run //Claim required objects @@ -120,7 +120,7 @@ _consumeItems = if (isNumber (_config >> "itemConsumed")) then { getNumber (_config >> "itemConsumed"); } else { // Check for required class - if (isText (_config >> "itemConsumed")) exitwith { + if (isText (_config >> "itemConsumed")) exitWith { missionNamespace getVariable [(getText (_config >> "itemConsumed")), 0]; }; 0; @@ -174,14 +174,14 @@ if (vehicle _caller == _caller && {_callerAnim != ""}) then { _repairTime = if (isNumber (_config >> "repairingTime")) then { getNumber (_config >> "repairingTime"); } else { - if (isText (_config >> "repairingTime")) exitwith { + if (isText (_config >> "repairingTime")) exitWith { _repairTimeConfig = getText(_config >> "repairingTime"); - if (isnil _repairTimeConfig) then { + if (isNil _repairTimeConfig) then { _repairTimeConfig = compile _repairTimeConfig; } else { _repairTimeConfig = missionNamespace getVariable _repairTimeConfig; }; - if (typeName _repairTimeConfig == "SCALAR") exitwith { + if (typeName _repairTimeConfig == "SCALAR") exitWith { _repairTimeConfig; }; [_caller, _target, _hitPoint, _className] call _repairTimeConfig; @@ -197,7 +197,8 @@ _hitPointClassname = if ((typeName _hitPoint) == "STRING") then { ((getAllHitPointsDamage _target) select 0) select _hitPoint }; _processText = getText (_config >> "displayNameProgress"); -([_hitPointClassname, _processText, _processText] call FUNC(getHitPointString)) params ["_text"]; +private _backupText = format [localize LSTRING(RepairingHitPoint), _hitPointClassname]; +([_hitPointClassname, _processText, _backupText] call FUNC(getHitPointString)) params ["_text"]; TRACE_4("display",_hitPoint,_hitPointClassname,_processText,_text); diff --git a/addons/repair/functions/fnc_setHitPointDamage.sqf b/addons/repair/functions/fnc_setHitPointDamage.sqf index 399f390767..018a03723b 100644 --- a/addons/repair/functions/fnc_setHitPointDamage.sqf +++ b/addons/repair/functions/fnc_setHitPointDamage.sqf @@ -19,7 +19,7 @@ #include "script_component.hpp" params ["_vehicle", "_hitPointIndex", "_hitPointDamage"]; -TRACE_3("params",_vehicle,_hitPointIndex,_hitPointDamage); +TRACE_4("params",_vehicle,typeOf _vehicle,_hitPointIndex,_hitPointDamage); private["_damageNew", "_damageOld", "_hitPointDamageRepaired", "_hitPointDamageSumOld", "_realHitpointCount", "_selectionName"]; @@ -50,8 +50,8 @@ _hitPointDamageRepaired = 0; //positive for repairs : newSum = (oldSum - repaire //Filter out all the bad hitpoints (HitPoint="" or no selection) if ((!isNil {_vehicle getHit _selectionName}) && {_x != ""}) then { _realHitpointCount = _realHitpointCount + 1; - - if ((!(_x in IGNORED_HITPOINTS)) && {!isText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints" >> _x >> "depends")}) then { + + if ((((toLower _x) find "glass") == -1) && {!isText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints" >> _x >> "depends")}) then { _hitPointDamageSumOld = _hitPointDamageSumOld + (_allHitPointDamages select _forEachIndex); if (_forEachIndex == _hitPointIndex) then { _hitPointDamageRepaired = (_allHitPointDamages select _forEachIndex) - _hitPointDamage; @@ -80,4 +80,4 @@ _allHitPointDamages set [_hitPointIndex, _hitPointDamage]; } forEach _allHitPointDamages; // normalize hitpoints -// [_vehicle] call FUNC(normalizeHitPoints); +[_vehicle] call FUNC(normalizeHitPoints); diff --git a/addons/repair/functions/fnc_spawnObject.sqf b/addons/repair/functions/fnc_spawnObject.sqf index 9c092d9c3a..86d0b563ac 100644 --- a/addons/repair/functions/fnc_spawnObject.sqf +++ b/addons/repair/functions/fnc_spawnObject.sqf @@ -8,7 +8,7 @@ * 2: Damage * * Return Value: - * None + * The new object * * Example: * ["classname", [0, 0, 0], 1] call ace_repair_fnc_spawnObject @@ -23,10 +23,12 @@ TRACE_3("params",_item,_position,_damage); // randomized end position _position = _position vectorAdd [1 - random 2, 1 - random 2, 0]; -_item = createVehicle [_item, _position, [], 0, "NONE"]; -_item setPosASL _position; +private _newObject = createVehicle [_item, _position, [], 0, "NONE"]; +_newObject setPosASL _position; -["fixCollision", _item] call EFUNC(common,localEvent); -["fixPosition", _item] call EFUNC(common,localEvent); +_newObject setDamage _damage; -_item setDamage _damage; +["fixCollision", _newObject] call EFUNC(common,localEvent); +["fixPosition", _newObject] call EFUNC(common,localEvent); + +_newObject diff --git a/addons/repair/functions/fnc_useItem.sqf b/addons/repair/functions/fnc_useItem.sqf index 72619657a2..024ee76c29 100644 --- a/addons/repair/functions/fnc_useItem.sqf +++ b/addons/repair/functions/fnc_useItem.sqf @@ -19,7 +19,7 @@ params ["_unit", "_item"]; TRACE_2("params",_unit,_item); -if ([_unit, _item] call EFUNC(common,hasItem)) exitwith { +if ([_unit, _item] call EFUNC(common,hasItem)) exitWith { [[_unit, _item], QUOTE(EFUNC(common,useItem)), _unit] call EFUNC(common,execRemoteFnc); /* TODO Replace by event system */ [true, _unit]; }; diff --git a/addons/repair/functions/fnc_useItems.sqf b/addons/repair/functions/fnc_useItems.sqf index 5e5cba0063..dd781ff371 100644 --- a/addons/repair/functions/fnc_useItems.sqf +++ b/addons/repair/functions/fnc_useItems.sqf @@ -27,14 +27,14 @@ _itemsUsedBy = []; if (typeName _x == "ARRAY") then { { _itemUsedInfo = [_unit, _x] call FUNC(useItem); - if (_itemUsedInfo select 0) exitwith { _itemsUsedBy pushback [(_itemUsedInfo select 1), _x]}; + if (_itemUsedInfo select 0) exitWith { _itemsUsedBy pushback [(_itemUsedInfo select 1), _x]}; } forEach _x; }; // handle required item if (typeName _x == "STRING") then { _itemUsedInfo = [_unit, _x] call FUNC(useItem); - if (_itemUsedInfo select 0) exitwith { _itemsUsedBy pushback [(_itemUsedInfo select 1), _x]}; + if (_itemUsedInfo select 0) exitWith { _itemsUsedBy pushback [(_itemUsedInfo select 1), _x]}; }; } forEach _items; diff --git a/addons/repair/script_component.hpp b/addons/repair/script_component.hpp index a6aa1db61f..ff5d40a6ae 100644 --- a/addons/repair/script_component.hpp +++ b/addons/repair/script_component.hpp @@ -13,6 +13,4 @@ #include "\z\ace\addons\main\script_macros.hpp" - -#define IGNORED_HITPOINTS ["HitGlass1", "HitGlass2", "HitGlass3", "HitGlass4", "HitGlass5", "HitGlass6", "HitGlass7", "HitGlass8", "HitGlass9", "HitGlass10", "HitGlass11", "HitGlass12", "HitGlass13", "HitGlass14", "HitGlass15", "HitRGlass", "HitLGlass", "Glass_1_hitpoint", "Glass_2_hitpoint", "Glass_3_hitpoint", "Glass_4_hitpoint", "Glass_5_hitpoint", "Glass_6_hitpoint", "Glass_7_hitpoint", "Glass_8_hitpoint", "Glass_9_hitpoint", "Glass_10_hitpoint", "Glass_11_hitpoint", "Glass_12_hitpoint", "Glass_13_hitpoint", "Glass_14_hitpoint", "Glass_15_hitpoint", "Glass_16_hitpoint", "Glass_17_hitpoint", "Glass_18_hitpoint", "Glass_19_hitpoint", "Glass_20_hitpoint"] #define TRACK_HITPOINTS ["HitLTrack", "HitRTrack"]