ACE3/addons/medical_damage/functions/fnc_interpolatePoints.sqf
pterolatypus 73a7dbdc1e
Medical - Rework wound handling (#8278)
- Add stackable wound handler system for easy 3rd party extensibility and overriding of default wound handler.
- Change mapping from wound type -> damage types, to damage type -> wound types. Improves the semantics and makes configuration easier to reason about.
- Allow damage types to influence wound properties (bleed, size, etc.) with configurable variance parameters.
- Allow configuration of wound type variance per damage type. Enabling more logically driven variance for sensible but still varied end results.
- Improve handling of non-selection-specific damage events. The wound handler now receives all incoming damages and may apply damage to multiple selections (previously only ever one) if the damage type is not configured to be selection specific (with new config property `selectionSpecific`).
- Add debug script for testing explosion damage events at varied ranges.
- Add custom fire wound handler.
2022-02-17 20:03:12 +00:00

42 lines
1.3 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: Pterolatypus
* Returns the image of a value on a linear piecewise function defined by given points
* Force integer causes decimals to be rounded up or down by chance based on their decimal part, i.e. 2.7 has a 70% chance to return 3 and 30% to return 2
*
* Arguments:
* 0: Input value <NUMBER>
* 1: Function points, must be in descending order by X (input) value <ARRAY>
* 2: Whether to force integer <BOOLEAN>
*
* ReturnValue:
* Interpolated result <NUMBER>
*
* Example:
* [0.2, [[1,0], [0.5,1], [0,0]]] call ace_medical_damage_fnc_interpolatePoints
*
* Public: No
*/
params ["_input", "_points", ["_randomRound", false]];
if (count _points < 1) exitWith {
//TODO: sensible default/error value
0
};
if (count _points == 1) exitWith {_points select 0 select 1};
private _output = 0;
private _lower = _points findIf {(_x select 0) < _input};
if (_lower == 0) exitWith {_points select 0 select 1};
if (_lower == -1) exitWith {_points select (count _points - 1) select 1};
private _upper = _points select (_lower-1);
_lower = _points select _lower;
_output = linearConversion [_lower select 0, _upper select 0, _input, _lower select 1, _upper select 1, true];
if (_randomRound) then {
// chance to round up is equal to the decimal part
_output = ceil (_output - random 1);
};
_output //return