2024-01-11 20:01:50 +00:00
|
|
|
#include "..\script_component.hpp"
|
2024-01-08 21:22:52 +00:00
|
|
|
/*
|
2024-07-17 06:53:40 +00:00
|
|
|
* Author: Jaynus, NouberNou, Lambda.Tiger,
|
2024-07-19 00:18:52 +00:00
|
|
|
* This function check whether a spall event has occured and generates spall.
|
2024-01-13 06:35:22 +00:00
|
|
|
*
|
2024-01-08 21:22:52 +00:00
|
|
|
* Arguments:
|
2024-07-17 06:53:40 +00:00
|
|
|
* 0: The object a projectile hit <OBJECT>
|
|
|
|
* 1: The config name of the projectile <STRING>
|
|
|
|
* 2: The projectile that should cause spalling <OBJECT>
|
2024-07-19 03:28:56 +00:00
|
|
|
* 3: The position (ASL) the projectile hit the object <ARRAY>
|
2024-07-17 06:53:40 +00:00
|
|
|
* 4: The old velocity of the projectile <ARRAY>
|
2024-07-19 03:28:56 +00:00
|
|
|
* 5: The projectile's shotParents <ARRAY>
|
2024-01-13 06:35:22 +00:00
|
|
|
*
|
2024-01-08 21:22:52 +00:00
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2024-07-19 00:18:52 +00:00
|
|
|
* [[1000, 45, 60], 0.8, getPosASL ace_player] call ace_frag_fnc_doSpall
|
2024-01-08 21:22:52 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2024-07-19 03:28:56 +00:00
|
|
|
#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"];
|
2024-07-17 06:53:40 +00:00
|
|
|
|
2024-07-19 03:28:56 +00:00
|
|
|
TRACE_6("",_objectHit,_roundType,_round,_oldPosASL,_oldVelocity,_shotParents);
|
2024-07-19 00:36:49 +00:00
|
|
|
if ((isNil "_objectHit") || {isNull _objectHit}) exitWith {
|
|
|
|
WARNING_1("Problem with hitPart data - bad object [%1]",_objectHit);
|
|
|
|
};
|
2024-07-17 06:53:40 +00:00
|
|
|
|
|
|
|
private _caliber = getNumber (configFile >> "CfgAmmo" >> _roundType >> "caliber");
|
|
|
|
private _explosive = getNumber (configFile >> "CfgAmmo" >> _roundType >> "explosive");
|
|
|
|
private _idh = getNumber (configFile >> "CfgAmmo" >> _roundType >> "indirectHitRange");
|
|
|
|
|
|
|
|
_roundType call FUNC(getSpallInfo) params ["_caliber", "_explosive"];
|
|
|
|
|
|
|
|
private _exit = false;
|
2024-07-19 03:58:52 +00:00
|
|
|
private _velocityModifier = 1;
|
2024-07-17 06:53:40 +00:00
|
|
|
|
|
|
|
private _curVelocity = velocity _round;
|
|
|
|
private _oldSpeed = vectorMagnitude _oldVelocity;
|
|
|
|
private _curSpeed = vectorMagnitude _curVelocity;
|
|
|
|
|
|
|
|
if (alive _round) then {
|
|
|
|
private _diff = _oldVelocity vectorDiff _curVelocity;
|
|
|
|
private _polar = _diff call CBA_fnc_vect2polar;
|
2024-07-19 00:18:52 +00:00
|
|
|
|
2024-07-17 06:53:40 +00:00
|
|
|
if (abs (_polar select 1) > 45 || {abs (_polar select 2) > 45}) then {
|
|
|
|
if (_caliber < 2.5) then {
|
|
|
|
_exit = true;
|
|
|
|
} else {
|
2024-07-19 03:58:52 +00:00
|
|
|
SUB(_velocityModifier,_curSpeed / _oldSpeed);
|
2024-07-17 06:53:40 +00:00
|
|
|
};
|
|
|
|
};
|
2024-01-08 21:22:52 +00:00
|
|
|
};
|
2024-07-19 03:28:56 +00:00
|
|
|
if (_exit) exitWith {
|
|
|
|
TRACE_1("exit alive",_caliber);
|
|
|
|
};
|
2024-01-08 21:22:52 +00:00
|
|
|
|
2024-07-17 06:53:40 +00:00
|
|
|
private _unitDir = vectorNormalized _oldVelocity;
|
2024-01-09 20:00:43 +00:00
|
|
|
|
2024-07-19 03:28:56 +00:00
|
|
|
if ((isNil "_oldPosASL") || {!(_oldPosASL isEqualTypeArray [0,0,0])}) exitWith {WARNING_1("Problem with hitPart data - bad pos [%1]",_oldPosASL);};
|
2024-07-19 05:12:14 +00:00
|
|
|
private _pos1 = _oldPosASL;
|
2024-07-19 15:47:49 +00:00
|
|
|
private _spallPosAGL = _pos1;
|
|
|
|
private _searchStepSize = _unitDir vectorMultiply 0.05;
|
|
|
|
for "_i" from 0 to 20 do {
|
2024-07-19 05:12:14 +00:00
|
|
|
_spallPosAGL = _pos1 vectorAdd _searchStepSize;
|
2024-07-19 15:47:49 +00:00
|
|
|
if (!lineIntersects [_pos1, _spallPosAGL]) exitWith {};
|
2024-07-19 05:12:14 +00:00
|
|
|
_pos1 = _spallPosAGL;
|
2024-01-15 05:10:15 +00:00
|
|
|
};
|
2024-07-19 05:12:14 +00:00
|
|
|
if (_spallPosAGL isEqualTo _pos1) exitWith {
|
2024-07-19 03:28:56 +00:00
|
|
|
TRACE_1("can't find other side",_oldPosASL);
|
|
|
|
};
|
2024-07-30 03:09:10 +00:00
|
|
|
_spallPosAGL = ASLToAGL _spallPosAGL;
|
2024-07-19 15:47:49 +00:00
|
|
|
|
2024-07-19 03:33:19 +00:00
|
|
|
(_shotParents#1) setVariable [QGVAR(nextSpallEvent), CBA_missionTime + ACE_FRAG_SPALL_UNIT_HOLDOFF];
|
2024-07-19 15:47:49 +00:00
|
|
|
private _oldVelocitySpherical = _oldVelocity call CBA_fnc_vect2polar;
|
2024-01-15 05:10:15 +00:00
|
|
|
|
2024-07-17 06:53:40 +00:00
|
|
|
if (_explosive > 0) then {
|
2024-07-19 15:47:49 +00:00
|
|
|
_roundType call FUNC(getFragInfo) params ["", "_fragVelocity"];
|
|
|
|
_oldVelocitySpherical set [0, _fragVelocity * 0.66];
|
2024-01-09 23:25:09 +00:00
|
|
|
};
|
2024-07-19 15:47:49 +00:00
|
|
|
TRACE_2("spallPosandVel",_spallPosAGL,_oldVelocitySpherical);
|
2024-07-17 02:30:17 +00:00
|
|
|
|
2024-07-18 23:56:00 +00:00
|
|
|
private _spread = 15 + (random 25);
|
|
|
|
private _spallCount = 5 + (random 10);
|
|
|
|
TRACE_1("",_spallCount);
|
|
|
|
for "_i" from 1 to _spallCount do {
|
2024-07-19 15:47:49 +00:00
|
|
|
private _fragmentElevation = ((_oldVelocitySpherical select 2) - _spread) + (random (_spread * 2));
|
|
|
|
private _fragmentAzimuth = ((_oldVelocitySpherical select 1) - _spread) + (random (_spread * 2));
|
2024-07-19 03:58:52 +00:00
|
|
|
if (abs _fragmentElevation > 90) then {
|
|
|
|
ADD(_fragmentAzimuth,180);
|
2024-07-18 23:56:00 +00:00
|
|
|
};
|
2024-07-19 03:58:52 +00:00
|
|
|
_fragmentAzimuth = _fragmentAzimuth % 360;
|
2024-07-19 15:47:49 +00:00
|
|
|
private _fragmentSpeed = (_oldVelocitySpherical select 0) * 0.33 * _velocityModifier;
|
2024-07-19 03:58:52 +00:00
|
|
|
_fragmentSpeed = _fragmentSpeed * (0.75 + random 0.5);
|
2024-07-18 23:56:00 +00:00
|
|
|
|
2024-07-19 03:58:52 +00:00
|
|
|
private _spallFragVect = [_fragmentSpeed, _fragmentAzimuth, _fragmentElevation] call CBA_fnc_polar2vect;
|
2024-07-19 03:28:56 +00:00
|
|
|
private _fragment = createVehicleLocal [selectRandomWeighted WEIGHTED_SIZE, _spallPosAGL, [], 0, "CAN_COLLIDE"];
|
2024-07-18 23:56:00 +00:00
|
|
|
_fragment setVelocity _spallFragVect;
|
2024-07-19 03:28:56 +00:00
|
|
|
_fragment setShotParents _shotParents;
|
2024-07-18 23:56:00 +00:00
|
|
|
|
2024-07-19 00:36:49 +00:00
|
|
|
#ifdef DEBUG_MODE_DRAW
|
2024-07-19 02:10:20 +00:00
|
|
|
[_fragment, "orange", true] call FUNC(dev_trackObj);
|
2024-07-18 23:56:00 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
_spread = 5 + (random 5);
|
|
|
|
_spallCount = 3 + (random 5);
|
|
|
|
for "_i" from 1 to _spallCount do {
|
2024-07-19 15:47:49 +00:00
|
|
|
private _fragmentElevation = ((_oldVelocitySpherical select 2) - _spread) + (random (_spread * 2));
|
|
|
|
private _fragmentAzimuth = ((_oldVelocitySpherical select 1) - _spread) + (random (_spread * 2));
|
2024-07-19 03:58:52 +00:00
|
|
|
if (abs _fragmentElevation > 90) then {
|
|
|
|
ADD(_fragmentAzimuth,180);
|
2024-07-18 23:56:00 +00:00
|
|
|
};
|
2024-07-19 03:58:52 +00:00
|
|
|
_fragmentAzimuth = _fragmentAzimuth % 360;
|
2024-07-19 15:47:49 +00:00
|
|
|
private _fragmentSpeed = (_oldVelocitySpherical select 0) * 0.55 * _velocityModifier;
|
2024-07-19 03:58:52 +00:00
|
|
|
_fragmentSpeed = _fragmentSpeed * (0.75 + random 0.5);
|
2024-07-18 23:56:00 +00:00
|
|
|
|
2024-07-19 03:58:52 +00:00
|
|
|
private _spallFragVect = [_fragmentSpeed, _fragmentAzimuth, _fragmentElevation] call CBA_fnc_polar2vect;
|
2024-07-19 03:28:56 +00:00
|
|
|
private _fragment = createVehicleLocal [selectRandomWeighted WEIGHTED_SIZE, _spallPosAGL, [], 0, "CAN_COLLIDE"];
|
2024-07-18 23:56:00 +00:00
|
|
|
_fragment setVelocity _spallFragVect;
|
2024-07-19 03:28:56 +00:00
|
|
|
_fragment setShotParents _shotParents;
|
2024-07-18 23:56:00 +00:00
|
|
|
|
2024-07-19 00:36:49 +00:00
|
|
|
#ifdef DEBUG_MODE_DRAW
|
2024-07-19 05:01:55 +00:00
|
|
|
[_fragment, "purple", true] call FUNC(dev_trackObj);
|
2024-07-18 23:56:00 +00:00
|
|
|
#endif
|
|
|
|
};
|