diff --git a/addons/laserpointer/functions/fnc_drawLaserpoint.sqf b/addons/laserpointer/functions/fnc_drawLaserpoint.sqf index 34ca98808b7..29befe96cda 100644 --- a/addons/laserpointer/functions/fnc_drawLaserpoint.sqf +++ b/addons/laserpointer/functions/fnc_drawLaserpoint.sqf @@ -1,19 +1,36 @@ -// by commy2 and esteldunedain +/* + * Author: commy2 and esteldunedain + * Draw a Laser Point + * + * Arguments: + * 0: Target unit + * 1: Range + * 2: is Green + * 3: Brightness + * + * Return Value: + * None + * + * Example: + * [player, 10, false, 2] call ace_laserpointer_fnc_drawLaserpoint + * + * Public: No + */ #include "script_component.hpp" -params ["_unit", "_range", "_isGreen", "_brightness"]; +params ["_target", "_range", "_isGreen", "_brightness"]; -private ["_p0", "_v1", "_v2", "_v3", "_p1", "_pL", "_distance", "_pL2", "_camPos", "_size"]; +private _unit = ACE_player; -_p0 = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "righthand")); +private _p0 = AGLToASL (_target modelToWorldVisual (_target selectionPosition "righthand")); // 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; +private _v1 = _target weaponDirection currentWeapon _target; +private _v2 = vectorNormalized (_v1 vectorCrossProduct [0,0,1]); +private _v3 = _v2 vectorCrossProduct _v1; // Offset over the 3 reference axis // This offset could eventually be configured by weapon in the config @@ -22,23 +39,24 @@ _v3 = _v2 vectorCrossProduct _v1; #define OFFV3 0.08 // Offset _p0, the start of the laser -_p0 = _p0 vectorAdd (_v1 vectorMultiply OFFV1) vectorAdd (_v3 vectorMultiply OFFV3) vectorAdd (_v2 vectorMultiply OFFV2); +_p0 = _p0 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); +private _p1 = _p0 vectorAdd (_v1 vectorMultiply _range); -_pL = lineIntersectsSurfaces [_p0, _p1, ACE_player, vehicle ACE_player, true, 1, "GEOM", "FIRE"] select 0 select 0; +private _pL = lineIntersectsSurfaces [_p0, _p1, _unit, vehicle _unit] select 0 select 0; // no intersection found, quit if (isNil "_pL") exitWith {}; -_distance = _p0 vectorDistance _pL; +private _distance = _p0 vectorDistance _pL; //systemChat str _distance; if (_distance < 0.5) exitWith {}; _pL = _p0 vectorAdd (_v1 vectorMultiply _distance); -_pL2 = _p0 vectorAdd (_v1 vectorMultiply (_distance - 0.5)); + +private _pL2 = _p0 vectorAdd (_v1 vectorMultiply (_distance - 0.5)); _pL = ASLtoAGL _pL; @@ -50,19 +68,20 @@ drawLine3D [ ]; */ -//systemChat str [_unit, "FIRE"] intersect [_camPos, _pL]; +//systemChat str [_target, "FIRE"] intersect [_camPos, _pL]; + +private _camPos = positionCameraToWorld [0,0,0.2]; -_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 {}; +if (count ([_target, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {}; +if (count ([_unit, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {}; // Convert _camPos to ASL _camPos = AGLToASL _camPos; -if ( terrainIntersectASL [_camPos, _pL2]) exitWith {}; -if ( lineIntersects [_camPos, _pL2]) exitWith {}; +if (terrainIntersectASL [_camPos, _pL2]) exitWith {}; +if (lineIntersects [_camPos, _pL2]) exitWith {}; -_size = 2 * (_range - (positionCameraToWorld [0,0,0] vectorDistance _pL)) / _range; +private _size = 2 * (_range - (positionCameraToWorld [0,0,0] vectorDistance _pL)) / _range; drawIcon3D [ format ["\a3\weapons_f\acc\data\collimdot_%1_ca.paa", ["red", "green"] select _isGreen], diff --git a/addons/laserpointer/functions/fnc_onDraw.sqf b/addons/laserpointer/functions/fnc_onDraw.sqf index 9e61e70156c..1945dcf2b75 100644 --- a/addons/laserpointer/functions/fnc_onDraw.sqf +++ b/addons/laserpointer/functions/fnc_onDraw.sqf @@ -1,34 +1,33 @@ -// by commy2 +/* + * Author: commy2 + * Draw the visible laser beams of all cached units. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" -private ["_brightness", "_cacheName", "_isIR", "_laser", "_laserID", "_weapon"]; +private _isIR = currentVisionMode ACE_player; -_isIR = currentVisionMode ACE_player; if (_isIR == 2) exitWith {}; _isIR = _isIR == 1; -_brightness = 2 - call EFUNC(common,ambientBrightness); +private _brightness = 2 - call EFUNC(common,ambientBrightness); { - _weapon = currentWeapon _x; - - _laser = switch (_weapon) do { - case (primaryWeapon _x): { - primaryWeaponItems _x select 1; - }; - case (secondaryWeapon _x): { - secondaryWeaponItems _x select 1; - }; - case (handgunWeapon _x): { - handgunItems _x select 1; - }; - default {""}; - }; + private _weapon = currentWeapon _x; + private _laser = (_x weaponAccessories _weapon) select 1; if (_laser != "") then { - _cacheName = format [QGVAR(laser_%1), _laser]; - _laserID = missionNamespace getVariable [_cacheName, -1]; + private _cacheName = format [QGVAR(laser_%1), _laser]; + private _laserID = missionNamespace getVariable [_cacheName, -1]; + if (missionNamespace getVariable [_cacheName, -1] == -1) then { _laserID = getNumber (configFile >> "CfgWeapons" >> _laser >> "ACE_laserpointer"); missionNamespace setVariable [_cacheName, _laserID]; @@ -38,5 +37,5 @@ _brightness = 2 - call EFUNC(common,ambientBrightness); [_x, 100, (_laserID == 2 || _isIR), _brightness] call FUNC(drawLaserpoint); }; }; - -} forEach GVAR(nearUnits); + false +} count GVAR(nearUnits); diff --git a/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf b/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf index 3332631c493..e26d5f75c15 100644 --- a/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf +++ b/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf @@ -1,89 +1,54 @@ -// by commy2 +/* + * Author: Commy2 + * Switch between laser modes. + * + * Arguments: + * 0: Unit + * 1: Weapon + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" -private ["_unit", "_weapon", "_error"]; +params ["_unit", "_weapon"]; -_unit = _this select 0; -_weapon = _this select 1; - -// 1 = primary, 2 = secondary, 3 = handgun -private "_currentWeaponType"; -_currentWeaponType = 0; - -private "_pointer"; -_pointer = switch (_weapon) do { - case (primaryWeapon _unit): { - _currentWeaponType = 1; - primaryWeaponItems _unit select 1 - }; - case (secondaryWeapon _unit): { - _currentWeaponType = 2; - secondaryWeaponItems _unit select 1 - }; - case (handgunWeapon _unit): { - _currentWeaponType = 3; - handgunItems _unit select 1 - }; - default {""}; -}; +private _pointer = (_unit weaponAccessories _weapon) select 1; if (_pointer == "") exitWith {}; -private "_config"; -_config = configFile >> "CfgWeapons" >> _pointer; +private _config = configFile >> "CfgWeapons" >> _pointer; -private "_nextPointer"; -_nextPointer = getText (_config >> "ACE_nextModeClass"); +private _nextPointer = getText (_config >> "ACE_nextModeClass"); if (_nextPointer == "") exitWith {}; //If system disabled, don't switch to a laser: -private "_nextPointerIsLaser"; -_nextPointerIsLaser = getNumber (configFile >> "CfgWeapons" >> _nextPointer >> "ACE_laserpointer"); +private _nextPointerIsLaser = getNumber (configFile >> "CfgWeapons" >> _nextPointer >> "ACE_laserpointer"); if ((!GVAR(enabled)) && {_nextPointerIsLaser == 1}) exitWith {}; // disable inheritance for this entry, because addons claim this as a base class for convenience if !((_config >> "ACE_nextModeClass") in configProperties [_config, "true", false]) exitWith {}; -private ["_description", "_picture"]; +_unit addWeaponItem [_weapon, _nextPointer]; -_description = getText (configFile >> "CfgWeapons" >> _nextPointer >> "ACE_modeDescription"); -_picture = getText (configFile >> "CfgWeapons" >> _nextPointer >> "picture"); -_error = false; +private _error = false; -switch (_currentWeaponType) do { - case 1: { - _unit removePrimaryWeaponItem _pointer; - _unit addPrimaryWeaponItem _nextPointer; - if (((primaryWeaponItems _unit) select 1) != _nextPointer) then { - ERROR("NextPointer not compatible"); - _unit addPrimaryWeaponItem _pointer; - _error = true; - }; - }; - case 2: { - _unit removeSecondaryWeaponItem _pointer; - _unit addSecondaryWeaponItem _nextPointer; - if (((secondaryWeaponItems _unit) select 1) != _nextPointer) then { - ERROR("NextPointer not compatible"); - _unit addSecondaryWeaponItem _pointer; - _error = true; - }; - }; - case 3: { - _unit removeHandgunItem _pointer; - _unit addHandgunItem _nextPointer; - if (((handgunItems _unit) select 1) != _nextPointer) then { - ERROR("NextPointer not compatible"); - _unit addHandgunItem _pointer; - _error = true; - }; - }; +if ((_unit weaponAccessories _weapon) select 1 != _nextPointer) then { + ERROR("NextPointer not compatible"); + _unit addWeaponItem [_weapon, _pointer]; + _error = true; }; if (!_error) then { + private _description = getText (configFile >> "CfgWeapons" >> _nextPointer >> "ACE_modeDescription"); + private _picture = getText (configFile >> "CfgWeapons" >> _nextPointer >> "picture"); + [_description, _picture] call EFUNC(common,displayTextPicture); } else { - ACE_LOGERROR_3("Failed to add %1 to %2 - reverting to %3",_nextPointer,_weapon,_pointer); + ACE_LOGERROR_3("Failed to add %1 to %2 - reverting to %3",_nextPointer,_weapon,_pointer); }; + playSound "ACE_Sound_Click";