2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-07-03 21:14:23 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal, KoffeinFlummi
|
2015-08-16 18:14:54 +00:00
|
|
|
* Starts the repair process.
|
2015-07-03 21:14:23 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-16 18:14:54 +00:00
|
|
|
* 0: Unit that does the repairing <OBJECT>
|
2015-09-26 04:36:35 +00:00
|
|
|
* 1: Vehicle to repair <OBJECT>
|
|
|
|
* 2: Selected hitpoint or hitpointIndex <STRING>or<NUMBER>
|
2015-08-16 18:14:54 +00:00
|
|
|
* 3: Repair Action Classname <STRING>
|
2015-07-03 21:14:23 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-16 18:14:54 +00:00
|
|
|
* Succesful Repair Started <BOOL>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [unit, vehicle, "hitpoint", "classname"] call ace_repair_fnc_repair
|
2015-07-03 21:14:23 +00:00
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
2015-08-09 06:54:44 +00:00
|
|
|
params ["_caller", "_target", "_hitPoint", "_className"];
|
2017-10-10 14:39:59 +00:00
|
|
|
TRACE_4("params",_caller,_target,_hitPoint,_className);
|
2015-08-09 06:54:44 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className);
|
2015-11-10 02:11:48 +00:00
|
|
|
if !(isClass _config) exitWith {false}; // or go for a default?
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _engineerRequired = if (isNumber (_config >> "requiredEngineer")) then {
|
2015-07-03 21:14:23 +00:00
|
|
|
getNumber (_config >> "requiredEngineer");
|
|
|
|
} else {
|
|
|
|
// Check for required class
|
2015-11-10 02:11:48 +00:00
|
|
|
if (isText (_config >> "requiredEngineer")) exitWith {
|
2015-08-16 14:45:46 +00:00
|
|
|
missionNamespace getVariable [(getText (_config >> "requiredEngineer")), 0];
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
0;
|
|
|
|
};
|
2015-11-10 02:11:48 +00:00
|
|
|
if !([_caller, _engineerRequired] call FUNC(isEngineer)) exitWith {false};
|
2016-04-13 01:04:12 +00:00
|
|
|
|
|
|
|
if ((isEngineOn _target) && {GVAR(autoShutOffEngineWhenStartingRepair)}) then {
|
2016-06-04 10:12:56 +00:00
|
|
|
[QEGVAR(common,engineOn), [_target, false], _target] call CBA_fnc_targetEvent;
|
2016-04-13 01:04:12 +00:00
|
|
|
};
|
|
|
|
if ((isEngineOn _target) && {!GVAR(autoShutOffEngineWhenStartingRepair)}) exitWith {
|
2016-06-04 10:12:56 +00:00
|
|
|
[LSTRING(shutOffEngineWarning), 1.5, _caller] call EFUNC(common,displayTextStructured);
|
2016-04-13 01:04:12 +00:00
|
|
|
false
|
|
|
|
};
|
2015-09-15 14:54:55 +00:00
|
|
|
|
2021-11-11 11:41:25 +00:00
|
|
|
private _items = _config call FUNC(getRepairItems);
|
2024-04-06 18:57:08 +00:00
|
|
|
if (_items isNotEqualTo [] && {!([_caller, _items] call FUNC(hasItems))}) exitWith {false};
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _return = true;
|
2015-07-03 21:14:23 +00:00
|
|
|
if (getText (_config >> "condition") != "") then {
|
2017-10-10 14:39:59 +00:00
|
|
|
private _condition = getText (_config >> "condition");
|
2020-02-12 21:07:19 +00:00
|
|
|
if (isNil _condition) then {
|
2015-07-03 21:14:23 +00:00
|
|
|
_condition = compile _condition;
|
|
|
|
} else {
|
2015-08-16 14:45:46 +00:00
|
|
|
_condition = missionNamespace getVariable _condition;
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
2015-11-20 17:40:31 +00:00
|
|
|
if (_condition isEqualType false) then {
|
2015-07-03 21:14:23 +00:00
|
|
|
_return = _condition;
|
|
|
|
} else {
|
|
|
|
_return = [_caller, _target, _hitPoint, _className] call _condition;
|
|
|
|
};
|
|
|
|
};
|
2015-11-10 02:11:48 +00:00
|
|
|
if (!_return) exitWith {false};
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
// private _vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then {
|
2015-09-26 04:36:35 +00:00
|
|
|
// missionNamespace getVariable [getText(_config >> "vehicleStateCondition"), 0]
|
|
|
|
// } else {
|
|
|
|
// getNumber(_config >> "vehicleStateCondition")
|
|
|
|
// };
|
2015-11-10 02:11:48 +00:00
|
|
|
// if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitWith {false};
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
private _repairLocations = getArray (_config >> "repairLocations");
|
2024-06-18 14:08:03 +00:00
|
|
|
if !("All" in _repairLocations) then {
|
2015-11-10 02:11:48 +00:00
|
|
|
private _repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))};
|
|
|
|
private _repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))};
|
2015-09-26 04:36:35 +00:00
|
|
|
{
|
2015-11-10 02:11:48 +00:00
|
|
|
if (_x == "field") exitWith {_return = true;};
|
|
|
|
if (_x == "RepairFacility" && _repairFacility) exitWith {_return = true;};
|
|
|
|
if (_x == "RepairVehicle" && _repairVeh) exitWith {_return = true;};
|
2020-02-12 21:07:19 +00:00
|
|
|
if (!isNil _x) exitWith {
|
2015-11-10 02:11:48 +00:00
|
|
|
private _val = missionNamespace getVariable _x;
|
2015-11-28 03:23:27 +00:00
|
|
|
if (_val isEqualType 0) then {
|
2015-09-26 04:36:35 +00:00
|
|
|
_return = switch (_val) do {
|
|
|
|
case 0: {true}; //useAnywhere
|
|
|
|
case 1: {call _repairVeh}; //repairVehicleOnly
|
|
|
|
case 2: {call _repairFacility}; //repairFacilityOnly
|
|
|
|
case 3: {(call _repairFacility) || {call _repairVeh}}; //vehicleAndFacility
|
|
|
|
default {false}; //Disabled
|
|
|
|
};
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
} forEach _repairLocations;
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
private _requiredObjects = getArray (_config >> "claimObjects");
|
|
|
|
private _claimObjectsAvailable = [];
|
2021-02-27 17:05:05 +00:00
|
|
|
if (_requiredObjects isNotEqualTo []) then {
|
2023-11-21 01:43:43 +00:00
|
|
|
_claimObjectsAvailable = [_caller, 5, _requiredObjects, true] call FUNC(getClaimObjects);
|
2015-09-26 04:36:35 +00:00
|
|
|
if (_claimObjectsAvailable isEqualTo []) then {
|
|
|
|
TRACE_2("Missing Required Objects",_requiredObjects,_claimObjectsAvailable);
|
|
|
|
_return = false
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
};
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
if !(_return && alive _target) exitWith {false};
|
2015-09-26 04:36:35 +00:00
|
|
|
//Last exitWith: repair_success or repair_failure will be run
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
//Claim required objects
|
2015-07-03 21:14:23 +00:00
|
|
|
{
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_2("Claiming",_x,(typeOf _x));
|
2015-09-26 04:36:35 +00:00
|
|
|
[_caller, _x, false] call EFUNC(common,claim);
|
|
|
|
} forEach _claimObjectsAvailable;
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _consumeItems = if (isNumber (_config >> "itemConsumed")) then {
|
2015-07-03 21:14:23 +00:00
|
|
|
getNumber (_config >> "itemConsumed");
|
|
|
|
} else {
|
|
|
|
// Check for required class
|
2015-11-10 02:11:48 +00:00
|
|
|
if (isText (_config >> "itemConsumed")) exitWith {
|
2015-08-16 14:45:46 +00:00
|
|
|
missionNamespace getVariable [(getText (_config >> "itemConsumed")), 0];
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
0;
|
|
|
|
};
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _usersOfItems = [];
|
2015-07-03 21:14:23 +00:00
|
|
|
if (_consumeItems > 0) then {
|
2015-12-09 02:31:40 +00:00
|
|
|
_usersOfItems = ([_caller, _items] call FUNC(useItems)) select 1;
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Parse the config for the progress callback
|
2017-10-10 14:39:59 +00:00
|
|
|
private _callbackProgress = getText (_config >> "callbackProgress");
|
2015-07-03 21:14:23 +00:00
|
|
|
if (_callbackProgress == "") then {
|
2019-02-23 00:54:25 +00:00
|
|
|
_callbackProgress = {
|
2021-10-10 16:50:10 +00:00
|
|
|
(_this select 0) params ["_caller", "_target", "", "", "", "", "_claimObjectsAvailable"];
|
|
|
|
(
|
2021-10-30 21:42:03 +00:00
|
|
|
(alive _target) &&
|
2021-10-10 16:50:10 +00:00
|
|
|
{(abs speed _target) < 1} && // make sure vehicle doesn't drive off
|
|
|
|
{_claimObjectsAvailable findIf {!alive _x || {_x getVariable [QEGVAR(common,owner), objNull] isNotEqualTo _caller}} == -1} // make sure claim objects are still available
|
|
|
|
)
|
2019-02-23 00:54:25 +00:00
|
|
|
};
|
2015-07-03 21:14:23 +00:00
|
|
|
} else {
|
2020-02-12 21:07:19 +00:00
|
|
|
if (isNil _callbackProgress) then {
|
2019-02-23 00:54:25 +00:00
|
|
|
_callbackProgress = compile _callbackProgress;
|
|
|
|
} else {
|
|
|
|
_callbackProgress = missionNamespace getVariable _callbackProgress;
|
|
|
|
};
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Player Animation
|
2017-10-10 14:39:59 +00:00
|
|
|
private _callerAnim = [getText (_config >> "animationCaller"), getText (_config >> "animationCallerProne")] select (stance _caller == "PRONE");
|
2023-07-06 03:52:04 +00:00
|
|
|
private _loopAnim = (getNumber (_config >> "loopAnimation")) isEqualTo 1;
|
2024-07-20 06:13:42 +00:00
|
|
|
|
|
|
|
private _currentWeapon = currentWeapon _caller;
|
|
|
|
|
|
|
|
if (_currentWeapon != "") then {
|
|
|
|
_caller setVariable [QGVAR(selectedWeaponOnrepair), (weaponState _caller) select [0, 3]];
|
|
|
|
};
|
2015-07-03 21:14:23 +00:00
|
|
|
|
|
|
|
// Cannot use secondairy weapon for animation
|
2024-07-20 06:13:42 +00:00
|
|
|
if (_currentWeapon == secondaryWeapon _caller) then {
|
2015-07-03 21:14:23 +00:00
|
|
|
_caller selectWeapon (primaryWeapon _caller);
|
|
|
|
};
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _wpn = ["non", "rfl", "pst"] select (1 + ([primaryWeapon _caller, handgunWeapon _caller] find (currentWeapon _caller)));
|
2015-07-03 21:14:23 +00:00
|
|
|
_callerAnim = [_callerAnim, "[wpn]", _wpn] call CBA_fnc_replace;
|
|
|
|
if (vehicle _caller == _caller && {_callerAnim != ""}) then {
|
|
|
|
if (primaryWeapon _caller == "") then {
|
|
|
|
_caller addWeapon "ACE_FakePrimaryWeapon";
|
|
|
|
};
|
|
|
|
if (currentWeapon _caller == "") then {
|
|
|
|
_caller selectWeapon (primaryWeapon _caller); // unit always has a primary weapon here
|
|
|
|
};
|
|
|
|
|
2017-10-01 18:38:11 +00:00
|
|
|
if !(_caller call EFUNC(common,isSwimming)) then {
|
2017-08-22 18:30:56 +00:00
|
|
|
if (stance _caller == "STAND") then {
|
|
|
|
_caller setVariable [QGVAR(repairPrevAnimCaller), "amovpknlmstpsraswrfldnon"];
|
|
|
|
} else {
|
|
|
|
_caller setVariable [QGVAR(repairPrevAnimCaller), animationState _caller];
|
|
|
|
};
|
2024-03-07 21:08:13 +00:00
|
|
|
_caller setVariable [QGVAR(repairCurrentAnimCaller), toLowerANSI _callerAnim];
|
2017-08-22 18:30:56 +00:00
|
|
|
[_caller, _callerAnim] call EFUNC(common,doAnimation);
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-06 03:52:04 +00:00
|
|
|
if (_loopAnim) then {
|
|
|
|
private _animDoneEh = _caller addEventHandler ["AnimDone", {
|
|
|
|
params ["_caller", "_anim"];
|
|
|
|
if (_anim isEqualTo (_caller getVariable [QGVAR(repairCurrentAnimCaller), ""])) then {
|
|
|
|
[{
|
|
|
|
params ["_caller", "_anim"];
|
|
|
|
if !(isNil {_caller getVariable QGVAR(repairCurrentAnimCaller)}) then {
|
|
|
|
TRACE_2("loop",_caller,_anim);
|
|
|
|
_this call EFUNC(common,doAnimation)
|
|
|
|
};
|
|
|
|
}, [_caller, _anim], 2.5] call CBA_fnc_waitAndExecute;
|
|
|
|
};
|
|
|
|
}];
|
|
|
|
_caller setVariable [QGVAR(repairLoopAnimEh), _animDoneEh];
|
|
|
|
};
|
|
|
|
|
2021-10-10 13:37:05 +00:00
|
|
|
private _soundPosition = _caller modelToWorldVisualWorld (_caller selectionPosition "RightHand");
|
2017-11-29 19:36:48 +00:00
|
|
|
["Acts_carFixingWheel", _soundPosition, nil, 50] call EFUNC(common,playConfigSound3D);
|
|
|
|
|
2017-06-08 18:31:25 +00:00
|
|
|
// Get repair time
|
2017-10-10 14:39:59 +00:00
|
|
|
private _repairTime = [
|
2021-02-18 18:58:08 +00:00
|
|
|
configOf _target >> QGVAR(repairTimes) >> configName _config,
|
2017-06-08 18:31:25 +00:00
|
|
|
"number",
|
|
|
|
-1
|
|
|
|
] call CBA_fnc_getConfigEntry;
|
|
|
|
|
|
|
|
if (_repairTime < 0) then {
|
|
|
|
_repairTime = if (isNumber (_config >> "repairingTime")) then {
|
|
|
|
getNumber (_config >> "repairingTime");
|
|
|
|
} else {
|
|
|
|
if (isText (_config >> "repairingTime")) exitWith {
|
2017-10-10 14:39:59 +00:00
|
|
|
private _repairTimeConfig = getText (_config >> "repairingTime");
|
2020-02-12 21:07:19 +00:00
|
|
|
if (isNil _repairTimeConfig) then {
|
2017-06-08 18:31:25 +00:00
|
|
|
_repairTimeConfig = compile _repairTimeConfig;
|
|
|
|
} else {
|
|
|
|
_repairTimeConfig = missionNamespace getVariable _repairTimeConfig;
|
|
|
|
};
|
|
|
|
if (_repairTimeConfig isEqualType 0) exitWith {
|
|
|
|
_repairTimeConfig;
|
|
|
|
};
|
|
|
|
[_caller, _target, _hitPoint, _className] call _repairTimeConfig;
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
2017-06-08 18:31:25 +00:00
|
|
|
0;
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-08-24 18:58:54 +00:00
|
|
|
// Find localized string
|
2017-10-10 14:39:59 +00:00
|
|
|
private _hitPointClassname = if (_hitPoint isEqualType "") then {
|
2015-09-26 04:36:35 +00:00
|
|
|
_hitPoint
|
|
|
|
} else {
|
|
|
|
((getAllHitPointsDamage _target) select 0) select _hitPoint
|
|
|
|
};
|
2016-09-04 14:44:22 +00:00
|
|
|
private _processText = getText (_config >> "displayNameProgress");
|
2015-11-10 02:11:48 +00:00
|
|
|
private _backupText = format [localize LSTRING(RepairingHitPoint), _hitPointClassname];
|
2023-07-06 03:52:04 +00:00
|
|
|
private _text = _processText;
|
|
|
|
if (getNumber (_config >> "forceDisplayName") isNotEqualTo 1) then {
|
|
|
|
_text = ([_hitPointClassname, _processText, _backupText] call FUNC(getHitPointString)) select 0;
|
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
|
|
|
|
TRACE_4("display",_hitPoint,_hitPointClassname,_processText,_text);
|
2015-08-24 03:24:25 +00:00
|
|
|
|
2015-07-03 21:14:23 +00:00
|
|
|
// Start repair
|
|
|
|
[
|
|
|
|
_repairTime,
|
2015-09-26 04:36:35 +00:00
|
|
|
[_caller, _target, _hitPoint, _className, _items, _usersOfItems, _claimObjectsAvailable],
|
2015-07-03 21:14:23 +00:00
|
|
|
DFUNC(repair_success),
|
|
|
|
DFUNC(repair_failure),
|
2015-08-09 13:53:52 +00:00
|
|
|
_text,
|
2015-07-03 21:14:23 +00:00
|
|
|
_callbackProgress,
|
2017-08-22 18:30:56 +00:00
|
|
|
["isNotSwimming", "isNotOnLadder"]
|
2015-07-03 21:14:23 +00:00
|
|
|
] call EFUNC(common,progressBar);
|
|
|
|
|
|
|
|
// Display Icon
|
2017-10-10 14:39:59 +00:00
|
|
|
private _iconDisplayed = getText (_config >> "actionIconPath");
|
2015-07-03 21:14:23 +00:00
|
|
|
if (_iconDisplayed != "") then {
|
|
|
|
[QGVAR(repairActionIcon), true, _iconDisplayed, [1,1,1,1], getNumber(_config >> "actionIconDisplayTime")] call EFUNC(common,displayIcon);
|
|
|
|
};
|
|
|
|
|
|
|
|
// handle display of text/hints
|
2017-10-10 14:39:59 +00:00
|
|
|
private _displayText = "";
|
2015-07-03 21:14:23 +00:00
|
|
|
if (_target != _caller) then {
|
|
|
|
_displayText = getText(_config >> "displayTextOther");
|
|
|
|
} else {
|
|
|
|
_displayText = getText(_config >> "displayTextSelf");
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_displayText != "") then {
|
2016-06-04 10:12:56 +00:00
|
|
|
[QEGVAR(common,displayTextStructured), [[_displayText, [_caller] call EFUNC(common,getName), [_target] call EFUNC(common,getName)], 1.5, _caller], [_caller]] call CBA_fnc_targetEvent;
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
true;
|