2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-03-10 18:42:21 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
2015-08-16 18:14:54 +00:00
|
|
|
* Set the hitpoint damage and change the structural damage acordingly, requires local vehicle.
|
2017-08-10 11:32:55 +00:00
|
|
|
* Handles the ace_repair_setVehicleHitPointDamage event.
|
2015-03-10 18:42:21 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-16 18:14:54 +00:00
|
|
|
* 0: Local Vehicle to Damage <OBJECT>
|
2015-09-26 04:36:35 +00:00
|
|
|
* 1: Selected hitpoint INDEX <NUMBER>
|
2015-08-16 18:14:54 +00:00
|
|
|
* 2: Total Damage <NUMBER>
|
2017-08-22 17:56:14 +00:00
|
|
|
* 3: Skip destruction effects <BOOL>
|
2015-03-10 18:42:21 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-16 18:14:54 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2015-09-26 04:36:35 +00:00
|
|
|
* [vehicle, 1, 0.5] call ace_repair_fnc_setHitPointDamage
|
2015-08-16 18:14:54 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
2015-03-10 18:42:21 +00:00
|
|
|
*/
|
|
|
|
|
2017-08-22 17:56:14 +00:00
|
|
|
params ["_vehicle", "_hitPointIndex", "_hitPointDamage", ["_useEffects", true]];
|
2015-11-10 02:11:48 +00:00
|
|
|
TRACE_4("params",_vehicle,typeOf _vehicle,_hitPointIndex,_hitPointDamage);
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2015-03-10 18:42:21 +00:00
|
|
|
// can't execute all commands if the vehicle isn't local. exit here.
|
2016-10-02 10:55:31 +00:00
|
|
|
if !(local _vehicle) exitWith {ERROR_1("Vehicle Not Local %1", _vehicle);};
|
2015-03-10 18:42:21 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
// get all hitpoints and selections and damages
|
|
|
|
(getAllHitPointsDamage _vehicle) params [["_allHitPoints", []], ["_allHitPointsSelections", []], ["_allHitPointDamages", []]];
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
// exit if the hitpoint is not valid
|
2016-10-02 10:55:31 +00:00
|
|
|
if ((_hitPointIndex < 0) || {_hitPointIndex >= (count _allHitPoints)}) exitWith {ERROR_2("NOT A VALID HITPOINT: %1-%2", _hitPointIndex,_vehicle);};
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
// save structural damage and sum of hitpoint damages
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _damageOld = damage _vehicle;
|
2015-03-10 18:42:21 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _realHitpointCount = 0;
|
|
|
|
private _hitPointDamageSumOld = 0;
|
|
|
|
private _hitPointDamageRepaired = 0; //positive for repairs : newSum = (oldSum - repaired)
|
2015-03-10 18:42:21 +00:00
|
|
|
{
|
2017-10-10 14:39:59 +00:00
|
|
|
private _selectionName = _allHitPointsSelections select _forEachIndex;
|
2015-09-26 04:36:35 +00:00
|
|
|
//Filter out all the bad hitpoints (HitPoint="" or no selection)
|
|
|
|
if ((!isNil {_vehicle getHit _selectionName}) && {_x != ""}) then {
|
|
|
|
_realHitpointCount = _realHitpointCount + 1;
|
2015-11-10 02:11:48 +00:00
|
|
|
|
2021-02-18 18:58:08 +00:00
|
|
|
if ((((toLower _x) find "glass") == -1) && {(getText (configOf _vehicle >> "HitPoints" >> _x >> "depends")) in ["", "0"]}) then {
|
2015-09-26 04:36:35 +00:00
|
|
|
_hitPointDamageSumOld = _hitPointDamageSumOld + (_allHitPointDamages select _forEachIndex);
|
|
|
|
if (_forEachIndex == _hitPointIndex) then {
|
|
|
|
_hitPointDamageRepaired = (_allHitPointDamages select _forEachIndex) - _hitPointDamage;
|
|
|
|
};
|
|
|
|
};
|
2015-03-11 23:59:04 +00:00
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
} forEach _allHitPoints;
|
2015-03-10 18:42:21 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
// calculate new structural damage
|
2017-10-10 14:39:59 +00:00
|
|
|
private _damageNew = (_hitPointDamageSumOld - _hitPointDamageRepaired) / _realHitpointCount;
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
if (_hitPointDamageSumOld > 0) then {
|
2015-09-26 04:36:35 +00:00
|
|
|
_damageNew = _damageOld * ((_hitPointDamageSumOld - _hitPointDamageRepaired) / _hitPointDamageSumOld);
|
2015-03-10 18:42:21 +00:00
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
TRACE_5("structuralDamage",_damageOld,_damageNew,_hitPointDamageRepaired,_hitPointDamageSumOld,_realHitpointCount);
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
// set new structural damage value
|
2019-05-03 15:09:16 +00:00
|
|
|
private _damageDisabled = !isDamageAllowed _vehicle;
|
|
|
|
if (_damageDisabled) then {
|
2019-05-03 15:03:17 +00:00
|
|
|
_vehicle allowDamage true;
|
|
|
|
};
|
|
|
|
|
2017-08-22 17:56:14 +00:00
|
|
|
_vehicle setDamage [_damageNew, _useEffects];
|
2015-03-10 18:42:21 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
//Repair the hitpoint in the damages array:
|
|
|
|
_allHitPointDamages set [_hitPointIndex, _hitPointDamage];
|
2015-03-10 18:42:21 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
//Set the new damage for all hitpoints
|
2015-03-10 18:42:21 +00:00
|
|
|
{
|
2017-08-22 17:56:14 +00:00
|
|
|
_vehicle setHitIndex [_forEachIndex, _x, _useEffects];
|
2015-09-26 04:36:35 +00:00
|
|
|
} forEach _allHitPointDamages;
|
2015-03-11 22:53:08 +00:00
|
|
|
|
|
|
|
// normalize hitpoints
|
2015-11-10 02:11:48 +00:00
|
|
|
[_vehicle] call FUNC(normalizeHitPoints);
|
2019-05-03 15:03:17 +00:00
|
|
|
|
2019-05-03 15:09:16 +00:00
|
|
|
if (_damageDisabled) then {
|
2019-05-03 15:03:17 +00:00
|
|
|
_vehicle allowDamage false;
|
|
|
|
};
|