Implementation

This commit is contained in:
Githawk 2016-02-27 20:31:07 +01:00
parent 279541676e
commit 91c6341bc8
33 changed files with 719 additions and 140 deletions

View File

@ -11,6 +11,6 @@ class ACE_Settings {
description = CSTRING(RearmSettings_supply_Description);
value = 0;
typeName = "SCALAR";
values[] = {CSTRING(RearmSettings_unlimited), CSTRING(RearmSettings_caliber), CSTRING(RearmSettings_magazineSupply)};
values[] = {CSTRING(RearmSettings_unlimited), CSTRING(RearmSettings_limited), CSTRING(RearmSettings_magazineSupply)};
};
};

View File

@ -15,6 +15,26 @@
#define MACRO_REARM_TRUCK_ACTIONS \
class ACE_Actions : ACE_Actions { \
class ACE_MainActions : ACE_MainActions { \
class GVAR(ReadSupplyCounter) { \
displayName = CSTRING(ReadSupplyCounter); \
distance = REARM_ACTION_DISTANCE; \
condition = QUOTE(_this call FUNC(canReadSupplyCounter)); \
statement = QUOTE(_this call FUNC(readSupplyCounter)); \
exceptions[] = {"isNotInside"}; \
showDisabled = 0; \
priority = 2; \
icon = PATHTOF(ui\icon_rearm_interact.paa); \
}; \
class GVAR(Rearm) { \
displayName = CSTRING(Rearm); \
distance = REARM_ACTION_DISTANCE; \
condition = QUOTE(_this call FUNC(canRearmVehicle)); \
insertChildren = QUOTE(_target call FUNC(addRearmActions)); \
exceptions[] = {"isNotInside"}; \
showDisabled = 0; \
priority = 2; \
icon = PATHTOF(ui\icon_rearm_interact.paa); \
}; \
class GVAR(TakeAmmo) { \
displayName = CSTRING(TakeAmmo); \
distance = REARM_ACTION_DISTANCE; \
@ -36,6 +56,9 @@
}; \
};
#define MACRO_REARM_DEFAULT_SUPPLY \
GVAR(defaultSupply) = 1200;
class CfgVehicles {
class ACE_Module;
class ACE_moduleRearmSettings : ACE_Module {
@ -69,6 +92,26 @@ class CfgVehicles {
};
};
};
class supply {
displayName = CSTRING(RearmSettings_supply_DisplayName);
description = CSTRING(RearmSettings_supply_Description);
typeName = "NUMBER";
class values {
class unlimited {
name = CSTRING(RearmSettings_unlimited);
value = 0;
default = 1;
};
class magazine {
name = CSTRING(RearmSettings_limited);
value = 1;
};
class caliber {
name = CSTRING(RearmSettings_magazineSupply);
value = 2;
};
};
};
};
class ModuleDescription {
description = CSTRING(RearmSettings_Module_Description);
@ -110,6 +153,7 @@ class CfgVehicles {
class Truck_03_base_F : Truck_F {};
class O_Truck_03_ammo_F : Truck_03_base_F {
transportAmmo = 0;
MACRO_REARM_DEFAULT_SUPPLY
MACRO_REARM_TRUCK_ACTIONS
};
@ -117,10 +161,12 @@ class CfgVehicles {
class Truck_02_Ammo_base_F : Truck_02_base_F {};
class I_Truck_02_ammo_F : Truck_02_Ammo_base_F {
transportAmmo = 0;
MACRO_REARM_DEFAULT_SUPPLY
MACRO_REARM_TRUCK_ACTIONS
};
class O_Truck_02_Ammo_F : Truck_02_Ammo_base_F {
transportAmmo = 0;
MACRO_REARM_DEFAULT_SUPPLY
MACRO_REARM_TRUCK_ACTIONS
};
@ -129,6 +175,7 @@ class CfgVehicles {
class B_Truck_01_mover_F : B_Truck_01_transport_F {};
class B_Truck_01_ammo_F : B_Truck_01_mover_F {
transportAmmo = 0;
MACRO_REARM_DEFAULT_SUPPLY
MACRO_REARM_TRUCK_ACTIONS
};
@ -137,12 +184,14 @@ class CfgVehicles {
class Heli_Transport_04_base_F : Helicopter_Base_H {};
class O_Heli_Transport_04_ammo_F : Heli_Transport_04_base_F {
transportAmmo = 0;
MACRO_REARM_DEFAULT_SUPPLY
MACRO_REARM_TRUCK_ACTIONS
};
class Pod_Heli_Transport_04_base_F: StaticWeapon {};
class Land_Pod_Heli_Transport_04_ammo_F: Pod_Heli_Transport_04_base_F {
transportAmmo = 0;
MACRO_REARM_DEFAULT_SUPPLY
MACRO_REARM_TRUCK_ACTIONS
};
@ -161,6 +210,7 @@ class CfgVehicles {
class B_Slingload_01_Ammo_F : Slingload_01_Base_F {
XEH_ENABLED;
transportAmmo = 0;
MACRO_REARM_DEFAULT_SUPPLY
MACRO_REARM_TRUCK_ACTIONS
};

View File

@ -1,26 +1,38 @@
PREP(addMagazineToSupply);
PREP(addRearmActions);
PREP(addVehicleMagazinesToSupply);
PREP(canReadSupplyCounter);
PREP(canRearm);
PREP(canRearmVehicle);
PREP(canStoreAmmo);
PREP(canTakeAmmo);
PREP(createDummy);
PREP(disable);
PREP(dropAmmo);
PREP(getCaliber);
PREP(getConfigMagazines);
PREP(getMaxMagazines);
PREP(getNeedRearmMagazines);
PREP(getSupplyCount);
PREP(getVehicleMagazines);
PREP(grabAmmo);
PREP(handleKilled);
PREP(handleUnconscious);
PREP(hasEnoughSupply);
PREP(magazineInSupply);
PREP(makeDummy);
PREP(moduleRearmSettings);
PREP(pickUpAmmo);
PREP(readSupplyCounter);
PREP(rearm);
PREP(rearmEntireVehicle);
PREP(rearmEntireVehicleSuccess);
PREP(rearmEntireVehicleSuccessLocal);
PREP(rearmSuccess);
PREP(rearmSuccessLocal);
PREP(removeMagazineFromSupply);
PREP(setSupplyCount);
PREP(storeAmmo);
PREP(takeAmmo);
PREP(takeSuccess);

View File

@ -0,0 +1,64 @@
/*
* Author: GitHawk
* Adds magazines to the supply.
*
* Argument:
* 0: Target <OBJECT>
* 1: Magazine Classname <STRING>
* 2: Only partial <BOOL><OPTIONAL>
*
* Return value:
* None
*
* Example:
* [ammo_truck, "32Rnd_155mm_Mo_shells"] call ace_rearm_fnc_addMagazineToSupply
*
* Public: Yes
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_magazineClass", "", [""]], ["_partial", false, [false]]];
if (isNull _target ||
{_magazineClass isEqualTo ""} ||
{GVAR(supply) == 0}) exitWith {};
// With limited supply, we add the caliber to the supply count
if (GVAR(supply) == 1) then {
private _supply = [_target] call FUNC(getSupplyCount);
([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"];
if (!_partial || {GVAR(level) == 1}) then {
[_target, _supply + _cal] call FUNC(setSupplyCount);
} else {
private _magazinePart = ((REARM_COUNT select _idx) / (getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"))) min 1;
[_target, (_supply + (_cal * _magazinePart))] call FUNC(setSupplyCount);
};
};
// With magazine specific supply, we add or update the magazineSupply array
if (GVAR(supply) == 2) then {
private _magazineSupply = _target getVariable [QGVAR(magazineSupply), []];
private _magazineIdx = -1;
{
_x params ["_magazine", "_rounds"];
if ((_magazine isEqualTo _magazineClass)) exitWith {
_magazineIdx = _forEachIndex;
};
} forEach _magazineSupply;
private _roundsPerTransaction = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
if (_partial) then {
_roundsPerTransaction = _roundsPerTransaction min (REARM_COUNT select _idx);
};
if (_magazineIdx == -1) then {
if (count _magazineSupply == 0) then {
_magazineSupply = [[_magazineClass, _roundsPerTransaction]];
} else {
_magazineSupply append [[_magazineClass, _roundsPerTransaction]];
}
} else {
(_magazineSupply select _magazineIdx) params ["", "_rounds"];
_magazineSupply set [_magazineIdx, [_magazineClass, (_rounds + _roundsPerTransaction)]];
};
_target setVariable [QGVAR(magazineSupply), _magazineSupply, true];
};

View File

@ -15,25 +15,24 @@
*/
#include "script_component.hpp"
private ["_vehicleActions", "_actions", "_action", "_vehicles", "_vehicle", "_needToAdd", "_magazineHelper", "_turretPath", "_magazines", "_magazine", "_icon", "_cnt"];
params [["_target", objNull, [objNull]]];
_vehicles = nearestObjects [_target, ["AllVehicles"], 20];
private _vehicles = nearestObjects [_target, ["AllVehicles"], 20];
if (count _vehicles < 2) exitWith {false}; // Rearming needs at least 2 vehicles
_vehicleActions = [];
private _vehicleActions = [];
{
_actions = [];
_vehicle = _x;
_needToAdd = false;
_action = [];
private _actions = [];
private _vehicle = _x;
private _needToAdd = false;
private _action = [];
if !((_vehicle == _target) || (_vehicle isKindOf "CAManBase")) then {
_magazineHelper = [];
private _magazineHelper = [];
{
_turretPath = _x;
_magazines = [_vehicle, _turretPath] call FUNC(getConfigMagazines);
private _turretPath = _x;
private _magazines = [_vehicle, _turretPath] call FUNC(getVehicleMagazines);
{
_magazine = _x;
private _magazine = _x;
_currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath);
if ((_currentMagazines < ([_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines))) && !(_magazine in _magazineHelper)) then {
_action = [_magazine,
@ -43,9 +42,11 @@ _vehicleActions = [];
{true},
{},
[_magazine, _vehicle]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
_magazineHelper pushBack _magazine;
_needToAdd = true;
if (GVAR(supply) == 0 || {(GVAR(supply) == 1) && ([_target, _magazine] call FUNC(hasEnoughSupply))} || {(GVAR(supply) == 2) && ([_target, _magazine] call FUNC(magazineInSupply))}) then {
_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,
@ -55,16 +56,18 @@ _vehicleActions = [];
{true},
{},
[_magazine, _vehicle]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
_magazineHelper pushBack _magazine;
_needToAdd = true;
if (GVAR(supply) == 0 || {(GVAR(supply) == 1) && ([_target, _magazine] call FUNC(hasEnoughSupply))} || {(GVAR(supply) == 2) && ([_target, _magazine] call FUNC(magazineInSupply))}) then {
_actions pushBack [_action, [], _target];
_magazineHelper pushBack _magazine;
_needToAdd = true;
};
};
};
} forEach _magazines;
} forEach REARM_TURRET_PATHS;
};
if (_needToAdd && !(_vehicle getVariable [QGVAR(disabled), false])) then {
_icon = getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "Icon");
private _icon = getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "Icon");
if !((_icon select [0, 1]) == "\") then {
_icon = "";
};

View File

@ -0,0 +1,42 @@
/*
* Author: GitHawk
* Adds all magazines of a vehicle to the supply.
*
* Argument:
* 0: Ammo Truck <OBJECT>
* 1: Vehicle <OBJECT>
* or
* 0: Ammo Truck <OBJECT>
* 1: Vehicle class <STRING>
*
* Return value:
* None
*
* Example:
* [ammo_truck, tank] call ace_rearm_fnc_addVehicleMagazinesToSupply
* [ammo_truck, "B_MBT_01_arty_F"] call ace_rearm_fnc_addVehicleMagazinesToSupply
*
* Public: Yes
*/
#include "script_component.hpp"
params [["_ammoTruck", objNull, [objNull]], ["_vehicle", objNull, [objNull, ""]]];
if (isNull _ammoTruck ||
{typeName _vehicle == "OBJECT" && {isNull _vehicle}}) exitWith {};
private _string = "";
if (typeName _vehicle == "OBJECT") then {
_string = typeOf _vehicle;
};
if (typeName _vehicle == "STRING") then {
_string = _vehicle;
};
if (_string == "") exitWith {[]};
{
private _turretPath = _x;
private _magazines = [_string, _turretPath] call FUNC(getConfigMagazines);
{
[_ammoTruck, _x] call FUNC(addMagazineToSupply);
} forEach _magazines;
} forEach REARM_TURRET_PATHS;

View File

@ -0,0 +1,26 @@
/*
* Author: GitHawk
* Checks if unit can read supply counter.
*
* Arguments:
* 0: Ammo Truck <OBJECT>
* 1: Unit <OBJECT>
*
* Return Value:
* Can read supply counter <BOOL>
*
* Example:
* [truck, player] call ace_rearm_fnc_canReadSupplyCounter
*
* Public: No
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]];
!(isNull _unit ||
{!(_unit isKindOf "CAManBase")} ||
{!local _unit} ||
{!alive _target} ||
{(_target distance _unit) > REARM_ACTION_DISTANCE} ||
{GVAR(supply) == 0})

View File

@ -0,0 +1,26 @@
/*
* Author: GitHawk
* Check if a unit can rearm a vehicle.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Unit <OBJECT>
*
* Return Value:
* Can Pick Up Ammo <BOOL>
*
* Example:
* [player, tank] call ace_rearm_fnc_canRearmVehicle
*
* Public: No
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]];
!(isNull _unit ||
{!(_unit isKindOf "CAManBase")} ||
{!local _unit} ||
{(_target distance _unit) > REARM_ACTION_DISTANCE} ||
{!isNull (_unit getVariable [QGVAR(dummy), objNull])} ||
{GVAR(level) > 0})

View File

@ -22,4 +22,5 @@ params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]];
{!(_unit isKindOf "CAManBase")} ||
{!local _unit} ||
{(_target distance _unit) > REARM_ACTION_DISTANCE} ||
{!isNull (_unit getVariable [QGVAR(dummy), objNull])})
{!isNull (_unit getVariable [QGVAR(dummy), objNull])} ||
{GVAR(level) == 0})

View File

@ -16,12 +16,11 @@
*/
#include "script_component.hpp"
private ["_ammo", "_dummyName", "_dummy"];
params [["_unit", objNull, [objNull]], ["_magazineClass", "", [""]]];
_ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo");
_dummyName = getText (configFile >> "CfgAmmo" >> _ammo >> QGVAR(dummy));
_dummy = objNull;
private _ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo");
private _dummyName = getText (configFile >> "CfgAmmo" >> _ammo >> QGVAR(dummy));
private _dummy = objNull;
if !(_dummyName == "") then {
_dummy = _dummyName createVehicle (position _unit);
} else {

View File

@ -17,10 +17,9 @@
*/
#include "script_component.hpp"
private ["_dummy", "_actionID"];
params [["_unit", objNull, [objNull]], ["_delete", false, [false]], ["_unholster", true, [true]]];
_dummy = _unit getVariable [QGVAR(dummy), objNull];
private _dummy = _unit getVariable [QGVAR(dummy), objNull];
if !(isNull _dummy) then {
detach _dummy;
if (_delete) then {
@ -29,9 +28,8 @@ if !(isNull _dummy) then {
_dummy setVelocity [0,0,-0.1];
};
_unit setVariable [QGVAR(dummy), objNull];
//_unit setVariable [QEGVAR(dragging,isCarrying), false, true]; // breaks things, since it hides interact menu on _target
};
_actionID = _unit getVariable [QGVAR(ReleaseActionID), -1];
private _actionID = _unit getVariable [QGVAR(ReleaseActionID), -1];
if (_actionID != -1) then {
_unit removeAction _actionID;
_unit setVariable [QGVAR(ReleaseActionID), nil];

View File

@ -0,0 +1,48 @@
/*
* Author: GitHawk
* Check whether enough supply is left to take the magazine.
*
* Argument:
* 0: Magazine Classname <STRING>
*
* Return value:
* 0: Caliber information <ARRAY>
* 0: Rounded caliber <NUMBER>
* 1: Caliber index <NUMBER>
*
* Example:
* ["500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_hasEnoughSupply
*
* Public: No
*/
#include "script_component.hpp"
params [["_magazineClass", "", [""]]];
if (_magazineClass isEqualTo "") exitWith {[8, 2]};
private _ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo");
private _tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_caliber");
private _cal = 8;
if (_tmpCal > 0) then {
_cal = _tmpCal;
} else {
_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(caliber));
if (_tmpCal > 0) then {
_cal = _tmpCal;
} else {
diag_log format ["[ACE] ERROR: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)];
if (_ammo isKindOf "BulletBase") then {
_cal = 8;
} else {
_cal = 100;
};
};
};
_cal = round _cal;
private _idx = REARM_CALIBERS find _cal;
if (_idx == -1 ) then {
_idx = 2;
};
[_cal, _idx]

View File

@ -3,30 +3,32 @@
* Returns all magazines a turret can hold according to config.
*
* Arguments:
* 0: Target <OBJECT>
* 0: Vehicle class <STRING>
* 1: Turret Path <ARRAY>
*
* Return Value:
* Magazine classes in TurretPath <ARRAY>
*
* Example:
* [vehicle, [0]] call ace_rearm_fnc_getConfigMagazines
* ["B_MBT_01_arty_F", [0]] call ace_rearm_fnc_getVehicleMagazines
*
* Public: No
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_turretPath", [], [[]]]];
params [["_cfgString", "", [""]], ["_turretPath", [], [[]]]];
if (isNull _target) exitWith {[]};
if (_cfgString == "") exitWith {[]};
_cfg = configFile >> "CfgVehicles" >> (typeOf _target) >> "Turrets";
private _cfg = configFile >> "CfgVehicles" >> _cfgString >> "Turrets";
if !(isClass _cfg) exitWith {[]};
if (count _turretPath == 1) then {
_turretPath params ["_subPath"];
if (_subPath == -1) exitWith {
_cfg = configFile >> "CfgVehicles" >> (typeOf _target);
_cfg = configFile >> "CfgVehicles" >> _cfgString;
};
if (count _cfg > _subPath) then {

View File

@ -17,10 +17,9 @@
*/
#include "script_component.hpp"
private ["_count", "_cfg"];
params [["_target", objNull, [objNull]], ["_turretPath", [], [[]]], ["_magazineClass", "", [""]]];
if (isNull _target) exitWith {0};
_count = {_x == _magazineClass} count ([_target, _turretPath] call FUNC(getConfigMagazines));
private _count = {_x == _magazineClass} count ([_target, _turretPath] call FUNC(getVehicleMagazines));
_count

View File

@ -19,15 +19,14 @@
*/
#include "script_component.hpp"
private ["_return", "_magazines", "_currentMagazines"];
params ["_target", "_magazineClass"];
_return = [false, [], 0];
private _return = [false, [], 0];
{
_magazines = [_target, _x] call FUNC(getConfigMagazines);
private _magazines = [_target, _x] call FUNC(getVehicleMagazines);
if (_magazineClass in _magazines) then {
_currentMagazines = {_x == _magazineClass} count (_target magazinesTurret _x);
private _currentMagazines = {_x == _magazineClass} count (_target magazinesTurret _x);
if ((_target magazineTurretAmmo [_magazineClass, _x]) < getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count")) exitWith {
_return = [true, _x, _currentMagazines];

View File

@ -0,0 +1,27 @@
/*
* Author: GitHawk
* Get the supply count.
*
* Argument:
* 0: Target <OBJECT>
*
* Return value:
* Supply count <NUMBER>
*
* Example:
* [ammo_truck] call ace_rearm_fnc_getSupplyCount
*
* Public: Yes
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]]];
private _supply = _target getVariable QGVAR(currentSupply);
if (isNil "_supply") then {
_supply = getNumber (configFile >> "CfgVehicles" >> typeOf _target >> QGVAR(defaultSupply));
_target setVariable [QGVAR(currentSupply), _supply, true];
};
_supply

View File

@ -0,0 +1,23 @@
/*
* Author: GitHawk, Jonpas
* Returns all magazines a turret can hold according to config.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Turret Path <ARRAY>
*
* Return Value:
* Magazine classes in TurretPath <ARRAY>
*
* Example:
* [vehicle, [0]] call ace_rearm_fnc_getVehicleMagazines
*
* Public: No
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_turretPath", [], [[]]]];
if (isNull _target) exitWith {[]};
([typeOf _target, _turretPath] call FUNC(getConfigMagazines))

View File

@ -0,0 +1,39 @@
/*
* Author: GitHawk
* Check whether enough supply is left to take the magazine.
*
* Argument:
* 0: Target <OBJECT>
* 1: Magazine Classname <STRING>
*
* Return value:
* Enough supply <BOOL>
*
* Example:
* [ammo_truck, "500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_hasEnoughSupply
*
* Public: No
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_magazineClass", "", [""]]];
if (isNull _target ||
{_magazineClass isEqualTo ""}) exitWith {false};
// With infinite supply, there is always enough
if (GVAR(supply) == 0) exitWith {true};
// With magazine specific supply, we need to check stored magazines
if (GVAR(supply) == 2) exitWith {_this call FUNC(magazineInSupply)};
private _supply = [_target] call FUNC(getSupplyCount);
([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"];
// With caliber based rearming, we only need partial supply
if (GVAR(level) == 2) exitWith {
// If REARM_COUNT is bigger than the magazine size, we might get a bigger number than 1
private _magazinePart = ((REARM_COUNT select _idx) / (getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"))) min 1;
(_cal * _magazinePart <= _supply)
};
(_cal <= _supply)

View File

@ -0,0 +1,39 @@
/*
* Author: GitHawk
* Returns true if the magazine is in the current supply
*
* Argument:
* 0: Target <OBJECT>
* 1: Magazine Classname <STRING>
*
* Return value:
* Magazine in supply <BOOL>
*
* Example:
* [ammo_truck, "500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_magazineInSupply
*
* Public: No
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_magazineClass", "", [""]]];
if (isNull _target ||
{_magazineClass isEqualTo ""}) exitWith {false};
// With limited supply, we need to check supply
if (GVAR(supply) == 1) exitWith {_this call FUNC(hasEnoughSupply)};
// With magazine specific supply, we need to check them
if (GVAR(supply) == 2) exitWith {
private _magazineSupply = _target getVariable [QGVAR(magazineSupply), []];
private _magazinePresent = false;
{
_x params ["_magazine", "_rounds"];
if ((_magazine isEqualTo _magazineClass) && (_rounds > 0)) exitWith {_magazinePresent = true; };
false
} count _magazineSupply;
_magazinePresent
};
// With infinite supply, the is always one left
true

View File

@ -16,16 +16,13 @@
*/
#include "script_component.hpp"
private ["_magazineClass"];
params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]];
_dummy = _unit getVariable [QGVAR(dummy), objNull];
private _dummy = _unit getVariable [QGVAR(dummy), objNull];
if !(isNull _dummy) exitWith {};
//_target attachTo [_unit, [0,0.7,0], "pelvis"];
_target attachTo [_unit, [0,1,0], "pelvis"];
{
[[_target, [[-1,0,0],[0,0,1]]], QFUNC(makeDummy), _x] call EFUNC(common,execRemoteFnc);
} count (position _unit nearObjects ["CAManBase", 100]);
_unit setVariable [QGVAR(dummy), _target];
//_unit setVariable [QEGVAR(dragging,isCarrying), true, true]; // breaks things, since it hides interact menu on _target

View File

@ -0,0 +1,75 @@
/*
* Author: GitHawk
* Get the remaining fuel amount
*
* Arguments:
* 0: Ammo Truck <OBJECT>
* 1: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [ammo_truck, player] call ace_rearm_fnc_readSupplyCounter
*
* Public: No
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]];
if (GVAR(supply) == 0) exitWith {};
if (GVAR(supply) == 1) then {
[
5,
[_unit, _target, [_target] call FUNC(getSupplyCount)],
{
params ["_args"];
_args params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]], ["_supplyCount", 0, [0]]];
if (_supplyCount > 0 ) then {
["displayTextStructured", [_unit], [[LSTRING(Hint_RemainingSupplyPoints), _supplyCount], 2, _unit]] call EFUNC(common,targetEvent);
} else {
["displayTextStructured", [_unit], [LSTRING(Hint_EmptySupplyPoints), 2, _unit]] call EFUNC(common,targetEvent);
};
true
},
{true},
localize LSTRING(ReadSupplyCounterAction),
{true},
["isnotinside"]
] call EFUNC(common,progressBar);
} else {
[
5,
[_unit, _target],
{
params ["_args"];
_args params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]]];
private _supply = 1.5;
private _numChars = count (localize LSTRING(Hint_RemainingAmmo));
private _text = "";
private _magazines = _target getVariable QGVAR(magazineSupply);
if !(isNil "_magazines") then {
{
_x params ["_magazineClass", "_rounds"];
private _line = format ["%1: %2", getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), _rounds];
_numChars = _numChars max (count _line);
_text = format ["%1<br/>%2", _text, _line];
_supply = _supply + 0.5;
} forEach _magazines;
diag_log _text;
};
if (_supply > 1.5) then {
["displayTextStructured", [_unit], [[LSTRING(Hint_RemainingAmmo), _text], _supply, _unit, (_numChars/2.9)]] call EFUNC(common,targetEvent);
} else {
["displayTextStructured", [_unit], [LSTRING(Hint_Empty), 2, _unit]] call EFUNC(common,targetEvent);
};
true
},
{true},
localize LSTRING(ReadSupplyCounterAction),
{true},
["isnotinside"]
] call EFUNC(common,progressBar);
};

View File

@ -15,40 +15,17 @@
*/
#include "script_component.hpp"
private ["_magazineClass", "_ammo", "_tmpCal", "_cal", "_idx", "_needRearmMags", "_magazineDisplayName"];
params [["_unit", objNull, [objNull]]];
_dummy = _unit getVariable [QGVAR(dummy), objNull];
private _dummy = _unit getVariable [QGVAR(dummy), objNull];
if (isNull _dummy) exitwith {false};
_magazineClass = _dummy getVariable QGVAR(magazineClass);
private _magazineClass = _dummy getVariable QGVAR(magazineClass);
if (isNil "_magazineClass") exitWith {false};
_ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo");
_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_caliber");
_cal = 8;
if (_tmpCal > 0) then {
_cal = _tmpCal;
} else {
_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(caliber));
if (_tmpCal > 0) then {
_cal = _tmpCal;
} else {
diag_log format ["[ACE] ERROR: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)];
if (_ammo isKindOf "BulletBase") then {
_cal = 8;
} else {
_cal = 100;
};
};
};
_cal = round _cal;
_idx = REARM_CALIBERS find _cal;
if (_idx == -1) then {
_idx = 2;
};
([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"];
// Get magazines that can be rearmed
_needRearmMags = [_target, _magazineClass] call FUNC(getNeedRearmMagazines);
private _needRearmMags = [_target, _magazineClass] call FUNC(getNeedRearmMagazines);
_needRearmMags params ["_needRearm", "_turretPath", "_cnt"];
// Exit if no magazines need rearming
@ -56,9 +33,7 @@ if (!_needRearm) exitWith {
diag_log format ["[ACE] ERROR: Could not find turret for %1 in %2", _magazineClass, typeOf _target];
};
//hint format ["Magazine: %1\nAmmo: %2\nCaliber: %3\nIndex: %4\nTurretPath: %5\nREARM_DURATION_REARM: %6\nCount: %7", _magazine, _ammo, _cal, _idx, _turretPath, (REARM_DURATION_REARM select _idx), (REARM_COUNT select _idx)];
_magazineDisplayName = getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName");
private _magazineDisplayName = getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName");
if (_magazineDisplayName == "") then {
_magazineDisplayName = _magazineClass;
diag_log format ["[ACE] ERROR: Magazine is missing display name [%1]", _magazineClass];

View File

@ -16,11 +16,12 @@
* Public: No
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]], ["_vehicle", objNull, [objNull]]]; // _target is for future possible finite ammo, _unit placeholder
params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]], ["_vehicle", objNull, [objNull]]];
[
10,
_vehicle,
[_target, _vehicle],
FUNC(rearmEntireVehicleSuccess),
"",
format [localize LSTRING(BasicRearmAction), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")],

View File

@ -3,28 +3,30 @@
* Rearm an entire vehicle.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 0: Rearm information <ARRAY>
* 0: Target <OBJECT>
* 1: Vehicle <OBJECT
*
* Return Value:
* None
*
* Example:
* [tank] call ace_rearm_fnc_rearmEntireVehicleSuccess
* [[ammo_truck, tank]] call ace_rearm_fnc_rearmEntireVehicleSuccess
*
* Public: No
*/
#include "script_component.hpp"
private ["_turretPath", "_magazines", "_magazine", "_currentMagazines", "_maxMagazines", "_maxRounds", "_currentRounds"];
params [["_vehicle", objNull, [objNull]]];
params ["_args"];
_args params [["_target", objNull, [objNull]], ["_vehicle", objNull, [objNull]]];
if (isServer) then {
{
_turretOwnerID = _vehicle turretOwner _x;
if (_turretOwnerID == 0) then {
[[_vehicle, _x], QFUNC(rearmEntireVehicleSuccessLocal), _target] call EFUNC(common,execRemoteFnc);
[[_target, _vehicle, _x], QFUNC(rearmEntireVehicleSuccessLocal), _target] call EFUNC(common,execRemoteFnc);
} else {
EGVAR(common,remoteFnc) = [[_vehicle, _x], QFUNC(rearmEntireVehicleSuccessLocal), 0];
EGVAR(common,remoteFnc) = [[_target, _vehicle, _x], QFUNC(rearmEntireVehicleSuccessLocal), 0];
_turretOwnerID publicVariableClient QEGVAR(common,remoteFnc);
};
} count REARM_TURRET_PATHS;

View File

@ -3,29 +3,30 @@
* Rearm an entire turret locally.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: TurretPath <ARRAY>
* 0: Target <OBJECT>
* 1: Vehicle <OBJECT>
* 2: TurretPath <ARRAY>
*
* Return Value:
* None
*
* Example:
* [tank, [0]] call ace_rearm_fnc_rearmEntireVehicleSuccessLocal
* [ammo_truck, tank, [0]] call ace_rearm_fnc_rearmEntireVehicleSuccessLocal
*
* Public: No
*/
#include "script_component.hpp"
private ["_magazines", "_magazine", "_currentMagazines", "_maxMagazines", "_maxRounds", "_currentRounds"];
params [["_vehicle", objNull, [objNull]], ["_turretPath", [], [[]]]];
params [["_target", objNull, [objNull]], ["_vehicle", objNull, [objNull]], ["_turretPath", [], [[]]]];
_magazines = [_vehicle, _turretPath] call FUNC(getConfigMagazines);
private _magazines = [_vehicle, _turretPath] call FUNC(getVehicleMagazines);
if (isNil "_magazines") exitWith {};
{
_magazine = _x;
_currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath);
_maxMagazines = [_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines);
_maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");
_currentRounds = _vehicle magazineTurretAmmo [_magazine, _turretPath];
private _magazine = _x;
private _currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath);
private _maxMagazines = [_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines);
private _maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");
private _currentRounds = _vehicle magazineTurretAmmo [_magazine, _turretPath];
TRACE_7("Rearmed Turret",_vehicle,_turretPath,_currentMagazines,_maxMagazines,_currentRounds,_maxRounds,_magazine);
@ -34,11 +35,27 @@ _magazines = [_vehicle, _turretPath] call FUNC(getConfigMagazines);
_currentMagazines = _currentMagazines + 1;
};
if (_currentMagazines < _maxMagazines) then {
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
for "_idx" from 1 to (_maxMagazines - _currentMagazines) do {
_vehicle addMagazineTurret [_magazine, _turretPath];
private _success = true;
if (GVAR(supply) > 0) then {
_success = [_target, _magazine, (_maxRounds - _currentRounds)] call FUNC(removeMagazineFromSupply);
};
if (_success) then {
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
for "_idx" from 1 to (_maxMagazines - _currentMagazines) do {
_success = true;
if (GVAR(supply) > 0) then {
_success = [_target, _magazine, _maxRounds] call FUNC(removeMagazineFromSupply);
};
_vehicle addMagazineTurret [_magazine, _turretPath];
};
};
} else {
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
private _success = true;
if (GVAR(supply) > 0) then {
_success = [_target, _magazine, (_maxRounds - _currentRounds)] call FUNC(removeMagazineFromSupply);
};
if (_success) then {
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
};
};
} foreach _magazines;

View File

@ -21,7 +21,6 @@
*/
#include "script_component.hpp"
private ["_dummy", "_weaponSelect", "_turretOwnerID"];
params [["_args", [objNull, objNull, [], 0, "", 0], [[]], [6]]];
_args params ["_target", "_unit", "_turretPath", "_numMagazines", "_magazineClass", "_numRounds"];
@ -32,7 +31,7 @@ if (local _unit) then {
};
if (isServer) then {
_turretOwnerID = _target turretOwner _turretPath;
private _turretOwnerID = _target turretOwner _turretPath;
if (_turretOwnerID == 0) then {
[_this, QFUNC(rearmSuccessLocal), _target] call EFUNC(common,execRemoteFnc);
} else {

View File

@ -21,21 +21,19 @@
*/
#include "script_component.hpp"
private ["_rounds", "_currentRounds", "_maxMagazines", "_currentMagazines", "_dummy", "_weaponSelect"];
params [["_args", [objNull, objNull, [], 0, "", 0], [[]], [6]]];
_args params ["_target", "_unit", "_turretPath", "_numMagazines", "_magazineClass", "_numRounds"];
//hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMagazine: %4\nNumRounds: %5\nUnit: %6", _target, _turretPath, _numMagazines, _magazineClass, _numRounds, _unit];
private _rounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
private _currentRounds = 0;
private _maxMagazines = [_target, _turretPath, _magazineClass] call FUNC(getMaxMagazines);
_rounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
_currentRounds = 0;
_maxMagazines = [_target, _turretPath, _magazineClass] call FUNC(getMaxMagazines);
if (_maxMagazines == 1) then {
_currentMagazines = { _x == _magazineClass } count (_target magazinesTurret _turretPath);
private _currentMagazines = { _x == _magazineClass } count (_target magazinesTurret _turretPath);
if (_currentMagazines == 0 && {!(_turretPath isEqualTo [-1])}) then {
// Driver gun will always retain it's magazines
_target addMagazineTurret [_magazineClass, _turretPath];
_target setMagazineTurretAmmo [_magazineClass, 0, _turretPath];
};
if (GVAR(level) == 1) then {
// Fill magazine completely

View File

@ -0,0 +1,86 @@
/*
* Author: GitHawk
* Removes a magazine from the supply.
*
* Argument:
* 0: Target <OBJECT>
* 1: Magazine Classname <STRING>
* 2: Number of Rounds to withdraw <NUMBER><OPTIONAL>
*
* Return value:
* Magazine was removed <BOOL>
*
* Example:
* [ammo_truck, "500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_removeMagazineFromSupply
*
* Public: Yes
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_magazineClass", "", [""]], ["_numRounds", -1, [0]]];
if (isNull _target ||
{_magazineClass isEqualTo ""}) exitWith {false};
private _return = false;
([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"];
if (GVAR(supply) == 1) then {
private _supply = [_target] call FUNC(getSupplyCount);
if (GVAR(level) == 2) then {
// Remove partial magazine supply count
private _rearmAmount = (REARM_COUNT select _idx);
if (_numRounds > 0) then {
_rearmAmount = _numRounds;
};
private _magazinePart = (_rearmAmount / (getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"))) min 1;
if (_supply >= (_cal * _magazinePart)) then {
[_target, (_supply - (_cal * _magazinePart))] call FUNC(setSupplyCount);
_return = true;
};
} else {
// Remove entire magazine supply count
if (_supply >= _cal) then {
[_target, (_supply - _cal)] call FUNC(setSupplyCount);
_return = true;
};
};
};
if (GVAR(supply) == 2) then {
private _magazineSupply = _target getVariable [QGVAR(magazineSupply), []];
private _magazineIdx = -1;
{
_x params ["_magazine"];
if ((_magazine isEqualTo _magazineClass)) exitWith {
_magazineIdx = _forEachIndex;
};
} forEach _magazineSupply;
if (_magazineIdx == -1) exitWith {false};
(_magazineSupply select _magazineIdx) params ["", "_rounds"];
private _configRounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
if (GVAR(level) == 2) then {
// With caliber based rearming, we need to remove the correct amount
private _rearmAmount = (REARM_COUNT select _idx);
if (_numRounds > 0) then {
if (_numRounds > _rearmAmount) then {
_rearmAmount = ceil (_numRounds / _rearmAmount);
};
};
private _roundsPerTransaction = _rearmAmount min _configRounds;
if (_rounds >= _roundsPerTransaction) then {
_magazineSupply set [_magazineIdx, [_magazineClass, (_rounds - _roundsPerTransaction)]];
_target setVariable [QGVAR(magazineSupply), _magazineSupply, true];
_return = true;
};
} else {
// Remove entire magazine
if (_rounds >= _configRounds) then {
_magazineSupply set [_magazineIdx, [_magazineClass, (_rounds - _configRounds)]];
_target setVariable [QGVAR(magazineSupply), _magazineSupply, true];
_return = true;
};
};
};
_return

View File

@ -0,0 +1,23 @@
/*
* Author: GitHawk
* Sets the supply count.
*
* Argument:
* 0: Target <OBJECT>
* 1: Supply Count <NUMBER>
*
* Return value:
* None
*
* Example:
* [ammo_truck, 1000] call ace_rearm_fnc_setSupplyCount
*
* Public: Yes
*/
#include "script_component.hpp"
params [["_target", objNull, [objNull]], ["_supply", 0, [0]]];
if (isNull _target) exitWith {};
_target setVariable [QGVAR(currentSupply), (_supply max 0), true];

View File

@ -16,16 +16,20 @@
*/
#include "script_component.hpp"
private "_dummy";
params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]];
_dummy = _unit getVariable [QGVAR(dummy), objNull];
private _dummy = _unit getVariable [QGVAR(dummy), objNull];
if (isNull _dummy) exitwith {};
[
5,
_unit,
{params ["_unit"]; [_unit, true, true] call FUNC(dropAmmo)},
[_unit, _target, _dummy],
{
params ["_args"];
_args params ["_unit", "_target", "_dummy"];
[_target, (_dummy getVariable [QGVAR(magazineClass), ""]), true] call FUNC(addMagazineToSupply);
[_unit, true, true] call FUNC(dropAmmo);
},
"",
format [localize LSTRING(StoreAmmoAction), getText(configFile >> "CfgMagazines" >> (_dummy getVariable QGVAR(magazineClass)) >> "displayName"), getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")],
{true},

View File

@ -19,34 +19,10 @@
*/
#include "script_component.hpp"
private ["_ammo", "_tmpCal", "_cal", "_idx"];
params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]], ["_args", ["", objNull], [[]]]];
_args params ["_magazineClass", "_vehicle"];
_ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo");
_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_caliber");
_cal = 8;
if (_tmpCal > 0) then {
_cal = _tmpCal;
} else {
_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(caliber));
if (_tmpCal > 0) then {
_cal = _tmpCal;
} else {
diag_log format ["[ACE] ERROR: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)];
if (_ammo isKindOf "BulletBase") then {
_cal = 8;
} else {
_cal = 100;
};
};
};
_cal = round _cal;
_idx = REARM_CALIBERS find _cal;
if (_idx == -1 ) then {
_idx = 2;
};
([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"];
REARM_HOLSTER_WEAPON

View File

@ -18,15 +18,20 @@
*/
#include "script_component.hpp"
private ["_ammo", "_dummyName", "_dummy", "_actionID"];
params [["_args", [objNull, "", objNull], [[]]]];
_args params ["_unit", "_magazineClass", "_target"]; // _target is for future possible finite ammo
params [["_args", [objNull, "", objNull], [[]], 3]];
_args params ["_unit", "_magazineClass", "_target"];
private _success = true;
if (GVAR(supply) > 0) then {
_success = [_target, _magazineClass] call FUNC(removeMagazineFromSupply);
};
if !(_success) exitWith {};
[_unit, "forceWalk", QGVAR(vehRearm), true] call EFUNC(common,statusEffect_set);
_dummy = [_unit, _magazineClass] call FUNC(createDummy);
private _dummy = [_unit, _magazineClass] call FUNC(createDummy);
[_dummy, _unit] call FUNC(pickUpAmmo);
_actionID = _unit addAction [
private _actionID = _unit addAction [
format ["<t color='#FF0000'>%1</t>", localize ELSTRING(dragging,Drop)],
'(_this select 0) call FUNC(dropAmmo)',
nil,

View File

@ -83,10 +83,34 @@
<English>Unlimited ammo supply</English>
<German>Unbegrenzter Munitionsvorat</German>
</Key>
<Key ID="STR_ACE_Rearm_RearmSettings_limited">
<English>Limited ammo supply based on caliber</English>
<German>Begrenzter, kaliberabhängiger Munitionsvorat</German>
</Key>
<Key ID="STR_ACE_Rearm_RearmSettings_magazineSupply">
<English>Only specific Magazines</English>
<German>Nur bestimmte Magazine</German>
</Key>
<Key ID="STR_ACE_Rearm_ReadSupplyCounter">
<English>Check remaining ammunition</English>
<German>Verbleibende Munition prüfen</German>
</Key>
<Key ID="STR_ACE_Rearm_ReadSupplyCounterAction">
<English>Checking remaining ammunition...</English>
<German>Überprüfe verbleibende Munition...</German>
</Key>
<Key ID="STR_ACE_Rearm_Hint_RemainingSupplyPoints">
<English>There is ammunition worth %1 points left.</English>
<German>Es ist noch Munition für %1 Punkte übrig.</German>
</Key>
<Key ID="STR_ACE_Rearm_Hint_RemainingAmmo">
<English>The following ammunition is left:%1</English>
<German>Folgende Munition ist übrig:%1</German>
</Key>
<Key ID="STR_ACE_Rearm_Hint_Empty">
<English>There is no ammunition left.</English>
<German>Es ist keine Munition übrig.</German>
</Key>
<Key ID="STR_ACE_Rearm_Rearm">
<English>Rearm</English>
<German>Aufmunitionieren</German>