2015-01-12 09:48:26 +00:00
|
|
|
/*
|
2015-02-02 08:35:17 +00:00
|
|
|
* Author: Garth 'L-H' de Wet
|
|
|
|
* Starts the setup process for the passed explosive. Player only.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-07-14 05:24:55 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
|
|
|
* 1: Player Unit <OBJECT>
|
|
|
|
* 2: Classname of explosive to place. (CfgMagazine class) <STRING>
|
2015-02-02 08:35:17 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2015-02-20 01:28:16 +00:00
|
|
|
* [player, "SatchelCharge_Remote_Mag"] call ACE_Explosives_fnc_SetupExplosive;
|
2015-02-02 08:35:17 +00:00
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
2015-07-15 07:54:38 +00:00
|
|
|
#define ENABLE_PERFORMANCE_COUNTERS
|
2015-01-13 21:21:31 +00:00
|
|
|
#include "script_component.hpp"
|
2015-07-14 05:24:55 +00:00
|
|
|
|
2015-07-15 07:54:38 +00:00
|
|
|
PARAMS_3(_vehicle,_unit,_magClassname);
|
2015-07-14 05:24:55 +00:00
|
|
|
|
2015-07-15 07:54:38 +00:00
|
|
|
[_unit, "ACE_Explosives", true] call EFUNC(common,setForceWalkStatus);
|
2015-07-14 05:24:55 +00:00
|
|
|
|
|
|
|
//Get setup object vehicle and model:
|
|
|
|
_setupObjectClass = getText(ConfigFile >> "CfgMagazines" >> _magClassname >> "ACE_SetupObject");
|
|
|
|
if (!isClass (configFile >> "CfgVehicles" >> _setupObjectClass)) exitWith {ERROR("Bad Vehicle");};
|
|
|
|
_p3dModel = getText (configFile >> "CfgVehicles" >> _setupObjectClass >> "model");
|
|
|
|
if (_p3dModel == "") exitWith {ERROR("No Model");}; //"" - will crash game!
|
|
|
|
|
2015-07-15 07:54:38 +00:00
|
|
|
//Show mouse buttons:
|
2015-07-14 05:24:55 +00:00
|
|
|
[localize LSTRING(PlaceAction), localize LSTRING(CancelAction), localize LSTRING(ScrollAction)] call EFUNC(interaction,showMouseHint);
|
2015-07-15 07:54:38 +00:00
|
|
|
_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)];
|
2015-07-14 05:24:55 +00:00
|
|
|
|
|
|
|
//Display to show virtual object:
|
|
|
|
(QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutRsc [QGVAR(virtualAmmo), "PLAIN", 0, false];
|
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModel _p3dModel;
|
|
|
|
|
|
|
|
GVAR(pfeh_running) = true;
|
|
|
|
GVAR(placeAction) = PLACE_WAITING;
|
2015-07-15 07:54:38 +00:00
|
|
|
GVAR(TweakedAngle) = 0;
|
2015-07-14 05:24:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
[{
|
2015-07-15 07:54:38 +00:00
|
|
|
BEGIN_COUNTER(pfeh);
|
2015-07-14 05:24:55 +00:00
|
|
|
|
|
|
|
PARAMS_2(_args,_pfID);
|
|
|
|
EXPLODE_3_PVT(_args,_unit,_magClassname,_setupObjectClass);
|
|
|
|
|
2015-07-15 07:54:38 +00:00
|
|
|
_lookDirVector = (positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,0,1]);
|
|
|
|
_cameraAngle = (_lookDirVector select 0) atan2 (_lookDirVector select 1);
|
|
|
|
|
|
|
|
_basePosASL = (eyePos _unit);
|
2015-07-14 05:24:55 +00:00
|
|
|
if (cameraView == "EXTERNAL") then {
|
2015-07-15 07:54:38 +00:00
|
|
|
_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)];
|
2015-07-14 05:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//Don't allow placing in a bad position:
|
|
|
|
if (_badPosition && {GVAR(placeAction) == PLACE_APPROVE}) then {GVAR(placeAction) = PLACE_WAITING;};
|
|
|
|
|
|
|
|
//Cancel on RMB, For some reason this works (when held) but AddActionEventHandler doesn't
|
|
|
|
if ((inputAction "zoomTemp") > 0) then {GVAR(placeAction) = PLACE_CANCEL;};
|
|
|
|
|
|
|
|
if ((GVAR(placeAction) != PLACE_WAITING) ||
|
2015-07-15 07:54:38 +00:00
|
|
|
{_unit != ACE_player}) then {
|
2015-07-14 05:24:55 +00:00
|
|
|
|
|
|
|
[_pfID] call CBA_fnc_removePerFrameHandler;
|
|
|
|
GVAR(pfeh_running) = false;
|
|
|
|
|
|
|
|
[_unit, "ACE_Explosives", false] call EFUNC(common,setForceWalkStatus);
|
|
|
|
[] call EFUNC(interaction,hideMouseHint);
|
|
|
|
[_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
|
|
|
[_unit, "zoomtemp", (_unit getVariable [QGVAR(cancelActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
|
|
|
|
|
|
|
(QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutText ["", "PLAIN"];
|
|
|
|
|
|
|
|
if (GVAR(placeAction) == PLACE_APPROVE) then {
|
2015-07-15 08:18:19 +00:00
|
|
|
systemChat format ["place %1 - %2", _virtualPosASL, aslToAtl _virtualPosASL];;
|
2015-07-15 07:54:38 +00:00
|
|
|
_placeAngle = 0;
|
|
|
|
_expSetupVehicle = _setupObjectClass createVehicle (_virtualPosASL call EFUNC(common,ASLToPosition));
|
|
|
|
if (isNull _attachVehicle) then {
|
|
|
|
_placeAngle = _cameraAngle - GVAR(TweakedAngle) - 180;
|
|
|
|
_expSetupVehicle setPosAsl _virtualPosASL;
|
2015-07-15 08:18:19 +00:00
|
|
|
_expSetupVehicle setDir _placeAngle;
|
2015-07-15 07:54:38 +00:00
|
|
|
} 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 ["Attach angel %1", _placeAngle];
|
|
|
|
|
|
|
|
_expSetupVehicle setVariable [QGVAR(class), _magClassname, true];
|
|
|
|
_expSetupVehicle setVariable [QGVAR(Direction), _placeAngle, true];
|
2015-07-14 05:24:55 +00:00
|
|
|
|
2015-07-15 07:54:38 +00:00
|
|
|
_unit removeMagazine _magClassname;
|
|
|
|
_unit playActionNow "PutDown";
|
|
|
|
_unit setVariable [QGVAR(PlantingExplosive), true];
|
|
|
|
[{_this setVariable [QGVAR(PlantingExplosive), false]}, _unit, 1.5] call EFUNC(common,waitAndExecute);
|
2015-07-14 05:24:55 +00:00
|
|
|
|
2015-07-15 07:54:38 +00:00
|
|
|
x3 = _expSetupVehicle;
|
|
|
|
systemChat format ["Mass %1", getMass _expSetupVehicle];
|
|
|
|
// x3 setMass 1;
|
2015-07-14 05:24:55 +00:00
|
|
|
};
|
|
|
|
} else {
|
2015-07-15 07:54:38 +00:00
|
|
|
_screenPos = worldToScreen (_virtualPosASL call EFUNC(common,ASLToPosition));
|
|
|
|
if (_badPosition || {_screenPos isEqualTo []}) then {
|
2015-07-14 05:24:55 +00:00
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow false;
|
|
|
|
} else {
|
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow true;
|
2015-07-15 07:54:38 +00:00
|
|
|
|
|
|
|
_realDistance = ((_virtualPosASL call EFUNC(common,ASLToPosition)) distance (positionCameraToWorld [0,0,0])) / ((call CBA_fnc_getFov) select 1);
|
2015-07-14 05:24:55 +00:00
|
|
|
_screenPos = [(_screenPos select 0), _realDistance, (_screenPos select 1)];
|
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetPosition _screenPos;
|
|
|
|
|
2015-07-15 07:54:38 +00:00
|
|
|
_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;
|
|
|
|
};
|
2015-07-14 05:24:55 +00:00
|
|
|
|
2015-07-15 07:54:38 +00:00
|
|
|
// systemChat format ["Running %1 [%2]", [_modelDir, _modelUp], _attachVehicle];
|
2015-07-14 05:24:55 +00:00
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModelDirAndUp [_modelDir, _modelUp];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-15 07:54:38 +00:00
|
|
|
END_COUNTER(pfeh);
|
|
|
|
}, 0, [_unit, _magClassname, _setupObjectClass]] call CBA_fnc_addPerFrameHandler;
|