Initial commit
This commit is contained in:
101
functions/ambience/fn_flakEH.sqf
Normal file
101
functions/ambience/fn_flakEH.sqf
Normal file
@@ -0,0 +1,101 @@
|
||||
params [
|
||||
["_event", [], []],
|
||||
["_maximumDistance", 2000, [0]],
|
||||
["_minimumAltitude", 0, [0]],
|
||||
["_primaryTurret", 0, [0]],
|
||||
["_fullAmmoCount", 2000, [0]],
|
||||
["_flakRoundsEvery", 2, [0]],
|
||||
["_speedDispersion", 20, [0]],
|
||||
["_distanceDispersion", 30, [0]]
|
||||
];
|
||||
|
||||
// diag_log("flakEH running");
|
||||
// diag_log(_event);
|
||||
|
||||
_unit = _event select 0;
|
||||
// diag_log(format["i have a unit: %1", _unit]);
|
||||
|
||||
_projectile = _event select 6;
|
||||
// diag_log(format["i have a projectile in flight: %1", _projectile]);
|
||||
|
||||
deleteVehicle _projectile;
|
||||
// diag_log("i have deleted the projectile");
|
||||
|
||||
// diag_log(_unit weaponsTurret [0] select _primaryTurret);
|
||||
|
||||
_weapon = _unit weaponsTurret [0] select _primaryTurret;
|
||||
|
||||
_munitionConversionRate = _fullAmmoCount - _flakRoundsEvery;
|
||||
|
||||
// diag_log(format["munition count: %1", _unit ammo _weapon]);
|
||||
// diag_log(format["munition replacement at: %1", _munitionConversionRate]);
|
||||
|
||||
if (_unit ammo _weapon < _munitionConversionRate) then {
|
||||
_unit setAmmo [_weapon, _fullAmmoCount];
|
||||
// diag_log(format["replacing ammo count to: %1", _fullAmmoCount]);
|
||||
|
||||
_targetPosition = [];
|
||||
|
||||
_target = 0;
|
||||
|
||||
if (isPlayer (assignedGunner _unit)) then {
|
||||
|
||||
_target = cursorTarget;
|
||||
|
||||
if (_unit distance _target < _maximumDistance) then {
|
||||
_targetPosition = getPos _target;
|
||||
};
|
||||
|
||||
} else {
|
||||
_possibleTargets = _unit nearTargets _maximumDistance;
|
||||
diag_log(format["ai has %1 possible targetting solutions", count _possibleTargets]);
|
||||
|
||||
if ((count _possibleTargets) > 0) then {
|
||||
|
||||
_i = 0;
|
||||
_hold = 0;
|
||||
|
||||
{
|
||||
_i = _unit aimedAtTarget [_x select 4, _weapon];
|
||||
if (_i > _hold && (_x select 3) > 0) then {
|
||||
_target = _x select 4;
|
||||
diag_log(format["setting target to %1", _target]);
|
||||
_targetPosition = _x select 0;
|
||||
_hold = _i;
|
||||
};
|
||||
} forEach _possibleTargets;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// diag_log(format["i have found target coordinates: %1", _targetPosition]);
|
||||
|
||||
if ((count _targetPosition) > 0) then {
|
||||
// diag_log("calculating new projectile placement");
|
||||
|
||||
_targetX = _targetPosition select 0;
|
||||
_targetY = _targetPosition select 1;
|
||||
_targetZ = _targetPosition select 2;
|
||||
|
||||
// diag_log(format["checking target altitude: %1", _targetZ]);
|
||||
|
||||
if (_targetZ > _minimumAltitude) then {
|
||||
// diag_log("target is above minimum height, proceeding");
|
||||
|
||||
if !(lineIntersects [getPos _unit, _targetPosition, _unit, _target]) then {
|
||||
|
||||
// diag_log("intersection calculated");
|
||||
|
||||
_flakDistance = ((speed _target * 0.8) * (_speedDispersion / 100)) + ((_unit distance _target) * (_distanceDispersion / 500));
|
||||
|
||||
_distanceX = ((random (_flakDistance * 2)) - _flakDistance) + _targetX;
|
||||
_distanceY = ((random (_flakDistance * 2)) - _flakDistance) + _targetY;
|
||||
_distanceZ = ((random (_flakDistance * 2)) - _flakDistance) + _targetZ;
|
||||
// diag_log( format["target is distance: %1 / distance2D %2 from me, creating munition distance %3, distance2D %4 from me", _unit distance _targetPosition, _unit distance2D _targetPosition, _unit distance [_distanceX, _distanceY, _distanceZ], _unit distance2D [_distanceX, _distanceY, _distanceZ]]);
|
||||
_flak = createVehicle ["SmallSecondary", [_distanceX, _distanceY, _distanceZ], [], 0, "CAN_COLLIDE"];
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
83
functions/ambience/fn_flakInitVehicle.sqf
Normal file
83
functions/ambience/fn_flakInitVehicle.sqf
Normal file
@@ -0,0 +1,83 @@
|
||||
params [
|
||||
["_unit", objNull, [objNull]],
|
||||
["_maximumDistance", 2000, [0]],
|
||||
["_minimumAltitude", 0, [0]],
|
||||
["_flakRoundsEvery", 2, [0]],
|
||||
["_speedDispersion", 20, [0]],
|
||||
["_distanceDispersion", 30, [0]],
|
||||
["_removeMissiles", true, [true]]
|
||||
];
|
||||
|
||||
diag_log("initializing flak v16");
|
||||
|
||||
_primaryTurret = objNull;
|
||||
|
||||
if (_removeMissiles) then {
|
||||
|
||||
diag_log("removing missiles");
|
||||
|
||||
_magazines = magazinesAllTurrets _unit;
|
||||
|
||||
{
|
||||
_magazine = _x select 0;
|
||||
diag_log( format["Checking: %1", _magazine]);
|
||||
|
||||
_ammo = gettext( configfile >> "CfgMagazines" >> _magazine >> "ammo");
|
||||
diag_log( format["ammo: %1", _ammo]);
|
||||
|
||||
_type = gettext(configFile >> "CfgAmmo" >> _ammo >> "simulation");
|
||||
diag_log( format["ammo type: %1", _type]);
|
||||
|
||||
if (_type == "shotMissile") then {
|
||||
_unit removeMagazinesTurret [_magazine, [0]];
|
||||
diag_log(format["removing ammo: %1", _ammo]);
|
||||
};
|
||||
|
||||
if ((_type == "shotBullet") && (_primaryTurret isEqualTo objNull)) then {
|
||||
_primaryTurret = _forEachIndex;
|
||||
diag_log(format["found primary turret: %1", _unit weaponsTurret [0] select _primaryTurret]);
|
||||
};
|
||||
|
||||
} foreach _magazines;
|
||||
|
||||
};
|
||||
|
||||
_weapon = _unit weaponsTurret [0] select _primaryTurret;
|
||||
|
||||
_fullAmmoCount = _unit ammo _weapon;
|
||||
|
||||
|
||||
_unit setVariable["feh_maximumDistance", _maximumDistance];
|
||||
_unit setVariable["feh_minimumAltitude", _minimumAltitude];
|
||||
_unit setVariable["feh_primaryTurret", _primaryTurret];
|
||||
_unit setVariable["feh_fullAmmoCount", _fullAmmoCount];
|
||||
_unit setVariable["feh_flakRoundsEvery", _flakRoundsEvery];
|
||||
_unit setVariable["feh_speedDispersion", _speedDispersion];
|
||||
_unit setVariable["feh_distanceDispersion", _distanceDispersion];
|
||||
|
||||
diag_log( format[
|
||||
"{[_this, maximumDistance: %1, minimumAltitude: %2, primaryTurret: %3, fullAmmoCount: %4, flakRoundsEvery: %5, speedDispersion: %6, distanceDispersion: %7] call milsim_fnc_flakEH;}",
|
||||
_maximumDistance,
|
||||
_minimumAltitude,
|
||||
_primaryTurret,
|
||||
_fullAmmoCount,
|
||||
_flakRoundsEvery,
|
||||
_speedDispersion,
|
||||
_distanceDispersion
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
_unit addEventHandler [
|
||||
"Fired",
|
||||
format[
|
||||
"diag_log('firing'); [_this, %1, %2, %3, %4, %5, %6, %7] call milsim_fnc_flakEH",
|
||||
_maximumDistance,
|
||||
_minimumAltitude,
|
||||
_primaryTurret,
|
||||
_fullAmmoCount,
|
||||
_flakRoundsEvery,
|
||||
_speedDispersion,
|
||||
_distanceDispersion
|
||||
]
|
||||
];
|
||||
Reference in New Issue
Block a user