Add animation and progresive digging

This commit is contained in:
esteldunedain 2016-02-04 18:43:47 -03:00
parent 3d47156547
commit 4cd0028794
2 changed files with 46 additions and 7 deletions

View File

@ -7,6 +7,7 @@ if (isServer) then {
if (!hasInterface) exitWith {};
GVAR(trenchId) = 0;
GVAR(trench) = objNull;
GVAR(digPFH) = -1;
GVAR(digDirection) = 0;

View File

@ -30,9 +30,6 @@ 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(isPlacing), false, true];
// Delete placement dummy and create real trench
@ -69,9 +66,50 @@ for [{_ix = -_dx/2},{_ix <= _dx/2},{_ix = _ix + _dx/3}] do {
};
};
_basePos set [2, (_basePos select 2) + _minzoffset + _offset];
TRACE_2("",_minzoffset,_offset);
_trench setPosASL _basePos;
_trench setVectorDirAndUp [_v1, _v3];
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, "Digging trench..."] 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);