2015-03-10 18:42:21 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
* Set the hitpoint damage and change the structural damage acordingly. Requires local vehicle.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: vehicle
|
|
|
|
* 1: hitpoint
|
|
|
|
* 2: damage
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* NONE
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-09 06:54:44 +00:00
|
|
|
params ["_vehicle", "_hitPoint", "_hitPointDamage"];
|
|
|
|
TRACE_3("params",_vehicle,_hitPoint,_hitPointDamage);
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
// can't execute all commands if the vehicle isn't local. exit here.
|
|
|
|
if !(local _vehicle) exitWith {};
|
|
|
|
|
|
|
|
// get all valid hitpoints
|
2015-03-11 23:59:04 +00:00
|
|
|
private ["_hitPoints", "_hitPointsWithSelections"];
|
|
|
|
|
2015-03-10 18:42:21 +00:00
|
|
|
_hitPoints = [_vehicle] call EFUNC(common,getHitpoints);
|
2015-03-11 23:59:04 +00:00
|
|
|
_hitPointsWithSelections = [_vehicle] call EFUNC(common,getHitpointsWithSelections) select 0;
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
// exit if the hitpoint is not valid
|
2015-08-09 15:23:32 +00:00
|
|
|
if !(_hitPoint in _hitPoints) exitWith {systemChat format["NOT A VALID HITPOINT: %1",_hitpoint]};
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
// save array with damage values of all hitpoints
|
|
|
|
private "_hitPointDamages";
|
|
|
|
_hitPointDamages = [];
|
|
|
|
|
|
|
|
{
|
2015-08-09 15:23:32 +00:00
|
|
|
_hitPointDamages set [_forEachIndex, (_vehicle getHitPointDamage _x)];
|
2015-03-10 18:42:21 +00:00
|
|
|
} forEach _hitPoints;
|
|
|
|
|
|
|
|
// save structural damage and sum of hitpoint damages
|
|
|
|
private ["_damageOld", "_hitPointDamageSumOld"];
|
|
|
|
|
|
|
|
_damageOld = damage _vehicle;
|
|
|
|
|
|
|
|
_hitPointDamageSumOld = 0;
|
|
|
|
{
|
2015-03-11 23:59:04 +00:00
|
|
|
if (!(_x in IGNORED_HITPOINTS) && {!isText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints" >> _x >> "depends")}) then {
|
|
|
|
_hitPointDamageSumOld = _hitPointDamageSumOld + (_hitPointDamages select (_hitPoints find _x));
|
|
|
|
};
|
|
|
|
} forEach _hitPointsWithSelections;
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
// set new damage in array
|
|
|
|
_hitPointDamages set [_hitPoints find _hitPoint, _hitPointDamage];
|
|
|
|
|
|
|
|
// save sum of new hitpoint damages
|
|
|
|
private "_hitPointDamageSumNew";
|
|
|
|
|
|
|
|
_hitPointDamageSumNew = 0;
|
|
|
|
{
|
2015-03-11 23:59:04 +00:00
|
|
|
if (!(_x in IGNORED_HITPOINTS) && {!isText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints" >> _x >> "depends")}) then {
|
|
|
|
_hitPointDamageSumNew = _hitPointDamageSumNew + (_hitPointDamages select (_hitPoints find _x));
|
|
|
|
};
|
|
|
|
} forEach _hitPointsWithSelections;
|
2015-03-10 18:42:21 +00:00
|
|
|
|
|
|
|
// calculate new strctural damage
|
|
|
|
private "_damageNew";
|
|
|
|
_damageNew = _hitPointDamageSumNew / count _hitPoints;
|
|
|
|
|
|
|
|
if (_hitPointDamageSumOld > 0) then {
|
|
|
|
_damageNew = _damageOld * (_hitPointDamageSumNew / _hitPointDamageSumOld);
|
|
|
|
};
|
|
|
|
|
|
|
|
// set new structural damage value
|
|
|
|
_vehicle setDamage _damageNew;
|
|
|
|
|
|
|
|
// set the new damage for that hit point
|
|
|
|
|
|
|
|
{
|
|
|
|
_vehicle setHitPointDamage [_x, _hitPointDamages select _forEachIndex];
|
|
|
|
} forEach _hitPoints;
|
2015-03-11 22:53:08 +00:00
|
|
|
|
|
|
|
// normalize hitpoints
|
2015-08-09 15:23:32 +00:00
|
|
|
// [_vehicle] call FUNC(normalizeHitPoints);
|