Skip to content

Commit 4a04214

Browse files
committed
Create (sup_)Artillery class with CBA statemachine
1 parent f1f844f commit 4a04214

File tree

3 files changed

+275
-23
lines changed

3 files changed

+275
-23
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
class ArtilleryStateMachine {
2+
list = "";
3+
4+
class Idle {
5+
onState = "";
6+
onStateEntered = "";
7+
onStateLeaving = "";
8+
9+
class HasFireMission {
10+
targetState = "Active";
11+
condition = "[_this, 'hasFireMission'] call ALIVE_fnc_Artillery";
12+
onTransition = "";
13+
};
14+
};
15+
16+
class Active {
17+
onState = "[_this, 'onActive'] call ALIVE_fnc_Artillery";
18+
onStateEntered = "";
19+
onStateLeaving = "";
20+
21+
class InRange {
22+
targetState = "Execute";
23+
condition = "[_this, 'inRange'] call ALIVE_fnc_Artillery";
24+
onTransition = "";
25+
};
26+
27+
class NotInRange {
28+
targetState = "Move";
29+
condition = "!([_this, 'inRange'] call ALIVE_fnc_Artillery)";
30+
onTransition = "";
31+
};
32+
};
33+
34+
class Move {
35+
onState = "[_this, 'onMove'] call ALIVE_fnc_Artillery";
36+
onStateEntered = "";
37+
onStateLeaving = "";
38+
39+
class InPosition {
40+
targetState = "Execute";
41+
condition = "[_this, 'inPosition'] call ALIVE_fnc_Artillery";
42+
onTransition = "";
43+
};
44+
45+
class Abort {
46+
targetState = "ReturnToBase";
47+
condition = "!([_this, 'hasFireMission'] call ALIVE_fnc_Artillery)";
48+
onTransition = "";
49+
};
50+
};
51+
52+
class Execute {
53+
onState = "[_this, 'onExecute'] call ALIVE_fnc_Artillery";
54+
onStateEntered = "";
55+
onStateLeaving = "";
56+
57+
class Abort {
58+
targetState = "ReturnToBase";
59+
condition = "!([_this, 'hasFireMission'] call ALIVE_fnc_Artillery)";
60+
onTransition = "";
61+
};
62+
};
63+
64+
class Fire {
65+
onState = "[_this, 'onFire'] call ALIVE_fnc_Artillery";
66+
onStateEntered = "";
67+
onStateLeaving = "";
68+
69+
class FireMissionComplete {
70+
targetState = "ReturnToBase";
71+
condition = "[_this, 'isFireMissionComplete'] call ALIVE_fnc_Artillery";
72+
onTransition = "";
73+
};
74+
75+
class Fired {
76+
targetState = "FireDelay";
77+
condition = "true";
78+
onTransition = "";
79+
};
80+
};
81+
82+
class FireDelay {
83+
onState = "";
84+
onStateEntered = "";
85+
onStateLeaving = "";
86+
87+
class Continue {
88+
targetState = "Fire";
89+
condition = "[_this, 'fireNextRound'] call ALIVE_fnc_Artillery";
90+
onTransition = "";
91+
};
92+
};
93+
94+
class ReturnToBase {
95+
onState = "[_this, 'onReturnToBase'] call ALIVE_fnc_Artillery";
96+
onStateEntered = "";
97+
onStateLeaving = "";
98+
99+
class AtBase {
100+
targetState = "Idle";
101+
condition = "[_this, 'inPosition'] call ALIVE_fnc_Artillery";
102+
onTransition = "";
103+
};
104+
};
105+
};

addons/sup_artillery/config.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
#include <CfgPatches.hpp>
44
#include <CfgVehicles.hpp>
55
#include <CfgFunctions.hpp>
6+
7+
#include <ArtilleryStateMachine.hpp>
Lines changed: 168 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <\x\alive\addons\sup_artillery\script_component.hpp>
2-
SCRIPT(CAS);
2+
SCRIPT(Artillery);
33

44
/* ----------------------------------------------------------------------------
5-
Function: ALIVE_fnc_CQB
5+
Function: ALIVE_fnc_Artillery
66
Description:
7-
XXXXXXXXXX
7+
Artillery module.
88
99
Parameters:
1010
Nil or Object - If Nil, return a new instance. If Object, reference an existing instance.
@@ -21,37 +21,182 @@ Boolean - enabled - Enabled or disable module
2121
Parameters:
2222
none
2323
24-
Description:
25-
CQB Module! Detailed description to follow
26-
2724
Examples:
28-
[_logic, "factions", ["OPF_F"] call ALiVE_fnc_CQB;
29-
[_logic, "houses", _nonStrategicHouses] call ALiVE_fnc_CQB;
30-
[_logic, "spawnDistance", 500] call ALiVE_fnc_CQB;
31-
[_logic, "active", true] call ALiVE_fnc_CQB;
3225
3326
See Also:
34-
- <ALIVE_fnc_CQBInit>
3527
3628
Author:
37-
Wolffy, Highhead
29+
marceldev89
3830
---------------------------------------------------------------------------- */
3931

40-
#define SUPERCLASS nil
41-
42-
private ["_logic","_operation","_args"];
43-
44-
PARAMS_1(_logic);
45-
DEFAULT_PARAM(1,_operation,"");
46-
DEFAULT_PARAM(2,_args,nil);
32+
#define SUPERCLASS ALIVE_fnc_baseClass
33+
#define MAINCLASS ALIVE_fnc_artillery
34+
35+
private _logic = param [0, objNull, [objNull, []]];
36+
private _operation = param [1, "", [""]];
37+
private _args = param [2, objNull, [objNull, [], "", 0, true, false]];
38+
39+
private _result = true;
40+
41+
switch (_operation) do {
42+
case "init": {
43+
[] call ALIVE_fnc_artillery_init;
44+
};
45+
46+
/****************
47+
** PROPERTIES **
48+
****************/
49+
case "fireMission": {
50+
if (isNull _args) then {
51+
_result = [_logic, "fireMission"] call ALIVE_fnc_hashGet;
52+
} else {
53+
private _position = _args param [0, [0,0,0], [[]], 3];
54+
private _roundType = _args param [1, "", [""]];
55+
private _roundCount = _args param [2, 1, [1]];
56+
private _delay = _args param [3, 5, [1]];
57+
private _dispersion = _args param [4, 50, [1]];
58+
59+
private _fireMission = [] call ALIVE_fnc_hashCreate;
60+
[_fireMission, "position", _position] call ALIVE_fnc_hashSet;
61+
[_fireMission, "roundType", _roundType] call ALIVE_fnc_hashSet;
62+
[_fireMission, "roundCount", _roundCount] call ALIVE_fnc_hashSet;
63+
[_fireMission, "delay", _delay] call ALIVE_fnc_hashSet;
64+
[_fireMission, "dispersion", _dispersion] call ALIVE_fnc_hashSet;
65+
// Defaults
66+
[_fireMission, "units", []] call ALIVE_fnc_hashSet;
67+
[_fireMission, "unitIndex", -1] call ALIVE_fnc_hashSet;
68+
[_fireMission, "roundsShot", -1] call ALIVE_fnc_hashSet;
69+
[_fireMission, "nextRoundTime", -1] call ALIVE_fnc_hashSet;
70+
71+
[_logic, "fireMission", _fireMission] call ALIVE_fnc_hashSet;
72+
};
73+
};
74+
case "position": {
75+
private _group = [_logic, "group"] call ALIVE_fnc_hashGet;
76+
_result = position (leader _group);
77+
};
78+
79+
/*************
80+
** METHODS **
81+
*************/
82+
case "execute": {
83+
private _group = [_logic, "group"] call ALIVE_fnc_hashGet;
84+
private _units = (units _group) select {vehicle _x != _x && {gunner _x == _x}};
85+
private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet;
86+
[_fireMission, "units", _units] call ALIVE_fnc_hashSet;
87+
[_fireMission, "unitIndex", 0] call ALIVE_fnc_hashSet;
88+
[_fireMission, "roundsShot", 0] call ALIVE_fnc_hashSet;
89+
[_logic, "fireMission", _fireMission] call ALIVE_fnc_hashSet; // TODO: Is this needed?
90+
};
91+
case "fire": {
92+
private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet;
93+
private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet;
94+
private _units = [_fireMission, "units"] call ALIVE_fnc_hashGet;
95+
private _unitIndex = [_fireMission, "unitIndex"] call ALIVE_fnc_hashGet;
96+
private _unit = _units select _unitIndex;
97+
private _position = [_fireMission, "position"] call ALIVE_fnc_hashGet;
98+
private _roundType = [_fireMission, "roundType"] call ALIVE_fnc_hashGet;
99+
private _delay = [_fireMission, "delay"] call ALIVE_fnc_hashGet;
100+
101+
_unit doArtilleryFire [
102+
_position,
103+
_roundType,
104+
1
105+
];
106+
107+
if ((_unitIndex + 1) > ((count _units) - 1)) then {
108+
_unitIndex = 0;
109+
} else {
110+
_unitIndex = _unitIndex + 1;
111+
};
112+
113+
[_fireMission, "nextRoundTime", time + _delay] call ALIVE_fnc_hashSet;
114+
[_fireMission, "unitIndex", _unitIndex] call ALIVE_fnc_hashSet;
115+
[_fireMission, "roundsShot", _roundsShot + 1] call ALIVE_fnc_hashSet;
116+
[_logic, "fireMission", _fireMission] call ALIVE_fnc_hashSet; // TODO: Is this needed?
117+
};
118+
case "fireNextRound": {
119+
private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet;
120+
private _nextRoundTime = [_fireMission, "nextRoundTime"] call ALIVE_fnc_hashGet;
121+
_result = (time >= _nextRoundTime);
122+
};
123+
case "hasFireMission": {
124+
private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet;
125+
_result = (count _fireMission == 3);
126+
};
127+
case "isFireMissionComplete": {
128+
private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet;
129+
private _roundCount = [_fireMission, "roundCount"] call ALIVE_fnc_hashGet;
130+
private _roundsShot = [_fireMission, "roundsShot"] call ALIVE_fnc_hashGet;
131+
_result = (_roundsShot >= _roundCount);
132+
};
133+
case "inPosition": {
134+
private _group = [_logic, "group"] call ALIVE_fnc_hashGet;
135+
_result = _group getVariable ["sup_artillery_inPosition", false];
136+
};
137+
case "inRange": {
138+
private _fireMission = [_logic, "fireMission"] call ALIVE_fnc_hashGet;
139+
private _group = [_logic, "group"] call ALIVE_fnc_hashGet;
140+
private _units = (units _group) select {vehicle _x != _x && {gunner _x == _x}};
141+
_result = _position inRangeOfArtillery [_units, _fireMission select 1];
142+
};
143+
case "move": {
144+
private _group = [_logic, "group"] call ALIVE_fnc_hashGet;
145+
private _position = [];
146+
147+
if (!isNull _args && {count _args == 3}) then {
148+
[_logic, "moveToPos", _args] call ALIVE_fnc_hashSet;
149+
_position = _args;
150+
} else {
151+
_position = [_logic, "moveToPos"] call ALIVE_fnc_hashGet;
152+
};
153+
154+
private _waypoint = _group addWaypoint [_position, 0];
155+
_waypoint setWaypointType "MOVE";
156+
_waypoint setWaypointBehaviour "SAFE";
157+
_waypoint setWaypointSpeed "NORMAL";
158+
_waypoint setWaypointStatements [
159+
"true",
160+
"(group _this) setVariable ['sup_artillery_inPosition', true]"
161+
];
162+
163+
_group setVariable ["sup_artillery_inPosition", false];
164+
};
165+
166+
/******************
167+
** STATEMACHINE **
168+
******************/
169+
case "onIdle": {
170+
private _group = [_logic, "group"] call ALIVE_fnc_hashGet;
171+
_group setVariable ["sup_artillery_inPosition", true];
172+
[_logic, "moveToPos", objNull] call ALIVE_fnc_hashSet;
173+
174+
};
175+
case "onActive": {
176+
if (!([_logic, "inRange"] call MAINCLASS)) then {
177+
[_logic, "moveToPos", [0,0,0]] call ALIVE_fnc_hashSet; // TODO: Figure out best firing position
178+
};
179+
};
180+
case "onFire": {
181+
[_logic, "fire"] call MAINCLASS;
182+
};
183+
case "onMove": {
184+
[_logic, "move"] call MAINCLASS;
185+
};
186+
case "onExecute": {
187+
[_logic, "execute"] call MAINCLASS;
188+
};
189+
case "onReturnToBase": {
190+
[_logic, "move", [0,0,0]] call MAINCLASS; // TODO: Find (best) RTB position
191+
};
192+
};
193+
194+
// TODO: Give this legacy stuff a place
47195
ALIVE_coreLogic = _logic;
48196
_position = getposATL ALIVE_coreLogic;
49197
_callsign = _logic getvariable ["artillery_callsign","EAGLE ONE"];
50198
_type = _logic getvariable ["artillery_type","B_Heli_Attack_01_F"];
51199
_ordnace = _logic getvariable ["artillery_ordnace",["HE", 30]];
52200
ARTYPOS = _position; PublicVariable "ARTYPOS";
53201

54-
55-
56-
57-
202+
_result;

0 commit comments

Comments
 (0)