Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remove trench and continue digging trench actions #3612

Merged
merged 4 commits into from
May 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions addons/trenches/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
class CBA_Extended_EventHandlers;

#define ACE_TRENCHES_ACTIONS class ACE_Actions { \
class ACE_MainActions { \
displayName = ECSTRING(interaction,MainAction); \
selection = ""; \
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);); \
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);); \
priority = -1; \
}; \
}; \
}

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));
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;
//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));
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;
Expand All @@ -34,16 +57,33 @@ class CfgVehicles {
descriptionShort = CSTRING(EnevlopeSmallDescription);
model = QUOTE(PATHTOEF(apl,ace_envelope_small4.p3d));
scope = 2;
GVAR(diggingDuration) = 20;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining the data here when the rest of the placement data is hard-coded in preInit is a bit inconsistent. Of course using the config is better, so we should probably migrate the rest of the data here eventually.

Ideally we could organize the data so more trench types could be added in config by third parties.

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 {};
};
};
class ACE_envelope_big: BagFence_base_F {
author = ECSTRING(common,ACETeam);
displayName = CSTRING(EnvelopeBigName);
descriptionShort = CSTRING(EnevlopeBigDescription);
model = QUOTE(PATHTOEF(apl,ace_envelope_big4.p3d));
scope = 2;
GVAR(diggingDuration) = 25;
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 {};
};
};


class ACE_envelope_small_NoGeo: ACE_envelope_small {
scope = 1;
//@todo: replace by a no geo model
Expand Down
5 changes: 5 additions & 0 deletions addons/trenches/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

PREP(canContinueDiggingTrench);
PREP(canDigTrench);
PREP(canRemoveTrench);
PREP(continueDiggingTrench);
PREP(handleInteractMenuOpened);
PREP(handleKilled);
PREP(handlePlayerChanged);
Expand All @@ -9,3 +12,5 @@ PREP(handleUnconscious);
PREP(placeCancel);
PREP(placeConfirm);
PREP(placeTrench);
PREP(removeTrench);
PREP(setTrenchPlacement);
6 changes: 0 additions & 6 deletions addons/trenches/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions addons/trenches/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CfgPatches {
VERSION_CONFIG;
};
};

#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
27 changes: 27 additions & 0 deletions addons/trenches/functions/fnc_canContinueDiggingTrench.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Author: SzwedzikPL
* Checks if a unit can continue digging a trench
*
* Arguments:
* 0: trench <OBJECT>
* 1: unit <OBJECT>
*
* Return Value:
* Can continue <BOOL>
*
* 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
9 changes: 3 additions & 6 deletions addons/trenches/functions/fnc_canDigTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Trench type <STRING>
*
* Return Value:
* Can dig <BOOL>
Expand All @@ -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)
26 changes: 26 additions & 0 deletions addons/trenches/functions/fnc_canRemoveTrench.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Author: SzwedzikPL
* Checks if a unit can remove a trench
*
* Arguments:
* 0: trench <OBJECT>
* 1: unit <OBJECT>
*
* Return Value:
* Can remove <BOOL>
*
* 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
91 changes: 91 additions & 0 deletions addons/trenches/functions/fnc_continueDiggingTrench.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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 <OBJECT>
* 1: unit <OBJECT>
*
* 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);

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;
private ["_i"];
for "_i" from _progressLeft to 10 do {
private _vectorDiffZ = 1 - (_i / 10);
private _delay = _digTime * ((_i / 10) - _actualProgress);
private _progress = _i / 10;
[DFUNC(setTrenchPlacement), [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, _vectorDiffZ], _vecDirAndUp, _progress], _delay] call EFUNC(common,waitAndExecute);
};

// Play animation
[_unit, "AinvPknlMstpSnonWnonDnon_medic4"] call EFUNC(common,doAnimation);
49 changes: 4 additions & 45 deletions addons/trenches/functions/fnc_placeConfirm.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

// 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);
_trench setVariable [QGVAR(placeData), [_basePos, _vecDirAndUp], true];

// Play animation
[_unit, "AinvPknlMstpSnonWnonDnon_medic4"] call EFUNC(common,doAnimation);
[_trench, _unit] call FUNC(continueDiggingTrench);
Loading