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 Unpack Static Weapon module #378

Open
wants to merge 75 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
450aeac
Add Unpack Static Weapon module
ampersand38 May 14, 2020
e5c9938
Extraneous file deleted
ampersand38 May 14, 2020
70caa97
Tabs to spaces
ampersand38 May 14, 2020
569249c
Update fnc_unpackStaticWeapon.sqf
ampersand38 May 14, 2020
22936d8
Add icon
ampersand38 May 14, 2020
92b8a15
Square icon
ampersand38 May 14, 2020
922e4b5
Update addons/modules/functions/fnc_moduleUnpackStaticWeapon.sqf
ampersand38 May 16, 2020
ca86fe4
Update addons/modules/functions/fnc_unpackStaticWeapon.sqf
ampersand38 May 16, 2020
f845df7
Update addons/modules/functions/fnc_unpackStaticWeapon.sqf
ampersand38 May 17, 2020
60631fc
unpackStaticWeapon function moved to ai component
ampersand38 May 17, 2020
8a4194a
Text elements added to stringtable
ampersand38 May 17, 2020
028ac3a
Update fnc_moduleUnpackStaticWeapon.sqf
ampersand38 May 17, 2020
cc5dcc7
Changed `remoteExec` to `CBA_fnc_targetEvent`.
ampersand38 May 17, 2020
4809634
Localize
ampersand38 May 21, 2020
5a71f89
Missing `private`
ampersand38 Jun 17, 2020
b2274af
isNull
ampersand38 Jun 17, 2020
026669a
replace select with if
ampersand38 Jun 17, 2020
16d46e9
Don't run if position selection cancelled
ampersand38 Jun 17, 2020
9a7569d
Replace remoteExec with CBA_fnc_targetEvent
ampersand38 Jun 17, 2020
7770381
orderGetIn instead of moveInGunner
ampersand38 Jun 23, 2020
9c15718
Check gunner/assistant distance, pfh
ampersand38 Jun 23, 2020
53be889
Add toLower in backpack check
ampersand38 Jun 29, 2020
cac53b1
if condition, moved pfh to ai fnc
ampersand38 Jun 29, 2020
9f5f346
Add back pfh skip
ampersand38 Jun 29, 2020
222c09d
Update addons/ai/functions/fnc_unpackStaticWeapon.sqf
ampersand38 Jul 7, 2020
dd7d74c
Removed unused code
ampersand38 Jul 7, 2020
3938ea9
Separated PFH from actual unpack to reduce repeated code
ampersand38 Jul 7, 2020
c9935b9
Update addons/ai/functions/fnc_unpackStaticWeapon.sqf
ampersand38 Jul 23, 2020
5c71128
Update addons/ai/functions/fnc_unpackStaticWeaponPFH.sqf
ampersand38 Jul 23, 2020
cbc3e5f
Comment case
ampersand38 Jul 23, 2020
1b02ccf
"Static Weapon Facing" to "Weapon Direction"
ampersand38 Jul 28, 2020
a6835aa
Suggested changes
ampersand38 Jul 28, 2020
b94d4a7
Only one example.
ampersand38 Aug 5, 2020
0ede921
Use full word for variable name: _group.
ampersand38 Aug 5, 2020
f6840c4
Positions to work off ASL
ampersand38 Aug 5, 2020
6646843
Remove magic numbers
ampersand38 Aug 5, 2020
a00352d
move ! into paren
ampersand38 Aug 5, 2020
3d3eafb
remove paren around unary
ampersand38 Aug 5, 2020
e2265cd
remove spaces around braces
ampersand38 Aug 5, 2020
dcaa2d9
move config type check into _fnc_getCompatibleBases
ampersand38 Aug 5, 2020
365244b
_mousePosASL to _position
ampersand38 Aug 5, 2020
b0db71f
_endTime for cleaner comparison
ampersand38 Aug 5, 2020
6451606
Move the ! into the parentheses.
ampersand38 Aug 5, 2020
142a0b5
Spaces after commas in arrays.
ampersand38 Aug 5, 2020
6718095
no need to declare _group
ampersand38 Aug 5, 2020
ca6ebc2
removed blank line
ampersand38 Aug 5, 2020
196e144
> to >=
ampersand38 Aug 5, 2020
474f4ec
fix Move the ! into the parentheses.
ampersand38 Aug 5, 2020
7204ff0
Change lower case to config case
ampersand38 Aug 5, 2020
2d2465f
run unpackStaticWeapon first, then pfh if needed
ampersand38 Aug 5, 2020
f8dc791
distance check to <= 3
ampersand38 Aug 5, 2020
283d60d
Comment case
ampersand38 Aug 5, 2020
d98c457
Should not restore FSM if it was already disabled. Use checkAIFeature
ampersand38 Aug 5, 2020
4fc2b7a
gunner watch targetPos while assistant runs up
ampersand38 Aug 5, 2020
3dd7367
Add weapon to curator
ampersand38 Aug 5, 2020
5c72ec3
No parentheses around unary commands.
ampersand38 Aug 5, 2020
39ef2e8
store nextMoveTime in PFH args
ampersand38 Aug 5, 2020
dfe1f17
Modules List documentation
ampersand38 Aug 11, 2020
10ce856
Move defines below docs
ampersand38 Aug 22, 2020
2f167e9
Update addons/modules/functions/fnc_moduleUnpackStaticWeapon.sqf
ampersand38 Aug 22, 2020
2cfb05c
new line before return value
ampersand38 Aug 22, 2020
0db8c1e
New Icon
ampersand38 Dec 18, 2020
a7a5822
Players, Distance, Single-bag
ampersand38 Dec 18, 2020
aea37ab
Removed < in text
ampersand38 Dec 19, 2020
1bd1ba0
findIf instead of count
ampersand38 Jan 13, 2021
6a41922
Update addons/ai/functions/fnc_unpackStaticWeaponPFH.sqf
ampersand38 Mar 4, 2021
a4df41c
Update addons/ai/functions/fnc_unpackStaticWeaponPFH.sqf
ampersand38 Mar 4, 2021
96e8a82
Update addons/ai/functions/fnc_unpackStaticWeaponPFH.sqf
ampersand38 Mar 4, 2021
69b1da8
Update addons/ai/functions/fnc_unpackStaticWeaponPFH.sqf
ampersand38 Mar 4, 2021
e1e006d
Update addons/modules/functions/fnc_moduleUnpackStaticWeapon.sqf
ampersand38 Mar 4, 2021
73aa57c
Update addons/modules/functions/fnc_moduleUnpackStaticWeapon.sqf
ampersand38 Mar 4, 2021
398c5d2
Update addons/modules/functions/fnc_moduleUnpackStaticWeapon.sqf
ampersand38 Mar 4, 2021
dd78720
Update addons/modules/functions/fnc_moduleUnpackStaticWeapon.sqf
ampersand38 Mar 4, 2021
bc929a2
remove commented code
ampersand38 Mar 4, 2021
0d34257
Merge branch 'master' into Unpack-Static-Weapon
ampersand38 Jul 1, 2021
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
2 changes: 2 additions & 0 deletions addons/ai/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ PREP(handleSkillsChange);
PREP(initMan);
PREP(searchBuilding);
PREP(unGarrison);
PREP(unpackStaticWeapon);
PREP(unpackStaticWeaponPFH);
2 changes: 2 additions & 0 deletions addons/ai/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ QGVAR(skills) addPublicVariableEventHandler LINKFUNC(handleSkillsChange);
["CAManBase", "InitPost", LINKFUNC(initMan), true, [], false] call CBA_fnc_addClassEventHandler;

[QGVAR(unGarrison), LINKFUNC(unGarrison)] call CBA_fnc_addEventHandler;

[QGVAR(unpackStaticWeapon), LINKFUNC(unpackStaticWeapon)] call CBA_fnc_addEventHandler;
65 changes: 65 additions & 0 deletions addons/ai/functions/fnc_unpackStaticWeapon.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Unpacks a static weapon from units' backpacks.
*
* Arguments:
* 0: Gunner <OBJECT>
* 1: Assistant <OBJECT>
* 2: Target Position <ARRAY>
*
* Return Value:
* None
*
* Example:
* [_gunner, _assistant] call zen_ai_fnc_unpackStaticWeapon
*
* Public: No
*/

#define DISTANCE_CLOSE 3

params ["_gunner", "_assistant", ["_targetPos", [], [[]], 3]];

if (!local _gunner) exitWith {
[QGVAR(unpackStaticWeapon), _this, _gunner] call CBA_fnc_targetEvent;
};

if (!(_targetPos isEqualTo [])) then {
Copy link
Member

Choose a reason for hiding this comment

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

isNotEqualTo.

_gunner doWatch _targetPos;
};

// Too far, run PFH
if (_gunner distance _assistant > DISTANCE_CLOSE) exitWith {
[_gunner, _assistant, _targetPos] call FUNC(unpackStaticWeaponPFH);
};

if (!(_targetPos isEqualTo [])) then {
Copy link
Member

Choose a reason for hiding this comment

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

isNotEqualTo.

_assistant doWatch _targetPos;
_gunner setVariable [QGVAR(unpackStaticWeaponTargetPos), _targetPos];
};

_gunner addEventHandler ["WeaponAssembled", {
params ["_gunner", "_weapon"];

_gunner removeEventHandler ["WeaponAssembled", _thisEventHandler];
[QEGVAR(common,addObjects), [[_weapon]]] call CBA_fnc_serverEvent;

private _targetPos = _gunner getVariable [QGVAR(unpackStaticWeaponTargetPos), []];
if (!(_targetPos isEqualTo [])) then {
Copy link
Member

Choose a reason for hiding this comment

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

isNotEqualTo.

_weapon setDir (_weapon getDir _targetPos);
_gunner doWatch _targetPos;
};

// Added due to occassional tripod leg clipping through ground
_weapon setPosASL (getPosASL _weapon vectorAdd [0, 0, 0.05]);
_weapon setVectorUp surfaceNormal position _weapon;

_gunner assignAsGunner _weapon;
_gunner moveInGunner _weapon;

group _gunner addVehicle _weapon;
}];

_gunner action ["PutBag", _assistant];
_gunner action ["Assemble", unitBackpack _assistant];
74 changes: 74 additions & 0 deletions addons/ai/functions/fnc_unpackStaticWeaponPFH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Move units together if needed and unpacks a static weapon from units' backpacks.
*
* Arguments:
* 0: Gunner <OBJECT>
* 1: Assistant <OBJECT>
* 2: Target Position <ARRAY>
*
* Return Value:
* None
*
* Example:
* [_gunner, _assistant] call zen_ai_fnc_unpackStaticWeaponPFH
*
* Public: No
*/

#define DISTANCE_CLOSE 3
#define MOVE_DELAY 5
#define MOVE_TIMEOUT 60

params ["_gunner", "_assistant", ["_targetPos", [], [[]], 3]];

// Order assistant to move to gunner and start pfh
_gunner setVariable [QGVAR(statePATH), _gunner checkAIFeature "PATH"];
_gunner disableAI "PATH";
[_assistant] joinSilent grpNull;
private _group = group _assistant;
_group setBehaviourStrong "CARELESS";
_group deleteGroupWhenEmpty true;
_group enableAttack false;
Comment on lines +30 to +33
Copy link
Member

Choose a reason for hiding this comment

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

Can probably use new setCombatBehaviour and setUnitCombatMode commands to avoid affecting the entire group. Also, likely make units more responsive even in combat.

_assistant doMove getPosATL _gunner;
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved
_assistant setVariable [QGVAR(stateFSM), _assistant checkAIFeature "FSM"];
_assistant disableAI "FSM";
_assistant setVariable [QGVAR(nextMoveTime), CBA_MissionTime + 5];
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved

[{
params ["_args", "_pfhID"];
_args params ["_gunner", "_assistant", "_targetPos", "_nextMoveTime", "_endTime"];

private _closeEnough = _gunner distance _assistant <= DISTANCE_CLOSE;

if (_closeEnough || {CBA_MissionTime > _endTime || {!alive _gunner || {!alive _assistant}}}) exitWith {
[_pfhID] call CBA_fnc_removePerFrameHandler;
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved

// Gunner AI PATH
if (_gunner getVariable [QGVAR(statePATH), true]) then {
_gunner setVariable [QGVAR(statePATH), nil];
_gunner enableAI "PATH";
};
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved

// Reset assistant behaviour
private _group = group _gunner;
[_assistant] joinSilent _group;
_group setBehaviour behaviour _gunner;
ampersand38 marked this conversation as resolved.
Show resolved Hide resolved

// Assistant AI FSM
if (_assistant getVariable [QGVAR(stateFSM), true]) then {
_assistant setVariable [QGVAR(stateFSM), nil];
_assistant enableAI "FSM";
};
// Close enough, unpack
if (_closeEnough) then {
[_gunner, _assistant, _targetPos] call FUNC(unpackStaticWeapon);
};
};

if (unitReady _assistant || {CBA_MissionTime >= _nextMoveTime}) then {
_assistant doMove ASLtoAGL getPosASL _gunner;
_args set [3, CBA_missionTime + MOVE_DELAY];
};
}, 0.1, [_gunner, _assistant, _targetPos, CBA_MissionTime + MOVE_DELAY, CBA_missionTime + MOVE_TIMEOUT]] call CBA_fnc_addPerFrameHandler;
7 changes: 7 additions & 0 deletions addons/modules/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,13 @@ class CfgVehicles {
displayName = CSTRING(ModuleUnGarrison);
function = QFUNC(moduleUnGarrison);
};
class GVAR(moduleUnpackStaticWeapon): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(AI);
displayName = CSTRING(moduleUnpackStaticWeapon);
function = QFUNC(moduleUnpackStaticWeapon);
icon = QPATHTOF(ui\unpack_static_ca.paa);
};
class GVAR(moduleVisibility): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(Objects);
Expand Down
1 change: 1 addition & 0 deletions addons/modules/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ PREP(moduleToggleIRLasers);
PREP(moduleToggleLamps);
PREP(moduleTurretOptics);
PREP(moduleUnGarrison);
PREP(moduleUnpackStaticWeapon);
PREP(moduleVisibility);
PREP(moduleWeather);
1 change: 1 addition & 0 deletions addons/modules/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CfgPatches {
QGVAR(moduleToggleLamps),
QGVAR(moduleTurretOptics),
QGVAR(moduleUnGarrison),
QGVAR(moduleUnpackStaticWeapon),
QGVAR(moduleVisibility),
QGVAR(moduleWeather)
};
Expand Down
120 changes: 120 additions & 0 deletions addons/modules/functions/fnc_moduleUnpackStaticWeapon.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Zeus module function to unpack and assemble a static weapon from supported backpacks.
*
* Arguments:
* 0: Logic <OBJECT>
*
* Return Value:
* None
*
* Example:
* [LOGIC] call zen_modules_fnc_moduleUnpackStaticWeapon
*
* Public: No
*/

params ["_logic"];

private _gunner = attachedTo _logic;
deleteVehicle _logic;

if (isNull _gunner) exitWith {
[LSTRING(NoUnitSelected)] call EFUNC(common,showMessage);
};

if !(_gunner isKindOf "CAManBase") exitWith {
[LSTRING(OnlyInfantry)] call EFUNC(common,showMessage);
};

if !(alive _gunner) exitWith {
[LSTRING(OnlyAlive)] call EFUNC(common,showMessage);
};

if (isPlayer _gunner) exitWith {
["str_a3_cfgvehicles_moduleremotecontrol_f_errorPlayer"] call EFUNC(common,showMessage);
};

if (units _gunner findIf {isPlayer _x} != -1) exitWith {
[LSTRING(ModuleUnpackStaticWeapon_Player)] call EFUNC(common,showMessage);
};

private _backpack = backpack _gunner;
if (_backpack isEqualTo "") exitWith {
[LSTRING(ModuleUnpackStaticWeapon_Unit)] call EFUNC(common,showMessage);
};

private _assembleInfo = ["assembleTo", "base", "displayName", "dissasembleTo", "primary"] apply {(configOf backpackContainer _gunner >> "assembleInfo" >> _x) call BIS_fnc_getCfgData};
_assembleInfo params ["_assembleTo", "_compatibleBases", "_displayName", "_dissasembleTo", "_primary"];
Comment on lines +48 to +49
Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit weird. Any specific reason for using BIS_fnc_getCfgData instead of just getNumber/getText/getArray directly.

if (_compatibleBases isEqualType "") then {_compatibleBases = [];};
Copy link
Member

Choose a reason for hiding this comment

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

Multi-line.

Copy link
Member

Choose a reason for hiding this comment

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

Is this correct? the base config entry is text when there is only one compatible base but this line makes it so there are none.


if (_primary == 1 && {_compatibleBases isEqualTo [] || {_compatibleBases isEqualTo "" || {_compatibleBases isEqualTo [""]}}}) then {
Copy link
Member

Choose a reason for hiding this comment

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

_compatibleBases cannot be a string at this point. Line 50 changes it to an array.

// Single-backpack weapon
[_gunner, {
params ["_successful", "_gunner", "_position"];
if (_successful) then {
_gunner setVariable [QGVAR(unpackStaticWeaponTargetPos), _position];

_gunner addEventHandler ["WeaponAssembled", {
params ["_gunner", "_weapon"];

_gunner removeEventHandler ["WeaponAssembled", _thisEventHandler];
[QEGVAR(common,addObjects), [[_weapon]]] call CBA_fnc_serverEvent;

private _targetPos = _gunner getVariable [QGVAR(unpackStaticWeaponTargetPos), []];
if (!(_targetPos isEqualTo [])) then {
Copy link
Member

Choose a reason for hiding this comment

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

isNotEqualTo.

_weapon setDir (_weapon getDir _targetPos);
_gunner doWatch _targetPos;
};

// Added due to occassional tripod leg clipping through ground
_weapon setPosASL (getPosASL _weapon vectorAdd [0, 0, 0.05]);
_weapon setVectorUp surfaceNormal position _weapon;

if (unitIsUAV _weapon) exitWith {
_gunner connectTerminalToUAV _weapon;
};

if (isNull gunner _weapon) exitWith {
_gunner assignAsGunner _weapon;
_gunner moveInGunner _weapon;

group _gunner addVehicle _weapon;
};
}];

_gunner action ["Assemble"];
};
}, [], LSTRING(ModuleUnpackStaticWeapon_Direction)] call EFUNC(common,selectPosition);
} else {
// Two-backpack weapon
private _backpackers = units _gunner select {!(backpack _x isEqualTo "")};
Copy link
Member

Choose a reason for hiding this comment

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

!=. Could probably just move this check into the forEach loop as well.

private _assistant = objNull;
{
if (
// Has matching backpack
(backpack _x in _compatibleBases || {_backpack in ((configOf backpackContainer _x >> "assembleInfo" >> "base") call BIS_fnc_getCfgData)})
Copy link
Member

Choose a reason for hiding this comment

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

The base config entry is not guaranteed to be an array.

// Closer than current
&& {_assistant == objNull || {(_gunner distance _x) < (_gunner distance _assistant)}}
Copy link
Member

Choose a reason for hiding this comment

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

isNull.

) then {
_assistant = _x;
};
} forEach _backpackers;

if (isNull _assistant) exitWith {
[LSTRING(ModuleUnpackStaticWeapon_Group)] call EFUNC(common,showMessage);
};

if (_assistant distance _gunner > 100) exitWith {
[LSTRING(ModuleUnpackStaticWeapon_Distance)] call EFUNC(common,showMessage);
};

// Get target position
[_gunner, {
params ["_successful", "_gunner", "_position", "_assistant"];
if (_successful) then {
[QEGVAR(ai,unpackStaticWeapon), [_gunner, _assistant, ASLToAGL _position], _gunner] call CBA_fnc_targetEvent;
};
}, _assistant, LSTRING(ModuleUnpackStaticWeapon_Direction)] call EFUNC(common,selectPosition);
Comment on lines +114 to +119
Copy link
Member

Choose a reason for hiding this comment

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

Fix indentation.

};
18 changes: 18 additions & 0 deletions addons/modules/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,24 @@
<Polish>Odgarnizonuj grupę</Polish>
<Japanese>非歩哨グループ</Japanese>
</Key>
<Key ID="STR_ZEN_Modules_ModuleUnpackStaticWeapon">
<English>Unpack Static Weapon</English>
</Key>
<Key ID="STR_ZEN_Modules_ModuleUnpackStaticWeapon_Unit">
<English>Unit must carry a weapon bag</English>
</Key>
<Key ID="STR_ZEN_Modules_ModuleUnpackStaticWeapon_Group">
<English>Unit group must contain two compatible weapon bags</English>
</Key>
<Key ID="STR_ZEN_Modules_ModuleUnpackStaticWeapon_Distance">
<English>Assistant must be within 100 m of gunner</English>
</Key>
<Key ID="STR_ZEN_Modules_ModuleUnpackStaticWeapon_Player">
<English>Unit must not be in a player's group</English>
</Key>
<Key ID="STR_ZEN_Modules_ModuleUnpackStaticWeapon_Direction">
<English>Weapon Direction</English>
</Key>
<Key ID="STR_ZEN_Modules_GroupSide">
<English>Group Side</English>
<Russian>Сторона группы</Russian>
Expand Down
Binary file added addons/modules/ui/unpack_static_ca.paa
Binary file not shown.
4 changes: 4 additions & 0 deletions docs/user_guide/modules_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ Toggles the visibility of the attached object.

Un-garrisons units from the attached group.

## Unpack Static Weapon

Orders AI with weapons bags to set up the static weapon facing the target position.

## Update Editable Objects

Adds or removes editable objects of the selected types from the local or all curators.
Expand Down