ACE3/addons/medical_treatment/functions/fnc_getBandageTime.sqf
Kyle Mckay 02365609b5
Medical - Change medical to use hashmaps for wound storage (#8926)
* Refactor medical to use hashmaps for wound storage

- We most frequently want to access wounds by body part, so this makes
  that a constant time lookup.
- The body part index is no longer stored in every wound since it's
  inherent in the wound storage.
- Using body part names as the keys of the hashmap to improve code
  clarity (no more magic numbers).

closes #6468

* Add deserilization migration from old wound arrays

Will migrate from old form array wound storage to the new hashmap
strucutre during deserlization. This is relevant for communities piping
medical state out to a database or similar between sessions.

* fix issue with suture stitching

* change version number in comment

---------

Co-authored-by: Salluci <salluci.lovi@gmail.com>
2023-06-24 08:11:56 +03:00

58 lines
1.9 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: kymckay
* Calculates the time to bandage a wound based on it's size, the patient and the medic.
*
* Arguments:
* 0: Medic <OBJECT>
* 1: Patient <OBJECT>
* 2: Body Part <STRING>
* 3: Treatment <STRING>
*
* Return Value:
* Treatment Time <NUMBER>
*
* Example:
* [player, cursorTarget, "Head", "FieldDressing"] call ace_medical_treatment_fnc_getBandageTime
*
* Public: No
*/
params ["_medic", "_patient", "_bodyPart", "_bandage"];
private _partIndex = ALL_BODY_PARTS find toLower _bodyPart;
if (_partIndex < 0) exitWith { ERROR_1("invalid partIndex - %1",_this); 0 };
private _targetWound = [_patient, _bandage, _bodyPart] call FUNC(findMostEffectiveWound);
_targetWound params ["_wound", "_woundIndex", "_effectiveness"];
TRACE_3("findMostEffectiveWound",_wound,_woundIndex,_effectiveness);
// Everything is patched up on this body part already
if (_wound isEqualTo EMPTY_WOUND) exitWith {0};
_wound params ["_classID", "_amountOf", "_bloodloss", "_damage"];
private _category = (_classID % 10);
// Base bandage time is based on wound size and remaining percentage
private _bandageTime = [BANDAGE_TIME_S, BANDAGE_TIME_M, BANDAGE_TIME_L] select _category;
// Scale bandage time based on amount left and effectiveness (less time if only a little wound left)
// Basic bandage treatment will have a very high effectiveness and can be ignored
if (GVAR(advancedBandages) != 0) then {
_bandageTime = _bandageTime * linearConversion [0, _effectiveness, _amountOf, 0.666, 1, true];
};
// Medics are more practised at applying bandages
if ([_medic] call FUNC(isMedic)) then {
_bandageTime = _bandageTime + BANDAGE_TIME_MOD_MEDIC;
};
// Bandaging yourself requires more work
if (_medic == _patient) then {
_bandageTime = _bandageTime + BANDAGE_TIME_MOD_SELF;
};
TRACE_1("",_bandageTime);
// Nobody can bandage instantly
_bandageTime max 2.25