Page MenuHomeFeedback Tracker

BIS_fnc_setHitPointDamage uses wrong dependencies
New, NormalPublic

Description

The function should be (I think) checking the dependencies of the given hit point, but instead it checks the dependencies of every other hit point.

For example:
"hithull" on vehicles is most of the time dependent on "Total". Total being the value returned by damage _vehicle. So you would expect that if you run the following code that "hithull" will get set to the maximum value of "Total" and the new "hithull":

[_vehicle, "hithull", _damage, true] call BIS_fnc_setHitPointDamage;

What happens instead is that every other part with dependencies gets set to the max of their damage and their dependencies. On the RHS MI24P the only two hit points with dependencies are the engine and the hull. When using the above function call on that vehicle, the engine gets set but not the hull. But if you replace the "hithull" with "hitengine", the hull hit point will get set.

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
Scripting
Steps To Reproduce

For the MI24P, as that was my test subject and has only two hit points with dependency:

  1. Set the damage on a vehicle: _vehicle setDamage 0.8
  2. Repair every hit point by looping through each value of getAllHitPointsDamage _vehicle and executing the following code:
{
    _vehicle setHitIndex [_forEachIndex, 0];
} foreach (getAllHitPointsDamage _vehicle) select 0;
  1. Observe that getAllHitPointsDamage _vehicle now returns 0 for all hit points and that all 6 hit point boxes in the vehicle are white.
  2. Use [_vehicle, "hithull", 0, true] call BIS_fnc_setHitPointDamage; and observe that none of the boxes have changed colour in the vehicle, and all values from getAllHitPointsDamage _vehicle are still 0.
  3. use [_vehicle, "hitengine", 0, true] call BIS_fnc_setHitPointDamage; and observe that the hull is now red in the vehicle and the value for hithull has changed to 0.8 when checking getAllHitPointsDamage _vehicle or _vehicle getHitPointDamage "hithull".
Additional Information

Part of this is related to T120242 since "hithull" can be set, but without using setDamage to set the "Total" damage lower than "hithull", "hithull" will always reset to the value of damage _vehicle. That alone is very annoying, because setDamage sets damage over all hitpoints when you only want to change the "hithull" hitpoint.

If I am correct in assuming that the dependency means that the hitPoint will get set to the maximum of the hitpoint and its dependency, this would be the fix: (excluding defines and includes that would be before the params)

params ["_entity", "_hitPoint", "_damage", ["_useDependency", true, [true]]];

_entity setHitPointDamage [_hitPoint, _damage];

if (_useDependency) then 
{
	private _cfgHitPoints = configFile >> "CfgVehicles" >> typeOf _entity >> "HitPoints";

	private _expr = getText (_cfgHitPoints >> _hitPoint >> "depends");
	
	{
		private _res = _x call
		{
			if (!isNull (_cfgHitPoints >> _this)) exitWith {_entity getHitPointDamage _this};
			if (_this == "Total") exitWith {damage _entity};
			nil
		};
		
		if (!isNil "_res") then
		{
			_expr find _x call
			{
				_expr = [_expr select [0, _this], _res, _expr select [_this + count _x]] joinString "";
			};
		};
	}
	forEach (_expr splitString ESCAPE_CHARS);

	configName _x call
	{
		_entity setHitPointDamage [_this, (_entity getHitPointDamage _this) max call compile _expr];
	};
};

Event Timeline

NeilZar created this task.Jan 31 2019, 2:33 AM
oukej added a subscriber: oukej.Feb 1 2019, 8:31 PM