From 8ff82049054bc17f5cf5473dd0bb553d7af41889 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 23 Jan 2016 20:45:59 -0300 Subject: [PATCH] Initial code implementation of ace_trenches --- addons/trenches/CfgEventHandlers.hpp | 20 +++++ addons/trenches/CfgVehicles.hpp | 47 ++++++++++ addons/trenches/CfgWeapons.hpp | 2 +- addons/trenches/XEH_postInit.sqf | 27 ++++++ addons/trenches/XEH_preInit.sqf | 22 +++++ addons/trenches/config.cpp | 7 +- .../trenches/functions/fnc_canDigTrench.sqf | 31 +++++++ addons/trenches/functions/fnc_digCancel.sqf | 36 ++++++++ addons/trenches/functions/fnc_digConfirm.sqf | 56 ++++++++++++ .../fnc_handleInteractMenuOpened.sqf | 19 ++++ .../trenches/functions/fnc_handleKilled.sqf | 19 ++++ .../functions/fnc_handlePlayerChanged.sqf | 24 +++++ .../fnc_handlePlayerInventoryChanged.sqf | 22 +++++ .../functions/fnc_handleScrollWheel.sqf | 24 +++++ .../functions/fnc_handleUnconscious.sqf | 19 ++++ addons/trenches/functions/fnc_placeTrench.sqf | 88 +++++++++++++++++++ .../trenches/functions/script_component.hpp | 1 + addons/trenches/stringtable.xml | 27 ++++-- 18 files changed, 481 insertions(+), 10 deletions(-) create mode 100644 addons/trenches/CfgEventHandlers.hpp create mode 100644 addons/trenches/XEH_postInit.sqf create mode 100644 addons/trenches/XEH_preInit.sqf create mode 100644 addons/trenches/functions/fnc_canDigTrench.sqf create mode 100644 addons/trenches/functions/fnc_digCancel.sqf create mode 100644 addons/trenches/functions/fnc_digConfirm.sqf create mode 100644 addons/trenches/functions/fnc_handleInteractMenuOpened.sqf create mode 100644 addons/trenches/functions/fnc_handleKilled.sqf create mode 100644 addons/trenches/functions/fnc_handlePlayerChanged.sqf create mode 100644 addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf create mode 100644 addons/trenches/functions/fnc_handleScrollWheel.sqf create mode 100644 addons/trenches/functions/fnc_handleUnconscious.sqf create mode 100644 addons/trenches/functions/fnc_placeTrench.sqf create mode 100644 addons/trenches/functions/script_component.hpp diff --git a/addons/trenches/CfgEventHandlers.hpp b/addons/trenches/CfgEventHandlers.hpp new file mode 100644 index 0000000000..dca07992b9 --- /dev/null +++ b/addons/trenches/CfgEventHandlers.hpp @@ -0,0 +1,20 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; + +class Extended_Killed_EventHandlers { + class CAManBase { + class ADDON { + killed = QUOTE(_this call FUNC(handleKilled)); + }; + }; +}; diff --git a/addons/trenches/CfgVehicles.hpp b/addons/trenches/CfgVehicles.hpp index 78a8987f62..3de05e3d83 100644 --- a/addons/trenches/CfgVehicles.hpp +++ b/addons/trenches/CfgVehicles.hpp @@ -1,4 +1,32 @@ class CfgVehicles { + class Man; + class CAManBase: Man { + class ACE_SelfActions { + class ACE_Equipment { + class GVAR(digEnvelopeSmall) { + displayName = CSTRING(DigEnvelopeSmall); + condition = QUOTE([ARR_2(_this select 0,'ace_trenches_trenchSmall')] call FUNC(canDigTrench)); + //wait a frame to handle "Do When releasing action menu key" option + statement = QUOTE([ARR_2({_this call FUNC(placeTrench)},[ARR_2(_this select 0,'ace_trenches_trenchSmall')])] call EFUNC(common,execNextFrame)); + exceptions[] = {}; + showDisabled = 0; + priority = 4; + //icon = PATHTOF(UI\icon_sandbag_ca.paa); + }; + class GVAR(digEnvelopeBig) { + displayName = CSTRING(DigEnvelopeBig); + condition = QUOTE([ARR_2(_this select 0,'ace_trenches_trenchBig')] call FUNC(canDigTrench)); + //wait a frame to handle "Do When releasing action menu key" option + statement = QUOTE([ARR_2({_this call FUNC(placeTrench)},[ARR_2(_this select 0,'ace_trenches_trenchBig')])] call EFUNC(common,execNextFrame)); + exceptions[] = {}; + showDisabled = 0; + priority = 4; + //icon = PATHTOF(UI\icon_sandbag_ca.paa); + }; + }; + }; + }; + class BagFence_base_F; class ACE_envelope_small: BagFence_base_F { author = ECSTRING(common,ACETeam); @@ -14,4 +42,23 @@ class CfgVehicles { model = QUOTE(PATHTOEF(apl,ace_envelope_big.p3d)); scope = 2; }; + + + class ACE_envelope_small_NoGeo: ACE_envelope_small { + scope = 1; + //@todo: replace by a no geo model + model = QUOTE(PATHTOEF(apl,ace_envelope_small.p3d)); + }; + class ACE_envelope_big_NoGeo: ACE_envelope_big { + scope = 1; + //@todo: replace by a no geo model + model = QUOTE(PATHTOEF(apl,ace_envelope_big.p3d)); + }; + + class Box_NATO_Support_F; + class ACE_Box_Misc: Box_NATO_Support_F { + class TransportItems { + MACRO_ADDITEM(ACE_EntrenchingTool,50); + }; + }; }; diff --git a/addons/trenches/CfgWeapons.hpp b/addons/trenches/CfgWeapons.hpp index 1cf85c6246..5b20e9e4c1 100644 --- a/addons/trenches/CfgWeapons.hpp +++ b/addons/trenches/CfgWeapons.hpp @@ -2,7 +2,7 @@ class CfgWeapons { class InventoryItem_Base_F; class ACE_ItemCore; - class ACE_entrenchingtool: ACE_ItemCore { + class ACE_EntrenchingTool: ACE_ItemCore { author = ECSTRING(common,ACETeam); displayName = CSTRING(EntrenchingToolName); descriptionShort = CSTRING(EntrenchingToolDescription); diff --git a/addons/trenches/XEH_postInit.sqf b/addons/trenches/XEH_postInit.sqf new file mode 100644 index 0000000000..47e0883762 --- /dev/null +++ b/addons/trenches/XEH_postInit.sqf @@ -0,0 +1,27 @@ +#include "script_component.hpp" + +if (isServer) then { + // Cancel dig on hard disconnection. Function is identical to killed + addMissionEventHandler ["HandleDisconnect", {_this call FUNC(handleKilled)}]; +}; + +if (!hasInterface) exitWith {}; + +GVAR(trench) = objNull; +GVAR(digPFH) = -1; +GVAR(digDirection) = 0; + +[{_this call FUNC(handleScrollWheel)}] call EFUNC(common,addScrollWheelEventHandler); + +// Cancel dig sandbag if interact menu opened +["interactMenuOpened", {[ACE_player] call FUNC(handleInteractMenuOpened)}] call EFUNC(common,addEventHandler); + +// Cancel dig on player change. This does work when returning to lobby, but not when hard disconnecting. +["playerChanged", {_this call FUNC(handlePlayerChanged)}] call EFUNC(common,addEventhandler); +["playerInventoryChanged", {_this call FUNC(handlePlayerInventoryChanged)}] call EFUNC(common,addEventhandler); +["playerVehicleChanged", {[ACE_player, objNull] call FUNC(handlePlayerChanged)}] call EFUNC(common,addEventhandler); + +// handle waking up dragged unit and falling unconscious while dragging +["medical_onUnconscious", {_this call FUNC(handleUnconscious)}] call EFUNC(common,addEventhandler); + +//@todo Captivity? diff --git a/addons/trenches/XEH_preInit.sqf b/addons/trenches/XEH_preInit.sqf new file mode 100644 index 0000000000..a3d9a06c16 --- /dev/null +++ b/addons/trenches/XEH_preInit.sqf @@ -0,0 +1,22 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP(canDigTrench); +PREP(digCancel); +PREP(digConfirm); +PREP(handleInteractMenuOpened); +PREP(handleKilled); +PREP(handlePlayerChanged); +PREP(handlePlayerInventoryChanged); +PREP(handleScrollWheel); +PREP(handleUnconscious); +PREP(placeTrench); + +// Trench types +// Name of the object, name of th dummy no geo object, dx, dy +GVAR(trenchSmall) = ["ACE_envelope_small", "ACE_envelope_small_NoGeo", 2, 3, 0.35]; +GVAR(trenchBig) = ["ACE_envelope_big", "ACE_envelope_big_NoGeo", 6, 1.1, 0.15]; +GVAR(trenchType) = GVAR(trenchSmall); + +ADDON = true; diff --git a/addons/trenches/config.cpp b/addons/trenches/config.cpp index 996be2348c..e2f2b5b4fe 100644 --- a/addons/trenches/config.cpp +++ b/addons/trenches/config.cpp @@ -3,13 +3,14 @@ class CfgPatches { class ADDON { units[] = {"ACE_envelope_small","ACE_envelope_big"}; - weapons[] = {"ACE_entrenchingtool"}; + weapons[] = {"ACE_EntrenchingTool"}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"ace_interaction"}; - author[] = {"Grey"}; + author[] = {"Grey", "esteldunedain"}; authorUrl = ""; VERSION_CONFIG; }; }; -#include "CfgWeapons.hpp" +#include "CfgEventHandlers.hpp" #include "CfgVehicles.hpp" +#include "CfgWeapons.hpp" diff --git a/addons/trenches/functions/fnc_canDigTrench.sqf b/addons/trenches/functions/fnc_canDigTrench.sqf new file mode 100644 index 0000000000..842b771b39 --- /dev/null +++ b/addons/trenches/functions/fnc_canDigTrench.sqf @@ -0,0 +1,31 @@ +/* + * Author: Ruthberg, commy2, esteldunedain + * Checks if a unit can dig a trench + * + * Arguments: + * 0: Unit + * 1: Trench type + * + * Return Value: + * Can dig + * + * Example: + * [ACE_player] call ace_trenches_fnc_canDigTrench + * + * Public: No + */ +#include "script_component.hpp" + +#define SURFACE_BLACKLIST ["water", "concrete", "tarmac", "wood", "metal", "roof_tin", "roof_tiles", "wood_int", "concrete_int", "tiles_int", "metal_int", "stony", "rock", "int_concrete", "int_tiles", "int_wood", "tiling", "wavymetal", "int_metal"] + +params ["_unit","_trenchTypeName"]; + +if !("ACE_EntrenchingTool" in items _unit) exitWith {false}; + +private ["_surfaceClass", "_surfaceType"]; + +_surfaceClass = (surfaceType getPosASL _unit) select [1]; +_surfaceType = getText (configFile >> "CfgSurfaces" >> _surfaceClass >> "soundEnviron"); +TRACE_1("",_surfaceType); + +!(_surfaceType in SURFACE_BLACKLIST) diff --git a/addons/trenches/functions/fnc_digCancel.sqf b/addons/trenches/functions/fnc_digCancel.sqf new file mode 100644 index 0000000000..b2e36f0170 --- /dev/null +++ b/addons/trenches/functions/fnc_digCancel.sqf @@ -0,0 +1,36 @@ +/* + * Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support + * Cancels trench dig + * + * Arguments: + * 0: unit + * + * Return Value: + * None + * + * Example: + * [ACE_player] call ace_sandbag_fnc_digCancel + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; + +// enable running again +[_unit, "forceWalk", "ACE_Trenches", false] call EFUNC(common,statusEffect_set); + +// delete placement dummy +deleteVehicle GVAR(trench); + +// remove digment 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); + +_unit setVariable [QGVAR(isDigging), false, true]; diff --git a/addons/trenches/functions/fnc_digConfirm.sqf b/addons/trenches/functions/fnc_digConfirm.sqf new file mode 100644 index 0000000000..b2103f35f3 --- /dev/null +++ b/addons/trenches/functions/fnc_digConfirm.sqf @@ -0,0 +1,56 @@ +/* + * 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 +[{ + if (isNull GVAR(trench)) exitWith {}; + + params ["_unit"]; + + private ["_position", "_direction", "_trench"]; + + _position = getPosASL GVAR(trench); + _direction = getDir GVAR(trench); + + deleteVehicle GVAR(trench); + + _trench = createVehicle [GVAR(trenchType) select 0, [0, 0, 0], [], 0, "NONE"]; + _trench setPosASL _position; + _trench setDir _direction; + + 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 new file mode 100644 index 0000000000..aa8d2b865c --- /dev/null +++ b/addons/trenches/functions/fnc_handleInteractMenuOpened.sqf @@ -0,0 +1,19 @@ +/* + * Author: commy2 + * Handle opening of interaction menu. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Public: No +*/ +#include "script_component.hpp" + +params ["_unit"]; + +if (_unit getVariable [QGVAR(isDigging), false]) then { + [_unit] call FUNC(digCancel); +}; diff --git a/addons/trenches/functions/fnc_handleKilled.sqf b/addons/trenches/functions/fnc_handleKilled.sqf new file mode 100644 index 0000000000..c2d17aab90 --- /dev/null +++ b/addons/trenches/functions/fnc_handleKilled.sqf @@ -0,0 +1,19 @@ +/* + * Author: commy2 + * Handle death. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Public: No +*/ +#include "script_component.hpp" + +params ["_unit"]; + +if (_unit getVariable [QGVAR(isDigging), false]) then { + [_unit] call FUNC(digCancel); +}; diff --git a/addons/trenches/functions/fnc_handlePlayerChanged.sqf b/addons/trenches/functions/fnc_handlePlayerChanged.sqf new file mode 100644 index 0000000000..6fce7d0297 --- /dev/null +++ b/addons/trenches/functions/fnc_handlePlayerChanged.sqf @@ -0,0 +1,24 @@ +/* + * Author: commy2 + * Handle player changes. + * + * Arguments: + * 0: New Player Unit + * 1: Old Player Unit + * + * Return Value: + * None + * + * Public: No +*/ +#include "script_component.hpp" + +params ["_newPlayer", "_oldPlayer"]; + +if (_newPlayer getVariable [QGVAR(isDigging), false]) then { + [_newPlayer] call FUNC(digCancel); +}; + +if (_oldPlayer getVariable [QGVAR(isDigging), false]) then { + [_oldPlayer] call FUNC(digCancel); +}; diff --git a/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf b/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf new file mode 100644 index 0000000000..d0c87f88ce --- /dev/null +++ b/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf @@ -0,0 +1,22 @@ +/* + * Author: commy2 + * Handle the InventoryChanged event. + * + * Arguments: + * 0: Unit + * 1: Weapon + * + * Return Value: + * None + * + * Public: No +*/ +#include "script_component.hpp" + +params ["_unit"]; + +if (_unit getVariable [QGVAR(isDigging), false]) then { + if !("ACE_EntrenchingTool" in items _unit) then { + [_unit] call FUNC(digCancel); + }; +}; diff --git a/addons/trenches/functions/fnc_handleScrollWheel.sqf b/addons/trenches/functions/fnc_handleScrollWheel.sqf new file mode 100644 index 0000000000..783463dd25 --- /dev/null +++ b/addons/trenches/functions/fnc_handleScrollWheel.sqf @@ -0,0 +1,24 @@ +/* + * Author: Garth 'L-H' de Wet, Ruthberg + * Handles sandbag rotation + * + * Arguments: + * 0: scroll amount + * + * Return Value: + * handled + * + * Example: + * [1.2] call ace_sandbag_fnc_handleScrollWheel + * + * Public: No + */ +#include "script_component.hpp" + +params ["_scroll"]; + +if (GETMVAR(ACE_Modifier,0) == 0 || GVAR(digPFH) == -1) exitWith { false }; + +GVAR(digDirection) = GVAR(digDirection) + (_scroll * 5); + +true diff --git a/addons/trenches/functions/fnc_handleUnconscious.sqf b/addons/trenches/functions/fnc_handleUnconscious.sqf new file mode 100644 index 0000000000..9c2f289559 --- /dev/null +++ b/addons/trenches/functions/fnc_handleUnconscious.sqf @@ -0,0 +1,19 @@ +/* + * Author: commy2 + * Handle unconsciousness. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Public: No +*/ +#include "script_component.hpp" + +params ["_unit"]; + +if (_unit getVariable [QGVAR(isDigging), false]) then { + [_unit] call FUNC(digCancel); +}; diff --git a/addons/trenches/functions/fnc_placeTrench.sqf b/addons/trenches/functions/fnc_placeTrench.sqf new file mode 100644 index 0000000000..12c9261503 --- /dev/null +++ b/addons/trenches/functions/fnc_placeTrench.sqf @@ -0,0 +1,88 @@ +/* + * Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support, esteldunedain + * Starts the place process for trench. + * + * Arguments: + * 0: unit + * 1: Trench type + * + * Return Value: + * None + * + * Example: + * [ACE_player] call ace_trenches_fnc_placeTrench + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit","_trenchTypeName"]; + +GVAR(trenchType) = missionNamespace getVariable _trenchTypeName; + +TRACE_2("",_trenchTypeName,GVAR(trenchType)); +// prevent the placing unit from running +[_unit, "forceWalk", "ACE_Trenches", true] call EFUNC(common,statusEffect_set); + +// create the trench +private "_trench"; +_trench = createVehicle [GVAR(trenchType) select 1, [0, 0, 0], [], 0, "NONE"]; + +GVAR(trench) = _trench; + +// prevent collisions with trench +["enableSimulationGlobal", [_trench, false]] call EFUNC(common,serverEvent); + +GVAR(digDirection) = 0; + +// pfh that runs while the dig is in progress +GVAR(digPFH) = [{ + (_this select 0) params ["_unit", "_trench"]; + + if (isNull _trench) exitWith { + [_unit] call FUNC(digCancel); + }; + + private _basePos = eyePos _unit vectorAdd (positionCameraToWorld [0, 0, 2] vectorDiff positionCameraToWorld [0, 0, 0]); + private _angle = (GVAR(digDirection) + getDir _unit); + + // Stick the trench to the ground + GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"]; + private _minz = (getTerrainHeightASL _basePos); + 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 ([cos _angle, -sin _angle, 0] vectorMultiply _ix) + vectorAdd ([sin _angle, +cos _angle, 0] vectorMultiply _iy); + _minz = _minz min (getTerrainHeightASL _pos); + + #ifdef DEBUG_MODE_FULL + _pos set [2, getTerrainHeightASL _pos]; + _pos2 = +_pos; + _pos2 set [2, getTerrainHeightASL _pos+2]; + drawLine3D [ASLtoAGL _pos, ASLtoAGL _pos2, [1,1,0,1]]; + #endif + }; + }; + _basePos set [2, _minz + _offset]; + + _trench setPosASL _basePos; + _trench setDir _angle; +}, 0, [_unit, _trench]] call CBA_fnc_addPerFrameHandler; + +// add mouse button action and hint +[localize LSTRING(ConfirmDig), localize LSTRING(CancelDig), localize LSTRING(ScrollAction)] call EFUNC(interaction,showMouseHint); + +_unit setVariable [QGVAR(Dig), [ + _unit, "DefaultAction", + {GVAR(digPFH) != -1}, + {[_this select 0] call FUNC(digConfirm)} +] call EFUNC(common,addActionEventHandler)]; + +_unit setVariable [QGVAR(Cancel), [ + _unit, "zoomtemp", + {GVAR(digPFH) != -1}, + {[_this select 0] call FUNC(digCancel)} +] call EFUNC(common,addActionEventHandler)]; + +_unit setVariable [QGVAR(isDigging), true, true]; diff --git a/addons/trenches/functions/script_component.hpp b/addons/trenches/functions/script_component.hpp new file mode 100644 index 0000000000..3747e01219 --- /dev/null +++ b/addons/trenches/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\trenches\script_component.hpp" \ No newline at end of file diff --git a/addons/trenches/stringtable.xml b/addons/trenches/stringtable.xml index e784f26c93..fc335a1b8d 100644 --- a/addons/trenches/stringtable.xml +++ b/addons/trenches/stringtable.xml @@ -1,25 +1,40 @@  - + Entrenching Tool Saperka - + Entrenching Tool Saperka, używana do budowy okopów - + Envelope - Small - + Small Personal Trench - + + Dig Small Trench + + Envelope - Big - + Large Personal Trench + + Dig Big Trench + + + Confirm Dig + + + Cancel Dig + + + +Ctrl rotate +