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.
|
2016-05-24 16:58:27 +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>
|
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
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
params ["_vehicle", "_hitPointIndex", "_hitPointDamage"];
|
2015-11-10 02:11:48 +00:00
|
|
|
TRACE_4("params",_vehicle,typeOf _vehicle,_hitPointIndex,_hitPointDamage);
|
2015-09-26 04:36:35 +00:00
|
|
|
|
|
|
|
private["_damageNew", "_damageOld", "_hitPointDamageRepaired", "_hitPointDamageSumOld", "_realHitpointCount", "_selectionName"];
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
// can't execute all commands if the vehicle isn't local. exit here.
|
2015-09-26 04:36:35 +00:00
|
|
|
if !(local _vehicle) exitWith {ACE_LOGERROR_1("Vehicle Not Local %1", _vehicle);};
|
2015-03-10 18:42:21 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
//Check for bad typeName (changed from orignal v3.3 that took string)
|
2015-11-28 03:23:27 +00:00
|
|
|
if (_hitPointIndex isEqualType "") then {
|
2015-09-26 04:36:35 +00:00
|
|
|
ACE_DEPRECATED("repair-setHitPointDamage (hit point name <string>","3.5.0","hit index <number>");
|
|
|
|
_hitPointIndex = _allHitPoints find _hitPointIndex;
|
|
|
|
};
|
2015-03-11 23:59:04 +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
|
2015-09-26 04:36:35 +00:00
|
|
|
if ((_hitPointIndex < 0) || {_hitPointIndex >= (count _allHitPoints)}) exitWith {ACE_LOGERROR_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
|
|
|
|
|
|
|
|
_damageOld = damage _vehicle;
|
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
_realHitpointCount = 0;
|
2015-03-10 18:42:21 +00:00
|
|
|
_hitPointDamageSumOld = 0;
|
2015-09-26 04:36:35 +00:00
|
|
|
_hitPointDamageRepaired = 0; //positive for repairs : newSum = (oldSum - repaired)
|
2015-03-10 18:42:21 +00:00
|
|
|
{
|
2015-09-26 04:36:35 +00:00
|
|
|
_selectionName = _allHitPointsSelections select _forEachIndex;
|
|
|
|
//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
|
|
|
|
|
|
|
if ((((toLower _x) find "glass") == -1) && {!isText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints" >> _x >> "depends")}) 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
|
|
|
|
_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
|
|
|
|
_vehicle setDamage _damageNew;
|
|
|
|
|
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
|
|
|
{
|
2015-09-26 04:36:35 +00:00
|
|
|
_vehicle setHitIndex [_forEachIndex, _x];
|
|
|
|
} forEach _allHitPointDamages;
|
2015-03-11 22:53:08 +00:00
|
|
|
|
|
|
|
// normalize hitpoints
|
2015-11-10 02:11:48 +00:00
|
|
|
[_vehicle] call FUNC(normalizeHitPoints);
|