mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #2246 from jonpas/repairHitpointGroups
Repair Hitpoint Groups Framework
This commit is contained in:
commit
f7679b45ad
@ -31,7 +31,7 @@ class ACE_Repair {
|
||||
class MiscRepair: ReplaceWheel {
|
||||
displayName = CSTRING(Repairing); // let's make empty string an auto generated string
|
||||
displayNameProgress = CSTRING(RepairingHitPoint);
|
||||
condition = QUOTE((_target getHitPointDamage _hitPoint) > ([_caller] call FUNC(getPostRepairDamage)));
|
||||
condition = QUOTE(call FUNC(canMiscRepair));
|
||||
requiredEngineer = 0;
|
||||
repairingTime = 15;
|
||||
callbackSuccess = QUOTE(call FUNC(doRepair));
|
||||
|
@ -285,7 +285,10 @@ class CfgVehicles {
|
||||
transportRepair = 0;
|
||||
};
|
||||
|
||||
class Heli_Transport_04_base_F;
|
||||
class Helicopter_Base_H;
|
||||
class Heli_Transport_04_base_F: Helicopter_Base_H {
|
||||
GVAR(hitpointGroups[]) = { {"HitEngine", {"HitEngine1", "HitEngine2"}}, {"Glass_1_hitpoint", {"Glass_2_hitpoint", "Glass_3_hitpoint", "Glass_4_hitpoint", "Glass_5_hitpoint", "Glass_6_hitpoint", "Glass_7_hitpoint", "Glass_8_hitpoint", "Glass_9_hitpoint", "Glass_10_hitpoint", "Glass_11_hitpoint", "Glass_12_hitpoint", "Glass_13_hitpoint", "Glass_14_hitpoint", "Glass_15_hitpoint", "Glass_16_hitpoint", "Glass_17_hitpoint", "Glass_18_hitpoint", "Glass_19_hitpoint", "Glass_20_hitpoint"}} };
|
||||
};
|
||||
class O_Heli_Transport_04_repair_F: Heli_Transport_04_base_F {
|
||||
GVAR(canRepair) = 1;
|
||||
transportRepair = 0;
|
||||
@ -303,12 +306,19 @@ class CfgVehicles {
|
||||
transportRepair = 0;
|
||||
};
|
||||
|
||||
class Offroad_01_base_F;
|
||||
class Car_F;
|
||||
class Offroad_01_base_F: Car_F {
|
||||
GVAR(hitpointGroups[]) = { {"HitGlass1", {"HitGlass2"}} };
|
||||
};
|
||||
class Offroad_01_repair_base_F: Offroad_01_base_F {
|
||||
GVAR(canRepair) = 1;
|
||||
transportRepair = 0;
|
||||
};
|
||||
|
||||
class MRAP_01_base_F: Car_F {
|
||||
GVAR(hitpointGroups[]) = { {"HitGlass1", {"HitGlass2", "HitGlass3", "HitGlass4", "HitGlass5", "HitGlass6"}} };
|
||||
};
|
||||
|
||||
class B_Truck_01_mover_F;
|
||||
class B_Truck_01_Repair_F: B_Truck_01_mover_F {
|
||||
GVAR(canRepair) = 1;
|
||||
|
@ -3,6 +3,7 @@
|
||||
ADDON = false;
|
||||
|
||||
PREP(addRepairActions);
|
||||
PREP(canMiscRepair);
|
||||
PREP(canRemove);
|
||||
PREP(canRepair);
|
||||
PREP(canRepairTrack);
|
||||
|
@ -14,7 +14,6 @@
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
#define TRACK_HITPOINTS ["HitLTrack", "HitRTrack"]
|
||||
|
||||
params ["_vehicle"];
|
||||
TRACE_1("params", _vehicle);
|
||||
@ -74,6 +73,26 @@ if (_type in _initializedClasses) exitWith {};
|
||||
// exit if the hitpoint is in the blacklist, e.g. glasses
|
||||
if (_x in IGNORED_HITPOINTS) exitWith {};
|
||||
|
||||
private ["_hitpointGroupConfig", "_inHitpointSubGroup", "_currentHitpoint"];
|
||||
|
||||
// Get hitpoint groups if available
|
||||
_hitpointGroupConfig = configFile >> "CfgVehicles" >> _type >> QGVAR(hitpointGroups);
|
||||
_inHitpointSubGroup = false;
|
||||
if (isArray _hitpointGroupConfig) then {
|
||||
// Set variable if current hitpoint is in a sub-group (to be excluded from adding action)
|
||||
_currentHitpoint = _x;
|
||||
{
|
||||
{
|
||||
if (_x == _currentHitpoint) exitWith {
|
||||
_inHitpointSubGroup = true;
|
||||
};
|
||||
} forEach (_x select 1);
|
||||
} forEach (getArray _hitpointGroupConfig);
|
||||
};
|
||||
|
||||
// Exit if current hitpoint is in sub-group (only main hitpoints get actions)
|
||||
if (_inHitpointSubGroup) exitWith {};
|
||||
|
||||
// exit if the hitpoint is virtual
|
||||
if (isText (configFile >> "CfgVehicles" >> _type >> "HitPoints" >> _x >> "depends")) exitWith {};
|
||||
|
||||
|
54
addons/repair/functions/fnc_canMiscRepair.sqf
Normal file
54
addons/repair/functions/fnc_canMiscRepair.sqf
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Author: Jonpas
|
||||
* Check if misc repair action can be done, called from callbackSuccess.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit that does the repairing <OBJECT>
|
||||
* 1: Vehicle to repair <OBJECT>
|
||||
* 2: Selected hitpoint <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* Can Misc Repair <BOOL>
|
||||
*
|
||||
* Example:
|
||||
* [unit, vehicle, "hitpoint", "classname"] call ace_repair_fnc_canMiscRepair
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_hitpointGroupConfig", "_hitpointGroup", "_postRepairDamage", "_return"];
|
||||
params ["_caller", "_target", "_hitPoint"];
|
||||
|
||||
// Get hitpoint groups if available
|
||||
_hitpointGroupConfig = configFile >> "CfgVehicles" >> typeOf _target >> QGVAR(hitpointGroups);
|
||||
_hitpointGroup = [];
|
||||
if (isArray _hitpointGroupConfig) then {
|
||||
// Retrieve hitpoint subgroup if current hitpoint is main hitpoint of a group
|
||||
{
|
||||
// Exit using found hitpoint group if this hitpoint is leader of any
|
||||
if (_x select 0 == _hitPoint) exitWith {
|
||||
_hitpointGroup = _x select 1;
|
||||
};
|
||||
} forEach (getArray _hitpointGroupConfig);
|
||||
};
|
||||
|
||||
// Add current hitpoint to the group
|
||||
_hitpointGroup pushBack _hitPoint;
|
||||
|
||||
// Get post repair damage
|
||||
_postRepairDamage = [_caller] call FUNC(getPostRepairDamage);
|
||||
|
||||
// Return true if damage can be repaired on any hitpoint in the group, else false
|
||||
_return = false;
|
||||
{
|
||||
if ((_target getHitPointDamage _x) > _postRepairDamage) exitWith {
|
||||
_return = true;
|
||||
};
|
||||
} forEach _hitpointGroup;
|
||||
|
||||
if (typeOf _target == "B_MRAP_01_F") then {
|
||||
diag_log format ["%1 - %2", _hitPoint, _hitpointGroup];
|
||||
};
|
||||
|
||||
_return
|
@ -17,11 +17,11 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_hitPointDamage", "_text", "_hitpointGroup"];
|
||||
params ["_unit", "_vehicle", "_hitPoint"];
|
||||
TRACE_3("params",_unit,_vehicle,_hitPoint);
|
||||
|
||||
// get current hitpoint damage
|
||||
private "_hitPointDamage";
|
||||
_hitPointDamage = _vehicle getHitPointDamage _hitPoint;
|
||||
|
||||
_hitPointDamage = _hitPointDamage - 0.5;
|
||||
@ -31,9 +31,29 @@ _hitPointDamage = _hitPointDamage max ([_unit] call FUNC(getPostRepairDamage));
|
||||
// raise event to set the new hitpoint damage
|
||||
["setVehicleHitPointDamage", _vehicle, [_vehicle, _hitPoint, _hitPointDamage]] call EFUNC(common,targetEvent);
|
||||
|
||||
// Get hitpoint groups if available
|
||||
_hitpointGroupConfig = configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(hitpointGroups);
|
||||
_hitpointGroup = [];
|
||||
if (isArray _hitpointGroupConfig) then {
|
||||
// Retrieve group if current hitpoint is leader of any
|
||||
{
|
||||
if (_x select 0 == _hitPoint) exitWith {
|
||||
([_vehicle] call EFUNC(common,getHitPointsWithSelections)) params ["_hitpoints"];
|
||||
// Set all sub-group hitpoints' damage to 0, if a hitpoint is invalid print RPT error
|
||||
{
|
||||
if (_x in _hitpoints) then {
|
||||
["setVehicleHitPointDamage", _vehicle, [_vehicle, _x, 0]] call EFUNC(common,targetEvent);
|
||||
} else {
|
||||
diag_log text format ["[ACE] ERROR: Invalid hitpoint %1 in hitpointGroups of %2", _x, _vehicle];
|
||||
};
|
||||
|
||||
} forEach (_x select 1);
|
||||
};
|
||||
} forEach (getArray _hitpointGroupConfig);
|
||||
};
|
||||
|
||||
// display text message if enabled
|
||||
if (GVAR(DisplayTextOnRepair)) then {
|
||||
private "_text";
|
||||
_text = format ["STR_ACE_Repair_%1", _hitPoint];
|
||||
|
||||
if (isLocalized _text) then {
|
||||
|
@ -12,5 +12,5 @@
|
||||
#include "\z\ace\addons\main\script_macros.hpp"
|
||||
|
||||
|
||||
#define IGNORED_HITPOINTS ["HitGlass1","HitGlass2","HitGlass3","HitGlass4","HitGlass5","HitGlass6","HitGlass7","HitGlass8","HitGlass9","HitGlass10","HitGlass11","HitGlass12","HitGlass13","HitGlass14","HitGlass15","HitRGlass","HitLGlass"]
|
||||
// #define TRACK_HITPOINTS ["HitLTrack", "HitRTrack"];
|
||||
#define IGNORED_HITPOINTS ["HitGlass1", "HitGlass2", "HitGlass3", "HitGlass4", "HitGlass5", "HitGlass6", "HitGlass7", "HitGlass8", "HitGlass9", "HitGlass10", "HitGlass11", "HitGlass12", "HitGlass13", "HitGlass14", "HitGlass15", "HitRGlass", "HitLGlass", "Glass_1_hitpoint", "Glass_2_hitpoint", "Glass_3_hitpoint", "Glass_4_hitpoint", "Glass_5_hitpoint", "Glass_6_hitpoint", "Glass_7_hitpoint", "Glass_8_hitpoint", "Glass_9_hitpoint", "Glass_10_hitpoint", "Glass_11_hitpoint", "Glass_12_hitpoint", "Glass_13_hitpoint", "Glass_14_hitpoint", "Glass_15_hitpoint", "Glass_16_hitpoint", "Glass_17_hitpoint", "Glass_18_hitpoint", "Glass_19_hitpoint", "Glass_20_hitpoint"]
|
||||
#define TRACK_HITPOINTS ["HitLTrack", "HitRTrack"]
|
||||
|
Loading…
Reference in New Issue
Block a user