2015-02-21 20:10:57 +00:00
/*
* Author: Glowbal
* Parse the ACE_Medical_Advanced config for all injury types.
*
* Arguments:
2015-08-22 14:25:10 +00:00
* None
2015-02-21 20:10:57 +00:00
* ReturnValue:
2015-08-22 14:25:10 +00:00
* None
2015-02-21 20:10:57 +00:00
*
* Public: No
*/
#include "script_component.hpp"
2016-06-30 15:33:29 +00:00
private _injuriesRootConfig = (configFile >> "ACE_Medical_Injuries");
private _allFoundDamageTypes = [];
private _configDamageTypes = (_injuriesRootConfig >> "damageTypes");
2015-04-02 20:57:35 +00:00
// minimum lethal damage collection, mapped to damageTypes
2016-06-30 15:33:29 +00:00
private _defaultMinLethalDamage = getNumber (_configDamageTypes >> "lethalDamage");
2015-04-02 20:57:35 +00:00
GVAR(minLethalDamages) = [];
// Collect all available damage types from the config
2015-02-23 15:18:33 +00:00
for "_i" from 0 to (count _configDamageTypes -1) /* step +1 */ do {
2015-03-03 21:13:22 +00:00
// Only get the subclasses in damageType class
2015-02-28 18:28:05 +00:00
if (isClass(_configDamageTypes select _i)) then {
2015-11-30 16:21:28 +00:00
_allFoundDamageTypes pushBack (configName (_configDamageTypes select _i));
2016-06-30 15:33:29 +00:00
private _minLethalDamage = if (isNumber((_configDamageTypes select _i) >> "lethalDamage")) then {
2015-04-02 20:57:35 +00:00
getNumber((_configDamageTypes select _i) >> "lethalDamage");
} else {
_defaultMinLethalDamage
};
2015-11-30 16:21:28 +00:00
GVAR(minLethalDamages) pushBack _minLethalDamage;
2015-02-28 18:28:05 +00:00
};
2015-02-23 15:18:33 +00:00
};
GVAR(allAvailableDamageTypes) = _allFoundDamageTypes;
2015-03-03 22:26:54 +00:00
GVAR(woundClassNames) = [];
2015-03-06 21:41:20 +00:00
GVAR(fractureClassNames) = [];
2016-06-30 15:33:29 +00:00
private _getIfInConfig = {
params ["_config", "_default"];
if (_default isEqualType []) exitWith {
if (isArray(_config)) then { getArray(_config)} else { _default };
};
if (_default isEqualType 0) exitWith {
if (isNumber(_config)) then { getNumber(_config)} else { _default };
};
if (_default isEqualType "") exitWith {
if (isText(_config)) then { getText(_config)} else { _default };
};
_default;
};
2015-03-06 21:41:20 +00:00
// Parsing the wounds
2015-03-03 21:13:22 +00:00
// function for parsing a sublcass of an injury
2016-06-30 15:33:29 +00:00
private _parseForSubClassWounds = {
params ["_subClass"];
2015-11-30 16:14:05 +00:00
if (isClass (_entry >> _subClass)) exitWith {
2016-06-30 15:33:29 +00:00
private _subClassConfig = (_entry >> _subClass);
private _subClassselections = [_subClassConfig >> "selections", _selections] call _getIfInConfig;
private _subClasscauses = [_subClassConfig >> "causes", _causes] call _getIfInConfig;
if (count _subClassselections > 0 && {count _subClasscauses > 0}) then {
// constructs a type name, such as: 'woundMinor'
GVAR(woundClassNames) pushBack (_classType + (configName _subClassConfig));
_allWoundClasses pushBack [
_classID,
_subClassselections,
[_subClassConfig >> "bleedingRate", _bloodLoss] call _getIfInConfig,
[_subClassConfig >> "pain", _pain] call _getIfInConfig,
[[_subClassConfig >> "minDamage", _minDamage] call _getIfInConfig, [_subClassConfig >> "maxDamage", _maxDamage] call _getIfInConfig],
_subClasscauses,
[_subClassConfig >> "name", (_classDisplayName + " " + _subClass)] call _getIfInConfig
];
2015-03-03 21:13:22 +00:00
_classID = _classID + 1;
2015-02-28 18:28:05 +00:00
};
true;
};
false;
2015-02-22 08:27:01 +00:00
};
2015-02-28 10:41:27 +00:00
// TODO classTypes are strings currently. Convert them to unqiue IDs instead.
2016-06-30 15:33:29 +00:00
private _woundsConfig = (_injuriesRootConfig >> "wounds");
private _allWoundClasses = [];
private _classID = 0;
2015-02-21 20:10:57 +00:00
if (isClass _woundsConfig) then {
2016-06-30 15:33:29 +00:00
private _amountOf = count _woundsConfig;
2015-02-28 18:28:05 +00:00
for "_i" from 0 to (_amountOf -1) /* step +1 */ do {
2016-06-30 15:33:29 +00:00
private _entry = _woundsConfig select _i;
2015-02-28 18:28:05 +00:00
if (isClass _entry) then {
2016-06-30 15:33:29 +00:00
private _classType = (ConfigName _entry);
private _selections = if (isArray(_entry >> "selections")) then { getArray(_entry >> "selections");} else {[]};
private _bloodLoss = if (isNumber(_entry >> "bleedingRate")) then { getNumber(_entry >> "bleedingRate");} else {0};
private _pain = if (isNumber(_entry >> "pain")) then { getNumber(_entry >> "pain");} else {0};
private _minDamage = if (isNumber(_entry >> "minDamage")) then { getNumber(_entry >> "minDamage");} else {0};
private _maxDamage = if (isNumber(_entry >> "maxDamage")) then { getNumber(_entry >> "maxDamage");} else {-1};
private _causes = if (isArray(_entry >> "causes")) then { getArray(_entry >> "causes");} else {[]};
private _classDisplayName = if (isText(_entry >> "name")) then { getText(_entry >> "name");} else {_classType};
2015-03-03 21:13:22 +00:00
// TODO instead of hardcoding minor, medium and large just go through all sub classes recursively until none are found
2015-11-30 16:14:05 +00:00
if (["Minor"] call _parseForSubClassWounds || ["Medium"] call _parseForSubClassWounds || ["Large"] call _parseForSubClassWounds) exitWith {}; // continue to the next one
2015-02-22 08:27:01 +00:00
2015-02-28 18:28:05 +00:00
// There were no subclasses, so we will add this one instead.
if (count _selections > 0 && count _causes > 0) then {
2015-11-30 16:21:28 +00:00
GVAR(woundClassNames) pushBack _classType;
_allWoundClasses pushBack [_classID, _selections, _bloodLoss, _pain, [_minDamage, _maxDamage], _causes, _classDisplayName];
2015-03-03 21:13:22 +00:00
_classID = _classID + 1;
2015-02-28 18:28:05 +00:00
};
true;
};
};
2015-02-21 20:10:57 +00:00
};
GVAR(AllWoundInjuryTypes) = _allWoundClasses;
2015-03-06 21:41:20 +00:00
// Linking injuries to the woundInjuryType variables.
2016-06-30 15:33:29 +00:00
private _damageTypesConfig = (_injuriesRootConfig >> "damageTypes");
private _thresholds = getArray(_damageTypesConfig >> "thresholds");
private _selectionSpecific = getNumber(_damageTypesConfig >> "selectionSpecific");
2015-02-21 20:10:57 +00:00
{
2016-06-30 15:33:29 +00:00
private _varName = format[QGVAR(woundInjuryType_%1),_x];
private _woundTypes = [];
private _type = _x;
2015-02-28 18:28:05 +00:00
{
// Check if this type is in the causes of a wound class, if so, we will store the wound types for this damage type
if (_type in (_x select 5)) then {
2015-11-30 16:21:28 +00:00
_woundTypes pushBack _x;
2015-02-28 18:28:05 +00:00
};
2015-11-30 16:23:48 +00:00
} forEach _allWoundClasses;
2016-06-30 15:33:29 +00:00
private _typeThresholds = _thresholds;
private _selectionSpecificType = _selectionSpecific;
2015-02-28 18:28:05 +00:00
if (isClass(_damageTypesConfig >> _x)) then {
if (isArray(_damageTypesConfig >> _x >> "thresholds")) then { _typeThresholds = getArray(_damageTypesConfig >> _x >> "thresholds");};
if (isNumber(_damageTypesConfig >> _x >> "selectionSpecific")) then { _selectionSpecificType = getNumber(_damageTypesConfig >> _x >> "selectionSpecific");};
};
2016-06-30 15:33:29 +00:00
// TODO use CBA namespace
2015-11-30 16:27:09 +00:00
missionNamespace setVariable [_varName, [_typeThresholds, _selectionSpecificType > 0, _woundTypes]];
2015-05-16 21:20:38 +00:00
// extension loading
2016-06-30 15:33:29 +00:00
private _minDamageThresholds = "";
private _amountThresholds = "";
2015-05-16 21:20:38 +00:00
{
_minDamageThresholds = _minDamageThresholds + str(_x select 0);
_amountThresholds = _amountThresholds + str(_x select 1);
if (_forEachIndex < (count _typeThresholds) - 1) then {
_minDamageThresholds = _minDamageThresholds + ":";
_amountThresholds = _amountThresholds + ":";
};
2015-11-30 16:23:48 +00:00
} forEach _typeThresholds;
2015-05-16 21:20:38 +00:00
2016-06-30 15:33:29 +00:00
// load in the damage types into the medical extension
private _extensionRes = "ace_medical" callExtension format ["addDamageType,%1,%2,%3,%4,%5",
_type,
GVAR(minLethalDamages) select _forEachIndex,
_minDamageThresholds,
_amountThresholds,
_selectionSpecificType
];
2016-09-18 12:17:18 +00:00
TRACE_1("",_extensionRes);
2015-11-30 16:23:48 +00:00
} forEach _allFoundDamageTypes;
2015-05-16 21:20:38 +00:00
// Extension loading
{
2015-08-22 16:54:51 +00:00
_x params ["_classID", "_selections", "_bloodLoss", "_pain", "_damage", "_causesArray", "_classDisplayName"];
2015-08-22 14:25:10 +00:00
_damage params ["_minDamage", "_maxDamage"];
2016-09-18 12:05:05 +00:00
2016-06-30 15:33:29 +00:00
private _className = GVAR(woundClassNames) select _forEachIndex;
2016-09-18 12:05:05 +00:00
if (_classDisplayName == "") then {_classDisplayName = _className; }; // fall back
2016-06-30 15:33:29 +00:00
private _allowedSelections = "";
2015-05-16 21:20:38 +00:00
{
_allowedSelections = _allowedSelections + _x;
if (_forEachIndex < (count _selections) - 1) then {
_allowedSelections = _allowedSelections + ":";
};
2015-11-30 16:23:48 +00:00
} forEach _selections;
2015-05-16 21:20:38 +00:00
2016-06-30 15:33:29 +00:00
private _causes = "";
2015-05-16 21:20:38 +00:00
{
_causes = _causes + _x;
if (_forEachIndex < (count _causesArray) - 1) then {
_causes = _causes + ":";
};
2015-11-30 16:23:48 +00:00
} forEach _causesArray;
2015-05-16 21:20:38 +00:00
2016-09-18 12:17:18 +00:00
private _extensionArgs = format ["addInjuryType,%1,%2,%3,%4,%5,%6,%7,%8,%9", _classID, _className, _allowedSelections, _bloodLoss, _pain, _minDamage, _maxDamage, _causes, _classDisplayName];
TRACE_1("",_extensionArgs);
private _extensionRes = "ace_medical" callExtension _extensionArgs;
TRACE_1("",_extensionRes);
2015-05-16 21:20:38 +00:00
2015-11-30 16:23:48 +00:00
} forEach _allWoundClasses;
2015-05-16 21:20:38 +00:00
2015-05-16 22:47:42 +00:00
"ace_medical" callExtension "ConfigComplete";