diff --git a/addons/repair/XEH_preInit.sqf b/addons/repair/XEH_preInit.sqf index 8e39bcb48d..7fac5dbcaf 100644 --- a/addons/repair/XEH_preInit.sqf +++ b/addons/repair/XEH_preInit.sqf @@ -3,6 +3,9 @@ ADDON = false; PREP(addRepairActions); +PREP(canRemoveWheel); +PREP(canRepair); +PREP(canReplaceWheel); PREP(doRepair); PREP(getWheelHitPointsWithSelections); PREP(normalizeHitPoints); diff --git a/addons/repair/functions/fnc_addRepairActions.sqf b/addons/repair/functions/fnc_addRepairActions.sqf index a0a4407847..cab3003d8a 100644 --- a/addons/repair/functions/fnc_addRepairActions.sqf +++ b/addons/repair/functions/fnc_addRepairActions.sqf @@ -41,54 +41,35 @@ _wheelHitPointSelections = _wheelHitPointsWithSelections select 1; if (_x in _wheelHitPoints) then { // add wheel repair action - private ["_nameRemove", "_nameReplace", "_icon", "_selection"]; + private ["_icon", "_selection"]; _nameRemove = format ["Remove_%1", _x]; - _nameReplace = format ["Replace_%1", _x]; _icon = QUOTE(PATHTOF(ui\tire_ca.paa)); _selection = _wheelHitPointSelections select (_wheelHitPoints find _x); - private ["_statement_remove", "_condition_remove", "_statement_replace", "_condition_replace"]; + private ["_name", "_text", "_condition", "_statement"]; - _statement_remove = format [QFUNC(removeWheel_%1), _x]; - _condition_remove = format [QFUNC(canRemoveWheel_%1), _x]; - _statement_replace = format [QFUNC(replaceWheel_%1), _x]; - _condition_replace = format [QFUNC(canReplaceWheel_%1), _x]; + // remove wheel action + _name = format ["Remove_%1", _x]; + _text = "Remove Wheel"; //@todo localize - // compile functions for that hitpoint if no such functions currently exist - if (isNil _statement_remove) then { - // remove wheel - private "_function"; - _function = compile format [QUOTE([ARR_2(_target,'%1')] call DFUNC(removeWheel)), _x]; - - missionNamespace setVariable [_statement_remove, _function]; - - _function = compile format ["alive _target && {_target getHitPointDamage '%1' < 1}", _x]; - - missionNamespace setVariable [_condition_remove, _function]; - - // replace wheel - _function = compile format [QUOTE([ARR_2(_target,'%1')] call DFUNC(replaceWheel)), _x]; - - missionNamespace setVariable [_statement_replace, _function]; - - _function = compile format ["alive _target && {_target getHitPointDamage '%1' >= 1}", _x]; - - missionNamespace setVariable [_condition_replace, _function]; - }; - - _statement_remove = missionNamespace getVariable [_statement_remove, {}]; - _condition_remove = missionNamespace getVariable [_condition_remove, {}]; - _statement_replace = missionNamespace getVariable [_statement_replace, {}]; - _condition_replace = missionNamespace getVariable [_condition_replace, {}]; + _condition = {[_this select 1, _this select 0, _this select 2 select 0] call DFUNC(canRemoveWheel)}; + _statement = {[_this select 1, _this select 0, _this select 2 select 0] call DFUNC(removeWheel)}; private "_action"; - _action = [_nameRemove, _nameRemove, _icon, _statement_remove, _condition_remove, {}, [], _selection, 2] call EFUNC(interact_menu,createAction); + _action = [_name, _text, _icon, _statement, _condition, {}, [_x], _selection, 2] call EFUNC(interact_menu,createAction); [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); - _action = [_nameReplace, _nameReplace, _icon, _statement_replace, _condition_replace, {}, [], _selection, 2] call EFUNC(interact_menu,createAction); + // replace wheel action + _name = format ["Replace_%1", _x]; + _text = "Replace Wheel"; //@todo localize + + _condition = {[_this select 1, _this select 0, _this select 2 select 0] call DFUNC(canReplaceWheel)}; + _statement = {[_this select 1, _this select 0, _this select 2 select 0] call DFUNC(replaceWheel)}; + + _action = [_name, _text, _icon, _statement, _condition, {}, [_x], _selection, 2] call EFUNC(interact_menu,createAction); [_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass); } else { @@ -100,36 +81,18 @@ _wheelHitPointSelections = _wheelHitPointsWithSelections select 1; // add misc repair action - private ["_name", "_icon", "_selection"]; + private ["_name", "_text", "_icon", "_selection", "_condition", "_statement"]; _name = format ["Repair_%1", _x]; - + _text = format ["Repair %1", _x]; //@todo localize _icon = ""; - _selection = ""; - private ["_statement", "_condition"]; - - _statement = format [QFUNC(repair_%1), _x]; - _condition = format [QFUNC(canRepair_%1), _x]; - - // compile functions for that hitpoint if no such functions currently exist - if (isNil _statement) then { - private "_function"; - _function = compile format [QUOTE([ARR_3(_player,_target,'%1')] call DFUNC(repairVehicle)), _x]; - - missionNamespace setVariable [_statement, _function]; - - _function = compile format ["alive _target && {_target getHitPointDamage '%1' > 0}", _x]; - - missionNamespace setVariable [_condition, _function]; - }; - - _statement = missionNamespace getVariable [_statement, {}]; - _condition = missionNamespace getVariable [_condition, {}]; + _condition = {[_this select 1, _this select 0, _this select 2 select 0] call DFUNC(canRepair)}; + _statement = {[_this select 1, _this select 0, _this select 2 select 0] call DFUNC(repairVehicle)}; private "_action"; - _action = [_name, _name, _icon, _statement, _condition, {}, [], _selection, 4] call EFUNC(interact_menu,createAction); + _action = [_name, _text, _icon, _statement, _condition, {}, [_x], _selection, 4] call EFUNC(interact_menu,createAction); [_type, 0, ["ACE_MainActions", QGVAR(Repair)], _action] call EFUNC(interact_menu,addActionToClass); }; diff --git a/addons/repair/functions/fnc_canRemoveWheel.sqf b/addons/repair/functions/fnc_canRemoveWheel.sqf new file mode 100644 index 0000000000..0138991503 --- /dev/null +++ b/addons/repair/functions/fnc_canRemoveWheel.sqf @@ -0,0 +1,24 @@ +/* + * Author: commy2 + * + * Check if the unit can remove given wheel of the vehicle. + * + * 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", "_target", "_hitPoint"]; + +_unit = _this select 0; +_target = _this select 1; +_hitPoint = _this select 2; + +if !([_unit, _target, []] call ace_common_fnc_canInteractWith) exitWith {false}; + +alive _target && {_target getHitPointDamage _hitPoint < 1} diff --git a/addons/repair/functions/fnc_canRepair.sqf b/addons/repair/functions/fnc_canRepair.sqf new file mode 100644 index 0000000000..22f98373aa --- /dev/null +++ b/addons/repair/functions/fnc_canRepair.sqf @@ -0,0 +1,24 @@ +/* + * Author: commy2 + * + * Check if the unit can repair given hitpoint of the vehicle. + * + * 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", "_target", "_hitPoint"]; + +_unit = _this select 0; +_target = _this select 1; +_hitPoint = _this select 2; + +if !([_unit, _target, []] call ace_common_fnc_canInteractWith) exitWith {false}; + +alive _target && {_target getHitPointDamage _hitPoint > 0} diff --git a/addons/repair/functions/fnc_canReplaceWheel.sqf b/addons/repair/functions/fnc_canReplaceWheel.sqf new file mode 100644 index 0000000000..b3e886a607 --- /dev/null +++ b/addons/repair/functions/fnc_canReplaceWheel.sqf @@ -0,0 +1,24 @@ +/* + * Author: commy2 + * + * Check if the unit can replace given wheel of the vehicle. + * + * 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", "_target", "_hitPoint"]; + +_unit = _this select 0; +_target = _this select 1; +_hitPoint = _this select 2; + +if !([_unit, _target, []] call ace_common_fnc_canInteractWith) exitWith {false}; + +alive _target && {_target getHitPointDamage _hitPoint >= 1} diff --git a/addons/repair/functions/fnc_removeWheel.sqf b/addons/repair/functions/fnc_removeWheel.sqf index 4c7aa90511..c5640fc307 100644 --- a/addons/repair/functions/fnc_removeWheel.sqf +++ b/addons/repair/functions/fnc_removeWheel.sqf @@ -1 +1 @@ -(_this select 0) setHitPointDamage [_this select 1, 1]; systemChat str _this; \ No newline at end of file +(_this select 1) setHitPointDamage [_this select 2, 1]; systemChat str _this; \ No newline at end of file diff --git a/addons/repair/functions/fnc_repairVehicle.sqf b/addons/repair/functions/fnc_repairVehicle.sqf index 211671f715..6261ccca67 100644 --- a/addons/repair/functions/fnc_repairVehicle.sqf +++ b/addons/repair/functions/fnc_repairVehicle.sqf @@ -44,3 +44,5 @@ if (isLocalized _text) then { // do animation [_unit] call EFUNC(common,goKneeling); + +// @todo play sound diff --git a/addons/repair/functions/fnc_replaceWheel.sqf b/addons/repair/functions/fnc_replaceWheel.sqf index 2e1276fe77..b3c741343a 100644 --- a/addons/repair/functions/fnc_replaceWheel.sqf +++ b/addons/repair/functions/fnc_replaceWheel.sqf @@ -1 +1 @@ -(_this select 0) setHitPointDamage [_this select 1, 0]; systemChat str _this; \ No newline at end of file +(_this select 1) setHitPointDamage [_this select 2, 0]; systemChat str _this; \ No newline at end of file