From d6e9890b1b612186692c10bb74c24217c9a258ce Mon Sep 17 00:00:00 2001 From: SzwedzikPL Date: Mon, 21 Mar 2016 18:25:38 +0100 Subject: [PATCH 1/4] Add remove trench and continue digging trench actions --- addons/trenches/CfgVehicles.hpp | 38 +++++++- addons/trenches/XEH_PREP.hpp | 4 + addons/trenches/config.cpp | 1 + .../fnc_canContinueDiggingTrench.sqf | 27 ++++++ .../functions/fnc_canRemoveTrench.sqf | 26 +++++ .../functions/fnc_continueDiggingTrench.sqf | 97 +++++++++++++++++++ .../trenches/functions/fnc_placeConfirm.sqf | 45 +-------- addons/trenches/functions/fnc_placeTrench.sqf | 2 +- .../trenches/functions/fnc_removeTrench.sqf | 92 ++++++++++++++++++ addons/trenches/script_component.hpp | 5 + addons/trenches/stringtable.xml | 12 +++ 11 files changed, 304 insertions(+), 45 deletions(-) create mode 100644 addons/trenches/functions/fnc_canContinueDiggingTrench.sqf create mode 100644 addons/trenches/functions/fnc_canRemoveTrench.sqf create mode 100644 addons/trenches/functions/fnc_continueDiggingTrench.sqf create mode 100644 addons/trenches/functions/fnc_removeTrench.sqf diff --git a/addons/trenches/CfgVehicles.hpp b/addons/trenches/CfgVehicles.hpp index 81880a4265..3123e9270d 100644 --- a/addons/trenches/CfgVehicles.hpp +++ b/addons/trenches/CfgVehicles.hpp @@ -1,3 +1,28 @@ +class CBA_Extended_EventHandlers; + +#define ACE_TRENCHES_ACTIONS class ACE_Actions { \ + class ACE_MainActions { \ + displayName = ECSTRING(interaction,MainAction); \ + selection = ""; \ + distance = 10; \ + condition = QUOTE(true); \ + class ACE_ContinueDiggingTrench { \ + displayName = CSTRING(ContinueDiggingTrench); \ + condition = QUOTE([ARR_2(_target,_player)] call FUNC(canContinueDiggingTrench)); \ + statement = QUOTE([ARR_2(_target,_player)] call FUNC(continueDiggingTrench);); \ + showDisabled = 0; \ + priority = -1; \ + }; \ + class ACE_RemoveTrench { \ + displayName = CSTRING(RemoveEnvelope); \ + condition = QUOTE([ARR_2(_target,_player)] call FUNC(canRemoveTrench)); \ + statement = QUOTE([ARR_2(_target,_player)] call FUNC(removeTrench);); \ + showDisabled = 0; \ + priority = -1; \ + }; \ + }; \ + } + class CfgVehicles { class Man; class CAManBase: Man { @@ -34,6 +59,12 @@ class CfgVehicles { descriptionShort = CSTRING(EnevlopeSmallDescription); model = QUOTE(PATHTOEF(apl,ace_envelope_small4.p3d)); scope = 2; + GVAR(diggingDuration) = 20; + GVAR(removalDuration) = 12; + ACE_TRENCHES_ACTIONS; + class EventHandlers { + class CBA_Extended_EventHandlers: CBA_Extended_EventHandlers {}; + }; }; class ACE_envelope_big: BagFence_base_F { author = ECSTRING(common,ACETeam); @@ -41,9 +72,14 @@ class CfgVehicles { descriptionShort = CSTRING(EnevlopeBigDescription); model = QUOTE(PATHTOEF(apl,ace_envelope_big4.p3d)); scope = 2; + GVAR(diggingDuration) = 25; + GVAR(removalDuration) = 15; + ACE_TRENCHES_ACTIONS; + class EventHandlers { + class CBA_Extended_EventHandlers: CBA_Extended_EventHandlers {}; + }; }; - class ACE_envelope_small_NoGeo: ACE_envelope_small { scope = 1; //@todo: replace by a no geo model diff --git a/addons/trenches/XEH_PREP.hpp b/addons/trenches/XEH_PREP.hpp index a9050b83bd..c0922b786c 100644 --- a/addons/trenches/XEH_PREP.hpp +++ b/addons/trenches/XEH_PREP.hpp @@ -9,3 +9,7 @@ PREP(handleUnconscious); PREP(placeCancel); PREP(placeConfirm); PREP(placeTrench); +PREP(canContinueDiggingTrench); +PREP(canRemoveTrench); +PREP(continueDiggingTrench); +PREP(removeTrench); diff --git a/addons/trenches/config.cpp b/addons/trenches/config.cpp index e2f2b5b4fe..e1b14fa37c 100644 --- a/addons/trenches/config.cpp +++ b/addons/trenches/config.cpp @@ -11,6 +11,7 @@ class CfgPatches { VERSION_CONFIG; }; }; + #include "CfgEventHandlers.hpp" #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" diff --git a/addons/trenches/functions/fnc_canContinueDiggingTrench.sqf b/addons/trenches/functions/fnc_canContinueDiggingTrench.sqf new file mode 100644 index 0000000000..2e1942d6b8 --- /dev/null +++ b/addons/trenches/functions/fnc_canContinueDiggingTrench.sqf @@ -0,0 +1,27 @@ +/* + * Author: SzwedzikPL + * Checks if a unit can continue digging a trench + * + * Arguments: + * 0: trench + * 1: unit + * + * Return Value: + * Can continue + * + * Example: + * [TrenchObj, ACE_player] call ace_trenches_fnc_canContinueDiggingTrench + * + * Public: No + */ +#include "script_component.hpp" + +params ["_trench", "_unit"]; + +if !("ACE_EntrenchingTool" in items _unit) exitWith {false}; +if ((_trench getVariable [QGVAR(progress), 0]) >= 1) exitWith {false}; + +// Prevent removing/digging trench by more than one person +if (_trench getVariable [QGVAR(digging), false]) exitWith {false}; + +true diff --git a/addons/trenches/functions/fnc_canRemoveTrench.sqf b/addons/trenches/functions/fnc_canRemoveTrench.sqf new file mode 100644 index 0000000000..4e33857637 --- /dev/null +++ b/addons/trenches/functions/fnc_canRemoveTrench.sqf @@ -0,0 +1,26 @@ +/* + * Author: SzwedzikPL + * Checks if a unit can remove a trench + * + * Arguments: + * 0: trench + * 1: unit + * + * Return Value: + * Can remove + * + * Example: + * [TrenchObj, ACE_player] call ace_trenches_fnc_canRemoveTrench + * + * Public: No + */ +#include "script_component.hpp" + +params ["_trench", "_unit"]; + +if !("ACE_EntrenchingTool" in items _unit) exitWith {false}; + +// Prevent removing/digging trench by more than one person +if (_trench getVariable [QGVAR(digging), false]) exitWith {false}; + +true diff --git a/addons/trenches/functions/fnc_continueDiggingTrench.sqf b/addons/trenches/functions/fnc_continueDiggingTrench.sqf new file mode 100644 index 0000000000..25f9fc4150 --- /dev/null +++ b/addons/trenches/functions/fnc_continueDiggingTrench.sqf @@ -0,0 +1,97 @@ +/* + * Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support, esteldunedain + * Continue process of digging trench. + * + * Arguments: + * 0: trench + * 1: unit + * + * Return Value: + * None + * + * Example: + * [TrenchObj, ACE_player] call ace_trenches_fnc_continueDiggingTrench + * + * Public: No + */ +#include "script_component.hpp" + +params ["_trench", "_unit"]; +TRACE_2("continueDiggingTrench",_trench,_unit); + +private _actualProgress = _trench getVariable [QGVAR(progress), 0]; +if(_actualProgress == 1) exitWith {}; + +// Mark trench as being worked on +_trench setVariable [QGVAR(digging), true, true]; + +private _digTime = getNumber (configFile >> "CfgVehicles" >> (typeof _trench) >> QGVAR(diggingDuration)); +private _digTimeLeft = _digTime * (1 - _actualProgress); + +private _placeData = _trench getVariable [QGVAR(placeData), [[], []]]; +_placeData params ["_basePos", "_vecDirAndUp"]; + +private _trenchId = _unit getVariable [QGVAR(isDiggingId), -1]; +if(_trenchId < 0) then { + _trenchId = GVAR(trenchId); + _unit setVariable [QGVAR(isDiggingId), _trenchId, true]; + GVAR(trenchId) = GVAR(trenchId) + 1; +}; + +// Create progress bar +private _fnc_onFinish = { + (_this select 0) params ["_unit", "_trench"]; + _unit setVariable [QGVAR(isDiggingId), -1, true]; + _trench setVariable [QGVAR(digging), false, true]; + + // Save progress global + private _progress = _trench getVariable [QGVAR(progress), 0]; + _trench setVariable [QGVAR(progress), _progress, true]; + + // Reset animation + [_unit, "", 1] call EFUNC(common,doAnimation); +}; +private _fnc_onFailure = { + (_this select 0) params ["_unit", "_trench"]; + _unit setVariable [QGVAR(isDiggingId), -1, true]; + _trench setVariable [QGVAR(digging), false, true]; + + // Save progress global + private _progress = _trench getVariable [QGVAR(progress), 0]; + _trench setVariable [QGVAR(progress), _progress, true]; + + // Reset animation + [_unit, "", 1] call EFUNC(common,doAnimation); +}; +[(_digTimeLeft + 0.5), [_unit, _trench], _fnc_onFinish, _fnc_onFailure, localize LSTRING(DiggingTrench)] call EFUNC(common,progressBar); + +// Schedule progressive raising of the trench +private _fnc_setPlacing = { + params ["_unit", "_trench", "_trenchId", "_pos", "_vecDirAndUp", "_progress"]; + + // If the progress bar was cancelled, cancel elevation + // We use an uid to avoid any chance of an older trench being raised when a new one is built + if (_unit getVariable [QGVAR(isDiggingId), -1] != _trenchId) exitWith {}; + + _trench setPosASL _pos; + _trench setVectorDirAndUp _vecDirAndUp; + + // Save progress local + _trench setVariable [QGVAR(progress), _progress]; +}; + +if(_actualProgress == 0) then { + [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 1.0], _vecDirAndUp, _actualProgress] call _fnc_setPlacing; +}; + +private _progressLeft = (_actualProgress * 10) + 1; +private ["_i"]; +for "_i" from _progressLeft to 10 do { + private _vectorDiffZ = 1 - (_i / 10); + private _delay = _digTime * ((_i / 10) - _actualProgress); + private _progress = _i / 10; + [_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, _vectorDiffZ], _vecDirAndUp, _progress], _delay] call EFUNC(common,waitAndExecute); +}; + +// Play animation +[_unit, "AinvPknlMstpSnonWnonDnon_medic4"] call EFUNC(common,doAnimation); diff --git a/addons/trenches/functions/fnc_placeConfirm.sqf b/addons/trenches/functions/fnc_placeConfirm.sqf index 47f80014f8..8a1407d2d6 100644 --- a/addons/trenches/functions/fnc_placeConfirm.sqf +++ b/addons/trenches/functions/fnc_placeConfirm.sqf @@ -66,49 +66,8 @@ for [{_ix = -_dx/2},{_ix <= _dx/2},{_ix = _ix + _dx/3}] do { }; _basePos set [2, (_basePos select 2) + _minzoffset + _offset]; private _vecDirAndUp = [_v1, _v3]; - GVAR(trench) = objNull; -// Mark the unit as digging -private _trenchId = GVAR(trenchId); -_unit setVariable [QGVAR(isDiggingId), _trenchId, true]; -GVAR(trenchId) = GVAR(trenchId) + 1; +_trench setVariable [QGVAR(placeData), [_basePos, _vecDirAndUp], true]; -// Create progress bar -private _fnc_onFinish = { - (_this select 0) params ["_unit"]; - _unit setVariable [QGVAR(isDiggingId), -1, true]; -}; -private _fnc_onFailure = { - (_this select 0) params ["_unit"]; - _unit setVariable [QGVAR(isDiggingId), -1, true]; -}; -[12.5, [_unit], _fnc_onFinish, _fnc_onFailure, localize LSTRING(DiggingTrench)] call EFUNC(common,progressBar); - -// Schedule progressive raising of the trench -private _fnc_setPlacing = { - params ["_unit", "_trench", "_trenchId", "_pos", "_vecDirAndUp"]; - - // If the progress bar was cancelled, cancel elevation - // We use an uid to avoid any chance of an older trench being raised when a new one is built - if (_unit getVariable [QGVAR(isDiggingId), -1] != _trenchId) exitWith {}; - - _trench setPosASL _pos; - _trench setVectorDirAndUp _vecDirAndUp; -}; - -// For loops are for wimps -[_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 1.0], _vecDirAndUp] call _fnc_setPlacing; -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.9], _vecDirAndUp], 3.0] call EFUNC(common,waitAndExecute); -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.8], _vecDirAndUp], 4.0] call EFUNC(common,waitAndExecute); -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.7], _vecDirAndUp], 5.0] call EFUNC(common,waitAndExecute); -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.6], _vecDirAndUp], 6.0] call EFUNC(common,waitAndExecute); -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.5], _vecDirAndUp], 7.0] call EFUNC(common,waitAndExecute); -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.4], _vecDirAndUp], 8.0] call EFUNC(common,waitAndExecute); -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.3], _vecDirAndUp], 9.0] call EFUNC(common,waitAndExecute); -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.2], _vecDirAndUp],10.0] call EFUNC(common,waitAndExecute); -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.1], _vecDirAndUp],11.0] call EFUNC(common,waitAndExecute); -[_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 0.0], _vecDirAndUp],12.0] call EFUNC(common,waitAndExecute); - -// Play animation -[_unit, "AinvPknlMstpSnonWnonDnon_medic4"] call EFUNC(common,doAnimation); +[_trench, _unit] call FUNC(continueDiggingTrench); diff --git a/addons/trenches/functions/fnc_placeTrench.sqf b/addons/trenches/functions/fnc_placeTrench.sqf index 48a768427f..b9a8bae52a 100644 --- a/addons/trenches/functions/fnc_placeTrench.sqf +++ b/addons/trenches/functions/fnc_placeTrench.sqf @@ -10,7 +10,7 @@ * None * * Example: - * [ACE_player] call ace_trenches_fnc_placeTrench + * [ACE_player, "ace_trenches_trenchBig"] call ace_trenches_fnc_placeTrench * * Public: No */ diff --git a/addons/trenches/functions/fnc_removeTrench.sqf b/addons/trenches/functions/fnc_removeTrench.sqf new file mode 100644 index 0000000000..1259d8bb9c --- /dev/null +++ b/addons/trenches/functions/fnc_removeTrench.sqf @@ -0,0 +1,92 @@ +/* + * Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support and esteldunedain + * Removes trench + * + * Arguments: + * 0: trench + * 1: unit + * + * Return Value: + * None + * + * Example: + * [TrenchObj, ACE_player] call ace_trenches_fnc_removeTrench + * + * Public: No + */ +#include "script_component.hpp" + +params ["_trench", "_unit"]; +TRACE_2("removeTrench",_trench,_unit); + +private _actualProgress = _trench getVariable [QGVAR(progress), 0]; +if(_actualProgress == 0) exitWith {}; + +// Mark trench as being worked on +_trench setVariable [QGVAR(digging), true, true]; + +private _removeTime = getNumber (configFile >> "CfgVehicles" >> (typeof _trench) >> QGVAR(removalDuration)); +private _removeTimeLeft = _removeTime * _actualProgress; + +private _placeData = _trench getVariable [QGVAR(placeData), [[], []]]; +_placeData params ["_basePos", "_vecDirAndUp"]; + +private _trenchId = _unit getVariable [QGVAR(isDiggingId), -1]; +if(_trenchId < 0) then { + _trenchId = GVAR(trenchId); + _unit setVariable [QGVAR(isDiggingId), _trenchId, true]; + GVAR(trenchId) = GVAR(trenchId) + 1; +}; + +// Create progress bar +private _fnc_onFinish = { + (_this select 0) params ["_unit", "_trench"]; + _unit setVariable [QGVAR(isDiggingId), -1, true]; + + // Remove trench + deleteVehicle _trench; + + // Reset animation + [_unit, "", 1] call EFUNC(common,doAnimation); +}; +private _fnc_onFailure = { + (_this select 0) params ["_unit", "_trench"]; + _unit setVariable [QGVAR(isDiggingId), -1, true]; + _trench setVariable [QGVAR(digging), false, true]; + + // Save progress global + private _progress = _trench getVariable [QGVAR(progress), 0]; + _trench setVariable [QGVAR(progress), _progress, true]; + + // Reset animation + [_unit, "", 1] call EFUNC(common,doAnimation); +}; +[(_removeTimeLeft + 0.5), [_unit, _trench], _fnc_onFinish, _fnc_onFailure, localize LSTRING(RemovingTrench)] call EFUNC(common,progressBar); + +// Schedule progressive raising of the trench +private _fnc_setPlacing = { + params ["_unit", "_trench", "_trenchId", "_pos", "_vecDirAndUp", "_progress"]; + + // If the progress bar was cancelled, cancel elevation + // We use an uid to avoid any chance of an older trench being raised when a new one is built + if (_unit getVariable [QGVAR(isDiggingId), -1] != _trenchId) exitWith {}; + + _trench setPosASL _pos; + _trench setVectorDirAndUp _vecDirAndUp; + + // Save progress local + _trench setVariable [QGVAR(progress), _progress]; +}; + +private _progressLeft = ((1 - _actualProgress) * 10) + 1; +private ["_i"]; +for "_i" from _progressLeft to 10 do { + private _vectorDiffZ = _i / 10; + private _delay = _removeTime * ((_i / 10) - (1 - _actualProgress)); + private _progress = 1 - (_i / 10); + + [_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, _vectorDiffZ], _vecDirAndUp, _progress], _delay] call EFUNC(common,waitAndExecute); +}; + +// Play animation +[_unit, "AinvPknlMstpSnonWnonDnon_medic4"] call EFUNC(common,doAnimation); diff --git a/addons/trenches/script_component.hpp b/addons/trenches/script_component.hpp index 3bb65ab0a6..432308fa51 100644 --- a/addons/trenches/script_component.hpp +++ b/addons/trenches/script_component.hpp @@ -1,6 +1,11 @@ #define COMPONENT trenches #include "\z\ace\addons\main\script_mod.hpp" +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE +// #define CBA_DEBUG_SYNCHRONOUS +// #define ENABLE_PERFORMANCE_COUNTERS + #ifdef DEBUG_ENABLED_TRENCHES #define DEBUG_MODE_FULL #endif diff --git a/addons/trenches/stringtable.xml b/addons/trenches/stringtable.xml index 617a604457..44c628de69 100644 --- a/addons/trenches/stringtable.xml +++ b/addons/trenches/stringtable.xml @@ -101,5 +101,17 @@ Cavando trinchera Creuse la tranchée + + Continue Digging Trench + Wzów kopanie okopu + + + Remove Trench + Usuń okop + + + Removing Trench + Usuwanie okopu + From 203c059cc1c26723c4a6c44800fbb7bfd271a1c4 Mon Sep 17 00:00:00 2001 From: SzwedzikPL Date: Tue, 22 Mar 2016 08:10:37 +0100 Subject: [PATCH 2/4] move placement data to config, setTrenchPlacement fnc, cleanup --- addons/trenches/CfgVehicles.hpp | 16 +++++---- addons/trenches/XEH_PREP.hpp | 7 ++-- addons/trenches/XEH_preInit.sqf | 6 ---- .../trenches/functions/fnc_canDigTrench.sqf | 9 ++--- .../functions/fnc_continueDiggingTrench.sqf | 19 ++--------- .../trenches/functions/fnc_placeConfirm.sqf | 4 +-- addons/trenches/functions/fnc_placeTrench.sqf | 22 ++++++++----- .../trenches/functions/fnc_removeTrench.sqf | 17 +--------- .../functions/fnc_setTrenchPlacement.sqf | 33 +++++++++++++++++++ 9 files changed, 67 insertions(+), 66 deletions(-) create mode 100644 addons/trenches/functions/fnc_setTrenchPlacement.sqf diff --git a/addons/trenches/CfgVehicles.hpp b/addons/trenches/CfgVehicles.hpp index 3123e9270d..68f4a7552a 100644 --- a/addons/trenches/CfgVehicles.hpp +++ b/addons/trenches/CfgVehicles.hpp @@ -4,20 +4,18 @@ class CBA_Extended_EventHandlers; class ACE_MainActions { \ displayName = ECSTRING(interaction,MainAction); \ selection = ""; \ - distance = 10; \ + distance = 3; \ condition = QUOTE(true); \ class ACE_ContinueDiggingTrench { \ displayName = CSTRING(ContinueDiggingTrench); \ condition = QUOTE([ARR_2(_target,_player)] call FUNC(canContinueDiggingTrench)); \ statement = QUOTE([ARR_2(_target,_player)] call FUNC(continueDiggingTrench);); \ - showDisabled = 0; \ priority = -1; \ }; \ class ACE_RemoveTrench { \ displayName = CSTRING(RemoveEnvelope); \ condition = QUOTE([ARR_2(_target,_player)] call FUNC(canRemoveTrench)); \ statement = QUOTE([ARR_2(_target,_player)] call FUNC(removeTrench);); \ - showDisabled = 0; \ priority = -1; \ }; \ }; \ @@ -30,9 +28,9 @@ class CfgVehicles { class ACE_Equipment { class GVAR(digEnvelopeSmall) { displayName = CSTRING(DigEnvelopeSmall); - condition = QUOTE([ARR_2(_this select 0,'ace_trenches_trenchSmall')] call FUNC(canDigTrench)); + condition = QUOTE(_player 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)); + statement = QUOTE([ARR_2({_this call FUNC(placeTrench)},[ARR_2(_this select 0,'ACE_envelope_small')])] call EFUNC(common,execNextFrame)); exceptions[] = {}; showDisabled = 0; priority = 4; @@ -40,9 +38,9 @@ class CfgVehicles { }; class GVAR(digEnvelopeBig) { displayName = CSTRING(DigEnvelopeBig); - condition = QUOTE([ARR_2(_this select 0,'ace_trenches_trenchBig')] call FUNC(canDigTrench)); + condition = QUOTE(_player 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)); + statement = QUOTE([ARR_2({_this call FUNC(placeTrench)},[ARR_2(_this select 0,'ACE_envelope_big')])] call EFUNC(common,execNextFrame)); exceptions[] = {}; showDisabled = 0; priority = 4; @@ -61,6 +59,8 @@ class CfgVehicles { scope = 2; GVAR(diggingDuration) = 20; GVAR(removalDuration) = 12; + GVAR(noGeoClass) = "ACE_envelope_small_NoGeo"; + GVAR(placementData)[] = {2,3,0.35}; ACE_TRENCHES_ACTIONS; class EventHandlers { class CBA_Extended_EventHandlers: CBA_Extended_EventHandlers {}; @@ -74,6 +74,8 @@ class CfgVehicles { scope = 2; GVAR(diggingDuration) = 25; GVAR(removalDuration) = 15; + GVAR(noGeoClass) = "ACE_envelope_big_NoGeo"; + GVAR(placementData)[] = {6,1.1,0.20}; ACE_TRENCHES_ACTIONS; class EventHandlers { class CBA_Extended_EventHandlers: CBA_Extended_EventHandlers {}; diff --git a/addons/trenches/XEH_PREP.hpp b/addons/trenches/XEH_PREP.hpp index c0922b786c..2e671acb85 100644 --- a/addons/trenches/XEH_PREP.hpp +++ b/addons/trenches/XEH_PREP.hpp @@ -1,5 +1,8 @@ +PREP(canContinueDiggingTrench); PREP(canDigTrench); +PREP(canRemoveTrench); +PREP(continueDiggingTrench); PREP(handleInteractMenuOpened); PREP(handleKilled); PREP(handlePlayerChanged); @@ -9,7 +12,5 @@ PREP(handleUnconscious); PREP(placeCancel); PREP(placeConfirm); PREP(placeTrench); -PREP(canContinueDiggingTrench); -PREP(canRemoveTrench); -PREP(continueDiggingTrench); PREP(removeTrench); +PREP(setTrenchPlacement); diff --git a/addons/trenches/XEH_preInit.sqf b/addons/trenches/XEH_preInit.sqf index 8b172b2b9e..a7feade1c3 100644 --- a/addons/trenches/XEH_preInit.sqf +++ b/addons/trenches/XEH_preInit.sqf @@ -4,10 +4,4 @@ ADDON = false; #include "XEH_PREP.hpp" -// 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.20]; -GVAR(trenchType) = GVAR(trenchSmall); - ADDON = true; diff --git a/addons/trenches/functions/fnc_canDigTrench.sqf b/addons/trenches/functions/fnc_canDigTrench.sqf index 9dc5e29017..0cbed2d9b7 100644 --- a/addons/trenches/functions/fnc_canDigTrench.sqf +++ b/addons/trenches/functions/fnc_canDigTrench.sqf @@ -4,7 +4,6 @@ * * Arguments: * 0: Unit - * 1: Trench type * * Return Value: * Can dig @@ -18,17 +17,15 @@ #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"]; +params ["_unit"]; if !("ACE_EntrenchingTool" in items _unit) exitWith {false}; // Can't dig trench if above ground level if ((getPosATL _unit) select 2 > 0.05) exitWith {false}; -private ["_surfaceClass", "_surfaceType"]; - -_surfaceClass = (surfaceType getPosASL _unit) select [1]; -_surfaceType = getText (configFile >> "CfgSurfaces" >> _surfaceClass >> "soundEnviron"); +private _surfaceClass = (surfaceType getPosASL _unit) select [1]; +private _surfaceType = getText (configFile >> "CfgSurfaces" >> _surfaceClass >> "soundEnviron"); TRACE_1("",_surfaceType); !(_surfaceType in SURFACE_BLACKLIST) diff --git a/addons/trenches/functions/fnc_continueDiggingTrench.sqf b/addons/trenches/functions/fnc_continueDiggingTrench.sqf index 25f9fc4150..04a2377f21 100644 --- a/addons/trenches/functions/fnc_continueDiggingTrench.sqf +++ b/addons/trenches/functions/fnc_continueDiggingTrench.sqf @@ -65,23 +65,8 @@ private _fnc_onFailure = { }; [(_digTimeLeft + 0.5), [_unit, _trench], _fnc_onFinish, _fnc_onFailure, localize LSTRING(DiggingTrench)] call EFUNC(common,progressBar); -// Schedule progressive raising of the trench -private _fnc_setPlacing = { - params ["_unit", "_trench", "_trenchId", "_pos", "_vecDirAndUp", "_progress"]; - - // If the progress bar was cancelled, cancel elevation - // We use an uid to avoid any chance of an older trench being raised when a new one is built - if (_unit getVariable [QGVAR(isDiggingId), -1] != _trenchId) exitWith {}; - - _trench setPosASL _pos; - _trench setVectorDirAndUp _vecDirAndUp; - - // Save progress local - _trench setVariable [QGVAR(progress), _progress]; -}; - if(_actualProgress == 0) then { - [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 1.0], _vecDirAndUp, _actualProgress] call _fnc_setPlacing; + [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 1.0], _vecDirAndUp, _actualProgress] call FUNC(setTrenchPlacement); }; private _progressLeft = (_actualProgress * 10) + 1; @@ -90,7 +75,7 @@ for "_i" from _progressLeft to 10 do { private _vectorDiffZ = 1 - (_i / 10); private _delay = _digTime * ((_i / 10) - _actualProgress); private _progress = _i / 10; - [_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, _vectorDiffZ], _vecDirAndUp, _progress], _delay] call EFUNC(common,waitAndExecute); + [DFUNC(setTrenchPlacement), [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, _vectorDiffZ], _vecDirAndUp, _progress], _delay] call EFUNC(common,waitAndExecute); }; // Play animation diff --git a/addons/trenches/functions/fnc_placeConfirm.sqf b/addons/trenches/functions/fnc_placeConfirm.sqf index 8a1407d2d6..7c3be2d901 100644 --- a/addons/trenches/functions/fnc_placeConfirm.sqf +++ b/addons/trenches/functions/fnc_placeConfirm.sqf @@ -36,9 +36,9 @@ params ["_unit"]; if (isNull GVAR(trench)) exitWith {}; deleteVehicle GVAR(trench); -private _trench = createVehicle [GVAR(trenchType) select 0, [0, 0, 0], [], 0, "NONE"]; +private _trench = createVehicle [GVAR(trenchClass), [0, 0, 0], [], 0, "NONE"]; -GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"]; +GVAR(trenchPlacementData) params ["_dx", "_dy", "_offset"]; private _basePos = GVAR(trenchPos); private _angle = (GVAR(digDirection) + getDir _unit); diff --git a/addons/trenches/functions/fnc_placeTrench.sqf b/addons/trenches/functions/fnc_placeTrench.sqf index b9a8bae52a..35a6706d30 100644 --- a/addons/trenches/functions/fnc_placeTrench.sqf +++ b/addons/trenches/functions/fnc_placeTrench.sqf @@ -4,29 +4,34 @@ * * Arguments: * 0: unit - * 1: Trench type + * 1: Trench class * * Return Value: * None * * Example: - * [ACE_player, "ace_trenches_trenchBig"] call ace_trenches_fnc_placeTrench + * [ACE_player, "ACE_envelope_small"] call ace_trenches_fnc_placeTrench * * Public: No */ #include "script_component.hpp" -params ["_unit","_trenchTypeName"]; +params ["_unit", "_trenchClass"]; -GVAR(trenchType) = missionNamespace getVariable _trenchTypeName; +//Load trench data +private _noGeoModel = getText (configFile >> "CfgVehicles" >> _trenchClass >> QGVAR(noGeoClass)); +if(_noGeoModel == "") then {_noGeoModel = _trenchClass;}; + +GVAR(trenchClass) = _trenchClass; +GVAR(trenchPlacementData) = getArray (configFile >> "CfgVehicles" >> _trenchClass >> QGVAR(placementData)); +TRACE_1("",GVAR(trenchPlacementData)); -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"]; +_trench = createVehicle [_noGeoModel, [0, 0, 0], [], 0, "NONE"]; GVAR(trench) = _trench; @@ -38,7 +43,6 @@ GVAR(digDirection) = 0; // pfh that runs while the dig is in progress GVAR(digPFH) = [{ (_this select 0) params ["_unit", "_trench"]; - GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"]; // Cancel if the helper object is gone if (isNull _trench) exitWith { @@ -46,12 +50,12 @@ GVAR(digPFH) = [{ }; // Cancel if the place is no longer suitable - if !([_unit, GVAR(trenchType)] call FUNC(canDigTrench)) exitWith { + if !([_unit] call FUNC(canDigTrench)) exitWith { [_unit] call FUNC(placeCancel); }; // Update trench position - GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"]; + GVAR(trenchPlacementData) params ["_dx", "_dy", "_offset"]; private _basePos = eyePos _unit vectorAdd ([sin getDir _unit, +cos getDir _unit, 0] vectorMultiply 1.0); private _angle = (GVAR(digDirection) + getDir _unit); diff --git a/addons/trenches/functions/fnc_removeTrench.sqf b/addons/trenches/functions/fnc_removeTrench.sqf index 1259d8bb9c..dd51bbbae5 100644 --- a/addons/trenches/functions/fnc_removeTrench.sqf +++ b/addons/trenches/functions/fnc_removeTrench.sqf @@ -63,21 +63,6 @@ private _fnc_onFailure = { }; [(_removeTimeLeft + 0.5), [_unit, _trench], _fnc_onFinish, _fnc_onFailure, localize LSTRING(RemovingTrench)] call EFUNC(common,progressBar); -// Schedule progressive raising of the trench -private _fnc_setPlacing = { - params ["_unit", "_trench", "_trenchId", "_pos", "_vecDirAndUp", "_progress"]; - - // If the progress bar was cancelled, cancel elevation - // We use an uid to avoid any chance of an older trench being raised when a new one is built - if (_unit getVariable [QGVAR(isDiggingId), -1] != _trenchId) exitWith {}; - - _trench setPosASL _pos; - _trench setVectorDirAndUp _vecDirAndUp; - - // Save progress local - _trench setVariable [QGVAR(progress), _progress]; -}; - private _progressLeft = ((1 - _actualProgress) * 10) + 1; private ["_i"]; for "_i" from _progressLeft to 10 do { @@ -85,7 +70,7 @@ for "_i" from _progressLeft to 10 do { private _delay = _removeTime * ((_i / 10) - (1 - _actualProgress)); private _progress = 1 - (_i / 10); - [_fnc_setPlacing, [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, _vectorDiffZ], _vecDirAndUp, _progress], _delay] call EFUNC(common,waitAndExecute); + [DFUNC(setTrenchPlacement), [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, _vectorDiffZ], _vecDirAndUp, _progress], _delay] call EFUNC(common,waitAndExecute); }; // Play animation diff --git a/addons/trenches/functions/fnc_setTrenchPlacement.sqf b/addons/trenches/functions/fnc_setTrenchPlacement.sqf new file mode 100644 index 0000000000..49c1efdaae --- /dev/null +++ b/addons/trenches/functions/fnc_setTrenchPlacement.sqf @@ -0,0 +1,33 @@ +/* + * Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support and esteldunedain + * Sets trench placement + * + * Arguments: + * 0: unit + * 1: trench + * 2: trench id + * 3: position ASL + * 4: vector dir and up + * 5: progress + * + * Return Value: + * None + * + * Example: + * [ACE_player, TrenchObj, 2, [0,0,0], [[0,0,0],[0,0,0]], 0.5] call ace_trenches_fnc_setTrenchPlacement + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit", "_trench", "_trenchId", "_pos", "_vecDirAndUp", "_progress"]; + +// If the progress bar was cancelled, cancel elevation +// We use an uid to avoid any chance of an older trench being raised when a new one is built +if (_unit getVariable [QGVAR(isDiggingId), -1] != _trenchId) exitWith {}; + +_trench setPosASL _pos; +_trench setVectorDirAndUp _vecDirAndUp; + +// Save progress local +_trench setVariable [QGVAR(progress), _progress]; From 10d20472d3303cdfb3ff3129bbd79f690567c41e Mon Sep 17 00:00:00 2001 From: SzwedzikPL Date: Tue, 22 Mar 2016 11:26:40 +0100 Subject: [PATCH 3/4] Remove grass behind the trench --- addons/trenches/CfgVehicles.hpp | 2 ++ addons/trenches/functions/fnc_continueDiggingTrench.sqf | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/addons/trenches/CfgVehicles.hpp b/addons/trenches/CfgVehicles.hpp index 68f4a7552a..8e1eb41fd0 100644 --- a/addons/trenches/CfgVehicles.hpp +++ b/addons/trenches/CfgVehicles.hpp @@ -61,6 +61,7 @@ class CfgVehicles { GVAR(removalDuration) = 12; GVAR(noGeoClass) = "ACE_envelope_small_NoGeo"; GVAR(placementData)[] = {2,3,0.35}; + GVAR(grassCuttingPoints)[] = {{0,-0.5,0}}; ACE_TRENCHES_ACTIONS; class EventHandlers { class CBA_Extended_EventHandlers: CBA_Extended_EventHandlers {}; @@ -76,6 +77,7 @@ class CfgVehicles { GVAR(removalDuration) = 15; GVAR(noGeoClass) = "ACE_envelope_big_NoGeo"; GVAR(placementData)[] = {6,1.1,0.20}; + GVAR(grassCuttingPoints)[] = {{-1.5,-1,0},{1.5,-1,0}}; ACE_TRENCHES_ACTIONS; class EventHandlers { class CBA_Extended_EventHandlers: CBA_Extended_EventHandlers {}; diff --git a/addons/trenches/functions/fnc_continueDiggingTrench.sqf b/addons/trenches/functions/fnc_continueDiggingTrench.sqf index 04a2377f21..223dc42df6 100644 --- a/addons/trenches/functions/fnc_continueDiggingTrench.sqf +++ b/addons/trenches/functions/fnc_continueDiggingTrench.sqf @@ -67,6 +67,15 @@ private _fnc_onFailure = { if(_actualProgress == 0) then { [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 1.0], _vecDirAndUp, _actualProgress] call FUNC(setTrenchPlacement); + + //Remove grass + { + private _trenchGrassCutter = createVehicle ["Land_ClutterCutter_medium_F", [0, 0, 0], [], 0, "NONE"]; + private _cutterPos = AGLToASL (_trench modelToWorld _x); + _cutterPos set [2, getTerrainHeightASL _cutterPos]; + _trenchGrassCutter setPosASL _cutterPos; + deleteVehicle _trenchGrassCutter; + } foreach getArray (configFile >> "CfgVehicles" >> (typeof _trench) >> QGVAR(grassCuttingPoints)); }; private _progressLeft = (_actualProgress * 10) + 1; From 9b1b4a46fa8a3c00efa5cffa011c9bb2dd6ab427 Mon Sep 17 00:00:00 2001 From: SzwedzikPL Date: Wed, 23 Mar 2016 17:17:16 +0100 Subject: [PATCH 4/4] better polish translation --- addons/trenches/stringtable.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/trenches/stringtable.xml b/addons/trenches/stringtable.xml index 44c628de69..5af459f7f8 100644 --- a/addons/trenches/stringtable.xml +++ b/addons/trenches/stringtable.xml @@ -96,22 +96,22 @@ Digging Trench Grabe Schützengraben - Kopanie okopu + Kopanie wnęki Sto Scavando la Trincea Cavando trinchera Creuse la tranchée Continue Digging Trench - Wzów kopanie okopu + Wzów kopanie wnęki Remove Trench - Usuń okop + Usuń wnękę Removing Trench - Usuwanie okopu + Usuwanie wnęki