2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2016-01-23 23:45:59 +00:00
|
|
|
/*
|
|
|
|
* Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support, esteldunedain
|
|
|
|
* Starts the place process for trench.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: unit <OBJECT>
|
2016-03-22 07:10:37 +00:00
|
|
|
* 1: Trench class <STRING>
|
2016-01-23 23:45:59 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2016-03-22 07:10:37 +00:00
|
|
|
* [ACE_player, "ACE_envelope_small"] call ace_trenches_fnc_placeTrench
|
2016-01-23 23:45:59 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2016-03-22 07:10:37 +00:00
|
|
|
params ["_unit", "_trenchClass"];
|
2016-01-23 23:45:59 +00:00
|
|
|
|
2016-03-22 07:10:37 +00:00
|
|
|
//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));
|
2016-01-23 23:45:59 +00:00
|
|
|
|
|
|
|
// prevent the placing unit from running
|
|
|
|
[_unit, "forceWalk", "ACE_Trenches", true] call EFUNC(common,statusEffect_set);
|
2017-12-07 17:26:21 +00:00
|
|
|
[_unit, "blockThrow", "ACE_Trenches", true] call EFUNC(common,statusEffect_set);
|
2016-01-23 23:45:59 +00:00
|
|
|
|
|
|
|
// create the trench
|
2016-09-04 14:44:22 +00:00
|
|
|
private _trench = createVehicle [_noGeoModel, [0, 0, 0], [], 0, "NONE"];
|
2016-01-23 23:45:59 +00:00
|
|
|
|
|
|
|
GVAR(trench) = _trench;
|
|
|
|
|
|
|
|
// prevent collisions with trench
|
2016-06-03 19:38:16 +00:00
|
|
|
[QEGVAR(common,enableSimulationGlobal), [_trench, false]] call CBA_fnc_serverEvent;
|
2016-01-23 23:45:59 +00:00
|
|
|
|
|
|
|
GVAR(digDirection) = 0;
|
|
|
|
|
|
|
|
// pfh that runs while the dig is in progress
|
|
|
|
GVAR(digPFH) = [{
|
|
|
|
(_this select 0) params ["_unit", "_trench"];
|
|
|
|
|
2016-01-24 01:04:49 +00:00
|
|
|
// Cancel if the helper object is gone
|
2016-01-23 23:45:59 +00:00
|
|
|
if (isNull _trench) exitWith {
|
2016-02-04 20:42:12 +00:00
|
|
|
[_unit] call FUNC(placeCancel);
|
2016-01-23 23:45:59 +00:00
|
|
|
};
|
|
|
|
|
2016-01-24 01:04:49 +00:00
|
|
|
// Cancel if the place is no longer suitable
|
2016-03-22 07:10:37 +00:00
|
|
|
if !([_unit] call FUNC(canDigTrench)) exitWith {
|
2016-02-04 20:42:12 +00:00
|
|
|
[_unit] call FUNC(placeCancel);
|
2016-01-24 01:04:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Update trench position
|
2016-03-22 07:10:37 +00:00
|
|
|
GVAR(trenchPlacementData) params ["_dx", "_dy", "_offset"];
|
2016-02-04 21:47:30 +00:00
|
|
|
private _basePos = eyePos _unit vectorAdd ([sin getDir _unit, +cos getDir _unit, 0] vectorMultiply 1.0);
|
2016-01-27 20:54:40 +00:00
|
|
|
|
2016-01-23 23:45:59 +00:00
|
|
|
private _angle = (GVAR(digDirection) + getDir _unit);
|
|
|
|
|
2016-01-27 20:54:40 +00:00
|
|
|
// _v1 forward from the player, _v2 to the right, _v3 points away from the ground
|
|
|
|
private _v3 = surfaceNormal _basePos;
|
|
|
|
private _v2 = [sin _angle, +cos _angle, 0] vectorCrossProduct _v3;
|
|
|
|
private _v1 = _v3 vectorCrossProduct _v2;
|
|
|
|
|
2016-01-23 23:45:59 +00:00
|
|
|
// Stick the trench to the ground
|
2016-01-27 20:54:40 +00:00
|
|
|
_basePos set [2, getTerrainHeightASL _basePos];
|
|
|
|
private _minzoffset = 0;
|
2017-10-10 14:39:59 +00:00
|
|
|
for [{private _ix = -_dx/2},{_ix <= _dx/2},{_ix = _ix + _dx/3}] do {
|
|
|
|
for [{private _iy = -_dy/2},{_iy <= _dy/2},{_iy = _iy + _dy/3}] do {
|
2016-01-27 20:54:40 +00:00
|
|
|
private _pos = _basePos vectorAdd (_v2 vectorMultiply _ix)
|
|
|
|
vectorAdd (_v1 vectorMultiply _iy);
|
|
|
|
_minzoffset = _minzoffset min ((getTerrainHeightASL _pos) - (_pos select 2));
|
2016-01-23 23:45:59 +00:00
|
|
|
#ifdef DEBUG_MODE_FULL
|
|
|
|
_pos set [2, getTerrainHeightASL _pos];
|
|
|
|
_pos2 = +_pos;
|
2016-01-26 14:03:11 +00:00
|
|
|
_pos2 set [2, getTerrainHeightASL _pos + 1];
|
2016-01-23 23:45:59 +00:00
|
|
|
drawLine3D [ASLtoAGL _pos, ASLtoAGL _pos2, [1,1,0,1]];
|
|
|
|
#endif
|
|
|
|
};
|
2016-01-27 20:54:40 +00:00
|
|
|
};
|
|
|
|
_basePos set [2, (_basePos select 2) + _minzoffset + _offset];
|
|
|
|
TRACE_2("",_minzoffset,_offset);
|
2016-01-23 23:45:59 +00:00
|
|
|
_trench setPosASL _basePos;
|
2016-01-27 20:54:40 +00:00
|
|
|
_trench setVectorDirAndUp [_v1, _v3];
|
|
|
|
GVAR(trenchPos) = _basePos;
|
2016-01-26 14:03:11 +00:00
|
|
|
|
2016-01-23 23:45:59 +00:00
|
|
|
}, 0, [_unit, _trench]] call CBA_fnc_addPerFrameHandler;
|
|
|
|
|
|
|
|
// add mouse button action and hint
|
|
|
|
[localize LSTRING(ConfirmDig), localize LSTRING(CancelDig), localize LSTRING(ScrollAction)] call EFUNC(interaction,showMouseHint);
|
|
|
|
|
|
|
|
_unit setVariable [QGVAR(Dig), [
|
|
|
|
_unit, "DefaultAction",
|
|
|
|
{GVAR(digPFH) != -1},
|
2016-02-04 20:42:12 +00:00
|
|
|
{[_this select 0] call FUNC(placeConfirm)}
|
2016-01-23 23:45:59 +00:00
|
|
|
] call EFUNC(common,addActionEventHandler)];
|
|
|
|
|
2016-02-04 20:42:12 +00:00
|
|
|
_unit setVariable [QGVAR(isPlacing), true, true];
|