Moved spare parts adding to init, Added module option to add spare parts or not, Added module to add specific spare part and amount of it to specific vehicle(s)

This commit is contained in:
jonpas 2015-08-18 23:41:25 +02:00
parent 42bd8751aa
commit 3bcebf9033
9 changed files with 223 additions and 13 deletions

View File

@ -61,4 +61,11 @@ class ACE_Settings {
values[] = {CSTRING(engineerSetting_anyone), CSTRING(engineerSetting_EngineerOnly), CSTRING(engineerSetting_RepairSpecialistOnly)};
category = CSTRING(categoryName);
};
class GVAR(addSpareParts) {
displayName = CSTRING(addSpareParts_name);
description = CSTRING(addSpareParts_description);
typeName = "BOOL";
value = 1;
category = CSTRING(categoryName);
};
};

View File

@ -13,31 +13,31 @@ class Extended_PostInit_EventHandlers {
class Extended_Init_EventHandlers {
class Car {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts));
};
};
class Tank {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts));
};
};
class Helicopter {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts));
};
};
class Plane {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts));
};
};
class Ship_F {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts));
};
};
class ACE_RepairItem_Base {

View File

@ -91,6 +91,12 @@ class CfgVehicles {
class Special { name = CSTRING(engineerSetting_RepairSpecialistOnly); value = 2; default = 1;};
};
};
class addSpareParts {
displayName = CSTRING(addSpareParts_name);
description = CSTRING(addSpareParts_description);
typeName = "BOOL";
defaultValue = 1;
};
};
class ModuleDescription {
description = CSTRING(moduleDescription);
@ -215,19 +221,57 @@ class CfgVehicles {
sync[] = {};
};
};
class ACE_moduleAddSpareParts: Module_F {
scope = 2;
displayName = CSTRING(AddSpareParts_Module_DisplayName);
icon = QUOTE(PATHTOF(ui\Icon_Module_Repair_ca.paa));
category = "ACE";
function = QFUNC(moduleAddSpareParts);
functionPriority = 10;
isGlobal = 0;
isTriggerActivated = 0;
isDisposable = 0;
author = ECSTRING(common,ACETeam);
class Arguments {
class List {
displayName = CSTRING(AddSpareParts_List_DisplayName);
description = CSTRING(AddSpareParts_List_Description);
defaultValue = "";
typeName = "STRING";
};
class Part {
displayName = CSTRING(AddSpareParts_Part_DisplayName);
description = CSTRING(AddSpareParts_Part_Description);
typeName = "STRING";
class values {
class Wheel {
name = CSTRING(SpareWheel);
value = "ACE_Wheel";
default = 1;
};
class Track {
name = CSTRING(SpareTrack);
value = "ACE_Track";
};
};
};
class Amount {
displayName = CSTRING(AddSpareParts_Amount_DisplayName);
description = CSTRING(AddSpareParts_Amount_Description);
typeName = "NUMBER";
defaultValue = 1;
};
};
class ModuleDescription {
description = CSTRING(AddSpareParts_Module_Description);
sync[] = {};
};
};
class LandVehicle;
class Car: LandVehicle {
MACRO_REPAIRVEHICLE
class ACE_Cargo {
class Cargo {
class ACE_Wheel {
type = "ACE_Wheel";
amount = 1;
};
};
};
};
class Tank: LandVehicle {

View File

@ -5,3 +5,17 @@
// wheels
["setWheelHitPointDamage", {(_this select 0) setHitPointDamage [_this select 1, _this select 2]}] call EFUNC(common,addEventHandler);
if (isServer) then {
["SettingsInitialized", {
GVAR(settingInitted) = true; // Stop collecting in FUNC(addSpareParts)
// Exit if adding spare parts disabled
if (!GVAR(addSpareParts)) exitWith {GVAR(addSparePartsCollection) = nil};
// Add spare parts to vehicles in collection
{
[_x] call FUNC(addSpareParts);
} forEach GVAR(addSparePartsCollection);
}] call EFUNC(common,addEventHandler);
};

View File

@ -3,6 +3,7 @@
ADDON = false;
PREP(addRepairActions);
PREP(addSpareParts);
PREP(canRemove);
PREP(canRepair);
PREP(canRepairTrack);
@ -22,6 +23,7 @@ PREP(isEngineer);
PREP(isInRepairFacility);
PREP(isNearRepairVehicle);
PREP(isRepairVehicle);
PREP(moduleAddSpareParts);
PREP(moduleAssignEngineer);
PREP(moduleAssignRepairVehicle);
PREP(moduleAssignRepairFacility);
@ -36,4 +38,6 @@ PREP(spawnObject);
PREP(useItem);
PREP(useItems);
GVAR(addSparePartsCollection) = [];
ADDON = true;

View File

@ -0,0 +1,46 @@
/*
* Author: Jonpas
* Adds spare parts to the vehicle. Before SettingsInitialized only collect for later execution.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Amount <NUMBER> (default: 1)
* 2: Spare Part Classname <STRING> (default: "")
* 3: Force (add even if setting is disabled) <BOOL> (default: false)
*
* Return Value:
* None
*
* Example:
* _added = [vehicle] call ace_repair_fnc_addSpareParts
*
* Public: No
*/
#include "script_component.hpp"
private ["_part"];
params ["_vehicle", ["_amount", 1], ["_part", ""], ["_force", false]];
TRACE_2("params",_vehicle,_amount);
// Exit if ace_cargo is not loaded
if !(["ace_cargo"] call EFUNC(common,isModLoaded)) exitWith {};
// Collect until SettingsInitialized
if (isNil QGVAR(settingInitted)) exitWith {
GVAR(addSparePartsCollection) pushBack _vehicle;
};
// Exit if not forced and add spare parts is disabled (after settings initted to make sure it really is)
if (!_force && !GVAR(addSpareParts)) exitWith {};
// Select appropriate part
if (_part == "") then {
if (_vehicle isKindOf "Car") then { _part = "ACE_Wheel" };
if (_vehicle isKindOf "Tank") then { _part = "ACE_Track" };
};
// Exit if no appropriate part
if (_part == "") exitWith {};
// Load
//["LoadItem", [_part, _vehicle]] call EFUNC(cargo,loadItem);
[_part, _vehicle, _amount] call EFUNC(cargo,addItem); // Change to above event

View File

@ -0,0 +1,61 @@
/*
* Author: Jonpas
* Adds spare parts to a vehicle.
*
* Arguments:
* 0: The module logic <OBJECT>
* 1: Synchronized units <ARRAY>
* 2: Activated <BOOL>
*
* Return Value:
* None
*
* Example:
* function = "ace_repair_fnc_moduleAssignRepairVehicle"
*
* Public: No
*/
#define DEBUG_MODE_FULL
#include "script_component.hpp"
params ["_logic"];
if (!isNull _logic) then {
private ["_list", "_part", "_amount", "_nilCheckPassedList"];
// Module settings
_list = _logic getVariable ["List", ""];
_part = _logic getVariable ["Part", 0];
_amount = _logic getVariable ["Amount", 1];
// Parse list
_nilCheckPassedList = "";
{
_x = [_x] call EFUNC(common,stringRemoveWhiteSpace);
if !(isnil _x) then {
if (_nilCheckPassedList == "") then {
_nilCheckPassedList = _x;
} else {
_nilCheckPassedList = _nilCheckPassedList + "," + _x;
};
};
} forEach ([_list, ","] call BIS_fnc_splitString);
_list = "[" + _nilCheckPassedList + "]";
_list = [] call compile _list;
// Add synchronized objects to list
{
_list pushBack _x;
} forEach (synchronizedObjects _logic);
if (_list isEqualTo []) exitWith {};
TRACE_3("module info parsed",_list,_part,_amount);
// Add spare parts
{
if (!isNil "_x" && {typeName _x == typeName objNull}) then {
[_x, _amount, _part, true] call FUNC(addSpareParts);
};
} forEach _list;
};
true

View File

@ -31,4 +31,6 @@ if (!isServer) exitWith {};
[_logic, QGVAR(fullRepairLocation), "fullRepairLocation"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(engineerSetting_fullRepair), "engineerSetting_fullRepair"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(addSpareParts), "addSpareParts"] call EFUNC(common,readSettingFromModule);
diag_log text "[ACE]: Repair Module Initialized.";

View File

@ -104,6 +104,12 @@
<Key ID="STR_ACE_Repair_engineerSetting_fullRepair_description">
<English>Who can perform a full repair on a vehicle?</English>
</Key>
<Key ID="STR_ACE_Repair_addSpareParts_name">
<English>Add Spare Parts</English>
</Key>
<Key ID="STR_ACE_Repair_addSpareParts_description">
<English>Add spare parts to vehicles (requires Cargo component)?</English>
</Key>
<Key ID="STR_ACE_Repair_RepairHitpoint">
<English>Repair %1</English>
<German>Reparieren %1</German>
@ -635,6 +641,32 @@
<Key ID="STR_ACE_Repair_AssignRepairFacility_Module_Description">
<English>Assign one or multiple objects as a repair Facility</English>
</Key>
<Key ID="STR_ACE_Repair_AddSpareParts_Module_DisplayName">
<English>Add Spare Parts</English>
</Key>
<Key ID="STR_ACE_Repair_AddSpareParts_Module_Description">
<English>Add spare parts to one or multiple objects</English>
</Key>
<Key ID="STR_ACE_Repair_AddSpareParts_List_DisplayName">
<English>List</English>
</Key>
<Key ID="STR_ACE_Repair_AddSpareParts_List_Description">
<English>List of objects that will get spare parts added, separated by commas.</English>
</Key>
<Key ID="STR_ACE_Repair_AddSpareParts_Part_DisplayName">
<English>Part</English>
</Key>
<Key ID="STR_ACE_Repair_AddSpareParts_Part_Description">
<English>Spare part.</English>
</Key>
<Key ID="STR_ACE_Repair_AddSpareParts_Amount_DisplayName">
<English>Amount</English>
</Key>
<Key ID="STR_ACE_Repair_AddSpareParts_Amount_Description">
<English>Number of selected spare parts.</English>
</Key>
<Key ID="STR_ACE_Repair_categoryName">
<English>Vehicle Repair</English>
</Key>