-
Notifications
You must be signed in to change notification settings - Fork 52
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
base: master
Are you sure you want to change the base?
Changes from 74 commits
450aeac
e5c9938
70caa97
569249c
22936d8
92b8a15
922e4b5
ca86fe4
f845df7
60631fc
8a4194a
028ac3a
cc5dcc7
4809634
5a71f89
b2274af
026669a
16d46e9
9a7569d
7770381
9c15718
53be889
cac53b1
9f5f346
222c09d
dd7d74c
3938ea9
c9935b9
5c71128
cbc3e5f
1b02ccf
a6835aa
b94d4a7
0ede921
f6840c4
6646843
a00352d
3d3eafb
e2265cd
dcaa2d9
365244b
b0db71f
6451606
142a0b5
6718095
ca6ebc2
196e144
474f4ec
7204ff0
2d2465f
f8dc791
283d60d
d98c457
4fc2b7a
3dd7367
5c72ec3
39ef2e8
dfe1f17
10ce856
2f167e9
2cfb05c
0db8c1e
a7a5822
aea37ab
1bd1ba0
6a41922
a4df41c
96e8a82
69b1da8
e1e006d
73aa57c
398c5d2
dd78720
bc929a2
0d34257
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
_gunner doWatch _targetPos; | ||
}; | ||
|
||
// Too far, run PFH | ||
if (_gunner distance _assistant > DISTANCE_CLOSE) exitWith { | ||
[_gunner, _assistant, _targetPos] call FUNC(unpackStaticWeaponPFH); | ||
}; | ||
|
||
if (!(_targetPos isEqualTo [])) then { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
_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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
_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]; |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can probably use new |
||
_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; |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a bit weird. Any specific reason for using |
||
if (_compatibleBases isEqualType "") then {_compatibleBases = [];}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multi-line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? the |
||
|
||
if (_primary == 1 && {_compatibleBases isEqualTo [] || {_compatibleBases isEqualTo "" || {_compatibleBases isEqualTo [""]}}}) then { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
_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 "")}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
private _assistant = objNull; | ||
{ | ||
if ( | ||
// Has matching backpack | ||
(backpack _x in _compatibleBases || {_backpack in ((configOf backpackContainer _x >> "assembleInfo" >> "base") call BIS_fnc_getCfgData)}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
// Closer than current | ||
&& {_assistant == objNull || {(_gunner distance _x) < (_gunner distance _assistant)}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation. |
||
}; |
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.
isNotEqualTo
.