diff --git a/addons/trenches/XEH_preInit.sqf b/addons/trenches/XEH_preInit.sqf index 3ec0b00601..a5e2a47956 100644 --- a/addons/trenches/XEH_preInit.sqf +++ b/addons/trenches/XEH_preInit.sqf @@ -3,14 +3,14 @@ ADDON = false; PREP(canDigTrench); -PREP(digCancel); -PREP(digConfirm); PREP(handleInteractMenuOpened); PREP(handleKilled); PREP(handlePlayerChanged); PREP(handlePlayerInventoryChanged); PREP(handleScrollWheel); PREP(handleUnconscious); +PREP(placeCancel); +PREP(placeConfirm); PREP(placeTrench); // Trench types diff --git a/addons/trenches/functions/fnc_digConfirm.sqf b/addons/trenches/functions/fnc_digConfirm.sqf deleted file mode 100644 index 075831867f..0000000000 --- a/addons/trenches/functions/fnc_digConfirm.sqf +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support and esteldunedain - * Confirms trench dig - * - * Arguments: - * 0: unit - * - * Return Value: - * None - * - * Example: - * [ACE_player] call ace_trenches_fnc_digConfirm - * - * Public: No - */ -#include "script_component.hpp" - -params ["_unit"]; - -// enable running again -[_unit, "forceWalk", "ACE_Trenches", false] call EFUNC(common,statusEffect_set); - -// Delete placement dummy and create real trench -[{ - params ["_unit"]; - if (isNull GVAR(trench)) exitWith {}; - - deleteVehicle GVAR(trench); - private _trench = createVehicle [GVAR(trenchType) select 0, [0, 0, 0], [], 0, "NONE"]; - - GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"]; - private _basePos = GVAR(trenchPos); - private _angle = (GVAR(digDirection) + getDir _unit); - - // _v1 forward from the player, _v2 to the right, _v3 points away from the ground - private _v3 = surfaceNormal _basePos; - private _v2 = [sin _angle, +cos _angle, 0] vectorCrossProduct _v3; - private _v1 = _v3 vectorCrossProduct _v2; - - // Stick the trench to the ground - _basePos set [2, getTerrainHeightASL _basePos]; - private _minzoffset = 0; - private ["_ix","_iy"]; - for [{_ix = -_dx/2},{_ix <= _dx/2},{_ix = _ix + _dx/3}] do { - for [{_iy = -_dy/2},{_iy <= _dy/2},{_iy = _iy + _dy/3}] do { - private _pos = _basePos vectorAdd (_v2 vectorMultiply _ix) - vectorAdd (_v1 vectorMultiply _iy); - _minzoffset = _minzoffset min ((getTerrainHeightASL _pos) - (_pos select 2)); - #ifdef DEBUG_MODE_FULL - _pos set [2, getTerrainHeightASL _pos]; - _pos2 = +_pos; - _pos2 set [2, getTerrainHeightASL _pos + 1]; - drawLine3D [ASLtoAGL _pos, ASLtoAGL _pos2, [1,1,0,1]]; - #endif - }; - }; - _basePos set [2, (_basePos select 2) + _minzoffset + _offset]; - TRACE_2("",_minzoffset,_offset); - _trench setPosASL _basePos; - _trench setVectorDirAndUp [_v1, _v3]; - - GVAR(trench) = objNull; -}, [_unit], 1] call EFUNC(common,waitAndExecute); - -// remove dig pfh -[GVAR(digPFH)] call CBA_fnc_removePerFrameHandler; -GVAR(digPFH) = -1; - -// remove mouse button actions -call EFUNC(interaction,hideMouseHint); - -[_unit, "DefaultAction", _unit getVariable [QGVAR(Dig), -1]] call EFUNC(common,removeActionEventHandler); -[_unit, "zoomtemp", _unit getVariable [QGVAR(Cancel), -1]] call EFUNC(common,removeActionEventHandler); - -// play animation -_unit playActionNow "PutDown"; - -_unit setVariable [QGVAR(isDigging), false, true]; diff --git a/addons/trenches/functions/fnc_handleInteractMenuOpened.sqf b/addons/trenches/functions/fnc_handleInteractMenuOpened.sqf index aa8d2b865c..91d6b0140b 100644 --- a/addons/trenches/functions/fnc_handleInteractMenuOpened.sqf +++ b/addons/trenches/functions/fnc_handleInteractMenuOpened.sqf @@ -14,6 +14,6 @@ params ["_unit"]; -if (_unit getVariable [QGVAR(isDigging), false]) then { - [_unit] call FUNC(digCancel); +if (_unit getVariable [QGVAR(isPlacing), false]) then { + [_unit] call FUNC(placeCancel); }; diff --git a/addons/trenches/functions/fnc_handleKilled.sqf b/addons/trenches/functions/fnc_handleKilled.sqf index c2d17aab90..e9f0353cb1 100644 --- a/addons/trenches/functions/fnc_handleKilled.sqf +++ b/addons/trenches/functions/fnc_handleKilled.sqf @@ -14,6 +14,6 @@ params ["_unit"]; -if (_unit getVariable [QGVAR(isDigging), false]) then { - [_unit] call FUNC(digCancel); +if (_unit getVariable [QGVAR(isPlacing), false]) then { + [_unit] call FUNC(placeCancel); }; diff --git a/addons/trenches/functions/fnc_handlePlayerChanged.sqf b/addons/trenches/functions/fnc_handlePlayerChanged.sqf index 6fce7d0297..684ccc22ce 100644 --- a/addons/trenches/functions/fnc_handlePlayerChanged.sqf +++ b/addons/trenches/functions/fnc_handlePlayerChanged.sqf @@ -15,10 +15,10 @@ params ["_newPlayer", "_oldPlayer"]; -if (_newPlayer getVariable [QGVAR(isDigging), false]) then { - [_newPlayer] call FUNC(digCancel); +if (_newPlayer getVariable [QGVAR(isPlacing), false]) then { + [_newPlayer] call FUNC(placeCancel); }; -if (_oldPlayer getVariable [QGVAR(isDigging), false]) then { - [_oldPlayer] call FUNC(digCancel); +if (_oldPlayer getVariable [QGVAR(isPlacing), false]) then { + [_oldPlayer] call FUNC(placeCancel); }; diff --git a/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf b/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf index d0c87f88ce..cbae02d07a 100644 --- a/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf +++ b/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf @@ -15,8 +15,8 @@ params ["_unit"]; -if (_unit getVariable [QGVAR(isDigging), false]) then { +if (_unit getVariable [QGVAR(isPlacing), false]) then { if !("ACE_EntrenchingTool" in items _unit) then { - [_unit] call FUNC(digCancel); + [_unit] call FUNC(placeCancel); }; }; diff --git a/addons/trenches/functions/fnc_handleUnconscious.sqf b/addons/trenches/functions/fnc_handleUnconscious.sqf index 9c2f289559..e4fc2814b2 100644 --- a/addons/trenches/functions/fnc_handleUnconscious.sqf +++ b/addons/trenches/functions/fnc_handleUnconscious.sqf @@ -14,6 +14,6 @@ params ["_unit"]; -if (_unit getVariable [QGVAR(isDigging), false]) then { - [_unit] call FUNC(digCancel); +if (_unit getVariable [QGVAR(isPlacing), false]) then { + [_unit] call FUNC(placeCancel); }; diff --git a/addons/trenches/functions/fnc_digCancel.sqf b/addons/trenches/functions/fnc_placeCancel.sqf similarity index 89% rename from addons/trenches/functions/fnc_digCancel.sqf rename to addons/trenches/functions/fnc_placeCancel.sqf index b2e36f0170..a48d6e3f5b 100644 --- a/addons/trenches/functions/fnc_digCancel.sqf +++ b/addons/trenches/functions/fnc_placeCancel.sqf @@ -9,7 +9,7 @@ * None * * Example: - * [ACE_player] call ace_sandbag_fnc_digCancel + * [ACE_player] call ace_sandbag_fnc_placeCancel * * Public: No */ @@ -33,4 +33,4 @@ call EFUNC(interaction,hideMouseHint); [_unit, "DefaultAction", _unit getVariable [QGVAR(Dig), -1]] call EFUNC(common,removeActionEventHandler); [_unit, "zoomtemp", _unit getVariable [QGVAR(Cancel), -1]] call EFUNC(common,removeActionEventHandler); -_unit setVariable [QGVAR(isDigging), false, true]; +_unit setVariable [QGVAR(isPlacing), false, true]; diff --git a/addons/trenches/functions/fnc_placeConfirm.sqf b/addons/trenches/functions/fnc_placeConfirm.sqf new file mode 100644 index 0000000000..1b1d13d0b4 --- /dev/null +++ b/addons/trenches/functions/fnc_placeConfirm.sqf @@ -0,0 +1,77 @@ +/* + * Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support and esteldunedain + * Confirms trench dig + * + * Arguments: + * 0: unit + * + * Return Value: + * None + * + * Example: + * [ACE_player] call ace_trenches_fnc_placeConfirm + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; + +// enable running again +[_unit, "forceWalk", "ACE_Trenches", false] call EFUNC(common,statusEffect_set); + +// remove dig pfh +[GVAR(digPFH)] call CBA_fnc_removePerFrameHandler; +GVAR(digPFH) = -1; + +// remove mouse button actions +call EFUNC(interaction,hideMouseHint); + +[_unit, "DefaultAction", _unit getVariable [QGVAR(Dig), -1]] call EFUNC(common,removeActionEventHandler); +[_unit, "zoomtemp", _unit getVariable [QGVAR(Cancel), -1]] call EFUNC(common,removeActionEventHandler); + +// play animation +_unit playActionNow "PutDown"; + +_unit setVariable [QGVAR(isPlacing), false, true]; + +// Delete placement dummy and create real trench +params ["_unit"]; +if (isNull GVAR(trench)) exitWith {}; + +deleteVehicle GVAR(trench); +private _trench = createVehicle [GVAR(trenchType) select 0, [0, 0, 0], [], 0, "NONE"]; + +GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"]; +private _basePos = GVAR(trenchPos); +private _angle = (GVAR(digDirection) + getDir _unit); + +// _v1 forward from the player, _v2 to the right, _v3 points away from the ground +private _v3 = surfaceNormal _basePos; +private _v2 = [sin _angle, +cos _angle, 0] vectorCrossProduct _v3; +private _v1 = _v3 vectorCrossProduct _v2; + +// Stick the trench to the ground +_basePos set [2, getTerrainHeightASL _basePos]; +private _minzoffset = 0; +private ["_ix","_iy"]; +for [{_ix = -_dx/2},{_ix <= _dx/2},{_ix = _ix + _dx/3}] do { + for [{_iy = -_dy/2},{_iy <= _dy/2},{_iy = _iy + _dy/3}] do { + private _pos = _basePos vectorAdd (_v2 vectorMultiply _ix) + vectorAdd (_v1 vectorMultiply _iy); + _minzoffset = _minzoffset min ((getTerrainHeightASL _pos) - (_pos select 2)); + #ifdef DEBUG_MODE_FULL + _pos set [2, getTerrainHeightASL _pos]; + _pos2 = +_pos; + _pos2 set [2, getTerrainHeightASL _pos + 1]; + drawLine3D [ASLtoAGL _pos, ASLtoAGL _pos2, [1,1,0,1]]; + #endif + }; +}; +_basePos set [2, (_basePos select 2) + _minzoffset + _offset]; +TRACE_2("",_minzoffset,_offset); + +_trench setPosASL _basePos; +_trench setVectorDirAndUp [_v1, _v3]; + +GVAR(trench) = objNull; diff --git a/addons/trenches/functions/fnc_placeTrench.sqf b/addons/trenches/functions/fnc_placeTrench.sqf index 2dc3c53a73..3a678098fc 100644 --- a/addons/trenches/functions/fnc_placeTrench.sqf +++ b/addons/trenches/functions/fnc_placeTrench.sqf @@ -42,12 +42,12 @@ GVAR(digPFH) = [{ // Cancel if the helper object is gone if (isNull _trench) exitWith { - [_unit] call FUNC(digCancel); + [_unit] call FUNC(placeCancel); }; // Cancel if the place is no longer suitable if !([_unit, GVAR(trenchType)] call FUNC(canDigTrench)) exitWith { - [_unit] call FUNC(digCancel); + [_unit] call FUNC(placeCancel); }; // Update trench position @@ -92,13 +92,13 @@ GVAR(digPFH) = [{ _unit setVariable [QGVAR(Dig), [ _unit, "DefaultAction", {GVAR(digPFH) != -1}, - {[_this select 0] call FUNC(digConfirm)} + {[_this select 0] call FUNC(placeConfirm)} ] call EFUNC(common,addActionEventHandler)]; _unit setVariable [QGVAR(Cancel), [ _unit, "zoomtemp", {GVAR(digPFH) != -1}, - {[_this select 0] call FUNC(digCancel)} + {[_this select 0] call FUNC(placeCancel)} ] call EFUNC(common,addActionEventHandler)]; -_unit setVariable [QGVAR(isDigging), true, true]; +_unit setVariable [QGVAR(isPlacing), true, true];