From b9638f749bc0553880082c9d7b093e9f44c316ff Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 16 Aug 2015 01:51:44 -0500 Subject: [PATCH] SetPosition Event - Fix digging down (#1991) --- addons/explosives/ACE_Triggers.hpp | 2 +- addons/explosives/CfgMagazines.hpp | 6 ++-- addons/explosives/XEH_postInit.sqf | 3 ++ .../functions/fnc_placeExplosive.sqf | 36 ++++++++++++++++--- .../functions/fnc_selectTrigger.sqf | 4 ++- .../explosives/functions/fnc_setPosition.sqf | 5 ++- .../functions/fnc_setupExplosive.sqf | 2 +- addons/explosives/script_component.hpp | 2 +- 8 files changed, 46 insertions(+), 14 deletions(-) diff --git a/addons/explosives/ACE_Triggers.hpp b/addons/explosives/ACE_Triggers.hpp index 86fbab1cef..952f360f22 100644 --- a/addons/explosives/ACE_Triggers.hpp +++ b/addons/explosives/ACE_Triggers.hpp @@ -38,7 +38,7 @@ onSetup parameters: isAttachable = 0; displayName = CSTRING(PressurePlate); picture = PATHTOF(Data\UI\PressurePlate.paa); - onPlace = "_dist=GetNumber(ConfigFile >> 'CfgMagazines' >> (_this select 2) >> 'ACE_Triggers' >> 'PressurePlate' >> 'digDistance');_ex=_this select 1;_ex setPosATL ((getPosATL _ex) vectorDiff ((VectorUp _ex) vectorCrossProduct [0,0,_dist]));false"; + onPlace = QUOTE(false); }; class IRSensor { isAttachable = 0; diff --git a/addons/explosives/CfgMagazines.hpp b/addons/explosives/CfgMagazines.hpp index b6ba37af67..d92ff08698 100644 --- a/addons/explosives/CfgMagazines.hpp +++ b/addons/explosives/CfgMagazines.hpp @@ -8,7 +8,7 @@ class CfgMagazines { class ACE_Triggers { SupportedTriggers[] = {"PressurePlate"}; class PressurePlate { - digDistance = 0.1; + digDistance = 0.06; }; }; }; @@ -17,7 +17,7 @@ class CfgMagazines { class ACE_Triggers { SupportedTriggers[] = {"PressurePlate"}; class PressurePlate { - digDistance = 0.075; + digDistance = 0.08; }; }; }; @@ -26,7 +26,7 @@ class CfgMagazines { class ACE_Triggers { SupportedTriggers[] = {"PressurePlate"}; class PressurePlate { - digDistance = 0.05; + digDistance = 0.025; }; }; }; diff --git a/addons/explosives/XEH_postInit.sqf b/addons/explosives/XEH_postInit.sqf index e269d733e5..5216db8215 100644 --- a/addons/explosives/XEH_postInit.sqf +++ b/addons/explosives/XEH_postInit.sqf @@ -15,6 +15,9 @@ */ #include "script_component.hpp" +//Event for setting explosive placement angle/pitch: +[QGVAR(place), {_this call FUNC(setPosition)}] call EFUNC(common,addEventHandler); + //When getting knocked out in medical, trigger deadman explosives: //Event is global, only run on server (ref: ace_medical_fnc_setUnconscious) if (isServer) then { diff --git a/addons/explosives/functions/fnc_placeExplosive.sqf b/addons/explosives/functions/fnc_placeExplosive.sqf index 0bb751ae64..1f9c76e1fb 100644 --- a/addons/explosives/functions/fnc_placeExplosive.sqf +++ b/addons/explosives/functions/fnc_placeExplosive.sqf @@ -25,7 +25,7 @@ params ["_unit", "_pos", "_dir", "_magazineClass", "_triggerConfig", "_triggerSpecificVars", ["_setupPlaceholderObject", objNull]]; TRACE_7("params",_unit,_pos,_dir,_magazineClass,_triggerConfig,_triggerSpecificVars,_setupPlaceholderObject); -private ["_ammo", "_explosive", "_attachedTo", "_magazineTrigger"]; +private ["_ammo", "_explosive", "_attachedTo", "_magazineTrigger", "_pitch", "_digDistance", "_canDigDown", "_soundEnviron", "_surfaceType"]; _unit playActionNow "PutDown"; @@ -54,6 +54,27 @@ if (isText(_magazineTrigger >> "ammo")) then { }; _triggerSpecificVars pushBack _triggerConfig; +//Dig the explosive down into the ground (usually on "pressurePlate") +if (isNumber (_magazineTrigger >> "digDistance")) then { + _digDistance = getNumber (_magazineTrigger >> "digDistance"); + + //Get Surface Type: + _canDigDown = true; + _surfaceType = surfaceType _pos; + if ((_surfaceType select [0,1]) == "#") then {_surfaceType = _surfaceType select [1, 99];}; + if ((_surfaceType != "") || {isClass (configfile >> "CfgSurfaces" >> _surfaceType >> "soundEnviron")}) then { + _soundEnviron = (configfile >> "CfgSurfaces" >> _surfaceType >> "soundEnviron"); + _canDigDown = !(_soundEnviron in ["road", "tarmac", "concrete", "concrete_int", "int_concrete", "concrete_ext"]); + }; + //Don't dig down if pos ATL is high (in a building or A2 road) + if (_canDigDown && {(_pos select 2) > 0.1}) then { + TRACE_2("Can Dig Down",_digDistance,_pos); + _pos = _pos vectorAdd [0,0, (-1 * _digDistance)]; + } else { + TRACE_2("Can NOT Dig Down",_digDistance,_pos); + }; +}; + _explosive = createVehicle [_ammo, _pos, [], 0, "NONE"]; _explosive setPosATL _pos; @@ -62,10 +83,17 @@ if (!isNull _attachedTo) then { _explosive attachTo [_attachedTo]; }; -if (isText(_triggerConfig >> "onPlace") && {[_unit,_explosive,_magazineClass,_triggerSpecificVars] - call compile (getText (_triggerConfig >> "onPlace"))}) exitWith {_explosive}; +//If trigger has "onPlace" and it returns true, just exitWith the explosive +if (isText(_triggerConfig >> "onPlace") && {[_unit,_explosive,_magazineClass,_triggerSpecificVars] call compile (getText (_triggerConfig >> "onPlace"))}) exitWith { + TRACE_1("onPlace returns true",_explosive); + _explosive +}; +//TODO: placing explosives on hills looks funny -[[_explosive, _dir, getNumber (_magazineTrigger >> "pitch")], QFUNC(setPosition)] call EFUNC(common,execRemoteFnc); +_pitch = getNumber (_magazineTrigger >> "pitch"); + +//Globaly set the position angle: +[QGVAR(place), [_explosive, _dir, _pitch]] call EFUNC(common,globalEvent); _explosive diff --git a/addons/explosives/functions/fnc_selectTrigger.sqf b/addons/explosives/functions/fnc_selectTrigger.sqf index d225265a68..203bfaf606 100644 --- a/addons/explosives/functions/fnc_selectTrigger.sqf +++ b/addons/explosives/functions/fnc_selectTrigger.sqf @@ -25,6 +25,8 @@ private ["_config"]; _config = ConfigFile >> "ACE_Triggers" >> _trigger; // If the onSetup function returns true, it is handled elsewhere -if (isText(_config >> "onSetup") && {[_explosive,_magazine] call compile getText (_config >> "onSetup")}) exitWith {}; +if (isText(_config >> "onSetup") && {[_explosive,_magazine] call compile getText (_config >> "onSetup")}) exitWith { + TRACE_2("onSetup returned true",_explosive,_trigger); +}; [ACE_player, getPosATL _explosive, _explosive getVariable [QGVAR(Direction), 0],_magazine, _trigger, [], _explosive] call FUNC(placeExplosive); diff --git a/addons/explosives/functions/fnc_setPosition.sqf b/addons/explosives/functions/fnc_setPosition.sqf index 8e50ac7f5e..b19e63ff5a 100644 --- a/addons/explosives/functions/fnc_setPosition.sqf +++ b/addons/explosives/functions/fnc_setPosition.sqf @@ -13,7 +13,7 @@ * Example: * [_explosive, 150, 90] call ACE_Explosives_fnc_setPosition; * - * Public: Yes + * Public: No */ #include "script_component.hpp" @@ -26,7 +26,6 @@ if (isNull (attachedTo _explosive)) then { [_explosive, _pitch, 0] call CALLSTACK(BIS_fnc_setPitchBank); }; } else { + //Attaching to a vehicle (dirAndUp based on vehicle) _explosive setVectorDirAndUp [[0,0,1],[(sin _direction),(cos _direction),0]]; }; - - diff --git a/addons/explosives/functions/fnc_setupExplosive.sqf b/addons/explosives/functions/fnc_setupExplosive.sqf index d09ebd2427..b104761fac 100644 --- a/addons/explosives/functions/fnc_setupExplosive.sqf +++ b/addons/explosives/functions/fnc_setupExplosive.sqf @@ -15,7 +15,7 @@ * * Public: Yes */ -#define ENABLE_PERFORMANCE_COUNTERS +// #define ENABLE_PERFORMANCE_COUNTERS #include "script_component.hpp" #define PLACE_RANGE_MAX 1 diff --git a/addons/explosives/script_component.hpp b/addons/explosives/script_component.hpp index 057f0aa086..17de3516a5 100644 --- a/addons/explosives/script_component.hpp +++ b/addons/explosives/script_component.hpp @@ -15,4 +15,4 @@ #define PLACE_WAITING -1 #define PLACE_CANCEL 0 -#define PLACE_APPROVE 1 \ No newline at end of file +#define PLACE_APPROVE 1