Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair - Add wheel patching #8835

Merged
merged 19 commits into from Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions addons/repair/ACE_Repair.hpp
Expand Up @@ -30,6 +30,17 @@ class ACE_Repair {
callbackSuccess = QFUNC(doRemoveWheel);
claimObjects[] = {};
};
class PatchWheel: ReplaceWheel {
displayName = CSTRING(PatchWheel);
displayNameProgress = CSTRING(PatchingWheel);
condition = QFUNC(canPatchWheel);
repairingTime = QFUNC(getPatchWheelTime);
callbackProgress = QFUNC(doPatchWheelProgress);
items = QGVAR(patchWheelRequiredItems);
requiredEngineer = QGVAR(engineerSetting_Wheel);
callbackSuccess = "";
claimObjects[] = {};
};
class MiscRepair: ReplaceWheel {
displayName = CSTRING(Repairing); // let's make empty string an auto generated string
displayNameProgress = CSTRING(RepairingHitPoint);
Expand Down
18 changes: 18 additions & 0 deletions addons/repair/CfgVehicles.hpp
Expand Up @@ -403,6 +403,24 @@ class CfgVehicles {
};

editorPreview = QPATHTOF(data\preview_wheel.jpg);

class ACE_Actions {
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
class ACE_MainActions {
displayName = ECSTRING(interaction,MainAction);
distance = 4;
condition = QUOTE(true);
statement = "";
modifierFunction = QUOTE(_this call FUNC(modifyInteraction));
class GVAR(Patch) {
displayName = CSTRING(PatchWheel);
distance = 4;
condition = QUOTE([ARR_2(_player, _target)] call FUNC(canPatchRemovedWheel));
statement = QUOTE([ARR_2(_player, _target)] call FUNC(patchRemovedWheel));
exceptions[] = {"isNotDragging", "isNotCarrying", "isNotOnLadder", "isNotSwimming", "isNotSitting"};
icon = "a3\ui_f\data\igui\cfg\actions\repair_ca.paa";
};
};
};
};

// disable vanilla repair
Expand Down
5 changes: 5 additions & 0 deletions addons/repair/XEH_PREP.hpp
Expand Up @@ -2,12 +2,15 @@
PREP(addRepairActions);
PREP(addSpareParts);
PREP(canMiscRepair);
PREP(canPatchRemovedWheel);
PREP(canPatchWheel);
PREP(canRemove);
PREP(canRepair);
PREP(canRepairTrack);
PREP(canReplaceTrack);
PREP(canReplaceWheel);
PREP(doFullRepair);
PREP(doPatchWheelProgress);
PREP(doRemoveTrack);
PREP(doRemoveWheel);
PREP(doRepair);
Expand All @@ -16,6 +19,7 @@ PREP(doReplaceTrack);
PREP(doReplaceWheel);
PREP(getClaimObjects);
PREP(getHitPointString);
PREP(getPatchWheelTime);
PREP(getPostRepairDamage);
PREP(getRepairItems);
PREP(getWheelHitPointsWithSelections);
Expand All @@ -32,6 +36,7 @@ PREP(moduleAssignRepairVehicle);
PREP(moduleAssignRepairFacility);
PREP(moduleRepairSettings);
PREP(normalizeHitPoints);
PREP(patchRemovedWheel);
PREP(repair);
PREP(repair_failure);
PREP(repair_success);
Expand Down
29 changes: 21 additions & 8 deletions addons/repair/functions/fnc_addRepairActions.sqf
Expand Up @@ -56,14 +56,6 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi

TRACE_3("Adding Wheel Actions",_hitpoint,_forEachIndex,_selection);

// An action to remove the wheel is required
private _name = format ["Remove_%1_%2", _forEachIndex, _hitpoint];
private _text = localize LSTRING(RemoveWheel);
private _condition = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(canRepair)};
private _statement = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(repair)};
private _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 2, nil, FUNC(modifySelectionInteraction)] 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, _hitpoint];
_text = localize LSTRING(ReplaceWheel);
Expand All @@ -72,6 +64,27 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi
_action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction);
[_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass);

// Create a wheel interaction
private _root = format ["Wheel_%1_%2", _forEachIndex, _hitpoint];
private _action = [_root, localize LSTRING(SpareWheel), ["","#FFFFFF"], {}, {true}, {}, [_hitpoint], _position, 2, nil, FUNC(modifySelectionInteraction)] call EFUNC(interact_menu,createAction);
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
[_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass);

// An action to remove the wheel is required
private _name = format ["Remove_%1_%2", _forEachIndex, _hitpoint];
private _text = localize LSTRING(RemoveWheel);
private _condition = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(canRepair)};
private _statement = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(repair)};
private _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction);
[_type, 0, [_root], _action] call EFUNC(interact_menu,addActionToClass);

// An action to patch the wheel is required.
private _name = format ["Patch_%1_%2", _forEachIndex, _hitpoint];
private _text = localize LSTRING(PatchWheel);
private _condition = {("vehicle" in GVAR(patchWheelLocation)) && {[_this select 1, _this select 0, _this select 2 select 0, "PatchWheel"] call DFUNC(canRepair)}};
private _statement = {[_this select 1, _this select 0, _this select 2 select 0, "PatchWheel"] call DFUNC(repair)};
private _action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction);
[_type, 0, [_root], _action] call EFUNC(interact_menu,addActionToClass);

_processedSelections pushBack _selection;
} else {
// Empty hitpoints don't contain enough information
Expand Down
27 changes: 27 additions & 0 deletions addons/repair/functions/fnc_canPatchRemovedWheel.sqf
@@ -0,0 +1,27 @@
#include "script_component.hpp"
/*
* Author: commy2, Brett Mayson
* Check if the unit can patch a wheel not on a vehicle.
*
* Arguments:
* 0: Unit that does the patching <OBJECT>
* 1: Wheel to patch <OBJECT>
*
* Return Value:
* None
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
*
* Example:
* [unit, vehicle] call ace_repair_fnc_canPatchRemovedWheel
*
* Public: No
*/

params ["_unit", "_target"];
TRACE_2("params",_unit,_target);

if (GVAR(patchWheelEnabled) == -1) exitWith {false};
if !("ground" in GVAR(patchWheelLocation)) exitWith {false};

PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
if !([_unit, GVAR(patchWheelEnabled)] call FUNC(isEngineer)) exitWith {false};

(damage _target > GVAR(patchWheelMaximumRepair))
31 changes: 31 additions & 0 deletions addons/repair/functions/fnc_canPatchWheel.sqf
@@ -0,0 +1,31 @@
#include "script_component.hpp"
/*
* Author: commy2, Brett Mayson
* Check if the unit can patch given wheel of the vehicle.
*
* Arguments:
* 0: Unit that does the patching <OBJECT>
* 1: Vehicle to patch <OBJECT>
* 2: Selected wheel hitpoint <STRING>
*
* Return Value:
* None
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
*
* Example:
* [unit, vehicle, "hitpoint"] call ace_repair_fnc_canPatchWheel
*
* Public: No
*/

params ["_unit", "_target", "_hitPoint"];
TRACE_3("params",_unit,_target,_hitPoint);

if (GVAR(patchWheelEnabled) == -1) exitWith {false};

private _damage = _target getHitPointDamage _hitPoint;

if (_damage == 1) exitWith {false};

if !([_unit, _target, ["isNotDragging", "isNotCarrying", "isNotOnLadder"]] call EFUNC(common,canInteractWith)) exitWith {false};

(_damage > GVAR(patchWheelMaximumRepair))
veteran29 marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions addons/repair/functions/fnc_doPatchWheelProgress.sqf
@@ -0,0 +1,39 @@
#include "script_component.hpp"
/*
* Author: commy2, Brett Mayson
* Called by repair action / progress bar. Raise events to set the new hitpoint damage.
*
* Arguments:
* 0: Unit that does the patching <OBJECT>
* 1: Vehicle to patch <OBJECT>
* 2: Selected wheel hitpoint <STRING>
*
* Return Value:
* None
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
*
* Example:
* [unit, vehicle, "hitpoint"] call ace_repair_fnc_doPatchWheelProgress
*
* Public: No
*/

params ["_args", "_elapsedTime", "_totalTime"];
_args params ["_unit", "_vehicle", "_hitPoint"];
TRACE_3("params",_unit,_vehicle,_hitPoint);

// get current hitpoint damage
private _hitPointDamage = _vehicle getHitPointDamage _hitPoint;

private _iterationsRemaining = ceil ((_hitPointDamage - GVAR(patchWheelMaximumRepair)) / 0.05) - 1;
if ((_totalTime - _elapsedTime) > _iterationsRemaining * GVAR(patchWheelTime)) exitWith {true};

_hitPointDamage = _hitPointDamage - 0.05;

if (_hitPointDamage < GVAR(patchWheelMaximumRepair)) then {
_hitPointDamage = GVAR(patchWheelMaximumRepair);
};
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved

// raise event to set the new hitpoint damage
[QGVAR(setWheelHitPointDamage), [_vehicle, _hitPoint, _hitPointDamage], _vehicle] call CBA_fnc_targetEvent;

_hitPointDamage > GVAR(patchWheelMaximumRepair)
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions addons/repair/functions/fnc_getPatchWheelTime.sqf
@@ -0,0 +1,25 @@
#include "script_component.hpp"
/*
* Author: Brett Mayson
* Calculate the time to patch the wheel
*
* Arguments:
* 0: Unit that does the patching <OBJECT>
* 1: Vehicle to patch <OBJECT>
* 2: Selected wheel hitpoint <STRING>
*
* Return Value:
* None
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
*
* Example:
* [unit, vehicle, "hitpoint"] call ace_repair_fnc_getPatchWheelTime
*
* Public: No
*/

params ["_unit", "_vehicle", "_hitPoint"];

// get current hitpoint damage
private _hitPointDamage = (_vehicle getHitPointDamage _hitPoint) - GVAR(patchWheelMaximumRepair);

ceil (_hitPointDamage / 0.05) * GVAR(patchWheelTime)
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions addons/repair/functions/fnc_patchRemovedWheel.sqf
@@ -0,0 +1,43 @@
#include "script_component.hpp"
/*
* Author: Brett Mayson
* Patch a wheel that is not on a vehicle
*
* Arguments:
* 0: Unit that does the patching <OBJECT>
* 1: Wheel to patch <OBJECT>
*
* Return Value:
* None
*
* Example:
* [unit, vehicle] call ace_repair_fnc_patchRemovedWheel
*
* Public: No
*/

params ["_unit", "_target"];

[_unit, "Acts_carFixingWheel"] call EFUNC(common,doAnimation);

private _wheelDamage = (damage _target) - GVAR(patchWheelMaximumRepair);

[ceil (_wheelDamage / 0.05) * GVAR(patchWheelTime), [_target], {}, {}, LLSTRING(PatchingWheel), {
params ["_args"];
_args params ["_target"];
private _damage = damage _target;

private _iterationsRemaining = ceil ((_damage - GVAR(patchWheelMaximumRepair)) / 0.05) - 1;
if ((_totalTime - _elapsedTime) > _iterationsRemaining * GVAR(patchWheelTime)) exitWith {true};

_damage = _damage - 0.05;

if (_damage < GVAR(patchWheelMaximumRepair)) then {
_damage = GVAR(patchWheelMaximumRepair);
};
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved

_target setDamage _damage;

_damage > GVAR(patchWheelMaximumRepair)
}] call ace_common_fnc_progressBar;

53 changes: 53 additions & 0 deletions addons/repair/initSettings.sqf
Expand Up @@ -25,6 +25,32 @@
{[QGVAR(engineerSetting_wheel), _this] call EFUNC(common,cbaSettings_settingChanged)}
] call CBA_fnc_addSetting;

[
QGVAR(patchWheelEnabled), "LIST",
[LSTRING(patchWheelEnabled_name), LSTRING(patchWheelEnabled_description)],
[localize ELSTRING(OptionsMenu,CategoryLogistics), localize "str_state_repair"],
[[-1,0,1,2],["str_player_none", LSTRING(engineerSetting_anyone), LSTRING(engineerSetting_EngineerOnly), LSTRING(engineerSetting_AdvancedOnly)],1], // default value
true // isGlobal
] call CBA_fnc_addSetting;

[
QGVAR(patchWheelRequiredItems),
"LIST",
[LSTRING(patchWheelRequiredItems_DisplayName), LSTRING(patchWheelRequiredItems_Description)],
[localize ELSTRING(OptionsMenu,CategoryLogistics), localize "str_state_repair"],
[[[], [ANY_TOOLKIT_FAKECLASS]], ["STR_A3_None", "STR_A3_CfgWeapons_Toolkit0"], 1],
true
] call CBA_fnc_addSetting;

[
QGVAR(patchWheelLocation),
"LIST",
[LSTRING(patchWheelLocation_DisplayName), LSTRING(patchWheelLocation_Description)],
[localize ELSTRING(OptionsMenu,CategoryLogistics), localize "str_state_repair"],
[[["ground", "vehicle"], ["vehicle"], ["ground"]], ["str_difficulty_any", LSTRING(patchWheelOnVehicle), LSTRING(patchWheelOnGround)], 0],
true
] call CBA_fnc_addSetting;

[
QGVAR(repairDamageThreshold), "SLIDER",
[LSTRING(repairDamageThreshold_name), LSTRING(repairDamageThreshold_description)],
Expand Down Expand Up @@ -124,3 +150,30 @@
true, // isGlobal
{[QGVAR(autoShutOffEngineWhenStartingRepair), _this] call EFUNC(common,cbaSettings_settingChanged)}
] call CBA_fnc_addSetting;

[
QGVAR(fullRepairRequiredItems),
"LIST",
[LSTRING(FullRepairRequiredItems_DisplayName), LSTRING(FullRepairRequiredItems_Description)],
[localize ELSTRING(OptionsMenu,CategoryLogistics), localize "str_state_repair"],
[[[], [ANY_TOOLKIT_FAKECLASS]], ["STR_A3_None", "STR_A3_CfgWeapons_Toolkit0"], 1],
true
] call CBA_fnc_addSetting;
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved

[
QGVAR(patchWheelTime),
"SLIDER",
[LSTRING(patchWheelTime_DisplayName), LSTRING(patchWheelTime_Description)],
[localize ELSTRING(OptionsMenu,CategoryLogistics), localize "str_state_repair"],
[0.1, 60, 5, 1],
true
] call CBA_fnc_addSetting;

[
QGVAR(patchWheelMaximumRepair),
"SLIDER",
[LSTRING(patchWheelMaximumRepair_DisplayName), LSTRING(patchWheelMaximumRepair_Description)],
[localize ELSTRING(OptionsMenu,CategoryLogistics), localize "str_state_repair"],
[0, 1, 0.3, 1, true],
true
] call CBA_fnc_addSetting;