-
Notifications
You must be signed in to change notification settings - Fork 148
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
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
b665fb3
add disposable launcher framework
commy2 e32c51e
fix and simplify launcher dummy magazine
commy2 126be1a
rename 2doptics to optics
commy2 f162b2c
rename 2doptics to optics
commy2 215f1d4
Merge branch 'rename-optics' into disposable
commy2 eec0682
add disposable component
commy2 f2b89fb
manual merge
commy2 ad59ccb
Merge branch 'master' of https://github.com/CBATeam/CBA_A3 into dispo…
commy2 f6ba624
disposable arsenal handling
commy2 09fee91
fix a bug
commy2 a0144e2
replace with used launcher script
commy2 1971152
auto drop launcher
commy2 38c4958
disable secondary weapon magazine slot for disposable launchers
commy2 3746349
disable secondary weapon magazine slot for disposable launchers
commy2 6651dbc
fix a thing, delete unused
commy2 eeaf031
fix addWeapon leeching magazines
commy2 6cd1016
simplify setUnitLoadout
commy2 c41f1a2
cba_optics_fnc_addWeapon
commy2 a5fabe4
cba_optics_fnc_addWeapon
commy2 32d6488
optimize and keep weapon mode when toggling to pip / normal weapon wi…
commy2 eec31df
Merge branch 'master' of https://github.com/CBATeam/CBA_A3 into dispo…
commy2 3931762
report mags of all muzzles
commy2 b83a61d
replace loaded launcher mags with loaded launchers
commy2 0db4829
add shared function CBA_fnc_addWeaponWithoutMagazines
commy2 0496b48
add shared function CBA_fnc_addWeaponWithoutItems
commy2 e4cdd72
add launcher mags and attachments to dropped container
commy2 c8e45f1
handle prequipped backpacks
commy2 ca99085
handle prequipped backpacks stored themselves in cargo
commy2 72d6838
handle prequipped backpacks stored themselves in cargo
commy2 6074858
drop used launcher setting
commy2 e5a51e5
handle Arsenal
commy2 2d012f7
fix a problem with backpacks
commy2 2b9454f
manual merge
commy2 e5bc3ce
support for vehicle optics
commy2 98c1a12
global to disable mag replacement
commy2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "script_component.hpp" | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_addWeaponWithoutItems | ||
|
||
Description: | ||
Adds weapon to unit without attachments and without taking a magazine. | ||
|
||
Does not work on vehicles. | ||
Attempts to keep magazine ids for unrelated magazines. | ||
|
||
Parameters: | ||
_unit - Unit to add the weapon to <OBEJCT> | ||
_weapon - Weapon to add <STRING> | ||
|
||
Returns: | ||
Nothing. | ||
|
||
Examples: | ||
(begin example) | ||
[player, "arifle_mx_F"] CBA_fnc_addWeaponWithoutItems; | ||
(end) | ||
|
||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
|
||
params ["_unit", "_weapon"]; | ||
|
||
// config case | ||
private _compatibleMagazines = [_weapon, true] call CBA_fnc_compatibleMagazines; | ||
|
||
private _uniform = uniformContainer _unit; | ||
private _uniformMagazines = magazinesAmmoCargo _uniform select { | ||
(_x select 0) in _compatibleMagazines // also config case | ||
}; | ||
|
||
private _vest = vestContainer _unit; | ||
private _vestMagazines = magazinesAmmoCargo _vest select { | ||
(_x select 0) in _compatibleMagazines | ||
}; | ||
|
||
private _backpack = backpackContainer _unit; | ||
private _backpackMagazines = magazinesAmmoCargo _backpack select { | ||
(_x select 0) in _compatibleMagazines | ||
}; | ||
|
||
{ | ||
_unit removeMagazines _x; | ||
} forEach _compatibleMagazines; | ||
|
||
_unit addWeapon _weapon; | ||
|
||
if (primaryWeapon _unit == _weapon) then { | ||
removeAllPrimaryWeaponItems _unit; | ||
}; | ||
|
||
if (secondaryWeapon _unit == _weapon) then { | ||
// 'removeAllSecondaryWeaponItems' does not exist | ||
{ | ||
_unit removeSecondaryWeaponItem _x; | ||
} forEach secondaryWeaponItems _unit; | ||
}; | ||
|
||
if (handgunWeapon _unit == _weapon) then { | ||
removeAllHandgunItems _unit; | ||
}; | ||
|
||
{ | ||
_x params ["_magazine", "_ammo"]; | ||
_uniform addMagazineAmmoCargo [_magazine, 1, _ammo]; | ||
} forEach _uniformMagazines; | ||
|
||
{ | ||
_x params ["_magazine", "_ammo"]; | ||
_vest addMagazineAmmoCargo [_magazine, 1, _ammo]; | ||
} forEach _vestMagazines; | ||
|
||
{ | ||
_x params ["_magazine", "_ammo"]; | ||
_backpack addMagazineAmmoCargo [_magazine, 1, _ammo]; | ||
} forEach _backpackMagazines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x\cba\addons\disposable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class CBA_DisposableLaunchers {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)')); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class CfgFunctions { | ||
class CBA { | ||
class Weapons { | ||
PATHTO_FNC(firedDisposable); | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] = {}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PREP(replaceMagazineCargo); | ||
PREP(changeDisposableLauncherClass); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "script_component.hpp" | ||
|
||
ADDON = false; | ||
|
||
#include "initSettings.sqf" | ||
|
||
if (configProperties [configFile >> "CBA_DisposableLaunchers"] isEqualTo []) exitWith {}; | ||
|
||
#include "XEH_PREP.sqf" | ||
|
||
["loadout", { | ||
params ["_unit"]; | ||
_unit call FUNC(changeDisposableLauncherClass); | ||
}] call CBA_fnc_addPlayerEventHandler; | ||
|
||
["CAManBase", "InitPost", { | ||
params ["_unit"]; | ||
_unit call FUNC(changeDisposableLauncherClass); | ||
}] call CBA_fnc_addClassEventHandler; | ||
|
||
["CAManBase", "Take", { | ||
params ["_unit"]; | ||
_unit call FUNC(changeDisposableLauncherClass); | ||
}] 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "script_component.hpp" | ||
|
||
// Do not move this below these checks, or this missing function can be exploited. | ||
PREP(initDisplayInventory); | ||
|
||
if (configProperties [configFile >> "CBA_DisposableLaunchers"] isEqualTo []) exitWith {}; | ||
|
||
#include "XEH_PREP.sqf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "script_component.hpp" | ||
/* ---------------------------------------------------------------------------- | ||
Internal Function: cba_disposable_fnc_changeDisposableLauncherClass | ||
|
||
Description: | ||
Switch loaded launcher class to class that can be fired with magazine. | ||
|
||
Parameters: | ||
_unit - The avatar <OBJECT> | ||
|
||
Returns: | ||
Nothing. | ||
|
||
Examples: | ||
(begin example) | ||
player call cba_disposable_fnc_changeDisposableLauncherClass; | ||
(end) | ||
|
||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
|
||
params ["_unit"]; | ||
if (!local _unit) exitWith {}; | ||
|
||
private _launcher = GVAR(NormalLaunchers) getVariable secondaryWeapon _unit; | ||
|
||
if (!isNil "_launcher") then { | ||
_launcher params ["_launcher", "_magazine"]; | ||
|
||
private _launcherItems = secondaryWeaponItems _unit; | ||
private _launcherMagazines = WEAPON_MAGAZINES(_unit,secondaryWeapon _unit); | ||
|
||
if (!isNil "_magazine") then { | ||
_launcherMagazines pushBack _magazine; | ||
}; | ||
|
||
[_unit, _launcher] call CBA_fnc_addWeaponWithoutItems; | ||
|
||
{ | ||
_unit addSecondaryWeaponItem _x; | ||
} forEach _launcherItems; | ||
|
||
{ | ||
_unit addWeaponItem [_launcher, _x]; | ||
} forEach _launcherMagazines; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#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"]; | ||
|
||
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, _usedLauncher] call CBA_fnc_addWeaponWithoutItems; | ||
|
||
if (_isSelected) then { | ||
_unit selectWeapon _usedLauncher; | ||
}; | ||
|
||
{ | ||
_unit addSecondaryWeaponItem _x; | ||
} forEach _launcherItems; | ||
|
||
{ | ||
_unit addWeaponItem [_usedLauncher, _x]; | ||
} forEach _launcherMagazines; | ||
}; | ||
|
||
// automatically drop | ||
if (GVAR(dropUsedLauncher) isEqualTo 0) exitWith {}; | ||
|
||
[{ | ||
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 { | ||
if (GVAR(dropUsedLauncher) isEqualTo 1 && {_unit == call CBA_fnc_currentUnit}) exitWith {true}; | ||
|
||
private _launcherItems = secondaryWeaponItems _unit; | ||
private _launcherMagazines = WEAPON_MAGAZINES(_unit,secondaryWeapon _unit); | ||
|
||
_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)); | ||
|
||
/* | ||
_container addWeaponWithAttachmentsCargoGlobal [ | ||
_usedLauncher, | ||
_silencer, _pointer, _optic, _bipod, [ | ||
_magazine1, _ammo1, | ||
_magazine2, _ammo2 | ||
], | ||
1]; | ||
*/ | ||
|
||
{ | ||
_container addItemCargoGlobal [_x, 1]; | ||
} forEach _launcherItems; | ||
|
||
{ | ||
_x params ["_magazine", "_ammo"]; | ||
|
||
if (_ammo > 0) then { | ||
_container addMagazineAmmoCargo [_x, 1, _ammo]; | ||
}; | ||
} forEach _launcherMagazines; | ||
|
||
true // quit | ||
}; | ||
|
||
false // continue | ||
}, {}, [_unit, _usedLauncher, _projectile]] call CBA_fnc_waitUntilAndExecute; | ||
}, [_unit, _launcher, _usedLauncher, _projectile], 1] call CBA_fnc_waitAndExecute; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)