From 01797fd3b92c36833ed12fba2690aec8380b573d Mon Sep 17 00:00:00 2001 From: jaynus Date: Sun, 12 Apr 2015 11:01:22 -0700 Subject: [PATCH] Integarate laser code into SALH guidance + self_designate. Note todo items. --- addons/laser/XEH_pre_init.sqf | 1 + .../functions/fnc_drawVisibleLaserTargets.sqf | 1 + addons/laser/functions/fnc_laserOn.sqf | 2 +- addons/laser/functions/fnc_laser_init.sqf | 8 +- addons/laser_selfdesignate/XEH_pre_init.sqf | 3 +- .../functions/fnc_findLaserSource.sqf | 19 +++ .../functions/fnc_laserHudDesignateOff.sqf | 24 +--- .../functions/fnc_laserHudDesignateOn.sqf | 122 +++++++----------- .../functions/fnc_seekerType_SALH.sqf | 13 +- 9 files changed, 89 insertions(+), 104 deletions(-) create mode 100644 addons/laser/functions/fnc_drawVisibleLaserTargets.sqf create mode 100644 addons/laser_selfdesignate/functions/fnc_findLaserSource.sqf diff --git a/addons/laser/XEH_pre_init.sqf b/addons/laser/XEH_pre_init.sqf index 5798e3c9a7..3fde1769e0 100644 --- a/addons/laser/XEH_pre_init.sqf +++ b/addons/laser/XEH_pre_init.sqf @@ -18,6 +18,7 @@ PREP(laserOff); PREP(handleLaserOn); PREP(handleLaserOff); +PREP(drawVisibleLaserTargets); PREP(laser_init); diff --git a/addons/laser/functions/fnc_drawVisibleLaserTargets.sqf b/addons/laser/functions/fnc_drawVisibleLaserTargets.sqf new file mode 100644 index 0000000000..161364c0f2 --- /dev/null +++ b/addons/laser/functions/fnc_drawVisibleLaserTargets.sqf @@ -0,0 +1 @@ +// @TODO: This is to draw the actual LaserTarget positions to utilize for laser shooting. \ No newline at end of file diff --git a/addons/laser/functions/fnc_laserOn.sqf b/addons/laser/functions/fnc_laserOn.sqf index 3091acc3f6..eb3cfd31f5 100644 --- a/addons/laser/functions/fnc_laserOn.sqf +++ b/addons/laser/functions/fnc_laserOn.sqf @@ -13,7 +13,7 @@ * Return value: * String, UUID for sending to laserOff function. */ - + #include "script_component.hpp" private ["_uuid", "_args"]; diff --git a/addons/laser/functions/fnc_laser_init.sqf b/addons/laser/functions/fnc_laser_init.sqf index 2790459724..1be770e4c8 100644 --- a/addons/laser/functions/fnc_laser_init.sqf +++ b/addons/laser/functions/fnc_laser_init.sqf @@ -5,21 +5,23 @@ TRACE_1("enter", _this); // Add the target to the global targets array // Everyone tracks them - // Add the laser localized to the laser array, and give it the default localized code PUSH(ACE_LASERS, _laserTarget); + // Check the vehicle, otherwise use the default _laserTarget setVariable ["ACE_LASER_CODE", ACE_DEFAULT_LASER_CODE, false]; + // Clean the lasers of any null objects while we are here REM(ACE_LASERS, objNull); if(!(local _laserTarget)) exitWith { }; + // The target is local, so its on this client if(!isDedicated) then { - _laserTarget setVariable ["ACE_LASERTARGET_SHOOTER", ACE_player, true]; + _laserTarget setVariable [QGVAR(owner), ACE_player, true]; [FUNC(laserTargetPFH), 0, [_laserTarget, ACE_player]] call cba_fnc_addPerFrameHandler; } else { // server side ownership of laser - //_laserTarget setVariable ["ACE_LASERTARGET_SHOOTER", nil, false]; + _laserTarget setVariable [QGVAR(owner), nil, true]; }; diff --git a/addons/laser_selfdesignate/XEH_pre_init.sqf b/addons/laser_selfdesignate/XEH_pre_init.sqf index dd971b9539..3f8c92e4db 100644 --- a/addons/laser_selfdesignate/XEH_pre_init.sqf +++ b/addons/laser_selfdesignate/XEH_pre_init.sqf @@ -5,7 +5,8 @@ PREP(laserHudDesignateOn); PREP(laserHudDesignateOff); PREP(unitTurretHasDesignator); -GVAR(laser) = nil; +PREP(findLaserSource); + GVAR(active) = false; FUNC(getPosASL) = {visiblePositionASL (_this select 0)}; diff --git a/addons/laser_selfdesignate/functions/fnc_findLaserSource.sqf b/addons/laser_selfdesignate/functions/fnc_findLaserSource.sqf new file mode 100644 index 0000000000..a432b838d8 --- /dev/null +++ b/addons/laser_selfdesignate/functions/fnc_findLaserSource.sqf @@ -0,0 +1,19 @@ +//findLaserSource.sqf +//#define DEBUG_MODE_FULL +#include "script_component.hpp" + +private["_emitter", "_owner", "_gunnerInfo", "_turretInfo", "_povPos", "_povDir"]; + +_emmiter = _this select 0; +_owner = _this select 1; + +_gunnerInfo = [_emmiter, (currentWeapon _emmiter)] call CBA_fnc_getFirer; +_turretInfo = [_emmiter, _gunnerInfo select 1] call EFUNC(common,getTurretDirection); +_povPos = _turretInfo select 0; +_povDir = _turretInfo select 1; + +if(!isNil "_povPos" && !isNil "_povDir") exitWith { + [_povPos, _povDir] +}; + +[-1,-1] \ No newline at end of file diff --git a/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOff.sqf b/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOff.sqf index 02ea7e6e70..fc50e571c7 100644 --- a/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOff.sqf +++ b/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOff.sqf @@ -1,28 +1,12 @@ #include "script_component.hpp" if( (count _this) > 2) then { - EXPLODE_3_PVT(_this,_vehicle,_shooter,_laserTarget); - // We got the optional vehicle list, clear the parameters - _vehicle setVariable[QGVAR(currentTarget), [], true]; + EXPLODE_3_PVT(_this,_shooter,_laserUuid, _localLaserTarget); + + [_laserUuid] call EFUNC(laser,laserOff); + deleteVehicle _localLaserTarget; }; -if(isNil QGVAR(laser)) exitWith { - false -}; -if(!local GVAR(laser)) then { - false -}; - -_handle = GVAR(laser) getVariable ["ACE_PFH_HANDLE", nil]; -if(!isNil "_handle") then { - [_handle] call cba_fnc_removePerFrameHandler; -}; - -REM(ACE_LASERS, GVAR(laser)); -deleteVehicle GVAR(laser); -GVAR(laser) = nil; GVAR(active) = false; - - true \ No newline at end of file diff --git a/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOn.sqf b/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOn.sqf index a6c8fc2295..e7518041ed 100644 --- a/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOn.sqf +++ b/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOn.sqf @@ -6,102 +6,72 @@ TRACE_1("enter", _this); #define FCS_UPDATE_DELAY 1 FUNC(laserHudDesignatePFH) = { - private["_strongestResultPos", "_args", "_laserTarget", "_shooter", "_vehicle", "_weapon", "_gunnerInfo", "_turret", "_pov", "_gunBeg", "_gunEnd", "_povPos", "_povDir", "_result", "_resultPositions", "_firstResult", "_forceUpdateTime"]; + private["_strongestResultPos", "_args", "_localLaserTarget", "_laserResultPosition", "_laserResult", "_shooter", "_vehicle", "_weapon", "_gunnerInfo", "_turretInfo", "_pov", "_gunBeg", "_gunEnd", "_povPos", "_povDir", "_result", "_resultPositions", "_firstResult", "_forceUpdateTime"]; _args = _this select 0; - _laserTarget = _args select 0; - _shooter = _args select 1; - - TRACE_1("", _args, (_laserTarget getVariable["ACE_LASER_CODE"])); - if((vehicle ACE_player) != _shooter || !alive _shooter || isNull _vehicle || isNull _laserTarget || !GVAR(active) ) exitWith { - [_vehicle, _shooter, _laserTarget] call FUNC(laserHudDesignateOff); + _shooter = _args select 0; + _localLaserTarget = _args select 2; + _vehicle = vehicle _shooter; + TRACE_1("", _args); + + if((vehicle _shooter) == _shooter || !alive _shooter || isNull _vehicle || !GVAR(active) ) exitWith { + _args call FUNC(laserHudDesignateOff); }; if(!([_shooter] call FUNC(unitTurretHasDesignator)) ) exitWith { - [_vehicle, _shooter, _laserTarget] call FUNC(laserHudDesignateOff); + _args call FUNC(laserHudDesignateOff); }; - if( (count _args) < 3) then { - _args set[2, diag_tickTime + FCS_UPDATE_DELAY]; + if( (count _args) < 4) then { + _args set[3, diag_tickTime + FCS_UPDATE_DELAY]; }; - _forceUpdateTime = _args select 2; - - _vehicle = vehicle _shooter; - _weapon = currentWeapon _vehicle; - - // Retrieve the gunner and turret memory point information - _gunnerInfo = [_vehicle, _weapon] call CBA_fnc_getFirer; + _forceUpdateTime = _args select 3; + + _gunnerInfo = [_vehicle, (currentWeapon _vehicle)] call CBA_fnc_getFirer; _turretInfo = [_vehicle, _gunnerInfo select 1] call EFUNC(common,getTurretDirection); _povPos = _turretInfo select 0; - _povDir = _turretInfo select 1; - _targetInfo = _vehicle getVariable[QGVAR(currentTarget), [] ]; - if( (count _targetInfo) > 0) then { - if(_laserTarget != (_targetInfo select 0) ) then { - _targetInfo = [] - }; - }; - if( (count _targetInfo) < 1) then { - _targetInfo = [_laserTarget, 1001]; // TODO: set laser code - _vehicle setVariable[QGVAR(currentTarget), _targetInfo, true]; - _laserTarget setVariable[QGVAR(owner), _vehicle, true]; - }; - - - _result = [_povPos, _povDir] call EFUNC(laser,shootCone); - if((count _result) > 0) then { - _resultPositions = _result select 2; + _laserResult = [_povPos, [1550,1550], 1001] call EFUNC(laser,seekerFindLaserSpot); + _laserResultPosition = _laserResult select 0; + TRACE_1("Search", _laserResult); - if((count _resultPositions) > 0) then { - _strongestResultPos = [_resultPositions, _povPos] call EFUNC(laser,findStrongestRay); - - // If the laser has moved less than a half meter, then dont move it. - // Just regular use of lasers will commonly make them move this much, - // but not across multiple close frames. - // This loses accuracy a little, but saves position updates per frame. - TRACE_5("", diag_tickTime, _forceUpdateTime, getPosASL _laserTarget, _strongestResultPos, ((getPosASL _laserTarget) distance _pos)); - - if(diag_tickTime > _forceUpdateTime) then { - TRACE_1("FCS Update", ""); - ["ace_fcs_forceUpdate", []] call ace_common_fnc_localEvent; - }; - - //if( (_laserTarget distance _strongestResultPos) > 0.1) then { - TRACE_1("LaserPos Update", ""); - _laserTarget setPosATL (ASLToATL _strongestResultPos); - //}; - - if(diag_tickTime > _forceUpdateTime) then { - _args set[2, diag_tickTime + FCS_UPDATE_DELAY]; - }; -#ifdef DEBUG_MODE_FULL - drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], (getPosATL _laserTarget), 0.75, 0.75, 0, "", 0.5, 0.025, "TahomaB"]; - - { - private["_position"]; - _position = _x select 0; - drawLine3d [ASLToATL _povPos, ASLToATL _position, [0,0,1,1] ]; - } forEach _resultPositions; -#endif + if((count _laserResult) > 0) then { + // If the laser has moved less than a half meter, then dont move it. + // Just regular use of lasers will commonly make them move this much, + // but not across multiple close frames. + // This loses accuracy a little, but saves position updates per frame. + TRACE_4("", diag_tickTime, _forceUpdateTime, _laserResultPosition, (_laserResultPosition vectorDistance _pos)); + + if(diag_tickTime > _forceUpdateTime) then { + TRACE_1("FCS Update", ""); + ["ace_fcs_forceUpdate", []] call ace_common_fnc_localEvent; }; + + if(diag_tickTime > _forceUpdateTime) then { + _args set[3, diag_tickTime + FCS_UPDATE_DELAY]; + }; + + _localLaserTarget setPosASL _laserResultPosition; + +#ifdef DEBUG_MODE_FULL + drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], _laserResultPosition, 0.75, 0.75, 0, "", 0.5, 0.025, "TahomaB"]; + drawLine3d [ASLToATL _povPos, ASLToATL _laserResultPosition, [0,0,1,1] ]; +#endif }; - _this set[0, _args]; }; -private ["_laserTarget", "_handle", "_vehicle"]; +private ["_laserTarget", "_handle", "_vehicle", "_laserUuid"]; -if(isNil QGVAR(laser)) then { - _laserTarget = "LaserTargetW" createVehicle (getpos ACE_player); - +if(!GVAR(active)) then { GVAR(active) = true; - _handle = [FUNC(laserHudDesignatePFH), 0.1, [_laserTarget, ACE_player]] call cba_fnc_addPerFrameHandler; - _laserTarget setVariable ["ACE_PFH_HANDLE", _handle, false]; + TRACE_1("Activating laser", ""); + _laserUuid = [(vehicle ACE_player), ACE_player, FUNC(findLaserSource), 1550, 1001, 1] call EFUNC(laser,laserOn); - // Clear the vehicle parameters - _vehicle setVariable[QGVAR(currentTarget), [], true]; - - GVAR(laser) = _laserTarget; + // @TODO: Create the local target for the players side + _localLaserTarget = "LaserTargetW" createVehicleLocal (getpos ACE_player); + + _handle = [FUNC(laserHudDesignatePFH), 0.25, [ACE_player, _laserUuid, _localLaserTarget]] call cba_fnc_addPerFrameHandler; } else { [] call FUNC(laserHudDesignateOff); [] call FUNC(laserHudDesignateOn); diff --git a/addons/missileguidance/functions/fnc_seekerType_SALH.sqf b/addons/missileguidance/functions/fnc_seekerType_SALH.sqf index f4d36285d8..d54a86c74c 100644 --- a/addons/missileguidance/functions/fnc_seekerType_SALH.sqf +++ b/addons/missileguidance/functions/fnc_seekerType_SALH.sqf @@ -1,4 +1,4 @@ -//#define DEBUG_MODE_FULL +#define DEBUG_MODE_FULL #include "script_component.hpp" EXPLODE_7_PVT(((_this select 1) select 0),_shooter,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile); @@ -10,8 +10,15 @@ _launchParams = _this select 1; _seekerParams = _launchParams select 3; // TODO: this needs to be shootCone/findStrongestRay after testing -_targets = [_projectile, ACE_DEFAULT_LASER_CODE, (_seekerParams select 0)] call ace_laser_fnc_findLaserDesignator; -_foundTargetPos = getPosASL (_targets select 1); +//_targets = [_projectile, ACE_DEFAULT_LASER_CODE, (_seekerParams select 0)] call ace_laser_fnc_findLaserDesignator; +//_foundTargetPos = getPosASL (_targets select 1); + +_laserResult = [(getPosASL _projectile), [1550,1550], 1001] call EFUNC(laser,seekerFindLaserSpot); +_foundTargetPos = _laserResult select 0; +TRACE_1("Search", _laserResult); + +// @TODO: Check angle to target from seeker head + TRACE_1("Seeker return target pos", _foundTargetPos); _foundTargetPos; \ No newline at end of file