Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/setvehicleammo/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\ace\addons\setvehicleammo
95 changes: 95 additions & 0 deletions addons/setvehicleammo/CfgEden.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
class ctrlToolbox;
class ctrlStatic;
class ctrlListNBox;
class ctrlTree;
class ctrlXSliderH;


class Cfg3DEN {
class Attributes {
class Default;
class TitleWide: Default {
class Controls {
class Title;
};
};
class GVAR(vehAmmoAttribute): TitleWide {
attributeLoad = QUOTE([ARR_2(_this,_value)] call FUNC(attributeLoad));
attributeSave = QUOTE([_this] call FUNC(attributeSave));

h = "(15 * 5 + 1) * (pixelH * pixelGrid * 0.5)";
class Controls: Controls {
class Type: ctrlToolbox {
idc = 100;
x = "5 * (pixelW * pixelGrid * 0.5)";
y = "0 * 5 * (pixelH * pixelGrid * 0.5)";
w = "( 48 + 82 - 5) * (pixelW * pixelGrid * 0.5)";
h = "1 * 5 * (pixelH * pixelGrid * 0.5)";
rows = 1;
columns = 2;
strings[] = {"Default","Custom"};
};
class ListBackground: ctrlStatic {
x = "5 * (pixelW * pixelGrid * 0.5)";
y = "1 * 5 * (pixelH * pixelGrid * 0.5)";
w = "( 48 + 82 - 5) * (pixelW * pixelGrid * 0.5)";
h = "13 * 5 * (pixelH * pixelGrid * 0.5)";
colorBackground[] = {1,1,1,0.1};
};
class List: ctrlTree {
idc = 101;
x = "5 * (pixelW * pixelGrid * 0.5)";
y = "1 * 5 * (pixelH * pixelGrid * 0.5)";
w = "( 48 + 82 - 5) * (pixelW * pixelGrid * 0.5)";
h = "13 * 5 * (pixelH * pixelGrid * 0.5)";
};
class ammoSlider: ctrlXSliderH {
idc = 102;
x = "5 * (pixelW * pixelGrid * 0.5)";
y = "14 * 5 * (pixelH * pixelGrid * 0.5)";
w = "( 48 + 82 - 5) * (pixelW * pixelGrid * 0.5)";
h = "1 * 5 * (pixelH * pixelGrid * 0.5)";
};
};
};
};

class Object {
class AttributeCategories {
class ace_attributes {
class Attributes {
class GVAR(vehicleCustomizationSet) {
displayName = "Copy Custom Garage Apperence";
tooltip = "Apply this vehicle's camo customiation to ALL other vehicles spawned with the SAME classname";
property = QGVAR(vehicleCustomizationSet);
control = "Checkbox";
expression = QUOTE(if (_value) then { call FUNC(vehicleCustomizationSet) });
typeName = "BOOL";
condition = "objectVehicle";
defaultValue = "(false)";
};
class GVAR(rearmCustom) {
displayName = "Set as Rearm-Scripted Loadouts";
tooltip = "ACE-Rearm will try to rearm the custom loadout instead of the config default";
property = QGVAR(rearmCustom);
control = "Checkbox";
expression = QUOTE(if (_value) then { _this setVariable [ARR_3('ace_rearm_scriptedLoadout',true,true)] });
typeName = "BOOL";
condition = "objectVehicle";
defaultValue = "(false)";
};
class ADDON {
displayName = "Set Vehicle Ammo";
tooltip = "";
property = QGVAR(vehAmmoAttribute);
control = QGVAR(vehAmmoAttribute);
defaultValue = "''";
typeName = "STRING";
expression = QUOTE([ARR_2(_this,_value)] call FUNC(initVehicle));
condition = "objectVehicle";
};
};
};
};
};
};
11 changes: 11 additions & 0 deletions addons/setvehicleammo/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};
7 changes: 7 additions & 0 deletions addons/setvehicleammo/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TRACE_1("",QUOTE(ADDON));

PREP(attributeLoad);
PREP(attributeSave);
PREP(initVehicle);

PREP(vehicleCustomizationSet);
33 changes: 33 additions & 0 deletions addons/setvehicleammo/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "script_component.hpp"

ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

// Vehicle customization - order is a little weird
// preInit, 3den-vehicleCustomizationSet, 3den-bisGarage, vehicleCustomizationSet's nextFrame, 1 sec delay (pubVar), 5 sec delay (apply)

if (isServer) then {
GVAR(vehicleCustomization) = createHashMap;
[{
publicVariable QGVAR(vehicleCustomization);
}, [], 1] call CBA_fnc_waitAndExecute;
};
[{
if (isNil QGVAR(vehicleCustomization)) exitWith { ERROR("hash nil?") };
if ((count GVAR(vehicleCustomization)) == 0) exitWith {};
INFO_1("applying %1 vehicle customizations",count GVAR(vehicleCustomization));
{
[_x, "InitPost", {
params ["_vehicle"];
if ((!alive _vehicle) || {!local _vehicle}) exitWith {};
private _customization = GVAR(vehicleCustomization) getOrDefault [typeOf _vehicle, []];
private _ret = [_vehicle, _customization select 0, _customization select 1] call bis_fnc_initVehicle;
TRACE_3("applied",typeOf _vehicle,_ret,_customization);
}, false, nil, true] call CBA_fnc_addClassEventHandler; // no inheritance, apply retro
} forEach GVAR(vehicleCustomization);
}, [], 5] call CBA_fnc_waitAndExecute;

ADDON = true;
3 changes: 3 additions & 0 deletions addons/setvehicleammo/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
16 changes: 16 additions & 0 deletions addons/setvehicleammo/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
author = ECSTRING(common,ACETeam);
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};

#include "CfgEden.hpp"
#include "CfgEventHandlers.hpp"
220 changes: 220 additions & 0 deletions addons/setvehicleammo/functions/fnc_attributeLoad.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#include "..\script_component.hpp"

params ["_control", "_loadoutValue"];
TRACE_2("params",_control,_loadoutValue);

GVAR(turretMagsArray) = [];
GVAR(defaultLoad) = [];
GVAR(deltaLoad) = [];
GVAR(selectedTurretPath) = [];
GVAR(selectedTreePath) = [];
GVAR(selectedMagazine) = "";


//Parse string into a delta loadout array:
if (_loadoutValue isEqualTo true) then {_loadoutValue = ""}; //why?
if (_loadoutValue != "") then {
_loadoutValue = call compile _loadoutValue;
if (_loadoutValue isEqualType []) then {
GVAR(deltaLoad) = _loadoutValue;
};
};

private _entity = (get3DENSelected "object") select 0;
TRACE_2("",_entity,typeOf _entity);

private _enableLBChangedEH = {
params ["_control", "_selection"];
TRACE_2("lbChanged eh",_control,_selection);
if (_selection == 0) then {
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) ctrlEnable false;
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) ctrlSetFade 0.5;
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) ctrlCommit 0;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlEnable false;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlSetFade 0.5;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlCommit 0;
} else {
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) ctrlEnable true;
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) ctrlSetFade 0;
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) ctrlCommit 0;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlEnable true;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlSetFade 0;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlCommit 0;
};
};
(_control controlsGroupCtrl 100) ctrlAddEventHandler ["ToolBoxSelChanged", _enableLBChangedEH];

if (GVAR(deltaLoad) isEqualTo []) then {
(_control controlsGroupCtrl 100) lbSetCurSel 0;
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) ctrlEnable false;
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) ctrlSetFade 0.5;
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) ctrlCommit 0;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlEnable false;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlSetFade 0.5;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlCommit 0;

} else {
(_control controlsGroupCtrl 100) lbSetCurSel 1;
};

private _treeSelChangedEH = {
params ["_control", "_newPath"];
TRACE_2("lbChanged eh",_control,_newPath);

private _mag = GVAR(turretMagsArray);
private _path = [];
{
_mag = _mag select _x;
if (_forEachIndex == 0) then {
_path = _mag select 0;
_mag = _mag select 1;
};
} forEach _newPath;
TRACE_1("",_mag);

if (_mag isEqualType "") then {
GVAR(selectedTurretPath) = _path;
GVAR(selectedMagazine) = _mag;
GVAR(selectedTreePath) = _newPath;
private _magCount = 0;
{
_x params ["_xPath", "_xMag", "_xCount"];
if ((_xPath isEqualTo GVAR(selectedTurretPath)) && {_xMag == GVAR(selectedMagazine)}) exitWith {
_magCount = _xCount;
};
} forEach GVAR(defaultLoad);
{
_x params ["_xPath", "_xMag", "_xCount"];
if ((_xPath isEqualTo GVAR(selectedTurretPath)) && {_xMag == GVAR(selectedMagazine)}) exitWith {
_magCount = _magCount + _xCount;
};
} forEach GVAR(deltaLoad);

((ctrlParentControlsGroup _control) controlsGroupCtrl 102) sliderSetRange [0, 10];
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) sliderSetPosition _magCount;

((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlEnable true;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlSetFade 0;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlCommit 0;
} else {
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlEnable false;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlSetFade 1;
((ctrlParentControlsGroup _control) controlsGroupCtrl 102) ctrlCommit 0;
};
};
(_control controlsGroupCtrl 101) ctrlAddEventHandler ["TreeSelChanged", _treeSelChangedEH];

private _sliderChangedEH = {
params ["_control", "_sliderValue"];
TRACE_2("lbChanged eh",_control,_sliderValue);

_sliderValue = (round (_sliderValue * 10)) / 10;

private _defaultCount = 0;
{
_x params ["_xPath", "_xMag", "_xCount"];
if ((_xPath isEqualTo GVAR(selectedTurretPath)) && {_xMag == GVAR(selectedMagazine)}) exitWith {
_defaultCount = _xCount;
};
} forEach GVAR(defaultLoad);

private _delta = _sliderValue - _defaultCount;
private _found = false;
{
_x params ["_xPath", "_xMag", "_xCount"];
if ((_xPath isEqualTo GVAR(selectedTurretPath)) && {_xMag == GVAR(selectedMagazine)}) exitWith {
_found = true;
_x set [2, _delta];
};
} forEach GVAR(deltaLoad);
if (!_found) then {
GVAR(deltaLoad) pushBack [GVAR(selectedTurretPath), GVAR(selectedMagazine), _delta];
};

TRACE_3("",_delta,GVAR(selectedMagazine),GVAR(selectedTreePath));

private _rounds = round (_sliderValue * getNumber (configFile >> "CfgMagazines" >> GVAR(selectedMagazine) >> "count"));
private _text = format ["%1 [%2x = %3rnds]", GVAR(selectedMagazine), _sliderValue, _rounds];
((ctrlParentControlsGroup _control) controlsGroupCtrl 101) tvSetText [GVAR(selectedTreePath), _text];
};
(_control controlsGroupCtrl 102) ctrlAddEventHandler ["SliderPosChanged", _sliderChangedEH];


private _config = configFile >> "CfgVehicles" >> (typeOf _entity);
private _turrets = allTurrets _entity;
TRACE_1("",_turrets);


private _addWeaponSystem = {
params ["_config", "_path", "_name"];
private _weapons = getArray (_config >> "weapons");
private _magazines = getArray (_config >> "magazines");
TRACE_3("",_weapons,_magazines,_config);
if (_weapons isEqualTo []) exitWith {};

{
private _magToAdd = _x;
private _found = false;
{
_x params ["_xPath", "_xMag", "_xCount"];
if ((_xPath isEqualTo _path) && {_xMag == _magToAdd}) exitWith {
_found = true;
_x set [2, (_xCount + 1)];
};
} forEach GVAR(defaultLoad);
if (!_found) then {
GVAR(defaultLoad) pushBack [_path, _magToAdd, 1];
};
} forEach _magazines;

private _tvIndexTurret = (_control controlsGroupCtrl 101) tvAdd [ [], _name];
(_control controlsGroupCtrl 101) tvExpand [_tvIndexTurret];

private _index = GVAR(turretMagsArray) pushBack [_path, []];

{
private _weapon = _x;
private _muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles");
private _weaponMagazines = compatibleMagazines _weapon;

((GVAR(turretMagsArray) select _index) select 1) pushBack _weaponMagazines;

{
if (_x != "this") then {
_weaponMagazines append (getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines"));
};
false
} count _muzzles;

private _tvIndexWeapon = (_control controlsGroupCtrl 101) tvAdd [[_tvIndexTurret], _x];
(_control controlsGroupCtrl 101) tvExpand [_tvIndexTurret, _tvIndexWeapon];
{
private _magToAdd = _x;
private _magCount = 0;
{
_x params ["_xPath", "_xMag", "_xCount"];
if ((_xPath isEqualTo _path) && {_xMag == _magToAdd}) exitWith {
_magCount = _xCount;
};
} forEach GVAR(defaultLoad);
{
_x params ["_xPath", "_xMag", "_xCount"];
if ((_xPath isEqualTo _path) && {_xMag == _magToAdd}) exitWith {
_magCount = _magCount + _xCount;
};
} forEach GVAR(deltaLoad);

private _rounds = round (_magCount * getNumber (configFile >> "CfgMagazines" >> _magToAdd >> "count"));
private _text = format ["%1 [%2x = %3rnds]", _magToAdd, _magCount, _rounds];
(_control controlsGroupCtrl 101) tvAdd [[_tvIndexTurret, _tvIndexWeapon], _text];
} forEach _weaponMagazines;
} forEach _weapons;
};

[_config, [-1], "Pilot"] call _addWeaponSystem;

{
private _turretConfig = [_config, _x] call ace_common_fnc_getTurretConfigPath;
TRACE_2("",_x,_turretConfig);
[_turretConfig, _x, (format ["Turret %1", _x])] call _addWeaponSystem;
} forEach _turrets;
Loading
Loading