From 0c4924259dd348b4524e98cb44ac99dce99331d8 Mon Sep 17 00:00:00 2001 From: IngoKauffmann Date: Sat, 15 Aug 2015 18:43:13 +0200 Subject: [PATCH] Initial code --- addons/rearm/$PBOPREFIX$ | 1 + addons/rearm/ACE_Settings.hpp | 9 + addons/rearm/CfgAmmo.hpp | 196 ++++++++++++++++++ addons/rearm/CfgEventHandlers.hpp | 5 + addons/rearm/CfgVehicles.hpp | 125 +++++++++++ addons/rearm/XEH_preInit.sqf | 15 ++ addons/rearm/config.cpp | 18 ++ .../rearm/functions/fnc_addRearmActions.sqf | 65 ++++++ addons/rearm/functions/fnc_canPickUpAmmo.sqf | 21 ++ addons/rearm/functions/fnc_canRearm.sqf | 81 ++++++++ .../rearm/functions/fnc_getMaxMagazines.sqf | 87 ++++++++ .../functions/fnc_moduleRearmSettings.sqf | 22 ++ addons/rearm/functions/fnc_pickUpAmmo.sqf | 58 ++++++ addons/rearm/functions/fnc_pickUpSuccess.sqf | 23 ++ addons/rearm/functions/fnc_rearm.sqf | 115 ++++++++++ addons/rearm/functions/fnc_rearmSuccess.sqf | 58 ++++++ addons/rearm/functions/script_component.hpp | 6 + addons/rearm/script_component.hpp | 4 + addons/rearm/stringtable.xml | 45 ++++ addons/rearm/ui/icon_module_rearm.paa | Bin 0 -> 11096 bytes addons/rearm/ui/icon_rearm_interact.paa | Bin 0 -> 11096 bytes 21 files changed, 954 insertions(+) create mode 100644 addons/rearm/$PBOPREFIX$ create mode 100644 addons/rearm/ACE_Settings.hpp create mode 100644 addons/rearm/CfgAmmo.hpp create mode 100644 addons/rearm/CfgEventHandlers.hpp create mode 100644 addons/rearm/CfgVehicles.hpp create mode 100644 addons/rearm/XEH_preInit.sqf create mode 100644 addons/rearm/config.cpp create mode 100644 addons/rearm/functions/fnc_addRearmActions.sqf create mode 100644 addons/rearm/functions/fnc_canPickUpAmmo.sqf create mode 100644 addons/rearm/functions/fnc_canRearm.sqf create mode 100644 addons/rearm/functions/fnc_getMaxMagazines.sqf create mode 100644 addons/rearm/functions/fnc_moduleRearmSettings.sqf create mode 100644 addons/rearm/functions/fnc_pickUpAmmo.sqf create mode 100644 addons/rearm/functions/fnc_pickUpSuccess.sqf create mode 100644 addons/rearm/functions/fnc_rearm.sqf create mode 100644 addons/rearm/functions/fnc_rearmSuccess.sqf create mode 100644 addons/rearm/functions/script_component.hpp create mode 100644 addons/rearm/script_component.hpp create mode 100644 addons/rearm/stringtable.xml create mode 100644 addons/rearm/ui/icon_module_rearm.paa create mode 100644 addons/rearm/ui/icon_rearm_interact.paa diff --git a/addons/rearm/$PBOPREFIX$ b/addons/rearm/$PBOPREFIX$ new file mode 100644 index 0000000000..7acbc38009 --- /dev/null +++ b/addons/rearm/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\rearm \ No newline at end of file diff --git a/addons/rearm/ACE_Settings.hpp b/addons/rearm/ACE_Settings.hpp new file mode 100644 index 0000000000..63e53cf4f6 --- /dev/null +++ b/addons/rearm/ACE_Settings.hpp @@ -0,0 +1,9 @@ +class ACE_Settings { + class GVAR(level) { + displayName = LSTRING(RearmSettings_level_DisplayName); + description = LSTRING(RearmSettings_level_Description); + value = 1; + typeName = "SCALAR"; + values[] = {LSTRING(RearmSettings_vehicle), LSTRING(RearmSettings_magazine), LSTRING(RearmSettings_caliber)}; + }; +}; diff --git a/addons/rearm/CfgAmmo.hpp b/addons/rearm/CfgAmmo.hpp new file mode 100644 index 0000000000..bb75946f0e --- /dev/null +++ b/addons/rearm/CfgAmmo.hpp @@ -0,0 +1,196 @@ +class CfgAmmo { + + class BombCore; + class BombBase : BombCore { + ace_logistics_caliber = 250; // Default caliber for bombs + }; + class LaserBombCore : BombCore { + ace_logistics_caliber = 250; // Default caliber for bombs + }; + class MissileCore; + class MissileBase : MissileCore { + ace_logistics_caliber = 250; // Default caliber for missiles + }; + class Rocket_04_HE_F : MissileBase { + ace_logistics_caliber = 70; + }; + class M_PG_AT : MissileBase { + ace_logistics_caliber = 100; + }; + class ACE_Hydra70_DAGR : M_PG_AT { + ace_logistics_caliber = 70; + }; + + class RocketCore; + class RocketBase : RocketCore { + ace_logistics_caliber = 70; // Default caliber for rockets + }; + class R_80mm_HE : RocketBase { + ace_logistics_caliber = 80; + }; + class R_60mm_HE : R_80mm_HE { + ace_logistics_caliber = 60; + }; + + class BulletBase; + + class B_19mm_HE : BulletBase { + ace_logistics_caliber = 19; + }; + + class B_20mm : BulletBase { + ace_logistics_caliber = 20; + }; + + class B_25mm : BulletBase { + ace_logistics_caliber = 25; + }; + + class B_30mm_AP : BulletBase { + ace_logistics_caliber = 30; + }; + class B_30mm_HE : B_19mm_HE { + ace_logistics_caliber = 30; + }; + class Gatling_30mm_HE_Plane_CAS_01_F : BulletBase { + ace_logistics_caliber = 30; + }; + + class B_35mm_AA : BulletBase { + ace_logistics_caliber = 35; + }; + + class B_30mm_APFSDS; + class B_40mm_APFSDS : B_30mm_APFSDS { + ace_logistics_caliber = 40; + }; + + class B_40mm_GPR : B_30mm_HE { + ace_logistics_caliber = 40; + }; + + class GrenadeBase; + class G_40mm_HE : GrenadeBase { + ace_logistics_caliber = 40; + }; + + class RDS_B_127x107_Ball : BulletBase { + ace_logistics_caliber = 12.7; + }; + + class ShellBase; + class Sh_120mm_APFSDS : Shellbase { + ace_logistics_caliber = 120; + }; + class Sh_105mm_APFSDS : Sh_120mm_APFSDS { + ace_logistics_caliber = 105; + }; + class Sh_125mm_APFSDS : Sh_120mm_APFSDS { + ace_logistics_caliber = 125; + }; + + class Sh_120mm_HE : ShellBase { + ace_logistics_caliber = 120; + }; + class Sh_125mm_HE : Sh_120mm_HE { + ace_logistics_caliber = 125; + }; + class Sh_125mm_HEAT : Sh_125mm_HE { + ace_logistics_caliber = 125; + }; + class Sh_105mm_HEAT_MP : Sh_125mm_HEAT { + ace_logistics_caliber = 105; + }; + + class Sh_155mm_AMOS : ShellBase { + ace_logistics_caliber = 155; + }; + class Sh_82mm_AMOS : Sh_155mm_AMOS { + ace_logistics_caliber = 82; + }; + class RDS_Sh_122_HE : Sh_155mm_AMOS { + ace_logistics_caliber = 122; + }; + class RDS_Sh_105_HE : Sh_155mm_AMOS { + ace_logistics_caliber = 105; + }; + + class Sh_82mm_AMOS_LG; + class Sh_155mm_AMOS_LG : Sh_82mm_AMOS_LG { + ace_logistics_caliber = 155; + }; + class RDS_Sh_122_LASER : Sh_155mm_AMOS_LG { + ace_logistics_caliber = 122; + }; + class RDS_Sh_105_LASER : Sh_155mm_AMOS_LG { + ace_logistics_caliber = 105; + }; + + class ShotDeployBase; + class Smoke_82mm_AMOS_White : ShotDeployBase { + ace_logistics_caliber = 82; + }; + + class FlareCore; + class Flare_82mm_AMOS_White : FlareCore { + ace_logistics_caliber = 82; + }; + + class SmokeLauncherAmmo : BulletBase { + ace_logistics_caliber = 250; + }; + + class CMflareAmmo : BulletBase { + ace_logistics_caliber = 40; + }; + + class SubmunitionBase; + class Sh_82mm_AMOS_guided : SubmunitionBase { + ace_logistics_caliber = 82; + }; + class Sh_155mm_AMOS_guided : Sh_82mm_AMOS_guided { + ace_logistics_caliber = 155; + }; + class R_230mm_HE : SubmunitionBase { + ace_logistics_caliber = 230; + }; + class rhs_ammo_127x108mm_x5 : SubmunitionBase { + ace_logistics_caliber = 12.7; + }; + class Mine_155mm_AMOS_range : SubmunitionBase { + ace_logistics_caliber = 155; + }; + class Cluster_155mm_AMOS : SubmunitionBase { + ace_logistics_caliber = 155; + }; + class Smoke_120mm_AMOS_White : SubmunitionBase { + ace_logistics_caliber = 155; + }; + class AT_Mine_155mm_AMOS_range : SubmunitionBase { + ace_logistics_caliber = 155; + }; + + class rhs_ammo_rpgShell_base : ShellBase { + ace_logistics_caliber = 70; + }; + + class Bomb_04_F : LaserBombCore { + ace_logistics_caliber = 250; // Default caliber for bombs + }; + class Bo_GBU12_LGB : LaserBombCore { + ace_logistics_caliber = 250; // Default caliber for bombs + }; + class js_a_fa18_wing_tank : LaserBombCore { + ace_logistics_caliber = 250; // Default caliber for bombs + }; + + class js_a_fa18x_MK82 : BombCore {}; + class js_a_fa18x_GBU39_SDB : js_a_fa18x_MK82 { + ace_logistics_caliber = 250; // Default caliber for bombs + }; + + class js_a_fa18_GBU12_LGB : LaserBombCore {}; + class js_a_fa18_GBU38_JDAM : js_a_fa18_GBU12_LGB { + ace_logistics_caliber = 250; // Default caliber for bombs + }; +}; diff --git a/addons/rearm/CfgEventHandlers.hpp b/addons/rearm/CfgEventHandlers.hpp new file mode 100644 index 0000000000..b928bc2de6 --- /dev/null +++ b/addons/rearm/CfgEventHandlers.hpp @@ -0,0 +1,5 @@ +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; diff --git a/addons/rearm/CfgVehicles.hpp b/addons/rearm/CfgVehicles.hpp new file mode 100644 index 0000000000..10d22b0527 --- /dev/null +++ b/addons/rearm/CfgVehicles.hpp @@ -0,0 +1,125 @@ +#define REARM_ACTION_DISTANCE 4.5 +#define MACRO_REARM_ACTIONS \ + class ACE_Actions { \ + class ACE_MainActions { \ + displayName = ECSTRING(interaction,MainAction); \ + selection = ""; \ + distance = 10; \ + condition = "true"; \ + class GVAR(rearm) { \ + displayName = CSTRING(rearm); \ + distance = REARM_ACTION_DISTANCE; \ + condition = QUOTE([ARR_2(_player,_target)] call FUNC(canRearm)); \ + statement = QUOTE([ARR_2(_player,_target)] call FUNC(rearm)); \ + exceptions[] = {"isNotInside"}; \ + icon = PATHTOF(ui\icon_rearm_interact.paa); \ + }; \ + }; \ + }; + +#define MACRO_REARM_PICKUPAMMO \ + class ACE_Actions : ACE_Actions { \ + class ACE_MainActions : ACE_MainActions { \ + class GVAR(pickUpAmmo) { \ + displayName = CSTRING(pickUpAmmo); \ + distance = REARM_ACTION_DISTANCE; \ + condition = QUOTE([ARR_2(_player,_target)] call FUNC(canPickUpAmmo)); \ + insertChildren = QUOTE([ARR_1(_target)] call DFUNC(addRearmActions)); \ + exceptions[] = {"isNotInside"}; \ + icon = PATHTOF(ui\icon_rearm_interact.paa); \ + }; \ + }; \ + }; + +class CfgVehicles { + class ACE_Module; + class ACE_moduleRearmSettings : ACE_Module { + scope = 2; + displayName = CSTRING(RearmSettings_Module_DisplayName); + icon = QUOTE(PATHTOF(ui\icon_module_rearm.paa)); + category = "ACE"; + function = QUOTE(DFUNC(moduleRearmSettings)); + functionPriority = 1; + isGlobal = 0; + isTriggerActivated = 0; + author = ECSTRING(common,ACETeam); + class Arguments { + class level { + displayName = CSTRING(RearmSettings_level_DisplayName); + description = CSTRING(RearmSettings_level_Description); + typeName = "NUMBER"; + class values { + class vehicle { + name = CSTRING(RearmSettings_vehicle); + value = 0; + }; + class magazine { + name = CSTRING(RearmSettings_magazine); + value = 1; + }; + class caliber { + name = CSTRING(RearmSettings_caliber); + value = 2; + default = 1; + }; + }; + }; + }; + }; + + class LandVehicle; + class Car : LandVehicle { + MACRO_REARM_ACTIONS + }; + + class Tank : LandVehicle { + MACRO_REARM_ACTIONS + }; + + class StaticWeapon : LandVehicle { + MACRO_REARM_ACTIONS + }; + + class Air; + class Helicopter : Air { + MACRO_REARM_ACTIONS + }; + + class Plane : Air { + MACRO_REARM_ACTIONS + }; + + class Ship; + class Ship_F : Ship { + MACRO_REARM_ACTIONS + }; + + class Car_F : Car {}; + class Truck_F : Car_F {}; + class Truck_01_base_F: Truck_F {}; + class Truck_02_base_F : Truck_F {}; + class Truck_03_base_F : Truck_F {}; + + class B_Truck_01_transport_F : Truck_01_base_F {}; + class B_Truck_01_mover_F: B_Truck_01_transport_F {}; + + class I_Truck_02_ammo_F : Truck_02_base_F { + transportAmmo = 0; + MACRO_REARM_PICKUPAMMO + }; + + class B_Truck_01_ammo_F : B_Truck_01_mover_F { + transportAmmo = 0; + MACRO_REARM_PICKUPAMMO + }; + + class O_Truck_02_Ammo_F : Truck_02_base_F { + transportAmmo = 0; + MACRO_REARM_PICKUPAMMO + }; + + class O_Truck_03_ammo_F : Truck_03_base_F { + transportAmmo = 0; + MACRO_REARM_PICKUPAMMO + }; +}; diff --git a/addons/rearm/XEH_preInit.sqf b/addons/rearm/XEH_preInit.sqf new file mode 100644 index 0000000000..70dd9327ac --- /dev/null +++ b/addons/rearm/XEH_preInit.sqf @@ -0,0 +1,15 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP(addRearmActions); +PREP(canRearm); +PREP(canPickupAmmo); +PREP(getMaxMagazines); +PREP(pickUpAmmo); +PREP(pickUpSuccess); +PREP(rearm); +PREP(rearmSuccess); +PREP(moduleRearmSettings); + +ADDON = true; diff --git a/addons/rearm/config.cpp b/addons/rearm/config.cpp new file mode 100644 index 0000000000..1d7083b2a4 --- /dev/null +++ b/addons/rearm/config.cpp @@ -0,0 +1,18 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_interaction"}; + author[] = {"GitHawk"}; + authorUrl = ""; + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" +#include "CfgVehicles.hpp" +#include "CfgAmmo.hpp" +#include "ACE_Settings.hpp" \ No newline at end of file diff --git a/addons/rearm/functions/fnc_addRearmActions.sqf b/addons/rearm/functions/fnc_addRearmActions.sqf new file mode 100644 index 0000000000..1bd9b064f2 --- /dev/null +++ b/addons/rearm/functions/fnc_addRearmActions.sqf @@ -0,0 +1,65 @@ +/* + * Author: GitHawk + * Show the resupplyable ammunition of all surrounding vehicles. + * Called from "insertChildren" on interact_menu + * + * Argument: + * 0: Target + * + * Return value: + * ChildActions + * + * Example: + * [tank] call ace_rearm_fnc_addRearmActions + * + * Public: No + */ +#include "script_component.hpp" + +private ["_vehicleActions", "_actions", "_action", "_vehicles", "_vehicle", "_needToAdd", "_magazineHelper", "_turretPath", "_magazines", "_magazine", "_icon"]; +params ["_target"]; + +_vehicles = nearestObjects [_target, ["AllVehicles"], 20]; +if (count _vehicles < 2) exitWith {false}; // Logistics needs at least 2 vehicles + +_vehicleActions = []; +{ + _actions = []; + _vehicle = _x; + _needToAdd = false; + _action = []; + if !(_vehicle == _target) then { + _magazineHelper = []; + { + _turretPath = _x; + _magazines = _vehicle magazinesTurret _turretPath; + { + _magazine = _x; + _cnt = { _x == _magazine } count (_vehicle magazinesTurret _turretPath); + if ((_cnt < ([_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines))) && !(_magazine in _magazineHelper)) then { + _action = [_magazine, getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"), getText(configFile >> "CfgMagazines" >> _magazine >> "picture"), {_this call FUNC(pickUpAmmo)}, {true}, {}, [_magazine, _vehicle]] call EFUNC(interact_menu,createAction); + _actions pushBack [_action, [], _target]; + _magazineHelper pushBack _magazine; + _needToAdd = true; + } else { + if (((_vehicle magazineTurretAmmo [_magazine, _turretPath]) < getNumber (configFile >> "CfgMagazines" >> _magazine >> "count")) && !(_magazine in _magazineHelper)) then { + _action = [_magazine, getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"), getText(configFile >> "CfgMagazines" >> _magazine >> "picture"), {_this call FUNC(pickUpAmmo)}, {true}, {}, [_magazine, _vehicle]] call EFUNC(interact_menu,createAction); + _actions pushBack [_action, [], _target]; + _magazineHelper pushBack _magazine; + _needToAdd = true; + }; + }; + } foreach _magazines; + } foreach [[0], [-1], [0,0], [0,1], [1], [2]]; + }; + if (_needToAdd) then { + _icon = getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "Icon"); + if !((_icon select [0, 1]) == "\") then { + _icon = ""; + }; + _action = [_vehicle, getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName"), _icon, "", {true}, {}, []] call EFUNC(interact_menu,createAction); + _vehicleActions pushBack [_action, _actions, _target]; + }; +} foreach _vehicles; + +_vehicleActions diff --git a/addons/rearm/functions/fnc_canPickUpAmmo.sqf b/addons/rearm/functions/fnc_canPickUpAmmo.sqf new file mode 100644 index 0000000000..b4e72f51fa --- /dev/null +++ b/addons/rearm/functions/fnc_canPickUpAmmo.sqf @@ -0,0 +1,21 @@ +/* + * Author: GitHawk + * Check if a unit can pick up ammo + * + * Arguments: + * 0: The Player + * 1: The Target + * + * Return Value: + * Can rearm + * + * Example: + * [tank] call ace_rearm_fnc_canPickUpAmmo + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit", "_target"]; + +!(isNull ace_player || {!(ace_player isKindOf "CAManBase")} || {!local ace_player} || { (_target distance ace_player) > 7}) diff --git a/addons/rearm/functions/fnc_canRearm.sqf b/addons/rearm/functions/fnc_canRearm.sqf new file mode 100644 index 0000000000..1e0e75cc0c --- /dev/null +++ b/addons/rearm/functions/fnc_canRearm.sqf @@ -0,0 +1,81 @@ +/* + * Author: GitHawk + * Check if a unit can rearm + * + * Arguments: + * 0: The unit + * 1: The target + * + * Return Value: + * Can rearm + * + * Example: + * [player, tank] call ace_rearm_fnc_canRearm + * + * Public: No + */ +#include "script_component.hpp" + +private ["_vehicles", "_magazine", "_magazines", "_path", "_return", "_cnt"]; +params ["_unit", "_vehicle"]; + +#define GETRETURNVALUE \ +if ((_vehicle magazineTurretAmmo [_magazine, _path]) < getNumber (configFile >> "CfgMagazines" >> _magazine >> "count")) then { \ + _return = true; \ +} else { \ + _cnt = { _x == _magazine } count _magazines; \ + if (_cnt < ([_vehicle, _path, _magazine] call FUNC(getMaxMagazines))) then { \ + _return = true; \ + }; \ +}; + +if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || { (_vehicle distance _unit) > 7}) exitWith {false}; + +_magazine = _unit getVariable QGVAR(carriedMagazine); +if (isNil "_magazine") exitWith {false}; + +// TODO move into loop + +_return = false; +_magazines = _vehicle magazinesTurret [-1]; +if (_magazine in _magazines) then { + _path = [-1]; + GETRETURNVALUE +}; +if (!_return) then { + _magazines = _vehicle magazinesTurret [0]; + if (_magazine in _magazines) then { + _path = [0]; + GETRETURNVALUE + }; +}; +if (!_return) then { + _magazines = _vehicle magazinesTurret [0,0]; + if (_magazine in _magazines) then { + _path = [0,0]; + GETRETURNVALUE + }; +}; +if (!_return) then { + _magazines = _vehicle magazinesTurret [0,1]; + if (_magazine in _magazines) then { + _path = [0,1]; + GETRETURNVALUE + }; +}; +if (!_return) then { + _magazines = _vehicle magazinesTurret [1]; + if (_magazine in _magazines) then { + _path = [1]; + GETRETURNVALUE + }; +}; +if (!_return) then { + _magazines = _vehicle magazinesTurret [2]; + if (_magazine in _magazines) then { + _path = [2]; + GETRETURNVALUE + }; +}; + +_return \ No newline at end of file diff --git a/addons/rearm/functions/fnc_getMaxMagazines.sqf b/addons/rearm/functions/fnc_getMaxMagazines.sqf new file mode 100644 index 0000000000..4c5f5b2544 --- /dev/null +++ b/addons/rearm/functions/fnc_getMaxMagazines.sqf @@ -0,0 +1,87 @@ +/* + * Author: GitHawk + * Calculates the maximum number of magazines a turret can hold according to config + * + * Arguments: + * 0: The Unit + * 1: The Turretpath + * 2: The Magazine + * + * Return Value: + * Number of magazines on the turret path + * + * Example: + * [vehicle, [0], "500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_getMaxMagazines + * + * Public: No + */ +#include "script_component.hpp" + +private ["_count", "_cfg"]; +params ["_target", "_turretPath", "_magazine"]; + +if (isNull _target) exitWith {0}; +_count = 0; + +// TODO replace by loop or method of interpreting _turretPath + +_cfg = configFile; +switch (_turretPath) do { + case [0] : { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target) >> "Turrets"; + if (count _cfg > 0) then { + _cfg = _cfg select 0; + } else { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + }; + }; + case [1] : { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target) >> "Turrets"; + if (count _cfg > 0) then { + _cfg = _cfg select 1; + } else { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + }; + }; + case [2] : { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target) >> "Turrets"; + if (count _cfg > 0) then { + _cfg = _cfg select 2; + } else { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + }; + }; + case [0,0] : { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target) >> "Turrets"; + if (count _cfg > 0) then { + _cfg = (_cfg select 0) >> "Turrets"; + if (count _cfg > 0) then { + _cfg = _cfg select 0; + } else { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + }; + } else { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + }; + }; + case [0,1] : { + if (count _cfg > 0) then { + _cfg = (_cfg select 0) >> "Turrets"; + if (count _cfg > 0) then { + _cfg = _cfg select 1; + } else { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + }; + } else { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + }; + }; + default { + _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + }; +}; + +if !(isClass _cfg) exitWith {0}; + +_count = {_x == _magazine} count getArray (_cfg >> "magazines"); +_count \ No newline at end of file diff --git a/addons/rearm/functions/fnc_moduleRearmSettings.sqf b/addons/rearm/functions/fnc_moduleRearmSettings.sqf new file mode 100644 index 0000000000..7325a8ddaf --- /dev/null +++ b/addons/rearm/functions/fnc_moduleRearmSettings.sqf @@ -0,0 +1,22 @@ +/* + * Author: GitHawk + * Module for adjusting the refuel settings + * + * Arguments: + * 0: The module logic + * 1: units + * 2: activated + * + * Return Value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_logic", "_units", "_activated"]; + +if !(_activated) exitWith {}; + +[_logic, QGVAR(level), "level"] call EFUNC(common,readSettingFromModule); diff --git a/addons/rearm/functions/fnc_pickUpAmmo.sqf b/addons/rearm/functions/fnc_pickUpAmmo.sqf new file mode 100644 index 0000000000..38dc38c945 --- /dev/null +++ b/addons/rearm/functions/fnc_pickUpAmmo.sqf @@ -0,0 +1,58 @@ +/* + * Author: GitHawk + * Picks up a specific kind of magazine from an ammo truck + * + * Arguments: + * 0: The Ammo Truck + * 1: The Player + * 2: The Params + * 2,0: The Magazine + * 2,1: The Vehicle to be armed + * + * Return Value: + * None + * + * Example: + * [ammo_truck, player, ["500Rnd_127x99_mag_Tracer_Red", tank]] call ace_rearm_fnc_pickUpAmmo + * + * Public: No + */ +#include "script_component.hpp" + +private ["_ammo", "_tmpCal", "_cal"]; +params ["_target","_unit","_args"]; +_args params ["_magazine", "_vehicle"]; + +_ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); +_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_caliber"); +_cal = 8; +if (_tmpCal > 0) then { + _cal = _tmpCal; +} else { + _tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_logistics_caliber"); + if (_tmpCal > 0) then { + _cal = _tmpCal; + } else { + diag_log format ["ACE_Logistics: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)]; + if (_ammo isKindOf "BulletBase") then { + _cal = 8; + } else { + _cal = 100; + }; + }; +}; +_cal = round _cal; +_idx = CALIBERS find _cal; +if (_idx == -1 ) then { + _idx = 2; +}; + +[ + (DURATION_PICKUP select _idx), + [_unit, _magazine], + FUNC(pickUpSuccess), + "", + format [localize LSTRING(PickUpAction), getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], + {true}, + ["isnotinside"] +] call EFUNC(common,progressBar); \ No newline at end of file diff --git a/addons/rearm/functions/fnc_pickUpSuccess.sqf b/addons/rearm/functions/fnc_pickUpSuccess.sqf new file mode 100644 index 0000000000..114cb99047 --- /dev/null +++ b/addons/rearm/functions/fnc_pickUpSuccess.sqf @@ -0,0 +1,23 @@ +/* + * Author: GitHawk + * Picks up a magazine + * + * Arguments: + * 0: The Params + * 0,0: The Unit + * 0,1: The Magazine + * + * Return Value: + * None + * + * Example: + * [[player, "500Rnd_127x99_mag_Tracer_Red"]] call ace_rearm_fnc_pickUpSuccess + * + * Public: No + */ +#include "script_component.hpp" + +params ["_args"]; +_args params ["_unit", "_magazine"]; + +_unit setVariable [QGVAR(carriedMagazine), _magazine]; // TODO replace by item diff --git a/addons/rearm/functions/fnc_rearm.sqf b/addons/rearm/functions/fnc_rearm.sqf new file mode 100644 index 0000000000..7ff3abcbdc --- /dev/null +++ b/addons/rearm/functions/fnc_rearm.sqf @@ -0,0 +1,115 @@ +/* + * Author: GitHawk + * Rearms a vehicle + * + * Arguments: + * 0: The vehicle + * + * Return Value: + * None + * + * Example: + * [player, vehicle] call ace_rearm_fnc_rearm + * + * Public: No + */ +#include "script_component.hpp" + +#define GETRETURNVALUE \ +_cnt = { _x == _magazine } count _magazines; \ +if ((_target magazineTurretAmmo [_magazine, _path]) < getNumber (configFile >> "CfgMagazines" >> _magazine >> "count")) then { \ + _turretPath = _path; \ + _return = true; \ +} else { \ + if (_cnt < ([_target, _path, _magazine] call FUNC(getMaxMagazines))) then { \ + _turretPath = _path; \ + _return = true; \ + }; \ +}; + +private ["_ammo", "_tmpCal", "_cal", "_idx", "_cnt","_return"]; +params ["_unit", "_vehicle"]; + +_magazine = _unit getVariable QGVAR(carriedMagazine); +if (isNil "_magazine") exitWith {false}; + +_ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); +_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_caliber"); +_cal = 8; +if (_tmpCal > 0) then { + _cal = _tmpCal; +} else { + _tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_logistics_caliber"); + if (_tmpCal > 0) then { + _cal = _tmpCal; + } else { + diag_log format ["ACE_Rearm: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)]; + if (_ammo isKindOf "BulletBase") then { + _cal = 8; + } else { + _cal = 100; + }; + }; +}; +_cal = round _cal; +_idx = CALIBERS find _cal; +if (_idx == -1 ) then { + _idx = 2; +}; + +_return = false; +_turretPath = [0]; _cnt = 0; +_magazines = _target magazinesTurret [-1]; +if (_magazine in _magazines) then { + _path = [-1]; + GETRETURNVALUE +}; +if (!_return) then { + _magazines = _target magazinesTurret [0]; + if (_magazine in _magazines) then { + _path = [0]; + GETRETURNVALUE + }; +}; +if (!_return) then { + _magazines = _target magazinesTurret [0,0]; + if (_magazine in _magazines) then { + _path = [0,0]; + GETRETURNVALUE + }; +}; +if (!_return) then { + _magazines = _target magazinesTurret [0,1]; + if (_magazine in _magazines) then { + _path = [0,1]; + GETRETURNVALUE + }; +}; +if (!_return) then { + _magazines = _target magazinesTurret [1]; + if (_magazine in _magazines) then { + _path = [1]; + GETRETURNVALUE + }; +}; +if (!_return) then { + _magazines = _target magazinesTurret [2]; + if (_magazine in _magazines) then { + _path = [2]; + GETRETURNVALUE + } else { + diag_log format ["ACE_Rearm: Could not find turret for %1 in %2", _magazine, (typeOf _target)]; + }; +}; + +//hint format ["Magazine: %1\nAmmo: %2\nCaliber: %3\nIndex: %4\nTurretPath: %5\nDURATION_REARM: %6\nCount: %7", _magazine, _ammo, _cal, _idx, _turretPath, (DURATION_REARM select _idx), (COUNT select _idx)]; + +[ + (DURATION_REARM select _idx), + [_target, _unit, _turretPath, _cnt, _magazine, (COUNT select _idx)], + FUNC(rearmSuccess), + "", + format [localize LSTRING(RearmAction), getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName"), getText(configFile >> "CfgMagazines" >> _magazine >> "displayName")], + {true}, + ["isnotinside"] +] call EFUNC(common,progressBar); \ No newline at end of file diff --git a/addons/rearm/functions/fnc_rearmSuccess.sqf b/addons/rearm/functions/fnc_rearmSuccess.sqf new file mode 100644 index 0000000000..1a308c6791 --- /dev/null +++ b/addons/rearm/functions/fnc_rearmSuccess.sqf @@ -0,0 +1,58 @@ +/* + * Author: GitHawk + * Rearms a vehicle + * + * Arguments: + * 0: The Params + * 0,1: The Target + * 0,2: The Caller + * 0,3: The Turretpath + * 0,4: The Number of magazines + * 0,5: The Magazine + * 0,6: The Number of rounds + * + * Return Value: + * None + * + * Example: + * [vehicle] call ace_rearm_fnc_rearmSuccess + * + * Public: No + */ +#include "script_component.hpp" + +private ["_rounds", "_currentRounds", "_maxMagazines"]; +params ["_args"]; +_args params ["_target", "_caller", "_turretPath", "_numMagazines", "_magazine", "_numRounds"]; + +//hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMagazine: %4\nNumRounds: %5", _target, _turretPath, _numMagazines, _magazine, _numRounds]; + +if !(local _target) exitWith { + [_this, QUOTE(DFUNC(rearmSuccess)), _target] call EFUNC(common,execRemoteFnc); +}; + +_rounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); +_currentRounds = 0; + +_maxMagazines = [_target, _turretPath, _magazine] call FUNC(getMaxMagazines); +if (_maxMagazines == 1) then { + _target setMagazineTurretAmmo [_magazine, ((_target magazineTurretAmmo [_magazine, _turretPath]) + _numRounds) min _rounds, _turretPath]; + ace_player setVariable [QGVAR(carriedMagazine), nil]; // TODO replace by item +} else { + for "_idx" from 1 to _maxMagazines do { + _currentRounds = _target magazineTurretAmmo [_magazine, _turretPath]; + if (_currentRounds > 0) exitWith { + if ((_currentRounds + _numRounds) > _rounds) then { + _target setMagazineTurretAmmo [_magazine, _rounds, _turretPath]; + if (_numMagazines < _maxMagazines) then { + _target addMagazineTurret [_magazine, _turretPath]; + _target setMagazineTurretAmmo [_magazine, _currentRounds + _numRounds - _rounds, _turretPath]; + }; + } else { + _target setMagazineTurretAmmo [_magazine, _currentRounds + _numRounds, _turretPath]; + }; + ace_player setVariable [QGVAR(carriedMagazine), nil]; // TODO replace by item + }; + _target removeMagazineTurret [_magazine, _turretPath]; + }; +}; \ No newline at end of file diff --git a/addons/rearm/functions/script_component.hpp b/addons/rearm/functions/script_component.hpp new file mode 100644 index 0000000000..bf5e8c982b --- /dev/null +++ b/addons/rearm/functions/script_component.hpp @@ -0,0 +1,6 @@ +#include "\z\ace\addons\rearm\script_component.hpp" + +#define CALIBERS [ 6, 7, 8, 13, 19, 20, 25, 30, 35, 40, 60, 70, 80, 82, 100, 105, 120, 122, 125, 155, 230, 250] +#define DURATION_PICKUP [ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 13, 10] +#define DURATION_REARM [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 7, 7, 7, 7, 7, 8, 10, 10, 10, 10, 27, 20] +#define COUNT [500, 500, 400, 100, 50, 50, 40, 25, 34, 10, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1] \ No newline at end of file diff --git a/addons/rearm/script_component.hpp b/addons/rearm/script_component.hpp new file mode 100644 index 0000000000..df53e433ab --- /dev/null +++ b/addons/rearm/script_component.hpp @@ -0,0 +1,4 @@ +#define COMPONENT rearm +#include "\z\ace\addons\main\script_mod.hpp" + +#include "\z\ace\addons\main\script_macros.hpp" diff --git a/addons/rearm/stringtable.xml b/addons/rearm/stringtable.xml new file mode 100644 index 0000000000..906bca12d1 --- /dev/null +++ b/addons/rearm/stringtable.xml @@ -0,0 +1,45 @@ + + + + + Rearm Settings + Aufmunitioniereinstellungen + + + Rearm speed + Aufmunitioniergeschwindigkeit + + + How fast should a vehicle be rearmed? + Wie schnell soll ein Fahrzeug aufmunitioniert werden? + + + Entire vehicle + Gesamtes Fahrzeug + + + Entire Magazine + Gesamtes Magazin + + + Amount based on caliber + Kaliberbasierte Anzahl + + + Rearm + Aufmunitionieren + + + Rearming %1 with %2 + Munitioniere %1 auf mit %2 + + + Taking %1 for %2 + Nehme %1 für %2 + + + Pick up ammo + Munition nehmen + + + diff --git a/addons/rearm/ui/icon_module_rearm.paa b/addons/rearm/ui/icon_module_rearm.paa new file mode 100644 index 0000000000000000000000000000000000000000..fe2a9a12357afcc75b3054d9f2df3d8175e541e6 GIT binary patch literal 11096 zcmeHN&r2IY6dtPwZ+d9(P!Bnl_Ub{QWfKH*X;~!3Erhavg7jF5thZiDPqio8oBu$e z7s14f9(yUVV8NV%haQq3i%7FO{l3*z8Fy>4Mq!f~SYO^aZ{ED0v$OL?WTB8>nlCKp z$Al2R@6QGJtNcsi5{-Bv|6+mo13biw3kzlrzt`}*&kFJJu@LJ|gqVIR#5|tv+ZyM{ zio+AKl2XI_)x(<)QdUjd`n4^k=kC^qMgPrr(6iy#QXcG&z+0(xI_=L5{P5cDpzC1~ zb}w4XrBLn=e)}Y4EmJBzsy}a{&mS~B(9a#yE{F2Q!DINrAjJdaL^D=lRconq&F=gs z{r?i4Z0CUgK4eeFOS>QZg&fX`UA&Y}l{XsS+Ly9D0C{m{vs=5XdN|&oAI$E}?$Hs_ z<_FAYRmU-VwYxfgs)Brw!hK=-NJ`VTZB?FL@z39-blu%X+U)-jeqSt?tzPAg8oz^< zHu)*XC|Z;}2#wfw_v|8QTKs?7bMFWeS}^Yt6%L{5nD#AN_)1K|v(5|k16_kLYPzGm54 z;x&`o$dvl6p1Ap5<2uj4y%tT2UG3s?F0ZY;_UWB}u78H>1q=6yDu1r4k-0lPOdr*y zVK|P;SHI$N5px{sZI}+$zHV zw)T;B5dYDTdB}C$zWaaDb@z*oab|QGf1QDie`DLT;>z;3xx)P^Isnsr*!&bhn|W z-Wf@#hlops5DGxhjNI=i*a-q8AY2U#t3@6q76q4b@PgxvML7 z0R8r9*nbt;Ma$x}QM(=KEPMnbjQWU0Iyo^q5x~~YMYbBp8)^1@xmbR{&i6b{9#rv(?uB1O^u39~;9L4*&oF literal 0 HcmV?d00001 diff --git a/addons/rearm/ui/icon_rearm_interact.paa b/addons/rearm/ui/icon_rearm_interact.paa new file mode 100644 index 0000000000000000000000000000000000000000..fe2a9a12357afcc75b3054d9f2df3d8175e541e6 GIT binary patch literal 11096 zcmeHN&r2IY6dtPwZ+d9(P!Bnl_Ub{QWfKH*X;~!3Erhavg7jF5thZiDPqio8oBu$e z7s14f9(yUVV8NV%haQq3i%7FO{l3*z8Fy>4Mq!f~SYO^aZ{ED0v$OL?WTB8>nlCKp z$Al2R@6QGJtNcsi5{-Bv|6+mo13biw3kzlrzt`}*&kFJJu@LJ|gqVIR#5|tv+ZyM{ zio+AKl2XI_)x(<)QdUjd`n4^k=kC^qMgPrr(6iy#QXcG&z+0(xI_=L5{P5cDpzC1~ zb}w4XrBLn=e)}Y4EmJBzsy}a{&mS~B(9a#yE{F2Q!DINrAjJdaL^D=lRconq&F=gs z{r?i4Z0CUgK4eeFOS>QZg&fX`UA&Y}l{XsS+Ly9D0C{m{vs=5XdN|&oAI$E}?$Hs_ z<_FAYRmU-VwYxfgs)Brw!hK=-NJ`VTZB?FL@z39-blu%X+U)-jeqSt?tzPAg8oz^< zHu)*XC|Z;}2#wfw_v|8QTKs?7bMFWeS}^Yt6%L{5nD#AN_)1K|v(5|k16_kLYPzGm54 z;x&`o$dvl6p1Ap5<2uj4y%tT2UG3s?F0ZY;_UWB}u78H>1q=6yDu1r4k-0lPOdr*y zVK|P;SHI$N5px{sZI}+$zHV zw)T;B5dYDTdB}C$zWaaDb@z*oab|QGf1QDie`DLT;>z;3xx)P^Isnsr*!&bhn|W z-Wf@#hlops5DGxhjNI=i*a-q8AY2U#t3@6q76q4b@PgxvML7 z0R8r9*nbt;Ma$x}QM(=KEPMnbjQWU0Iyo^q5x~~YMYbBp8)^1@xmbR{&i6b{9#rv(?uB1O^u39~;9L4*&oF literal 0 HcmV?d00001