scopes: Code cleaned up, removed spawns, added standard headers.

This commit is contained in:
Nicolás Badano 2015-02-10 01:22:10 -03:00
parent eadcd82366
commit ff5c5a5bac
13 changed files with 178 additions and 181 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

@ -17,35 +17,3 @@ class Extended_Fired_EventHandlers {
};
};
};
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);};);
};
};
};

View File

@ -9,34 +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];
call FUNC(showZeroing);
// Check inventory when it changes
["playerInventoryChanged", {
[ACE_player] call FUNC(inventoryCheck);
}] call EFUNC(common,addEventhandler);
sleep 3;
_layer cutFadeOut 2;
_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,7 +6,7 @@ PREP(adjustScope);
PREP(canAdjustScope);
PREP(firedEH);
PREP(getOptics);
PREP(hideZeroing);
PREP(getWeaponIndex);
PREP(inventoryCheck);
PREP(showZeroing);

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,45 +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 FUNC(getWeaponIndex);
_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
_adjustment = [[0,0], [0,0], [0,0]];
_unit setVariable [QGVAR(Adjustment), _adjustment];
};
_zeroing = _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];
_adjustment set [_weapons find (currentWeapon _unit), _zeroing];
_unit setVariable [QGVAR(Adjustment), _adjustment];
// Change the adjustment array
_adjustment set [_weaponIndex, _zeroing];
[_unit, QGVAR(Adjustment), 0.5] call EFUNC(common,throttledPublicVariable);
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
@ -47,19 +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)
};
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];
call FUNC(showZeroing);
sleep 3;
_layer cutFadeOut 2;
};
} else {
[] call FUNC(showZeroing);
};
true

View File

@ -1,29 +1,25 @@
/*
* 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
];
if !(currentWeapon _unit in _weapons) exitWith {false};
_weaponIndex = [_unit, currentWeapon _unit] call FUNC(getWeaponIndex);
if (_weaponIndex < 0) exitWith {false};
_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
@ -34,11 +30,11 @@ if (isNil QGVAR(Optics)) then {
GVAR(Optics) = ["", "", ""];
};
_zeroing = _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,39 +1,42 @@
/*
* 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", "_round", "_weapons", "_zeroing", "_adjustment"];
private ["_unit", "_adjustment", "_weapon", "_projectile", "_weaponIndex", "_zeroing", "_adjustment"];
_unit = _this select 0;
// Exit if the unit doesn't have any adjusment variable
_adjustment = _unit getVariable QGVAR(Adjustment);
if (isNil "_adjustment") exitWith {};
// Exit if the unit isn't a player
if !([_unit] call EFUNC(common,isPlayer)) exitWith {};
_weaponType = _this select 1;
_round = _this select 5;
_weapon = _this select 1;
_projectile = _this select 5;
_weapons = [
primaryWeapon _unit,
secondaryWeapon _unit,
handgunWeapon _unit
];
if !(_weaponType in _weapons) exitWith {};
_weaponIndex = [_unit, currentWeapon _unit] call FUNC(getWeaponIndex);
if (_weaponIndex < 0) exitWith {};
_zeroing = _adjustment select (_weapons find _weaponType);
_zeroing = _adjustment select _weaponIndex;
// convert zeroing from mils to degrees
// 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

@ -0,0 +1,23 @@
/*
* 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);
[
primaryWeapon _unit,
secondaryWeapon _unit,
handgunWeapon _unit
] find _weapon

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,26 +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), 0.5] call EFUNC(common,throttledPublicVariable);
};
if (isNil QGVAR(Optics)) then {
GVAR(Optics) = ["", "", ""];
};
_adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
ACE_player setVariable [QGVAR(Adjustment), [[0,0], [0,0], [0,0]]];
[ACE_player, QGVAR(Adjustment), 0.5] call EFUNC(common,throttledPublicVariable);
};
_newOptics = [_player] call FUNC(getOptics);
{
if (_new select _forEachIndex != _x) then {
_adjustment set [_forEachIndex, [0,0]];
[ACE_player, QGVAR(Adjustment), 0.5] call EFUNC(common,throttledPublicVariable);
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), 0.5] call EFUNC(common,throttledPublicVariable);
};
};
} forEach GVAR(Optics);
GVAR(Optics) = _new;
_adjustment = ACE_player getVariable QGVAR(Adjustment);
GVAR(Optics) = _newOptics;

View File

@ -1,26 +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;
_display = uiNamespace getVariable [QGVAR(ZeroingDisplay), displayNull];
if (isNull _display) exitWith {};
private ["_weaponIndex","_adjustment","_layer","_display","_zeroing","_vertical","_horizontal"];
_weapons = [
primaryWeapon ACE_player,
secondaryWeapon ACE_player,
handgunWeapon ACE_player
];
if !((currentWeapon ACE_player) in _weapons) exitWith {};
_weaponIndex = [ACE_player, currentWeapon ACE_player] call FUNC(getWeaponIndex);
if (_weaponIndex < 0) exitWith {};
_adjustment = ACE_player getVariable QGVAR(Adjustment);
if (isNil "_adjustment") then {
_adjustment = [[0,0], [0,0], [0,0]];
};
_zeroing = _adjustment select (_weapons find (currentWeapon ACE_player));
// 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 925002;
_horizontal = _display displayCtrl 925003;
_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