Skip to content

Commit

Permalink
update version, fix trench offset
Browse files Browse the repository at this point in the history
  • Loading branch information
nomisum committed May 7, 2023
1 parent c92ce0b commit 4b04da6
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 135 deletions.
76 changes: 38 additions & 38 deletions addons/functions/CfgDigVehicles.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
class CfgDigVehicles {

class B_APC_Tracked_01_CRV_F {
type = "animate";
animation = "moveplow";
selection = "plow";
plowRaised = 0;
plowLowered = 0.9;
distanceToTrench = 3.35;
};

class B_T_APC_Tracked_01_CRV_F {
type = "animate";
animation = "moveplow";
selection = "plow";
plowRaised = 0;
plowLowered = 0.9;
distanceToTrench = 3.35;
};

class gm_ge_army_bpz2a0 {
type = "source";
animation = "dozer_blade_elev_source";
selection = "dozer_blade_elev";
plowRaised = 0;
plowLowered = .7;
distanceToTrench = 3.35;
};

class gm_dk_army_bpz2a0 {
type = "source";
animation = "dozer_blade_elev_source";
selection = "dozer_blade_elev";
plowRaised = 0;
plowLowered = .7;
distanceToTrench = 3.35;
};
};
class CfgDigVehicles {

class B_APC_Tracked_01_CRV_F {
type = "animate";
animation = "moveplow";
selection = "plow";
plowRaised = 0;
plowLowered = 0.9;
distanceToTrench = 3;
};

class B_T_APC_Tracked_01_CRV_F {
type = "animate";
animation = "moveplow";
selection = "plow";
plowRaised = 0;
plowLowered = 0.9;
distanceToTrench = 3;
};

class gm_ge_army_bpz2a0 {
type = "source";
animation = "dozer_blade_elev_source";
selection = "dozer_blade_elev";
plowRaised = 0;
plowLowered = .7;
distanceToTrench = 3;
};

class gm_dk_army_bpz2a0 {
type = "source";
animation = "dozer_blade_elev_source";
selection = "dozer_blade_elev";
plowRaised = 0;
plowLowered = .7;
distanceToTrench = 3;
};
};
195 changes: 99 additions & 96 deletions addons/functions/functions/fnc_vehicleTrenchBuild.sqf
Original file line number Diff line number Diff line change
@@ -1,96 +1,99 @@
#include "script_component.hpp"
/*
* Author: Salbei
* Digging trenches with vehicles.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Trench Class <STRING>
* 2: Offset <ARRAY>
*
* Return Value:
* None
*
* Example:
* [vehicle ACE_player, ACE_player, [0,0,0]] call grad_trenches_functions_fnc_bpzBuild
*
* Public: No
*/

params ["_vehicle"];

private _config = configFile >> "CfgDigVehicles" >> typeOf _vehicle;
private _distanceToTrench = getNumber (_config >> "distanceToTrench");

[{
params ["_args", "_handle"];
_args params ["_vehicle", "_distanceToTrench"];

if (
isNull _vehicle ||
!(alive _vehicle)
) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
};

#define trenchHorizontalOffset -0.227
#define vehicleNotTiltedValue 0.99

// save performance
if ((_vehicle getVariable ["grad_trenches_functions_plowlowered", 0] == 0) && !(_vehicle getVariable [QGVAR(isDigging), false])) exitWith {};

// init digging
if (!(_vehicle getVariable [QGVAR(isDigging), false])) then {

// can dig vehicle on this position
if (!([_vehicle modelToWorld [trenchHorizontalOffset,_distanceToTrench,0]] call FUNC(canDig))) exitWith {};

// only work when vehicle is not tilted
if (vectorUp _vehicle select 2 < vehicleNotTiltedValue) exitWith {};

private _speed = speed _vehicle;
if (_speed > 1) then {

_vehicle setVariable [QGVAR(isDigging), true, true];
private _trench = "GRAD_envelope_vehicle" createVehicle [0,0,0];
[_trench, 0] call FUNC(setTrenchProgress);
_vehicle setVariable [QGVAR(trenchDigged), _trench, true];

[{
params ["_vehicle", "_trench", "_distanceToTrench"];
_trench setObjectTextureGlobal [0, surfaceTexture getPos _vehicle];
_trench attachTo [_vehicle, [trenchHorizontalOffset,_distanceToTrench,-5]];
}, [_vehicle, _trench, _distanceToTrench], 0.2] call CBA_fnc_waitAndExecute;
};

} else {
private _trench = _vehicle getVariable [QGVAR(trenchDigged), objNull];
private _actualProgress = _trench getVariable ["ace_trenches_progress", 0];

if (!([_vehicle modelToWorld [trenchHorizontalOffset,_distanceToTrench,0]] call FUNC(canDig))) exitWith {
detach _trench;
_vehicle setVariable [QGVAR(trenchDigged), objNull, true];
_vehicle setVariable [QGVAR(isDigging), false, true];
_trench setVariable ["ace_trenches_placeData", [getPos _trench, [vectorDir _trench, vectorUp _trench]], true];
};

private _speed = speed _vehicle;
private _digTime = missionNameSpace getVariable [QGVAR(vehicleTrenchBuildSpeed), 5];
private _diff = 1/(_digTime*10);

if (_speed > 1) then {
[_trench, _actualProgress + _diff, 0.7] call FUNC(setTrenchProgress);
_trench setObjectTextureGlobal [0, surfaceTexture position _vehicle];
[QGVAR(digFX), [_trench]] call CBA_fnc_globalEvent;
[QGVAR(digFXVehicleBlade), [_vehicle]] call CBA_fnc_globalEvent;
} else {
if (_speed < -0.5 || (vectorUp _vehicle select 2 < vehicleNotTiltedValue)) then {
detach _trench;
_vehicle setVariable [QGVAR(trenchDigged), objNull, true];
_vehicle setVariable [QGVAR(isDigging), false, true];
_trench setVariable ["ace_trenches_placeData", [getPos _trench, [vectorDir _trench, vectorUp _trench]], true];
};
};
};

}, 0.1, [_vehicle, _distanceToTrench]] call CBA_fnc_addPerFrameHandler;
#include "script_component.hpp"
/*
* Author: Salbei
* Digging trenches with vehicles.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Trench Class <STRING>
* 2: Offset <ARRAY>
*
* Return Value:
* None
*
* Example:
* [vehicle ACE_player, ACE_player, [0,0,0]] call grad_trenches_functions_fnc_bpzBuild
*
* Public: No
*/

params ["_vehicle"];

private _config = configFile >> "CfgDigVehicles" >> typeOf _vehicle;
private _distanceToTrench = getNumber (_config >> "distanceToTrench");

[{
params ["_args", "_handle"];
_args params ["_vehicle", "_distanceToTrench"];

if (
isNull _vehicle ||
!(alive _vehicle)
) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
};

// hardcoded values, adjust if vehicle_trench.p3d changes!
#define trenchHorizontalOffset -0.227
#define trenchVerticalOffset -2.25

#define vehicleNotTiltedValue 0.99

// save performance
if ((_vehicle getVariable ["grad_trenches_functions_plowlowered", 0] == 0) && !(_vehicle getVariable [QGVAR(isDigging), false])) exitWith {};

// init digging
if (!(_vehicle getVariable [QGVAR(isDigging), false])) then {

// can dig vehicle on this position
if (!([_vehicle modelToWorld [trenchHorizontalOffset,_distanceToTrench,0]] call FUNC(canDig))) exitWith {};

// only work when vehicle is not tilted
if (vectorUp _vehicle select 2 < vehicleNotTiltedValue) exitWith {};

private _speed = speed _vehicle;
if (_speed > 1) then {

_vehicle setVariable [QGVAR(isDigging), true, true];
private _trench = "GRAD_envelope_vehicle" createVehicle [0,0,0];
[_trench, 0] call FUNC(setTrenchProgress);
_vehicle setVariable [QGVAR(trenchDigged), _trench, true];

[{
params ["_vehicle", "_trench", "_distanceToTrench"];
_trench setObjectTextureGlobal [0, surfaceTexture getPos _vehicle];
_trench attachTo [_vehicle, [trenchHorizontalOffset,_distanceToTrench,trenchVerticalOffset]];
}, [_vehicle, _trench, _distanceToTrench], 0.2] call CBA_fnc_waitAndExecute;
};

} else {
private _trench = _vehicle getVariable [QGVAR(trenchDigged), objNull];
private _actualProgress = _trench getVariable ["ace_trenches_progress", 0];

if (!([_vehicle modelToWorld [trenchHorizontalOffset,_distanceToTrench,0]] call FUNC(canDig))) exitWith {
detach _trench;
_vehicle setVariable [QGVAR(trenchDigged), objNull, true];
_vehicle setVariable [QGVAR(isDigging), false, true];
_trench setVariable ["ace_trenches_placeData", [getPos _trench, [vectorDir _trench, vectorUp _trench]], true];
};

private _speed = speed _vehicle;
private _digTime = missionNameSpace getVariable [QGVAR(vehicleTrenchBuildSpeed), 5];
private _diff = 1/(_digTime*10);

if (_speed > 1) then {
[_trench, _actualProgress + _diff, 0.7] call FUNC(setTrenchProgress);
_trench setObjectTextureGlobal [0, surfaceTexture position _vehicle];
[QGVAR(digFX), [_trench]] call CBA_fnc_globalEvent;
[QGVAR(digFXVehicleBlade), [_vehicle]] call CBA_fnc_globalEvent;
} else {
if (_speed < -0.5 || (vectorUp _vehicle select 2 < vehicleNotTiltedValue)) then {
detach _trench;
_vehicle setVariable [QGVAR(trenchDigged), objNull, true];
_vehicle setVariable [QGVAR(isDigging), false, true];
_trench setVariable ["ace_trenches_placeData", [getPos _trench, [vectorDir _trench, vectorUp _trench]], true];
};
};
};

}, 0.1, [_vehicle, _distanceToTrench]] call CBA_fnc_addPerFrameHandler;
2 changes: 1 addition & 1 deletion addons/main/script_version.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define MAJOR 1
#define MINOR 6
#define PATCHLVL 9
#define BUILD 1
#define BUILD 2

0 comments on commit 4b04da6

Please sign in to comment.