2015-03-24 04:18:00 +00:00
|
|
|
// by commy2 and esteldunedain
|
2015-01-17 22:38:13 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-06-18 22:16:53 +00:00
|
|
|
private ["_p0", "_p1", "_p0Pos", "_offV1", "_offV2", "_offV3", "_camPos", "_intermediatePos", "_iteration", "_light", "_line", "_pL", "_pL2", "_pX", "_size", "_units", "_fnc_getDistanceToTerrain", "_fnc_doesIntersectWithMan"];
|
2015-06-13 08:41:19 +00:00
|
|
|
|
2015-04-14 11:14:37 +00:00
|
|
|
// init object
|
|
|
|
/*if (isNil QGVAR(laserdot)) then {
|
|
|
|
_light = "#lightpoint" createVehicleLocal [0,0,0];
|
|
|
|
_light setLightBrightness 10;
|
|
|
|
_light setLightColor [1,0,0];
|
|
|
|
_light setLightAmbient [1,0,0];
|
|
|
|
_light setLightDayLight true;
|
|
|
|
//_light lightAttachObject [GVAR(laserdot), [0,0,0]];
|
|
|
|
_light setLightAttenuation [0.04,4,4,0,0.04,0.08];
|
|
|
|
|
|
|
|
GVAR(laserdot) = _light;
|
|
|
|
};*/
|
|
|
|
|
2015-06-18 22:16:53 +00:00
|
|
|
EXPLODE_4_PVT(_this,_unit,_range,_isGreen,_brightness);
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-04-03 22:26:27 +00:00
|
|
|
_p0Pos = _unit modelToWorldVisual (_unit selectionPosition "righthand");
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
// Convert _p0Pos to ASL
|
|
|
|
_p0 = + _p0Pos;
|
|
|
|
if (!surfaceIsWater _p0) then {
|
|
|
|
_p0 = ATLtoASL _p0;
|
|
|
|
};
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
// Find a system of orthogonal reference vectors
|
|
|
|
// _v1 points in the direction of the weapon
|
|
|
|
// _v2 points to the right of the weapon
|
|
|
|
// _v3 points to the top side of the weapon
|
|
|
|
_v1 = _unit weaponDirection currentWeapon _unit;
|
|
|
|
_v2 = vectorNormalized (_v1 vectorCrossProduct [0,0,1]);
|
|
|
|
_v3 = _v2 vectorCrossProduct _v1;
|
|
|
|
|
|
|
|
// Offset over the 3 reference axis
|
|
|
|
// This offset could eventually be configured by weapon in the config
|
|
|
|
_offV1 = 0.31;
|
|
|
|
_offV2 = 0;
|
|
|
|
_offV3 = 0.08;
|
|
|
|
|
|
|
|
// Offset _p0, the start of the laser
|
|
|
|
_p0 = _p0 vectorAdd (_v1 vectorMultiply _offV1) vectorAdd (_v3 vectorMultiply _offV3) vectorAdd (_v2 vectorMultiply _offV2);
|
|
|
|
_p0Pos = _p0Pos vectorAdd (_v1 vectorMultiply _offV1) vectorAdd (_v3 vectorMultiply _offV3) vectorAdd (_v2 vectorMultiply _offV2);
|
|
|
|
// Calculate _p1, the potential end of the laser
|
|
|
|
_p1 = _p0 vectorAdd (_v1 vectorMultiply _range);
|
|
|
|
|
|
|
|
//Debugaaa = lineIntersectsObjs [_p0, _p1, objNull, _unit, false, 2];
|
|
|
|
|
|
|
|
_fnc_getDistanceToTerrain = {
|
2015-06-13 08:41:19 +00:00
|
|
|
private ["_distance"];
|
2015-01-17 22:38:13 +00:00
|
|
|
|
|
|
|
_pX = + _p0;
|
2015-01-18 02:51:31 +00:00
|
|
|
_line = [_p0, _pX];
|
2015-01-17 22:38:13 +00:00
|
|
|
|
|
|
|
_distance = _this;
|
|
|
|
_iteration = _distance;
|
|
|
|
|
2015-06-13 08:41:19 +00:00
|
|
|
while {_iteration > 0.05 / 2} do {
|
2015-01-17 22:38:13 +00:00
|
|
|
_iteration = _iteration / 2;
|
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
_pX = _p0 vectorAdd (_v1 vectorMultiply _distance);
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
_line set [1, _pX];
|
2015-01-17 22:38:13 +00:00
|
|
|
|
|
|
|
_distance = _distance + (([1, -1] select (lineIntersects (_line + [_unit]) || {terrainIntersectASL _line})) * _iteration);
|
|
|
|
|
|
|
|
if (_distance > _this) exitWith {_distance = _this};
|
|
|
|
};
|
|
|
|
|
|
|
|
_distance
|
|
|
|
};
|
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
// Get distance to nearest object or terrain (excluding men)
|
|
|
|
_distance = _range call _fnc_getDistanceToTerrain;
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
// Find all men potentially intercepted by the ray
|
|
|
|
_intermediatePos = _p0 vectorAdd (_v1 vectorMultiply _distance/2);
|
|
|
|
if (!surfaceIsWater _intermediatePos) then {
|
|
|
|
_intermediatePos = ASLtoATL _intermediatePos;
|
|
|
|
};
|
|
|
|
_units = nearestObjects [_intermediatePos, ["Man"], _distance/2];
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
_units deleteAt (_units find _unit);
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
_fnc_doesIntersectWithMan = {
|
|
|
|
_pX = _p0 vectorAdd (_v1 vectorMultiply (_this select 1));
|
|
|
|
if (!surfaceIsWater _pX) then {
|
|
|
|
_pX = ASLtoATL _pX;
|
|
|
|
};
|
|
|
|
count ([_this select 0, "FIRE"] intersect [_p0Pos, _pX]) > 0
|
2015-01-17 22:38:13 +00:00
|
|
|
};
|
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
// Test intersection with nearby men
|
2015-01-17 22:38:13 +00:00
|
|
|
{
|
2015-01-18 02:51:31 +00:00
|
|
|
if ([_x, _distance] call _fnc_doesIntersectWithMan) then {
|
|
|
|
_distance = _distance min ((_unit distance _x) - _offV1);
|
2015-01-17 22:38:13 +00:00
|
|
|
};
|
|
|
|
} forEach _units;
|
|
|
|
|
|
|
|
//systemChat str _distance;
|
|
|
|
if (_distance < 0.5) exitWith {};
|
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
_pL = _p0 vectorAdd (_v1 vectorMultiply _distance);
|
|
|
|
_pL2 = _p0 vectorAdd (_v1 vectorMultiply (_distance - 0.5));
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
// Convert _pL to pos
|
|
|
|
if (!surfaceIsWater _pL) then {
|
|
|
|
_pL = ASLtoATL _pL;
|
|
|
|
};
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-04-14 11:14:37 +00:00
|
|
|
/*
|
|
|
|
drawLine3D [
|
|
|
|
_p0Pos,
|
|
|
|
_pL,
|
|
|
|
[[1,0,0,1], [0,1,0,1]] select _isGreen
|
|
|
|
];
|
|
|
|
*/
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-04-14 11:14:37 +00:00
|
|
|
_size = 2 * (_range - (positionCameraToWorld [0,0,0] vectorDistance _pL)) / _range;
|
2015-01-17 22:38:13 +00:00
|
|
|
|
|
|
|
_camPos = positionCameraToWorld [0,0,0.2];
|
|
|
|
if (count ([_unit, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {};
|
|
|
|
if (count ([ACE_player, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {};
|
2015-01-18 02:51:31 +00:00
|
|
|
|
|
|
|
// Convert _camPos to ASL
|
|
|
|
if (!surfaceIsWater _camPos) then { _camPos = ATLtoASL _camPos; };
|
|
|
|
if ( terrainIntersectASL [_camPos, _pL2]) exitWith {};
|
|
|
|
if ( lineIntersects [_camPos, _pL2]) exitWith {};
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-04-14 11:14:37 +00:00
|
|
|
//GVAR(laserdot) setPos _pL;
|
|
|
|
|
2015-01-17 22:38:13 +00:00
|
|
|
drawIcon3D [
|
|
|
|
format ["\a3\weapons_f\acc\data\collimdot_%1_ca.paa", ["red", "green"] select _isGreen],
|
|
|
|
[[1,0.25,0.25,0.5*_brightness], [0.25,1,0.25,0.5*_brightness]] select _isGreen,
|
|
|
|
_pL,
|
|
|
|
_size,
|
|
|
|
_size,
|
|
|
|
45,
|
|
|
|
"",
|
|
|
|
0,
|
|
|
|
0.05
|
|
|
|
];
|