2015-03-11 22:30:24 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
* Used to normalize dependant hitpoints. May overwrite some global variables that are named like hitpoints or "Total" though...
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-16 18:14:54 +00:00
|
|
|
* 0: Local Vehicle <OBJECT>
|
2015-03-11 22:30:24 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-16 18:14:54 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [vehicle] call ace_repair_fnc_normalizeHitPoints
|
|
|
|
*
|
|
|
|
* Public: No
|
2015-03-11 22:30:24 +00:00
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-09 06:54:44 +00:00
|
|
|
params ["_vehicle"];
|
2015-11-10 02:11:48 +00:00
|
|
|
TRACE_2("params",_vehicle, typeOf _vehicle);
|
2015-03-11 22:30:24 +00:00
|
|
|
|
2015-08-16 18:14:54 +00:00
|
|
|
// Can't execute all commands if the vehicle isn't local, exit if that's so
|
2015-11-10 02:11:48 +00:00
|
|
|
if !(local _vehicle) exitWith {ACE_LOGERROR_1("Vehicle Not Local %1", _vehicle);};
|
2015-03-11 22:30:24 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
(getAllHitPointsDamage _vehicle) params [["_allHitPoints", []]];
|
2015-03-11 22:30:24 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
private _config = configFile >> "CfgVehicles" >> typeOf _vehicle >> "HitPoints";
|
2015-03-11 22:30:24 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
private _realHitPoints = [];
|
|
|
|
private _dependentHitPoints = [];
|
|
|
|
private _dependentHitPointScripts = [];
|
2015-03-11 22:30:24 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
// Find dependent hitpoints
|
|
|
|
{
|
|
|
|
if ((_x != "") && {isClass (_config >> _x)} && {!(_x in _realHitPoints)}) then {
|
|
|
|
_realHitPoints pushBack _x;
|
|
|
|
if (isText (_config >> _x >> "depends")) then {
|
|
|
|
_dependentHitPoints pushBack _x;
|
|
|
|
_dependentHitPointScripts pushBack compile getText (_config >> _x >> "depends");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach _allHitPoints;
|
2015-03-11 22:30:24 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
TRACE_2("",_realHitPoints,_dependentHitPoints);
|
|
|
|
|
|
|
|
// Don't bother setting variables if no depends on vehicle:
|
|
|
|
if (_dependentHitPoints isEqualTo []) exitWith {};
|
2015-03-11 22:30:24 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
|
|
|
|
// Define global variables
|
|
|
|
Total = damage _vehicle;
|
2015-03-11 22:30:24 +00:00
|
|
|
{
|
|
|
|
missionNamespace setVariable [_x, _vehicle getHitPointDamage _x];
|
2015-11-10 02:11:48 +00:00
|
|
|
} forEach _realHitPoints;
|
2015-03-11 22:30:24 +00:00
|
|
|
|
|
|
|
// apply normalized damage to all dependand hitpoints
|
|
|
|
{
|
2015-11-10 02:11:48 +00:00
|
|
|
private _damage = call (_dependentHitPointScripts select _forEachIndex);
|
|
|
|
TRACE_2("setting depend hitpoint", _x, _damage);
|
2015-03-11 22:30:24 +00:00
|
|
|
_vehicle setHitPointDamage [_x, _damage];
|
|
|
|
} forEach _dependentHitPoints;
|