diff --git a/addons/laserpointer/$PBOPREFIX$ b/addons/laserpointer/$PBOPREFIX$ new file mode 100644 index 0000000000..dd910bd307 --- /dev/null +++ b/addons/laserpointer/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\laserpointer \ No newline at end of file diff --git a/addons/laserpointer/CfgEventHandlers.hpp b/addons/laserpointer/CfgEventHandlers.hpp new file mode 100644 index 0000000000..0cd959a047 --- /dev/null +++ b/addons/laserpointer/CfgEventHandlers.hpp @@ -0,0 +1,12 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; diff --git a/addons/laserpointer/CfgVehicles.hpp b/addons/laserpointer/CfgVehicles.hpp new file mode 100644 index 0000000000..c98d0626c2 --- /dev/null +++ b/addons/laserpointer/CfgVehicles.hpp @@ -0,0 +1,42 @@ + +#define MACRO_ADDITEM(ITEM,COUNT) class _xx_##ITEM { \ + name = #ITEM; \ + count = COUNT; \ +} + +class CfgVehicles { + class NATO_Box_Base; + class Box_NATO_Support_F: NATO_Box_Base { + class TransportItems { + MACRO_ADDITEM(ACE_acc_pointer_red,4); + }; + }; + + class EAST_Box_Base; + class Box_East_Support_F: EAST_Box_Base { + class TransportItems { + MACRO_ADDITEM(ACE_acc_pointer_green,4); + }; + }; + + class IND_Box_Base; + class Box_IND_Support_F: IND_Box_Base { + class TransportItems { + MACRO_ADDITEM(ACE_acc_pointer_green,4); + }; + }; + + class FIA_Box_Base_F; + class Box_FIA_Support_F: FIA_Box_Base_F { + class TransportItems { + MACRO_ADDITEM(ACE_acc_pointer_red,4); + }; + }; + + class ACE_Box_Misc: Box_NATO_Support_F { + class TransportItems { + MACRO_ADDITEM(ACE_acc_pointer_red,4); + MACRO_ADDITEM(ACE_acc_pointer_green,4); + }; + }; +}; diff --git a/addons/laserpointer/CfgWeapons.hpp b/addons/laserpointer/CfgWeapons.hpp new file mode 100644 index 0000000000..364f4b2168 --- /dev/null +++ b/addons/laserpointer/CfgWeapons.hpp @@ -0,0 +1,62 @@ + +class SlotInfo; +class PointerSlot: SlotInfo { + compatibleItems[] += {"ACE_acc_pointer_red","ACE_acc_pointer_green"}; +}; + +class CfgWeapons { + class ItemCore; + class InventoryFlashLightItem_Base_F; + + class ACE_acc_pointer_red: ItemCore { + author = "$STR_ACE_Common_ACETeam"; + _generalMacro = "ACE_acc_pointer_red"; + scope = 2; + displayName = "$STR_ACE_Laserpointer_red"; + descriptionUse = "$STR_ACE_Laserpointer_useLaser"; + picture = "\A3\weapons_F\Data\UI\gear_accv_pointer_CA.paa"; + model = "\A3\weapons_f\acc\accv_pointer_F"; + descriptionShort = "$STR_ACE_Laserpointer_Description"; + + class ItemInfo: InventoryFlashLightItem_Base_F { + mass = 6; + + class Pointer {}; + + class FlashLight { + color[] = {0,0,0}; + ambient[] = {0,0,0}; + intensity = 0; + size = 0; + innerAngle = 0; + outerAngle = 0; + coneFadeCoef = 5; + position = "flash dir"; + direction = "flash"; + useFlare = 0; + flareSize = 0; + flareMaxDistance = "100.0f"; + dayLight = 0; + + class Attenuation { + start = 0; + constant = 0; + linear = 0; + quadratic = 0; + hardLimitStart = 0; + hardLimitEnd = 0; + }; + + scale[] = {0}; + }; + }; + + inertia = 0.1; + }; + + class ACE_acc_pointer_green: ACE_acc_pointer_red { + author = "$STR_ACE_Common_ACETeam"; + _generalMacro = "ACE_acc_pointer_green"; + displayName = "$STR_ACE_Laserpointer_green"; + }; +}; diff --git a/addons/laserpointer/XEH_postInit.sqf b/addons/laserpointer/XEH_postInit.sqf new file mode 100644 index 0000000000..34d9acd675 --- /dev/null +++ b/addons/laserpointer/XEH_postInit.sqf @@ -0,0 +1,21 @@ +// by commy2 +#include "script_component.hpp" + +GVAR(nearUnits) = []; + +// @todo. Maybe move to common? +[{ + private "_nearUnits"; + _nearUnits = nearestObjects [ACE_player, ["CAManBase"], 50]; + + if (count _nearUnits > 10) then { + _nearUnits resize 10; + }; + + GVAR(nearUnits) = _nearUnits; + +} , 5, []] call CBA_fnc_addPerFrameHandler; + +addMissionEventHandler ["Draw3D", { + call FUNC(onDraw); +}]; diff --git a/addons/laserpointer/XEH_preInit.sqf b/addons/laserpointer/XEH_preInit.sqf new file mode 100644 index 0000000000..3a89535f2e --- /dev/null +++ b/addons/laserpointer/XEH_preInit.sqf @@ -0,0 +1,4 @@ +#include "script_component.hpp" + +PREP(drawLaserpoint); +PREP(onDraw); diff --git a/addons/laserpointer/config.cpp b/addons/laserpointer/config.cpp new file mode 100644 index 0000000000..32357b31ef --- /dev/null +++ b/addons/laserpointer/config.cpp @@ -0,0 +1,17 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {"AGM_acc_pointer_red","AGM_acc_pointer_green"}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_common"}; + author[] = {"commy2"}; + authorUrl = "https://github.com/commy2"; + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" +#include "CfgVehicles.hpp" +#include "CfgWeapons.hpp" diff --git a/addons/laserpointer/functions/fnc_drawLaserpoint.sqf b/addons/laserpointer/functions/fnc_drawLaserpoint.sqf new file mode 100644 index 0000000000..24cd14de79 --- /dev/null +++ b/addons/laserpointer/functions/fnc_drawLaserpoint.sqf @@ -0,0 +1,111 @@ +// by commy2 +#include "script_component.hpp" + +private ["_unit", "_range", "_isGreen"]; + +_unit = _this select 0; +_range = _this select 1; +_isGreen = _this select 2; + +_p0 = _unit modelToWorld (_unit selectionPosition "righthand"); +_d = _unit weaponDirection currentWeapon _unit; + +_p1 = _p0 vectorAdd (_d vectorMultiply _range); +_pA = _p0 vectorAdd (_d vectorMultiply 0.5); + +_offset0 = getTerrainHeightASL _p0; +_offset1 = getTerrainHeightASL _p1; +_offsetA = getTerrainHeightASL _pA; + +_p1 = _p1 vectorAdd [0, 0, _offset0 - _offset1]; +_p0 = _pA vectorAdd [0, 0, _offset0 - _offsetA]; + +_fnc_getDistance = { + private "_distance"; + + _pX = + _p0; + _line = [ATLToASL _p0, ATLToASL _pX]; + + _distance = _this; + _iteration = _distance; + + while { + _iteration > 0.01 / 2 + } do { + _iteration = _iteration / 2; + + _pX = _p0 vectorAdd (_d vectorMultiply _distance); + + _offsetX = getTerrainHeightASL _pX; + + _pX = _pX vectorAdd [0, 0, _offset0 - _offsetX]; + + _line set [1, ATLToASL _pX]; + + _distance = _distance + (([1, -1] select (lineIntersects (_line + [_unit]) || {terrainIntersectASL _line})) * _iteration); + + if (_distance > _this) exitWith {_distance = _this}; + }; + + _distance +}; + +_distance = _range call _fnc_getDistance; + +_units = nearestObjects [_unit, ["Man"], _distance]; +_units deleteAt (_units find _unit); + +_fnc_doesIntersect = { + _pX = _p0 vectorAdd (_d vectorMultiply (_this select 1)); + + _offsetX = getTerrainHeightASL _pX; + + _pX = _pX vectorAdd [0, 0, _offset0 - _o1]; + + count ([_this select 0, "FIRE"] intersect [_p0, _pX]) > 0 +}; + +{ + if ([_x, _distance] call _fnc_doesIntersect) then { + _distance = _distance min (_unit distance _x); + }; +} forEach _units; + +//systemChat str _distance; +if (_distance < 0.5) exitWith {}; + +_pL = _p0 vectorAdd (_d vectorMultiply _distance); +_pL2 = _p0 vectorAdd (_d vectorMultiply (_distance - 0.5)); + +_offsetL = getTerrainHeightASL _pL; +_offsetL2 = getTerrainHeightASL _pL2; + +_pL = _pL vectorAdd [0, 0, _offset0 - _offsetL]; +_pL2 = _pL2 vectorAdd [0, 0, _offset0 - _offsetL2]; + +drawLine3D [ + _p0, + _pL, + [[1,0,0,1], [0,1,0,1]] select _isGreen +]; + +_spL = worldToScreen _pL; //systemChat str _spL; +_size = 2 * (_range - (positionCameraToWorld [0,0,0] distance _pL)) / _range; + +_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 ( terrainIntersect [_camPos, _pL2]) exitWith {}; +if (lineIntersects [ATLToASL _camPos, ATLToASL _pL2]) exitWith {}; + +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 +]; diff --git a/addons/laserpointer/functions/fnc_onDraw.sqf b/addons/laserpointer/functions/fnc_onDraw.sqf new file mode 100644 index 0000000000..6fa7275531 --- /dev/null +++ b/addons/laserpointer/functions/fnc_onDraw.sqf @@ -0,0 +1,34 @@ +// by commy2 +#include "script_component.hpp" + +_brightness = 2 - call EFUNC(common,ambientBrightness); +_isIR = currentVisionMode ACE_player; + +if (_isIR == 2) exitWith {}; + +_isIR = _isIR == 1; + +{ + _weapon = currentWeapon _x; + + _laser = switch (_weapon) do { + case (""): {""}; + case (primaryWeapon _x): { + primaryWeaponItems _x select 1; + }; + case (secondaryWeapon _x): { + secondaryWeaponItems _x select 1; + }; + case (handgunWeapon _x): { + handgunItems _x select 1; + }; + default {""}; + }; + + _laserID = ["ACE_acc_pointer_red", "ACE_acc_pointer_green"] find _laser; + + if (_laserID > -1 && {_x isFlashlightOn _weapon}) then { + [_x, 30, _laserID == 1 || _isIR] call FUNC(drawLaserpoint); + }; + +} forEach GVAR(nearUnits); diff --git a/addons/laserpointer/functions/script_component.hpp b/addons/laserpointer/functions/script_component.hpp new file mode 100644 index 0000000000..727c32539f --- /dev/null +++ b/addons/laserpointer/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\laserpointer\script_component.hpp" \ No newline at end of file diff --git a/addons/laserpointer/script_component.hpp b/addons/laserpointer/script_component.hpp new file mode 100644 index 0000000000..34c689cbbf --- /dev/null +++ b/addons/laserpointer/script_component.hpp @@ -0,0 +1,12 @@ +#define COMPONENT laserpointer +#include "\z\ace\addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_LASERPOINTER + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_ENABLED_LASERPOINTER + #define DEBUG_SETTINGS DEBUG_ENABLED_LASERPOINTER +#endif + +#include "\z\ace\addons\main\script_macros.hpp" \ No newline at end of file diff --git a/addons/laserpointer/stringtable.xml b/addons/laserpointer/stringtable.xml new file mode 100644 index 0000000000..1da46607d4 --- /dev/null +++ b/addons/laserpointer/stringtable.xml @@ -0,0 +1,33 @@ + + + + + + Laser Pointer (red) + Laserpointer (rot) + + + Laser Pointer (green) + Laserpointer (grün) + + + + Emits visible light. + Strahlt sichtbares Licht aus. + + + + <t color='#9cf953'>Use: </t>Turn Laser ON/OFF + <t color='#9cf953'>Use: </t>Turn Laser ON/OFF + <t color='#9cf953'>Použití: </t>Zapnout/vypnout laser + <t color='#9cf953'>Utiliser : </t>laser on/off + <t color='#9cf953'>Benutzen: </t>Laser EIN/AUS + <t color='#9cf953'>Uso: </t>Laser ON/OFF + <t color='#9cf953'>Użyj: </t>wł./wył. lasera + <t color='#9cf953'>Uso: </t>Ativar/Desativar laser + <t color='#9cf953'>Использовать: </t>вкл/выкл лазер + <t color='#9cf953'>Usar: </t>encender/apagar láser + + + +