From 6a85750f9cc0bb0a8b4a62479e4b1220ae889bec Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Mon, 4 Jul 2016 00:17:34 +0200 Subject: [PATCH 01/29] Rewrite fnc_unpackMortar part 1/x --- addons/sup_combatsupport/fnc_unpackMortar.sqf | 176 +++++++++++------- 1 file changed, 105 insertions(+), 71 deletions(-) diff --git a/addons/sup_combatsupport/fnc_unpackMortar.sqf b/addons/sup_combatsupport/fnc_unpackMortar.sqf index 6877a6e9e..5c5812b1d 100644 --- a/addons/sup_combatsupport/fnc_unpackMortar.sqf +++ b/addons/sup_combatsupport/fnc_unpackMortar.sqf @@ -15,99 +15,133 @@ SCRIPT(unpackMortar); _this select 1: location to place gun (position) _this select 2: location of target (position) */ -private ["_group","_position","_targetPos","_leader","_units","_gunner","_assistant","_weapon"]; +private _group = _this param [0, grpNull]; +private _position = _this param [1, grpNull]; +private _targetPos = _this param [2, grpNull]; -//diag_log str(_this); +// TODO: Perhaps leader could pick up an other role if needed? +if (count (units _group) < 3) exitWith { + // TODO: is supportWeaponCount needed? + _sptCount = _grp getVariable ["supportWeaponCount",3]; + _grp setVariable ["supportWeaponCount", _sptCount - 1]; + + diag_log "unpackMortar: cannot assemble, requires 3 units" +}; -_group = [_this, 0, grpNull] call bis_fnc_param; -_position = [_this, 1, grpNull] call bis_fnc_param; -_targetPos = [_this, 2, grpNull] call bis_fnc_param; -_weapon = [_this, 3, grpNull] call bis_fnc_param; -_units = (units _group); +private _assembleTo = ""; +private _disassembleTo = []; +private _backpacks = []; { - if (vehicle _x != _x) then { - doGetOut _x; - }; - if (_x getVariable ["supportWeaponGunner",objNull] == _weapon) then { - _gunner = _x; - }; - if (_x getVariable ["supportWeaponAsst",objNull] == _weapon) then { - _assistant = _x; - }; -} foreach _units; + private _backpack = unitBackpack _x; -if (isNil "_gunner" || isNil "_assistant") exitWith { - diag_log "Someone from the mortar team died"; - // reduce mortar count - _sptCount = _grp getVariable ["supportWeaponCount",3]; - _grp setVariable ["supportWeaponCount", _sptCount - 1]; -}; + if (!isNull _backpack) then { + private _cfg = (configFile >> "CfgVehicles" >> typeOf _backpack >> "assembleInfo" >> "assembleTo"); + private _assembleToValue = _cfg call BIS_fnc_getCfgData; -[_gunner, _assistant, _targetPos, _weapon, _group] spawn { + if (!isNil "_assembleToValue" && {count _assembleToValue > 0}) then { + private _cfg = (configFile >> "CfgVehicles" >> _assembleToValue >> "assembleInfo" >> "dissasembleTo"); + private _disassembleToValue = _cfg call BIS_fnc_getCfgData; - private ["_gunner","_assistant","_pos","_tPos","_wait","_dirTo","_sptarr","_weapont", "_weapon","_grp","_timein","_timer","_sptCount"]; + if (!isNil "_disassembleToValue" && {count _disassembleToValue > 0}) then { + _disassembleTo = _disassembleToValue; + }; + }; - _gunner = _this select 0; - _assistant = _this select 1; - _tPos = _this select 2; - _weapont = typeOf (_this select 3); - _grp = _this select 4; + _backpacks pushBack (typeOf _backpack); + }; +} forEach (units _group); - waitUntil{sleep 0.1; _gunner call ALiVE_fnc_unitReadyRemote}; +private _canAssemble = true; - _gunner disableAI "move"; +{ + if (!(_x in _backpacks)) exitWith { + _canAssemble = false; + }; +} forEach _disassembleTo; + +if (!_canAssemble) exitWith { diag_log format ["unpackMortar: cannot assemble %1! NEED: %2 HAS: %3", _assembleTo, _disassembleTo, _backpacks] }; + +private _weapon = objNull; +private _leader = leader _group; +private _units = (units _group) - [_leader]; +private _gunner = _units select 0; +private _assistant = _units select 1; +private _timeout = -1; + +{_x doMove ([_position, 0, 5, 0, 0, 20, 0] call BIS_fnc_findSafePos)} forEach (_units + [_leader]); + +private _unitsReady = false; +_timeout = time + 60; +while {!_unitsReady} do { + if (time >= _timeout) exitWith { + { + doStop _x; + _x setPos ([_position, 0, 5, 0, 0, 20, 0] call BIS_fnc_findSafePos); + } forEach (_units + [_leader]); + }; - _assistant disableAI "move"; + { + // Break out of forEach as soon as unit is not "ready" + if (!(_x call ALiVE_fnc_unitReadyRemote)) exitWith { + _unitsReady = false; + }; - _assistant setpos (position _gunner); + _unitsReady = true; + } forEach (_units + [_leader]); - _assistant setUnitPos "Middle"; + sleep 0.1; +}; - _assistant action ["PutBag",_assistant]; - _gunner action ["Assemble",unitbackpack _gunner]; +// TODO: change MOVE to PATH post A3 1.62 release? +_gunner disableAI "MOVE"; +_assistant disableAI "MOVE"; - _wait = true; - _timein = true; - _timer = time; - while {_wait && _timein} do { - _weapon = (nearestObjects [position _gunner, [_weapont], 3]) select 0; - if (!isNil "_weapon") then { - if (alive _weapon) then {_wait = false}; - }; - if (time-_timer > 60) then {_timein = false}; - sleep 1; - }; +private _assistantBackpack = unitBackpack _assistant; +_assistant action ["PutBag"]; - if (!_timein && _wait) then { - diag_log format["unpack timedout %1",(nearestObjects [position _gunner, [], 3])]; - removeBackpackGlobal _gunner; - removeBackpackGlobal _assistant; - _weapon = createVehicle [_weapont, position _gunner, [], 3, "NONE"]; +_timeout = time + 5; +while {!isNull (unitBackpack _assistant)} do { + if (time >= _timeout) exitWith { + // TODO: handle timeout }; + sleep 0.1; +}; + +_gunner action ["Assemble", _assistantBackpack]; + +private _assembledEH = _gunner addEventHandler ["WeaponAssembled", { + private _unit = _this param [0, objNull]; + private _weapon = _this param [1, objNull]; - _sptarr = _grp getVariable ["supportWeaponArray",[]]; - _sptarr pushback _weapon; - _grp setvariable ["supportWeaponArray", _sptarr]; + _unit setVariable ["assembledWeapon", _weapon]; +}]; - _dirTo = ((position _weapon) getDir _tPos); +_timeout = time + 5; +while {isNull _weapon} do { + if (time >= _timeout) exitWith { + // TODO: handle timeout + }; + _weapon = _gunner getVariable ["assembledWeapon", objNull]; + sleep 0.1; +}; - sleep 5; - _gunner assignAsGunner _weapon; - _gunner moveInGunner _weapon; - sleep 5; +_gunner removeEventHandler ["WeaponAssembled", _assembledEH]; - _gunner commandWatch _tPos; +private _dirTo = [position _weapon, _targetPos] call BIS_fnc_dirTo; +_weapon setDir _dirTo; - _assistant selectWeapon "Binocular"; - sleep 6; - _assistant commandWatch _tPos; - _assistant setDir _dirTo; +_gunner assignAsGunner _weapon; +_gunner moveInGunner _weapon; +_gunner commandWatch _targetPos; - _gunner setVariable ["unpacked", true]; - _assistant setVariable ["packAssistant", false]; +_assistant setUnitPos "Middle"; +_assistant setDir _dirTo; +_assistant commandWatch _targetPos; -// diag_log str(_grp getVariable ["supportWeaponArray",[]]); -}; +_leader selectWeapon "Binocular"; +_leader setUnitPos "Middle"; +_leader setDir _dirTo; +_leader commandWatch _targetPos; -_gunner +_gunner; From faa57739c6aad701cc2ce47f8c11d150bacfe2d2 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Mon, 4 Jul 2016 00:44:25 +0200 Subject: [PATCH 02/29] Rename _cfg to something a bit more descriptive --- addons/sup_combatsupport/fnc_unpackMortar.sqf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/sup_combatsupport/fnc_unpackMortar.sqf b/addons/sup_combatsupport/fnc_unpackMortar.sqf index 5c5812b1d..fa67ca5cc 100644 --- a/addons/sup_combatsupport/fnc_unpackMortar.sqf +++ b/addons/sup_combatsupport/fnc_unpackMortar.sqf @@ -36,12 +36,12 @@ private _backpacks = []; private _backpack = unitBackpack _x; if (!isNull _backpack) then { - private _cfg = (configFile >> "CfgVehicles" >> typeOf _backpack >> "assembleInfo" >> "assembleTo"); - private _assembleToValue = _cfg call BIS_fnc_getCfgData; + private _assembleToCfg = (configFile >> "CfgVehicles" >> typeOf _backpack >> "assembleInfo" >> "assembleTo"); + private _assembleToValue = _assembleToCfg call BIS_fnc_getCfgData; if (!isNil "_assembleToValue" && {count _assembleToValue > 0}) then { - private _cfg = (configFile >> "CfgVehicles" >> _assembleToValue >> "assembleInfo" >> "dissasembleTo"); - private _disassembleToValue = _cfg call BIS_fnc_getCfgData; + private _disassembleToCfg = (configFile >> "CfgVehicles" >> _assembleToValue >> "assembleInfo" >> "dissasembleTo"); + private _disassembleToValue = _disassembleToCfg call BIS_fnc_getCfgData; if (!isNil "_disassembleToValue" && {count _disassembleToValue > 0}) then { _disassembleTo = _disassembleToValue; From c50155d0dfe8d0af60522a8aac1fde7695994c90 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Thu, 14 Jul 2016 14:21:06 +0200 Subject: [PATCH 03/29] Handle timeouts in fnc_unpackMortar --- addons/sup_combatsupport/fnc_unpackMortar.sqf | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/addons/sup_combatsupport/fnc_unpackMortar.sqf b/addons/sup_combatsupport/fnc_unpackMortar.sqf index fa67ca5cc..2e56ff592 100644 --- a/addons/sup_combatsupport/fnc_unpackMortar.sqf +++ b/addons/sup_combatsupport/fnc_unpackMortar.sqf @@ -32,6 +32,7 @@ private _assembleTo = ""; private _disassembleTo = []; private _backpacks = []; +// TODO: Extract to seperate script? { private _backpack = unitBackpack _x; @@ -103,13 +104,12 @@ _assistant action ["PutBag"]; _timeout = time + 5; while {!isNull (unitBackpack _assistant)} do { if (time >= _timeout) exitWith { - // TODO: handle timeout + _assistantBackpack = createVehicle [typeOf _assistantBackpack, position _assistant, [], 0, "NONE"]; + removeBackpackGlobal _assistant; }; sleep 0.1; }; -_gunner action ["Assemble", _assistantBackpack]; - private _assembledEH = _gunner addEventHandler ["WeaponAssembled", { private _unit = _this param [0, objNull]; private _weapon = _this param [1, objNull]; @@ -117,17 +117,37 @@ private _assembledEH = _gunner addEventHandler ["WeaponAssembled", { _unit setVariable ["assembledWeapon", _weapon]; }]; +_gunner action ["Assemble", _assistantBackpack]; + _timeout = time + 5; while {isNull _weapon} do { if (time >= _timeout) exitWith { - // TODO: handle timeout + _weapon = createVehicle [_assembleTo, position _gunner, [], 0, "NONE"]; + removeBackpackGlobal _gunner; }; + _weapon = _gunner getVariable ["assembledWeapon", objNull]; sleep 0.1; }; _gunner removeEventHandler ["WeaponAssembled", _assembledEH]; +// Cleanup possible remaining backpacks +private _weaponHolders = nearestObjects [position _gunner, ["GroundWeaponHolder"], 25]; + +{ + private _weaponHolder = _x param [0, objNull]; + private _weaponHolderBackpacks = backpackCargo _weaponHolder; + + { + private _backpack = _x param [0, objNull]; + + if (_backpack in _weaponHolderBackpacks) exitWith { + deleteVehicle _weaponHolder; + }; + } forEach _disassembleTo; +} forEach _weaponHolders; + private _dirTo = [position _weapon, _targetPos] call BIS_fnc_dirTo; _weapon setDir _dirTo; From b6029a91b42e0d6c6249debb62b9e85e32c33e56 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Mon, 18 Jul 2016 00:00:07 +0200 Subject: [PATCH 04/29] Redo fnc_packMortar --- addons/sup_combatsupport/fnc_packMortar.sqf | 140 ++++++++------------ 1 file changed, 57 insertions(+), 83 deletions(-) diff --git a/addons/sup_combatsupport/fnc_packMortar.sqf b/addons/sup_combatsupport/fnc_packMortar.sqf index c77fdf382..ac7b7ab23 100644 --- a/addons/sup_combatsupport/fnc_packMortar.sqf +++ b/addons/sup_combatsupport/fnc_packMortar.sqf @@ -14,108 +14,82 @@ SCRIPT(packMortar); _this select 0: the support team group (group) _this select 1: the weapon (option if weapon registered as "supportWeaponSetup" variable) */ -private["_group","_weapon","_position","_leader","_units","_gunner","_assistant","_type","_wait"]; +private _group = _this param [0, grpNull]; +private _weapon = _this param [0, objNull]; -_group = [_this, 0, grpNull] call bis_fnc_param; -_weapon = [_this, 1, grpNull] call bis_fnc_param; -_type = typeOf _weapon; -_position = position _weapon; -_leader = leader _group; -_gunner = gunner _weapon; -_units = (units _group) - [_leader]; -_units = _units - [_gunner]; +if (isNull _group || isNull _weapon) exitWith {}; -if (_weapon == objNull || isNil "_weapon" || _group == grpNull || _leader == objNull) exitWith {}; +private _disassembleToCfg = (configFile >> "CfgVehicles" >> typeOf _weapon >> "assembleInfo" >> "dissasembleTo"); +private _disassembleTo = _disassembleToCfg call BIS_fnc_getCfgData; -{ - // find a group member that is not in a vehicle or staticweapon and is free - if !(_x getVariable ["packAssistant",false] || (vehicle _x != _x)) exitWith { - _assistant = _x; - _assistant setVariable ["packAssistant",true]; - }; -} foreach _units; +if (isNil "_disassembleTo" || {count _disassembleTo == 0}) exitWith {}; + +private _leader = leader _group; +private _gunner = gunner _weapon; +private _units = (units _group) - [_leader] - [_gunner]; +private _assistant = _unit select 0; -// diag_log format ["%1, %2, %3, %4, %5, %6, %7", _group, _weapon, _position, _leader, _gunner, _assistant, _type]; +private _primaryBag = objNull; +private _secondaryBag = objNull; + +private _timeout = -1; _gunner leaveVehicle _weapon; -_gunner addEventHandler ["WeaponDisassembled", { - _this spawn { - private ["_unit","_bag1","_bag2"]; - _unit = _this select 0; - _bag1 = _this select 1; - _bag2 = _this select 2; +private _disassembledEH = _gunner addEventHandler ["WeaponDisassembled", { + private _unit = _this param [0, objNull]; + private _primaryBag = _this param [1, objNull]; + private _secondaryBag = _this param [2, objNull]; - _unit setVariable ["supportWeaponBag1", _bag1]; - _unit setVariable ["supportWeaponBag2", _bag2]; - }; + _unit setVariable ["primaryBag", _primaryBag]; + _unit setVariable ["secondaryBag", _secondaryBag]; }]; -_gunner action ["Disassemble",_weapon]; +_gunner action ["Disassemble", _weapon]; + +_timeout = time + 5; +while {isNull _primaryBag || isNull _secondaryBag} do { + if (time >= _timeout) exitWith { + _primaryBag = createVehicle [_disassembleTo select 0, position _weapon, [], 0, "NONE"]; + _secondaryBag = createVehicle [_disassembleTo select 1, position _weapon, [], 0, "NONE"]; + + deleteVehicle _weapon; + }; + + _primaryBag = _gunner getVariable ["primaryBag", objNull]; + _secondaryBag = _gunner getVariable ["secondaryBag", objNull]; + sleep 0.1; +}; { _x enableAI "MOVE"; - _x enableAI "ANIM"; _x setUnitPos "AUTO"; } forEach [_gunner, _assistant]; -{ - [_x,position _weapon] call ALiVE_fnc_doMoveRemote; -} foreach [_gunner, _assistant]; - -[_weapon, _gunner, _assistant] spawn { - private ["_weapon","_gunner","_assistant","_position","_wait","_bag2","_bag1","_timeout","_packs"]; - _weapon = _this select 0; - _gunner = _this select 1; - _assistant = _this select 2; - _position = position _weapon; - - _timer = time; - waitUntil {sleep 0.3; _gunner call ALiVE_fnc_unitReadyRemote || (time-_timer > 30)}; - - _gunner action ["Disassemble",_weapon]; - - _wait = true; - _timeout = false; - _timer = time; - while {_wait} do { - _packs = nearestObjects [_position, ["GroundWeaponHolder"], 3]; - if (count _packs > 1) then {_wait = false}; - if ((time-_timer) > 30) exitWith {_timeout = true;}; - sleep 1; - }; +_gunner action ["takeBag", _primaryBag]; +_assistant action ["takeBag", _secondaryBag]; - if (_timeout) then { - _bag1 = format ["%1_Mortar_01_weapon_F", _weapon select [0,1]]; - _bag2 = format ["%1_Mortar_01_support_F",_weapon select [0,1]]; - deleteVehicle _weapon; - _gunner addBackpackGlobal _bag1; - _assistant addBackpackGlobal _bag2; - } else { - _bag1 = _gunner getVariable ["supportWeaponBag1", objNull]; - _bag2 = _gunner getVariable ["supportWeaponBag2", objNull]; - _gunner action ["takeBag", _bag1]; - _assistant action ["takeBag", _bag2]; +_timeout = time + 5; +while {unitBackpack _gunner != _primaryBag || unitBackpack _assistant != _secondaryBag} do { + if (time >= _timeout) exitWith { + _gunner addBackpackGlobal (typeOf _primaryBag); + _assistant addBackpackGlobal (typeOf _secondaryBag); }; + sleep 0.1; +}; - _timer = time; - waitUntil {sleep 1; (unitBackpack _gunner == _bag1 && unitBackpack _assistant == _bag2) || (time-_timer) > 30}; +// Cleanup possible remaining backpacks +private _weaponHolders = nearestObjects [position _gunner, ["GroundWeaponHolder"], 25]; - if (unitBackpack _gunner != _bag1) then { - _gunner addBackpackGlobal (typeOf _bag1); - }; - - if (unitBackpack _assistant != _bag2) then { - _assistant addBackpackGlobal (typeOf _bag2); - { - deleteVehicle _x; - }foreach _packs; - }; - - _gunner setVariable ["supportWeaponGunner", _weapon]; - _assistant setVariable ["supportWeaponAsst", _weapon]; - _weapon setVariable ["packed",true]; +{ + private _weaponHolder = _x param [0, objNull]; + private _weaponHolderBackpacks = backpackCargo _weaponHolder; + { + private _backpack = _x param [0, objNull]; -// diag_log format ["%1 packed up!",_weapon]; -}; \ No newline at end of file + if (_backpack in _weaponHolderBackpacks) exitWith { + deleteVehicle _weaponHolder; + }; + } forEach _disassembleTo; +} forEach _weaponHolders; From 617c50564928c7491de5f143a11db4c58e78c583 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 30 Jul 2016 23:19:06 +0200 Subject: [PATCH 05/29] Create (sup_)Artillery class with CBA statemachine --- .../sup_artillery/ArtilleryStateMachine.hpp | 105 ++++++++++ addons/sup_artillery/config.cpp | 2 + addons/sup_artillery/fnc_ARTILLERY.sqf | 191 +++++++++++++++--- 3 files changed, 275 insertions(+), 23 deletions(-) create mode 100644 addons/sup_artillery/ArtilleryStateMachine.hpp diff --git a/addons/sup_artillery/ArtilleryStateMachine.hpp b/addons/sup_artillery/ArtilleryStateMachine.hpp new file mode 100644 index 000000000..057997302 --- /dev/null +++ b/addons/sup_artillery/ArtilleryStateMachine.hpp @@ -0,0 +1,105 @@ +class ArtilleryStateMachine { + list = ""; + + class Idle { + onState = ""; + onStateEntered = ""; + onStateLeaving = ""; + + class HasFireMission { + targetState = "Active"; + condition = "[_this, 'hasFireMission'] call ALIVE_fnc_Artillery"; + onTransition = ""; + }; + }; + + class Active { + onState = "[_this, 'onActive'] call ALIVE_fnc_Artillery"; + onStateEntered = ""; + onStateLeaving = ""; + + class InRange { + targetState = "Execute"; + condition = "[_this, 'inRange'] call ALIVE_fnc_Artillery"; + onTransition = ""; + }; + + class NotInRange { + targetState = "Move"; + condition = "!([_this, 'inRange'] call ALIVE_fnc_Artillery)"; + onTransition = ""; + }; + }; + + class Move { + onState = "[_this, 'onMove'] call ALIVE_fnc_Artillery"; + onStateEntered = ""; + onStateLeaving = ""; + + class InPosition { + targetState = "Execute"; + condition = "[_this, 'inPosition'] call ALIVE_fnc_Artillery"; + onTransition = ""; + }; + + class Abort { + targetState = "ReturnToBase"; + condition = "!([_this, 'hasFireMission'] call ALIVE_fnc_Artillery)"; + onTransition = ""; + }; + }; + + class Execute { + onState = "[_this, 'onExecute'] call ALIVE_fnc_Artillery"; + onStateEntered = ""; + onStateLeaving = ""; + + class Abort { + targetState = "ReturnToBase"; + condition = "!([_this, 'hasFireMission'] call ALIVE_fnc_Artillery)"; + onTransition = ""; + }; + }; + + class Fire { + onState = "[_this, 'onFire'] call ALIVE_fnc_Artillery"; + onStateEntered = ""; + onStateLeaving = ""; + + class FireMissionComplete { + targetState = "ReturnToBase"; + condition = "[_this, 'isFireMissionComplete'] call ALIVE_fnc_Artillery"; + onTransition = ""; + }; + + class Fired { + targetState = "FireDelay"; + condition = "true"; + onTransition = ""; + }; + }; + + class FireDelay { + onState = ""; + onStateEntered = ""; + onStateLeaving = ""; + + class Continue { + targetState = "Fire"; + condition = "[_this, 'fireNextRound'] call ALIVE_fnc_Artillery"; + onTransition = ""; + }; + }; + + class ReturnToBase { + onState = "[_this, 'onReturnToBase'] call ALIVE_fnc_Artillery"; + onStateEntered = ""; + onStateLeaving = ""; + + class AtBase { + targetState = "Idle"; + condition = "[_this, 'inPosition'] call ALIVE_fnc_Artillery"; + onTransition = ""; + }; + }; +}; diff --git a/addons/sup_artillery/config.cpp b/addons/sup_artillery/config.cpp index 6643ea355..eba9c8329 100644 --- a/addons/sup_artillery/config.cpp +++ b/addons/sup_artillery/config.cpp @@ -3,3 +3,5 @@ #include #include #include + +#include diff --git a/addons/sup_artillery/fnc_ARTILLERY.sqf b/addons/sup_artillery/fnc_ARTILLERY.sqf index a20a81047..d98d6d820 100644 --- a/addons/sup_artillery/fnc_ARTILLERY.sqf +++ b/addons/sup_artillery/fnc_ARTILLERY.sqf @@ -1,10 +1,10 @@ #include <\x\alive\addons\sup_artillery\script_component.hpp> -SCRIPT(CAS); +SCRIPT(Artillery); /* ---------------------------------------------------------------------------- -Function: ALIVE_fnc_CQB +Function: ALIVE_fnc_Artillery Description: -XXXXXXXXXX +Artillery module. Parameters: Nil or Object - If Nil, return a new instance. If Object, reference an existing instance. @@ -21,29 +21,177 @@ Boolean - enabled - Enabled or disable module Parameters: none -Description: -CQB Module! Detailed description to follow - Examples: -[_logic, "factions", ["OPF_F"] call ALiVE_fnc_CQB; -[_logic, "houses", _nonStrategicHouses] call ALiVE_fnc_CQB; -[_logic, "spawnDistance", 500] call ALiVE_fnc_CQB; -[_logic, "active", true] call ALiVE_fnc_CQB; See Also: -- Author: -Wolffy, Highhead +marceldev89 ---------------------------------------------------------------------------- */ -#define SUPERCLASS nil - -private ["_logic","_operation","_args"]; - -PARAMS_1(_logic); -DEFAULT_PARAM(1,_operation,""); -DEFAULT_PARAM(2,_args,nil); +#define SUPERCLASS ALIVE_fnc_baseClass +#define MAINCLASS ALIVE_fnc_artillery + +private _logic = param [0, objNull, [objNull, []]]; +private _operation = param [1, "", [""]]; +private _args = param [2, objNull, [objNull, [], "", 0, true, false]]; + +private _result = true; + +switch (_operation) do { + case "init": { + [] call ALIVE_fnc_artillery_init; + }; + + /**************** + ** PROPERTIES ** + ****************/ + case "fireMission": { + if (isNull _args) then { + _result = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + } else { + private _position = _args param [0, [0,0,0], [[]], 3]; + private _roundType = _args param [1, "", [""]]; + private _roundCount = _args param [2, 1, [1]]; + private _delay = _args param [3, 5, [1]]; + private _dispersion = _args param [4, 50, [1]]; + + private _fireMission = [] call ALIVE_fnc_hashCreate; + [_fireMission, "position", _position] call ALIVE_fnc_hashSet; + [_fireMission, "roundType", _roundType] call ALIVE_fnc_hashSet; + [_fireMission, "roundCount", _roundCount] call ALIVE_fnc_hashSet; + [_fireMission, "delay", _delay] call ALIVE_fnc_hashSet; + [_fireMission, "dispersion", _dispersion] call ALIVE_fnc_hashSet; + // Defaults + [_fireMission, "units", []] call ALIVE_fnc_hashSet; + [_fireMission, "unitIndex", -1] call ALIVE_fnc_hashSet; + [_fireMission, "roundsShot", -1] call ALIVE_fnc_hashSet; + [_fireMission, "nextRoundTime", -1] call ALIVE_fnc_hashSet; + + [_logic, "fireMission", _fireMission] call ALIVE_fnc_hashSet; + }; + }; + case "position": { + private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + _result = position (leader _group); + }; + + /************* + ** METHODS ** + *************/ + case "execute": { + private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + private _units = (units _group) select {vehicle _x != _x && {gunner _x == _x}}; + private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + [_fireMission, "units", _units] call ALIVE_fnc_hashSet; + [_fireMission, "unitIndex", 0] call ALIVE_fnc_hashSet; + [_fireMission, "roundsShot", 0] call ALIVE_fnc_hashSet; + [_logic, "fireMission", _fireMission] call ALIVE_fnc_hashSet; // TODO: Is this needed? + }; + case "fire": { + private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet; + private _units = [_fireMission, "units"] call ALIVE_fnc_hashGet; + private _unitIndex = [_fireMission, "unitIndex"] call ALIVE_fnc_hashGet; + private _unit = _units select _unitIndex; + private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; + private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; + private _delay = [_fireMission, "delay"] call ALIVE_fnc_hashGet; + + _unit doArtilleryFire [ + _position, + _roundType, + 1 + ]; + + if ((_unitIndex + 1) > ((count _units) - 1)) then { + _unitIndex = 0; + } else { + _unitIndex = _unitIndex + 1; + }; + + [_fireMission, "nextRoundTime", time + _delay] call ALIVE_fnc_hashSet; + [_fireMission, "unitIndex", _unitIndex] call ALIVE_fnc_hashSet; + [_fireMission, "roundsShot", _roundsShot + 1] call ALIVE_fnc_hashSet; + [_logic, "fireMission", _fireMission] call ALIVE_fnc_hashSet; // TODO: Is this needed? + }; + case "fireNextRound": { + private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + private _nextRoundTime = [_fireMission, "nextRoundTime"] call ALIVE_fnc_hashGet; + _result = (time >= _nextRoundTime); + }; + case "hasFireMission": { + private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + _result = (count _fireMission == 3); + }; + case "isFireMissionComplete": { + private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + private _roundCount = [_fireMission, "roundCount"] call ALIVE_fnc_hashGet; + private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet; + _result = (_roundsShot >= _roundCount); + }; + case "inPosition": { + private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + _result = _group getVariable ["sup_artillery_inPosition", false]; + }; + case "inRange": { + private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + private _units = (units _group) select {vehicle _x != _x && {gunner _x == _x}}; + _result = _position inRangeOfArtillery [_units, _fireMission select 1]; + }; + case "move": { + private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + private _position = []; + + if (!isNull _args && {count _args == 3}) then { + [_logic, "moveToPos", _args] call ALIVE_fnc_hashSet; + _position = _args; + } else { + _position = [_logic, "moveToPos"] call ALIVE_fnc_hashGet; + }; + + private _waypoint = _group addWaypoint [_position, 0]; + _waypoint setWaypointType "MOVE"; + _waypoint setWaypointBehaviour "SAFE"; + _waypoint setWaypointSpeed "NORMAL"; + _waypoint setWaypointStatements [ + "true", + "(group _this) setVariable ['sup_artillery_inPosition', true]" + ]; + + _group setVariable ["sup_artillery_inPosition", false]; + }; + + /****************** + ** STATEMACHINE ** + ******************/ + case "onIdle": { + private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + _group setVariable ["sup_artillery_inPosition", true]; + [_logic, "moveToPos", objNull] call ALIVE_fnc_hashSet; + + }; + case "onActive": { + if (!([_logic, "inRange"] call MAINCLASS)) then { + [_logic, "moveToPos", [0,0,0]] call ALIVE_fnc_hashSet; // TODO: Figure out best firing position + }; + }; + case "onFire": { + [_logic, "fire"] call MAINCLASS; + }; + case "onMove": { + [_logic, "move"] call MAINCLASS; + }; + case "onExecute": { + [_logic, "execute"] call MAINCLASS; + }; + case "onReturnToBase": { + [_logic, "move", [0,0,0]] call MAINCLASS; // TODO: Find (best) RTB position + }; +}; + +// TODO: Give this legacy stuff a place ALIVE_coreLogic = _logic; _position = getposATL ALIVE_coreLogic; _callsign = _logic getvariable ["artillery_callsign","EAGLE ONE"]; @@ -51,7 +199,4 @@ _type = _logic getvariable ["artillery_type","B_Heli_Attack_01_F"]; _ordnace = _logic getvariable ["artillery_ordnace",["HE", 30]]; ARTYPOS = _position; PublicVariable "ARTYPOS"; - - - - + _result; From de788dde7f6fb1d84596cdd5cdf6a6f5111952f0 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 30 Jul 2016 23:57:20 +0200 Subject: [PATCH 06/29] Fix typo :smiley: --- addons/sup_combatsupport/fnc_packMortar.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sup_combatsupport/fnc_packMortar.sqf b/addons/sup_combatsupport/fnc_packMortar.sqf index ac7b7ab23..6b80cec3f 100644 --- a/addons/sup_combatsupport/fnc_packMortar.sqf +++ b/addons/sup_combatsupport/fnc_packMortar.sqf @@ -15,7 +15,7 @@ SCRIPT(packMortar); _this select 1: the weapon (option if weapon registered as "supportWeaponSetup" variable) */ private _group = _this param [0, grpNull]; -private _weapon = _this param [0, objNull]; +private _weapon = _this param [1, objNull]; if (isNull _group || isNull _weapon) exitWith {}; From 18010ca95b7fd9c604b5e8173744e0d59a9cbad7 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Tue, 2 Aug 2016 19:52:08 +0200 Subject: [PATCH 07/29] Change file/function case --- .../sup_artillery/ArtilleryStateMachine.hpp | 28 +++++++++---------- addons/sup_artillery/CfgVehicles.hpp | 4 +-- .../{fnc_ARTILLERY.sqf => fnc_artillery.sqf} | 2 +- ...RTILLERYInit.sqf => fnc_artilleryInit.sqf} | 0 4 files changed, 17 insertions(+), 17 deletions(-) rename addons/sup_artillery/{fnc_ARTILLERY.sqf => fnc_artillery.sqf} (99%) rename addons/sup_artillery/{fnc_ARTILLERYInit.sqf => fnc_artilleryInit.sqf} (100%) diff --git a/addons/sup_artillery/ArtilleryStateMachine.hpp b/addons/sup_artillery/ArtilleryStateMachine.hpp index 057997302..b0071fc23 100644 --- a/addons/sup_artillery/ArtilleryStateMachine.hpp +++ b/addons/sup_artillery/ArtilleryStateMachine.hpp @@ -8,67 +8,67 @@ class ArtilleryStateMachine { class HasFireMission { targetState = "Active"; - condition = "[_this, 'hasFireMission'] call ALIVE_fnc_Artillery"; + condition = "[_this, 'hasFireMission'] call ALIVE_fnc_artillery"; onTransition = ""; }; }; class Active { - onState = "[_this, 'onActive'] call ALIVE_fnc_Artillery"; + onState = "[_this, 'onActive'] call ALIVE_fnc_artillery"; onStateEntered = ""; onStateLeaving = ""; class InRange { targetState = "Execute"; - condition = "[_this, 'inRange'] call ALIVE_fnc_Artillery"; + condition = "[_this, 'inRange'] call ALIVE_fnc_artillery"; onTransition = ""; }; class NotInRange { targetState = "Move"; - condition = "!([_this, 'inRange'] call ALIVE_fnc_Artillery)"; + condition = "!([_this, 'inRange'] call ALIVE_fnc_artillery)"; onTransition = ""; }; }; class Move { - onState = "[_this, 'onMove'] call ALIVE_fnc_Artillery"; + onState = "[_this, 'onMove'] call ALIVE_fnc_artillery"; onStateEntered = ""; onStateLeaving = ""; class InPosition { targetState = "Execute"; - condition = "[_this, 'inPosition'] call ALIVE_fnc_Artillery"; + condition = "[_this, 'inPosition'] call ALIVE_fnc_artillery"; onTransition = ""; }; class Abort { targetState = "ReturnToBase"; - condition = "!([_this, 'hasFireMission'] call ALIVE_fnc_Artillery)"; + condition = "!([_this, 'hasFireMission'] call ALIVE_fnc_artillery)"; onTransition = ""; }; }; class Execute { - onState = "[_this, 'onExecute'] call ALIVE_fnc_Artillery"; + onState = "[_this, 'onExecute'] call ALIVE_fnc_artillery"; onStateEntered = ""; onStateLeaving = ""; class Abort { targetState = "ReturnToBase"; - condition = "!([_this, 'hasFireMission'] call ALIVE_fnc_Artillery)"; + condition = "!([_this, 'hasFireMission'] call ALIVE_fnc_artillery)"; onTransition = ""; }; }; class Fire { - onState = "[_this, 'onFire'] call ALIVE_fnc_Artillery"; + onState = "[_this, 'onFire'] call ALIVE_fnc_artillery"; onStateEntered = ""; onStateLeaving = ""; class FireMissionComplete { targetState = "ReturnToBase"; - condition = "[_this, 'isFireMissionComplete'] call ALIVE_fnc_Artillery"; + condition = "[_this, 'isFireMissionComplete'] call ALIVE_fnc_artillery"; onTransition = ""; }; @@ -86,19 +86,19 @@ class ArtilleryStateMachine { class Continue { targetState = "Fire"; - condition = "[_this, 'fireNextRound'] call ALIVE_fnc_Artillery"; + condition = "[_this, 'fireNextRound'] call ALIVE_fnc_artillery"; onTransition = ""; }; }; class ReturnToBase { - onState = "[_this, 'onReturnToBase'] call ALIVE_fnc_Artillery"; + onState = "[_this, 'onReturnToBase'] call ALIVE_fnc_artillery"; onStateEntered = ""; onStateLeaving = ""; class AtBase { targetState = "Idle"; - condition = "[_this, 'inPosition'] call ALIVE_fnc_Artillery"; + condition = "[_this, 'inPosition'] call ALIVE_fnc_artillery"; onTransition = ""; }; }; diff --git a/addons/sup_artillery/CfgVehicles.hpp b/addons/sup_artillery/CfgVehicles.hpp index 9c6ac2d26..14edc5f54 100644 --- a/addons/sup_artillery/CfgVehicles.hpp +++ b/addons/sup_artillery/CfgVehicles.hpp @@ -4,7 +4,7 @@ class CfgVehicles { { scope = 2; displayName = "$STR_ALIVE_ARTILLERY"; - function = "ALIVE_fnc_ARTILLERYInit"; + function = "ALIVE_fnc_artilleryInit"; author = MODULE_AUTHOR; functionPriority = 161; isGlobal = 2; @@ -97,4 +97,4 @@ class CfgVehicles { }; }; }; -}; \ No newline at end of file +}; diff --git a/addons/sup_artillery/fnc_ARTILLERY.sqf b/addons/sup_artillery/fnc_artillery.sqf similarity index 99% rename from addons/sup_artillery/fnc_ARTILLERY.sqf rename to addons/sup_artillery/fnc_artillery.sqf index d98d6d820..bde8170a3 100644 --- a/addons/sup_artillery/fnc_ARTILLERY.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -2,7 +2,7 @@ SCRIPT(Artillery); /* ---------------------------------------------------------------------------- -Function: ALIVE_fnc_Artillery +Function: ALIVE_fnc_artillery Description: Artillery module. diff --git a/addons/sup_artillery/fnc_ARTILLERYInit.sqf b/addons/sup_artillery/fnc_artilleryInit.sqf similarity index 100% rename from addons/sup_artillery/fnc_ARTILLERYInit.sqf rename to addons/sup_artillery/fnc_artilleryInit.sqf From 10a25308809242ccfbe074ab40eb2ef6adde2f85 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Tue, 2 Aug 2016 21:54:10 +0200 Subject: [PATCH 08/29] Replace hashSet with setVariable --- addons/sup_artillery/fnc_artillery.sqf | 59 ++++++++++++++------------ 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index bde8170a3..3025af786 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -40,7 +40,13 @@ private _result = true; switch (_operation) do { case "init": { - [] call ALIVE_fnc_artillery_init; + _logic setVariable ["super", SUPERCLASS]; + _logic setVariable ["class", MAINCLASS]; + + // Defaults + _logic setVariable ["group", grpNull]; + _logic setVariable ["moveToPos", objNull]; + _logic setVariable ["fireMission", objNull]; }; /**************** @@ -48,7 +54,7 @@ switch (_operation) do { ****************/ case "fireMission": { if (isNull _args) then { - _result = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + _result = _logic getVariable ["fireMission", objNull]; } else { private _position = _args param [0, [0,0,0], [[]], 3]; private _roundType = _args param [1, "", [""]]; @@ -68,11 +74,11 @@ switch (_operation) do { [_fireMission, "roundsShot", -1] call ALIVE_fnc_hashSet; [_fireMission, "nextRoundTime", -1] call ALIVE_fnc_hashSet; - [_logic, "fireMission", _fireMission] call ALIVE_fnc_hashSet; + _logic setVariable ["fireMission", _fireMission]; }; }; case "position": { - private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + private _group = _logic getVariable ["group", grpNull]; _result = position (leader _group); }; @@ -80,16 +86,17 @@ switch (_operation) do { ** METHODS ** *************/ case "execute": { - private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + private _group = _logic getVariable ["group", grpNull]; private _units = (units _group) select {vehicle _x != _x && {gunner _x == _x}}; - private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + private _fireMission = _logic getVariable ["fireMission", objNull]; [_fireMission, "units", _units] call ALIVE_fnc_hashSet; [_fireMission, "unitIndex", 0] call ALIVE_fnc_hashSet; [_fireMission, "roundsShot", 0] call ALIVE_fnc_hashSet; - [_logic, "fireMission", _fireMission] call ALIVE_fnc_hashSet; // TODO: Is this needed? + + _logic setVariable ["fireMission", _fireMission]; }; case "fire": { - private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + private _fireMission = _logic getVariable ["fireMission", objNull]; private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet; private _units = [_fireMission, "units"] call ALIVE_fnc_hashGet; private _unitIndex = [_fireMission, "unitIndex"] call ALIVE_fnc_hashGet; @@ -113,44 +120,47 @@ switch (_operation) do { [_fireMission, "nextRoundTime", time + _delay] call ALIVE_fnc_hashSet; [_fireMission, "unitIndex", _unitIndex] call ALIVE_fnc_hashSet; [_fireMission, "roundsShot", _roundsShot + 1] call ALIVE_fnc_hashSet; - [_logic, "fireMission", _fireMission] call ALIVE_fnc_hashSet; // TODO: Is this needed? + + _logic setVariable ["fireMission", _fireMission]; }; case "fireNextRound": { - private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + private _fireMission = _logic getVariable ["fireMission", objNull]; private _nextRoundTime = [_fireMission, "nextRoundTime"] call ALIVE_fnc_hashGet; _result = (time >= _nextRoundTime); }; case "hasFireMission": { - private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; - _result = (count _fireMission == 3); + private _fireMission = _logic getVariable ["fireMission", objNull]; + _result = (!isNull _fireMission); }; case "isFireMissionComplete": { - private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; + private _fireMission = _logic getVariable ["fireMission", objNull]; private _roundCount = [_fireMission, "roundCount"] call ALIVE_fnc_hashGet; private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet; _result = (_roundsShot >= _roundCount); }; case "inPosition": { - private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + private _group = _logic getVariable ["group", grpNull]; _result = _group getVariable ["sup_artillery_inPosition", false]; }; case "inRange": { - private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet; - private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + private _fireMission = _logic getVariable ["fireMission", objNull]; + private _group = _logic getVariable ["group", grpNull]; private _units = (units _group) select {vehicle _x != _x && {gunner _x == _x}}; _result = _position inRangeOfArtillery [_units, _fireMission select 1]; }; case "move": { - private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + private _group = _logic getVariable ["group", grpNull]; private _position = []; if (!isNull _args && {count _args == 3}) then { - [_logic, "moveToPos", _args] call ALIVE_fnc_hashSet; + _logic setVariable ["moveToPos", _args]; _position = _args; } else { - _position = [_logic, "moveToPos"] call ALIVE_fnc_hashGet; + _position = _logic getVariable ["moveToPos", objNull]; }; + _group setVariable ["sup_artillery_inPosition", false]; + private _waypoint = _group addWaypoint [_position, 0]; _waypoint setWaypointType "MOVE"; _waypoint setWaypointBehaviour "SAFE"; @@ -159,22 +169,19 @@ switch (_operation) do { "true", "(group _this) setVariable ['sup_artillery_inPosition', true]" ]; - - _group setVariable ["sup_artillery_inPosition", false]; }; /****************** ** STATEMACHINE ** ******************/ case "onIdle": { - private _group = [_logic, "group"] call ALIVE_fnc_hashGet; + private _group = _logic getVariable ["group", grpNull]; _group setVariable ["sup_artillery_inPosition", true]; - [_logic, "moveToPos", objNull] call ALIVE_fnc_hashSet; - + _logic setVariable ["moveToPos", objNull]; }; case "onActive": { if (!([_logic, "inRange"] call MAINCLASS)) then { - [_logic, "moveToPos", [0,0,0]] call ALIVE_fnc_hashSet; // TODO: Figure out best firing position + _logic setVariable ["moveToPos", [0,0,0]]; // TODO: Figure out best firing position }; }; case "onFire": { @@ -187,7 +194,7 @@ switch (_operation) do { [_logic, "execute"] call MAINCLASS; }; case "onReturnToBase": { - [_logic, "move", [0,0,0]] call MAINCLASS; // TODO: Find (best) RTB position + [_logic, "move", position _logic] call MAINCLASS; // TODO: Find (best) RTB position }; }; From 00501ba673a7129d6b140e928647840f3696a756 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sun, 7 Aug 2016 00:36:00 +0200 Subject: [PATCH 09/29] Update ArtilleryStateMachine (onState => onStateEntered) --- .../sup_artillery/ArtilleryStateMachine.hpp | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/addons/sup_artillery/ArtilleryStateMachine.hpp b/addons/sup_artillery/ArtilleryStateMachine.hpp index b0071fc23..29cbea635 100644 --- a/addons/sup_artillery/ArtilleryStateMachine.hpp +++ b/addons/sup_artillery/ArtilleryStateMachine.hpp @@ -1,5 +1,5 @@ class ArtilleryStateMachine { - list = ""; + list = "ALIVE_sup_artillery_stateMachine_list"; class Idle { onState = ""; @@ -14,8 +14,8 @@ class ArtilleryStateMachine { }; class Active { - onState = "[_this, 'onActive'] call ALIVE_fnc_artillery"; - onStateEntered = ""; + onState = ""; + onStateEntered = "[_this, 'onActive'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class InRange { @@ -32,8 +32,8 @@ class ArtilleryStateMachine { }; class Move { - onState = "[_this, 'onMove'] call ALIVE_fnc_artillery"; - onStateEntered = ""; + onState = ""; + onStateEntered = "[_this, 'onMove'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class InPosition { @@ -50,10 +50,16 @@ class ArtilleryStateMachine { }; class Execute { - onState = "[_this, 'onExecute'] call ALIVE_fnc_artillery"; - onStateEntered = ""; + onState = ""; + onStateEntered = "[_this, 'onExecute'] call ALIVE_fnc_artillery"; onStateLeaving = ""; + class Fire { + targetState = "Fire"; + condition = "[_this, 'fireNextRound'] call ALIVE_fnc_artillery"; + onTransition = ""; + }; + class Abort { targetState = "ReturnToBase"; condition = "!([_this, 'hasFireMission'] call ALIVE_fnc_artillery)"; @@ -62,8 +68,8 @@ class ArtilleryStateMachine { }; class Fire { - onState = "[_this, 'onFire'] call ALIVE_fnc_artillery"; - onStateEntered = ""; + onState = ""; + onStateEntered = "[_this, 'onFire'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class FireMissionComplete { @@ -92,8 +98,8 @@ class ArtilleryStateMachine { }; class ReturnToBase { - onState = "[_this, 'onReturnToBase'] call ALIVE_fnc_artillery"; - onStateEntered = ""; + onState = ""; + onStateEntered = "[_this, 'onReturnToBase'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class AtBase { From 03e38b472bb009b30482b70bd53dfb9940afb43c Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sun, 7 Aug 2016 00:39:18 +0200 Subject: [PATCH 10/29] Spawn arty units using the artillery class Very basic and leaves CS (Arty) in a broken state... :smile: --- addons/sup_artillery/fnc_artillery.sqf | 70 +++++++++++++++---- .../sup_combatsupport/fnc_combatSupport.sqf | 9 ++- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 3025af786..65b97811d 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -34,26 +34,28 @@ marceldev89 private _logic = param [0, objNull, [objNull, []]]; private _operation = param [1, "", [""]]; -private _args = param [2, objNull, [objNull, [], "", 0, true, false]]; +private _args = param [2, [], [objNull, [], "", 0, true, false]]; private _result = true; +diag_log format ["###### %1: _logic: %2, _operation: %3, _args: %4", "ALIVE_fnc_artillery", _logic, _operation, _args]; + switch (_operation) do { case "init": { _logic setVariable ["super", SUPERCLASS]; _logic setVariable ["class", MAINCLASS]; // Defaults - _logic setVariable ["group", grpNull]; + /* _logic setVariable ["group", grpNull]; */ _logic setVariable ["moveToPos", objNull]; - _logic setVariable ["fireMission", objNull]; + _logic setVariable ["fireMission", []]; }; /**************** ** PROPERTIES ** ****************/ case "fireMission": { - if (isNull _args) then { + if (count _args == 0) then { _result = _logic getVariable ["fireMission", objNull]; } else { private _position = _args param [0, [0,0,0], [[]], 3]; @@ -87,11 +89,13 @@ switch (_operation) do { *************/ case "execute": { private _group = _logic getVariable ["group", grpNull]; - private _units = (units _group) select {vehicle _x != _x && {gunner _x == _x}}; + private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; private _fireMission = _logic getVariable ["fireMission", objNull]; + private _fireMissionPos = [_fireMission, "position"] call ALIVE_fnc_hashGet; [_fireMission, "units", _units] call ALIVE_fnc_hashSet; [_fireMission, "unitIndex", 0] call ALIVE_fnc_hashSet; [_fireMission, "roundsShot", 0] call ALIVE_fnc_hashSet; + _units doWatch _fireMissionPos; _logic setVariable ["fireMission", _fireMission]; }; @@ -130,7 +134,7 @@ switch (_operation) do { }; case "hasFireMission": { private _fireMission = _logic getVariable ["fireMission", objNull]; - _result = (!isNull _fireMission); + _result = (count _fireMission > 0); }; case "isFireMissionComplete": { private _fireMission = _logic getVariable ["fireMission", objNull]; @@ -144,19 +148,21 @@ switch (_operation) do { }; case "inRange": { private _fireMission = _logic getVariable ["fireMission", objNull]; + private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; + private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; private _group = _logic getVariable ["group", grpNull]; - private _units = (units _group) select {vehicle _x != _x && {gunner _x == _x}}; - _result = _position inRangeOfArtillery [_units, _fireMission select 1]; + private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; + _result = _position inRangeOfArtillery [_units, _roundType]; }; case "move": { private _group = _logic getVariable ["group", grpNull]; private _position = []; - if (!isNull _args && {count _args == 3}) then { - _logic setVariable ["moveToPos", _args]; - _position = _args; - } else { + if (count _args == 0) then { _position = _logic getVariable ["moveToPos", objNull]; + } else { + _position = _args param [0, [0,0,0], [[]], 3]; + _logic setVariable ["moveToPos", _position]; }; _group setVariable ["sup_artillery_inPosition", false]; @@ -167,8 +173,39 @@ switch (_operation) do { _waypoint setWaypointSpeed "NORMAL"; _waypoint setWaypointStatements [ "true", - "(group _this) setVariable ['sup_artillery_inPosition', true]" + "(group this) setVariable ['sup_artillery_inPosition', true]" ]; + diag_log format["_group: %1, _position: %2, _waypoint: %3", _group, _position, _waypoint]; + }; + case "spawn": { + private _position = position _logic; + private _type = _logic getVariable ["artillery_type", ""]; + private _callsign = _logic getVariable ["artillery_callsign", ""]; + private _code = _logic getVariable ["artillery_code", ""]; + + private _side = _type call ALIVE_fnc_classSide; + private _group = createGroup _side; + + for "_i" from 0 to 2 do { + // TODO: Spawn vehicles in proper fancy formation (see CfgFormations) + private _vehiclePosition = _position getPos [15 * _i, (getDir _logic) * _i]; + private _vehicle = createVehicle [_type, _vehiclePosition, [], 0, "NONE"]; + _vehicle setDir (getDir _logic); + _vehicle lock true; + [_vehicle, _group] call BIS_fnc_spawnCrew; + }; + + _group setVariable ["logic", _logic]; + _logic setVariable ["group", _group]; + + if (isNil "ALIVE_sup_artillery_stateMachine") then { + ALIVE_sup_artillery_stateMachine_list = []; + ALIVE_sup_artillery_stateMachine = [ + configFile >> "ArtilleryStateMachine" + ] call CBA_statemachine_fnc_createFromConfig; + }; + + ALIVE_sup_artillery_stateMachine_list pushBack _logic; }; /****************** @@ -194,7 +231,12 @@ switch (_operation) do { [_logic, "execute"] call MAINCLASS; }; case "onReturnToBase": { - [_logic, "move", position _logic] call MAINCLASS; // TODO: Find (best) RTB position + private _group = _logic getVariable ["group", grpNull]; + private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; + _units doWatch objNull; + + _logic setVariable ["fireMission", []]; + [_logic, "move", [position _logic]] call MAINCLASS; // TODO: Find (best) RTB position }; }; diff --git a/addons/sup_combatsupport/fnc_combatSupport.sqf b/addons/sup_combatsupport/fnc_combatSupport.sqf index 06e871379..a143fa866 100644 --- a/addons/sup_combatsupport/fnc_combatSupport.sqf +++ b/addons/sup_combatsupport/fnc_combatSupport.sqf @@ -712,8 +712,15 @@ switch(_operation) do { NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", _side], _a, true]; - } forEach SUP_ARTYARRAYS; + //} forEach SUP_ARTYARRAYS; + } forEach []; + for "_i" from 0 to ((count synchronizedObjects _logic)-1) do { + if (typeOf ((synchronizedObjects _logic) select _i) == "ALiVE_sup_artillery") then { + private _artyLogic = (synchronizedObjects _logic) select _i; + [_artyLogic, "spawn"] call ALIVE_fnc_artillery; + }; + }; From 291f5582c96c7ac2167160e8a2276d041b4e3eb4 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sun, 14 Aug 2016 17:24:15 +0200 Subject: [PATCH 11/29] Basic integration of sup_artillery with NEO_radio Can now request and execute arty support --- addons/sup_artillery/fnc_artillery.sqf | 6 ++- .../sup_combatsupport/fnc_combatSupport.sqf | 38 ++++++++++++++++++- .../ui/arty/fn_artyConfirmButton.sqf | 3 ++ .../ui/arty/fn_artyConfirmButtonEnable.sqf | 1 + .../ui/arty/fn_artyUnitLbSelChanged.sqf | 1 + 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 65b97811d..f6c51757b 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -170,7 +170,9 @@ switch (_operation) do { private _waypoint = _group addWaypoint [_position, 0]; _waypoint setWaypointType "MOVE"; _waypoint setWaypointBehaviour "SAFE"; + _waypoint setWaypointForceBehaviour true; _waypoint setWaypointSpeed "NORMAL"; + _waypoint setWaypointFormation "COLUMN"; _waypoint setWaypointStatements [ "true", "(group this) setVariable ['sup_artillery_inPosition', true]" @@ -206,6 +208,8 @@ switch (_operation) do { }; ALIVE_sup_artillery_stateMachine_list pushBack _logic; + + _result = _group; }; /****************** @@ -218,7 +222,7 @@ switch (_operation) do { }; case "onActive": { if (!([_logic, "inRange"] call MAINCLASS)) then { - _logic setVariable ["moveToPos", [0,0,0]]; // TODO: Figure out best firing position + _logic setVariable ["moveToPos", [3451.45,5379.89,0]]; // TODO: Figure out best firing position }; }; case "onFire": { diff --git a/addons/sup_combatsupport/fnc_combatSupport.sqf b/addons/sup_combatsupport/fnc_combatSupport.sqf index a143fa866..38ea8a3ad 100644 --- a/addons/sup_combatsupport/fnc_combatSupport.sqf +++ b/addons/sup_combatsupport/fnc_combatSupport.sqf @@ -715,10 +715,46 @@ switch(_operation) do { //} forEach SUP_ARTYARRAYS; } forEach []; + // TODO: Move most of the code below to ALIVE_fnc_artillery for "_i" from 0 to ((count synchronizedObjects _logic)-1) do { if (typeOf ((synchronizedObjects _logic) select _i) == "ALiVE_sup_artillery") then { private _artyLogic = (synchronizedObjects _logic) select _i; - [_artyLogic, "spawn"] call ALIVE_fnc_artillery; + private _group = [_artyLogic, "spawn"] call ALIVE_fnc_artillery; + private _vehicles = []; + + { + if (vehicle _x != _x && {!(vehicle _x in _vehicles)}) then { + _vehicles pushBack (vehicle _x); + }; + } forEach (units _group); + + private _callsign = _artyLogic getVariable ["artillery_callsign","FOX ONE"]; + + private _rounds = [ + ["HE", parseNumber (_artyLogic getVariable ["artillery_he", "30"])], + ["ILLUM", parseNumber (_artyLogic getVariable ["artillery_illum", "30"])], + ["SMOKE", parseNumber (_artyLogic getVariable ["artillery_smoke", "30"])], + ["SADARM", parseNumber (_artyLogic getVariable ["artillery_guided", "30"])], + ["CLUSTER", parseNumber (_artyLogic getVariable ["artillery_cluster", "30"])], + ["LASER", parseNumber (_artyLogic getVariable ["artillery_lg", "30"])], + ["MINE", parseNumber (_artyLogic getVariable ["artillery_mine", "30"])], + ["AT MINE", parseNumber (_artyLogic getVariable ["artillery_atmine", "30"])], + ["ROCKETS", parseNumber (_artyLogic getVariable ["artillery_rockets", "16"])] + ]; + + private _roundsAvailable = []; + private _roundsUnit = (typeOf (_vehicles select 0)) call ALIVE_fnc_getArtyRounds; + + { + if ((_x select 0) in _roundsUnit) then { + _roundsAvailable pushBack _x; + }; + } forEach _rounds; + + leader _group setVariable ["NEO_radioArtyBatteryRounds", _roundsAvailable, true]; + private _a = NEO_radioLogic getVariable format ["NEO_radioArtyArray_%1", side _group]; + _a set [count _a, [leader _group, _group, _callsign, _vehicles, _roundsAvailable]]; + NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", side _group], _a, true]; }; }; diff --git a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf index 52bf768c4..f7b3ad7c2 100644 --- a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf +++ b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf @@ -57,6 +57,9 @@ if (_audio) then { player kbTell [_battery, "ALIVE_SUPP_protocol", "Artillery_Request", "GROUP"]; }; +// TODO: Cleanup obsolete bits +private _logic = _unit getVariable ["logic", objNull]; +[_logic, "fireMission", [_pos, _ord, _count, _rate, _dispersion]] call ALIVE_fnc_artillery; //NEW TASK _battery setVariable ["NEO_radioArtyNewTask", [_type, _ordnanceType, _rate, _count, _dispersion, _pos, _unit, _ord, _callsignPlayer, player], true]; diff --git a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButtonEnable.sqf b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButtonEnable.sqf index a2e050863..1876634a0 100644 --- a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButtonEnable.sqf +++ b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButtonEnable.sqf @@ -12,6 +12,7 @@ _artyRateOfFireLb = _display displayCtrl 655603; _artyRoundCountLb = _display displayCtrl 655605; _battery = _artyArray select (lbCurSel _artyUnitLb) select 0; if (!isNil { NEO_radioLogic getVariable "NEO_radioTalkWithArty" }) then { _battery = ((NEO_radioLogic getVariable "NEO_radioTalkWithArty") getVariable "NEO_radioArtyModule") select 0 }; _status = _battery getVariable "NEO_radioArtyUnitStatus"; +_status = "NONE"; // TODO: Handle status properly if ( diff --git a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyUnitLbSelChanged.sqf b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyUnitLbSelChanged.sqf index f4c533cfc..dfcf4e83a 100644 --- a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyUnitLbSelChanged.sqf +++ b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyUnitLbSelChanged.sqf @@ -31,6 +31,7 @@ _supportMarker = NEO_radioLogic getVariable "NEO_supportMarker"; _artyMarkers = NEO_radioLogic getVariable "NEO_supportArtyMarkers"; _battery = _artyArray select (lbCurSel _artyUnitLb) select 0; if (!isNil { NEO_radioLogic getVariable "NEO_radioTalkWithArty" }) then { _battery = ((NEO_radioLogic getVariable "NEO_radioTalkWithArty") getVariable "NEO_radioArtyModule") select 0 }; _status = _battery getVariable "NEO_radioArtyUnitStatus"; +_status = "NONE"; // TODO: Handle status properly _class = typeOf (((_artyArray select (lbCurSel _artyUnitLb)) select 3) select 0); if (!isNil { NEO_radioLogic getVariable "NEO_radioTalkWithArty" }) then { _class = typeOf (NEO_radioLogic getVariable "NEO_radioTalkWithArty") }; _ord = _battery getVariable "NEO_radioArtyBatteryRounds"; From d9a9eafc6471595ca4065133747948e487d6f1aa Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Wed, 17 Aug 2016 00:39:03 +0200 Subject: [PATCH 12/29] Add support for "full" and "semi" rate of fire --- .../sup_artillery/ArtilleryStateMachine.hpp | 8 +- addons/sup_artillery/fnc_artillery.sqf | 110 +++++++++++++----- 2 files changed, 91 insertions(+), 27 deletions(-) diff --git a/addons/sup_artillery/ArtilleryStateMachine.hpp b/addons/sup_artillery/ArtilleryStateMachine.hpp index 29cbea635..d7c12b24c 100644 --- a/addons/sup_artillery/ArtilleryStateMachine.hpp +++ b/addons/sup_artillery/ArtilleryStateMachine.hpp @@ -80,7 +80,7 @@ class ArtilleryStateMachine { class Fired { targetState = "FireDelay"; - condition = "true"; + condition = "[_this, 'isFireMissionDelayed'] call ALIVE_fnc_artillery"; onTransition = ""; }; }; @@ -90,6 +90,12 @@ class ArtilleryStateMachine { onStateEntered = ""; onStateLeaving = ""; + class FireMissionComplete { + targetState = "ReturnToBase"; + condition = "[_this, 'isFireMissionComplete'] call ALIVE_fnc_artillery"; + onTransition = ""; + }; + class Continue { targetState = "Fire"; condition = "[_this, 'fireNextRound'] call ALIVE_fnc_artillery"; diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index f6c51757b..8709d9f66 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -56,7 +56,7 @@ switch (_operation) do { ****************/ case "fireMission": { if (count _args == 0) then { - _result = _logic getVariable ["fireMission", objNull]; + _result = _logic getVariable ["fireMission", []]; } else { private _position = _args param [0, [0,0,0], [[]], 3]; private _roundType = _args param [1, "", [""]]; @@ -90,64 +90,112 @@ switch (_operation) do { case "execute": { private _group = _logic getVariable ["group", grpNull]; private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; - private _fireMission = _logic getVariable ["fireMission", objNull]; + private _fireMission = _logic getVariable ["fireMission", []]; private _fireMissionPos = [_fireMission, "position"] call ALIVE_fnc_hashGet; [_fireMission, "units", _units] call ALIVE_fnc_hashSet; [_fireMission, "unitIndex", 0] call ALIVE_fnc_hashSet; [_fireMission, "roundsShot", 0] call ALIVE_fnc_hashSet; + [_fireMission, "nextRoundTime", time] call ALIVE_fnc_hashSet; + /* _units doWatch [_fireMissionPos select 0, _fireMissionPos select 1, 9999]; */ _units doWatch _fireMissionPos; _logic setVariable ["fireMission", _fireMission]; + + // Attach Fired EH to all vehicles in group + { + private _vehicle = vehicle _x; + private _firedEH = _vehicle addEventHandler ["Fired", { + private _unit = param [0, objNull]; + private _magazine = param [5, ""]; + private _logic = (group _unit) getVariable ["logic", objNull]; + private _fireMission = _logic getVariable ["fireMission", []]; + private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; + private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet; + + if (_magazine == _roundType) then { + private _delay = [_fireMission, "delay"] call ALIVE_fnc_hashGet; + + if (_delay > 0) then { + private _units = [_fireMission, "units"] call ALIVE_fnc_hashGet; + private _unitIndex = [_fireMission, "unitIndex"] call ALIVE_fnc_hashGet; + + if ((_unitIndex + 1) >= count _units) then { + _unitIndex = 0; + } else { + _unitIndex = _unitIndex + 1; + }; + + [_fireMission, "unitIndex", _unitIndex] call ALIVE_fnc_hashSet; + [_fireMission, "nextRoundTime", time + _delay] call ALIVE_fnc_hashSet; + }; + + [_fireMission, "roundsShot", _roundsShot + 1] call ALIVE_fnc_hashSet; + _logic setVariable ["fireMission", _fireMission]; + }; + }]; + _vehicle setVariable ["sup_artillery_firedEH", _firedEH]; + } forEach _units; }; + // TODO: Check if unit is alive, otherwise skip case "fire": { - private _fireMission = _logic getVariable ["fireMission", objNull]; - private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet; + private _fireMission = _logic getVariable ["fireMission", []]; + private _delay = [_fireMission, "delay"] call ALIVE_fnc_hashGet; private _units = [_fireMission, "units"] call ALIVE_fnc_hashGet; - private _unitIndex = [_fireMission, "unitIndex"] call ALIVE_fnc_hashGet; - private _unit = _units select _unitIndex; private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; - private _delay = [_fireMission, "delay"] call ALIVE_fnc_hashGet; - _unit doArtilleryFire [ - _position, - _roundType, - 1 - ]; + if (_delay > 0) then { + private _unitIndex = [_fireMission, "unitIndex"] call ALIVE_fnc_hashGet; + private _unit = _units select _unitIndex; + + _unit doArtilleryFire [ + _position, + _roundType, + 1 + ]; - if ((_unitIndex + 1) > ((count _units) - 1)) then { - _unitIndex = 0; + hint format ["%3: _unit: %1 firing 1 %2", _unit, _roundType, time]; } else { - _unitIndex = _unitIndex + 1; + { + private _roundCount = [_fireMission, "roundCount"] call ALIVE_fnc_hashGet; + + _x doArtilleryFire [ + _position, + _roundType, + floor (_roundCount / (count _units)) // TODO: Better distribution + ]; + } forEach _units; }; - [_fireMission, "nextRoundTime", time + _delay] call ALIVE_fnc_hashSet; - [_fireMission, "unitIndex", _unitIndex] call ALIVE_fnc_hashSet; - [_fireMission, "roundsShot", _roundsShot + 1] call ALIVE_fnc_hashSet; - + [_fireMission, "nextRoundTime", -1] call ALIVE_fnc_hashSet; _logic setVariable ["fireMission", _fireMission]; }; case "fireNextRound": { - private _fireMission = _logic getVariable ["fireMission", objNull]; + private _fireMission = _logic getVariable ["fireMission", []]; private _nextRoundTime = [_fireMission, "nextRoundTime"] call ALIVE_fnc_hashGet; - _result = (time >= _nextRoundTime); + _result = (_nextRoundTime != -1 && {time >= _nextRoundTime}); }; case "hasFireMission": { - private _fireMission = _logic getVariable ["fireMission", objNull]; + private _fireMission = _logic getVariable ["fireMission", []]; _result = (count _fireMission > 0); }; case "isFireMissionComplete": { - private _fireMission = _logic getVariable ["fireMission", objNull]; + private _fireMission = _logic getVariable ["fireMission", []]; private _roundCount = [_fireMission, "roundCount"] call ALIVE_fnc_hashGet; private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet; _result = (_roundsShot >= _roundCount); }; + case "isFireMissionDelayed": { + private _fireMission = _logic getVariable ["fireMission", []]; + private _delay = [_fireMission, "delay"] call ALIVE_fnc_hashGet; + _result = (_delay > 0); + }; case "inPosition": { private _group = _logic getVariable ["group", grpNull]; _result = _group getVariable ["sup_artillery_inPosition", false]; }; case "inRange": { - private _fireMission = _logic getVariable ["fireMission", objNull]; + private _fireMission = _logic getVariable ["fireMission", []]; private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; private _group = _logic getVariable ["group", grpNull]; @@ -177,7 +225,6 @@ switch (_operation) do { "true", "(group this) setVariable ['sup_artillery_inPosition', true]" ]; - diag_log format["_group: %1, _position: %2, _waypoint: %3", _group, _position, _waypoint]; }; case "spawn": { private _position = position _logic; @@ -222,7 +269,7 @@ switch (_operation) do { }; case "onActive": { if (!([_logic, "inRange"] call MAINCLASS)) then { - _logic setVariable ["moveToPos", [3451.45,5379.89,0]]; // TODO: Figure out best firing position + _logic setVariable ["moveToPos", [3744.56,4757.54,0]]; // TODO: Figure out best firing position }; }; case "onFire": { @@ -239,6 +286,17 @@ switch (_operation) do { private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; _units doWatch objNull; + // Cleanup event handlers + { + private _vehicle = vehicle _x; + private _firedEH = _vehicle getVariable ["sup_artillery_firedEH", nil]; + + if (!isNil "_firedEH") then { + _vehicle removeEventHandler ["Fired", _firedEH]; + _vehicle setVariable ["sup_artillery_firedEH", nil]; + }; + } forEach _units; + _logic setVariable ["fireMission", []]; [_logic, "move", [position _logic]] call MAINCLASS; // TODO: Find (best) RTB position }; From 43dbfce66262a91e06ddad0ad31edea9c52389cf Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 24 Sep 2016 16:07:56 +0200 Subject: [PATCH 13/29] Move bits from fnc_combatSupport to fnc_artillery --- addons/sup_artillery/fnc_artillery.sqf | 32 +++++++++++++++ .../sup_combatsupport/fnc_combatSupport.sqf | 40 +------------------ 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 8709d9f66..16892080c 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -234,6 +234,7 @@ switch (_operation) do { private _side = _type call ALIVE_fnc_classSide; private _group = createGroup _side; + private _vehicles = []; for "_i" from 0 to 2 do { // TODO: Spawn vehicles in proper fancy formation (see CfgFormations) @@ -242,11 +243,41 @@ switch (_operation) do { _vehicle setDir (getDir _logic); _vehicle lock true; [_vehicle, _group] call BIS_fnc_spawnCrew; + _vehicles pushBack _vehicle; }; _group setVariable ["logic", _logic]; _logic setVariable ["group", _group]; + // Set available rounds + private _rounds = [ + ["HE", parseNumber (_artyLogic getVariable ["artillery_he", "30"])], + ["ILLUM", parseNumber (_artyLogic getVariable ["artillery_illum", "30"])], + ["SMOKE", parseNumber (_artyLogic getVariable ["artillery_smoke", "30"])], + ["SADARM", parseNumber (_artyLogic getVariable ["artillery_guided", "30"])], + ["CLUSTER", parseNumber (_artyLogic getVariable ["artillery_cluster", "30"])], + ["LASER", parseNumber (_artyLogic getVariable ["artillery_lg", "30"])], + ["MINE", parseNumber (_artyLogic getVariable ["artillery_mine", "30"])], + ["AT MINE", parseNumber (_artyLogic getVariable ["artillery_atmine", "30"])], + ["ROCKETS", parseNumber (_artyLogic getVariable ["artillery_rockets", "16"])] + ]; + + private _roundsAvailable = []; + private _roundsUnit = (typeOf (_vehicles select 0)) call ALIVE_fnc_getArtyRounds; + + { + if ((_x select 0) in _roundsUnit) then { + _roundsAvailable pushBack _x; + }; + } forEach _rounds; + + // Assign artillery group to the NEO_radio scripts + leader _group setVariable ["NEO_radioArtyBatteryRounds", _roundsAvailable, true]; + private _a = NEO_radioLogic getVariable format ["NEO_radioArtyArray_%1", _side]; + _a set [count _a, [leader _group, _group, _callsign, _vehicles, _roundsAvailable]]; + NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", _side], _a, true]; + + // Start state machine if it hasn't already if (isNil "ALIVE_sup_artillery_stateMachine") then { ALIVE_sup_artillery_stateMachine_list = []; ALIVE_sup_artillery_stateMachine = [ @@ -254,6 +285,7 @@ switch (_operation) do { ] call CBA_statemachine_fnc_createFromConfig; }; + // Add artillery group to state machine ALIVE_sup_artillery_stateMachine_list pushBack _logic; _result = _group; diff --git a/addons/sup_combatsupport/fnc_combatSupport.sqf b/addons/sup_combatsupport/fnc_combatSupport.sqf index 38ea8a3ad..f93786e15 100644 --- a/addons/sup_combatsupport/fnc_combatSupport.sqf +++ b/addons/sup_combatsupport/fnc_combatSupport.sqf @@ -713,48 +713,12 @@ switch(_operation) do { NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", _side], _a, true]; //} forEach SUP_ARTYARRAYS; - } forEach []; + } forEach []; // TODO: Delete entire block once arty fixes are done :-) - // TODO: Move most of the code below to ALIVE_fnc_artillery for "_i" from 0 to ((count synchronizedObjects _logic)-1) do { if (typeOf ((synchronizedObjects _logic) select _i) == "ALiVE_sup_artillery") then { private _artyLogic = (synchronizedObjects _logic) select _i; - private _group = [_artyLogic, "spawn"] call ALIVE_fnc_artillery; - private _vehicles = []; - - { - if (vehicle _x != _x && {!(vehicle _x in _vehicles)}) then { - _vehicles pushBack (vehicle _x); - }; - } forEach (units _group); - - private _callsign = _artyLogic getVariable ["artillery_callsign","FOX ONE"]; - - private _rounds = [ - ["HE", parseNumber (_artyLogic getVariable ["artillery_he", "30"])], - ["ILLUM", parseNumber (_artyLogic getVariable ["artillery_illum", "30"])], - ["SMOKE", parseNumber (_artyLogic getVariable ["artillery_smoke", "30"])], - ["SADARM", parseNumber (_artyLogic getVariable ["artillery_guided", "30"])], - ["CLUSTER", parseNumber (_artyLogic getVariable ["artillery_cluster", "30"])], - ["LASER", parseNumber (_artyLogic getVariable ["artillery_lg", "30"])], - ["MINE", parseNumber (_artyLogic getVariable ["artillery_mine", "30"])], - ["AT MINE", parseNumber (_artyLogic getVariable ["artillery_atmine", "30"])], - ["ROCKETS", parseNumber (_artyLogic getVariable ["artillery_rockets", "16"])] - ]; - - private _roundsAvailable = []; - private _roundsUnit = (typeOf (_vehicles select 0)) call ALIVE_fnc_getArtyRounds; - - { - if ((_x select 0) in _roundsUnit) then { - _roundsAvailable pushBack _x; - }; - } forEach _rounds; - - leader _group setVariable ["NEO_radioArtyBatteryRounds", _roundsAvailable, true]; - private _a = NEO_radioLogic getVariable format ["NEO_radioArtyArray_%1", side _group]; - _a set [count _a, [leader _group, _group, _callsign, _vehicles, _roundsAvailable]]; - NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", side _group], _a, true]; + [_artyLogic, "spawn"] call ALIVE_fnc_artillery; }; }; From cc09e94edbb187fc987f8a49d64815a1c8ca89fd Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 24 Sep 2016 16:24:08 +0200 Subject: [PATCH 14/29] Add "rounds" property to fnc_artillery Gets the available rounds for the given arty group --- addons/sup_artillery/fnc_artillery.sqf | 51 ++++++++++++++------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 16892080c..296632821 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -83,6 +83,30 @@ switch (_operation) do { private _group = _logic getVariable ["group", grpNull]; _result = position (leader _group); }; + case "rounds": { + private _rounds = [ + ["HE", parseNumber (_logic getVariable ["artillery_he", "30"])], + ["ILLUM", parseNumber (_logic getVariable ["artillery_illum", "30"])], + ["SMOKE", parseNumber (_logic getVariable ["artillery_smoke", "30"])], + ["SADARM", parseNumber (_logic getVariable ["artillery_guided", "30"])], + ["CLUSTER", parseNumber (_logic getVariable ["artillery_cluster", "30"])], + ["LASER", parseNumber (_logic getVariable ["artillery_lg", "30"])], + ["MINE", parseNumber (_logic getVariable ["artillery_mine", "30"])], + ["AT MINE", parseNumber (_logic getVariable ["artillery_atmine", "30"])], + ["ROCKETS", parseNumber (_logic getVariable ["artillery_rockets", "16"])] + ]; + + private _roundsAvailable = []; + private _roundsUnit = (typeOf (_vehicles select 0)) call ALIVE_fnc_getArtyRounds; + + { + if ((_x select 0) in _roundsUnit) then { + _roundsAvailable pushBack _x; + }; + } forEach _rounds; + + _result = _roundsAvailable; + }; /************* ** METHODS ** @@ -249,32 +273,11 @@ switch (_operation) do { _group setVariable ["logic", _logic]; _logic setVariable ["group", _group]; - // Set available rounds - private _rounds = [ - ["HE", parseNumber (_artyLogic getVariable ["artillery_he", "30"])], - ["ILLUM", parseNumber (_artyLogic getVariable ["artillery_illum", "30"])], - ["SMOKE", parseNumber (_artyLogic getVariable ["artillery_smoke", "30"])], - ["SADARM", parseNumber (_artyLogic getVariable ["artillery_guided", "30"])], - ["CLUSTER", parseNumber (_artyLogic getVariable ["artillery_cluster", "30"])], - ["LASER", parseNumber (_artyLogic getVariable ["artillery_lg", "30"])], - ["MINE", parseNumber (_artyLogic getVariable ["artillery_mine", "30"])], - ["AT MINE", parseNumber (_artyLogic getVariable ["artillery_atmine", "30"])], - ["ROCKETS", parseNumber (_artyLogic getVariable ["artillery_rockets", "16"])] - ]; - - private _roundsAvailable = []; - private _roundsUnit = (typeOf (_vehicles select 0)) call ALIVE_fnc_getArtyRounds; - - { - if ((_x select 0) in _roundsUnit) then { - _roundsAvailable pushBack _x; - }; - } forEach _rounds; - // Assign artillery group to the NEO_radio scripts - leader _group setVariable ["NEO_radioArtyBatteryRounds", _roundsAvailable, true]; + private _rounds = [_logic, "rounds"] call MAINCLASS; + leader _group setVariable ["NEO_radioArtyBatteryRounds", _rounds, true]; private _a = NEO_radioLogic getVariable format ["NEO_radioArtyArray_%1", _side]; - _a set [count _a, [leader _group, _group, _callsign, _vehicles, _roundsAvailable]]; + _a set [count _a, [leader _group, _group, _callsign, _vehicles, _rounds]]; NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", _side], _a, true]; // Start state machine if it hasn't already From 37bbf2cb5dae58e9e4f4da929ccbbebac9dda1a2 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 24 Sep 2016 16:38:45 +0200 Subject: [PATCH 15/29] Cleanup --- addons/sup_artillery/fnc_artillery.sqf | 39 +++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 296632821..4fa6386fc 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -177,8 +177,6 @@ switch (_operation) do { _roundType, 1 ]; - - hint format ["%3: _unit: %1 firing 1 %2", _unit, _roundType, time]; } else { { private _roundCount = [_fireMission, "roundCount"] call ALIVE_fnc_hashGet; @@ -250,6 +248,25 @@ switch (_operation) do { "(group this) setVariable ['sup_artillery_inPosition', true]" ]; }; + case "returnToBase": { + private _group = _logic getVariable ["group", grpNull]; + private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; + _units doWatch objNull; + + // Cleanup event handlers + { + private _vehicle = vehicle _x; + private _firedEH = _vehicle getVariable ["sup_artillery_firedEH", nil]; + + if (!isNil "_firedEH") then { + _vehicle removeEventHandler ["Fired", _firedEH]; + _vehicle setVariable ["sup_artillery_firedEH", nil]; + }; + } forEach _units; + + _logic setVariable ["fireMission", []]; + [_logic, "move", [position _logic]] call MAINCLASS; + }; case "spawn": { private _position = position _logic; private _type = _logic getVariable ["artillery_type", ""]; @@ -317,23 +334,7 @@ switch (_operation) do { [_logic, "execute"] call MAINCLASS; }; case "onReturnToBase": { - private _group = _logic getVariable ["group", grpNull]; - private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; - _units doWatch objNull; - - // Cleanup event handlers - { - private _vehicle = vehicle _x; - private _firedEH = _vehicle getVariable ["sup_artillery_firedEH", nil]; - - if (!isNil "_firedEH") then { - _vehicle removeEventHandler ["Fired", _firedEH]; - _vehicle setVariable ["sup_artillery_firedEH", nil]; - }; - } forEach _units; - - _logic setVariable ["fireMission", []]; - [_logic, "move", [position _logic]] call MAINCLASS; // TODO: Find (best) RTB position + [_logic, "returnToBase"] call MAINCLASS; }; }; From 3a1941f65685fcc8bc86a856c1e40c129a29509f Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 22 Oct 2016 00:32:59 +0200 Subject: [PATCH 16/29] Pack/unpack mortars --- .../sup_artillery/ArtilleryStateMachine.hpp | 28 ++++++- addons/sup_artillery/fnc_artillery.sqf | 79 ++++++++++++++++++- addons/sup_combatsupport/fnc_packMortar.sqf | 2 +- 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/addons/sup_artillery/ArtilleryStateMachine.hpp b/addons/sup_artillery/ArtilleryStateMachine.hpp index d7c12b24c..f86ebf994 100644 --- a/addons/sup_artillery/ArtilleryStateMachine.hpp +++ b/addons/sup_artillery/ArtilleryStateMachine.hpp @@ -25,19 +25,31 @@ class ArtilleryStateMachine { }; class NotInRange { - targetState = "Move"; + targetState = "Pack"; condition = "!([_this, 'inRange'] call ALIVE_fnc_artillery)"; onTransition = ""; }; }; + class Pack { + onState = ""; + onStateEntered = "[_this, 'onPack'] call ALIVE_fnc_artillery"; + onStateLeaving = ""; + + class Packed { + targetState = "Move"; + condition = "[_this, 'hasPacked'] call ALIVE_fnc_artillery"; + onTransition = ""; + }; + }; + class Move { onState = ""; onStateEntered = "[_this, 'onMove'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class InPosition { - targetState = "Execute"; + targetState = "Unpack"; condition = "[_this, 'inPosition'] call ALIVE_fnc_artillery"; onTransition = ""; }; @@ -49,6 +61,18 @@ class ArtilleryStateMachine { }; }; + class Unpack { + onState = ""; + onStateEntered = "[_this, 'onUnpack'] call ALIVE_fnc_artillery"; + onStateLeaving = ""; + + class Unpacked { + targetState = "Execute"; + condition = "[_this, 'hasUnpacked'] call ALIVE_fnc_artillery"; + onTransition = ""; + }; + }; + class Execute { onState = ""; onStateEntered = "[_this, 'onExecute'] call ALIVE_fnc_artillery"; diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 4fa6386fc..2edd6e242 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -31,6 +31,8 @@ marceldev89 #define SUPERCLASS ALIVE_fnc_baseClass #define MAINCLASS ALIVE_fnc_artillery +#define TYPE_ARTILLERY 0 +#define TYPE_MORTAR 1 private _logic = param [0, objNull, [objNull, []]]; private _operation = param [1, "", [""]]; @@ -38,7 +40,7 @@ private _args = param [2, [], [objNull, [], "", 0, true, false]]; private _result = true; -diag_log format ["###### %1: _logic: %2, _operation: %3, _args: %4", "ALIVE_fnc_artillery", _logic, _operation, _args]; +/* diag_log format ["###### %1: _logic: %2, _operation: %3, _args: %4", "ALIVE_fnc_artillery", _logic, _operation, _args]; */ switch (_operation) do { case "init": { @@ -201,6 +203,26 @@ switch (_operation) do { private _fireMission = _logic getVariable ["fireMission", []]; _result = (count _fireMission > 0); }; + case "hasPacked": { + private _type = _logic getvariable ["type", TYPE_ARTILLERY]; + + if (_type == TYPE_MORTAR) then { + private _group = _logic getVariable ["group", grpNull]; + _result = !(_group getVariable ["sup_artillery_deployed", true]); + } else { + _result = true + }; + }; + case "hasUnpacked": { + private _type = _logic getvariable ["type", TYPE_ARTILLERY]; + + if (_type == TYPE_MORTAR) then { + private _group = _logic getVariable ["group", grpNull]; + _result = _group getVariable ["sup_artillery_deployed", true]; + } else { + _result = true + }; + }; case "isFireMissionComplete": { private _fireMission = _logic getVariable ["fireMission", []]; private _roundCount = [_fireMission, "roundCount"] call ALIVE_fnc_hashGet; @@ -248,6 +270,28 @@ switch (_operation) do { "(group this) setVariable ['sup_artillery_inPosition', true]" ]; }; + case "pack": { + private _group = _logic getVariable ["group", grpNull]; + private _deployed = _group getVariable ["sup_artillery_deployed", true]; + + if (_deployed) then { + private _weapon = objNull; + + { + if (vehicle _x != _x) exitWith { _weapon = vehicle _x }; + } forEach (units _group); + + private _handle = [_group, _weapon] spawn ALIVE_fnc_packMortar; + + [_group, _handle] spawn { + private _group = _this select 0; + private _handle = _this select 1; + + waitUntil { scriptDone _handle }; + _group setVariable ["sup_artillery_deployed", false]; + }; + }; + }; case "returnToBase": { private _group = _logic getVariable ["group", grpNull]; private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; @@ -277,7 +321,7 @@ switch (_operation) do { private _group = createGroup _side; private _vehicles = []; - for "_i" from 0 to 2 do { + for "_i" from 0 to 0 do { // TODO: Spawn vehicles in proper fancy formation (see CfgFormations) private _vehiclePosition = _position getPos [15 * _i, (getDir _logic) * _i]; private _vehicle = createVehicle [_type, _vehiclePosition, [], 0, "NONE"]; @@ -285,6 +329,16 @@ switch (_operation) do { _vehicle lock true; [_vehicle, _group] call BIS_fnc_spawnCrew; _vehicles pushBack _vehicle; + + if (_vehicle isKindOf "StaticMortar") then { + private _leader = _group createUnit ["B_Soldier_F", _vehiclePosition, [], 0, "NONE"]; + private _assistant = _group createUnit ["B_Soldier_F", _vehiclePosition, [], 0, "NONE"]; + _group selectLeader _leader; + _logic setVariable ["type", TYPE_MORTAR]; + _group setVariable ["sup_artillery_deployed", true]; + } else { + _logic setVariable ["type", TYPE_ARTILLERY]; + }; }; _group setVariable ["logic", _logic]; @@ -310,6 +364,21 @@ switch (_operation) do { _result = _group; }; + case "unpack": { + private _group = _logic getVariable ["group", grpNull]; + private _fireMission = _logic getVariable ["fireMission", []]; + private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; + + private _handle = [_group, position (leader _group), _position] spawn ALIVE_fnc_unpackMortar; + + [_group, _handle] spawn { + private _group = _this select 0; + private _handle = _this select 1; + + waitUntil { scriptDone _handle }; + _group setVariable ["sup_artillery_deployed", true]; + }; + }; /****************** ** STATEMACHINE ** @@ -330,6 +399,12 @@ switch (_operation) do { case "onMove": { [_logic, "move"] call MAINCLASS; }; + case "onPack": { + [_logic, "pack"] call MAINCLASS; + }; + case "onUnpack": { + [_logic, "unpack"] call MAINCLASS; + }; case "onExecute": { [_logic, "execute"] call MAINCLASS; }; diff --git a/addons/sup_combatsupport/fnc_packMortar.sqf b/addons/sup_combatsupport/fnc_packMortar.sqf index 6b80cec3f..5e62b70b0 100644 --- a/addons/sup_combatsupport/fnc_packMortar.sqf +++ b/addons/sup_combatsupport/fnc_packMortar.sqf @@ -27,7 +27,7 @@ if (isNil "_disassembleTo" || {count _disassembleTo == 0}) exitWith {}; private _leader = leader _group; private _gunner = gunner _weapon; private _units = (units _group) - [_leader] - [_gunner]; -private _assistant = _unit select 0; +private _assistant = _units select 0; private _primaryBag = objNull; private _secondaryBag = objNull; From a7c849caf8a9d20d792665cdaf59cb43f2ebe984 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 22 Oct 2016 15:18:47 +0200 Subject: [PATCH 17/29] Cleanup obsolete code from fnc_combatSupport --- addons/sup_artillery/fnc_artillery.sqf | 7 +- .../sup_combatsupport/fnc_combatSupport.sqf | 269 ------------------ 2 files changed, 5 insertions(+), 271 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 2edd6e242..bb18db269 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -48,9 +48,12 @@ switch (_operation) do { _logic setVariable ["class", MAINCLASS]; // Defaults - /* _logic setVariable ["group", grpNull]; */ + _logic setVariable ["group", grpNull]; _logic setVariable ["moveToPos", objNull]; _logic setVariable ["fireMission", []]; + + // Spawn and initialize artillery units + [_logic, "spawn"] call MAINCLASS; }; /**************** @@ -334,8 +337,8 @@ switch (_operation) do { private _leader = _group createUnit ["B_Soldier_F", _vehiclePosition, [], 0, "NONE"]; private _assistant = _group createUnit ["B_Soldier_F", _vehiclePosition, [], 0, "NONE"]; _group selectLeader _leader; - _logic setVariable ["type", TYPE_MORTAR]; _group setVariable ["sup_artillery_deployed", true]; + _logic setVariable ["type", TYPE_MORTAR]; } else { _logic setVariable ["type", TYPE_ARTILLERY]; }; diff --git a/addons/sup_combatsupport/fnc_combatSupport.sqf b/addons/sup_combatsupport/fnc_combatSupport.sqf index f93786e15..1a596e76d 100644 --- a/addons/sup_combatsupport/fnc_combatSupport.sqf +++ b/addons/sup_combatsupport/fnc_combatSupport.sqf @@ -85,14 +85,11 @@ switch(_operation) do { CAS_RESPAWN_LIMIT = parsenumber(_CAS_SET_RESPAWN_LIMIT); _TRANS_SET_RESPAWN_LIMIT = NEO_radioLogic getvariable ["combatsupport_transportrespawnlimit","3"]; TRANS_RESPAWN_LIMIT = parsenumber(_TRANS_SET_RESPAWN_LIMIT); - _ARTY_SET_RESPAWN_LIMIT = NEO_radioLogic getvariable ["combatsupport_artyrespawnlimit","3"]; - ARTY_RESPAWN_LIMIT = parsenumber(_ARTY_SET_RESPAWN_LIMIT); _audio = NEO_radioLogic getvariable ["combatsupport_audio",true]; _transportArrays = []; _casArrays = []; - _artyArrays = []; _sides = [WEST,EAST,RESISTANCE,CIVILIAN]; for "_i" from 0 to ((count synchronizedObjects _logic)-1) do { @@ -176,34 +173,6 @@ switch(_operation) do { _casArrays pushback _casArray; }; }; - } else { - switch (tolower(_type)) do { - case ("arty") : { - private ["_position","_callsign","_type"]; - - _position = getposATL _entry; - _direction = getDir _entry; - _class = typeOf _entry; - - _callsign = _entry getvariable ["CS_CALLSIGN",groupID (group _entry)]; - - _he = ["HE",parsenumber(_entry getvariable ["CS_artillery_he","30"])]; - _illum = ["ILLUM",parsenumber(_entry getvariable ["CS_artillery_illum","30"])]; - _smoke = ["SMOKE",parsenumber(_entry getvariable ["CS_artillery_smoke","30"])]; - _guided = ["SADARM",parsenumber(_entry getvariable ["CS_artillery_guided","30"])]; - _cluster = ["CLUSTER",parsenumber(_entry getvariable ["CS_artillery_cluster","30"])]; - _lg = ["LASER",parsenumber(_entry getvariable ["CS_artillery_lg","30"])]; - _mine = ["MINE",parsenumber(_entry getvariable ["CS_artillery_atmine","30"])]; - _atmine = ["AT MINE",parsenumber(_entry getvariable ["CS_artillery_atmine","30"])]; - _rockets = ["ROCKETS",parsenumber(_entry getvariable ["CS_artillery_rockets","16"])]; - - _ordnance = [_he,_illum,_smoke,_guided,_cluster,_lg,_mine,_atmine, _rockets]; - _code = _entry getvariable ["CS_CODE",""]; - _code = [_code,"this","(_this select 0)"] call CBA_fnc_replace; - _artyArray = [_position,_class, _callsign,3,_ordnance,_code]; - _artyArrays pushback _artyArray; - }; - }; }; switch (typeOf ((synchronizedObjects _logic) select _i)) do { @@ -251,57 +220,11 @@ switch(_operation) do { _transportArray = [_position,_direction,_type, _callsign,_tasks,_code,_height,_slingloading, _containers]; _transportArrays pushback _transportArray; }; - case ("ALiVE_sup_artillery") : { - private ["_position","_callsign","_type"]; - - _position = getposATL ((synchronizedObjects _logic) select _i); - _callsign = ((synchronizedObjects _logic) select _i) getvariable ["artillery_callsign","FOX ONE"]; - _class = ((synchronizedObjects _logic) select _i) getvariable ["artillery_type","B_Mortar_01_F"]; - _setherounds = ((synchronizedObjects _logic) select _i) getvariable ["artillery_he","30"]; - _setillumrounds = ((synchronizedObjects _logic) select _i) getvariable ["artillery_illum","30"]; - _setsmokerounds = ((synchronizedObjects _logic) select _i) getvariable ["artillery_smoke","30"]; - _setguidedrounds = ((synchronizedObjects _logic) select _i) getvariable ["artillery_guided","30"]; - _setclusterrounds = ((synchronizedObjects _logic) select _i) getvariable ["artillery_cluster","30"]; - _setlgrounds = ((synchronizedObjects _logic) select _i) getvariable ["artillery_lg","30"]; - _setminerounds = ((synchronizedObjects _logic) select _i) getvariable ["artillery_mine","30"]; - _setatminerounds = ((synchronizedObjects _logic) select _i) getvariable ["artillery_atmine","30"]; - _setrocketrounds = ((synchronizedObjects _logic) select _i) getvariable ["artillery_rockets","16"]; - - _direction = getDir ((synchronizedObjects _logic) select _i); - _code = ((synchronizedObjects _logic) select _i) getvariable ["artillery_code",""]; - _code = [_code,"this","(_this select 0)"] call CBA_fnc_replace; - - _herounds = parsenumber(_setherounds); - _illumrounds = parsenumber(_setillumrounds); - _smokerounds = parsenumber(_setsmokerounds); - _guidedrounds = parsenumber(_setguidedrounds); - _clusterrounds = parsenumber(_setclusterrounds); - _lgrounds = parsenumber(_setlgrounds); - _minerounds = parsenumber(_setminerounds); - _atminerounds = parsenumber(_setatminerounds); - _rocketrounds = parsenumber(_setrocketrounds); - - _he = ["HE",_herounds]; - _illum = ["ILLUM",_illumrounds]; - _smoke = ["SMOKE",_smokerounds]; - _guided = ["SADARM",_guidedrounds]; - _cluster = ["CLUSTER",_clusterrounds]; - _lg = ["LASER",_lgrounds]; - _mine = ["MINE",_minerounds]; - _atmine = ["AT MINE",_atminerounds]; - _rockets = ["ROCKETS", _rocketrounds]; - - _ordnance = [_he,_illum,_smoke,_guided,_cluster,_lg,_mine,_atmine, _rockets]; - - _artyArray = [_position,_class, _callsign,3,_ordnance,_code]; - _artyArrays pushback _artyArray; - }; }; }; SUP_CASARRAYS = _casArrays; PublicVariable "SUP_CASARRAYS"; SUP_TRANSPORTARRAYS = _transportArrays; PublicVariable "SUP_TRANSPORTARRAYS"; - SUP_ARTYARRAYS = _artyArrays; PublicVariable "SUP_ARTYARRAYS"; { NEO_radioLogic setVariable [format ["NEO_radioTrasportArray_%1", _x], [],true]; @@ -547,183 +470,6 @@ switch(_operation) do { } forEach SUP_CASARRAYS; - - - // ARTY - - { - private ["_pos", "_class", "_callsign", "_unitCount", "_rounds", "_code", "_roundsUnit", "_roundsAvailable", "_canMove", "_units", "_grp", "_vehDir","_tempclass","_side","_artyBatteries"]; - _pos = _x select 0; _pos set [2, 0]; - _class = _x select 1; - _callsign = toUpper (_x select 2); - _unitCount = round (_x select 3); if (_unitCount > 4) then { _unitCount = 4 }; if (_unitCount < 1) then { _unitCount = 1 }; - _rounds = _x select 4; - _code = _x select 5; - - if (_class in ["BUS_Support_Mort","BUS_MotInf_MortTeam","OIA_MotInf_MortTeam","OI_support_Mort","HAF_MotInf_MortTeam","HAF_Support_Mort"]) then { - // Force _unitCount to 1 to prevent spawning 3x3 units when _class is from CfgGroups - _unitCount = 1; - private _letter = _class select [0,1]; - - switch (_letter) do { - case "O" : {_tempclass = "O_Mortar_01_F"}; - case "B" : {_tempclass = "B_Mortar_01_F"}; - case "H" : {_tempclass = "I_Mortar_01_F"}; - default {_tempclass = "B_Mortar_01_F"}; - }; - - _side = getNumber(configfile >> "CfgVehicles" >> _tempclass >> "side"); - } else { - _side = getNumber(configfile >> "CfgVehicles" >> _class >> "side"); - }; - - switch (_side) do { - case 0 : {_side = EAST}; - case 1 : {_side = WEST}; - case 2 : {_side = RESISTANCE}; - default {_side = EAST}; - }; - - if (!isNil "_tempclass") then { - _roundsUnit = _tempclass call ALiVE_fnc_GetArtyRounds; - } else { - _roundsUnit = _class call ALiVE_fnc_GetArtyRounds; - }; - - _roundsAvailable = []; - _canMove = if (_class in ["B_MBT_01_arty_F", "O_MBT_02_arty_F", "B_MBT_01_mlrs_F","O_Mortar_01_F", "B_Mortar_01_F","I_Mortar_01_F","BUS_Support_Mort","BUS_MotInf_MortTeam","OIA_MotInf_MortTeam","OI_support_Mort","HAF_MotInf_MortTeam","HAF_Support_Mort"]) then { true } else { false }; - _units = []; - _artyBatteries = []; - _vehDir = 0; - - private ["_veh","_grp"]; - - _veh = nearestObjects [_pos, [_class], 5]; - - if (count _veh > 0) then {_veh = _veh select 0; _grp = group _veh} else {_veh = nil; _grp = createGroup _side}; - - if (isnil "_veh") then { - private ["_vehPos","_i"]; - for "_i" from 1 to _unitCount do - { - private ["_veh","_sptarr"]; - _vehPos = _pos getPos [15, _vehDir]; _vehPos set [2, 0]; - - if (isNil "_tempclass") then { - _veh = createVehicle [_class, _vehPos, [], 0, "CAN_COLLIDE"]; - _artyBatteries pushback _veh; - } else { - _veh = createVehicle [_tempclass, _vehPos, [], 0, "CAN_COLLIDE"]; - _artyBatteries pushback _veh; - }; - _veh setDir _vehDir; - _veh setPosATL _vehPos; - _veh lock true; - _vehDir = _vehDir + 90; - - [_veh, _grp] call BIS_fnc_spawnCrew; - - // set ownership flag for other modules - _veh setVariable ["ALIVE_CombatSupport", true]; - - // Exclude CS from VCOM - // CS only runs serverside so no PV is needed - (driver _veh) setvariable ["VCOM_NOAI", true]; - - if (_i == 1) then {leader _grp setRank "CAPTAIN"}; - - // Add leader and assistant if a mortar weapon, in order to use BIS pack and unpack functions - if (_class in ["O_Mortar_01_F", "B_Mortar_01_F","I_Mortar_01_F","BUS_Support_Mort","BUS_MotInf_MortTeam","OIA_MotInf_MortTeam","OI_support_Mort","HAF_MotInf_MortTeam","HAF_Support_Mort"]) then { - private ["_tl","_sl","_newgrp","_cars"]; - private _prefix = _class select [0,1]; - - if (_prefix == "H") then { - _prefix = "I"; - }; - - _tl = format ["%1_soldier_TL_F", _prefix]; - _sl = format ["%1_soldier_F", _prefix]; - _newgrp = [_vehPos, _side, [_tl, _sl],[],[],[],[],[],_vehDir] call BIS_fnc_spawnGroup; - (units _newgrp) joinSilent _grp; - - _sptarr = _grp getVariable ["supportWeaponArray",[]]; - _sptarr pushback _veh; - _grp setvariable ["supportWeaponArray", _sptarr]; - }; - - _units pushback _veh; - }; - if (_class in ["BUS_MotInf_MortTeam","OIA_MotInf_MortTeam","HAF_MotInf_MortTeam"]) then { - _cars = [2, faction (leader _grp),"Car"] call ALiVE_fnc_findVehicleType; - if (count _cars > 0) then { - for "_i" from 1 to ceil((count (units _grp))/4) do { - private "_car"; - _car = createVehicle [_cars select 0, [position (leader _grp),1,100,1,0,4,0] call bis_fnc_findSafePos, [], 0, "NONE"]; - _grp addVehicle _car; - _artyBatteries pushback _car; - }; - }; - }; - } else { - _units pushback _veh; - _veh lock true; - - // set ownership flag for other modules - _veh setVariable ["ALIVE_CombatSupport", true]; - }; - - { _x setVariable ["NEO_radioArtyModule", [leader _grp, _callsign], true] } forEach _units; - - [_grp,0] setWaypointPosition [_pos,0]; - [[(units _grp select 0),_callsign], "fnc_setGroupID", false, false] spawn BIS_fnc_MP; - - - _codeArray = [_code, ";"] call CBA_fnc_split; - { - _vehicle = _x; - { - if (_x != "") then { - [_vehicle, _x] spawn { - private ["_vehicle", "_spawn"]; - _vehicle = _this select 0; - _spawn = compile(_this select 1); - [_vehicle] spawn _spawn; - }; - }; - } forEach _codeArray; - } forEach _artyBatteries; - - //Validate rounds - { - if ((_x select 0) in _roundsUnit) then - { - _roundsAvailable pushback _x; - }; - } forEach _rounds; - - - leader _grp setVariable ["NEO_radioArtyBatteryRounds", _roundsAvailable, true]; - - //FSM - [_units, _grp, _callsign, _pos, _roundsAvailable, _canMove, _class, leader _grp, _code, _audio] execFSM "\x\alive\addons\sup_combatSupport\scripts\NEO_radio\fsms\alivearty.fsm"; - - _a = NEO_radioLogic getVariable format ["NEO_radioArtyArray_%1", _side]; - _a pushback ([leader _grp, _grp, _callsign, _units, _roundsAvailable]); - - NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", _side], _a, true]; - - //} forEach SUP_ARTYARRAYS; - } forEach []; // TODO: Delete entire block once arty fixes are done :-) - - for "_i" from 0 to ((count synchronizedObjects _logic)-1) do { - if (typeOf ((synchronizedObjects _logic) select _i) == "ALiVE_sup_artillery") then { - private _artyLogic = (synchronizedObjects _logic) select _i; - [_artyLogic, "spawn"] call ALIVE_fnc_artillery; - }; - }; - - - for "_i" from 0 to ((count _sides)-1) do { _sideIn = _sides select _i; @@ -758,21 +504,6 @@ switch(_operation) do { } foreach _xArray; NEO_radioLogic setVariable [format ["NEO_radioCasArray_%1", _sideIn], _sideInArray + _add,true]; }; - - private ["_sideInArray","_xArray"]; - _sideInArray = NEO_radioLogic getVariable format["NEO_radioArtyArray_%1", _sideIn]; - _xArray = NEO_radioLogic getVariable format["NEO_radioArtyArray_%1", _x]; - - if (count _xArray > 0) then { - _add = []; - { - _vehicle = _x select 0; - if (({_vehicle == _x select 0} count _sideInArray) == 0) then { - _add pushback _x; - }; - } foreach _xArray; - NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", _sideIn], _sideInArray + _add,true]; - }; }; } foreach _sides; }; From 3c34beae89f30dd1326ed23018f03c43399358a5 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 22 Oct 2016 15:19:22 +0200 Subject: [PATCH 18/29] Fix NEO_radio issue with mortar teams --- .../NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf index f7b3ad7c2..579cf3231 100644 --- a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf +++ b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf @@ -24,7 +24,8 @@ _type = "IMMEDIATE"; _ordnanceType = _artyOrdnanceTypeLb lbText (lbCurSel _artyOrdnanceTypeLb); //_ord = [_battery, _ordnanceType] CALL ALIVE_fnc_GetMagazineType; -_ord = [_battery, _ordnanceType] CALL ALIVE_fnc_getArtyMagazineType; +private _gunner = ((units _unit) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}); +_ord = [_gunner, _ordnanceType] CALL ALIVE_fnc_getArtyMagazineType; _rate = switch (_artyRateOfFireLb lbText (lbCurSel _artyRateOfFireLb)) do { From d9bb1eaa1585267476f33dcc101cab53e52d055f Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 22 Oct 2016 16:24:44 +0200 Subject: [PATCH 19/29] Really fix NEO_radio issue with mortar teams --- .../NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf index 579cf3231..434619dfe 100644 --- a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf +++ b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf @@ -24,7 +24,7 @@ _type = "IMMEDIATE"; _ordnanceType = _artyOrdnanceTypeLb lbText (lbCurSel _artyOrdnanceTypeLb); //_ord = [_battery, _ordnanceType] CALL ALIVE_fnc_GetMagazineType; -private _gunner = ((units _unit) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}); +private _gunner = ((units _unit) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}) select 0; _ord = [_gunner, _ordnanceType] CALL ALIVE_fnc_getArtyMagazineType; _rate = switch (_artyRateOfFireLb lbText (lbCurSel _artyRateOfFireLb)) do From f2980dafe762f956823affce46acca83e1c5ab02 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 22 Oct 2016 17:32:59 +0200 Subject: [PATCH 20/29] Create proper mortar teams --- addons/sup_artillery/fnc_artillery.sqf | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index bb18db269..43196f6de 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -324,7 +324,7 @@ switch (_operation) do { private _group = createGroup _side; private _vehicles = []; - for "_i" from 0 to 0 do { + for "_i" from 0 to 2 do { // TODO: Spawn vehicles in proper fancy formation (see CfgFormations) private _vehiclePosition = _position getPos [15 * _i, (getDir _logic) * _i]; private _vehicle = createVehicle [_type, _vehiclePosition, [], 0, "NONE"]; @@ -332,16 +332,22 @@ switch (_operation) do { _vehicle lock true; [_vehicle, _group] call BIS_fnc_spawnCrew; _vehicles pushBack _vehicle; + }; - if (_vehicle isKindOf "StaticMortar") then { - private _leader = _group createUnit ["B_Soldier_F", _vehiclePosition, [], 0, "NONE"]; - private _assistant = _group createUnit ["B_Soldier_F", _vehiclePosition, [], 0, "NONE"]; - _group selectLeader _leader; - _group setVariable ["sup_artillery_deployed", true]; - _logic setVariable ["type", TYPE_MORTAR]; - } else { - _logic setVariable ["type", TYPE_ARTILLERY]; - }; + if (_type isKindOf "StaticMortar") then { + // Create group leader + private _leader = _group createUnit ["B_Soldier_F", position (leader _group), [], 0, "NONE"]; + _group selectLeader _leader; + + // Create gunner assitants + { + private _vehicle = _x param [0, objNull]; + _group createUnit ["B_Soldier_F", position _vehicle, [], 0, "NONE"]; + } forEach _vehicles; + + _logic setVariable ["type", TYPE_MORTAR]; + } else { + _logic setVariable ["type", TYPE_ARTILLERY]; }; _group setVariable ["logic", _logic]; From 6d7f17073ceaec5d62f7cc944dba8b69d2246968 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Thu, 17 Nov 2016 18:20:20 +0100 Subject: [PATCH 21/29] Get rid of the event "methods" --- .../sup_artillery/ArtilleryStateMachine.hpp | 14 +++---- addons/sup_artillery/fnc_artillery.sqf | 37 +++---------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/addons/sup_artillery/ArtilleryStateMachine.hpp b/addons/sup_artillery/ArtilleryStateMachine.hpp index f86ebf994..05b3c9116 100644 --- a/addons/sup_artillery/ArtilleryStateMachine.hpp +++ b/addons/sup_artillery/ArtilleryStateMachine.hpp @@ -15,7 +15,7 @@ class ArtilleryStateMachine { class Active { onState = ""; - onStateEntered = "[_this, 'onActive'] call ALIVE_fnc_artillery"; + onStateEntered = "[_this, 'activate'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class InRange { @@ -33,7 +33,7 @@ class ArtilleryStateMachine { class Pack { onState = ""; - onStateEntered = "[_this, 'onPack'] call ALIVE_fnc_artillery"; + onStateEntered = "[_this, 'pack'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class Packed { @@ -45,7 +45,7 @@ class ArtilleryStateMachine { class Move { onState = ""; - onStateEntered = "[_this, 'onMove'] call ALIVE_fnc_artillery"; + onStateEntered = "[_this, 'move'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class InPosition { @@ -63,7 +63,7 @@ class ArtilleryStateMachine { class Unpack { onState = ""; - onStateEntered = "[_this, 'onUnpack'] call ALIVE_fnc_artillery"; + onStateEntered = "[_this, 'unpack'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class Unpacked { @@ -75,7 +75,7 @@ class ArtilleryStateMachine { class Execute { onState = ""; - onStateEntered = "[_this, 'onExecute'] call ALIVE_fnc_artillery"; + onStateEntered = "[_this, 'execute'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class Fire { @@ -93,7 +93,7 @@ class ArtilleryStateMachine { class Fire { onState = ""; - onStateEntered = "[_this, 'onFire'] call ALIVE_fnc_artillery"; + onStateEntered = "[_this, 'fire'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class FireMissionComplete { @@ -129,7 +129,7 @@ class ArtilleryStateMachine { class ReturnToBase { onState = ""; - onStateEntered = "[_this, 'onReturnToBase'] call ALIVE_fnc_artillery"; + onStateEntered = "[_this, 'returnToBase'] call ALIVE_fnc_artillery"; onStateLeaving = ""; class AtBase { diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 43196f6de..df8a2036a 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -116,6 +116,11 @@ switch (_operation) do { /************* ** METHODS ** *************/ + case "activate": { + if (!([_logic, "inRange"] call MAINCLASS)) then { + _logic setVariable ["moveToPos", [3744.56,4757.54,0]]; // TODO: Figure out best firing position + }; + }; case "execute": { private _group = _logic getVariable ["group", grpNull]; private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; @@ -388,38 +393,6 @@ switch (_operation) do { _group setVariable ["sup_artillery_deployed", true]; }; }; - - /****************** - ** STATEMACHINE ** - ******************/ - case "onIdle": { - private _group = _logic getVariable ["group", grpNull]; - _group setVariable ["sup_artillery_inPosition", true]; - _logic setVariable ["moveToPos", objNull]; - }; - case "onActive": { - if (!([_logic, "inRange"] call MAINCLASS)) then { - _logic setVariable ["moveToPos", [3744.56,4757.54,0]]; // TODO: Figure out best firing position - }; - }; - case "onFire": { - [_logic, "fire"] call MAINCLASS; - }; - case "onMove": { - [_logic, "move"] call MAINCLASS; - }; - case "onPack": { - [_logic, "pack"] call MAINCLASS; - }; - case "onUnpack": { - [_logic, "unpack"] call MAINCLASS; - }; - case "onExecute": { - [_logic, "execute"] call MAINCLASS; - }; - case "onReturnToBase": { - [_logic, "returnToBase"] call MAINCLASS; - }; }; // TODO: Give this legacy stuff a place From 6d65a208042191c612b3f693d3f82b07256e1075 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Thu, 17 Nov 2016 19:07:38 +0100 Subject: [PATCH 22/29] Extract spawn method to separate script --- addons/sup_artillery/CfgFunctions.hpp | 27 ++-- addons/sup_artillery/fnc_artillery.sqf | 129 ++++++-------------- addons/sup_artillery/fnc_artillerySpawn.sqf | 68 +++++++++++ 3 files changed, 122 insertions(+), 102 deletions(-) create mode 100644 addons/sup_artillery/fnc_artillerySpawn.sqf diff --git a/addons/sup_artillery/CfgFunctions.hpp b/addons/sup_artillery/CfgFunctions.hpp index 56ed2cd78..eab2cdb8d 100644 --- a/addons/sup_artillery/CfgFunctions.hpp +++ b/addons/sup_artillery/CfgFunctions.hpp @@ -1,16 +1,21 @@ class cfgFunctions { - class PREFIX { - class COMPONENT { - class ARTILLERY { - description = "The main class"; - file = "\x\alive\addons\sup_artillery\fnc_artillery.sqf"; + class PREFIX { + class COMPONENT { + class ARTILLERY { + description = "The main class"; + file = "\x\alive\addons\sup_artillery\fnc_artillery.sqf"; RECOMPILE; - }; - class artilleryInit { - description = "The module initialisation function"; - file = "\x\alive\addons\sup_artillery\fnc_artilleryInit.sqf"; + }; + class artilleryInit { + description = "The module initialisation function"; + file = "\x\alive\addons\sup_artillery\fnc_artilleryInit.sqf"; RECOMPILE; - }; - }; + }; + class artillerySpawn { + description = "Spawns artillery assets"; + file = "\x\alive\addons\sup_artillery\fnc_artillerySpawn.sqf"; + RECOMPILE; + }; }; + }; }; diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index df8a2036a..ce080e6d7 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -53,12 +53,45 @@ switch (_operation) do { _logic setVariable ["fireMission", []]; // Spawn and initialize artillery units - [_logic, "spawn"] call MAINCLASS; + [_logic] call ALIVE_fnc_artillerySpawn; + + // Start state machine if it hasn't already + if (isNil "ALIVE_sup_artillery_stateMachine") then { + ALIVE_sup_artillery_stateMachine_list = []; + ALIVE_sup_artillery_stateMachine = [ + configFile >> "ArtilleryStateMachine" + ] call CBA_statemachine_fnc_createFromConfig; + }; + + // Add artillery module to state machine + ALIVE_sup_artillery_stateMachine_list pushBack _logic; }; + // get available rounds + case "rounds": { + private _rounds = [ + ["HE", parseNumber (_logic getVariable ["artillery_he", "30"])], + ["ILLUM", parseNumber (_logic getVariable ["artillery_illum", "30"])], + ["SMOKE", parseNumber (_logic getVariable ["artillery_smoke", "30"])], + ["SADARM", parseNumber (_logic getVariable ["artillery_guided", "30"])], + ["CLUSTER", parseNumber (_logic getVariable ["artillery_cluster", "30"])], + ["LASER", parseNumber (_logic getVariable ["artillery_lg", "30"])], + ["MINE", parseNumber (_logic getVariable ["artillery_mine", "30"])], + ["AT MINE", parseNumber (_logic getVariable ["artillery_atmine", "30"])], + ["ROCKETS", parseNumber (_logic getVariable ["artillery_rockets", "16"])] + ]; + + private _roundsAvailable = []; + private _roundsUnit = (typeOf (_vehicles select 0)) call ALIVE_fnc_getArtyRounds; + + { + if ((_x select 0) in _roundsUnit) then { + _roundsAvailable pushBack _x; + }; + } forEach _rounds; - /**************** - ** PROPERTIES ** - ****************/ + _result = _roundsAvailable; + }; + // get/set fire mission case "fireMission": { if (count _args == 0) then { _result = _logic getVariable ["fireMission", []]; @@ -84,38 +117,11 @@ switch (_operation) do { _logic setVariable ["fireMission", _fireMission]; }; }; + // get position case "position": { private _group = _logic getVariable ["group", grpNull]; _result = position (leader _group); }; - case "rounds": { - private _rounds = [ - ["HE", parseNumber (_logic getVariable ["artillery_he", "30"])], - ["ILLUM", parseNumber (_logic getVariable ["artillery_illum", "30"])], - ["SMOKE", parseNumber (_logic getVariable ["artillery_smoke", "30"])], - ["SADARM", parseNumber (_logic getVariable ["artillery_guided", "30"])], - ["CLUSTER", parseNumber (_logic getVariable ["artillery_cluster", "30"])], - ["LASER", parseNumber (_logic getVariable ["artillery_lg", "30"])], - ["MINE", parseNumber (_logic getVariable ["artillery_mine", "30"])], - ["AT MINE", parseNumber (_logic getVariable ["artillery_atmine", "30"])], - ["ROCKETS", parseNumber (_logic getVariable ["artillery_rockets", "16"])] - ]; - - private _roundsAvailable = []; - private _roundsUnit = (typeOf (_vehicles select 0)) call ALIVE_fnc_getArtyRounds; - - { - if ((_x select 0) in _roundsUnit) then { - _roundsAvailable pushBack _x; - }; - } forEach _rounds; - - _result = _roundsAvailable; - }; - - /************* - ** METHODS ** - *************/ case "activate": { if (!([_logic, "inRange"] call MAINCLASS)) then { _logic setVariable ["moveToPos", [3744.56,4757.54,0]]; // TODO: Figure out best firing position @@ -319,65 +325,6 @@ switch (_operation) do { _logic setVariable ["fireMission", []]; [_logic, "move", [position _logic]] call MAINCLASS; }; - case "spawn": { - private _position = position _logic; - private _type = _logic getVariable ["artillery_type", ""]; - private _callsign = _logic getVariable ["artillery_callsign", ""]; - private _code = _logic getVariable ["artillery_code", ""]; - - private _side = _type call ALIVE_fnc_classSide; - private _group = createGroup _side; - private _vehicles = []; - - for "_i" from 0 to 2 do { - // TODO: Spawn vehicles in proper fancy formation (see CfgFormations) - private _vehiclePosition = _position getPos [15 * _i, (getDir _logic) * _i]; - private _vehicle = createVehicle [_type, _vehiclePosition, [], 0, "NONE"]; - _vehicle setDir (getDir _logic); - _vehicle lock true; - [_vehicle, _group] call BIS_fnc_spawnCrew; - _vehicles pushBack _vehicle; - }; - - if (_type isKindOf "StaticMortar") then { - // Create group leader - private _leader = _group createUnit ["B_Soldier_F", position (leader _group), [], 0, "NONE"]; - _group selectLeader _leader; - - // Create gunner assitants - { - private _vehicle = _x param [0, objNull]; - _group createUnit ["B_Soldier_F", position _vehicle, [], 0, "NONE"]; - } forEach _vehicles; - - _logic setVariable ["type", TYPE_MORTAR]; - } else { - _logic setVariable ["type", TYPE_ARTILLERY]; - }; - - _group setVariable ["logic", _logic]; - _logic setVariable ["group", _group]; - - // Assign artillery group to the NEO_radio scripts - private _rounds = [_logic, "rounds"] call MAINCLASS; - leader _group setVariable ["NEO_radioArtyBatteryRounds", _rounds, true]; - private _a = NEO_radioLogic getVariable format ["NEO_radioArtyArray_%1", _side]; - _a set [count _a, [leader _group, _group, _callsign, _vehicles, _rounds]]; - NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", _side], _a, true]; - - // Start state machine if it hasn't already - if (isNil "ALIVE_sup_artillery_stateMachine") then { - ALIVE_sup_artillery_stateMachine_list = []; - ALIVE_sup_artillery_stateMachine = [ - configFile >> "ArtilleryStateMachine" - ] call CBA_statemachine_fnc_createFromConfig; - }; - - // Add artillery group to state machine - ALIVE_sup_artillery_stateMachine_list pushBack _logic; - - _result = _group; - }; case "unpack": { private _group = _logic getVariable ["group", grpNull]; private _fireMission = _logic getVariable ["fireMission", []]; diff --git a/addons/sup_artillery/fnc_artillerySpawn.sqf b/addons/sup_artillery/fnc_artillerySpawn.sqf new file mode 100644 index 000000000..7644fc3b7 --- /dev/null +++ b/addons/sup_artillery/fnc_artillerySpawn.sqf @@ -0,0 +1,68 @@ +#include <\x\alive\addons\sup_artillery\script_component.hpp> +SCRIPT(ArtillerySpawn); + +/* ---------------------------------------------------------------------------- +Function: ALIVE_fnc_artillerySpawn +Description: +Spawns the assets associated with the artillery module. + +Parameters: +Object - The artillery module + +Returns: +Nothing + +Examples: +[_logic] call ALIVE_fnc_artillerySpawn; + +See Also: + +Author: +marceldev89 +---------------------------------------------------------------------------- */ +private _logic = param [0, objNull, [objNull]]; + +private _position = position _logic; +private _type = _logic getVariable ["artillery_type", ""]; +private _callsign = _logic getVariable ["artillery_callsign", ""]; +private _code = _logic getVariable ["artillery_code", ""]; + +private _side = _type call ALIVE_fnc_classSide; +private _group = createGroup _side; +private _vehicles = []; + +for "_i" from 0 to 2 do { + // TODO: Spawn vehicles in proper fancy formation (see CfgFormations) + private _vehiclePosition = _position getPos [15 * _i, (getDir _logic) * _i]; + private _vehicle = createVehicle [_type, _vehiclePosition, [], 0, "NONE"]; + _vehicle setDir (getDir _logic); + _vehicle lock true; + [_vehicle, _group] call BIS_fnc_spawnCrew; + _vehicles pushBack _vehicle; +}; + +if (_type isKindOf "StaticMortar") then { + // Create group leader + private _leader = _group createUnit ["B_Soldier_F", position (leader _group), [], 0, "NONE"]; + _group selectLeader _leader; + + // Create gunner assitants + { + private _vehicle = _x param [0, objNull]; + _group createUnit ["B_Soldier_F", position _vehicle, [], 0, "NONE"]; + } forEach _vehicles; + + _logic setVariable ["type", TYPE_MORTAR]; +} else { + _logic setVariable ["type", TYPE_ARTILLERY]; +}; + +_group setVariable ["logic", _logic]; +_logic setVariable ["group", _group]; + +// Assign artillery group to NEO_radio +private _rounds = [_logic, "rounds"] call ALIVE_fnc_artillery; +leader _group setVariable ["NEO_radioArtyBatteryRounds", _rounds, true]; +private _a = NEO_radioLogic getVariable format ["NEO_radioArtyArray_%1", _side]; +_a set [count _a, [leader _group, _group, _callsign, _vehicles, _rounds]]; +NEO_radioLogic setVariable [format ["NEO_radioArtyArray_%1", _side], _a, true]; From 80f031f3d839dfc60b311d19ebcde5e934e579aa Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Thu, 17 Nov 2016 19:24:22 +0100 Subject: [PATCH 23/29] Extract fired event handler to script --- addons/sup_artillery/CfgFunctions.hpp | 5 ++ addons/sup_artillery/fnc_artillery.sqf | 30 +---------- addons/sup_artillery/fnc_artilleryFiredEH.sqf | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+), 29 deletions(-) create mode 100644 addons/sup_artillery/fnc_artilleryFiredEH.sqf diff --git a/addons/sup_artillery/CfgFunctions.hpp b/addons/sup_artillery/CfgFunctions.hpp index eab2cdb8d..9fdeef2ad 100644 --- a/addons/sup_artillery/CfgFunctions.hpp +++ b/addons/sup_artillery/CfgFunctions.hpp @@ -16,6 +16,11 @@ class cfgFunctions { file = "\x\alive\addons\sup_artillery\fnc_artillerySpawn.sqf"; RECOMPILE; }; + class artilleryFiredEH { + description = "Handles artillery fired events"; + file = "\x\alive\addons\sup_artillery\fnc_artilleryFiredEH.sqf"; + RECOMPILE; + }; }; }; }; diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index ce080e6d7..a410c2968 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -144,35 +144,7 @@ switch (_operation) do { // Attach Fired EH to all vehicles in group { private _vehicle = vehicle _x; - private _firedEH = _vehicle addEventHandler ["Fired", { - private _unit = param [0, objNull]; - private _magazine = param [5, ""]; - private _logic = (group _unit) getVariable ["logic", objNull]; - private _fireMission = _logic getVariable ["fireMission", []]; - private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; - private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet; - - if (_magazine == _roundType) then { - private _delay = [_fireMission, "delay"] call ALIVE_fnc_hashGet; - - if (_delay > 0) then { - private _units = [_fireMission, "units"] call ALIVE_fnc_hashGet; - private _unitIndex = [_fireMission, "unitIndex"] call ALIVE_fnc_hashGet; - - if ((_unitIndex + 1) >= count _units) then { - _unitIndex = 0; - } else { - _unitIndex = _unitIndex + 1; - }; - - [_fireMission, "unitIndex", _unitIndex] call ALIVE_fnc_hashSet; - [_fireMission, "nextRoundTime", time + _delay] call ALIVE_fnc_hashSet; - }; - - [_fireMission, "roundsShot", _roundsShot + 1] call ALIVE_fnc_hashSet; - _logic setVariable ["fireMission", _fireMission]; - }; - }]; + private _firedEH = _vehicle addEventHandler ["Fired", ALIVE_fnc_artilleryFiredEH]; _vehicle setVariable ["sup_artillery_firedEH", _firedEH]; } forEach _units; }; diff --git a/addons/sup_artillery/fnc_artilleryFiredEH.sqf b/addons/sup_artillery/fnc_artilleryFiredEH.sqf new file mode 100644 index 000000000..48a6667e4 --- /dev/null +++ b/addons/sup_artillery/fnc_artilleryFiredEH.sqf @@ -0,0 +1,51 @@ +#include <\x\alive\addons\sup_artillery\script_component.hpp> +SCRIPT(ArtilleryFiredEH); + +/* ---------------------------------------------------------------------------- +Function: ALIVE_fnc_artilleryFiredEH +Description: +Handles the fired event for all vehicles (guns) in the artillery group. + +Parameters: +Object - The vehicle +String - The magazine type + +Returns: +Nothing + +Examples: +[_logic] call ALIVE_fnc_artillerySpawn; + +See Also: + +Author: +marceldev89 +---------------------------------------------------------------------------- */ +private _unit = param [0, objNull]; +private _magazine = param [5, ""]; + +private _logic = (group _unit) getVariable ["logic", objNull]; +private _fireMission = _logic getVariable ["fireMission", []]; +private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; +private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet; + +if (_magazine == _roundType) then { + private _delay = [_fireMission, "delay"] call ALIVE_fnc_hashGet; + + if (_delay > 0) then { + private _units = [_fireMission, "units"] call ALIVE_fnc_hashGet; + private _unitIndex = [_fireMission, "unitIndex"] call ALIVE_fnc_hashGet; + + if ((_unitIndex + 1) >= count _units) then { + _unitIndex = 0; + } else { + _unitIndex = _unitIndex + 1; + }; + + [_fireMission, "unitIndex", _unitIndex] call ALIVE_fnc_hashSet; + [_fireMission, "nextRoundTime", time + _delay] call ALIVE_fnc_hashSet; + }; + + [_fireMission, "roundsShot", _roundsShot + 1] call ALIVE_fnc_hashSet; + _logic setVariable ["fireMission", _fireMission]; +}; From 4532cc24e1386a7d922aeb15746ffcbef483d05f Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Thu, 17 Nov 2016 19:30:51 +0100 Subject: [PATCH 24/29] Cleanup --- addons/sup_artillery/fnc_artillery.sqf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index a410c2968..0ef5e6d0c 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -108,7 +108,7 @@ switch (_operation) do { [_fireMission, "roundCount", _roundCount] call ALIVE_fnc_hashSet; [_fireMission, "delay", _delay] call ALIVE_fnc_hashSet; [_fireMission, "dispersion", _dispersion] call ALIVE_fnc_hashSet; - // Defaults + // Fire mission state [_fireMission, "units", []] call ALIVE_fnc_hashSet; [_fireMission, "unitIndex", -1] call ALIVE_fnc_hashSet; [_fireMission, "roundsShot", -1] call ALIVE_fnc_hashSet; @@ -136,7 +136,6 @@ switch (_operation) do { [_fireMission, "unitIndex", 0] call ALIVE_fnc_hashSet; [_fireMission, "roundsShot", 0] call ALIVE_fnc_hashSet; [_fireMission, "nextRoundTime", time] call ALIVE_fnc_hashSet; - /* _units doWatch [_fireMissionPos select 0, _fireMissionPos select 1, 9999]; */ _units doWatch _fireMissionPos; _logic setVariable ["fireMission", _fireMission]; From e783c44991d44dcb7ab82087a0e17735e766d58c Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Thu, 17 Nov 2016 19:53:24 +0100 Subject: [PATCH 25/29] Reorder class methods for readability(?) --- .../sup_artillery/ArtilleryStateMachine.hpp | 4 +- addons/sup_artillery/fnc_artillery.sqf | 204 +++++++++--------- 2 files changed, 104 insertions(+), 104 deletions(-) diff --git a/addons/sup_artillery/ArtilleryStateMachine.hpp b/addons/sup_artillery/ArtilleryStateMachine.hpp index 05b3c9116..3576aeb4a 100644 --- a/addons/sup_artillery/ArtilleryStateMachine.hpp +++ b/addons/sup_artillery/ArtilleryStateMachine.hpp @@ -80,7 +80,7 @@ class ArtilleryStateMachine { class Fire { targetState = "Fire"; - condition = "[_this, 'fireNextRound'] call ALIVE_fnc_artillery"; + condition = "[_this, 'canFireRound'] call ALIVE_fnc_artillery"; onTransition = ""; }; @@ -122,7 +122,7 @@ class ArtilleryStateMachine { class Continue { targetState = "Fire"; - condition = "[_this, 'fireNextRound'] call ALIVE_fnc_artillery"; + condition = "[_this, 'canFireRound'] call ALIVE_fnc_artillery"; onTransition = ""; }; }; diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 0ef5e6d0c..07966edb9 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -122,11 +122,108 @@ switch (_operation) do { private _group = _logic getVariable ["group", grpNull]; _result = position (leader _group); }; + case "hasFireMission": { + private _fireMission = _logic getVariable ["fireMission", []]; + _result = (count _fireMission > 0); + }; case "activate": { if (!([_logic, "inRange"] call MAINCLASS)) then { _logic setVariable ["moveToPos", [3744.56,4757.54,0]]; // TODO: Figure out best firing position }; }; + case "inRange": { + private _fireMission = _logic getVariable ["fireMission", []]; + private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; + private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; + private _group = _logic getVariable ["group", grpNull]; + private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; + _result = _position inRangeOfArtillery [_units, _roundType]; + }; + case "pack": { + private _group = _logic getVariable ["group", grpNull]; + private _deployed = _group getVariable ["sup_artillery_deployed", true]; + + if (_deployed) then { + private _weapon = objNull; + + { + if (vehicle _x != _x) exitWith { _weapon = vehicle _x }; + } forEach (units _group); + + private _handle = [_group, _weapon] spawn ALIVE_fnc_packMortar; + + [_group, _handle] spawn { + private _group = _this select 0; + private _handle = _this select 1; + + waitUntil { scriptDone _handle }; + _group setVariable ["sup_artillery_deployed", false]; + }; + }; + }; + case "hasPacked": { + private _type = _logic getvariable ["type", TYPE_ARTILLERY]; + + if (_type == TYPE_MORTAR) then { + private _group = _logic getVariable ["group", grpNull]; + _result = !(_group getVariable ["sup_artillery_deployed", true]); + } else { + _result = true + }; + }; + case "move": { + private _group = _logic getVariable ["group", grpNull]; + private _position = []; + + if (count _args == 0) then { + _position = _logic getVariable ["moveToPos", objNull]; + } else { + _position = _args param [0, [0,0,0], [[]], 3]; + _logic setVariable ["moveToPos", _position]; + }; + + _group setVariable ["sup_artillery_inPosition", false]; + + private _waypoint = _group addWaypoint [_position, 0]; + _waypoint setWaypointType "MOVE"; + _waypoint setWaypointBehaviour "SAFE"; + _waypoint setWaypointForceBehaviour true; + _waypoint setWaypointSpeed "NORMAL"; + _waypoint setWaypointFormation "COLUMN"; + _waypoint setWaypointStatements [ + "true", + "(group this) setVariable ['sup_artillery_inPosition', true]" + ]; + }; + case "inPosition": { + private _group = _logic getVariable ["group", grpNull]; + _result = _group getVariable ["sup_artillery_inPosition", false]; + }; + case "unpack": { + private _group = _logic getVariable ["group", grpNull]; + private _fireMission = _logic getVariable ["fireMission", []]; + private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; + + private _handle = [_group, position (leader _group), _position] spawn ALIVE_fnc_unpackMortar; + + [_group, _handle] spawn { + private _group = _this select 0; + private _handle = _this select 1; + + waitUntil { scriptDone _handle }; + _group setVariable ["sup_artillery_deployed", true]; + }; + }; + case "hasUnpacked": { + private _type = _logic getvariable ["type", TYPE_ARTILLERY]; + + if (_type == TYPE_MORTAR) then { + private _group = _logic getVariable ["group", grpNull]; + _result = _group getVariable ["sup_artillery_deployed", true]; + } else { + _result = true + }; + }; case "execute": { private _group = _logic getVariable ["group", grpNull]; private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; @@ -147,6 +244,11 @@ switch (_operation) do { _vehicle setVariable ["sup_artillery_firedEH", _firedEH]; } forEach _units; }; + case "canFireRound": { + private _fireMission = _logic getVariable ["fireMission", []]; + private _nextRoundTime = [_fireMission, "nextRoundTime"] call ALIVE_fnc_hashGet; + _result = (_nextRoundTime != -1 && {time >= _nextRoundTime}); + }; // TODO: Check if unit is alive, otherwise skip case "fire": { private _fireMission = _logic getVariable ["fireMission", []]; @@ -179,35 +281,6 @@ switch (_operation) do { [_fireMission, "nextRoundTime", -1] call ALIVE_fnc_hashSet; _logic setVariable ["fireMission", _fireMission]; }; - case "fireNextRound": { - private _fireMission = _logic getVariable ["fireMission", []]; - private _nextRoundTime = [_fireMission, "nextRoundTime"] call ALIVE_fnc_hashGet; - _result = (_nextRoundTime != -1 && {time >= _nextRoundTime}); - }; - case "hasFireMission": { - private _fireMission = _logic getVariable ["fireMission", []]; - _result = (count _fireMission > 0); - }; - case "hasPacked": { - private _type = _logic getvariable ["type", TYPE_ARTILLERY]; - - if (_type == TYPE_MORTAR) then { - private _group = _logic getVariable ["group", grpNull]; - _result = !(_group getVariable ["sup_artillery_deployed", true]); - } else { - _result = true - }; - }; - case "hasUnpacked": { - private _type = _logic getvariable ["type", TYPE_ARTILLERY]; - - if (_type == TYPE_MORTAR) then { - private _group = _logic getVariable ["group", grpNull]; - _result = _group getVariable ["sup_artillery_deployed", true]; - } else { - _result = true - }; - }; case "isFireMissionComplete": { private _fireMission = _logic getVariable ["fireMission", []]; private _roundCount = [_fireMission, "roundCount"] call ALIVE_fnc_hashGet; @@ -219,64 +292,6 @@ switch (_operation) do { private _delay = [_fireMission, "delay"] call ALIVE_fnc_hashGet; _result = (_delay > 0); }; - case "inPosition": { - private _group = _logic getVariable ["group", grpNull]; - _result = _group getVariable ["sup_artillery_inPosition", false]; - }; - case "inRange": { - private _fireMission = _logic getVariable ["fireMission", []]; - private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; - private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; - private _group = _logic getVariable ["group", grpNull]; - private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; - _result = _position inRangeOfArtillery [_units, _roundType]; - }; - case "move": { - private _group = _logic getVariable ["group", grpNull]; - private _position = []; - - if (count _args == 0) then { - _position = _logic getVariable ["moveToPos", objNull]; - } else { - _position = _args param [0, [0,0,0], [[]], 3]; - _logic setVariable ["moveToPos", _position]; - }; - - _group setVariable ["sup_artillery_inPosition", false]; - - private _waypoint = _group addWaypoint [_position, 0]; - _waypoint setWaypointType "MOVE"; - _waypoint setWaypointBehaviour "SAFE"; - _waypoint setWaypointForceBehaviour true; - _waypoint setWaypointSpeed "NORMAL"; - _waypoint setWaypointFormation "COLUMN"; - _waypoint setWaypointStatements [ - "true", - "(group this) setVariable ['sup_artillery_inPosition', true]" - ]; - }; - case "pack": { - private _group = _logic getVariable ["group", grpNull]; - private _deployed = _group getVariable ["sup_artillery_deployed", true]; - - if (_deployed) then { - private _weapon = objNull; - - { - if (vehicle _x != _x) exitWith { _weapon = vehicle _x }; - } forEach (units _group); - - private _handle = [_group, _weapon] spawn ALIVE_fnc_packMortar; - - [_group, _handle] spawn { - private _group = _this select 0; - private _handle = _this select 1; - - waitUntil { scriptDone _handle }; - _group setVariable ["sup_artillery_deployed", false]; - }; - }; - }; case "returnToBase": { private _group = _logic getVariable ["group", grpNull]; private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; @@ -296,21 +311,6 @@ switch (_operation) do { _logic setVariable ["fireMission", []]; [_logic, "move", [position _logic]] call MAINCLASS; }; - case "unpack": { - private _group = _logic getVariable ["group", grpNull]; - private _fireMission = _logic getVariable ["fireMission", []]; - private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; - - private _handle = [_group, position (leader _group), _position] spawn ALIVE_fnc_unpackMortar; - - [_group, _handle] spawn { - private _group = _this select 0; - private _handle = _this select 1; - - waitUntil { scriptDone _handle }; - _group setVariable ["sup_artillery_deployed", true]; - }; - }; }; // TODO: Give this legacy stuff a place From 6679c93714f15e880f11e2f4b09d7dce141a2cc1 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Thu, 17 Nov 2016 21:22:37 +0100 Subject: [PATCH 26/29] Separate getters and setters --- addons/sup_artillery/fnc_artillery.sqf | 62 ++++++++----------- addons/sup_artillery/fnc_artillerySpawn.sqf | 2 +- addons/sup_artillery/script_component.hpp | 3 + addons/sup_combatsupport/script_component.hpp | 2 +- .../ui/arty/fn_artyConfirmButton.sqf | 2 +- 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 07966edb9..637f2e0c8 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -31,8 +31,6 @@ marceldev89 #define SUPERCLASS ALIVE_fnc_baseClass #define MAINCLASS ALIVE_fnc_artillery -#define TYPE_ARTILLERY 0 -#define TYPE_MORTAR 1 private _logic = param [0, objNull, [objNull, []]]; private _operation = param [1, "", [""]]; @@ -66,8 +64,33 @@ switch (_operation) do { // Add artillery module to state machine ALIVE_sup_artillery_stateMachine_list pushBack _logic; }; - // get available rounds - case "rounds": { + case "getFireMission": { + _result = _logic getVariable ["fireMission", []]; + }; + case "setFireMission": { + if (count _args == 0) exitWith { _result = false }; + + private _position = _args param [0, [0,0,0], [[]], 3]; + private _roundType = _args param [1, "", [""]]; + private _roundCount = _args param [2, 1, [1]]; + private _delay = _args param [3, 5, [1]]; + private _dispersion = _args param [4, 50, [1]]; + + private _fireMission = [] call ALIVE_fnc_hashCreate; + [_fireMission, "position", _position] call ALIVE_fnc_hashSet; + [_fireMission, "roundType", _roundType] call ALIVE_fnc_hashSet; + [_fireMission, "roundCount", _roundCount] call ALIVE_fnc_hashSet; + [_fireMission, "delay", _delay] call ALIVE_fnc_hashSet; + [_fireMission, "dispersion", _dispersion] call ALIVE_fnc_hashSet; + // Fire mission state + [_fireMission, "units", []] call ALIVE_fnc_hashSet; + [_fireMission, "unitIndex", -1] call ALIVE_fnc_hashSet; + [_fireMission, "roundsShot", -1] call ALIVE_fnc_hashSet; + [_fireMission, "nextRoundTime", -1] call ALIVE_fnc_hashSet; + + _logic setVariable ["fireMission", _fireMission]; + }; + case "getRounds": { private _rounds = [ ["HE", parseNumber (_logic getVariable ["artillery_he", "30"])], ["ILLUM", parseNumber (_logic getVariable ["artillery_illum", "30"])], @@ -91,37 +114,6 @@ switch (_operation) do { _result = _roundsAvailable; }; - // get/set fire mission - case "fireMission": { - if (count _args == 0) then { - _result = _logic getVariable ["fireMission", []]; - } else { - private _position = _args param [0, [0,0,0], [[]], 3]; - private _roundType = _args param [1, "", [""]]; - private _roundCount = _args param [2, 1, [1]]; - private _delay = _args param [3, 5, [1]]; - private _dispersion = _args param [4, 50, [1]]; - - private _fireMission = [] call ALIVE_fnc_hashCreate; - [_fireMission, "position", _position] call ALIVE_fnc_hashSet; - [_fireMission, "roundType", _roundType] call ALIVE_fnc_hashSet; - [_fireMission, "roundCount", _roundCount] call ALIVE_fnc_hashSet; - [_fireMission, "delay", _delay] call ALIVE_fnc_hashSet; - [_fireMission, "dispersion", _dispersion] call ALIVE_fnc_hashSet; - // Fire mission state - [_fireMission, "units", []] call ALIVE_fnc_hashSet; - [_fireMission, "unitIndex", -1] call ALIVE_fnc_hashSet; - [_fireMission, "roundsShot", -1] call ALIVE_fnc_hashSet; - [_fireMission, "nextRoundTime", -1] call ALIVE_fnc_hashSet; - - _logic setVariable ["fireMission", _fireMission]; - }; - }; - // get position - case "position": { - private _group = _logic getVariable ["group", grpNull]; - _result = position (leader _group); - }; case "hasFireMission": { private _fireMission = _logic getVariable ["fireMission", []]; _result = (count _fireMission > 0); diff --git a/addons/sup_artillery/fnc_artillerySpawn.sqf b/addons/sup_artillery/fnc_artillerySpawn.sqf index 7644fc3b7..186914388 100644 --- a/addons/sup_artillery/fnc_artillerySpawn.sqf +++ b/addons/sup_artillery/fnc_artillerySpawn.sqf @@ -61,7 +61,7 @@ _group setVariable ["logic", _logic]; _logic setVariable ["group", _group]; // Assign artillery group to NEO_radio -private _rounds = [_logic, "rounds"] call ALIVE_fnc_artillery; +private _rounds = [_logic, "getRounds"] call ALIVE_fnc_artillery; leader _group setVariable ["NEO_radioArtyBatteryRounds", _rounds, true]; private _a = NEO_radioLogic getVariable format ["NEO_radioArtyArray_%1", _side]; _a set [count _a, [leader _group, _group, _callsign, _vehicles, _rounds]]; diff --git a/addons/sup_artillery/script_component.hpp b/addons/sup_artillery/script_component.hpp index 2982f4db2..7ad752926 100644 --- a/addons/sup_artillery/script_component.hpp +++ b/addons/sup_artillery/script_component.hpp @@ -9,4 +9,7 @@ #define DEBUG_SETTINGS DEBUG_SETTINGS_sup_artillery #endif +#define TYPE_ARTILLERY 0 +#define TYPE_MORTAR 1 + #include <\x\cba\addons\main\script_macros.hpp> diff --git a/addons/sup_combatsupport/script_component.hpp b/addons/sup_combatsupport/script_component.hpp index 2910df7ca..7a726ce96 100644 --- a/addons/sup_combatsupport/script_component.hpp +++ b/addons/sup_combatsupport/script_component.hpp @@ -9,4 +9,4 @@ #define DEBUG_SETTINGS DEBUG_SETTINGS_SUP_COMBATSUPPORT #endif -#include <\x\cba\addons\main\script_macros.hpp> \ No newline at end of file +#include <\x\cba\addons\main\script_macros.hpp> diff --git a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf index 434619dfe..b6a944297 100644 --- a/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf +++ b/addons/sup_combatsupport/scripts/NEO_radio/functions/ui/arty/fn_artyConfirmButton.sqf @@ -60,7 +60,7 @@ if (_audio) then { // TODO: Cleanup obsolete bits private _logic = _unit getVariable ["logic", objNull]; -[_logic, "fireMission", [_pos, _ord, _count, _rate, _dispersion]] call ALIVE_fnc_artillery; +[_logic, "setFireMission", [_pos, _ord, _count, _rate, _dispersion]] call ALIVE_fnc_artillery; //NEW TASK _battery setVariable ["NEO_radioArtyNewTask", [_type, _ordnanceType, _rate, _count, _dispersion, _pos, _unit, _ord, _callsignPlayer, player], true]; From cc98238c4cd96faef7cf1869687f91bf03682664 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sat, 19 Nov 2016 13:35:19 +0100 Subject: [PATCH 27/29] Don't initialize arty module if not synced to CS module --- addons/sup_artillery/fnc_artillery.sqf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 637f2e0c8..6d3a56972 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -50,6 +50,9 @@ switch (_operation) do { _logic setVariable ["moveToPos", objNull]; _logic setVariable ["fireMission", []]; + // Are we synced with combat support module? + if (({typeOf _x == "ALIVE_sup_combatsupport"} count (synchronizedObjects _logic)) == 0) exitWith { _result = false }; + // Spawn and initialize artillery units [_logic] call ALIVE_fnc_artillerySpawn; From ed7dc3b9bd0c1eb8259e76001b93e1adba4ededa Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sun, 20 Nov 2016 16:32:03 +0100 Subject: [PATCH 28/29] Relocate arty asset when not in range --- addons/sup_artillery/CfgFunctions.hpp | 5 +++ addons/sup_artillery/fnc_artillery.sqf | 13 +++++- .../sup_artillery/fnc_artilleryGetRange.sqf | 43 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 addons/sup_artillery/fnc_artilleryGetRange.sqf diff --git a/addons/sup_artillery/CfgFunctions.hpp b/addons/sup_artillery/CfgFunctions.hpp index 9fdeef2ad..0b59b73a8 100644 --- a/addons/sup_artillery/CfgFunctions.hpp +++ b/addons/sup_artillery/CfgFunctions.hpp @@ -21,6 +21,11 @@ class cfgFunctions { file = "\x\alive\addons\sup_artillery\fnc_artilleryFiredEH.sqf"; RECOMPILE; }; + class artilleryGetRange { + description = "Gets range of artillery asset"; + file = "\x\alive\addons\sup_artillery\fnc_artilleryGetRange.sqf"; + RECOMPILE; + }; }; }; }; diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 6d3a56972..883ecef54 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -123,7 +123,18 @@ switch (_operation) do { }; case "activate": { if (!([_logic, "inRange"] call MAINCLASS)) then { - _logic setVariable ["moveToPos", [3744.56,4757.54,0]]; // TODO: Figure out best firing position + private _fireMission = _logic getVariable ["fireMission", []]; + private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; + private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet; + private _group = _logic getVariable ["group", grpNull]; + private _units = (units _group) select {vehicle _x != _x && {gunner (vehicle _x) == _x}}; + + private _vehicle = vehicle (_units select 0); + private _range = [_vehicle, _roundType] call ALIVE_fnc_artilleryGetRange; + private _radius = 500; + private _newPosition = [_position, _range - _radius, _position getDir _vehicle] call BIS_fnc_relPos; + _newPosition = [_newPosition, 10, _radius, 5, 0, 0.15, 0] call BIS_fnc_findSafePos; + _logic setVariable ["moveToPos", _newPosition]; }; }; case "inRange": { diff --git a/addons/sup_artillery/fnc_artilleryGetRange.sqf b/addons/sup_artillery/fnc_artilleryGetRange.sqf new file mode 100644 index 000000000..c303ca69a --- /dev/null +++ b/addons/sup_artillery/fnc_artilleryGetRange.sqf @@ -0,0 +1,43 @@ +#include <\x\alive\addons\sup_artillery\script_component.hpp> +SCRIPT(ArtilleryGetRange); + +/* ---------------------------------------------------------------------------- +Function: ALIVE_fnc_artilleryGetRange +Description: +Gets the range for artillery assets + +Parameters: +Object - The artillery asset +String - The round type + +Returns: +Number - The range + +Examples: + +See Also: + +Author: +marceldev89 +---------------------------------------------------------------------------- */ +private _vehicle = param [0, objNull, [objNull]]; +private _roundType = param [1, "", [""]]; + +private _range = 0; +private _inRange = true; +private _eta = 0; +private _target = position _vehicle; + +// Figure out range by incrementing distance from asset. Configs seem unreliable. +while {_range == 0 || (_inRange && _eta != -1)} do { + _inRange = _target inRangeOfArtillery [[_vehicle], _roundType]; + _eta = _vehicle getArtilleryETA [_target, _roundType]; + + if (_inRange && _eta != -1) then { + _range = (position _vehicle) distance2D _target; + }; + + _target = [_target, 1, 0] call BIS_fnc_relPos; +}; + +_range; From 6e5a339aba599fad07692e7dd346c29348fd5253 Mon Sep 17 00:00:00 2001 From: Marcel de Vries Date: Sun, 20 Nov 2016 16:32:40 +0100 Subject: [PATCH 29/29] Fix RTB behaviour --- addons/sup_artillery/fnc_artillery.sqf | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/addons/sup_artillery/fnc_artillery.sqf b/addons/sup_artillery/fnc_artillery.sqf index 883ecef54..c2e7e071a 100644 --- a/addons/sup_artillery/fnc_artillery.sqf +++ b/addons/sup_artillery/fnc_artillery.sqf @@ -208,7 +208,13 @@ switch (_operation) do { case "unpack": { private _group = _logic getVariable ["group", grpNull]; private _fireMission = _logic getVariable ["fireMission", []]; - private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; + private _position = []; + + if (count _fireMission > 0) then { + _position = [_fireMission, "position"] call ALIVE_fnc_hashGet; + } else { + _position = position _logic; + }; private _handle = [_group, position (leader _group), _position] spawn ALIVE_fnc_unpackMortar; @@ -315,7 +321,16 @@ switch (_operation) do { } forEach _units; _logic setVariable ["fireMission", []]; - [_logic, "move", [position _logic]] call MAINCLASS; + + [_logic] spawn { + private _logic = param [0, objNull, [objNull]]; + + [_logic, "pack"] call MAINCLASS; + waitUntil { [_logic, "hasPacked"] call MAINCLASS }; + [_logic, "move", [position _logic]] call MAINCLASS; + waitUntil { [_logic, "inPosition"] call MAINCLASS }; + [_logic, "unpack"] call MAINCLASS; + }; }; };