Merge pull request #2056 from worldwidesorrow/master

Archive unused utility functions
This commit is contained in:
worldwidesorrow
2020-01-21 12:08:00 -06:00
committed by GitHub
23 changed files with 121 additions and 259 deletions

View File

@@ -1,20 +1,13 @@
#include "\z\addons\dayz_code\util\mutex.hpp"
#include "\z\addons\dayz_code\util\player.hpp" #include "\z\addons\dayz_code\util\player.hpp"
#define BANDAID
#define TIMEOUT 2
#define IS_PRIMARY(wpn) (getNumber (configFile >> "CfgWeapons" >> wpn >> "type") == 1) #define IS_PRIMARY(wpn) (getNumber (configFile >> "CfgWeapons" >> wpn >> "type") == 1)
#define MELEE(wpn) getNumber (configFile >> "CfgWeapons" >> wpn >> "melee") #define MELEE(wpn) getNumber (configFile >> "CfgWeapons" >> wpn >> "melee")
#define IS_MELEE(wpn) (MELEE(wpn) == 1) #define IS_MELEE(wpn) (MELEE(wpn) == 1)
//0 if not found, 1 if in primary slot, 2 if on back //0 if not found, 1 if in primary slot, 2 if on back
#define FIND_RIFLE() (0 call dz_fn_switchWeapon_find) #define FIND_RIFLE (0 call dz_fn_switchWeapon_find)
#define FIND_MELEE() (1 call dz_fn_switchWeapon_find) #define FIND_MELEE (1 call dz_fn_switchWeapon_find)
dz_switchWeapon_mutex = Mutex_New();
dz_switchWeapon_time = 0;
dz_switchWeapon_pistolTime = 0; dz_switchWeapon_pistolTime = 0;
//0: switch rifle/melee instantly and update gear //0: switch rifle/melee instantly and update gear
@@ -22,181 +15,117 @@ dz_switchWeapon_pistolTime = 0;
//2: switch to rifle //2: switch to rifle
//3: switch to pistol //3: switch to pistol
//4: switch to melee //4: switch to melee
dz_fn_switchWeapon = dz_fn_switchWeapon = {
{ if Player_IsInVehicle exitWith {};
if (vehicle player != player) exitWith {};
if Player_IsOnLadder() exitWith {}; if Player_IsOnLadder() exitWith {};
if (dayz_autoRun) then {call dayz_autoRunOff;}; if (dayz_autoRun) then {call dayz_autoRunOff;};
if (dayz_isSwimming) exitWith {};
private ["_current","_primary","_secondary","_swapWeapons"]; private ["_current","_secondary","_option"];
_option = _this;
_current = currentWeapon player; _current = currentWeapon player;
switch _this do call {
{ if (_option == 0) exitWith { // Instantly switch primary and carry, also update gear
//Instantly switch primary and carry, also update gear if (IS_PRIMARY(_current)) then {true call dz_fn_switchWeapon_swap;} else {false call dz_fn_switchWeapon_swap;};
case 0:
{
if (IS_PRIMARY(_current)) then
{ true call dz_fn_switchWeapon_swap; }
else
{ false call dz_fn_switchWeapon_swap; };
/*call _swapWeapons;
if (IS_PRIMARY(_current)) then
{ player selectWeapon primaryWeapon player; };*/
[[(findDisplay 106)],"onLBSelChanged"] execVM "\z\addons\dayz_code\system\handleGear.sqf"; [[(findDisplay 106)],"onLBSelChanged"] execVM "\z\addons\dayz_code\system\handleGear.sqf";
}; };
//Switch primary and carry if (_option == 1) exitWith { //Switch primary and carry
case 1: if (dayz_quickSwitch) then {
{
if (dayz_quickSwitch) then
{
true call dz_fn_switchWeapon_swap; true call dz_fn_switchWeapon_swap;
#ifdef BANDAID } else {
call dayz_meleeMagazineCheck; call dz_fn_switchWeapon_swapSecure;
#endif };
}
else
{ call dz_fn_switchWeapon_swapSecure; };
}; };
//Switch to rifle if (_option == 2) exitWith { // Switch to rifle
case 2: if (_current == "") exitWith { // No current weapon
{ switch FIND_RIFLE do {
//No current weapon case 1: { //In primary
if (_current == "") exitWith
{
switch FIND_RIFLE() do
{
//In primary
case 1:
{
player selectWeapon primaryWeapon player; player selectWeapon primaryWeapon player;
}; };
case 2: { //On back
//On back
case 2:
{
true call dz_fn_switchWeapon_swap; true call dz_fn_switchWeapon_swap;
}; };
}; };
}; };
if (IS_PRIMARY(_current)) exitWith { // Current weapon is primary
//Current weapon is primary if (IS_MELEE(_current) && {!IS_MELEE(dayz_onBack)}) then { // if current is melee and on back is rifle
if (IS_PRIMARY(_current)) exitWith if (dayz_quickSwitch) then {
{ true call dz_fn_switchWeapon_swap;
//if current is melee and on back is rifle } else {
if (IS_MELEE(_current) && { !IS_MELEE(dayz_onBack) }) then call dz_fn_switchWeapon_swapSecure;
{
if (dayz_quickSwitch) then
{ true call dz_fn_switchWeapon_swap; }
else
{ call dz_fn_switchWeapon_swapSecure; };
}; };
}; };
};
//Current is pistol // Default: Current is pistol
switch FIND_RIFLE() do switch FIND_RIFLE do {
{ case 1: { //In primary
//In primary if (Player_GetStance() == Player_GetStance_PRONE) then {
case 1: player playMoveNow "AmovPpneMstpSrasWrflDnon";
{ };
if (Player_GetStance() == Player_GetStance_PRONE) then
{ player playMoveNow "AmovPpneMstpSrasWrflDnon"; };
player selectWeapon primaryWeapon player; player selectWeapon primaryWeapon player;
}; };
case 2: { //On back
//On back
case 2:
{
if (diag_tickTime - dz_switchWeapon_pistolTime < 1) exitWith {}; if (diag_tickTime - dz_switchWeapon_pistolTime < 1) exitWith {};
if (Player_GetStance() == Player_GetStance_PRONE) then if (Player_GetStance() == Player_GetStance_PRONE) then {
{ player playMoveNow "AmovPpneMstpSrasWrflDnon"; }; player playMoveNow "AmovPpneMstpSrasWrflDnon";
};
true call dz_fn_switchWeapon_swap; true call dz_fn_switchWeapon_swap;
}; };
}; };
}; };
//Switch to pistol if (_option == 3) exitWith { //Switch to pistol
case 3: if (IS_PRIMARY(_current)) then { //If current weapon is primary
{
//If current weapon is primary
if (IS_PRIMARY(_current)) then
{
_secondary = Player_GetSidearm(); _secondary = Player_GetSidearm();
if (!isNil "_secondary") then if (!isNil "_secondary") then {
{
player selectWeapon _secondary; player selectWeapon _secondary;
dz_switchWeapon_pistolTime = diag_tickTime; dz_switchWeapon_pistolTime = diag_tickTime;
}; };
}; };
}; };
if (_option == 4) exitWith { //Switch to melee or onBack
//Switch to melee if (_current == "") exitWith { //No current weapon
case 4: switch FIND_MELEE do {
{ case 1: { //In primary
//No current weapon
if (_current == "") exitWith
{
switch FIND_MELEE() do
{
//In primary
case 1:
{
player selectWeapon primaryWeapon player; player selectWeapon primaryWeapon player;
}; };
case 2: { //On back
//On back
case 2:
{
true call dz_fn_switchWeapon_swap; true call dz_fn_switchWeapon_swap;
#ifdef BANDAID
call dayz_meleeMagazineCheck;
#endif
}; };
}; };
}; };
if (IS_PRIMARY(_current)) exitWith { //Current weapon is primary
//Current weapon is primary if ((!IS_MELEE(_current) && { IS_MELEE(dayz_onBack) }) or (DZE_TwoPrimaries > 1)) then { //if current is rifle and on back is melee OR two rifles are allowed
if (IS_PRIMARY(_current)) exitWith if (dayz_quickSwitch) then {
{
//if current is rifle and on back is melee OR two rifles are allowed
if ((!IS_MELEE(_current) && { IS_MELEE(dayz_onBack) }) or (DZE_TwoPrimaries > 1)) then
{
if (dayz_quickSwitch) then
{
true call dz_fn_switchWeapon_swap; true call dz_fn_switchWeapon_swap;
#ifdef BANDAID } else {
call dayz_meleeMagazineCheck; call dz_fn_switchWeapon_swapSecure;
#endif
}
else
{ call dz_fn_switchWeapon_swapSecure; };
}; };
}; };
};
//Current is pistol // Default: Current is pistol
//Find melee weapon if (DZE_TwoPrimaries > 1 && {!IS_MELEE(dayz_onBack)}) exitWith { // Allow switching to on back rifle if DZE_TwoPrimaries = 2.
switch FIND_MELEE() do if (dayz_quickSwitch) then {
{ true call dz_fn_switchWeapon_swap;
//In primary } else {
case 1: call dz_fn_switchWeapon_swapSecure;
{ };
};
switch FIND_MELEE do { // Find melee weapon
case 1: { // In primary
player selectWeapon primaryWeapon player; player selectWeapon primaryWeapon player;
if (Player_GetStance() == Player_GetStance_PRONE) then if (Player_GetStance() == Player_GetStance_PRONE) then {
{ player playMoveNow "AmovPpneMstpSrasWrflDnon"; }; player playMoveNow "AmovPpneMstpSrasWrflDnon";
}; };
};
//On back case 2: { // On back
case 2:
{
if (diag_tickTime - dz_switchWeapon_pistolTime < 1) exitWith {}; if (diag_tickTime - dz_switchWeapon_pistolTime < 1) exitWith {};
if (Player_GetStance() == Player_GetStance_PRONE) then if (Player_GetStance() == Player_GetStance_PRONE) then {
{ player playMoveNow "AmovPpneMstpSrasWrflDnon"; }; player playMoveNow "AmovPpneMstpSrasWrflDnon";
};
true call dz_fn_switchWeapon_swap; true call dz_fn_switchWeapon_swap;
}; };
}; };
@@ -204,90 +133,46 @@ dz_fn_switchWeapon =
}; };
}; };
//See FIND_RIFLE() and FIND_MELEE() //See FIND_RIFLE and FIND_MELEE
dz_fn_switchWeapon_find = dz_fn_switchWeapon_find = {
{ private "_primary";
_primary = primaryWeapon player; _primary = primaryWeapon player;
if (_primary != "" && { _this == MELEE(_primary) }) exitWith { 1 };
if (_primary != "" && { _this == MELEE(_primary) }) if (dayz_onBack != "" && { _this == MELEE(dayz_onBack) }) exitWith { 2 };
exitWith { 1 }; 0 // Default
if (dayz_onBack != "" && { _this == MELEE(dayz_onBack) })
exitWith { 2 };
0
}; };
//Swaps rifle / melee instantly without animation //Swaps rifle / melee instantly without animation
dz_fn_switchWeapon_swap = dz_fn_switchWeapon_swap = {
{ if (dayz_onBack == "") then {
if (dayz_onBack == "") then
{
//Must be in a single statement to ensure atomicity in the scheduled environment. //Must be in a single statement to ensure atomicity in the scheduled environment.
dayz_onBack = dayz_onBack = [primaryWeapon player,player removeWeapon primaryWeapon player] select 0;
[ } else {
primaryWeapon player, dayz_onBack = [primaryWeapon player,player removeWeapon primaryWeapon player,player addWeapon dayz_onBack] select 0;
player removeWeapon primaryWeapon player
] select 0;
}
else
{
dayz_onBack =
[
primaryWeapon player,
player removeWeapon primaryWeapon player,
player addWeapon dayz_onBack
] select 0;
}; };
if (_this) then if (_this) then {
{ player selectWeapon primaryWeapon player; }; player selectWeapon primaryWeapon player;
if (IS_MELEE(primaryWeapon player)) then {
call dayz_meleeMagazineCheck;
};
};
}; };
//Swaps rifle / melee forcing an animation //Swaps rifle / melee forcing an animation
dz_fn_switchWeapon_swapSecure = dz_fn_switchWeapon_swapSecure = {
{ private ["_anim","_array","_str"];
if (!Mutex_TryLock_Fast(dz_switchWeapon_mutex)) exitWith {};
//animation states are in the form "AmovPerc...", "AmovPknl...", "AmovPpne..." //animation states are in the form "AmovPerc...", "AmovPknl...", "AmovPpne..."
dz_switchWeapon_anim = format _array = toArray (animationState player);
[ _str = toString [_array select 5,_array select 6,_array select 7];
"AmovP%1MstpSrasWrflDnon_AmovP%1MstpSrasWpstDnon", _anim = format["AmovP%1MstpSrasWrflDnon_AmovP%1MstpSrasWpstDnon",_str];
//Switch on player stance player playMoveNow _anim;
switch Player_GetStance() do
{
case Player_GetStance_STAND: { "erc" };
case Player_GetStance_KNEEL: { "knl" };
case Player_GetStance_PRONE: { "pne" };
}
];
//Add AnimDone event handler to wait until current weapon is put away //Add AnimDone event handler to wait until current weapon is put away
dz_switchWeapon_handler = player addEventHandler ["AnimDone", dz_fn_switchWeapon_animDone]; dz_switchWeapon_handler = player addEventHandler ["AnimDone", {
player playMoveNow dz_switchWeapon_anim;
dz_switchWeapon_time = diag_tickTime;
};
dz_fn_switchWeapon_animDone =
{
//Wait at most TIMEOUT seconds
if (diag_tickTime - dz_switchWeapon_time > TIMEOUT) exitWith
{
player removeEventHandler ["AnimDone", dz_switchWeapon_handler];
Mutex_Unlock(dz_switchWeapon_mutex);
};
//Check if finished animation is the correct one
if ((_this select 1) != dz_switchWeapon_anim) exitWith {};
true call dz_fn_switchWeapon_swap; true call dz_fn_switchWeapon_swap;
//Remove eventhandler
player removeEventHandler ["AnimDone", dz_switchWeapon_handler]; player removeEventHandler ["AnimDone", dz_switchWeapon_handler];
Mutex_Unlock(dz_switchWeapon_mutex); dz_switchWeapon_handler = nil;
}];
#ifdef BANDAID
if (IS_MELEE(primaryWeapon player)) then
{ call dayz_meleeMagazineCheck; };
#endif
}; };

View File

@@ -11,7 +11,7 @@ Author: Foxy
//True if player is on a ladder, otherwise false //True if player is on a ladder, otherwise false
#define Player_IsOnLadder() ((getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1) #define Player_IsOnLadder() ((getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1)
#define Player_IsInVehicle() (player != vehicle player); #define Player_IsInVehicle (player != vehicle player)
//Gets the classname of the player's sidearm. nil if the player has no sidearm. //Gets the classname of the player's sidearm. nil if the player has no sidearm.
#define Player_GetSidearm() ({ if ((getNumber (configFile >> "CfgWeapons" >> _x >> "type")) == 2) exitWith { _x }; nil } foreach weapons player) #define Player_GetSidearm() ({ if ((getNumber (configFile >> "CfgWeapons" >> _x >> "type")) == 2) exitWith { _x }; nil } foreach weapons player)

View File

@@ -1,22 +1,4 @@
#define STRINGIFY(x) #x call compile preprocessFileLineNumbers "\z\addons\dayz_code\util\math.sqf";
#define PATH(sub_path) STRINGIFY(\z\addons\dayz_code\util\sub_path) call compile preprocessFileLineNumbers "\z\addons\dayz_code\util\array.sqf";
#define CCPP call compile preprocessFileLineNumbers call compile preprocessFileLineNumbers "\z\addons\dayz_code\util\vector.sqf";
call compile preprocessFileLineNumbers "\z\addons\dayz_code\util\player.sqf";
//Debug
CCPP PATH(debug.sqf);
//Very generic utilities
CCPP PATH(util.sqf);
CCPP PATH(mutex.sqf);
CCPP PATH(math.sqf);
CCPP PATH(array.sqf);
//Collections
CCPP PATH(stack.sqf);
CCPP PATH(queue.sqf);
CCPP PATH(dictionary.sqf);
//Specialized
CCPP PATH(vector.sqf);
CCPP PATH(task.sqf);
CCPP PATH(request.sqf);

View File

@@ -1,6 +1,3 @@
#define DEBUG_STEP() call { dbg_step = false; waitUntil {dbg_step}; }
#include "Debug.hpp"
#include "Player.hpp" #include "Player.hpp"
#define WeaponSlotPrimary 1 #define WeaponSlotPrimary 1
@@ -15,8 +12,6 @@
#define IS_MAGAZINE(type) (type == WeaponSlotHandGunItem || type == WeaponSlotItem) #define IS_MAGAZINE(type) (type == WeaponSlotHandGunItem || type == WeaponSlotItem)
dz_player_invTypes = [WeaponSlotPrimary, WeaponSlotHandGun, WeaponSlotSecondary, WeaponSlotHandGunItem, WeaponSlotItem, WeaponSlotBinocular, WeaponHardMounted, WeaponSlotInventory]; dz_player_invTypes = [WeaponSlotPrimary, WeaponSlotHandGun, WeaponSlotSecondary, WeaponSlotHandGunItem, WeaponSlotItem, WeaponSlotBinocular, WeaponHardMounted, WeaponSlotInventory];
dz_player_invSlots = [call compile getText (configFile >> "CfgVehicles" >> Player_BASE)] call BIS_FNC_invCodeToArray;
//dz_player_invSlots = [1,1,1,8,12,2,0,12];
dz_fn_player_numItems = dz_fn_player_numItems =
{ {