Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add disposable launcher framework #1116

Merged
merged 35 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b665fb3
add disposable launcher framework
commy2 Apr 13, 2019
e32c51e
fix and simplify launcher dummy magazine
commy2 Apr 13, 2019
126be1a
rename 2doptics to optics
commy2 Apr 14, 2019
f162b2c
rename 2doptics to optics
commy2 Apr 14, 2019
215f1d4
Merge branch 'rename-optics' into disposable
commy2 Apr 14, 2019
eec0682
add disposable component
commy2 Apr 14, 2019
f2b89fb
manual merge
commy2 Apr 14, 2019
ad59ccb
Merge branch 'master' of https://github.com/CBATeam/CBA_A3 into dispo…
commy2 Apr 15, 2019
f6ba624
disposable arsenal handling
commy2 Apr 19, 2019
09fee91
fix a bug
commy2 Apr 19, 2019
a0144e2
replace with used launcher script
commy2 Apr 19, 2019
1971152
auto drop launcher
commy2 Apr 19, 2019
38c4958
disable secondary weapon magazine slot for disposable launchers
commy2 Apr 20, 2019
3746349
disable secondary weapon magazine slot for disposable launchers
commy2 Apr 20, 2019
6651dbc
fix a thing, delete unused
commy2 Apr 21, 2019
eeaf031
fix addWeapon leeching magazines
commy2 Apr 21, 2019
6cd1016
simplify setUnitLoadout
commy2 Apr 21, 2019
c41f1a2
cba_optics_fnc_addWeapon
commy2 Apr 22, 2019
a5fabe4
cba_optics_fnc_addWeapon
commy2 Apr 22, 2019
32d6488
optimize and keep weapon mode when toggling to pip / normal weapon wi…
commy2 Apr 22, 2019
eec31df
Merge branch 'master' of https://github.com/CBATeam/CBA_A3 into dispo…
commy2 Apr 22, 2019
3931762
report mags of all muzzles
commy2 Apr 23, 2019
b83a61d
replace loaded launcher mags with loaded launchers
commy2 Apr 26, 2019
0db4829
add shared function CBA_fnc_addWeaponWithoutMagazines
commy2 Apr 26, 2019
0496b48
add shared function CBA_fnc_addWeaponWithoutItems
commy2 Apr 26, 2019
e4cdd72
add launcher mags and attachments to dropped container
commy2 Apr 26, 2019
c8e45f1
handle prequipped backpacks
commy2 Apr 26, 2019
ca99085
handle prequipped backpacks stored themselves in cargo
commy2 Apr 26, 2019
72d6838
handle prequipped backpacks stored themselves in cargo
commy2 Apr 26, 2019
6074858
drop used launcher setting
commy2 Apr 26, 2019
e5a51e5
handle Arsenal
commy2 Apr 26, 2019
2d012f7
fix a problem with backpacks
commy2 Apr 26, 2019
2b9454f
manual merge
commy2 Apr 26, 2019
e5bc3ce
support for vehicle optics
commy2 Apr 27, 2019
98c1a12
global to disable mag replacement
commy2 Apr 27, 2019
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/disposable/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\cba\addons\disposable
1 change: 1 addition & 0 deletions addons/disposable/CfgDisposableLaunchers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class CBA_DisposableLaunchers {};
17 changes: 17 additions & 0 deletions addons/disposable/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};

class Extended_DisplayLoad_EventHandlers {
class RscDisplayInventory {
ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayInventory)'));
};
};
7 changes: 7 additions & 0 deletions addons/disposable/CfgFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CfgFunctions {
class CBA {
class Weapons {
PATHTO_FNC(firedDisposable);
};
};
};
9 changes: 9 additions & 0 deletions addons/disposable/CfgMagazines.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CfgMagazines {
class CA_LauncherMagazine;
class CBA_FakeLauncherMagazine: CA_LauncherMagazine {
scope = 1;
ammo = "RocketBase";
count = 0;
allowedSlots[] = {};
};
};
1 change: 1 addition & 0 deletions addons/disposable/XEH_PREP.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PREP(replaceMagazineCargo);
58 changes: 58 additions & 0 deletions addons/disposable/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "script_component.hpp"

ADDON = false;

if (configProperties [configFile >> "CBA_DisposableLaunchers"] isEqualTo []) exitWith {};

#include "XEH_PREP.sqf"

private _fnc_update = {
params ["_unit"];
if (!local _unit) exitWith {};
(GVAR(NormalLaunchers) getVariable secondaryWeapon _unit) params ["_launcher", "_magazine"];

if (!isNil "_launcher") then {
private _launcherItems = secondaryWeaponItems _unit;

_unit addWeapon _launcher;
{
_unit addSecondaryWeaponItem _x;
} forEach _launcherItems;

_unit addWeaponItem [_launcher, _magazine];
};
};

["loadout", _fnc_update] call CBA_fnc_addPlayerEventHandler;
["CAManBase", "InitPost", _fnc_update] call CBA_fnc_addClassEventHandler;
["CAManBase", "Take", _fnc_update] call CBA_fnc_addClassEventHandler;

GVAR(NormalLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(LoadedLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(UsedLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(magazines) = [];
GVAR(MagazineLaunchers) = [] call CBA_fnc_createNamespace;

private _cfgWeapons = configFile >> "CfgWeapons";
private _cfgMagazines = configFile >> "CfgMagazines";

{
private _launcher = configName _x;
private _magazine = configName (_cfgMagazines >> (getArray (_cfgWeapons >> _launcher >> "magazines") select 0));
getArray _x params ["_loadedLauncher", "_usedLauncher"];

GVAR(LoadedLaunchers) setVariable [_launcher, _loadedLauncher];
GVAR(UsedLaunchers) setVariable [_launcher, _usedLauncher];

if (isNil {GVAR(NormalLaunchers) getVariable _loadedLauncher}) then {
GVAR(NormalLaunchers) setVariable [_loadedLauncher, [_launcher, _magazine]];
};

if (GVAR(magazines) pushBackUnique _magazine != -1) then {
GVAR(MagazineLaunchers) setVariable [_magazine, _loadedLauncher];
};
} forEach configProperties [configFile >> "CBA_DisposableLaunchers", "isArray _x"];

["All", "InitPost", FUNC(replaceMagazineCargo)] call CBA_fnc_addClassEventHandler;

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

if (configProperties [configFile >> "CBA_DisposableLaunchers"] isEqualTo []) exitWith {};

#include "XEH_PREP.sqf"

if (!hasInterface) exitWith {};

PREP(initDisplayInventory);
20 changes: 20 additions & 0 deletions addons/disposable/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
author = "$STR_CBA_Author";
name = CSTRING(component);
url = "$STR_CBA_URL";
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"cba_common","cba_events"};
version = VERSION;
authors[] = {"commy2"};
};
};

#include "CfgEventHandlers.hpp"
#include "CfgFunctions.hpp"
#include "CfgDisposableLaunchers.hpp"
#include "CfgMagazines.hpp"
101 changes: 101 additions & 0 deletions addons/disposable/fnc_firedDisposable.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_firedDisposable

Description:
Handles firing a disposable weapon.

Parameters:
_unit - Unit that fired the disposable weapon <OBEJCT>
_launcher - Disposable weapon <STRING>
_muzzle - Muzzle fired by the disposable weapon <STRING>
_mode - Current weapon mode of the disposable weapon <STRING>
_ammo - Ammo fired by the disposable weapon <STRING>
_magazine - Current magazine of the disposable weapon <STRING>
_projectile - Fired projectile <OBEJCT>
_unit - Always same as element 0 <OBEJCT>

Returns:
Nothing.

Examples:
(begin example)
class EventHandlers {
fired = "_this call CBA_fnc_firedDisposable";
};
(end)

Author:
commy2
---------------------------------------------------------------------------- */

params ["_unit", "_launcher", "_muzzle", "", "", "", "_projectile"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be done in a later release, but we should add some way of handling spotting rounds (LAW 80)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is why I don't like dropping the launcher. It needs addWeaponWithAttachmentsCargoGlobal to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe

_wh = "GroundWeaponHolder_Scripted" createVehicle position _unit;
_unit action ["DropWeapon", _wh, _usedLauncher];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DropWeapon is broken. Always has been always will be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addWeaponWithAttachmentsCargo will be fully implemented in 1.96 (contact DLC is 1.94)


private _usedLauncher = GVAR(UsedLaunchers) getVariable _launcher;
if (isNil "_usedLauncher") exitWith {};

[{
params ["_unit", "_launcher", "_usedLauncher", "_projectile"];

// switch to used tube
if (local _unit) then {
private _isSelected = currentWeapon _unit == _launcher;

private _launcherItems = secondaryWeaponItems _unit;
private _launcherMagazines = WEAPON_MAGAZINES(_unit,secondaryWeapon _unit);

_unit addWeapon _usedLauncher;
{
_unit addSecondaryWeaponItem _x;
} forEach _launcherItems;

{
_unit addWeaponItem [_usedLauncher, _x];
} forEach _launcherMagazines;

if (_isSelected) then {
_unit selectWeapon _usedLauncher;
};
};

// automatically drop
[{
params ["_unit", "_usedLauncher", "_projectile"];

// quit if dead or weapon is gone
if (!alive _unit || secondaryWeapon _unit != _usedLauncher) exitWith {true};

if (local _unit && {
if (_unit == call CBA_fnc_currentUnit) then {
cameraView != "GUNNER"
} else {
isNull _projectile
};
}) exitWith {
_unit removeWeapon _usedLauncher;

private _dir = getDir _unit - 180;

private _container = createVehicle ["WeaponHolderSimulated", [0,0,0], [], 0, "CAN_COLLIDE"];
_container addWeaponCargoGlobal [_usedLauncher, 1];

_container setDir (_dir + 90);
_container setPosASL AGLToASL (_unit modelToWorld (_unit selectionPosition "rightshoulder" vectorAdd [0, 0.2, 0.1]));
_container setVelocity (velocity _unit vectorAdd ([sin _dir, cos _dir, 0] vectorMultiply 1.5));

/*
addWeaponWithAttachmentsCargoGlobal [
_usedLauncher,
_silencer, _pointer, _optic, _bipod, [
_magazine1, _ammo1,
_magazine2, _ammo2
],
1];
*/

true // quit
};

false // continue
}, {}, [_unit, _usedLauncher, _projectile]] call CBA_fnc_waitUntilAndExecute;
}, [_unit, _launcher, _usedLauncher, _projectile], 1] call CBA_fnc_waitAndExecute;
14 changes: 14 additions & 0 deletions addons/disposable/fnc_initDisplayInventory.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "script_component.hpp"

params ["_display"];

private _fnc_update = {
params ["_display"];
private _control = _display displayCtrl IDC_FG_SW_MAGAZINE;

private _unit = call CBA_fnc_currentUnit;
_control ctrlEnable isNil {GVAR(LoadedLaunchers) getVariable secondaryWeapon _unit};
};

_display displayAddEventHandler ["MouseMoving", _fnc_update];
_display displayAddEventHandler ["MouseHolding", _fnc_update];
39 changes: 39 additions & 0 deletions addons/disposable/fnc_replaceMagazineCargo.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Internal Function: cba_disposable_fnc_replaceMagazineCargo

Description:
Replaces disposable launcher magazines with loaded disposable launchers.

Parameters:
_box - Any object with cargo <OBJECT>

Returns:
Nothing.

Examples:
(begin example)
_box call cba_disposable_fnc_replaceMagazineCargo
(end)

Author:
commy2
---------------------------------------------------------------------------- */

params ["_box"];
if (!local _box) exitWith {};

if (magazineCargo _box arrayIntersect GVAR(magazines) isEqualTo []) exitWith {};

private _magazines = magazinesAmmoCargo _box;
clearMagazineCargoGlobal _box;

{
_x params ["_magazine", "_ammo"];

if (_magazine in GVAR(magazines)) then {
_box addWeaponCargoGlobal [GVAR(MagazineLaunchers) getVariable _magazine, 1];
} else {
_box addMagazineAmmoCargo [_magazine, 1, _ammo];
};
} forEach _magazines;
22 changes: 22 additions & 0 deletions addons/disposable/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#define COMPONENT disposable
#include "\x\cba\addons\main\script_mod.hpp"

//#define DEBUG_MODE_FULL
//#define DISABLE_COMPILE_CACHE
//#define DEBUG_ENABLED_DISPOSABLE

#ifdef DEBUG_ENABLED_DISPOSABLE
#define DEBUG_MODE_FULL
#endif

#ifdef DEBUG_SETTINGS_DISPOSABLE
#define DEBUG_SETTINGS DEBUG_SETTINGS_DISPOSABLE
#endif

#define DEBUG_MODE_NORMAL
#define DEBUG_SYNCHRONOUS
#include "\x\cba\addons\main\script_macros.hpp"

#include "\a3\ui_f\hpp\defineResincl.inc"

#define WEAPON_MAGAZINES(unit,weapon) (weaponsItems (unit) select {_x select 0 == (weapon)} param [0, []] select {_x isEqualType []})
9 changes: 9 additions & 0 deletions addons/disposable/stringtable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="CBA_A3">
<Package name="Disposable">
<Key ID="STR_CBA_Disposable_Component">
<English>Community Base Addons - Disposable Weapons</English>
<German>Community Base Addons - Einwegwaffen</German>
</Key>
</Package>
</Project>
3 changes: 2 additions & 1 deletion addons/main/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class CfgPatches {
"cba_jam",
"cba_ui",
"cba_versioning",
"cba_optics"
"cba_optics",
"cba_disposable"
};
versionDesc = "C.B.A.";
VERSION_CONFIG;
Expand Down
2 changes: 1 addition & 1 deletion addons/optics/RscInGameUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RscInGameUI {
};

class CBA_ScriptedOptic: RscWeaponZeroing {
onLoad = QUOTE(call FUNC(loadScriptedOptic));
onLoad = QUOTE([ARR_2(_this select 0, true)] call FUNC(loadScriptedOptic));
controls[] = {"CA_FOVMode","ScopeBlack","Reticle","BodyNight","BodyDay","TrippleHeadLeft","TrippleHeadRight","CA_Zeroing","Magnification","ActiveDisplayHelper"};

// Idea by Taosenai. This control can be used to determine whether the scope or the collimator is used.
Expand Down
1 change: 1 addition & 0 deletions addons/optics/XEH_PREP.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ PREP(changeCarryHandleOpticClass);
PREP(setOpticMagnification);
PREP(setOpticMagnificationHelper);
PREP(setOpticMagnificationHelperZeroing);
PREP(addWeapon);
12 changes: 7 additions & 5 deletions addons/optics/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include "script_component.hpp"

ADDON = false;

#include "initSettings.sqf"

if (!hasInterface) exitWith {};
if (configProperties [configFile >> "CBA_PIPItems"] isEqualTo []) exitWith {};
if (configProperties [configFile >> "CBA_CarryHandleTypes"] isEqualTo []) exitWith {};

ADDON = false;
if (configProperties [configFile >> "CBA_PIPItems"] isEqualTo [] && {
configProperties [configFile >> "CBA_CarryHandleTypes"] isEqualTo []
}) exitWith {};

#include "XEH_PREP.sqf"

if (!hasInterface) exitWith {};

QGVAR(pauseOpticLayer) cutText ["", "PLAIN"];

GVAR(camera) = objNull;
Expand Down
11 changes: 6 additions & 5 deletions addons/optics/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "script_component.hpp"

if (configProperties [configFile >> "CBA_PIPItems"] isEqualTo [] && {
configProperties [configFile >> "CBA_CarryHandleTypes"] isEqualTo []
}) exitWith {};

#include "XEH_PREP.sqf"

if (!hasInterface) exitWith {};

// Do not move this below these checks, or this missing function can be exploited.
commy2 marked this conversation as resolved.
Show resolved Hide resolved
PREP(initDisplayInterrupt);

if (configProperties [configFile >> "CBA_PIPItems"] isEqualTo []) exitWith {};
if (configProperties [configFile >> "CBA_CarryHandleTypes"] isEqualTo []) exitWith {};

#include "XEH_PREP.sqf"
2 changes: 1 addition & 1 deletion addons/optics/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"cba_common","cba_jr"};
requiredAddons[] = {"cba_common","cba_events","cba_jr"};
version = VERSION;
authors[] = {"commy2"};
};
Expand Down
Loading