Skip to content

Commit

Permalink
MP reWork (step 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenLuke committed Feb 16, 2020
1 parent 131e868 commit 8aebb02
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 185 deletions.
4 changes: 2 additions & 2 deletions addons/laser/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class CfgVehicles {
class ACE_Equipment {
class ACE_ToggleMarkerLaser {
displayName = CSTRING(laserMarkToggle);
condition = QUOTE('Laserdesignator' in weapons ACE_player);
statement = QUOTE( ARR_1(ACE_player) call FUNC(toggleMarkerHand));
condition = QUOTE(getNumber (configFile >> 'CfgWeapons' >> (currentWeapon ACE_player) >> QUOTE(QUOTE(ADDON)) >> 'markerEnabled') > 0);
statement = QUOTE( ARR_1(ACE_player) call FUNC(toggleMarker));
showDisabled = 0;
exceptions[] = {"isNotSwimming"};
};
Expand Down
17 changes: 16 additions & 1 deletion addons/laser/CfgWeapons.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@

class CfgWeapons {
class Binocular;
class Laserdesignator : Binocular {
class Laserdesignator: Binocular {
visionMode[] = {"Normal","NVG"};
class ADDON {
markerEnabled = 1;
};
};
class Default;
class Laserdesignator_Mounted: Default {
class ADDON {
markerEnabled = 1;
};
};
class Laserdesignator_pilotCamera: Laserdesignator_Mounted {
class ADDON {
markerEnabled = 1;
pilotLaser = 1;
};
};
};
4 changes: 2 additions & 2 deletions addons/laser/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PREP(laserOff);
PREP(laserOn);
PREP(laserPointTrack);
PREP(laserTargetPFH);
PREP(manageMarkers);
PREP(onLaserDesignatorDraw);
PREP(rotateVectLine);
PREP(rotateVectLineGetMap);
Expand All @@ -17,5 +18,4 @@ PREP(shootCone);
PREP(shootRay);
PREP(showVehicleHud);
PREP(toggleLST);
PREP(toggleMarker);
PREP(toggleMarkerHand);
PREP(toggleMarker);
183 changes: 128 additions & 55 deletions addons/laser/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ if (hasInterface) then {
params ["_uuid", "_args"];
TRACE_2("ace_laserOn eh",_uuid,_args);
[GVAR(laserEmitters), _uuid, _args] call CBA_fnc_hashSet;
private _unit = _args select 0;
if (hasPilotCamera _unit) then {
[_unit] call FUNC(laserPointTrack);
};
}] call CBA_fnc_addEventHandler;

["ace_laserOff", {
Expand All @@ -37,6 +41,79 @@ if (hasInterface) then {
};
}] call CBA_fnc_addEventHandler;

["ace_markerOn", {
params ["_uuid", "_args"];
_args params ["_vehicle"];
private _found = false;
{
_x params ["_unit", "_sourceName", "_selectedWeapon", "_selectedTurret", "_pilotLaser", "_active"];
if(isNull _unit) exitWith {};
if (_unit == _vehicle) exitWith {
_found = true;
GVAR(laserMarkers) set [_forEachIndex, [_unit, _sourceName, _selectedWeapon, _selectedTurret, _pilotLaser, true]];
private _markerMessage = localize ([LSTRING(LaserMarkOff), LSTRING(LaserMarkOn)] select (true));
[_markerMessage] call EFUNC(common,displayTextStructured);
_unit setVariable [QGVAR(laserMarkerOn), true];
};
} forEach GVAR(laserMarkers);

//If not in the list; add to the list
if (! _found) then {
private _weapons = weapons _vehicle;
{
_weapons = _weapons + (_vehicle weaponsTurret _x);
} forEach (allTurrets _vehicle);
private _selectedWeapon = "";
private _selectedTurret = [];
private _sourcePoint = "";
private _hasMarker = false;
private _pilotLaser = false;
{
if ((getNumber (configFile >> "CfgWeapons" >> _x >> "Laser")) == 1) exitWith {
_selectedWeapon = _x;
_y = _x;
_hasMarker = (getNumber (configFile >> "CfgWeapons" >> _x >> QUOTE(ADDON) >> "markerEnabled")) > 0;
if (_hasMarker) then {
_pilotLaser = (getNumber (configFile >> "CfgWeapons" >> _x >> QUOTE(ADDON) >> "pilotLaser")) > 0;
if(_pilotLaser) then {
_sourcePoint = getText (configfile >> "CfgVehicles" >> (typeOf _vehicle) >> "memoryPointDriverOptics");
};
};
{
private _turretWeapons = _vehicle weaponsTurret _x;
if (_turretWeapons find _y > -1) then {
private _turretConfig = [_vehicle, _x] call CBA_fnc_getTurret;
_selectedTurret = _x;
_sourcePoint = getText(_turretConfig >> "memoryPointGunnerOptics");
};
} forEach (allTurrets _vehicle);
};
} forEach _weapons;
if(allUnitsUAV find _vehicle > -1) then {
_sourcePoint = getText (configfile >> "CfgVehicles" >> (typeOf _vehicle) >> "uavCameraGunnerPos");
};
GVAR(laserMarkers) pushBack [_vehicle, _sourcePoint, _selectedWeapon, _selectedTurret, _pilotLaser, false];
};


}] call CBA_fnc_addEventHandler;

["ace_markerOff", {
params ["_uuid", "_args"];
_args params ["_vehicle"];
{
_x params ["_unit", "_sourceName", "_selectedWeapon", "_selectedTurret", "_pilotLaser", "_active"];
if(isNull _unit) exitWith {};
if (_unit == _vehicle) exitWith {
_vehicle setVariable [QGVAR(laserMarkerOn), false];
GVAR(laserMarkers) set [_forEachIndex, [_vehicle, _sourceName, _selectedWeapon, _selectedTurret, _pilotLaser, false]];
private _markerMessage = localize ([LSTRING(LaserMarkOff), LSTRING(LaserMarkOn)] select (false));
[_markerMessage] call EFUNC(common,displayTextStructured);
};
} forEach GVAR(laserMarkers);

}] call CBA_fnc_addEventHandler;

[QGVAR(updateCode), {
params ["_uuid", "_newCode"];
TRACE_2("ace_laser_updateCode eh",_uuid,_newCode);
Expand All @@ -47,70 +124,66 @@ if (hasInterface) then {
};
}] call CBA_fnc_addEventHandler;


["ace_laserOn", {
params ["_uuid", "_args"];
private _vehicle = _args select 0;
if (hasPilotCamera _vehicle) then {
[_vehicle] call FUNC(laserPointTrack);
};
}] call CBA_fnc_addEventHandler;

["AllVehicles", "init", {
params ["_vehicle"];
private _hasPilotCamera = hasPilotCamera _vehicle;
private _hasLaserSensor = isClass (configfile >> "CfgVehicles" >> (typeOf _vehicle) >> "Components" >> "SensorsManagerComponent" >> "Components" >> "LaserSensorComponent");
params ["_unit"];

private _weapons = weapons _unit;
{
_weapons = _weapons + (_unit weaponsTurret _x);
} forEach (allTurrets _unit);

private _selectedWeapon = "";
private _selectedTurret = [];
private _sourcePoint = "";
private _hasMarker = false;
private _pilotLaser = false;
{
if ((getNumber (configFile >> "CfgWeapons" >> _x >> "Laser")) == 1) exitWith {
_selectedWeapon = _x;
_y = _x;
_hasMarker = (getNumber (configFile >> "CfgWeapons" >> _x >> QUOTE(ADDON) >> "markerEnabled")) > 0;
if (_hasMarker) then {
_pilotLaser = (getNumber (configFile >> "CfgWeapons" >> _x >> QUOTE(ADDON) >> "pilotLaser")) > 0;
if(_pilotLaser) then {
_sourcePoint = getText (configfile >> "CfgVehicles" >> (typeOf _unit) >> "memoryPointDriverOptics");
};
};
{
private _turretWeapons = _unit weaponsTurret _x;
if (_turretWeapons find _y > -1) then {
private _turretConfig = [_unit, _x] call CBA_fnc_getTurret;
_selectedTurret = _x;
_sourcePoint = getText(_turretConfig >> "memoryPointGunnerOptics");
};
} forEach (allTurrets _unit);
};
} forEach _weapons;

if(allUnitsUAV find _unit > -1) then {
_sourcePoint = getText (configfile >> "CfgVehicles" >> (typeOf _vehicle) >> "uavCameraGunnerPos");
};

GVAR(laserMarkers) pushBack [_unit, _sourcePoint, _selectedWeapon, _selectedTurret, _pilotLaser, false];

if ( (_hasPilotCamera) && (_hasLaserSensor) ) then {
_vehicle setVariable [QGVAR(hasLaserSpotTracker), true];
_vehicle setVariable [QGVAR(laserSpotTrackerOn), false];
if (hasPilotCamera _unit) then {
_unit setVariable [QGVAR(hasLaserSpotTracker), true];
_unit setVariable [QGVAR(laserSpotTrackerOn), false];
private _actionOff = ["LSTOff", localize LSTRING(LSTOff), "", {[_this select 0] call FUNC(toggleLST)}, {(_this select 0) getVariable [QGVAR(laserSpotTrackerOn), false]}] call ace_interact_menu_fnc_createAction;
[_vehicle, 1, ["ACE_SelfActions"], _actionOff] call ace_interact_menu_fnc_addActionToObject;
[_unit, 1, ["ACE_SelfActions"], _actionOff] call ace_interact_menu_fnc_addActionToObject;
private _actionOn = ["LSTOn", localize LSTRING(LSTOn), "", {[_this select 0] call FUNC(toggleLST)}, {!((_this select 0) getVariable [QGVAR(laserSpotTrackerOn), false])}] call ace_interact_menu_fnc_createAction;
[_vehicle, 1, ["ACE_SelfActions"], _actionOn] call ace_interact_menu_fnc_addActionToObject;
[_unit, 1, ["ACE_SelfActions"], _actionOn] call ace_interact_menu_fnc_addActionToObject;
};

private _foundLaser = 0;
private _weapons = weapons _vehicle;
{
_weapons = _weapons + (_vehicle weaponsTurret _x);
} forEach (allTurrets _vehicle);

if (_weapons find "Laserdesignator_mounted" > -1) then {
_foundLaser = 1;
};
if (_weapons find "Laserdesignator_pilotCamera" > -1) then {
_foundLaser = 2;
if (_hasMarker && !(_unit isKindOf "Man")) then {
_unit setVariable [QGVAR(laserMarkerOn), false];
private _actionOff = ["LaserMarkerOff", localize LSTRING(laserMarkOff), "", {[_this select 0] call FUNC(toggleMarker)}, {(_this select 0) getVariable [QGVAR(laserMarkerOn), false]}] call ace_interact_menu_fnc_createAction;
[_unit, 1, ["ACE_SelfActions"], _actionOff] call ace_interact_menu_fnc_addActionToObject;
private _actionOn = ["LaserMarkerOn", localize LSTRING(laserMarkOn), "", {[_this select 0] call FUNC(toggleMarker)}, {!((_this select 0) getVariable [QGVAR(laserMarkerOn), false])}] call ace_interact_menu_fnc_createAction;
[_unit, 1, ["ACE_SelfActions"], _actionOn] call ace_interact_menu_fnc_addActionToObject;
};
}, true, [], true] call CBA_fnc_addClassEventHandler;

if (_foundlaser == 0) exitWith {};
_vehicle setVariable [QGVAR(hasMarkerLaser), true];
_vehicle setVariable [QGVAR(laserMarkerOn), false];

private _actionOff = ["LaserMarkerOff", localize LSTRING(laserMarkOff), "", {[_this select 0] call FUNC(toggleMarker)}, {(_this select 0) getVariable [QGVAR(laserMarkerOn), false]}] call ace_interact_menu_fnc_createAction;
[_vehicle, 1, ["ACE_SelfActions"], _actionOff] call ace_interact_menu_fnc_addActionToObject;
private _actionOn = ["LaserMarkerOn", localize LSTRING(laserMarkOn), "", {[_this select 0] call FUNC(toggleMarker)}, {!((_this select 0) getVariable [QGVAR(laserMarkerOn), false])}] call ace_interact_menu_fnc_createAction;
[_vehicle, 1, ["ACE_SelfActions"], _actionOn] call ace_interact_menu_fnc_addActionToObject;

}, nil, nil, true] call CBA_fnc_addClassEventHandler;


["CAManBase", "init", {
params ["_unit"];
findDisplay 46 displayAddEventHandler ["KeyDown", {
params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"];
if (_ctrl) then {_key = _key + 486539264};
if (_shift) then {_key = _key + 704643072};
if (_alt) then {_key = _key + 939524096};
private _lightKeys = actionKeys "headlights";
if (_lightKeys find _key > -1) then {
if ( ((currentWeapon player) == "Laserdesignator")) then {
[player] call FUNC(toggleMarkerHand);
};
};
}];
}, nil, nil, true] call CBA_fnc_addClassEventHandler;
[] call FUNC(manageMarkers);

// Shows detector and mine posistions in 3d when debug is on
#ifdef DRAW_LASER_INFO
Expand Down
1 change: 1 addition & 0 deletions addons/laser/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ACE_DEFAULT_LASER_BEAMSPREAD = 1;

GVAR(laserEmitters) = [] call CBA_fnc_hashCreate;
GVAR(trackedLaserTargets) = [];
GVAR(laserMarkers) = [];
GVAR(pfehID) = -1;

ADDON = true;
108 changes: 108 additions & 0 deletions addons/laser/functions/fnc_manageMarkers.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include "script_component.hpp"

/*
/*
* Author: LorenLuke
* Used to initiate long-running PFH for laser markers;
*
* Arguments:
* Nothing
*
* Return Value:
* Nothing
*
* Example:
* [] call ace_laser_fnc_manageMarkers
*
* Public: No
*/

[{
if ((currentVisionMode ACE_player) == 0) exitWith {};
if(count GVAR(laserMarkers) < 1) exitWith {};

//randomly schedule an occasional pruning
if ((random 5000) < 2) then {
{
_x params ["_unit", "_sourceName", "_selectedWeapon", "_selectedTurret", "_pilotLaser", "_active"];
private _weapons = weapons _unit;
{
_weapons = _weapons + (_unit weaponsTurret _x);
} forEach (allTurrets _unit);
if(_weapons find _selectedWeapon < 0) then {
GVAR(laserMarkers) deleteAt _forEachIndex;
};
} forEach GVAR(laserMarkers);
};

{
_x params ["_unit", "_sourceName", "_selectedWeapon", "_selectedTurret", "_pilotLaser", "_active"];
if(_active) then {
private _laserTargetPos = getPosASL (laserTarget _unit);
if (_laserTargetPos isEqualTo [0,0,0]) then {
{
_x params ["_targetObject", "_owner", "_laserUuid", "_laserCode"];
if(_owner == _unit) exitWith {
_laserTargetPos = getPosASL _targetObject;
};
} forEach GVAR(trackedLaserTargets);
};
if(! (_laserTargetPos isEqualTo [0,0,0])) then {
private _laserSource = [0,0,0];
private _direction = _unit weaponDirection _selectedWeapon;
if(count _selectedTurret > 0) then {
private _turretConfig = [_unit, _selectedTurret] call CBA_fnc_getTurret;
_sourceName = getText(_turretConfig >> "memoryPointGunnerOptics");
private _gunEnd = getText(_turretConfig >> "gunEnd");
private _gunBeg = getText(_turretConfig >> "gunBeg");
if( !((_gunEnd == "") || (_gunBeg == "")) ) then {
private _modelPos = (vehicle player selectionPosition _gunEnd) vectorFromTo (vehicle player selectionPosition _gunBeg);
_direction = (_unit ModelToWorldVisual [0,0,0]) vectorFromTo (_unit modelToWorldVisual _modelPos);
} else {
private _animationSourceBody = getText(_turretConfig >> "animationSourceBody");
private _animationSourceGun = getText(_turretConfig >> "animationSourceGun");
private _gBody = -deg(_unit animationPhase _animationSourceBody);
private _gGun = deg(_unit animationPhase _animationSourceGun);
private _modelPos = _unit vectorModelToWorldVisual ([1, _gBody, _gGun] call CBA_fnc_polar2vect);
_direction = (_unit ModelToWorldVisual [0,0,0]) vectorFromTo (_unit modelToWorldVisual _modelPos);
};
};

if( _pilotLaser) then {
_direction = (_unit modelToWorldWorld [0,0,0]) vectorFromTo (_unit modelToWorldWorld (getPilotCameraDirection _unit));
};


if(_sourceName == "") then {
private _p0 = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "lefthand"));
private _p1 = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "righthand"));
_laserSource = ((_p0 vectorAdd _p1) vectorMultiply (1/2));
_laserSource = _laserSource vectorAdd ( ( vectorNormalized(_direction vectorCrossProduct (_laserSource vectorFromTo _p1))) vectorMultiply 0.025);
} else {
_laserSource = _unit modelToWorldVisualWorld (_unit selectionPosition _sourceName);
};

_vecCos = acos(_direction vectorCos (_laserSource vectorFromTo _laserTargetPos));
if( acos(_direction vectorCos (_laserSource vectorFromTo _laserTargetPos)) > 0.01) then {
private _intersects= lineIntersectsSurfaces [_laserSource, _laserSource vectorAdd (_direction vectorMultiply 10000), _unit];
_laserTargetPos = _laserSource vectorAdd (_direction vectorMultiply 10000);
if(count _intersects > 0) then {
_laserPos = (_intersects select 0) select 0;
};
};

private _distance = ( (_laserTargetPos distance _laserSource) max ((getPosASL (laserTarget _unit)) distance (_laserSource)) ) + 1.5;
private _vector = _laserSource vectorFromTo _laserTargetPos;

private _num = 13;
private _diam = 0.005;
for "_i" from 1 to _num do {
private _toPos = (_laserSource vectorAdd (_vector vectorMultiply _distance)) vectorAdd [sin(_i*(360/_num))*_diam,cos(_i*(360/_num))*_diam,0];
drawLine3D [ASLToAGL (_laserSource), ASLToAGL (_toPos), [0.8,1,0.8,1]];
};
};
};

} forEach GVAR(laserMarkers);

}, 0, []] call CBA_fnc_addPerFrameHandler;
Loading

0 comments on commit 8aebb02

Please sign in to comment.