diff --git a/addons/dragging/CfgEventHandlers.hpp b/addons/dragging/CfgEventHandlers.hpp index f568eace4e..4841ae4eae 100644 --- a/addons/dragging/CfgEventHandlers.hpp +++ b/addons/dragging/CfgEventHandlers.hpp @@ -33,6 +33,11 @@ class Extended_Init_EventHandlers { init = QUOTE(_this call DFUNC(initObject)); }; }; + class ACE_RepairItem_Base { + class ADDON { + init = QUOTE(_this call DFUNC(initObject)); + }; + }; }; class Extended_Killed_EventHandlers { diff --git a/addons/dragging/CfgVehicles.hpp b/addons/dragging/CfgVehicles.hpp index 5ac84b7038..d4d791724b 100644 --- a/addons/dragging/CfgVehicles.hpp +++ b/addons/dragging/CfgVehicles.hpp @@ -83,4 +83,18 @@ class CfgVehicles { GVAR(canCarry) = 0; GVAR(canDrag) = 0; }; + + class ACE_RepairItem_Base: ThingX {}; + + class ACE_Track: ACE_RepairItem_Base { + GVAR(canCarry) = 1; + GVAR(carryPosition[]) = {0,1,1}; + GVAR(carryDirection) = 0; + }; + + class ACE_Wheel: ACE_RepairItem_Base { + GVAR(canCarry) = 1; + GVAR(carryPosition[]) = {0,1,1}; + GVAR(carryDirection) = 0; + }; }; diff --git a/addons/interaction/CfgVehicles.hpp b/addons/interaction/CfgVehicles.hpp index 02dd078a2b..2c94d1ecf8 100644 --- a/addons/interaction/CfgVehicles.hpp +++ b/addons/interaction/CfgVehicles.hpp @@ -558,4 +558,16 @@ class CfgVehicles { class ACE_SelfActions {}; }; + class ACE_RepairItem_Base: thingX { + class ACE_Actions { + class ACE_MainActions { + displayName = "$STR_ACE_Interaction_MainAction"; + selection = ""; + distance = 2; + condition = "true"; + }; + }; + class ACE_SelfActions {}; + }; + }; diff --git a/addons/repair/CfgVehicles.hpp b/addons/repair/CfgVehicles.hpp index b709fccd02..5a9bdc3cac 100644 --- a/addons/repair/CfgVehicles.hpp +++ b/addons/repair/CfgVehicles.hpp @@ -39,8 +39,9 @@ class CfgVehicles { MACRO_REPAIRVEHICLE }; - class ThingX; - class ACE_RepairItem_Base: ThingX { + class thingX; + class ACE_RepairItem_Base: thingX { + XEH_ENABLED; icon = "iconObject_circle"; mapSize = 0.7; accuracy = 0.2; diff --git a/addons/repair/XEH_postInit.sqf b/addons/repair/XEH_postInit.sqf index b5c5f7ef77..44ca157b0c 100644 --- a/addons/repair/XEH_postInit.sqf +++ b/addons/repair/XEH_postInit.sqf @@ -2,3 +2,6 @@ ["setVehicleDamage", {_this call FUNC(setDamage)}] call EFUNC(common,addEventHandler); ["setVehicleHitPointDamage", {_this call FUNC(setHitPointDamage)}] call EFUNC(common,addEventHandler); + +// wheels +["setWheelHitPointDamage", {(_this select 0) setHitPointDamage [_this select 1, _this select 2]}] call EFUNC(common,addEventHandler); diff --git a/addons/repair/XEH_preInit.sqf b/addons/repair/XEH_preInit.sqf index 7fac5dbcaf..0870f4da27 100644 --- a/addons/repair/XEH_preInit.sqf +++ b/addons/repair/XEH_preInit.sqf @@ -6,6 +6,7 @@ PREP(addRepairActions); PREP(canRemoveWheel); PREP(canRepair); PREP(canReplaceWheel); +PREP(doRemoveWheel); PREP(doRepair); PREP(getWheelHitPointsWithSelections); PREP(normalizeHitPoints); @@ -14,5 +15,6 @@ PREP(repairVehicle); PREP(replaceWheel); PREP(setDamage); PREP(setHitPointDamage); +PREP(spawnObject); ADDON = true; diff --git a/addons/repair/functions/fnc_doRemoveWheel.sqf b/addons/repair/functions/fnc_doRemoveWheel.sqf new file mode 100644 index 0000000000..75c834a9c3 --- /dev/null +++ b/addons/repair/functions/fnc_doRemoveWheel.sqf @@ -0,0 +1,44 @@ +/* + * Author: commy2 + * + * Called by repair action / progress bar. Raise events to set the new hitpoint damage. + * + * Arguments: + * Stuff from progress bar. + * + * Return Value: + * NONE + */ +#include "script_component.hpp" + +private ["_unit", "_vehicle", "_hitPoint"]; + +_unit = _this select 0 select 0; +_vehicle = _this select 0 select 1; +_hitPoint = _this select 0 select 2; + +// get current hitpoint damage +private "_hitPointDamage"; +_hitPointDamage = _vehicle getHitPointDamage _hitPoint; + +// can't remove destroyed or already removed wheel +if (_hitPointDamage >= 1) exitWith {}; + +// don't die by spawning / moving the wheel +["fixCollision", _unit] call EFUNC(common,localEvent); + +// spawn wheel +private "_wheel"; +_wheel = ["ACE_Wheel", getPosASL _unit] call FUNC(spawnObject); +_wheel setdamage _damage; + +// raise event to set the new hitpoint damage +["setWheelHitPointDamage", _vehicle, [_vehicle, _hitPoint, 1]] call EFUNC(common,targetEvent); + +// display text message if enabled +if (GVAR(DisplayTextOnRepair)) then { + private "_text"; + _text = "WHEEL REMOVED"; + + [_text] call EFUNC(common,displayTextStructured); +}; diff --git a/addons/repair/functions/fnc_removeWheel.sqf b/addons/repair/functions/fnc_removeWheel.sqf index c5640fc307..f0b984dd34 100644 --- a/addons/repair/functions/fnc_removeWheel.sqf +++ b/addons/repair/functions/fnc_removeWheel.sqf @@ -1 +1,39 @@ -(_this select 1) setHitPointDamage [_this select 2, 1]; systemChat str _this; \ No newline at end of file +/* + * Author: commy2 + * + * Start a remove wheel action and open progress bar. + * + * Arguments: + * 0: Unit that does the repairing (Object) + * 1: vehicle to repair (Object) + * 2: Selected hitpoint (String) + * + * Return Value: + * NONE + */ +#include "script_component.hpp" + +private ["_unit", "_vehicle", "_hitPoint"]; + +_unit = _this select 0; +_vehicle = _this select 1; +_hitPoint = _this select 2; + +// exit if not a valid hitpoint +if !(_hitPoint in ([_vehicle] call EFUNC(common,getHitPoints))) exitWith {}; + +// calculate time to fully repair the hitpoint +private "_time"; +_time = 10; + +// get string of the hitpoint +private "_text"; +_text = "REMOVE WHEEL"; + +// open the loading bar +[_time, [_unit, _vehicle, _hitPoint], DFUNC(doRemoveWheel), {hint "abort"}, _text, {true}, []] call EFUNC(common,progressBar); + +// do animation +[_unit] call EFUNC(common,goKneeling); + +// @todo play sound diff --git a/addons/repair/functions/fnc_spawnObject.sqf b/addons/repair/functions/fnc_spawnObject.sqf new file mode 100644 index 0000000000..a37cbded07 --- /dev/null +++ b/addons/repair/functions/fnc_spawnObject.sqf @@ -0,0 +1,21 @@ +// by commy2 +#include "script_component.hpp" + +private ["_item", "_position", "_damage"]; + +_item = _this select 0; +_position = _this select 1; +_damage = _this select 2; + +if (isNil "_damage") then {_damage = 0}; + +// randomized end position +_position = _position vectorAdd [1 - random 2, 1 - random 2, 0]; + +_item = createVehicle [_item, _position, [], 0, "NONE"]; +_item setPosASL _position; + +["fixCollision", _item] call EFUNC(common,localEvent); +["fixPosition", _item] call EFUNC(common,localEvent); + +_item setDamage _damage;