Merge pull request #135 from KoffeinFlummi/syncedScopeAdjustment

Synced scope adjustment
This commit is contained in:
commy2 2015-02-12 16:24:41 +01:00
commit a41299b05a
18 changed files with 265 additions and 204 deletions

View File

@ -82,7 +82,7 @@ enableCamShake true;
}] call FUNC(addEventhandler);
GVAR(OldPlayerInventory) = ACE_player call FUNC(getAllGear);
GVAR(OldPlayerInventory) = [ACE_player] call FUNC(getAllGear);
GVAR(OldPlayerVisionMode) = currentVisionMode ACE_player;
GVAR(OldZeusDisplayIsOpen) = !(isNull findDisplay 312);
GVAR(OldCameraView) = cameraView;
@ -93,7 +93,7 @@ GVAR(OldPlayerTurret) = [ACE_player] call FUNC(getTurretIndex);
[{
// "playerInventoryChanged" event
_newPlayerInventory = ACE_player call FUNC(getAllGear);
_newPlayerInventory = [ACE_player] call FUNC(getAllGear);
if !(_newPlayerInventory isEqualTo GVAR(OldPlayerInventory)) then {
// Raise ACE event locally
GVAR(OldPlayerInventory) = _newPlayerInventory;

View File

@ -75,6 +75,7 @@ PREP(getVehicleCargo);
PREP(getVehicleCodriver);
PREP(getVehicleCrew);
PREP(getWeaponAzimuthAndInclination);
PREP(getWeaponIndex);
PREP(getWeaponType);
PREP(getWindDirection);
PREP(goKneeling);
@ -128,6 +129,7 @@ PREP(toBin);
PREP(toBitmask);
PREP(toHex);
PREP(toNumber);
PREP(throttledPublicVariable);
PREP(unmuteUnit);
PREP(waitAndExecute);

View File

@ -0,0 +1,25 @@
/*
* Author: commy2
* Get the index of the weapon.
* 0 = primary, 1 = secondary, 2 = handgun, -1 = other
*
* Argument:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
*
* Return value:
* Weapon index <NUMBER>
*
* Public: No
*/
#include "script_component.hpp"
EXPLODE_2_PVT(_this,_unit,_weapon);
if (_weapon = "") exitWith {-1};
[
primaryWeapon _unit,
secondaryWeapon _unit,
handgunWeapon _unit
] find _weapon

View File

@ -0,0 +1,49 @@
/*
* Author: CAA-Picard
* Schedules the publishment of an object variable to reduce network overhead
*
* Arguments:
* 0: Unit <OBJECT>.
* 1: Variable name <STRING>
* 2: Maximum delay <NUMBER>
*
* Return Value:
* None
*
* Example:
* None
*
* Public: No
*/
#include "script_component.hpp"
EXPLODE_3_PVT(_this,_unit,_varName,_maxDelay);
// Create the publish scheduler PFH the first time
if (isNil QGVAR(publishSchedId)) then {
GVAR(publishVarNames) = [];
GVAR(publishNextTime) = 1e7;
GVAR(publishSchedId) = [{
if (diag_tickTime > GVAR(publishNextTime)) then {
{
EXPLODE_2_PVT(_x,_unit,_varName);
_unit setVariable [_varName, (_unit getVariable _varName), true];
} forEach GVAR(publishVarNames);
GVAR(publishVarNames) = [];
GVAR(publishNextTime) = 1e7;
};
}, 0, []] call cba_fnc_addPerFrameHandler;
};
// If the variable is not on the list
if (GVAR(publishVarNames) find [_unit,_varName] == -1) exitWith {
GVAR(publishVarNames) pushBack [_unit,_varName];
GVAR(publishNextTime) = GVAR(publishNextTime) min (diag_tickTime + _maxDelay);
};
// If the variable is on the list
GVAR(publishNextTime) = GVAR(publishNextTime) min (diag_tickTime + _maxDelay);

View File

@ -13,39 +13,7 @@ class Extended_PostInit_EventHandlers {
class Extended_Fired_EventHandlers {
class CAManBase {
class ADDON {
clientFired = QUOTE(if (_this select 0 == ACE_player) then { _this call FUNC(firedEH);};);
};
};
};
class Extended_Take_EventHandlers {
class CAManBase {
class ADDON {
clientTake = QUOTE(if (_this select 0 == ACE_player) then{ _this call FUNC(inventoryCheck);};);
};
};
};
class Extended_Put_EventHandlers {
class CAManBase {
class ADDON {
clientPut = QUOTE(if (_this select 0 == ACE_player) then {_this call FUNC(inventoryCheck);};);
};
};
};
class Extended_InitPost_EventHandlers {
class CAManBase {
class ADDON {
init = QUOTE(if (_this select 0 == call EFUNC(common,player)) then{ _this call FUNC(inventoryCheck);};);
};
};
};
class Extended_Respawn_EventHandlers {
class CAManBase {
class ADDON {
respawn = QUOTE(if (_this select 0 == call EFUNC(common,player)) then{ _this call FUNC(inventoryCheck);};);
fired = QUOTE(_this call FUNC(firedEH););
};
};
};

View File

@ -4,7 +4,7 @@ class RscTitles {
movingEnable = 0;
enableSimulation = 1;
enableDisplay = 1;
onLoad = QUOTE(_this spawn compile preprocessFileLineNumbers QUOTE(QUOTE(PATHTOF(scripts\zeroingOnLoad.sqf))); uiNamespace setVariable [ARR_2('ACE_Scopes_Debug', _this)];);
onLoad = QUOTE(uiNamespace setVariable [ARR_2(QUOTE(QGVAR(ZeroingDisplay)),_this select 0)];);
duration = 1e+011;
fadein = 0;
fadeout = 0;
@ -13,7 +13,7 @@ class RscTitles {
class RscText;
class controls {
class ACE_Scopes_Zeroing_BG : RscPicture {
idc = 925001;
idc = 11;
type = 0;
text = PATHTOF(UI\scopes_bg.paa);
style = 48 + 0x800;
@ -30,7 +30,7 @@ class RscTitles {
h = 0.3 * safezoneH;
};
class ACE_Scopes_Zeroing_Vertical : RscText {
idc = 925002;
idc = 12;
type = 0;
style = 2;
sizeEx = 0.04;
@ -47,7 +47,7 @@ class RscTitles {
h = 0.025 * safezoneH;
};
class ACE_Scopes_Zeroing_Horizontal : RscText {
idc = 925003;
idc = 13;
type = 0;
style = 0;
sizeEx = 0.04;

View File

@ -9,32 +9,27 @@
if !(hasInterface) exitWith {};
// show overlay after changing weapon/optic
0 spawn {
_layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
while {True} do {
waitUntil {[ACE_player, 0,0] call FUNC(canAdjustScope)};
_layer cutRsc [QGVAR(Zeroing), "PLAIN", 0, false];
sleep 3;
_layer cutFadeOut 2;
// Check inventory when it changes
["playerInventoryChanged", {
[ACE_player] call FUNC(inventoryCheck);
}] call EFUNC(common,addEventhandler);
_weapon = currentWeapon ACE_player;
_optics = [ACE_player] call FUNC(getOptics);
waitUntil {sleep 0.05; !(_optics isEqualTo ([ACE_player] call FUNC(getOptics))) or (currentWeapon ACE_player != _weapon)};
};
};
// instantly hide when scoping in
0 spawn {
_layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
while {True} do {
waitUntil {sleep 0.05; cameraView == "GUNNER"};
if !(isNull GVAR(fadeScript)) then {
terminate GVAR(fadeScript);
};
// Instantly hide knobs when scoping in
["cameraViewChanged", {
EXPLODE_2_PVT(_this,_player,_newCameraView);
if (_newCameraView == "GUNNER") then {
private "_layer";
_layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
_layer cutText ["", "PLAIN", 0];
if !(isNil QGVAR(fadePFH)) then {
[GVAR(fadePFH)] call cba_fnc_removePerFrameHandler;
GVAR(fadePFH) = nil;
};
};
};
}] call EFUNC(common,addEventhandler);
// Add keybinds

View File

@ -6,8 +6,8 @@ PREP(adjustScope);
PREP(canAdjustScope);
PREP(firedEH);
PREP(getOptics);
PREP(hideZeroing);
PREP(inventoryCheck);
PREP(showZeroing);
GVAR(fadeScript) = scriptNull;

View File

@ -5,8 +5,8 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = { "ace_main", "ace_common" };
author[] = {"KoffeinFlummi"};
requiredAddons[] = { "ace_common" };
author[] = {"KoffeinFlummi", "CAA-Picard"};
authorUrl = "https://github.com/KoffeinFlummi";
VERSION_CONFIG;
};

View File

@ -1,42 +1,44 @@
/*
* Author: KoffeinFlummi
*
* Changes the adjustment for the current scope
*
* Arguments:
* 0: Horizontal adjustment
* 1: Vertical adjustment
* Argument:
* 0: Unit <OBJECT>
* 1: Horizontal adjustment <NUMBER>
* 2: Vertical adjustment <NUMBER>
*
* Return Value:
* True
* Return value:
* True <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_weapons", "_zeroing", "_pitchbankyaw", "_pitch", "_bank", "_yaw", "_hint"];
_unit = _this select 0;
_weapons = [
primaryWeapon _unit,
secondaryWeapon _unit,
handgunWeapon _unit
];
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (isNil QGVAR(Adjustment)) then {
GVAR(Adjustment) = [[0,0], [0,0], [0,0]];
_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
_adjustment = [[0,0], [0,0], [0,0]];
_unit setVariable [QGVAR(Adjustment), _adjustment];
};
_zeroing = GVAR(Adjustment) select (_weapons find (currentWeapon _unit));
_zeroing = _adjustment select _weaponIndex;
_zeroing set [0, (round (((_zeroing select 0) + (_this select 1)) * 10)) / 10];
_zeroing set [1, (round (((_zeroing select 1) + (_this select 2)) * 10)) / 10];
GVAR(Adjustment) set [_weapons find (currentWeapon _unit), _zeroing];
// Change the adjustment array
_adjustment set [_weaponIndex, _zeroing];
[_unit, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
playSound (["ACE_Scopes_Click_1", "ACE_Scopes_Click_2", "ACE_Scopes_Click_3"] select floor random 3);
// slightly rotate the player if looking through optic
if (cameraView == "GUNNER") then {
_pitchbankyaw = [_unit] call EFUNC(common,getPitchBankYaw);
// these are not exact mil-to-degree conversions, but instead chosen
// to minimize the effect of rounding errors
@ -44,26 +46,11 @@ if (cameraView == "GUNNER") then {
_bank = _pitchbankyaw select 1;
_yaw = (_pitchbankyaw select 2) + ((_this select 1) * -0.04);
[_unit, _pitch, _bank, _yaw] call EFUNC(common,setPitchBankYaw)
};
_display = uiNamespace getVariable [QGVAR(ZeroingDisplay), displayNull];
if !(isNull _display) then {
_vertical = _display displayCtrl 925002;
_horizontal = _display displayCtrl 925003;
_vertical ctrlSetText (str (_zeroing select 1));
_horizontal ctrlSetText (str (_zeroing select 0));
};
} else {
[] call FUNC(showZeroing);
if (!isNull (missionNamespace getVariable [QGVAR(fadeScript), scriptNull])) then {
terminate GVAR(fadeScript);
};
if (cameraView != "GUNNER") then {
GVAR(fadeScript) = 0 spawn {
_layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
_layer cutRsc [QGVAR(Zeroing), "PLAIN", 0, false];
sleep 3;
_layer cutFadeOut 2;
};
};
true

View File

@ -1,43 +1,40 @@
/*
* Author: KoffeinFlummi
*
* Checks if a player can adjust his optic in the given way.
*
* Arguments:
* 0: Horizontal adjustment
* 1: Vertical adjustment
* Argument:
* 0: Unit <OBJECT>
* 1: Horizontal adjustment <NUMBER>
* 2: Vertical adjustment <NUMBER>
*
* Return Value:
* Can adjustment be done? (Bool)
* Return value:
* Can adjustment be done? <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_weapons", "_zeroing", "_optic", "_maxHorizontal", "_maxVertical"];
private ["_unit", "_weaponIndex", "_zeroing", "_optic", "_maxHorizontal", "_maxVertical"];
_unit = _this select 0;
_weapons = [
primaryWeapon _unit,
secondaryWeapon _unit,
handgunWeapon _unit
];
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {false};
if !(currentWeapon _unit in _weapons) exitWith {false};
if (isNil QGVAR(Adjustment)) then {
GVAR(Adjustment) = [[0,0], [0,0], [0,0]];
_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
_adjustment = [[0,0], [0,0], [0,0]];
};
if (isNil QGVAR(Optics)) then {
GVAR(Optics) = ["", "", ""];
};
_zeroing = GVAR(Adjustment) select (_weapons find (currentWeapon _unit));
_zeroing = _adjustment select _weaponIndex;
_zeroX = (_zeroing select 0) + (_this select 1);
_zeroY = (_zeroing select 1) + (_this select 2);
_optic = GVAR(Optics) select (_weapons find (currentWeapon _unit));
_optic = GVAR(Optics) select _weaponIndex;
_maxHorizontal = getArray (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_Horizontal");
_maxVertical = getArray (configFile >> "CfgWeapons" >> _optic >> "ACE_ScopeAdjust_Vertical");
if ((count _maxHorizontal < 2) or (count _maxVertical < 2)) exitWith {false};

View File

@ -1,35 +1,42 @@
/*
* Author: KoffeinFlummi
*
* Author: KoffeinFlummi and CAA-Picard
* Adjusts the flight path of the bullet according to the zeroing
*
* Arguments:
* Fired EH
* Argument:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
* 3: Muzzle <STRING>
* 4: Magazine <STRING>
* 5: Ammo <STRING>
* 6: Projectile <OBJECT>
*
* Return Value:
* Return value:
* None
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_weaponType", "_ammoType", "_magazineType", "_round", "_weapons", "_zeroing", "_direction", "_azimuth", "_altitude", "_velocity"];
private ["_unit", "_adjustment", "_weapon", "_projectile", "_weaponIndex", "_zeroing", "_adjustment"];
_unit = _this select 0;
_weaponType = _this select 1;
_ammoType = _this select 4;
_round = _this select 5;
_magazineType = _this select 6;
_weapons = [
primaryWeapon _unit,
secondaryWeapon _unit,
handgunWeapon _unit
];
if !(_weaponType in _weapons) exitWith {};
// Exit if the unit doesn't have any adjusment variable
_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") exitWith {};
_zeroing = GVAR(Adjustment) select (_weapons find _weaponType);
// Exit if the unit isn't a player
if !([_unit] call EFUNC(common,isPlayer)) exitWith {};
// convert zeroing from mils to degrees
_weapon = _this select 1;
_projectile = _this select 5;
_weaponIndex = [_unit, currentWeapon _unit] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {};
_zeroing = _adjustment select _weaponIndex;
// Convert zeroing from mils to degrees
_zeroing = [_zeroing, {_this * 0.05625}] call EFUNC(common,map);
[_round, _zeroing select 0, _zeroing select 1, 0] call EFUNC(common,changeProjectileDirection);
[_projectile, _zeroing select 0, _zeroing select 1, 0] call EFUNC(common,changeProjectileDirection);

View File

@ -1,21 +1,22 @@
/*
* Author: commy2
*
* Gets the optic classnames of all currently equipped weapons.
*
* Arguments:
* 0: Unit (Object)
* 0: Unit <OBJECT>
*
* Return Value:
* [optic of primary, optic of secondary, optic of handgun] (Array)
* 0: Optic of primary <STRING>
* 1: Optic of secondary <STRING>
* 2: Optic of handgun <STRING>
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_array"];
_unit = _this select 0;
EXPLODE_1_PVT(_this,_unit);
private ["_array"];
_array = ["", "", ""];
if !(_unit isKindOf "CAManBase") exitWith {_array};

View File

@ -1,27 +0,0 @@
// by commy2
#include "script_component.hpp"
private ["_state", "_ctrl"];
_state = _this select 0;
disableSerialization;
_ctrl = (uiNamespace getVariable ['ACE_dlgWeaponZeroing', displayNull]) displayCtrl 168;
if (_state) then {
_ctrl ctrlSetPosition [0,0,0,0];
} else {
private "_config";
_config = configFile >> "RscInGameUI" >> "RscWeaponZeroing" >> "CA_Zeroing";
_ctrl ctrlSetPosition [
getNumber (_config >> "x"),
getNumber (_config >> "y"),
getNumber (_config >> "w"),
getNumber (_config >> "h")
];
};
_ctrl ctrlCommit 0;

View File

@ -1,23 +1,42 @@
// by KoffeinFlummi / commy2
/*
* Author: KoffeinFlummi and Commy2
* Check if weapon optics changed and reset zeroing if needed
*
* Arguments:
* 0: Player <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
private "_new";
EXPLODE_1_PVT(_this,_player);
_new = _this call FUNC(getOptics);
private ["_newOptics", "_adjustment"];
_adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
_adjustment = [[0,0], [0,0], [0,0]];
ACE_player setVariable [QGVAR(Adjustment), _adjustment];
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
};
if (isNil QGVAR(Optics)) then {
GVAR(Optics) = ["", "", ""];
};
if (isNil QGVAR(Adjustment)) then {
GVAR(Adjustment) = [[0,0], [0,0], [0,0]];
};
_newOptics = [_player] call FUNC(getOptics);
{
if (_new select _forEachIndex != _x) then {
GVAR(Adjustment) set [_forEachIndex, [0,0]];
if (_newOptics select _forEachIndex != _x) then {
// The optic for this weapon changed, set adjustment to zero
if !((_adjustment select _foreachindex) isEqualTo [0,0]) then {
_adjustment set [_forEachIndex, [0,0]];
[ACE_player, QGVAR(Adjustment), _adjustment, 0.5] call EFUNC(common,setVariablePublic);
};
};
} forEach GVAR(Optics);
GVAR(Optics) = _new;
_adjustment = ACE_player getVariable QGVAR(Adjustment);
GVAR(Optics) = _newOptics;

View File

@ -0,0 +1,59 @@
/*
* Author: KoffeinFlummi and CAA-Picard
* Display the adjustment knobs, update their value and fade them out later
*
* Arguments:
* None
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
disableSerialization;
private ["_weaponIndex","_adjustment","_layer","_display","_zeroing","_vertical","_horizontal"];
_weaponIndex = [ACE_player, currentWeapon ACE_player] call EFUNC(common,getWeaponIndex);
if (_weaponIndex < 0) exitWith {};
_adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
_adjustment = [[0,0], [0,0], [0,0]];
};
// Display the adjustment knobs
_layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
_layer cutRsc [QGVAR(Zeroing), "PLAIN", 0, false];
// Find the display
_display = uiNamespace getVariable [QGVAR(ZeroingDisplay), displayNull];
if (isNull _display) exitWith {};
// Update values
_zeroing = _adjustment select _weaponIndex;
_vertical = _display displayCtrl 12;
_horizontal = _display displayCtrl 13;
_vertical ctrlSetText (str (_zeroing select 1));
_horizontal ctrlSetText (str (_zeroing select 0));
// Set the time when to hide the knobs
GVAR(timeToHide) = diag_tickTime + 3.0;
if !(isNil QGVAR(fadePFH)) exitWith {};
// Launch a PFH to wait and fade out the knobs
GVAR(fadePFH) = [{
if (diag_tickTime >= GVAR(timeToHide)) exitWith {
private "_layer";
_layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer;
_layer cutFadeOut 2;
GVAR(fadePFH) = nil;
[_this select 1] call cba_fnc_removePerFrameHandler;
};
}, 0.1, []] call CBA_fnc_addPerFrameHandler

View File

@ -1 +0,0 @@
#include "\z\ace\addons\scopes\script_component.hpp"

View File

@ -1,20 +0,0 @@
#include "script_component.hpp"
disableSerialization;
_display = _this select 0;
uiNamespace setVariable [QGVAR(ZeroingDisplay, _display];
_vertical = _display displayCtrl 925002;
_horizontal = _display displayCtrl 925003;
_weapons = [
primaryWeapon player,
secondaryWeapon player,
handgunWeapon player
];
if ((currentWeapon ACE_player) in _weapons) then {
_zeroing = GVAR(Adjustment) select (_weapons find (currentWeapon ACE_player));
_horizontal ctrlSetText (str (_zeroing select 0));
_vertical ctrlSetText (str (_zeroing select 1));
};