2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-03-21 17:25:38 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_trench", "_unit"];
|
|
|
|
TRACE_2("continueDiggingTrench",_trench,_unit);
|
|
|
|
|
2020-06-05 16:35:32 +00:00
|
|
|
private _actualProgress = _trench getVariable [QGVAR(progress), 1];
|
2016-03-21 17:25:38 +00:00
|
|
|
if(_actualProgress == 1) exitWith {};
|
|
|
|
|
|
|
|
// Mark trench as being worked on
|
|
|
|
_trench setVariable [QGVAR(digging), true, true];
|
|
|
|
|
2021-02-18 18:58:08 +00:00
|
|
|
private _digTime = missionNamespace getVariable [getText (configOf _trench >> QGVAR(diggingDuration)), 20];
|
2016-03-21 17:25:38 +00:00
|
|
|
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];
|
|
|
|
|
2022-08-20 20:43:50 +00:00
|
|
|
[QGVAR(finished), [_unit, _trench]] call CBA_fnc_globalEvent;
|
|
|
|
|
2016-03-21 17:25:38 +00:00
|
|
|
// 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);
|
|
|
|
};
|
2019-11-27 15:51:22 +00:00
|
|
|
private _fnc_condition = {
|
|
|
|
(_this select 0) params ["_unit"];
|
2022-09-04 22:21:29 +00:00
|
|
|
_unit call FUNC(hasEntrenchingTool)
|
2019-11-27 15:51:22 +00:00
|
|
|
};
|
|
|
|
[(_digTimeLeft + 0.5), [_unit, _trench], _fnc_onFinish, _fnc_onFailure, localize LSTRING(DiggingTrench), _fnc_condition] call EFUNC(common,progressBar);
|
2016-03-21 17:25:38 +00:00
|
|
|
|
|
|
|
if(_actualProgress == 0) then {
|
2016-03-22 07:10:37 +00:00
|
|
|
[_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, 1.0], _vecDirAndUp, _actualProgress] call FUNC(setTrenchPlacement);
|
2016-03-22 10:26:40 +00:00
|
|
|
|
|
|
|
//Remove grass
|
|
|
|
{
|
|
|
|
private _trenchGrassCutter = createVehicle ["Land_ClutterCutter_medium_F", [0, 0, 0], [], 0, "NONE"];
|
2021-10-10 13:37:05 +00:00
|
|
|
private _cutterPos = _trench modelToWorldWorld _x;
|
2016-03-22 10:26:40 +00:00
|
|
|
_cutterPos set [2, getTerrainHeightASL _cutterPos];
|
|
|
|
_trenchGrassCutter setPosASL _cutterPos;
|
|
|
|
deleteVehicle _trenchGrassCutter;
|
2021-02-18 18:58:08 +00:00
|
|
|
} foreach getArray (configOf _trench >> QGVAR(grassCuttingPoints));
|
2016-03-21 17:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private _progressLeft = (_actualProgress * 10) + 1;
|
2017-10-10 14:39:59 +00:00
|
|
|
|
2016-03-21 17:25:38 +00:00
|
|
|
for "_i" from _progressLeft to 10 do {
|
|
|
|
private _vectorDiffZ = 1 - (_i / 10);
|
|
|
|
private _delay = _digTime * ((_i / 10) - _actualProgress);
|
|
|
|
private _progress = _i / 10;
|
2016-05-22 13:27:24 +00:00
|
|
|
[DFUNC(setTrenchPlacement), [_unit, _trench, _trenchId, _basePos vectorDiff [0, 0, _vectorDiffZ], _vecDirAndUp, _progress], _delay] call CBA_fnc_waitAndExecute;
|
2016-03-21 17:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Play animation
|
|
|
|
[_unit, "AinvPknlMstpSnonWnonDnon_medic4"] call EFUNC(common,doAnimation);
|