mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Add remove trench and continue digging trench actions
This commit is contained in:
parent
faa2b26cc1
commit
d6e9890b1b
@ -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
|
||||
|
@ -9,3 +9,7 @@ PREP(handleUnconscious);
|
||||
PREP(placeCancel);
|
||||
PREP(placeConfirm);
|
||||
PREP(placeTrench);
|
||||
PREP(canContinueDiggingTrench);
|
||||
PREP(canRemoveTrench);
|
||||
PREP(continueDiggingTrench);
|
||||
PREP(removeTrench);
|
||||
|
@ -11,6 +11,7 @@ class CfgPatches {
|
||||
VERSION_CONFIG;
|
||||
};
|
||||
};
|
||||
|
||||
#include "CfgEventHandlers.hpp"
|
||||
#include "CfgVehicles.hpp"
|
||||
#include "CfgWeapons.hpp"
|
||||
|
27
addons/trenches/functions/fnc_canContinueDiggingTrench.sqf
Normal file
27
addons/trenches/functions/fnc_canContinueDiggingTrench.sqf
Normal file
@ -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
|
26
addons/trenches/functions/fnc_canRemoveTrench.sqf
Normal file
26
addons/trenches/functions/fnc_canRemoveTrench.sqf
Normal file
@ -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
|
97
addons/trenches/functions/fnc_continueDiggingTrench.sqf
Normal file
97
addons/trenches/functions/fnc_continueDiggingTrench.sqf
Normal file
@ -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 <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);
|
||||
|
||||
// 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);
|
@ -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);
|
||||
|
@ -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
|
||||
*/
|
||||
|
92
addons/trenches/functions/fnc_removeTrench.sqf
Normal file
92
addons/trenches/functions/fnc_removeTrench.sqf
Normal file
@ -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 <OBJECT>
|
||||
* 1: unit <OBJECT>
|
||||
*
|
||||
* 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);
|
@ -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
|
||||
|
@ -101,5 +101,17 @@
|
||||
<Spanish>Cavando trinchera</Spanish>
|
||||
<French>Creuse la tranchée</French>
|
||||
</Key>
|
||||
<Key ID="STR_ACE_Trenches_ContinueDiggingTrench">
|
||||
<English>Continue Digging Trench</English>
|
||||
<Polish>Wzów kopanie okopu</Polish>
|
||||
</Key>
|
||||
<Key ID="STR_ACE_Trenches_RemoveEnvelope">
|
||||
<English>Remove Trench</English>
|
||||
<Polish>Usuń okop</Polish>
|
||||
</Key>
|
||||
<Key ID="STR_ACE_Trenches_RemovingTrench">
|
||||
<English>Removing Trench</English>
|
||||
<Polish>Usuwanie okopu</Polish>
|
||||
</Key>
|
||||
</Package>
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user