mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Implemented a new logic that decides when to use AB.
*Added a new global variable ace_advanced_ballistics_enabled *Added an updateTrajectoryPFH to the winddeflection (WD) module *WD is now automatically disabled when AB is enabled *The new updateTrajectoryPFH is called whenever AB aborts -> Wind deflection is now always present (either through AB or WD) -> AB no longer runs for non local units (unless they use high power optics)
This commit is contained in:
parent
2261225ad3
commit
5ff54f7d1c
@ -1,7 +1,7 @@
|
||||
class Extended_PreInit_EventHandlers {
|
||||
class ADDON {
|
||||
init = QUOTE( call COMPILE_FILE(XEH_preInit) );
|
||||
};
|
||||
class ADDON {
|
||||
init = QUOTE( call COMPILE_FILE(XEH_preInit) );
|
||||
};
|
||||
};
|
||||
|
||||
class Extended_PostInit_EventHandlers {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "initKeybinds.sqf"
|
||||
|
||||
GVAR(AdvancedBallistics) = true;
|
||||
GVAR(enabled) = true;
|
||||
|
||||
GVAR(bulletDatabase) = [];
|
||||
GVAR(bulletDatabaseStartTime) = [];
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "script_component.hpp"
|
||||
#include "defines.h"
|
||||
|
||||
private ["_unit", "_weapon", "_mode", "_ammo", "_magazine", "_caliber", "_bullet", "_index", "_opticsName", "_opticType", "_bulletTraceVisible", "_temperature", "_barometricPressure", "_atmosphereModel", "_bulletMass", "_bulletLength", "_bulletTranslation", "_airFriction", "_dragModel", "_velocityBoundaryData", "_muzzleVelocity", "_muzzleVelocityCoef", "_muzzleVelocityShift", "_bulletVelocity", "_bulletSpeed", "_bulletLength", "_bulletWeight", "_barrelTwist", "_twistDirection", "_stabilityFactor", "_transonicStabilityCoef", "_ACE_Elevation", "_ACE_Windage", "_ID"];
|
||||
private ["_unit", "_weapon", "_mode", "_ammo", "_magazine", "_caliber", "_bullet", "_abort", "_index", "_opticsName", "_opticType", "_bulletTraceVisible", "_temperature", "_barometricPressure", "_atmosphereModel", "_bulletMass", "_bulletLength", "_bulletTranslation", "_airFriction", "_dragModel", "_velocityBoundaryData", "_muzzleVelocity", "_muzzleVelocityCoef", "_muzzleVelocityShift", "_bulletVelocity", "_bulletSpeed", "_bulletLength", "_bulletWeight", "_barrelTwist", "_twistDirection", "_stabilityFactor", "_transonicStabilityCoef", "_ACE_Elevation", "_ACE_Windage", "_ID"];
|
||||
_unit = _this select 0;
|
||||
_weapon = _this select 1;
|
||||
_mode = _this select 3;
|
||||
@ -29,7 +29,9 @@ _magazine = _this select 5;
|
||||
_bullet = _this select 6;
|
||||
|
||||
if (isDedicated) exitWith {};
|
||||
if (!hasInterface) exitWith {};
|
||||
if (!alive _bullet) exitWith {};
|
||||
if (!GVAR(enabled)) exitWith {};
|
||||
if (!([_unit] call EFUNC(common,isPlayer))) exitWith {};
|
||||
if (underwater _unit) exitWith {};
|
||||
if (!(_ammo isKindOf "BulletBase")) exitWith {};
|
||||
@ -38,6 +40,20 @@ if (GVAR(ONLY_ACTIVE_FOR_LOCAL_PLAYER) && _unit != ACE_player) exitWith {};
|
||||
if (!GVAR(VehicleGunnerEnabled) && !(_unit isKindOf "Man")) exitWith {};
|
||||
if (GVAR(DISABLED_IN_FULL_AUTO_MODE) && getNumber(configFile >> "cfgWeapons" >> _weapon >> _mode >> "autoFire") == 1) exitWith {};
|
||||
|
||||
// Decide whether normal winddeflection is good enough
|
||||
_abort = !(local _unit);
|
||||
if (_abort) then {
|
||||
// The shooter is non local
|
||||
if (currentWeapon _unit == primaryWeapon _unit && count primaryWeaponItems _unit > 2) then {
|
||||
_opticsName = (primaryWeaponItems _unit) select 2;
|
||||
_opticType = getNumber(configFile >> "cfgWeapons" >> _opticsName >> "ItemInfo" >> "opticType");
|
||||
_abort = _opticType != 2; // We only abort if the non local shooter is not a sniper
|
||||
};
|
||||
};
|
||||
if (_abort) exitWith {
|
||||
[_bullet, getNumber(configFile >> "cfgAmmo" >> _ammo >> "airFriction")] call EFUNC(winddeflection,updateTrajectoryPFH);
|
||||
};
|
||||
|
||||
_airFriction = getNumber(configFile >> "cfgAmmo" >> _ammo >> "airFriction");
|
||||
_muzzleVelocity = getNumber(configFile >> "cfgMagazines" >> _magazine >> "initSpeed");
|
||||
_muzzleVelocityCoef = getNumber(configFile >> "cfgWeapons" >> _weapon >> "initSpeed");
|
||||
|
@ -10,5 +10,10 @@
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
ADDON = false;
|
||||
|
||||
PREP(handleFired);
|
||||
PREP(initalizeModule);
|
||||
PREP(updateTrajectoryPFH);
|
||||
|
||||
ADDON = true;
|
||||
|
@ -21,49 +21,18 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_unit", "_weapon", "_ammo", "_bullet", "_airFriction", "_index"];
|
||||
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) exitWith {false};
|
||||
|
||||
private ["_unit", "_bullet"];
|
||||
_unit = _this select 0;
|
||||
|
||||
if (EGVAR(advanced_ballistics,AdvancedBallistics)) exitWith {false};
|
||||
|
||||
if (_unit distance ACE_player > 3000) exitWith {false}; // Large enough distance to not simulate any wind deflection.
|
||||
if (!GVAR(EnableForAI) && !([_unit] call EFUNC(common,isPlayer))) exitWith {false};
|
||||
_bullet = _this select 6;
|
||||
|
||||
if (_bullet isKindOf "BulletBase") then {
|
||||
[{
|
||||
private ["_bullet", "_airFriction", "_args", "_deltaT", "_bulletVelocity", "_bulletSpeed", "_trueVelocity", "_trueVelocity", "_dragRef", "_drag", "_accelRef", "_accel"];
|
||||
if (isDedicated) exitWith {false};
|
||||
if (!hasInterface) exitWith {false};
|
||||
if (!(_bullet isKindOf "BulletBase")) exitWith {false};
|
||||
if (_unit distanceSqr ACE_player > 9000000) exitWith {false};
|
||||
if (!GVAR(EnableForAI) && !([_unit] call EFUNC(common,isPlayer))) exitWith {false}; // TODO: Remove this?
|
||||
|
||||
_args = _this select 0;
|
||||
_bullet = _args select 0;
|
||||
_airFriction = _args select 1;
|
||||
_time = _args select 2;
|
||||
[_bullet, getNumber(configFile >> "cfgAmmo" >> (_this select 4) >> "airFriction")] call FUNC(updateTrajectoryPFH);
|
||||
|
||||
if (!alive _bullet) exitwith {
|
||||
[_this select 1] call cba_fnc_removePerFrameHandler;
|
||||
};
|
||||
|
||||
_deltaT = time - _time;
|
||||
_args set[2, time];
|
||||
|
||||
_bulletVelocity = velocity _bullet;
|
||||
_bulletSpeed = vectorMagnitude _bulletVelocity;
|
||||
|
||||
if (vectorMagnitude ACE_wind > 0) then {
|
||||
_trueVelocity = _bulletVelocity vectorDiff ACE_wind;
|
||||
_trueSpeed = vectorMagnitude _trueVelocity;
|
||||
|
||||
_dragRef = _deltaT * _airFriction * _bulletSpeed * _bulletSpeed;
|
||||
_accelRef = (vectorNormalized _bulletVelocity) vectorMultiply (_dragRef);
|
||||
_bulletVelocity = _bulletVelocity vectorDiff _accelRef;
|
||||
|
||||
_drag = _deltaT * _airFriction * _trueSpeed;
|
||||
_accel = _trueVelocity vectorMultiply (_drag);
|
||||
_bulletVelocity = _bulletVelocity vectorAdd _accel;
|
||||
};
|
||||
_bullet setVelocity _bulletVelocity;
|
||||
// TODO expand with advanced ballistics functionality.
|
||||
|
||||
}, 0, [_bullet, getNumber(configFile >> "cfgAmmo" >> (_this select 4) >> "airFriction"), time]] call CBA_fnc_addPerFrameHandler;
|
||||
};
|
||||
true;
|
50
addons/winddeflection/functions/fnc_updateTrajectoryPFH.sqf
Normal file
50
addons/winddeflection/functions/fnc_updateTrajectoryPFH.sqf
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Author: Glowbal, Ruthberg
|
||||
* Handles wind deflection for projectiles.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: bullet - Object the event handler is assigned to <OBJECT>
|
||||
* 1: airFriction - air friction of the bullet <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
[{
|
||||
private ["_bullet", "_airFriction", "_args", "_deltaT", "_bulletVelocity", "_bulletSpeed", "_trueVelocity", "_trueVelocity", "_dragRef", "_drag", "_accelRef", "_accel"];
|
||||
|
||||
_args = _this select 0;
|
||||
_bullet = _args select 0;
|
||||
_airFriction = _args select 1;
|
||||
_time = _args select 2;
|
||||
|
||||
if (!alive _bullet) exitwith {
|
||||
[_this select 1] call cba_fnc_removePerFrameHandler;
|
||||
};
|
||||
|
||||
_deltaT = time - _time;
|
||||
_args set[2, time];
|
||||
|
||||
_bulletVelocity = velocity _bullet;
|
||||
_bulletSpeed = vectorMagnitude _bulletVelocity;
|
||||
|
||||
if (vectorMagnitude ACE_wind > 0) then {
|
||||
_trueVelocity = _bulletVelocity vectorDiff ACE_wind;
|
||||
_trueSpeed = vectorMagnitude _trueVelocity;
|
||||
|
||||
_dragRef = _deltaT * _airFriction * _bulletSpeed * _bulletSpeed;
|
||||
_accelRef = (vectorNormalized _bulletVelocity) vectorMultiply (_dragRef);
|
||||
_bulletVelocity = _bulletVelocity vectorDiff _accelRef;
|
||||
|
||||
_drag = _deltaT * _airFriction * _trueSpeed;
|
||||
_accel = _trueVelocity vectorMultiply (_drag);
|
||||
_bulletVelocity = _bulletVelocity vectorAdd _accel;
|
||||
};
|
||||
_bullet setVelocity _bulletVelocity;
|
||||
|
||||
}, 0, [_this select 0, _this select 1, time]] call CBA_fnc_addPerFrameHandler;
|
Loading…
Reference in New Issue
Block a user