From 104d1a1cc77602fdcf53c03a5d231360d81ffd72 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 15 Jul 2015 02:54:38 -0500 Subject: [PATCH] Attaching (Rotate to verticle) --- addons/explosives/CfgMagazines.hpp | 6 +- addons/explosives/XEH_postInit.sqf | 13 +- addons/explosives/XEH_preInit.sqf | 4 - addons/explosives/functions/fnc_onLanded.sqf | 45 ----- .../functions/fnc_place_Approve.sqf | 46 ----- .../explosives/functions/fnc_place_Cancel.sqf | 32 ---- .../functions/fnc_setupExplosive.sqf | 177 ++++++++++-------- 7 files changed, 108 insertions(+), 215 deletions(-) delete mode 100644 addons/explosives/functions/fnc_onLanded.sqf delete mode 100644 addons/explosives/functions/fnc_place_Approve.sqf delete mode 100644 addons/explosives/functions/fnc_place_Cancel.sqf diff --git a/addons/explosives/CfgMagazines.hpp b/addons/explosives/CfgMagazines.hpp index 39d08917c3..b6ba37af67 100644 --- a/addons/explosives/CfgMagazines.hpp +++ b/addons/explosives/CfgMagazines.hpp @@ -96,7 +96,7 @@ class CfgMagazines { }; }; }; - + class IEDUrbanBig_Remote_Mag: DemoCharge_Remote_Mag { ACE_SetupObject = "ACE_Explosives_Place_IEDUrbanBig"; class ACE_Triggers { @@ -113,9 +113,9 @@ class CfgMagazines { ammo = "IEDUrbanBig_Range_Ammo"; pitch = 0; }; - }; + }; }; - + class IEDLandBig_Remote_Mag: IEDUrbanBig_Remote_Mag { ACE_SetupObject = "ACE_Explosives_Place_IEDLandBig"; class ACE_Triggers: ACE_Triggers { diff --git a/addons/explosives/XEH_postInit.sqf b/addons/explosives/XEH_postInit.sqf index 27a4703906..836631efdd 100644 --- a/addons/explosives/XEH_postInit.sqf +++ b/addons/explosives/XEH_postInit.sqf @@ -17,18 +17,21 @@ if !(hasInterface) exitWith {}; -["interactMenuOpened", {_this call FUNC(interactEH)}] call EFUNC(common,addEventHandler); - GVAR(PlacedCount) = 0; GVAR(Setup) = objNull; GVAR(pfeh_running) = false; GVAR(CurrentSpeedDial) = 0; -//Cancel placement if interact menu opened + ["interactMenuOpened", { - if (GVAR(pfeh_running) && {!isNull (GVAR(Setup))}) then { - call FUNC(place_Cancel) + //Cancel placement if interact menu opened + if (GVAR(pfeh_running)) then { + GVAR(placeAction) = PLACE_CANCEL; }; + + //Show defuse actions on cfgAmmos (allMines): + _this call FUNC(interactEH); + }] call EFUNC(common,addEventHandler); [{(_this select 0) call FUNC(handleScrollWheel);}] call EFUNC(Common,addScrollWheelEventHandler); diff --git a/addons/explosives/XEH_preInit.sqf b/addons/explosives/XEH_preInit.sqf index b3888e1535..fc1b02e1bc 100644 --- a/addons/explosives/XEH_preInit.sqf +++ b/addons/explosives/XEH_preInit.sqf @@ -46,13 +46,9 @@ PREP(module); PREP(onInventoryChanged); PREP(onKilled); -PREP(onLanded); PREP(openTimerSetUI); -PREP(place_Approve); -PREP(place_Cancel); - PREP(placeExplosive); PREP(removeFromSpeedDial); diff --git a/addons/explosives/functions/fnc_onLanded.sqf b/addons/explosives/functions/fnc_onLanded.sqf deleted file mode 100644 index f2ed729b1a..0000000000 --- a/addons/explosives/functions/fnc_onLanded.sqf +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Handles the "EpeContactStart" event when placing the explosive. - * - * Arguments: - * 0: Explosive Placing Object - * 1: Colliding Object - * - * Return Value: - * None - * - * Example: - * object addEventHandler ["EpeContactStart", ACE_explosive_fnc_onLanded]; - * - * Public: No - */ -#include "script_component.hpp" -EXPLODE_2_PVT(_this,_explosive,_hitTarget); - -TRACE_2("Explosive EpeContactStart",_explosive,_hitTarget); - -if ((_explosive getVariable [QGVAR(Handled), false])) exitWith {}; - -_explosive setVariable [QGVAR(Handled), true]; -if (!isNull _hitTarget && {_hitTarget isKindOf "AllVehicles"}) then { - TRACE_1("Attaching to",_hitTarget); - _explosive attachTo [_hitTarget]; - private "_dir"; - _dir = _explosive getVariable [QGVAR(Direction), 0]; - _dir = _dir - (getDir _hitTarget); - [[_explosive, _dir, 0], QFUNC(setPosition)] call EFUNC(common,execRemoteFnc); -} else { - [{ - EXPLODE_2_PVT(_this,_player,_explosive); - private "_pos"; - _pos = getPosASL _explosive; - if (surfaceIsWater _pos) then { - _pos = getPosASL _explosive; - _explosive setPosASL _pos; - }else{ - _pos = getPosATL _explosive; - _explosive setPosATL _pos; - }; - }, [ACE_player, _explosive], 0.5, 0.1] call EFUNC(common,waitAndExecute); -}; diff --git a/addons/explosives/functions/fnc_place_Approve.sqf b/addons/explosives/functions/fnc_place_Approve.sqf deleted file mode 100644 index 0604045f65..0000000000 --- a/addons/explosives/functions/fnc_place_Approve.sqf +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Approves placement of the explosive, releases the placement object for it - * to settle in a location suitable for the explosive to be created. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * call ACE_Explosives_fnc_place_Approve; - * - * Public: No - */ -#include "script_component.hpp" -if (GVAR(pfeh_running)) then { - [QGVAR(Placement),"OnEachFrame"] call CALLSTACK(BIS_fnc_removeStackedEventHandler); - GVAR(pfeh_running) = false; -}; -private ["_setup", "_player", "_dir"]; -_setup = GVAR(Setup); -GVAR(Setup) = objNull; -[GVAR(placer), "ACE_Explosives", false] call EFUNC(Common,setForceWalkStatus); -[ACE_player, "DefaultAction", ACE_player getVariable [QGVAR(Place), -1]] call EFUNC(Common,removeActionEventHandler); -[ACE_player, "zoomtemp", ACE_player getVariable [QGVAR(Cancel), -1]] call EFUNC(Common,removeActionEventHandler); -GVAR(placer) = objNull; -_player = ACE_player; -call EFUNC(interaction,hideMouseHint); -if ((_setup getVariable [QGVAR(Class), ""]) == "") exitWith { - deleteVehicle _setup; -}; -_dir = (getDir _setup); -if (_dir > 180) then { - _dir = _dir - 180; -} else { - _dir = 180 + _dir; -}; -_setup setVariable [QGVAR(Direction), _dir, true]; -_player setVariable [QGVAR(PlantingExplosive), true]; -[{_this setVariable [QGVAR(PlantingExplosive), false]}, _player, 1.5, 0.5] call EFUNC(common,waitAndExecute); -_setup addEventHandler ["EpeContactStart", FUNC(onLanded)]; -_setup enableSimulationGlobal true; -_player playActionNow "PutDown"; -_player removeMagazine (_setup getVariable [QGVAR(Class), ""]); diff --git a/addons/explosives/functions/fnc_place_Cancel.sqf b/addons/explosives/functions/fnc_place_Cancel.sqf deleted file mode 100644 index 78d718e283..0000000000 --- a/addons/explosives/functions/fnc_place_Cancel.sqf +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Cancels placement of the explosive - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * call ACE_Explosives_fnc_place_Cancel; - * - * Public: Yes - */ -#include "script_component.hpp" -if (GVAR(pfeh_running)) then { - [QGVAR(Placement),"OnEachFrame"] call CALLSTACK(BIS_fnc_removeStackedEventHandler); - GVAR(pfeh_running) = false; -}; -if (!isNull (GVAR(Setup))) then { - deleteVehicle GVAR(Setup); -}; -GVAR(Setup) = objNull; -if (isNil {GVAR(placer)}) then { - GVAR(placer) = objNull; -}; -[GVAR(placer), "ACE_Explosives", false] call EFUNC(Common,setForceWalkStatus); -GVAR(placer) = objNull; -call EFUNC(interaction,hideMouseHint); -[ACE_player, "DefaultAction", ACE_player getVariable [QGVAR(Place), -1]] call EFUNC(Common,removeActionEventHandler); -[ACE_player, "zoomtemp", ACE_player getVariable [QGVAR(Cancel), -1]] call EFUNC(Common,removeActionEventHandler); diff --git a/addons/explosives/functions/fnc_setupExplosive.sqf b/addons/explosives/functions/fnc_setupExplosive.sqf index 14b2b52844..1e6a17fa72 100644 --- a/addons/explosives/functions/fnc_setupExplosive.sqf +++ b/addons/explosives/functions/fnc_setupExplosive.sqf @@ -15,12 +15,12 @@ * * Public: Yes */ +#define ENABLE_PERFORMANCE_COUNTERS #include "script_component.hpp" -PARAMS_3(_vehicle,_player,_magClassname); +PARAMS_3(_vehicle,_unit,_magClassname); -[_player, "ACE_Explosives", true] call EFUNC(common,setForceWalkStatus); -GVAR(TweakedAngle) = 0; +[_unit, "ACE_Explosives", true] call EFUNC(common,setForceWalkStatus); //Get setup object vehicle and model: _setupObjectClass = getText(ConfigFile >> "CfgMagazines" >> _magClassname >> "ACE_SetupObject"); @@ -28,10 +28,10 @@ if (!isClass (configFile >> "CfgVehicles" >> _setupObjectClass)) exitWith {ERROR _p3dModel = getText (configFile >> "CfgVehicles" >> _setupObjectClass >> "model"); if (_p3dModel == "") exitWith {ERROR("No Model");}; //"" - will crash game! +//Show mouse buttons: [localize LSTRING(PlaceAction), localize LSTRING(CancelAction), localize LSTRING(ScrollAction)] call EFUNC(interaction,showMouseHint); -_player setVariable [QGVAR(placeActionEH), [_player, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,AddActionEventHandler)]; -_player setVariable [QGVAR(cancelActionEH), [_player, "zoomtemp", {true}, {GVAR(placeAction) = PLACE_CANCEL;}] call EFUNC(common,AddActionEventHandler)]; - +_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,AddActionEventHandler)]; +_unit setVariable [QGVAR(cancelActionEH), [_unit, "zoomtemp", {true}, {GVAR(placeAction) = PLACE_CANCEL;}] call EFUNC(common,AddActionEventHandler)]; //Display to show virtual object: (QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutRsc [QGVAR(virtualAmmo), "PLAIN", 0, false]; @@ -39,25 +39,65 @@ _player setVariable [QGVAR(cancelActionEH), [_player, "zoomtemp", {true}, {GVAR( GVAR(pfeh_running) = true; GVAR(placeAction) = PLACE_WAITING; +GVAR(TweakedAngle) = 0; [{ - private["_angle", "_dir", "_screenPos", "_realDistance", "_up", "_virtualPos", "_virtualPosASL", "_badPosition"]; + BEGIN_COUNTER(pfeh); PARAMS_2(_args,_pfID); EXPLODE_3_PVT(_args,_unit,_magClassname,_setupObjectClass); - _virtualPosASL = (eyePos _unit) vectorAdd (positionCameraToWorld [0,0,1]) vectorDiff (positionCameraToWorld [0,0,0]); - if (cameraView == "EXTERNAL") then { - _virtualPosASL = _virtualPosASL vectorAdd ((positionCameraToWorld [0.3,0,0]) vectorDiff (positionCameraToWorld [0,0,0])); - }; - _virtualPos = _virtualPosASL call EFUNC(common,ASLToPosition); - _intersectsWith = lineIntersectsWith [eyePos ACE_player, _virtualPosASL, ACE_player]; + _lookDirVector = (positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,0,1]); + _cameraAngle = (_lookDirVector select 0) atan2 (_lookDirVector select 1); + + _basePosASL = (eyePos _unit); + if (cameraView == "EXTERNAL") then { + _basePosASL = _basePosASL vectorAdd ((positionCameraToWorld [0.3,0,0]) vectorDiff (positionCameraToWorld [0,0,0])); + }; + + _testPositionIsValid = { + _testDistance = _this select 0; + _testBase = _basePosASL vectorAdd (_lookDirVector vectorMultiply _testDistance); + _return = true; + { + _testPos = _testBase vectorAdd [0.1 * (_x select 0) * (cos _cameraAngle), 0.1 * (_x select 0) * (sin _cameraAngle), 0.1 * (_x select 1)]; + drawLine3d [(eyePos _unit) call EFUNC(common,ASLToPosition), (_testPos) call EFUNC(common,ASLToPosition), [1,0,0,1]]; + if (lineIntersects [eyePos _unit, _testPos, _unit]) exitWith {_return = false;}; + } forEach [[0,0], [-1,-1], [1,-1], [-1,1], [1,1]]; + _return + }; + + _distanceFromBase = 1; + _badPosition = !([_distanceFromBase] call _testPositionIsValid); + _attachVehicle = objNull; + + + if (_badPosition && {!isNull cursorTarget} && {(cursorTarget isKindOf "Car")}) then { + _attachVehicle = cursorTarget; + if ([0.05] call _testPositionIsValid) then { + _min = 0.05; + _max = 1; + for "_index" from 0 to 5 do { + _distanceFromBase = (_min + _max) / 2; + if ([_distanceFromBase] call _testPositionIsValid) then { + _min = _distanceFromBase; + } else { + _max = _distanceFromBase; + }; + }; + _badPosition = false; + _distanceFromBase = ((_min + _max) / 2 + 0.075) min 1; + systemChat format ["Attaching, dist %1", _distanceFromBase]; + }; + }; + + _virtualPosASL = _basePosASL vectorAdd (_lookDirVector vectorMultiply _distanceFromBase); + if ((getTerrainHeightASL _virtualPosASL) > (_virtualPosASL select 2)) then { + systemChat "adjusting height"; + _virtualPosASL set [2, (getTerrainHeightASL _virtualPosASL)]; + }; - hintSilent format ["IntersectsWith %1", _intersectsWith]; - - _badPosition = (count _intersectsWith) > 0; - //Don't allow placing in a bad position: if (_badPosition && {GVAR(placeAction) == PLACE_APPROVE}) then {GVAR(placeAction) = PLACE_WAITING;}; @@ -65,8 +105,7 @@ GVAR(placeAction) = PLACE_WAITING; if ((inputAction "zoomTemp") > 0) then {GVAR(placeAction) = PLACE_CANCEL;}; if ((GVAR(placeAction) != PLACE_WAITING) || - {_unit != ACE_player} || - {(inputAction "optics") > 0}) then { + {_unit != ACE_player}) then { [_pfID] call CBA_fnc_removePerFrameHandler; GVAR(pfeh_running) = false; @@ -80,80 +119,58 @@ GVAR(placeAction) = PLACE_WAITING; if (GVAR(placeAction) == PLACE_APPROVE) then { systemChat "place"; - _dir = (positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,0,1]); - _angle = ((_dir select 0) atan2 (_dir select 1)) - GVAR(TweakedAngle) - 180; + _placeAngle = 0; + _expSetupVehicle = _setupObjectClass createVehicle (_virtualPosASL call EFUNC(common,ASLToPosition)); + if (isNull _attachVehicle) then { + _placeAngle = _cameraAngle - GVAR(TweakedAngle) - 180; + _expSetupVehicle setPosAsl _virtualPosASL; + _expSetupVehicle setDir _angle; + } else { + _modelOffset = _attachVehicle worldToModel (_virtualPosASL call EFUNC(common,ASLToPosition)); + _placeAngle = _cameraAngle - (getDir _attachVehicle) + 180; + _expSetupVehicle attachTo [_attachVehicle, _modelOffset]; + _expSetupVehicle setVectorDirAndUp [[0,0,-1],[(sin _placeAngle),(cos _placeAngle),0]]; + }; - systemChat format ["Pos %1, Cam %2, Ang %3", _virtualPosASL, ((_dir select 0) atan2 (_dir select 1)), _angle]; - _realObject = _setupObjectClass createVehicle _virtualPos; - _realObject setPosAsl _virtualPosASL; - _realObject setDir _angle; - // [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAtachText, _virtualPos] call FUNC(placeApprove); + systemChat format ["Attach angel %1", _placeAngle]; + + _expSetupVehicle setVariable [QGVAR(class), _magClassname, true]; + _expSetupVehicle setVariable [QGVAR(Direction), _placeAngle, true]; + + _unit removeMagazine _magClassname; + _unit playActionNow "PutDown"; + _unit setVariable [QGVAR(PlantingExplosive), true]; + [{_this setVariable [QGVAR(PlantingExplosive), false]}, _unit, 1.5] call EFUNC(common,waitAndExecute); + + x3 = _expSetupVehicle; + systemChat format ["Mass %1", getMass _expSetupVehicle]; + // x3 setMass 1; }; } else { - // systemChat format ["A Running %1 - %2", time, _badPosition]; - //Show the virtual object: - if (_badPosition) then { + _screenPos = worldToScreen (_virtualPosASL call EFUNC(common,ASLToPosition)); + if (_badPosition || {_screenPos isEqualTo []}) then { ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow false; } else { ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow true; - _screenPos = worldToScreen _virtualPos; - if (_screenPos isEqualTo []) exitWith { - ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow false; - }; - _realDistance = (_virtualPos distance (positionCameraToWorld [0,0,0])) / ((call CBA_fnc_getFov) select 1); + + _realDistance = ((_virtualPosASL call EFUNC(common,ASLToPosition)) distance (positionCameraToWorld [0,0,0])) / ((call CBA_fnc_getFov) select 1); _screenPos = [(_screenPos select 0), _realDistance, (_screenPos select 1)]; ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetPosition _screenPos; - _dir = (positionCameraToWorld [0,0,1]) vectorFromTo (positionCameraToWorld [0,0,0]); - _angle = asin (_dir select 2) + 90; - _modelUp = [0, (cos _angle), (sin _angle)]; - _modelDir = [cos GVAR(TweakedAngle), sin GVAR(TweakedAngle), 0] vectorCrossProduct _modelUp; + _modelDir = [0,0,-1]; + _modelUp = [0,-1,0]; + if (isNull _attachVehicle) then { + _angle = acos (_lookDirVector select 2); + _modelUp = [0, (cos _angle), (sin _angle)]; + _modelDir = [cos GVAR(TweakedAngle), sin GVAR(TweakedAngle), 0] vectorCrossProduct _modelUp; + }; - // systemChat format ["Running %1", [_modelDir, _modelUp]]; + // systemChat format ["Running %1 [%2]", [_modelDir, _modelUp], _attachVehicle]; ((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModelDirAndUp [_modelDir, _modelUp]; }; }; -}, 0, [_player, _magClassname, _setupObjectClass]] call CBA_fnc_addPerFrameHandler; - - - - - - - - - - -/* - - -closeDialog 0; -EXPLODE_2_PVT(_this,_unit,_class); -GVAR(placer) = _unit; -// TODO: check MP performance and MP compatible. -GVAR(Setup) = createVehicle [getText(ConfigFile >> "CfgMagazines" >> _class >> "ACE_SetupObject"),[0,0,-10000],[], 0, "NONE"]; - -GVAR(Setup) enableSimulationGlobal false; -GVAR(Setup) setVariable [QGVAR(class), _class, true]; - - - - -[QGVAR(Placement),"OnEachFrame", { - private ["_player", "_pos"]; - _player = ACE_player; - if (GVAR(placer) != _player) exitWith { - call FUNC(place_Cancel); - }; - GVAR(pfeh_running) = true; - _pos = (ASLtoATL eyePos _player) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]); - GVAR(Setup) setPosATL _pos; - if (ACE_Modifier == 0) then { - GVAR(Setup) setDir (GVAR(TweakedAngle) + getDir _player); - }; -}] call CALLSTACK(BIS_fnc_addStackedEventHandler); - - */ + END_COUNTER(pfeh); +}, 0, [_unit, _magClassname, _setupObjectClass]] call CBA_fnc_addPerFrameHandler;