mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
fixed timing and other spall issues
This commit is contained in:
parent
48e299663b
commit
1480715111
@ -7,8 +7,9 @@
|
||||
* 0: The object a projectile hit <OBJECT>
|
||||
* 1: The config name of the projectile <STRING>
|
||||
* 2: The projectile that should cause spalling <OBJECT>
|
||||
* 3: The position the projectile hit the object <ARRAY>
|
||||
* 3: The position (ASL) the projectile hit the object <ARRAY>
|
||||
* 4: The old velocity of the projectile <ARRAY>
|
||||
* 5: The projectile's shotParents <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
@ -18,9 +19,10 @@
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
params ["_objectHit", "_roundType", "_round", "_oldPos", "_oldVelocity"];
|
||||
#define WEIGHTED_SIZE [QGVAR(spall_small), 4, QGVAR(spall_medium), 3, QGVAR(spall_large), 2, QGVAR(spall_huge), 1]
|
||||
params ["_objectHit", "_roundType", "_round", "_oldPosASL", "_oldVelocity", "_shotParents"];
|
||||
|
||||
TRACE_1("",_objectHit);
|
||||
TRACE_6("",_objectHit,_roundType,_round,_oldPosASL,_oldVelocity,_shotParents);
|
||||
if ((isNil "_objectHit") || {isNull _objectHit}) exitWith {
|
||||
WARNING_1("Problem with hitPart data - bad object [%1]",_objectHit);
|
||||
};
|
||||
@ -50,45 +52,50 @@ if (alive _round) then {
|
||||
};
|
||||
};
|
||||
};
|
||||
if (_exit) exitWith {};
|
||||
if (_exit) exitWith {
|
||||
TRACE_1("exit alive",_caliber);
|
||||
};
|
||||
|
||||
private _unitDir = vectorNormalized _oldVelocity;
|
||||
|
||||
private _spallPos = [];
|
||||
if ((isNil "_oldPos") || {!(_oldPos isEqualTypeArray [0,0,0])}) exitWith {WARNING_1("Problem with hitPart data - bad pos [%1]",_oldPos);};
|
||||
private _spallPosAGL = [];
|
||||
if ((isNil "_oldPosASL") || {!(_oldPosASL isEqualTypeArray [0,0,0])}) exitWith {WARNING_1("Problem with hitPart data - bad pos [%1]",_oldPosASL);};
|
||||
for "_i" from 0 to 100 do {
|
||||
private _pos1 = _oldPos vectorAdd (_unitDir vectorMultiply (0.01 * _i));
|
||||
private _pos2 = _oldPos vectorAdd (_unitDir vectorMultiply (0.01 * (_i + 1)));
|
||||
private _pos1 = _oldPosASL vectorAdd (_unitDir vectorMultiply (0.01 * _i));
|
||||
private _pos2 = _oldPosASL vectorAdd (_unitDir vectorMultiply (0.01 * (_i + 1)));
|
||||
|
||||
if (!lineIntersects [_pos1, _pos2]) exitWith {
|
||||
_spallPos = _pos2;
|
||||
_spallPosAGL = ASLtoAGL _pos2;
|
||||
};
|
||||
};
|
||||
if (_spallPos isEqualTo []) exitWith {};
|
||||
private _spallPolar = _oldVelocity call CBA_fnc_vect2polar;
|
||||
if (_spallPosAGL isEqualTo []) exitWith {
|
||||
TRACE_1("can't find other side",_oldPosASL);
|
||||
};
|
||||
(_shotParents#1) setVariable [QGVAR(nextSpallEvent), CBA_missionTime + ACE_FRAG_SPALL_EVENT_HOLDOFF];
|
||||
private _spallVelocitySpherical = _oldVelocity call CBA_fnc_vect2polar;
|
||||
|
||||
if (_explosive > 0) then {
|
||||
_shellType call FUNC(getFragInfo) params ["", "_fragVelocity"];
|
||||
_spallPolar set [0, _fragVelocity * 0.66];
|
||||
_spallVelocitySpherical set [0, _fragVelocity * 0.66];
|
||||
};
|
||||
|
||||
private _spread = 15 + (random 25);
|
||||
private _spallCount = 5 + (random 10);
|
||||
TRACE_1("",_spallCount);
|
||||
for "_i" from 1 to _spallCount do {
|
||||
private _elev = ((_spallVelocity select 2) - _spread) + (random (_spread * 2));
|
||||
private _dir = ((_spallVelocity select 1) - _spread) + (random (_spread * 2));
|
||||
private _elev = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2));
|
||||
private _dir = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2));
|
||||
if (abs _elev > 90) then {
|
||||
ADD(_dir,180);
|
||||
};
|
||||
_dir = _dir % 360;
|
||||
private _vel = (_spallVelocity select 0) * 0.33 * _vm;
|
||||
private _vel = (_spallVelocitySpherical select 0) * 0.33 * _vm;
|
||||
_vel = (_vel - (_vel * 0.25)) + (random (_vel * 0.5));
|
||||
|
||||
private _spallFragVect = [_vel, _dir, _elev] call CBA_fnc_polar2vect;
|
||||
private _fragment = (selectRandomWeighted WEIGHTED_SIZE) createVehicle [0, 0, 10000];
|
||||
_fragment setPosASL _spallPos;
|
||||
private _fragment = createVehicleLocal [selectRandomWeighted WEIGHTED_SIZE, _spallPosAGL, [], 0, "CAN_COLLIDE"];
|
||||
_fragment setVelocity _spallFragVect;
|
||||
_fragment setShotParents _shotParents;
|
||||
|
||||
#ifdef DEBUG_MODE_DRAW
|
||||
[_fragment, "orange", true] call FUNC(dev_trackObj);
|
||||
@ -98,19 +105,19 @@ for "_i" from 1 to _spallCount do {
|
||||
_spread = 5 + (random 5);
|
||||
_spallCount = 3 + (random 5);
|
||||
for "_i" from 1 to _spallCount do {
|
||||
private _elev = ((_spallVelocity select 2) - _spread) + (random (_spread * 2));
|
||||
private _dir = ((_spallVelocity select 1) - _spread) + (random (_spread * 2));
|
||||
private _elev = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2));
|
||||
private _dir = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2));
|
||||
if (abs _elev > 90) then {
|
||||
ADD(_dir,180);
|
||||
};
|
||||
_dir = _dir % 360;
|
||||
private _vel = (_spallVelocity select 0) * 0.55 * _vm;
|
||||
private _vel = (_spallVelocitySpherical select 0) * 0.55 * _vm;
|
||||
_vel = (_vel - (_vel * 0.25)) + (random (_vel * 0.5));
|
||||
|
||||
private _spallFragVect = [_vel, _dir, _elev] call CBA_fnc_polar2vect;
|
||||
private _fragment = (selectRandomWeighted WEIGHTED_SIZE) createVehicle [0, 0, 10000];
|
||||
_fragment setPosASL _spallPos;
|
||||
private _fragment = createVehicleLocal [selectRandomWeighted WEIGHTED_SIZE, _spallPosAGL, [], 0, "CAN_COLLIDE"];
|
||||
_fragment setVelocity _spallFragVect;
|
||||
_fragment setShotParents _shotParents;
|
||||
|
||||
#ifdef DEBUG_MODE_DRAW
|
||||
[_fragment, "orange", true] call FUNC(dev_trackObj);
|
||||
|
@ -31,21 +31,22 @@ if (GVAR(spallEnabled) && {_ammo call FUNC(shouldSpall)}) then {
|
||||
|
||||
// starting v2.18 it may be faster to use the instigator parameter, the same as the second entry shotParents, to recreate _shotParent
|
||||
// The "explode" EH does not get the same parameter
|
||||
private _shotParent = getShotParents _projectile;
|
||||
private _shotParents = getShotParents _projectile;
|
||||
private _ammo = typeOf _projectile;
|
||||
private _vectorUp = vectorUp _projectile;
|
||||
|
||||
// only let a unit make a frag event once per second
|
||||
private _instigator = _shotParents#1;
|
||||
if (CBA_missionTime < (_instigator getVariable [QGVAR(nextSpallEvent), -1])) exitWith {};
|
||||
_instigator setVariable [QGVAR(nextSpallEvent), CBA_missionTime + ACE_FRAG_SPALL_EVENT_HOLDOFF];
|
||||
|
||||
/*
|
||||
* Wait a frame to see what happens to the round, may result in
|
||||
* multiple hits / slowdowns getting shunted to the first hit
|
||||
*/
|
||||
[
|
||||
FUNC(doSpallLocal),
|
||||
[_projectile, _hitObject, _posASL, _velocity, _surfNorm, _surfType, _ammo, _shotParent, _vectorUp]
|
||||
// only let a unit make a frag event once per ACE_FRAG_SPALL_EVENT_HOLDOFF
|
||||
{
|
||||
private _shotParents = _this#5;
|
||||
if (CBA_missionTime < _shotParents#1 getVariable [QGVAR(nextSpallEvent), -1]) exitWith {};
|
||||
_this call FUNC(doSpall);
|
||||
},
|
||||
[_hitObject, _ammo, _projectile, _posASL, _velocity, _shotParents]
|
||||
] call CBA_fnc_execNextFrame;
|
||||
}
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user