Implemented repair action framework

copied across treatment framework from medical and adjusted it to suit the repair actions
This commit is contained in:
Glowbal 2015-07-03 23:14:23 +02:00
parent 0bf56d64bd
commit 071a673f28
14 changed files with 611 additions and 18 deletions

View File

@ -0,0 +1,32 @@
class ACE_Repair {
class Actions {
class ReplaceWheel {
displayName = CSTRING(Wheel);
displayNameProgress = CSTRING(ReplacingWheel);
locations[] = {"All"};
requiredEngineer = 0;
repairingTime = 5;
repairingTimeSelfCoef = 1;
items[] = {};
condition = "";
itemConsumed = 0;
callbackSuccess = QUOTE(DFUNC(repairBasic_bandage));
callbackFailure = "";
callbackProgress = "";
animationCaller = "AinvPknlMstpSlayWrflDnon_medicOther";
animationCallerProne = "AinvPpneMstpSlayW[wpn]Dnon_medicOther";
animationCallerSelf = "AinvPknlMstpSlayW[wpn]Dnon_medic";
animationCallerSelfProne = "AinvPpneMstpSlayW[wpn]Dnon_medic";
litter[] = {};
};
class Tracks: Wheel {
};
class MiscRepair: Wheel {
};
};
};

View File

@ -35,7 +35,7 @@ class CfgVehicles {
typeName = "NUMBER";
class values {
class anyone { name = "Anyone"; value = 0; };
class Medic { name = "Engineers only"; value = 1; default = 1; };
class Engineer { name = "Engineers only"; value = 1; default = 1; };
class Special { name = "Repair Specialists only"; value = 2; };
};
};
@ -45,7 +45,7 @@ class CfgVehicles {
typeName = "NUMBER";
class values {
class anyone { name = "Anyone"; value = 0; default = 1; };
class Medic { name = "Engineers only"; value = 1; };
class Engineer { name = "Engineers only"; value = 1; };
class Special { name = "Repair Specialists only"; value = 2; };
};
};
@ -174,7 +174,7 @@ class CfgVehicles {
transportRepair = 0;
};
class Truck_02_medical_base_F: Truck_02_box_base_F {
class Truck_02_engineeral_base_F: Truck_02_box_base_F {
GVAR(canRepair) = 0;
};

View File

@ -11,14 +11,23 @@ PREP(doRepair);
PREP(doReplaceWheel);
PREP(getPostRepairDamage);
PREP(getWheelHitPointsWithSelections);
PREP(hasItems);
PREP(isEngineer);
PREP(isInRepairFacility);
PREP(isNearRepairVehicle);
PREP(isRepairVehicle);
PREP(moduleRepairSettings);
PREP(normalizeHitPoints);
PREP(removeWheel);
PREP(repair);
PREP(repairVehicle);
PREP(repair_failure);
PREP(repair_success);
PREP(replaceWheel);
PREP(setDamage);
PREP(setHitPointDamage);
PREP(spawnObject);
PREP(useItem);
PREP(useItems);
ADDON = true;

View File

@ -1,26 +1,91 @@
/*
* Author: commy2
*
* Check if the unit can repair given hitpoint of the vehicle.
* Author: Glowbal
* Check if the repair action can be performed.
*
* Arguments:
* 0: Unit that does the repairing (Object)
* 1: vehicle to repair (Object)
* 2: Selected hitpoint (String)
* 0: The caller <OBJECT>
* 1: The target <OBJECT>
* 2: Selection name <STRING>
* 3: ACE_Engineeral_Treatments Classname <STRING>
*
* Return Value:
* NONE
* ReturnValue:
* Can Treat <BOOL>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_unit", "_target", "_hitPoint"];
_unit = _this select 0;
private ["_caller", "_target", "_hitPoint", "_className", "_config", "_engineerRequired", "_items", "_locations", "_return", "_condition", "_vehicleStateCondition"];
_caller = _this select 0;
_target = _this select 1;
_hitPoint = _this select 2;
_className = _this select 3;
if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false};
_config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className);
if !(isClass _config) exitwith {false}; // or go for a default?
if !([_unit, GVAR(engineerSetting_Repair)] call FUNC(isEngineer)) exitWith {false};
_engineerRequired = if (isNumber (_config >> "requiredEngineer")) then {
getNumber (_config >> "requiredEngineer");
} else {
// Check for required class
if (isText (_config >> "requiredEngineer")) exitwith {
missionNamespace getvariable [(getText (_config >> "requiredEngineer")), 0];
};
0;
};
if !([_caller, _engineerRequired] call FUNC(isEngineer)) exitwith {false};
alive _target && {_target getHitPointDamage _hitPoint > ([_unit] call FUNC(getPostRepairDamage))}
_items = getArray (_config >> "items");
if (count _items > 0 && {!([_caller, _items] call FUNC(hasItems))}) exitwith {false};
_return = true;
if (getText (_config >> "condition") != "") then {
_condition = getText (_config >> "condition");
if (isnil _condition) then {
_condition = compile _condition;
} else {
_condition = missionNamespace getvariable _condition;
};
if (typeName _condition == "BOOL") then {
_return = _condition;
} else {
_return = [_caller, _target, _hitPoint, _className] call _condition;
};
};
if (!_return) exitwith {false};
_vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then {
missionNamespace getvariable [getText(_config >> "vehicleStateCondition"), 0]
} else {
getNumber(_config >> "vehicleStateCondition")
};
// if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitwith {false};
_locations = getArray (_config >> "repairLocations");
if ("All" in _locations) exitwith {true};
private ["_repairFacility", "_repairVeh"];
_repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))};
_repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))};
{
if (_x == "field") exitwith {_return = true;};
if (_x == "RepairFacility" && _repairFacility) exitwith {_return = true;};
if (_x == "RepairVehicle" && _repairVeh) exitwith {_return = true;};
if !(isnil _x) exitwith {
private "_val";
_val = missionNamespace getvariable _x;
if (typeName _val == "SCALAR") then {
_return = switch (_val) do {
case 0: {true};
case 1: _repairVeh;
case 2: _repairFacility;
case 3: {call _repairFacility || call _repairVeh};
};
_return = call _return;
};
};
}foreach _locations;
_return && alive _target && {_target getHitPointDamage _hitPoint > ([_unit] call FUNC(getPostRepairDamage))}

View File

@ -0,0 +1,32 @@
/*
* Author: Glowbal
* Check if the engineer has all items.
*
* Arguments:
* 0: Engineer <OBJECT>
* 1: Patient <OBJECT>
* 2: Items <ARRAY<STRING>>
*
* ReturnValue:
* Has the items <BOOL>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_engineer", "_items", "_return"];
_engineer = _this select 0;
_items = _this select 1;
_return = true;
{
if (typeName _x == "ARRAY" && {({[_engineer, _x] call EFUNC(common,hasItem)}count _x == 0)}) exitwith {
_return = false;
};
if (typeName _x == "STRING" && {!([_engineer, _x] call EFUNC(common,hasItem))}) exitwith {
_return = false;
};
}foreach _items;
_return;

View File

@ -7,7 +7,7 @@
* 1: Class <NUMBER> <OPTIONAL>
*
* ReturnValue:
* Is in of medic class <BOOL>
* Is in of engineer class <BOOL>
*
* Public: Yes
*/

View File

@ -0,0 +1,37 @@
/*
* Author: Glowbal
* Checks if a unit is in a designated engineeral facility
*
* Arguments:
* 0: The Unit <OBJECT>
*
* ReturnValue:
* Is in engineeral facility <BOOL>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_object","_position","_objects","_isInBuilding","_repairFacility"];
_object = _this select 0;
_position = getPosASL _object;
_isInBuilding = false;
_repairFacility = [];
_objects = (lineIntersectsWith [_object modelToWorldVisual [0, 0, (_position select 2)], _object modelToWorldVisual [0, 0, (_position select 2) +10], _object]);
{
if (((typeOf _x) in _repairFacility) || (_x getVariable [QGVAR(isRepairFacility),false])) exitwith {
_isInBuilding = true;
};
}foreach _objects;
if (!_isInBuilding) then {
_objects = position _object nearObjects 7.5;
{
if (((typeOf _x) in _repairFacility) || (_x getVariable [QGVAR(isRepairFacility),false])) exitwith {
_isInBuilding = true;
};
}foreach _objects;
};
_isInBuilding;

View File

@ -0,0 +1,26 @@
/*
* Author: KoffeinFlummi
* Checks if a unit is in a engineeral vehicle.
*
* Arguments:
* 0: unit to be checked <OBJECT>
*
* Return Value:
* Is unit in engineeral vehicle? <BOOL>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_unit", "_vehicle"];
_unit = _this select 0;
_nearObjects = nearestObjects [_unit, ["Air","LandVehicle"], 20];
_return = false;
{
if ([_x] call FUNC(isRepairVehicle)) exitwith {_return = true;};
}foreach _nearObjects;
_return;

View File

@ -0,0 +1,20 @@
/*
* Author: Glowbal
* Check if vehicle is a engineeral vehicle
*
* Arguments:
* 0: The Vehicle <OBJECT>
*
* ReturnValue:
* Is in of engineer class <BOOL>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_vehicle"];
_vehicle = _this select 0;
if (_vehicle isKindOf "CAManBase") exitwith {false};
((_vehicle getVariable [QGVAR(engineerClass), getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "engineer")]) > 0);

View File

@ -0,0 +1,195 @@
/*
* Author: Glowbal, KoffeinFlummi
* Starts the repair process
*
* Arguments:
* 0: The engineer <OBJECT>
* 1: The patient <OBJECT>
* 2: SelectionName <STRING>
* 3: repair classname <STRING>
*
* Return Value:
* Succesful repair started <BOOL>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_caller", "_target", "_hitPoint", "_className", "_config", "_engineerRequired", "_items", "_locations", "_return", "_condition", "_vehicleStateCondition"];
_caller = _this select 0;
_target = _this select 1;
_hitPoint = _this select 2;
_className = _this select 3;
_config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className);
if !(isClass _config) exitwith {false}; // or go for a default?
_engineerRequired = if (isNumber (_config >> "requiredEngineer")) then {
getNumber (_config >> "requiredEngineer");
} else {
// Check for required class
if (isText (_config >> "requiredEngineer")) exitwith {
missionNamespace getvariable [(getText (_config >> "requiredEngineer")), 0];
};
0;
};
if !([_caller, _engineerRequired] call FUNC(isEngineer)) exitwith {false};
_items = getArray (_config >> "items");
if (count _items > 0 && {!([_caller, _items] call FUNC(hasItems))}) exitwith {false};
_return = true;
if (getText (_config >> "condition") != "") then {
_condition = getText (_config >> "condition");
if (isnil _condition) then {
_condition = compile _condition;
} else {
_condition = missionNamespace getvariable _condition;
};
if (typeName _condition == "BOOL") then {
_return = _condition;
} else {
_return = [_caller, _target, _hitPoint, _className] call _condition;
};
};
if (!_return) exitwith {false};
_vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then {
missionNamespace getvariable [getText(_config >> "vehicleStateCondition"), 0]
} else {
getNumber(_config >> "vehicleStateCondition")
};
// if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitwith {false};
_locations = getArray (_config >> "repairLocations");
if ("All" in _locations) exitwith {true};
private ["_repairFacility", "_repairVeh"];
_repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))};
_repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))};
{
if (_x == "field") exitwith {_return = true;};
if (_x == "RepairFacility" && _repairFacility) exitwith {_return = true;};
if (_x == "RepairVehicle" && _repairVeh) exitwith {_return = true;};
if !(isnil _x) exitwith {
private "_val";
_val = missionNamespace getvariable _x;
if (typeName _val == "SCALAR") then {
_return = switch (_val) do {
case 0: {true};
case 1: _repairVeh;
case 2: _repairFacility;
case 3: {call _repairFacility || call _repairVeh};
};
_return = call _return;
};
};
}foreach _locations;
if !(_return && alive _target && {_target getHitPointDamage _hitPoint > ([_unit] call FUNC(getPostRepairDamage))}) exitwith {false};
_consumeItems = if (isNumber (_config >> "itemConsumed")) then {
getNumber (_config >> "itemConsumed");
} else {
// Check for required class
if (isText (_config >> "itemConsumed")) exitwith {
missionNamespace getvariable [(getText (_config >> "itemConsumed")), 0];
};
0;
};
_usersOfItems = [];
if (_consumeItems > 0) then {
_usersOfItems = ([_caller, _target, _items] call FUNC(useItems)) select 1;
};
// Parse the config for the progress callback
_callbackProgress = getText (_config >> "callbackProgress");
if (_callbackProgress == "") then {
_callbackProgress = "true";
};
if (isNil _callbackProgress) then {
_callbackProgress = compile _callbackProgress;
} else {
_callbackProgress = missionNamespace getvariable _callbackProgress;
};
// Player Animation
_callerAnim = [getText (_config >> "animationCaller"), getText (_config >> "animationCallerProne")] select (stance _caller == "PRONE");
_caller setvariable [QGVAR(selectedWeaponOnrepair), currentWeapon _caller];
// Cannot use secondairy weapon for animation
if (currentWeapon _caller == secondaryWeapon _caller) then {
_caller selectWeapon (primaryWeapon _caller);
};
_wpn = ["non", "rfl", "pst"] select (1 + ([primaryWeapon _caller, handgunWeapon _caller] find (currentWeapon _caller)));
_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
};
if (stance _caller == "STAND") then {
_caller setvariable [QGVAR(repairPrevAnimCaller), "amovpknlmstpsraswrfldnon"];
} else {
_caller setvariable [QGVAR(repairPrevAnimCaller), animationState _caller];
};
[_caller, _callerAnim] call EFUNC(common,doAnimation);
};
//Get repair time
_repairTime = if (isNumber (_config >> "repairTime")) then {
getNumber (_config >> "repairTime");
} else {
if (isText (_config >> "repairTime")) exitwith {
_repairTimeConfig = getText(_config >> "repairTime");
if (isnil _repairTimeConfig) then {
_repairTimeConfig = compile _repairTimeConfig;
} else {
_repairTimeConfig = missionNamespace getvariable _repairTimeConfig;
};
if (typeName _repairTimeConfig == "SCALAR") exitwith {
_repairTimeConfig;
};
[_caller, _target, _selectionName, _className] call _repairTimeConfig;
};
0;
};
// Start repair
[
_repairTime,
[_caller, _target, _selectionName, _className, _items, _usersOfItems],
DFUNC(repair_success),
DFUNC(repair_failure),
getText (_config >> "displayNameProgress"),
_callbackProgress,
[]
] call EFUNC(common,progressBar);
// Display Icon
_iconDisplayed = getText (_config >> "actionIconPath");
if (_iconDisplayed != "") then {
[QGVAR(repairActionIcon), true, _iconDisplayed, [1,1,1,1], getNumber(_config >> "actionIconDisplayTime")] call EFUNC(common,displayIcon);
};
// handle display of text/hints
_displayText = "";
if (_target != _caller) then {
_displayText = getText(_config >> "displayTextOther");
} else {
_displayText = getText(_config >> "displayTextSelf");
};
if (_displayText != "") then {
["displayTextStructured", [_caller], [[_displayText, [_caller] call EFUNC(common,getName), [_target] call EFUNC(common,getName)], 1.5, _caller]] call EFUNC(common,targetEvent);
};
true;

View File

@ -0,0 +1,60 @@
/*
* Author: KoffeinFlummi, Glowbal
* Callback when the repair fails
*
* Arguments:
* 0: The engineer <OBJECT>
* 1: The patient <OBJECT>
* 2: SelectionName <STRING>
* 3: Treatment classname <STRING>
* 4: Items available <ARRAY<STRING>>
*
* Return Value:
* nil
*
* Public: No
*/
#include "script_component.hpp"
private ["_args", "_caller", "_target","_selectionName","_className","_config","_callback", "_usersOfItems", "_weaponSelect"];
_args = _this select 0;
_caller = _args select 0;
_target = _args select 1;
_selectionName = _args select 2;
_className = _args select 3;
_usersOfItems = _args select 5;
if (primaryWeapon _caller == "ACE_FakePrimaryWeapon") then {
_caller removeWeapon "ACE_FakePrimaryWeapon";
};
if (vehicle _caller == _caller) then {
[_caller, _caller getvariable [QGVAR(repairPrevAnimCaller), ""], 1] call EFUNC(common,doAnimation);
};
_caller setvariable [QGVAR(repairPrevAnimCaller), nil];
_weaponSelect = (_caller getvariable [QGVAR(selectedWeaponOnTreatment), ""]);
if (_weaponSelect != "") then {
_caller selectWeapon _weaponSelect;
} else {
_caller action ["SwitchWeapon", _caller, _caller, 99];
};
{
(_x select 0) addItem (_x select 1);
}foreach _usersOfItems;
// Record specific callback
_config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className);
_callback = getText (_config >> "callbackFailure");
if (isNil _callback) then {
_callback = compile _callback;
} else {
_callback = missionNamespace getvariable _callback;
};
_args call _callback;
// _args call FUNC(createLitter);

View File

@ -0,0 +1,54 @@
/*
* Author: KoffeinFlummi, Glowbal
* Callback when the repair is completed
*
* Arguments:
* 0: The engineer <OBJECT>
* 1: The patient <OBJECT>
* 2: SelectionName <STRING>
* 3: Treatment classname <STRING>
* 4: Items available <ARRAY<STRING>>
*
* Return Value:
* nil
*
* Public: No
*/
#include "script_component.hpp"
private ["_args", "_caller", "_target","_selectionName","_className","_config","_callback", "_weaponSelect"];
_args = _this select 0;
_caller = _args select 0;
_target = _args select 1;
_selectionName = _args select 2;
_className = _args select 3;
if (primaryWeapon _caller == "ACE_FakePrimaryWeapon") then {
_caller removeWeapon "ACE_FakePrimaryWeapon";
};
if (vehicle _caller == _caller) then {
[_caller, _caller getvariable [QGVAR(repairPrevAnimCaller), ""], 1] call EFUNC(common,doAnimation);
};
_caller setvariable [QGVAR(repairPrevAnimCaller), nil];
_weaponSelect = (_caller getvariable [QGVAR(selectedWeaponOnTreatment), ""]);
if (_weaponSelect != "") then {
_caller selectWeapon _weaponSelect;
} else {
_caller action ["SwitchWeapon", _caller, _caller, 99];
};
// Record specific callback
_config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className);
_callback = getText (_config >> "callbackSuccess");
if (isNil _callback) then {
_callback = compile _callback;
} else {
_callback = missionNamespace getvariable _callback;
};
_args call _callback;
// _args call FUNC(createLitter);

View File

@ -0,0 +1,25 @@
/*
* Author: Glowbal
* Use Equipment if any is available.
*
* Arguments:
* 0: Engineer <OBJECT>
* 2: Item <STRING>
*
* ReturnValue:
* <NIL>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_engineer", "_item", "_return","_crew"];
_engineer = _this select 0;
_item = _this select 1;
if ([_engineer, _item] call EFUNC(common,hasItem)) exitwith {
[[_engineer, _item], QUOTE(EFUNC(common,useItem)), _engineer] call EFUNC(common,execRemoteFnc); /* TODO Replace by event system */
[true, _engineer];
};
[false, objNull];

View File

@ -0,0 +1,38 @@
/*
* Author: Glowbal
* Use Equipment items if any is available.
*
* Arguments:
* 0: Engineer <OBJECT>
* 2: Items <ARRAY<STRING>>
*
* ReturnValue:
* <NIL>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_engineer", "_patient", "_items", "_itemUsedInfo", "_itemsUsedBy"];
_engineer = _this select 0;
_items = _this select 1;
_itemsUsedBy = [];
{
// handle a one of type use item
if (typeName _x == "ARRAY") then {
{
_itemUsedInfo = [_engineer, _x] call FUNC(useItem);
if (_itemUsedInfo select 0) exitwith { _itemsUsedBy pushback [(_itemUsedInfo select 1), _x]};
}foreach _x;
};
// handle required item
if (typeName _x == "STRING") then {
_itemUsedInfo = [_engineer, _x] call FUNC(useItem);
if (_itemUsedInfo select 0) exitwith { _itemsUsedBy pushback [(_itemUsedInfo select 1), _x]};
};
}foreach _items;
[count _items == count _itemsUsedBy, _itemsUsedBy];