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 enable setting #8070

Merged
merged 13 commits into from
Jul 29, 2023
9 changes: 0 additions & 9 deletions addons/repair/CfgActions.hpp

This file was deleted.

7 changes: 4 additions & 3 deletions addons/repair/CfgEden.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#define VANILLA_ISREPAIRVEHICLE (parseNumber (getRepairCargo _this > 0))
#define GET_NUMBER(config,default) (if (isNumber (config)) then {getNumber (config)} else {default})

#define DEFAULT_ISENGINEER ([ARR_2(0,1)] select (_this getUnitTrait 'engineer'))
#define DEFAULT_ISREPAIRVEHICLE GET_NUMBER(configOf _this >> QQGVAR(canRepair),0)
#define DEFAULT_ISREPAIRVEHICLE GET_NUMBER(configOf _this >> QQGVAR(canRepair),VANILLA_ISREPAIRVEHICLE)

class ctrlToolbox;

Expand Down Expand Up @@ -69,7 +70,7 @@ class Cfg3DEN {
property = QGVAR(editorLoadedTracks);
control = "Edit";
expression = "_this setVariable ['%s',_value];";
defaultValue = "[0,1] select (_this isKindOf 'Tank')"; // must match pre init script
defaultValue = "parseNumber (_this isKindOf 'Tank')"; // must match post init script
validate = "number";
condition = "objectHasInventoryCargo";
typeName = "NUMBER";
Expand All @@ -78,7 +79,7 @@ class Cfg3DEN {
displayName = CSTRING(editorLoadedWheels);
tooltip = CSTRING(editorLoadedWheels_tooltip);
property = QGVAR(editorLoadedWheels);
defaultValue = "[0,1] select (_this isKindOf 'Car')"; // must match pre init script
defaultValue = "parseNumber (_this isKindOf 'Car')"; // must match post init script
};
};
};
Expand Down
68 changes: 0 additions & 68 deletions addons/repair/CfgVehicles.hpp
Dystopian marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
class ACE_MainActions { \
class GVAR(Repair) { \
displayName = CSTRING(Repair); \
condition = "true"; \
statement = ""; \
runOnHover = 1; \
showDisabled = 0; \
icon = "\A3\ui_f\data\igui\cfg\actions\repair_ca.paa"; \
distance = 4; \
exceptions[] = {"isNotSwimming", "isNotOnLadder"}; \
Expand Down Expand Up @@ -418,39 +414,10 @@ class CfgVehicles {
};
};

// disable vanilla repair
// "getNumber (_x >> ""transportRepair"") > 0" configClasses (configFile >> "CfgVehicles")
class ReammoBox_F;
class Land_RepairDepot_01_base_F: ReammoBox_F { // TanksDLC - Repair Depo Thing
GVAR(canRepair) = 1;
transportRepair = 0;
};
class Van_02_base_F;
class Van_02_service_base_F: Van_02_base_F { // OrangeDLC
GVAR(canRepair) = 1;
transportRepair = 0;
};

class Slingload_01_Base_F;
class B_Slingload_01_Repair_F: Slingload_01_Base_F {
GVAR(canRepair) = 1;
transportRepair = 0;
};

class Helicopter_Base_H;
class Heli_Transport_04_base_F: Helicopter_Base_H {
GVAR(hitpointGroups)[] = { {"HitEngine", {"HitEngine1", "HitEngine2"}} };
};
class O_Heli_Transport_04_repair_F: Heli_Transport_04_base_F {
GVAR(canRepair) = 1;
transportRepair = 0;
};

class Pod_Heli_Transport_04_base_F;
class Land_Pod_Heli_Transport_04_repair_F: Pod_Heli_Transport_04_base_F {
GVAR(canRepair) = 1;
transportRepair = 0;
};

class Heli_Transport_02_base_F;
class I_Heli_Transport_02_F: Heli_Transport_02_base_F {
Expand All @@ -463,41 +430,10 @@ class CfgVehicles {
};

class B_APC_Tracked_01_base_F;
class B_APC_Tracked_01_CRV_F: B_APC_Tracked_01_base_F {
GVAR(canRepair) = 1;
transportRepair = 0;
};

class B_APC_Tracked_01_AA_F: B_APC_Tracked_01_base_F {
GVAR(hitpointPositions)[] = {{"HitTurret", {0,-2,0}}};
};

class Offroad_01_base_F;
class Offroad_01_repair_base_F: Offroad_01_base_F {
GVAR(canRepair) = 1;
transportRepair = 0;
};

class B_Truck_01_mover_F;
class B_Truck_01_Repair_F: B_Truck_01_mover_F {
GVAR(canRepair) = 1;
transportRepair = 0;
};

class B_Truck_01_fuel_F: B_Truck_01_mover_F { // the fuel hemet apparently can repair. GJ BI
transportRepair = 0;
};

class Truck_02_base_F;
class Truck_02_box_base_F: Truck_02_base_F {
GVAR(canRepair) = 1;
transportRepair = 0;
};

class Truck_02_medical_base_F: Truck_02_box_base_F {
GVAR(canRepair) = 0;
};

class Car_F: Car {
class HitPoints;
};
Expand All @@ -517,10 +453,6 @@ class CfgVehicles {
};
};
};
class O_Truck_03_repair_F: Truck_03_base_F {
GVAR(canRepair) = 1;
transportRepair = 0;
};

class Quadbike_01_base_F: Car_F {
GVAR(hitpointPositions)[] = { {"HitEngine", {0, 0.5, -0.7}}, {"HitFuel", {0, 0, -0.5}} };
Expand Down
66 changes: 64 additions & 2 deletions addons/repair/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "script_component.hpp"

if !GVAR(enabled) exitWith {};
Dystopian marked this conversation as resolved.
Show resolved Hide resolved

[QGVAR(setVehicleDamage), {_this call FUNC(setDamage)}] call CBA_fnc_addEventHandler;
[QGVAR(setVehicleHitPointDamage), {_this call FUNC(setHitPointDamage)}] call CBA_fnc_addEventHandler;

// wheels
[QGVAR(setWheelHitPointDamage), {
params ["_object", "_hitPoint", "_damage"];
private _damageDisabled = !isDamageAllowed _object;
Expand All @@ -18,3 +18,65 @@
_object allowDamage false;
};
}] call CBA_fnc_addEventHandler;


// placed in editor static objects don't trigger init
{
if (local _x && {getRepairCargo _x > 0}) then {
_x setRepairCargo 0;
TRACE_3("setRepairCargo static",_x,typeOf _x,getRepairCargo _x);
};
} forEach allMissionObjects "Static";

["All", "InitPost", {
params ["_vehicle"];
if !(local _vehicle && {getRepairCargo _vehicle > 0}) exitWith {};
_vehicle setRepairCargo 0;
TRACE_3("setRepairCargo vehicle",_vehicle,typeOf _vehicle,getRepairCargo _vehicle);
}, true, ["Man"], true] call CBA_fnc_addClassEventHandler;

["CAManBase", "InitPost", {
params ["_unit"];
if !(local _unit && {_unit getUnitTrait "engineer"}) exitWith {};
_unit setUnitTrait ["engineer", false];
if (_unit getVariable ["ACE_IsEngineer", -1] isEqualTo -1) then {
_unit setVariable ["ACE_IsEngineer", true, true];
};
TRACE_3("setUnitTrait",_unit,typeOf _unit,_unit getUnitTrait "engineer");
}, true, [], true] call CBA_fnc_addClassEventHandler;


GVAR(allToolKits) = call (uiNamespace getVariable QGVAR(allToolKits));

["ACE_RepairItem_Base", "killed", {
params ["_object"];

[{deleteVehicle _this}, _object, 5] call CBA_fnc_waitAndExecute;
}, true, [], true] call CBA_fnc_addClassEventHandler;

// load tracks and wheels
if (isServer) then {
private _fnc_addSpareItems = {
if (!GVAR(addSpareParts)) exitWith {};
params ["_vehicle"];

private _spareTracks = _vehicle getVariable QGVAR(editorLoadedTracks);
if (isNil "_spareTracks") then {
_spareTracks = parseNumber (_vehicle isKindOf "Tank"); // must match eden attribute default
};
if (_spareTracks > 0) then {
[_vehicle, _spareTracks, "ACE_Track"] call FUNC(addSpareParts);
};

private _spareWheels = _vehicle getVariable QGVAR(editorLoadedWheels);
if (isNil "_spareWheels") then {
_spareWheels = parseNumber (_vehicle isKindOf "Car"); // must match eden attribute default
};
if (_spareWheels > 0) then {
[_vehicle, _spareWheels, "ACE_Wheel"] call FUNC(addSpareParts);
};
};

["Tank", "initPost", _fnc_addSpareItems, true, [], true] call CBA_fnc_addClassEventHandler;
["Car", "initPost", _fnc_addSpareItems, true, [], true] call CBA_fnc_addClassEventHandler;
};
35 changes: 0 additions & 35 deletions addons/repair/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,4 @@ PREP_RECOMPILE_END;

#include "initSettings.sqf"

GVAR(allToolKits) = call (uiNamespace getVariable QGVAR(allToolKits));

["ACE_RepairItem_Base", "killed", {
params ["_object"];

[{deleteVehicle _this}, _object, 5] call CBA_fnc_waitAndExecute;
}] call CBA_fnc_addClassEventHandler;

// load tracks and wheels
if (isServer) then {
private _fnc_addSpareItems = {
if (!GVAR(addSpareParts)) exitWith {};
params ["_vehicle"];

private _spareTracks = _vehicle getVariable QGVAR(editorLoadedTracks);
if (isNil "_spareTracks") then {
_spareTracks = [0, 1] select (_vehicle isKindOf "Tank"); // must match eden attribute default
};
if (_spareTracks > 0) then {
[_vehicle, _spareTracks, "ACE_Track"] call FUNC(addSpareParts);
};

private _spareWheels = _vehicle getVariable QGVAR(editorLoadedWheels);
if (isNil "_spareWheels") then {
_spareWheels = [0, 1] select (_vehicle isKindOf "Car"); // must match eden attribute default
};
if (_spareWheels > 0) then {
[_vehicle, _spareWheels, "ACE_Wheel"] call FUNC(addSpareParts);
};
};

["Tank", "initPost", _fnc_addSpareItems] call CBA_fnc_addClassEventHandler;
["Car", "initPost", _fnc_addSpareItems] call CBA_fnc_addClassEventHandler;
};

ADDON = true;
1 change: 0 additions & 1 deletion addons/repair/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class CfgPatches {

#include "ACE_Repair.hpp"
#include "ACE_Settings.hpp"
#include "CfgActions.hpp"
#include "CfgEden.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgMoves.hpp"
Expand Down
2 changes: 1 addition & 1 deletion addons/repair/functions/fnc_addRepairActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Public: No
*/

if (!hasInterface) exitWith {};
if !(hasInterface && {GVAR(enabled)}) exitWith {};

params ["_vehicle"];
private _type = typeOf _vehicle;
Expand Down
26 changes: 19 additions & 7 deletions addons/repair/functions/fnc_isInRepairFacility.sqf
Dystopian marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,32 @@
* Is inside a repair facility <BOOL>
*
* Example:
* [unit] call ace_repair_fnc_isInRepairFacility
* player call ace_repair_fnc_isInRepairFacility
*
* Public: Yes
*/

#define CHECK_OBJECTS(var) ((var) findIf {(_x getVariable ["ACE_isRepairFacility", getNumber (configOf _x >> QGVAR(canRepair))] > 0) && {!(_x isKindOf "AllVehicles")} && {alive _x}} != -1)
#define CHECK_OBJECTS(var) ((var) findIf _checkObject != -1)

params [["_object", objNull, [objNull]]];
TRACE_1("params",_object);
params [["_unit", objNull, [objNull]]];
TRACE_1("params",_unit);

private _checkObject = {
private _config = configOf _x;
private _canRepair = getNumber (_config >> QGVAR(canRepair));
if (_canRepair == 0) then {
_canRepair = getNumber (_config >> "transportRepair");
};

_x getVariable ["ACE_isRepairFacility", _canRepair > 0] in [1, true] // can be integer or boolean
&& {!(_x isKindOf "AllVehicles")} // check if it's not repair vehicle
&& {alive _x}
};

private _fnc_check = {
private _position = _object modelToWorldVisual [0, 0, eyePos _object select 2];
CHECK_OBJECTS(lineIntersectsWith [ARR_3(_position, _position vectorAdd [ARR_3(0, 0, 10)], _object)]) || {CHECK_OBJECTS(_object nearObjects 7.5)}
private _position = _unit modelToWorldVisual [0, 0, eyePos _unit select 2];
CHECK_OBJECTS(lineIntersectsWith [ARR_3(_position, _position vectorAdd [ARR_3(0, 0, 10)], _unit)])
|| {CHECK_OBJECTS(_unit nearObjects 7.5)}
};

[[], _fnc_check, _object, QGVAR(inRepairFacilityCache), IN_REPAIR_FACILITY_CACHE_EXPIRY] call EFUNC(common,cachedCall);
[[], _fnc_check, _unit, QGVAR(inRepairFacilityCache), IN_REPAIR_FACILITY_CACHE_EXPIRY] call EFUNC(common,cachedCall);
9 changes: 7 additions & 2 deletions addons/repair/functions/fnc_isRepairVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Is engineering vehicle <BOOL>
*
* Example:
* [vehicle] call ace_repair_fnc_isRepairVehicle
* cursorObject call ace_repair_fnc_isRepairVehicle
*
* Public: Yes
*/
Expand All @@ -20,6 +20,11 @@ TRACE_1("params",_vehicle);

if (_vehicle isKindOf "CAManBase") exitWith {false};

private _config = configOf _vehicle;
private _canRepair = getNumber (_config >> QGVAR(canRepair));
if (_canRepair == 0) then {
_canRepair = getNumber (_config >> "transportRepair");
};
// Value can be integer or boolean
private _value = _vehicle getVariable ["ACE_isRepairVehicle", getNumber (configOf _vehicle >> QGVAR(canRepair))];
private _value = _vehicle getVariable ["ACE_isRepairVehicle", _canRepair > 0];
_value in [1, true] // return
10 changes: 10 additions & 0 deletions addons/repair/initSettings.sqf
Dystopian marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
private _category = format ["ACE %1", LLSTRING(Repair)];

[
QGVAR(enabled), "CHECKBOX",
ELSTRING(common,Enabled),
_category,
true,
true,
{[QGVAR(enabled), _this] call EFUNC(common,cbaSettings_settingChanged)},
true
] call CBA_fnc_addSetting;

[
QGVAR(displayTextOnRepair), "CHECKBOX",
[LSTRING(SettingDisplayTextName), LSTRING(SettingDisplayTextDesc)],
Expand Down