2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-03-10 20:49:53 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
* Called by repair action / progress bar. Raise events to set the new hitpoint damage.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-16 18:14:54 +00:00
|
|
|
* 0: Unit that does the repairing <OBJECT>
|
|
|
|
* 1: Vehicle to repair <OBJECT>
|
2015-09-26 04:36:35 +00:00
|
|
|
* 2: Selected hitpointIndex <NUMBER>
|
2015-03-10 20:49:53 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-16 18:14:54 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2015-09-26 04:36:35 +00:00
|
|
|
* [unit, vehicle, 6, "MiscRepair"] call ace_repair_fnc_doRepair
|
2015-08-16 18:14:54 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
2015-03-10 20:49:53 +00:00
|
|
|
*/
|
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
params ["_unit", "_vehicle", "_hitPointIndex"];
|
|
|
|
TRACE_3("params",_unit,_vehicle,_hitPointIndex);
|
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
private _postRepairDamageMin = [_unit] call FUNC(getPostRepairDamage);
|
2015-09-26 04:36:35 +00:00
|
|
|
|
|
|
|
(getAllHitPointsDamage _vehicle) params ["_allHitPoints"];
|
2015-11-10 02:11:48 +00:00
|
|
|
private _hitPointClassname = _allHitPoints select _hitPointIndex;
|
2015-03-10 20:49:53 +00:00
|
|
|
|
|
|
|
// get current hitpoint damage
|
2015-11-10 02:11:48 +00:00
|
|
|
private _hitPointCurDamage = _vehicle getHitIndex _hitPointIndex;
|
2015-03-10 20:49:53 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
// repair a max of 0.5, don't use negative values for damage
|
2015-11-10 02:11:48 +00:00
|
|
|
private _hitPointNewDamage = (_hitPointCurDamage - 0.5) max _postRepairDamageMin;
|
2015-03-10 20:49:53 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
if (_hitPointNewDamage < _hitPointCurDamage) then {
|
|
|
|
// raise event to set the new hitpoint damage
|
|
|
|
TRACE_3("repairing main point", _vehicle, _hitPointIndex, _hitPointNewDamage);
|
2016-05-24 16:58:27 +00:00
|
|
|
[QGVAR(setVehicleHitPointDamage), [_vehicle, _hitPointIndex, _hitPointNewDamage], _vehicle] call CBA_fnc_targetEvent;
|
2015-09-26 04:36:35 +00:00
|
|
|
_hitPointCurDamage = _hitPointNewDamage;
|
|
|
|
};
|
2015-03-10 21:52:44 +00:00
|
|
|
|
2015-08-24 18:03:11 +00:00
|
|
|
// Get hitpoint groups if available
|
2021-02-18 18:58:08 +00:00
|
|
|
private _hitpointGroupConfig = configOf _vehicle >> QGVAR(hitpointGroups);
|
2015-08-24 18:03:11 +00:00
|
|
|
if (isArray _hitpointGroupConfig) then {
|
2015-09-26 04:36:35 +00:00
|
|
|
// Retrieve hitpoint subgroup if current hitpoint is main hitpoint of a group
|
2015-08-24 02:17:24 +00:00
|
|
|
{
|
2015-09-26 04:36:35 +00:00
|
|
|
_x params ["_masterHitpoint", "_subHitArray"];
|
|
|
|
// Exit using found hitpoint group if this hitpoint is leader of any
|
|
|
|
if (_masterHitpoint == _hitPointClassname) exitWith {
|
2015-08-24 18:03:11 +00:00
|
|
|
{
|
2018-04-12 14:15:57 +00:00
|
|
|
private _subHitpoint = _x;
|
|
|
|
private _subHitIndex = _allHitPoints findIf {_x == _subHitpoint}; //convert hitpoint classname to index
|
2015-09-26 04:36:35 +00:00
|
|
|
if (_subHitIndex == -1) then {
|
2018-04-12 14:15:57 +00:00
|
|
|
ERROR_2("Invalid hitpoint %1 in hitpointGroups of %2",_subHitpoint,_vehicle);
|
2015-08-24 18:03:11 +00:00
|
|
|
} else {
|
2015-11-10 02:11:48 +00:00
|
|
|
private _subPointCurDamage = _vehicle getHitIndex _hitPointIndex;
|
|
|
|
private _subPointNewDamage = (_subPointCurDamage - 0.5) max _postRepairDamageMin;
|
2015-09-26 04:36:35 +00:00
|
|
|
if (_subPointNewDamage < _subPointCurDamage) then {
|
|
|
|
TRACE_3("repairing sub point", _vehicle, _subHitIndex, _subPointNewDamage);
|
2016-05-24 16:58:27 +00:00
|
|
|
[QGVAR(setVehicleHitPointDamage), [_vehicle, _subHitIndex, _subPointNewDamage], _vehicle] call CBA_fnc_targetEvent;
|
2015-09-26 04:36:35 +00:00
|
|
|
};
|
2015-08-24 18:03:11 +00:00
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
} forEach _subHitArray;
|
2015-08-24 02:17:24 +00:00
|
|
|
};
|
2015-08-24 18:03:11 +00:00
|
|
|
} forEach (getArray _hitpointGroupConfig);
|
2015-08-24 02:17:24 +00:00
|
|
|
};
|
|
|
|
|
2015-03-10 21:52:44 +00:00
|
|
|
// display text message if enabled
|
|
|
|
if (GVAR(DisplayTextOnRepair)) then {
|
2015-08-24 18:58:54 +00:00
|
|
|
// Find localized string
|
2015-11-10 02:11:48 +00:00
|
|
|
private _textLocalized = localize ([LSTRING(RepairedHitPointFully), LSTRING(RepairedHitPointPartially)] select (_hitPointCurDamage > 0));
|
|
|
|
private _textDefault = localize ([LSTRING(RepairedFully), LSTRING(RepairedPartially)] select (_hitPointCurDamage > 0));
|
2015-09-26 04:36:35 +00:00
|
|
|
([_hitPointClassname, _textLocalized, _textDefault] call FUNC(getHitPointString)) params ["_text"];
|
2015-03-10 21:52:44 +00:00
|
|
|
|
2015-08-24 03:24:25 +00:00
|
|
|
// Display text
|
2015-03-10 21:52:44 +00:00
|
|
|
[_text] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|