mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Compare commits
562 Commits
2.4.6
...
v2.5.0pre1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e67b819df9 | ||
|
|
efccefecad | ||
|
|
faa2debbae | ||
|
|
ddf61d1bf3 | ||
|
|
c5d514efdf | ||
|
|
f1c16def9a | ||
|
|
626db45a7e | ||
|
|
21a7594134 | ||
|
|
5fd20477d9 | ||
|
|
01dd3c93d2 | ||
|
|
b733e3b6d8 | ||
|
|
fe2ef11f8d | ||
|
|
9b6994749b | ||
|
|
9b209d6ce0 | ||
|
|
ed649747bd | ||
|
|
f5f1c9043b | ||
|
|
c7c371dc34 | ||
|
|
1cea10f03a | ||
|
|
3e9f54aaa5 | ||
|
|
ab1cd41d79 | ||
|
|
dc9f730d7d | ||
|
|
c0e48288de | ||
|
|
a13b79ced1 | ||
|
|
cd845d385f | ||
|
|
dea7a5674c | ||
|
|
8d1d2179f9 | ||
|
|
9b96ff5978 | ||
|
|
6cc233cac7 | ||
|
|
ad2ce8df78 | ||
|
|
4ea44308bc | ||
|
|
5cdaf53727 | ||
|
|
fb875077d7 | ||
|
|
c579aad606 | ||
|
|
8c54b7298d | ||
|
|
b309c25619 | ||
|
|
04a699f990 | ||
|
|
d51fc5de8a | ||
|
|
e458c70a7b | ||
|
|
2d4a4fb2ca | ||
|
|
e23ebd622a | ||
|
|
98e2f2c09b | ||
|
|
1fd9cbec1f | ||
|
|
1aedcf1ae4 | ||
|
|
e0075cc9ac | ||
|
|
372dd704d2 | ||
|
|
14b35cb069 | ||
|
|
c1b240857f | ||
|
|
0f5eb30a0f | ||
|
|
9e0f2c22b6 | ||
|
|
c0771c0096 | ||
|
|
c716ba16b3 | ||
|
|
96a904c077 | ||
|
|
f951aae3ee | ||
|
|
7a859f20bb | ||
|
|
3bfa8830a5 | ||
|
|
ec85b42a38 | ||
|
|
a216eb4e74 | ||
|
|
94476e418e | ||
|
|
fd1eb5f601 | ||
|
|
db7ec60c86 | ||
|
|
97e1a65b52 | ||
|
|
23497dddd4 | ||
|
|
e8a7def26e | ||
|
|
28a23c21f4 | ||
|
|
f32094aa43 | ||
|
|
c215255ae2 | ||
|
|
53b998cfab | ||
|
|
0a0a7d0fc3 | ||
|
|
d84ae236eb | ||
|
|
6dff84f435 | ||
|
|
1bfa5b5ee0 | ||
|
|
c3618bdc26 | ||
|
|
eebc5d90d1 | ||
|
|
596b3ddb4a | ||
|
|
e770af9fc9 | ||
|
|
d3c76da7a2 | ||
|
|
5f9880f17d | ||
|
|
d6b1018700 | ||
|
|
f934c8cb77 | ||
|
|
db4b5383fa | ||
|
|
4982cabcfb | ||
|
|
5594cd8fdf | ||
|
|
fbb32a9e45 | ||
|
|
1c559110a2 | ||
|
|
6f170db344 | ||
|
|
27a1401ae1 | ||
|
|
debf784d0c | ||
|
|
5a97f68778 | ||
|
|
d2ef75b22c | ||
|
|
115743263b | ||
|
|
59447999f0 | ||
|
|
4554ac1f3e | ||
|
|
d08d8db298 | ||
|
|
099f95f3cc | ||
|
|
20cf69c182 | ||
|
|
f931af2ee9 | ||
|
|
96fe9d51d6 | ||
|
|
d264c6f6a5 | ||
|
|
e17e635710 | ||
|
|
d4b9fc9e40 | ||
|
|
d66672a29c | ||
|
|
345b0055f3 | ||
|
|
7fdc049079 | ||
|
|
5caab9c6f3 | ||
|
|
03042c8282 | ||
|
|
c46028ff2d | ||
|
|
bd83344c21 | ||
|
|
183c05bcf5 | ||
|
|
a94591d811 | ||
|
|
6973e8c028 | ||
|
|
ab0b3f9b91 | ||
|
|
6f140be710 | ||
|
|
8780ec3687 | ||
|
|
1afe1c48b4 | ||
|
|
14b834e8ad | ||
|
|
0b53bd8f7e | ||
|
|
376a3553fa | ||
|
|
35653898cd | ||
|
|
ab1ba9595d | ||
|
|
2a7b9cf898 | ||
|
|
1224fb2d5a | ||
|
|
ac1d07ec66 | ||
|
|
1a534108bf | ||
|
|
c88f7bede5 | ||
|
|
598ef58849 | ||
|
|
2a485ef85a | ||
|
|
98ce42e9aa | ||
|
|
3612d5d171 | ||
|
|
83f8e76584 | ||
|
|
a108751e0c | ||
|
|
6f4d6c3daf | ||
|
|
a907369082 | ||
|
|
bc9060adfc | ||
|
|
4296dbade7 | ||
|
|
b1cee9969f | ||
|
|
9c0c4a11b1 | ||
|
|
b4324cb057 | ||
|
|
1d4dad0180 | ||
|
|
1e0e67c13d | ||
|
|
9c523cad52 | ||
|
|
6a1bf50700 | ||
|
|
d34cff1675 | ||
|
|
0a027caa47 | ||
|
|
10bfefdd06 | ||
|
|
ead1aed8d5 | ||
|
|
bc229f1a86 | ||
|
|
94f9cb4a79 | ||
|
|
acd5b1bdca | ||
|
|
9fed91b16f | ||
|
|
1627c92460 | ||
|
|
7bae22248a | ||
|
|
7b5b57c087 | ||
|
|
271217cf04 | ||
|
|
c5236d337e | ||
|
|
747bb949da | ||
|
|
a53bb1aac6 | ||
|
|
d3ecbac40a | ||
|
|
28fe8c5a0e | ||
|
|
6d79bbfb45 | ||
|
|
944c76c250 | ||
|
|
256ef2c7b4 | ||
|
|
2a0ae95e3e | ||
|
|
604ff07933 | ||
|
|
be8fc4e2e6 | ||
|
|
e92a625c5c | ||
|
|
e141823556 | ||
|
|
fbd0e9839d | ||
|
|
889ce8f64b | ||
|
|
6be56b1b86 | ||
|
|
78a5e89928 | ||
|
|
e09a02ec14 | ||
|
|
32ff4db36a | ||
|
|
9bb1c83999 | ||
|
|
93951dd4b4 | ||
|
|
1440f6c626 | ||
|
|
aacf83fd11 | ||
|
|
6c35892f05 | ||
|
|
3657a19645 | ||
|
|
ab423b3ba4 | ||
|
|
b4d6f78e42 | ||
|
|
49217291ad | ||
|
|
315d6bf82a | ||
|
|
486fc83323 | ||
|
|
3dbb013e16 | ||
|
|
b21ff707ba | ||
|
|
d985d9a41d | ||
|
|
178ee09614 | ||
|
|
95b67550eb | ||
|
|
48e0f8add6 | ||
|
|
d4f6ba2bdb | ||
|
|
e26b2f4919 | ||
|
|
208761fa46 | ||
|
|
03c47cc9f9 | ||
|
|
eb62810911 | ||
|
|
bf449492b5 | ||
|
|
4c08002d3e | ||
|
|
5e67861ea9 | ||
|
|
c657ba9218 | ||
|
|
ddfc22bb50 | ||
|
|
f9f4b3a9fd | ||
|
|
0e14624d39 | ||
|
|
f1d217b6d7 | ||
|
|
8126b198ba | ||
|
|
c2b46ceea1 | ||
|
|
fcceb278ec | ||
|
|
7a89960d21 | ||
|
|
4abdad5f35 | ||
|
|
6593a262bb | ||
|
|
b2f6b141d4 | ||
|
|
4bcf43122f | ||
|
|
70f30d2c53 | ||
|
|
a29a8d7d81 | ||
|
|
77f1bb4fdd | ||
|
|
53166b555f | ||
|
|
5f58fd3550 | ||
|
|
b7b6034d76 | ||
|
|
59974ea33e | ||
|
|
e4935d8717 | ||
|
|
de0c8e3789 | ||
|
|
bd290ffdab | ||
|
|
bfb11b6f79 | ||
|
|
8667c98449 | ||
|
|
4c72496599 | ||
|
|
aa8498ce0b | ||
|
|
ec155ed80c | ||
|
|
f849732f55 | ||
|
|
9856a8625d | ||
|
|
b1e99dc317 | ||
|
|
310ba9bb8a | ||
|
|
565a3062cb | ||
|
|
e8b74f0fc7 | ||
|
|
ca65154ecd | ||
|
|
e996a30333 | ||
|
|
e33a38556e | ||
|
|
3f2b3e0e1a | ||
|
|
dab0aef1e3 | ||
|
|
d9fb9c4928 | ||
|
|
964a6d0708 | ||
|
|
985282ba55 | ||
|
|
8534afe0e3 | ||
|
|
a70fa066fe | ||
|
|
3f8468dcc7 | ||
|
|
d9d9235fba | ||
|
|
5e20b244c5 | ||
|
|
40ebc4e990 | ||
|
|
70e7857b62 | ||
|
|
02a486e457 | ||
|
|
9e09a5bac9 | ||
|
|
ece7fc3ea9 | ||
|
|
0ea5c7fa48 | ||
|
|
3f64a1b33f | ||
|
|
02ee12402a | ||
|
|
837361e899 | ||
|
|
cff4f60923 | ||
|
|
fb23ac1d55 | ||
|
|
87a44f7f7f | ||
|
|
3b520ab0c4 | ||
|
|
044b5cba7c | ||
|
|
0f9591464a | ||
|
|
6a301060bf | ||
|
|
1e0b51a0a9 | ||
|
|
e19f0402da | ||
|
|
925ce3ad63 | ||
|
|
afc918c5e5 | ||
|
|
10b96f6cce | ||
|
|
d72e89d52b | ||
|
|
ef1a9330a4 | ||
|
|
eee1aca14f | ||
|
|
c8c95e063d | ||
|
|
0af9e57b82 | ||
|
|
e0899a8a9d | ||
|
|
093dadc0f6 | ||
|
|
23f92e49dd | ||
|
|
d1c909e9ed | ||
|
|
5dbc3b1ba1 | ||
|
|
85febea3d9 | ||
|
|
dca772cac6 | ||
|
|
26347ce779 | ||
|
|
b49f3c5b0c | ||
|
|
79be7cbd2c | ||
|
|
6fe8667885 | ||
|
|
b56d62c777 | ||
|
|
6f13aa2c5b | ||
|
|
d4510af249 | ||
|
|
fb784a9a96 | ||
|
|
25c7b1ddac | ||
|
|
71c7e15fc3 | ||
|
|
e6e0cf5977 | ||
|
|
775757e657 | ||
|
|
1a303ec7c2 | ||
|
|
c16edd65b0 | ||
|
|
1ff41ec7ec | ||
|
|
d874456361 | ||
|
|
6853eecffa | ||
|
|
71001adc5e | ||
|
|
b6a19d34c6 | ||
|
|
1364115b07 | ||
|
|
48c7254c84 | ||
|
|
60b6d2ade0 | ||
|
|
df43ff0841 | ||
|
|
5ee0ae44cd | ||
|
|
9df35840fe | ||
|
|
cff9557217 | ||
|
|
b5b6d398ae | ||
|
|
aba0c19215 | ||
|
|
5050371e0d | ||
|
|
81b36ef37d | ||
|
|
59e219e3d6 | ||
|
|
412d9e7a82 | ||
|
|
d01b55c790 | ||
|
|
5ed768065c | ||
|
|
e64703de03 | ||
|
|
71126eb34d | ||
|
|
6992e47a66 | ||
|
|
70d1f96681 | ||
|
|
83ed456c29 | ||
|
|
26607776a2 | ||
|
|
7a075e73ca | ||
|
|
6c15091df2 | ||
|
|
e063379cd8 | ||
|
|
3a49f2258b | ||
|
|
dddf056b20 | ||
|
|
bdbfed13ff | ||
|
|
9eb0800b66 | ||
|
|
713ec61031 | ||
|
|
264e84649e | ||
|
|
c4016cfa4d | ||
|
|
1cb248692b | ||
|
|
331315a83e | ||
|
|
e325b2192b | ||
|
|
86094bc6d2 | ||
|
|
f2b2b1974d | ||
|
|
080c496cc3 | ||
|
|
bcfa0f9ac5 | ||
|
|
746c0d25f7 | ||
|
|
9e450ce76b | ||
|
|
77bee89ea5 | ||
|
|
dbc80183e6 | ||
|
|
ff0371faa5 | ||
|
|
ebaddb3fe4 | ||
|
|
8f3aeeb182 | ||
|
|
3157e4f986 | ||
|
|
0fe18ee5b4 | ||
|
|
265d6da331 | ||
|
|
1c063ca308 | ||
|
|
5a5340431e | ||
|
|
869a8a57e1 | ||
|
|
dd15da28b2 | ||
|
|
47778c6fe7 | ||
|
|
0d90eed270 | ||
|
|
d8147348c6 | ||
|
|
6b85141a39 | ||
|
|
0fcc379ede | ||
|
|
f22f62339f | ||
|
|
934b9d9cf1 | ||
|
|
47dd068655 | ||
|
|
382dfd797c | ||
|
|
8e66031afe | ||
|
|
eea1d56468 | ||
|
|
6edcc58b9a | ||
|
|
7a8197208c | ||
|
|
acd6e0f423 | ||
|
|
e741e0d1d6 | ||
|
|
09f28a555f | ||
|
|
a9590561d2 | ||
|
|
9700776468 | ||
|
|
cec6940aeb | ||
|
|
e082ee17e4 | ||
|
|
2327fa7e4b | ||
|
|
bd25a8ccb4 | ||
|
|
fff0c8ccd3 | ||
|
|
df6a10862e | ||
|
|
a33b7b2769 | ||
|
|
5e01db8809 | ||
|
|
32c064a1be | ||
|
|
610938b6e8 | ||
|
|
ea93e3863b | ||
|
|
ab38efd69e | ||
|
|
8dc5642599 | ||
|
|
d8c5ab7eae | ||
|
|
49e7a24e28 | ||
|
|
6f2de65b64 | ||
|
|
34603d69ab | ||
|
|
afb79391dd | ||
|
|
7f1dcf93d9 | ||
|
|
04722a7d83 | ||
|
|
fd6a319928 | ||
|
|
e91a744bd9 | ||
|
|
876b369c0d | ||
|
|
75ac76a8e5 | ||
|
|
6c4bde4ceb | ||
|
|
cfc9c655c5 | ||
|
|
d576573cf8 | ||
|
|
1559f14f11 | ||
|
|
242151eedf | ||
|
|
7cf10e90f8 | ||
|
|
5201c73d35 | ||
|
|
07f313a4a6 | ||
|
|
fa08434690 | ||
|
|
8969c58ca5 | ||
|
|
810cebfe0a | ||
|
|
d607b96021 | ||
|
|
d098930351 | ||
|
|
143e729a5e | ||
|
|
5ef4b593a2 | ||
|
|
7eb98c05eb | ||
|
|
43ec58fe85 | ||
|
|
0a5f042555 | ||
|
|
44f8c2a933 | ||
|
|
ecbdbedd96 | ||
|
|
c6a4e4c533 | ||
|
|
afb0a8af33 | ||
|
|
8d222fd0c3 | ||
|
|
9795d5655f | ||
|
|
db6c7f1a2c | ||
|
|
cfdce853a3 | ||
|
|
01b2f238c5 | ||
|
|
5a327b1d6b | ||
|
|
96b60d8ac0 | ||
|
|
e7f1d98b64 | ||
|
|
c2ddf17aa2 | ||
|
|
302d9dfad4 | ||
|
|
a83008aad3 | ||
|
|
047df5917a | ||
|
|
6b53e9f9a8 | ||
|
|
d66028a1b9 | ||
|
|
51de6756a7 | ||
|
|
74d97cc220 | ||
|
|
cf2ad6f277 | ||
|
|
b05d3fbde2 | ||
|
|
7b0db24e00 | ||
|
|
21f0094d7c | ||
|
|
99c2e76e53 | ||
|
|
50c40cb4e9 | ||
|
|
5e8b461478 | ||
|
|
73db4b365b | ||
|
|
0cf5bee09a | ||
|
|
3d54d78be8 | ||
|
|
bd537ece00 | ||
|
|
1f282693b3 | ||
|
|
e16f306e1d | ||
|
|
6b24673b6f | ||
|
|
58886dc42d | ||
|
|
8cea501748 | ||
|
|
c5171e8722 | ||
|
|
5af235a345 | ||
|
|
8133ef2036 | ||
|
|
9269e1e943 | ||
|
|
b4c82d0aac | ||
|
|
39ffc28cb4 | ||
|
|
e23488a723 | ||
|
|
ba1cb61f4d | ||
|
|
921ec8732c | ||
|
|
51a1f56011 | ||
|
|
2feb293c12 | ||
|
|
9d9f233c15 | ||
|
|
9ad948632c | ||
|
|
9b40ebe00c | ||
|
|
dab3ed5fbe | ||
|
|
34d7b18c26 | ||
|
|
dc4115d4e3 | ||
|
|
5cfd0aac1c | ||
|
|
9481cbf7e8 | ||
|
|
748f9b52aa | ||
|
|
c5ce3342e2 | ||
|
|
6c4ca046a9 | ||
|
|
256697c39e | ||
|
|
4017876fe2 | ||
|
|
9651614894 | ||
|
|
3bc2baaf9d | ||
|
|
fa05352882 | ||
|
|
849ca24ac8 | ||
|
|
84e9d225e9 | ||
|
|
7b53a43c5c | ||
|
|
e3121781d0 | ||
|
|
2c788b1b38 | ||
|
|
369606f0f1 | ||
|
|
8d4ce5e486 | ||
|
|
1b691e5887 | ||
|
|
2d7d19880f | ||
|
|
8b06af01b0 | ||
|
|
ea3899f469 | ||
|
|
adb8b6cbca | ||
|
|
252950af73 | ||
|
|
14189e1bca | ||
|
|
ed60c5dca4 | ||
|
|
c4984a7576 | ||
|
|
6a1052d95f | ||
|
|
caa3bcb02b | ||
|
|
74123d8ff3 | ||
|
|
70b858d200 | ||
|
|
3ca712a223 | ||
|
|
cf4be99093 | ||
|
|
900a55614b | ||
|
|
f76b0dc7d3 | ||
|
|
4542c96eae | ||
|
|
dd242bc1fe | ||
|
|
456a38022f | ||
|
|
34d73af8bf | ||
|
|
238b1cb925 | ||
|
|
604255bfba | ||
|
|
cfc0367c55 | ||
|
|
488804308b | ||
|
|
6fac8fe940 | ||
|
|
b53b1edd29 | ||
|
|
5a2bac9979 | ||
|
|
e7181c255b | ||
|
|
ac074ca23d | ||
|
|
b21bb3d433 | ||
|
|
0e656c8520 | ||
|
|
708ff794b0 | ||
|
|
6e34f12ac8 | ||
|
|
f4a89d62e3 | ||
|
|
a36e39205b | ||
|
|
6d45c09ea2 | ||
|
|
9fac65f31f | ||
|
|
3789674666 | ||
|
|
a22774b278 | ||
|
|
81bb8dd65f | ||
|
|
9d3796b605 | ||
|
|
ba4caf179a | ||
|
|
1febe765bf | ||
|
|
087ac992a2 | ||
|
|
3e3dfc83aa | ||
|
|
27bf6069d7 | ||
|
|
3153d196a2 | ||
|
|
8c320f729a | ||
|
|
c7fdc77ec8 | ||
|
|
dfd20ced59 | ||
|
|
5f40feb1af | ||
|
|
ae754fe334 | ||
|
|
e062db9411 | ||
|
|
023eae825d | ||
|
|
1a4baeafb6 | ||
|
|
b754972490 | ||
|
|
0c36e4e40d | ||
|
|
1f97495fdd | ||
|
|
c164c0f9e3 | ||
|
|
f0b5ec1025 | ||
|
|
b72ea2d02c | ||
|
|
238fcf1176 | ||
|
|
c354fecc6d | ||
|
|
4434d1da21 | ||
|
|
17ffc7cef9 | ||
|
|
006fd25e56 | ||
|
|
f2eafe0302 | ||
|
|
52069cc1d0 | ||
|
|
d9374f0389 | ||
|
|
19520f9688 | ||
|
|
1eda5af7df | ||
|
|
2ea8487e04 | ||
|
|
b0885ada00 | ||
|
|
1c6c0c4d81 | ||
|
|
645ca570a8 | ||
|
|
07e690caf0 | ||
|
|
223de9d1aa | ||
|
|
7d7c521bce | ||
|
|
baaee9f92e | ||
|
|
3a9be7a890 | ||
|
|
74d2ee9430 | ||
|
|
856bd56cde | ||
|
|
4c91880a85 |
@@ -10,7 +10,8 @@
|
||||
-- @image AI_Combat_Air_Patrol.JPG
|
||||
|
||||
--- @type AI_A2A_CAP
|
||||
-- @extends AI.AI_A2A_Patrol#AI_A2A_PATROL
|
||||
-- @extends AI.AI_Air_Patrol#AI_AIR_PATROL
|
||||
-- @extends AI.AI_Air_Engage#AI_AIR_ENGAGE
|
||||
|
||||
|
||||
--- The AI_A2A_CAP class implements the core functions to patrol a @{Zone} by an AI @{Wrapper.Group} or @{Wrapper.Group}
|
||||
@@ -97,6 +98,37 @@ AI_A2A_CAP = {
|
||||
ClassName = "AI_A2A_CAP",
|
||||
}
|
||||
|
||||
--- Creates a new AI_A2A_CAP object
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap
|
||||
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude The highest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#AltitudeType EngageAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to "RADIO".
|
||||
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to "RADIO".
|
||||
-- @return #AI_A2A_CAP
|
||||
function AI_A2A_CAP:New2( AICap, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType, PatrolZone, PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType )
|
||||
|
||||
-- Multiple inheritance ... :-)
|
||||
local AI_Air = AI_AIR:New( AICap )
|
||||
local AI_Air_Patrol = AI_AIR_PATROL:New( AI_Air, AICap, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType ) -- #AI_AIR_PATROL
|
||||
local AI_Air_Engage = AI_AIR_ENGAGE:New( AI_Air_Patrol, AICap, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType )
|
||||
local self = BASE:Inherit( self, AI_Air_Engage )
|
||||
|
||||
self:SetFuelThreshold( .2, 60 )
|
||||
self:SetDamageThreshold( 0.4 )
|
||||
self:SetDisengageRadius( 70000 )
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Creates a new AI_A2A_CAP object
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap
|
||||
@@ -111,174 +143,8 @@ AI_A2A_CAP = {
|
||||
-- @return #AI_A2A_CAP
|
||||
function AI_A2A_CAP:New( AICap, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, EngageMinSpeed, EngageMaxSpeed, PatrolAltType )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, AI_A2A_PATROL:New( AICap, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType ) ) -- #AI_A2A_CAP
|
||||
return self:New2( AICap, EngageMinSpeed, EngageMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolZone, PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType, PatrolAltType )
|
||||
|
||||
self.Accomplished = false
|
||||
self.Engaging = false
|
||||
|
||||
self.EngageMinSpeed = EngageMinSpeed
|
||||
self.EngageMaxSpeed = EngageMaxSpeed
|
||||
|
||||
self:AddTransition( { "Patrolling", "Engaging", "Returning", "Airborne" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_CAP.
|
||||
|
||||
--- OnBefore Transition Handler for Event Engage.
|
||||
-- @function [parent=#AI_A2A_CAP] OnBeforeEngage
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Engage.
|
||||
-- @function [parent=#AI_A2A_CAP] OnAfterEngage
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Engage.
|
||||
-- @function [parent=#AI_A2A_CAP] Engage
|
||||
-- @param #AI_A2A_CAP self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Engage.
|
||||
-- @function [parent=#AI_A2A_CAP] __Engage
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
--- OnLeave Transition Handler for State Engaging.
|
||||
-- @function [parent=#AI_A2A_CAP] OnLeaveEngaging
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnEnter Transition Handler for State Engaging.
|
||||
-- @function [parent=#AI_A2A_CAP] OnEnterEngaging
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_CAP.
|
||||
|
||||
--- OnBefore Transition Handler for Event Fired.
|
||||
-- @function [parent=#AI_A2A_CAP] OnBeforeFired
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Fired.
|
||||
-- @function [parent=#AI_A2A_CAP] OnAfterFired
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Fired.
|
||||
-- @function [parent=#AI_A2A_CAP] Fired
|
||||
-- @param #AI_A2A_CAP self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Fired.
|
||||
-- @function [parent=#AI_A2A_CAP] __Fired
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
self:AddTransition( "*", "Destroy", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_CAP.
|
||||
|
||||
--- OnBefore Transition Handler for Event Destroy.
|
||||
-- @function [parent=#AI_A2A_CAP] OnBeforeDestroy
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Destroy.
|
||||
-- @function [parent=#AI_A2A_CAP] OnAfterDestroy
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Destroy.
|
||||
-- @function [parent=#AI_A2A_CAP] Destroy
|
||||
-- @param #AI_A2A_CAP self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Destroy.
|
||||
-- @function [parent=#AI_A2A_CAP] __Destroy
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
|
||||
self:AddTransition( "Engaging", "Abort", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_CAP.
|
||||
|
||||
--- OnBefore Transition Handler for Event Abort.
|
||||
-- @function [parent=#AI_A2A_CAP] OnBeforeAbort
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Abort.
|
||||
-- @function [parent=#AI_A2A_CAP] OnAfterAbort
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Abort.
|
||||
-- @function [parent=#AI_A2A_CAP] Abort
|
||||
-- @param #AI_A2A_CAP self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Abort.
|
||||
-- @function [parent=#AI_A2A_CAP] __Abort
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
self:AddTransition( "Engaging", "Accomplish", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_CAP.
|
||||
|
||||
--- OnBefore Transition Handler for Event Accomplish.
|
||||
-- @function [parent=#AI_A2A_CAP] OnBeforeAccomplish
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Accomplish.
|
||||
-- @function [parent=#AI_A2A_CAP] OnAfterAccomplish
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Accomplish.
|
||||
-- @function [parent=#AI_A2A_CAP] Accomplish
|
||||
-- @param #AI_A2A_CAP self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Accomplish.
|
||||
-- @function [parent=#AI_A2A_CAP] __Accomplish
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- onafter State Transition for Event Patrol.
|
||||
@@ -289,7 +155,7 @@ end
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_CAP:onafterStart( AICap, From, Event, To )
|
||||
|
||||
self:GetParent( self ).onafterStart( self, AICap, From, Event, To )
|
||||
self:GetParent( self, AI_A2A_CAP ).onafterStart( self, AICap, From, Event, To )
|
||||
AICap:HandleEvent( EVENTS.Takeoff, nil, self )
|
||||
|
||||
end
|
||||
@@ -322,167 +188,27 @@ function AI_A2A_CAP:SetEngageRange( EngageRange )
|
||||
end
|
||||
end
|
||||
|
||||
--- onafter State Transition for Event Patrol.
|
||||
--- Evaluate the attack and create an AttackUnitTask list.
|
||||
-- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The AI Group managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_CAP:onafterPatrol( AICap, From, Event, To )
|
||||
-- @param Core.Set#SET_UNIT AttackSetUnit The set of units to attack.
|
||||
-- @param Wrappper.Group#GROUP DefenderGroup The group of defenders.
|
||||
-- @param #number EngageAltitude The altitude to engage the targets.
|
||||
-- @return #AI_A2A_CAP self
|
||||
function AI_A2A_CAP:CreateAttackUnitTasks( AttackSetUnit, DefenderGroup, EngageAltitude )
|
||||
|
||||
-- Call the parent Start event handler
|
||||
self:GetParent(self).onafterPatrol( self, AICap, From, Event, To )
|
||||
self:HandleEvent( EVENTS.Dead )
|
||||
local AttackUnitTasks = {}
|
||||
|
||||
end
|
||||
|
||||
-- todo: need to fix this global function
|
||||
|
||||
--- @param Wrapper.Group#GROUP AICap
|
||||
function AI_A2A_CAP.AttackRoute( AICap, Fsm )
|
||||
|
||||
AICap:F( { "AI_A2A_CAP.AttackRoute:", AICap:GetName() } )
|
||||
|
||||
if AICap:IsAlive() then
|
||||
Fsm:__Engage( 0.5 )
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_CAP:onbeforeEngage( AICap, From, Event, To )
|
||||
|
||||
if self.Accomplished == true then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The AI Group managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_CAP:onafterAbort( AICap, From, Event, To )
|
||||
AICap:ClearTasks()
|
||||
self:__Route( 0.5 )
|
||||
end
|
||||
|
||||
|
||||
--- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The AICap Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_CAP:onafterEngage( AICap, From, Event, To, AttackSetUnit )
|
||||
|
||||
self:F( { AICap, From, Event, To, AttackSetUnit} )
|
||||
|
||||
self.AttackSetUnit = AttackSetUnit or self.AttackSetUnit -- Core.Set#SET_UNIT
|
||||
|
||||
local FirstAttackUnit = self.AttackSetUnit:GetFirst() -- Wrapper.Unit#UNIT
|
||||
|
||||
if FirstAttackUnit and FirstAttackUnit:IsAlive() then -- If there is no attacker anymore, stop the engagement.
|
||||
|
||||
if AICap:IsAlive() then
|
||||
|
||||
local EngageRoute = {}
|
||||
|
||||
--- Calculate the target route point.
|
||||
local CurrentCoord = AICap:GetCoordinate()
|
||||
local ToTargetCoord = self.AttackSetUnit:GetFirst():GetCoordinate()
|
||||
local ToTargetSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
|
||||
local ToInterceptAngle = CurrentCoord:GetAngleDegrees( CurrentCoord:GetDirectionVec3( ToTargetCoord ) )
|
||||
|
||||
--- Create a route point of type air.
|
||||
local ToPatrolRoutePoint = CurrentCoord:Translate( 5000, ToInterceptAngle ):WaypointAir(
|
||||
self.PatrolAltType,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
ToTargetSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
self:F( { Angle = ToInterceptAngle, ToTargetSpeed = ToTargetSpeed } )
|
||||
self:T2( { self.MinSpeed, self.MaxSpeed, ToTargetSpeed } )
|
||||
|
||||
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
|
||||
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
|
||||
|
||||
local AttackTasks = {}
|
||||
|
||||
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
||||
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
||||
self:T( { "Attacking Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
||||
if AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
||||
AttackTasks[#AttackTasks+1] = AICap:TaskAttackUnit( AttackUnit )
|
||||
end
|
||||
end
|
||||
|
||||
if #AttackTasks == 0 then
|
||||
self:E("No targets found -> Going back to Patrolling")
|
||||
self:__Abort( 0.5 )
|
||||
else
|
||||
AICap:OptionROEOpenFire()
|
||||
AICap:OptionROTEvadeFire()
|
||||
|
||||
AttackTasks[#AttackTasks+1] = AICap:TaskFunction( "AI_A2A_CAP.AttackRoute", self )
|
||||
EngageRoute[#EngageRoute].task = AICap:TaskCombo( AttackTasks )
|
||||
end
|
||||
|
||||
AICap:Route( EngageRoute, 0.5 )
|
||||
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
||||
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
||||
self:T( { "Attacking Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
||||
if AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
||||
-- TODO: Add coalition check? Only attack units of if AttackUnit:GetCoalition()~=AICap:GetCoalition()
|
||||
-- Maybe the detected set also contains
|
||||
self:T( { "Attacking Task:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
||||
AttackUnitTasks[#AttackUnitTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit )
|
||||
end
|
||||
else
|
||||
self:E("No targets found -> Going back to Patrolling")
|
||||
self:__Abort( 0.5 )
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_CAP:onafterAccomplish( AICap, From, Event, To )
|
||||
self.Accomplished = true
|
||||
self:SetDetectionOff()
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_CAP self
|
||||
-- @param Wrapper.Group#GROUP AICap The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_A2A_CAP:onafterDestroy( AICap, From, Event, To, EventData )
|
||||
|
||||
if EventData.IniUnit then
|
||||
self.AttackUnits[EventData.IniUnit] = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_CAP self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_A2A_CAP:OnEventDead( EventData )
|
||||
self:F( { "EventDead", EventData } )
|
||||
|
||||
if EventData.IniDCSUnit then
|
||||
if self.AttackUnits and self.AttackUnits[EventData.IniUnit] then
|
||||
self:__Destroy( 1, EventData )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- @param Wrapper.Group#GROUP AICap
|
||||
function AI_A2A_CAP.Resume( AICap )
|
||||
|
||||
AICap:F( { "AI_A2A_CAP.Resume:", AICap:GetName() } )
|
||||
if AICap:IsAlive() then
|
||||
local _AI_A2A = AICap:GetState( AICap, "AI_A2A" ) -- #AI_A2A
|
||||
_AI_A2A:__Reset( 1 )
|
||||
_AI_A2A:__Route( 5 )
|
||||
end
|
||||
|
||||
return AttackUnitTasks
|
||||
end
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -105,183 +105,39 @@ AI_A2A_GCI = {
|
||||
--- Creates a new AI_A2A_GCI object
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept
|
||||
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude The highest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#AltitudeType EngageAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to "RADIO".
|
||||
-- @return #AI_A2A_GCI
|
||||
function AI_A2A_GCI:New( AIIntercept, EngageMinSpeed, EngageMaxSpeed )
|
||||
function AI_A2A_GCI:New2( AIIntercept, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, AI_A2A:New( AIIntercept ) ) -- #AI_A2A_GCI
|
||||
|
||||
self.Accomplished = false
|
||||
self.Engaging = false
|
||||
local AI_Air = AI_AIR:New( AIIntercept )
|
||||
local AI_Air_Engage = AI_AIR_ENGAGE:New( AI_Air, AIIntercept, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType )
|
||||
local self = BASE:Inherit( self, AI_Air_Engage ) -- #AI_A2A_GCI
|
||||
|
||||
self.EngageMinSpeed = EngageMinSpeed
|
||||
self.EngageMaxSpeed = EngageMaxSpeed
|
||||
self.PatrolMinSpeed = EngageMinSpeed
|
||||
self.PatrolMaxSpeed = EngageMaxSpeed
|
||||
|
||||
self.PatrolAltType = "RADIO"
|
||||
|
||||
self:AddTransition( { "Started", "Engaging", "Returning", "Airborne" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
|
||||
|
||||
--- OnBefore Transition Handler for Event Engage.
|
||||
-- @function [parent=#AI_A2A_GCI] OnBeforeEngage
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Engage.
|
||||
-- @function [parent=#AI_A2A_GCI] OnAfterEngage
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Engage.
|
||||
-- @function [parent=#AI_A2A_GCI] Engage
|
||||
-- @param #AI_A2A_GCI self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Engage.
|
||||
-- @function [parent=#AI_A2A_GCI] __Engage
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
--- OnLeave Transition Handler for State Engaging.
|
||||
-- @function [parent=#AI_A2A_GCI] OnLeaveEngaging
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnEnter Transition Handler for State Engaging.
|
||||
-- @function [parent=#AI_A2A_GCI] OnEnterEngaging
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
|
||||
|
||||
--- OnBefore Transition Handler for Event Fired.
|
||||
-- @function [parent=#AI_A2A_GCI] OnBeforeFired
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Fired.
|
||||
-- @function [parent=#AI_A2A_GCI] OnAfterFired
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Fired.
|
||||
-- @function [parent=#AI_A2A_GCI] Fired
|
||||
-- @param #AI_A2A_GCI self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Fired.
|
||||
-- @function [parent=#AI_A2A_GCI] __Fired
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
self:AddTransition( "*", "Destroy", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
|
||||
|
||||
--- OnBefore Transition Handler for Event Destroy.
|
||||
-- @function [parent=#AI_A2A_GCI] OnBeforeDestroy
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Destroy.
|
||||
-- @function [parent=#AI_A2A_GCI] OnAfterDestroy
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Destroy.
|
||||
-- @function [parent=#AI_A2A_GCI] Destroy
|
||||
-- @param #AI_A2A_GCI self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Destroy.
|
||||
-- @function [parent=#AI_A2A_GCI] __Destroy
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
|
||||
self:AddTransition( "Engaging", "Abort", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
|
||||
|
||||
--- OnBefore Transition Handler for Event Abort.
|
||||
-- @function [parent=#AI_A2A_GCI] OnBeforeAbort
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Abort.
|
||||
-- @function [parent=#AI_A2A_GCI] OnAfterAbort
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Abort.
|
||||
-- @function [parent=#AI_A2A_GCI] Abort
|
||||
-- @param #AI_A2A_GCI self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Abort.
|
||||
-- @function [parent=#AI_A2A_GCI] __Abort
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
self:AddTransition( "Engaging", "Accomplish", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
|
||||
|
||||
--- OnBefore Transition Handler for Event Accomplish.
|
||||
-- @function [parent=#AI_A2A_GCI] OnBeforeAccomplish
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Accomplish.
|
||||
-- @function [parent=#AI_A2A_GCI] OnAfterAccomplish
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Accomplish.
|
||||
-- @function [parent=#AI_A2A_GCI] Accomplish
|
||||
-- @param #AI_A2A_GCI self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Accomplish.
|
||||
-- @function [parent=#AI_A2A_GCI] __Accomplish
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
self:SetFuelThreshold( .2, 60 )
|
||||
self:SetDamageThreshold( 0.4 )
|
||||
self:SetDisengageRadius( 70000 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Creates a new AI_A2A_GCI object
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept
|
||||
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude The highest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#AltitudeType EngageAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to "RADIO".
|
||||
-- @return #AI_A2A_GCI
|
||||
function AI_A2A_GCI:New( AIIntercept, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType )
|
||||
|
||||
return self:New2( AIIntercept, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType )
|
||||
end
|
||||
|
||||
--- onafter State Transition for Event Patrol.
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The AI Group managed by the FSM.
|
||||
@@ -290,173 +146,33 @@ end
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_GCI:onafterStart( AIIntercept, From, Event, To )
|
||||
|
||||
self:GetParent( self ).onafterStart( self, AIIntercept, From, Event, To )
|
||||
AIIntercept:HandleEvent( EVENTS.Takeoff, nil, self )
|
||||
|
||||
self:GetParent( self, AI_A2A_GCI ).onafterStart( self, AIIntercept, From, Event, To )
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- onafter State Transition for Event Patrol.
|
||||
--- Evaluate the attack and create an AttackUnitTask list.
|
||||
-- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The AI Group managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_GCI:onafterEngage( AIIntercept, From, Event, To )
|
||||
-- @param Core.Set#SET_UNIT AttackSetUnit The set of units to attack.
|
||||
-- @param Wrappper.Group#GROUP DefenderGroup The group of defenders.
|
||||
-- @param #number EngageAltitude The altitude to engage the targets.
|
||||
-- @return #AI_A2A_GCI self
|
||||
function AI_A2A_GCI:CreateAttackUnitTasks( AttackSetUnit, DefenderGroup, EngageAltitude )
|
||||
|
||||
self:HandleEvent( EVENTS.Dead )
|
||||
local AttackUnitTasks = {}
|
||||
|
||||
end
|
||||
|
||||
-- todo: need to fix this global function
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIControllable
|
||||
function AI_A2A_GCI.InterceptRoute( AIIntercept, Fsm )
|
||||
|
||||
AIIntercept:F( { "AI_A2A_GCI.InterceptRoute:", AIIntercept:GetName() } )
|
||||
|
||||
if AIIntercept:IsAlive() then
|
||||
Fsm:__Engage( 0.5 )
|
||||
|
||||
--local Task = AIIntercept:TaskOrbitCircle( 4000, 400 )
|
||||
--AIIntercept:SetTask( Task )
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_GCI:onbeforeEngage( AIIntercept, From, Event, To )
|
||||
|
||||
if self.Accomplished == true then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The AI Group managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_GCI:onafterAbort( AIIntercept, From, Event, To )
|
||||
AIIntercept:ClearTasks()
|
||||
self:Return()
|
||||
self:__RTB( 0.5 )
|
||||
end
|
||||
|
||||
|
||||
--- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The GroupGroup managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_GCI:onafterEngage( AIIntercept, From, Event, To, AttackSetUnit )
|
||||
|
||||
self:F( { AIIntercept, From, Event, To, AttackSetUnit} )
|
||||
|
||||
self.AttackSetUnit = AttackSetUnit or self.AttackSetUnit -- Core.Set#SET_UNIT
|
||||
|
||||
local FirstAttackUnit = self.AttackSetUnit:GetFirst()
|
||||
|
||||
if FirstAttackUnit and FirstAttackUnit:IsAlive() then
|
||||
|
||||
if AIIntercept:IsAlive() then
|
||||
|
||||
local EngageRoute = {}
|
||||
|
||||
local CurrentCoord = AIIntercept:GetCoordinate()
|
||||
|
||||
--- Calculate the target route point.
|
||||
|
||||
local CurrentCoord = AIIntercept:GetCoordinate()
|
||||
|
||||
local ToTargetCoord = self.AttackSetUnit:GetFirst():GetCoordinate()
|
||||
self:SetTargetDistance( ToTargetCoord ) -- For RTB status check
|
||||
|
||||
local ToTargetSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
|
||||
local ToInterceptAngle = CurrentCoord:GetAngleDegrees( CurrentCoord:GetDirectionVec3( ToTargetCoord ) )
|
||||
|
||||
--- Create a route point of type air.
|
||||
local ToPatrolRoutePoint = CurrentCoord:Translate( 15000, ToInterceptAngle ):WaypointAir(
|
||||
self.PatrolAltType,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
ToTargetSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
self:F( { Angle = ToInterceptAngle, ToTargetSpeed = ToTargetSpeed } )
|
||||
self:F( { self.EngageMinSpeed, self.EngageMaxSpeed, ToTargetSpeed } )
|
||||
|
||||
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
|
||||
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
|
||||
|
||||
local AttackTasks = {}
|
||||
|
||||
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
||||
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
||||
if AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
||||
self:T( { "Intercepting Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
||||
AttackTasks[#AttackTasks+1] = AIIntercept:TaskAttackUnit( AttackUnit )
|
||||
end
|
||||
end
|
||||
|
||||
if #AttackTasks == 0 then
|
||||
self:E("No targets found -> Going RTB")
|
||||
self:Return()
|
||||
self:__RTB( 0.5 )
|
||||
else
|
||||
AIIntercept:OptionROEOpenFire()
|
||||
AIIntercept:OptionROTEvadeFire()
|
||||
|
||||
AttackTasks[#AttackTasks+1] = AIIntercept:TaskFunction( "AI_A2A_GCI.InterceptRoute", self )
|
||||
EngageRoute[#EngageRoute].task = AIIntercept:TaskCombo( AttackTasks )
|
||||
end
|
||||
|
||||
AIIntercept:Route( EngageRoute, 0.5 )
|
||||
|
||||
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
||||
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
||||
self:T( { "Attacking Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
||||
if AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
||||
-- TODO: Add coalition check? Only attack units of if AttackUnit:GetCoalition()~=AICap:GetCoalition()
|
||||
-- Maybe the detected set also contains
|
||||
AttackUnitTasks[#AttackUnitTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit )
|
||||
end
|
||||
else
|
||||
self:E("No targets found -> Going RTB")
|
||||
self:Return()
|
||||
self:__RTB( 0.5 )
|
||||
end
|
||||
|
||||
return AttackUnitTasks
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A_GCI:onafterAccomplish( AIIntercept, From, Event, To )
|
||||
self.Accomplished = true
|
||||
self:SetDetectionOff()
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_GCI self
|
||||
-- @param Wrapper.Group#GROUP AIIntercept The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_A2A_GCI:onafterDestroy( AIIntercept, From, Event, To, EventData )
|
||||
|
||||
if EventData.IniUnit then
|
||||
self.AttackUnits[EventData.IniUnit] = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_A2A_GCI self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_A2A_GCI:OnEventDead( EventData )
|
||||
self:F( { "EventDead", EventData } )
|
||||
|
||||
if EventData.IniDCSUnit then
|
||||
if self.AttackUnits and self.AttackUnits[EventData.IniUnit] then
|
||||
self:__Destroy( 1, EventData )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,8 +136,14 @@ AI_A2A_PATROL = {
|
||||
-- PatrolArea = AI_A2A_PATROL:New( PatrolZone, 3000, 6000, 600, 900 )
|
||||
function AI_A2A_PATROL:New( AIPatrol, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, AI_A2A:New( AIPatrol ) ) -- #AI_A2A_PATROL
|
||||
local AI_Air = AI_AIR:New( AIPatrol )
|
||||
local AI_Air_Patrol = AI_A2A_PATROL:New( AI_Air, AIPatrol, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
local self = BASE:Inherit( self, AI_Air_Patrol ) -- #AI_A2A_PATROL
|
||||
|
||||
self:SetFuelThreshold( .2, 60 )
|
||||
self:SetDamageThreshold( 0.4 )
|
||||
self:SetDisengageRadius( 70000 )
|
||||
|
||||
|
||||
self.PatrolZone = PatrolZone
|
||||
self.PatrolFloorAltitude = PatrolFloorAltitude
|
||||
@@ -312,7 +318,7 @@ function AI_A2A_PATROL:onafterRoute( AIPatrol, From, Event, To )
|
||||
end
|
||||
|
||||
|
||||
if AIPatrol:IsAlive() then
|
||||
if AIPatrol and AIPatrol:IsAlive() then
|
||||
|
||||
local PatrolRoute = {}
|
||||
|
||||
@@ -320,44 +326,80 @@ function AI_A2A_PATROL:onafterRoute( AIPatrol, From, Event, To )
|
||||
|
||||
local CurrentCoord = AIPatrol:GetCoordinate()
|
||||
|
||||
local ToTargetCoord = self.PatrolZone:GetRandomPointVec2()
|
||||
ToTargetCoord:SetAlt( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ) )
|
||||
self:SetTargetDistance( ToTargetCoord ) -- For RTB status check
|
||||
-- Random altitude.
|
||||
local altitude=math.random(self.PatrolFloorAltitude, self.PatrolCeilingAltitude)
|
||||
|
||||
-- Random speed in km/h.
|
||||
local speedkmh = math.random(self.PatrolMinSpeed, self.PatrolMaxSpeed)
|
||||
|
||||
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
|
||||
-- First waypoint is current position.
|
||||
PatrolRoute[1]=CurrentCoord:WaypointAirTurningPoint(nil, speedkmh, {}, "Current")
|
||||
|
||||
--- Create a route point of type air.
|
||||
local ToPatrolRoutePoint = ToTargetCoord:WaypointAir(
|
||||
self.PatrolAltType,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
ToTargetSpeed,
|
||||
true
|
||||
)
|
||||
if self.racetrack then
|
||||
|
||||
-- Random heading.
|
||||
local heading = math.random(self.racetrackheadingmin, self.racetrackheadingmax)
|
||||
|
||||
-- Random leg length.
|
||||
local leg=math.random(self.racetracklegmin, self.racetracklegmax)
|
||||
|
||||
-- Random duration if any.
|
||||
local duration = self.racetrackdurationmin
|
||||
if self.racetrackdurationmax then
|
||||
duration=math.random(self.racetrackdurationmin, self.racetrackdurationmax)
|
||||
end
|
||||
|
||||
-- CAP coordinate.
|
||||
local c0=self.PatrolZone:GetRandomCoordinate()
|
||||
if self.racetrackcapcoordinates and #self.racetrackcapcoordinates>0 then
|
||||
c0=self.racetrackcapcoordinates[math.random(#self.racetrackcapcoordinates)]
|
||||
end
|
||||
|
||||
-- Race track points.
|
||||
local c1=c0:SetAltitude(altitude) --Core.Point#COORDINATE
|
||||
local c2=c1:Translate(leg, heading):SetAltitude(altitude)
|
||||
|
||||
self:SetTargetDistance(c0) -- For RTB status check
|
||||
|
||||
-- Debug:
|
||||
self:T(string.format("Patrol zone race track: v=%.1f knots, h=%.1f ft, heading=%03d, leg=%d m, t=%s sec", UTILS.KmphToKnots(speedkmh), UTILS.MetersToFeet(altitude), heading, leg, tostring(duration)))
|
||||
--c1:MarkToAll("Race track c1")
|
||||
--c2:MarkToAll("Race track c2")
|
||||
|
||||
PatrolRoute[#PatrolRoute+1] = ToPatrolRoutePoint
|
||||
PatrolRoute[#PatrolRoute+1] = ToPatrolRoutePoint
|
||||
|
||||
local Tasks = {}
|
||||
Tasks[#Tasks+1] = AIPatrol:TaskFunction( "AI_A2A_PATROL.PatrolRoute", self )
|
||||
PatrolRoute[#PatrolRoute].task = AIPatrol:TaskCombo( Tasks )
|
||||
|
||||
-- Task to orbit.
|
||||
local taskOrbit=AIPatrol:TaskOrbit(c1, altitude, UTILS.KmphToMps(speedkmh), c2)
|
||||
|
||||
-- Task function to redo the patrol at other random position.
|
||||
local taskPatrol=AIPatrol:TaskFunction("AI_A2A_PATROL.PatrolRoute", self)
|
||||
|
||||
-- Controlled task with task condition.
|
||||
local taskCond=AIPatrol:TaskCondition(nil, nil, nil, nil, duration, nil)
|
||||
local taskCont=AIPatrol:TaskControlled(taskOrbit, taskCond)
|
||||
|
||||
-- Second waypoint
|
||||
PatrolRoute[2]=c1:WaypointAirTurningPoint(self.PatrolAltType, speedkmh, {taskCont, taskPatrol}, "CAP Orbit")
|
||||
|
||||
else
|
||||
|
||||
-- Target coordinate.
|
||||
local ToTargetCoord=self.PatrolZone:GetRandomCoordinate() --Core.Point#COORDINATE
|
||||
ToTargetCoord:SetAltitude(altitude)
|
||||
|
||||
self:SetTargetDistance( ToTargetCoord ) -- For RTB status check
|
||||
|
||||
local taskReRoute=AIPatrol:TaskFunction( "AI_A2A_PATROL.PatrolRoute", self )
|
||||
|
||||
PatrolRoute[2]=ToTargetCoord:WaypointAirTurningPoint(self.PatrolAltType, speedkmh, {taskReRoute}, "Patrol Point")
|
||||
|
||||
end
|
||||
|
||||
-- ROE
|
||||
AIPatrol:OptionROEReturnFire()
|
||||
AIPatrol:OptionROTEvadeFire()
|
||||
|
||||
AIPatrol:Route( PatrolRoute, 0.5 )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIPatrol
|
||||
function AI_A2A_PATROL.Resume( AIPatrol )
|
||||
|
||||
AIPatrol:F( { "AI_A2A_PATROL.Resume:", AIPatrol:GetName() } )
|
||||
if AIPatrol:IsAlive() then
|
||||
local _AI_A2A = AIPatrol:GetState( AIPatrol, "AI_A2A" ) -- AI.AI_A2A#AI_A2A
|
||||
_AI_A2A:__Reset( 1 )
|
||||
_AI_A2A:__Route( 5 )
|
||||
end
|
||||
|
||||
-- Patrol.
|
||||
AIPatrol:Route( PatrolRoute, 0.5)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
99
Moose Development/Moose/AI/AI_A2G_BAI.lua
Normal file
99
Moose Development/Moose/AI/AI_A2G_BAI.lua
Normal file
@@ -0,0 +1,99 @@
|
||||
--- **AI** -- Models the process of air to ground BAI engagement for airplanes and helicopters.
|
||||
--
|
||||
-- This is a class used in the @{AI_A2G_Dispatcher}.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_A2G_BAI
|
||||
-- @image AI_Air_To_Ground_Engage.JPG
|
||||
|
||||
|
||||
|
||||
--- @type AI_A2G_BAI
|
||||
-- @extends AI.AI_A2A_Engage#AI_A2A_Engage
|
||||
|
||||
|
||||
--- Implements the core functions to intercept intruders. Use the Engage trigger to intercept intruders.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @field #AI_A2G_BAI
|
||||
AI_A2G_BAI = {
|
||||
ClassName = "AI_A2G_BAI",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Creates a new AI_A2G_BAI object
|
||||
-- @param #AI_A2G_BAI self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude The highest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#AltitudeType EngageAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to "RADIO".
|
||||
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
|
||||
-- @return #AI_A2G_BAI
|
||||
function AI_A2G_BAI:New2( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
|
||||
local AI_Air = AI_AIR:New( AIGroup )
|
||||
local AI_Air_Patrol = AI_AIR_PATROL:New( AI_Air, AIGroup, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType ) -- #AI_AIR_PATROL
|
||||
local AI_Air_Engage = AI_AIR_ENGAGE:New( AI_Air_Patrol, AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType )
|
||||
local self = BASE:Inherit( self, AI_Air_Engage )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Creates a new AI_A2G_BAI object
|
||||
-- @param #AI_A2G_BAI self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude The highest altitude in meters where to execute the engagement.
|
||||
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
|
||||
-- @return #AI_A2G_BAI
|
||||
function AI_A2G_BAI:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
|
||||
return self:New2( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, PatrolAltType, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType)
|
||||
end
|
||||
|
||||
--- Evaluate the attack and create an AttackUnitTask list.
|
||||
-- @param #AI_A2G_BAI self
|
||||
-- @param Core.Set#SET_UNIT AttackSetUnit The set of units to attack.
|
||||
-- @param Wrappper.Group#GROUP DefenderGroup The group of defenders.
|
||||
-- @param #number EngageAltitude The altitude to engage the targets.
|
||||
-- @return #AI_A2G_BAI self
|
||||
function AI_A2G_BAI:CreateAttackUnitTasks( AttackSetUnit, DefenderGroup, EngageAltitude )
|
||||
|
||||
local AttackUnitTasks = {}
|
||||
|
||||
local AttackSetUnitPerThreatLevel = AttackSetUnit:GetSetPerThreatLevel( 10, 0 )
|
||||
for AttackUnitIndex, AttackUnit in ipairs( AttackSetUnitPerThreatLevel or {} ) do
|
||||
if AttackUnit then
|
||||
if AttackUnit:IsAlive() and AttackUnit:IsGround() then
|
||||
self:T( { "BAI Unit:", AttackUnit:GetName() } )
|
||||
AttackUnitTasks[#AttackUnitTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit, true, false, nil, nil, EngageAltitude )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return AttackUnitTasks
|
||||
end
|
||||
|
||||
|
||||
100
Moose Development/Moose/AI/AI_A2G_CAS.lua
Normal file
100
Moose Development/Moose/AI/AI_A2G_CAS.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
--- **AI** -- Models the process of air to ground engagement for airplanes and helicopters.
|
||||
--
|
||||
-- This is a class used in the @{AI_A2G_Dispatcher}.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_A2G_CAS
|
||||
-- @image AI_Air_To_Ground_Engage.JPG
|
||||
|
||||
|
||||
|
||||
--- @type AI_A2G_CAS
|
||||
-- @extends AI.AI_A2G_Patrol#AI_AIR_PATROL
|
||||
|
||||
|
||||
--- Implements the core functions to intercept intruders. Use the Engage trigger to intercept intruders.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @field #AI_A2G_CAS
|
||||
AI_A2G_CAS = {
|
||||
ClassName = "AI_A2G_CAS",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Creates a new AI_A2G_CAS object
|
||||
-- @param #AI_A2G_CAS self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude The highest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#AltitudeType EngageAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to "RADIO".
|
||||
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
|
||||
-- @return #AI_A2G_CAS
|
||||
function AI_A2G_CAS:New2( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
|
||||
local AI_Air = AI_AIR:New( AIGroup )
|
||||
local AI_Air_Patrol = AI_AIR_PATROL:New( AI_Air, AIGroup, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType ) -- #AI_AIR_PATROL
|
||||
local AI_Air_Engage = AI_AIR_ENGAGE:New( AI_Air_Patrol, AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType )
|
||||
local self = BASE:Inherit( self, AI_Air_Engage )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Creates a new AI_A2G_CAS object
|
||||
-- @param #AI_A2G_CAS self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude The highest altitude in meters where to execute the engagement.
|
||||
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
|
||||
-- @return #AI_A2G_CAS
|
||||
function AI_A2G_CAS:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
|
||||
return self:New2( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, PatrolAltType, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType)
|
||||
end
|
||||
|
||||
--- Evaluate the attack and create an AttackUnitTask list.
|
||||
-- @param #AI_A2G_CAS self
|
||||
-- @param Core.Set#SET_UNIT AttackSetUnit The set of units to attack.
|
||||
-- @param Wrappper.Group#GROUP DefenderGroup The group of defenders.
|
||||
-- @param #number EngageAltitude The altitude to engage the targets.
|
||||
-- @return #AI_A2G_CAS self
|
||||
function AI_A2G_CAS:CreateAttackUnitTasks( AttackSetUnit, DefenderGroup, EngageAltitude )
|
||||
|
||||
local AttackUnitTasks = {}
|
||||
|
||||
local AttackSetUnitPerThreatLevel = AttackSetUnit:GetSetPerThreatLevel( 10, 0 )
|
||||
for AttackUnitIndex, AttackUnit in ipairs( AttackSetUnitPerThreatLevel or {} ) do
|
||||
if AttackUnit then
|
||||
if AttackUnit:IsAlive() and AttackUnit:IsGround() then
|
||||
self:T( { "CAS Unit:", AttackUnit:GetName() } )
|
||||
AttackUnitTasks[#AttackUnitTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit, true, false, nil, nil, EngageAltitude )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return AttackUnitTasks
|
||||
end
|
||||
|
||||
|
||||
|
||||
4711
Moose Development/Moose/AI/AI_A2G_Dispatcher.lua
Normal file
4711
Moose Development/Moose/AI/AI_A2G_Dispatcher.lua
Normal file
File diff suppressed because it is too large
Load Diff
152
Moose Development/Moose/AI/AI_A2G_SEAD.lua
Normal file
152
Moose Development/Moose/AI/AI_A2G_SEAD.lua
Normal file
@@ -0,0 +1,152 @@
|
||||
--- **AI** -- Models the process of air to ground SEAD engagement for airplanes and helicopters.
|
||||
--
|
||||
-- This is a class used in the @{AI_A2G_Dispatcher}.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_A2G_SEAD
|
||||
-- @image AI_Air_To_Ground_Engage.JPG
|
||||
|
||||
|
||||
|
||||
--- @type AI_A2G_SEAD
|
||||
-- @extends AI.AI_A2G_Patrol#AI_AIR_PATROL
|
||||
|
||||
|
||||
--- Implements the core functions to SEAD intruders. Use the Engage trigger to intercept intruders.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- The AI_A2G_SEAD is assigned a @{Wrapper.Group} and this must be done before the AI_A2G_SEAD process can be started using the **Start** event.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- The AI will fly towards the random 3D point within the patrol zone, using a random speed within the given altitude and speed limits.
|
||||
-- Upon arrival at the 3D point, a new random 3D point will be selected within the patrol zone using the given limits.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- This cycle will continue.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- During the patrol, the AI will detect enemy targets, which are reported through the **Detected** event.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- When enemies are detected, the AI will automatically engage the enemy.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- Until a fuel or damage treshold has been reached by the AI, or when the AI is commanded to RTB.
|
||||
-- When the fuel treshold has been reached, the airplane will fly towards the nearest friendly airbase and will land.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- ## 1. AI_A2G_SEAD constructor
|
||||
--
|
||||
-- * @{#AI_A2G_SEAD.New}(): Creates a new AI_A2G_SEAD object.
|
||||
--
|
||||
-- ## 3. Set the Range of Engagement
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- An optional range can be set in meters,
|
||||
-- that will define when the AI will engage with the detected airborne enemy targets.
|
||||
-- The range can be beyond or smaller than the range of the Patrol Zone.
|
||||
-- The range is applied at the position of the AI.
|
||||
-- Use the method @{AI.AI_GCI#AI_A2G_SEAD.SetEngageRange}() to define that range.
|
||||
--
|
||||
-- ## 4. Set the Zone of Engagement
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- An optional @{Zone} can be set,
|
||||
-- that will define when the AI will engage with the detected airborne enemy targets.
|
||||
-- Use the method @{AI.AI_Cap#AI_A2G_SEAD.SetEngageZone}() to define that Zone.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @field #AI_A2G_SEAD
|
||||
AI_A2G_SEAD = {
|
||||
ClassName = "AI_A2G_SEAD",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Creates a new AI_A2G_SEAD object
|
||||
-- @param #AI_A2G_SEAD self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude The highest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#AltitudeType EngageAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to "RADIO".
|
||||
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
|
||||
-- @return #AI_A2G_SEAD
|
||||
function AI_A2G_SEAD:New2( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
|
||||
local AI_Air = AI_AIR:New( AIGroup )
|
||||
local AI_Air_Patrol = AI_AIR_PATROL:New( AI_Air, AIGroup, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType ) -- #AI_AIR_PATROL
|
||||
local AI_Air_Engage = AI_AIR_ENGAGE:New( AI_Air_Patrol, AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType )
|
||||
local self = BASE:Inherit( self, AI_Air_Engage )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Creates a new AI_A2G_SEAD object
|
||||
-- @param #AI_A2G_SEAD self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude The highest altitude in meters where to execute the engagement.
|
||||
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
|
||||
-- @return #AI_A2G_SEAD
|
||||
function AI_A2G_SEAD:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
|
||||
return self:New2( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, PatrolAltType, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
end
|
||||
|
||||
|
||||
--- Evaluate the attack and create an AttackUnitTask list.
|
||||
-- @param #AI_A2G_SEAD self
|
||||
-- @param Core.Set#SET_UNIT AttackSetUnit The set of units to attack.
|
||||
-- @param Wrappper.Group#GROUP DefenderGroup The group of defenders.
|
||||
-- @param #number EngageAltitude The altitude to engage the targets.
|
||||
-- @return #AI_A2G_SEAD self
|
||||
function AI_A2G_SEAD:CreateAttackUnitTasks( AttackSetUnit, DefenderGroup, EngageAltitude )
|
||||
|
||||
local AttackUnitTasks = {}
|
||||
|
||||
local AttackSetUnitPerThreatLevel = AttackSetUnit:GetSetPerThreatLevel( 10, 0 )
|
||||
for AttackUnitID, AttackUnit in ipairs( AttackSetUnitPerThreatLevel ) do
|
||||
if AttackUnit then
|
||||
if AttackUnit:IsAlive() and AttackUnit:IsGround() then
|
||||
local HasRadar = AttackUnit:HasSEAD()
|
||||
if HasRadar then
|
||||
self:F( { "SEAD Unit:", AttackUnit:GetName() } )
|
||||
AttackUnitTasks[#AttackUnitTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit, true, false, nil, nil, EngageAltitude )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return AttackUnitTasks
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--- **AI** -- (R2.2) - Models the process of air operations for airplanes.
|
||||
--- **AI** -- Models the process of AI air operations.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
@@ -6,102 +6,99 @@
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_A2A
|
||||
-- @image AI_Air_To_Air_Dispatching.JPG
|
||||
-- @module AI.AI_Air
|
||||
-- @image MOOSE.JPG
|
||||
|
||||
--BASE:TraceClass("AI_A2A")
|
||||
|
||||
|
||||
--- @type AI_A2A
|
||||
--- @type AI_AIR
|
||||
-- @extends Core.Fsm#FSM_CONTROLLABLE
|
||||
|
||||
--- The AI_A2A class implements the core functions to operate an AI @{Wrapper.Group} A2A tasking.
|
||||
--- The AI_AIR class implements the core functions to operate an AI @{Wrapper.Group}.
|
||||
--
|
||||
--
|
||||
-- ## AI_A2A constructor
|
||||
-- # 1) AI_AIR constructor
|
||||
--
|
||||
-- * @{#AI_A2A.New}(): Creates a new AI_A2A object.
|
||||
-- * @{#AI_AIR.New}(): Creates a new AI_AIR object.
|
||||
--
|
||||
-- ## 2. AI_A2A is a FSM
|
||||
-- # 2) AI_AIR is a Finite State Machine.
|
||||
--
|
||||
-- 
|
||||
-- This section must be read as follows. Each of the rows indicate a state transition, triggered through an event, and with an ending state of the event was executed.
|
||||
-- The first column is the **From** state, the second column the **Event**, and the third column the **To** state.
|
||||
--
|
||||
-- ### 2.1. AI_A2A States
|
||||
-- So, each of the rows have the following structure.
|
||||
--
|
||||
-- * **None** ( Group ): The process is not started yet.
|
||||
-- * **Patrolling** ( Group ): The AI is patrolling the Patrol Zone.
|
||||
-- * **Returning** ( Group ): The AI is returning to Base.
|
||||
-- * **Stopped** ( Group ): The process is stopped.
|
||||
-- * **Crashed** ( Group ): The AI has crashed or is dead.
|
||||
-- * **From** => **Event** => **To**
|
||||
--
|
||||
-- ### 2.2. AI_A2A Events
|
||||
-- Important to know is that an event can only be executed if the **current state** is the **From** state.
|
||||
-- This, when an **Event** that is being triggered has a **From** state that is equal to the **Current** state of the state machine, the event will be executed,
|
||||
-- and the resulting state will be the **To** state.
|
||||
--
|
||||
-- * **Start** ( Group ): Start the process.
|
||||
-- * **Stop** ( Group ): Stop the process.
|
||||
-- * **Route** ( Group ): Route the AI to a new random 3D point within the Patrol Zone.
|
||||
-- * **RTB** ( Group ): Route the AI to the home base.
|
||||
-- * **Detect** ( Group ): The AI is detecting targets.
|
||||
-- * **Detected** ( Group ): The AI has detected new targets.
|
||||
-- * **Status** ( Group ): The AI is checking status (fuel and damage). When the tresholds have been reached, the AI will RTB.
|
||||
--
|
||||
-- ## 3. Set or Get the AI controllable
|
||||
-- These are the different possible state transitions of this state machine implementation:
|
||||
--
|
||||
-- * @{#AI_A2A.SetControllable}(): Set the AIControllable.
|
||||
-- * @{#AI_A2A.GetControllable}(): Get the AIControllable.
|
||||
-- * Idle => Start => Monitoring
|
||||
--
|
||||
-- @field #AI_A2A
|
||||
AI_A2A = {
|
||||
ClassName = "AI_A2A",
|
||||
-- ## 2.1) AI_AIR States.
|
||||
--
|
||||
-- * **Idle**: The process is idle.
|
||||
--
|
||||
-- ## 2.2) AI_AIR Events.
|
||||
--
|
||||
-- * **Start**: Start the transport process.
|
||||
-- * **Stop**: Stop the transport process.
|
||||
-- * **Monitor**: Monitor and take action.
|
||||
--
|
||||
-- @field #AI_AIR
|
||||
AI_AIR = {
|
||||
ClassName = "AI_AIR",
|
||||
}
|
||||
|
||||
--- Creates a new AI_A2A object
|
||||
-- @param #AI_A2A self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The GROUP object to receive the A2A Process.
|
||||
-- @return #AI_A2A
|
||||
function AI_A2A:New( AIGroup )
|
||||
AI_AIR.TaskDelay = 0.5 -- The delay of each task given to the AI.
|
||||
|
||||
--- Creates a new AI_AIR process.
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The group object to receive the A2G Process.
|
||||
-- @return #AI_AIR
|
||||
function AI_AIR:New( AIGroup )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- #AI_A2A
|
||||
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- #AI_AIR
|
||||
|
||||
self:SetControllable( AIGroup )
|
||||
|
||||
self:SetFuelThreshold( .2, 60 )
|
||||
self:SetDamageThreshold( 0.4 )
|
||||
self:SetDisengageRadius( 70000 )
|
||||
|
||||
self:SetStartState( "Stopped" )
|
||||
|
||||
|
||||
self:AddTransition( "*", "Queue", "Queued" )
|
||||
|
||||
self:AddTransition( "*", "Start", "Started" )
|
||||
|
||||
--- Start Handler OnBefore for AI_A2A
|
||||
-- @function [parent=#AI_A2A] OnBeforeStart
|
||||
-- @param #AI_A2A self
|
||||
--- Start Handler OnBefore for AI_AIR
|
||||
-- @function [parent=#AI_AIR] OnBeforeStart
|
||||
-- @param #AI_AIR self
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
-- @return #boolean
|
||||
|
||||
--- Start Handler OnAfter for AI_A2A
|
||||
-- @function [parent=#AI_A2A] OnAfterStart
|
||||
-- @param #AI_A2A self
|
||||
--- Start Handler OnAfter for AI_AIR
|
||||
-- @function [parent=#AI_AIR] OnAfterStart
|
||||
-- @param #AI_AIR self
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
|
||||
--- Start Trigger for AI_A2A
|
||||
-- @function [parent=#AI_A2A] Start
|
||||
-- @param #AI_A2A self
|
||||
--- Start Trigger for AI_AIR
|
||||
-- @function [parent=#AI_AIR] Start
|
||||
-- @param #AI_AIR self
|
||||
|
||||
--- Start Asynchronous Trigger for AI_A2A
|
||||
-- @function [parent=#AI_A2A] __Start
|
||||
-- @param #AI_A2A self
|
||||
--- Start Asynchronous Trigger for AI_AIR
|
||||
-- @function [parent=#AI_AIR] __Start
|
||||
-- @param #AI_AIR self
|
||||
-- @param #number Delay
|
||||
|
||||
self:AddTransition( "*", "Stop", "Stopped" )
|
||||
|
||||
--- OnLeave Transition Handler for State Stopped.
|
||||
-- @function [parent=#AI_A2A] OnLeaveStopped
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnLeaveStopped
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
@@ -109,16 +106,16 @@ function AI_A2A:New( AIGroup )
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnEnter Transition Handler for State Stopped.
|
||||
-- @function [parent=#AI_A2A] OnEnterStopped
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnEnterStopped
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- OnBefore Transition Handler for Event Stop.
|
||||
-- @function [parent=#AI_A2A] OnBeforeStop
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnBeforeStop
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
@@ -126,27 +123,27 @@ function AI_A2A:New( AIGroup )
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Stop.
|
||||
-- @function [parent=#AI_A2A] OnAfterStop
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnAfterStop
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Stop.
|
||||
-- @function [parent=#AI_A2A] Stop
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] Stop
|
||||
-- @param #AI_AIR self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Stop.
|
||||
-- @function [parent=#AI_A2A] __Stop
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] __Stop
|
||||
-- @param #AI_AIR self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
self:AddTransition( "*", "Status", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A.
|
||||
self:AddTransition( "*", "Status", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR.
|
||||
|
||||
--- OnBefore Transition Handler for Event Status.
|
||||
-- @function [parent=#AI_A2A] OnBeforeStatus
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnBeforeStatus
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
@@ -154,27 +151,27 @@ function AI_A2A:New( AIGroup )
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Status.
|
||||
-- @function [parent=#AI_A2A] OnAfterStatus
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnAfterStatus
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Status.
|
||||
-- @function [parent=#AI_A2A] Status
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] Status
|
||||
-- @param #AI_AIR self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Status.
|
||||
-- @function [parent=#AI_A2A] __Status
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] __Status
|
||||
-- @param #AI_AIR self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
self:AddTransition( "*", "RTB", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A.
|
||||
self:AddTransition( "*", "RTB", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR.
|
||||
|
||||
--- OnBefore Transition Handler for Event RTB.
|
||||
-- @function [parent=#AI_A2A] OnBeforeRTB
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnBeforeRTB
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
@@ -182,25 +179,25 @@ function AI_A2A:New( AIGroup )
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event RTB.
|
||||
-- @function [parent=#AI_A2A] OnAfterRTB
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnAfterRTB
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event RTB.
|
||||
-- @function [parent=#AI_A2A] RTB
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] RTB
|
||||
-- @param #AI_AIR self
|
||||
|
||||
--- Asynchronous Event Trigger for Event RTB.
|
||||
-- @function [parent=#AI_A2A] __RTB
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] __RTB
|
||||
-- @param #AI_AIR self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
--- OnLeave Transition Handler for State Returning.
|
||||
-- @function [parent=#AI_A2A] OnLeaveReturning
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnLeaveReturning
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
@@ -208,8 +205,8 @@ function AI_A2A:New( AIGroup )
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnEnter Transition Handler for State Returning.
|
||||
-- @function [parent=#AI_A2A] OnEnterReturning
|
||||
-- @param #AI_A2A self
|
||||
-- @function [parent=#AI_AIR] OnEnterReturning
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
@@ -217,30 +214,30 @@ function AI_A2A:New( AIGroup )
|
||||
|
||||
self:AddTransition( "Patrolling", "Refuel", "Refuelling" )
|
||||
|
||||
--- Refuel Handler OnBefore for AI_A2A
|
||||
-- @function [parent=#AI_A2A] OnBeforeRefuel
|
||||
-- @param #AI_A2A self
|
||||
--- Refuel Handler OnBefore for AI_AIR
|
||||
-- @function [parent=#AI_AIR] OnBeforeRefuel
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
-- @return #boolean
|
||||
|
||||
--- Refuel Handler OnAfter for AI_A2A
|
||||
-- @function [parent=#AI_A2A] OnAfterRefuel
|
||||
-- @param #AI_A2A self
|
||||
--- Refuel Handler OnAfter for AI_AIR
|
||||
-- @function [parent=#AI_AIR] OnAfterRefuel
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
|
||||
--- Refuel Trigger for AI_A2A
|
||||
-- @function [parent=#AI_A2A] Refuel
|
||||
-- @param #AI_A2A self
|
||||
--- Refuel Trigger for AI_AIR
|
||||
-- @function [parent=#AI_AIR] Refuel
|
||||
-- @param #AI_AIR self
|
||||
|
||||
--- Refuel Asynchronous Trigger for AI_A2A
|
||||
-- @function [parent=#AI_A2A] __Refuel
|
||||
-- @param #AI_A2A self
|
||||
--- Refuel Asynchronous Trigger for AI_AIR
|
||||
-- @function [parent=#AI_AIR] __Refuel
|
||||
-- @param #AI_AIR self
|
||||
-- @param #number Delay
|
||||
|
||||
self:AddTransition( "*", "Takeoff", "Airborne" )
|
||||
@@ -266,15 +263,17 @@ function GROUP:OnEventTakeoff( EventData, Fsm )
|
||||
self:UnHandleEvent( EVENTS.Takeoff )
|
||||
end
|
||||
|
||||
function AI_A2A:SetDispatcher( Dispatcher )
|
||||
|
||||
|
||||
function AI_AIR:SetDispatcher( Dispatcher )
|
||||
self.Dispatcher = Dispatcher
|
||||
end
|
||||
|
||||
function AI_A2A:GetDispatcher()
|
||||
function AI_AIR:GetDispatcher()
|
||||
return self.Dispatcher
|
||||
end
|
||||
|
||||
function AI_A2A:SetTargetDistance( Coordinate )
|
||||
function AI_AIR:SetTargetDistance( Coordinate )
|
||||
|
||||
local CurrentCoord = self.Controllable:GetCoordinate()
|
||||
self.TargetDistance = CurrentCoord:Get2DDistance( Coordinate )
|
||||
@@ -283,7 +282,7 @@ function AI_A2A:SetTargetDistance( Coordinate )
|
||||
end
|
||||
|
||||
|
||||
function AI_A2A:ClearTargetDistance()
|
||||
function AI_AIR:ClearTargetDistance()
|
||||
|
||||
self.TargetDistance = nil
|
||||
self.ClosestTargetDistance = nil
|
||||
@@ -291,11 +290,11 @@ end
|
||||
|
||||
|
||||
--- Sets (modifies) the minimum and maximum speed of the patrol.
|
||||
-- @param #AI_A2A self
|
||||
-- @param #AI_AIR self
|
||||
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Controllable} in km/h.
|
||||
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Controllable} in km/h.
|
||||
-- @return #AI_A2A self
|
||||
function AI_A2A:SetSpeed( PatrolMinSpeed, PatrolMaxSpeed )
|
||||
-- @return #AI_AIR self
|
||||
function AI_AIR:SetSpeed( PatrolMinSpeed, PatrolMaxSpeed )
|
||||
self:F2( { PatrolMinSpeed, PatrolMaxSpeed } )
|
||||
|
||||
self.PatrolMinSpeed = PatrolMinSpeed
|
||||
@@ -303,12 +302,25 @@ function AI_A2A:SetSpeed( PatrolMinSpeed, PatrolMaxSpeed )
|
||||
end
|
||||
|
||||
|
||||
--- Sets (modifies) the minimum and maximum RTB speed of the patrol.
|
||||
-- @param #AI_AIR self
|
||||
-- @param DCS#Speed RTBMinSpeed The minimum speed of the @{Wrapper.Controllable} in km/h.
|
||||
-- @param DCS#Speed RTBMaxSpeed The maximum speed of the @{Wrapper.Controllable} in km/h.
|
||||
-- @return #AI_AIR self
|
||||
function AI_AIR:SetRTBSpeed( RTBMinSpeed, RTBMaxSpeed )
|
||||
self:F( { RTBMinSpeed, RTBMaxSpeed } )
|
||||
|
||||
self.RTBMinSpeed = RTBMinSpeed
|
||||
self.RTBMaxSpeed = RTBMaxSpeed
|
||||
end
|
||||
|
||||
|
||||
--- Sets the floor and ceiling altitude of the patrol.
|
||||
-- @param #AI_A2A self
|
||||
-- @param #AI_AIR self
|
||||
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @return #AI_A2A self
|
||||
function AI_A2A:SetAltitude( PatrolFloorAltitude, PatrolCeilingAltitude )
|
||||
-- @return #AI_AIR self
|
||||
function AI_AIR:SetAltitude( PatrolFloorAltitude, PatrolCeilingAltitude )
|
||||
self:F2( { PatrolFloorAltitude, PatrolCeilingAltitude } )
|
||||
|
||||
self.PatrolFloorAltitude = PatrolFloorAltitude
|
||||
@@ -317,20 +329,20 @@ end
|
||||
|
||||
|
||||
--- Sets the home airbase.
|
||||
-- @param #AI_A2A self
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Airbase#AIRBASE HomeAirbase
|
||||
-- @return #AI_A2A self
|
||||
function AI_A2A:SetHomeAirbase( HomeAirbase )
|
||||
-- @return #AI_AIR self
|
||||
function AI_AIR:SetHomeAirbase( HomeAirbase )
|
||||
self:F2( { HomeAirbase } )
|
||||
|
||||
self.HomeAirbase = HomeAirbase
|
||||
end
|
||||
|
||||
--- Sets to refuel at the given tanker.
|
||||
-- @param #AI_A2A self
|
||||
-- @param #AI_AIR self
|
||||
-- @param Wrapper.Group#GROUP TankerName The group name of the tanker as defined within the Mission Editor or spawned.
|
||||
-- @return #AI_A2A self
|
||||
function AI_A2A:SetTanker( TankerName )
|
||||
-- @return #AI_AIR self
|
||||
function AI_AIR:SetTanker( TankerName )
|
||||
self:F2( { TankerName } )
|
||||
|
||||
self.TankerName = TankerName
|
||||
@@ -338,19 +350,19 @@ end
|
||||
|
||||
|
||||
--- Sets the disengage range, that when engaging a target beyond the specified range, the engagement will be cancelled and the plane will RTB.
|
||||
-- @param #AI_A2A self
|
||||
-- @param #AI_AIR self
|
||||
-- @param #number DisengageRadius The disengage range.
|
||||
-- @return #AI_A2A self
|
||||
function AI_A2A:SetDisengageRadius( DisengageRadius )
|
||||
-- @return #AI_AIR self
|
||||
function AI_AIR:SetDisengageRadius( DisengageRadius )
|
||||
self:F2( { DisengageRadius } )
|
||||
|
||||
self.DisengageRadius = DisengageRadius
|
||||
end
|
||||
|
||||
--- Set the status checking off.
|
||||
-- @param #AI_A2A self
|
||||
-- @return #AI_A2A self
|
||||
function AI_A2A:SetStatusOff()
|
||||
-- @param #AI_AIR self
|
||||
-- @return #AI_AIR self
|
||||
function AI_AIR:SetStatusOff()
|
||||
self:F2()
|
||||
|
||||
self.CheckStatus = false
|
||||
@@ -359,16 +371,16 @@ end
|
||||
|
||||
--- When the AI is out of fuel, it is required that a new AI is started, before the old AI can return to the home base.
|
||||
-- Therefore, with a parameter and a calculation of the distance to the home base, the fuel treshold is calculated.
|
||||
-- When the fuel treshold is reached, the AI will continue for a given time its patrol task in orbit, while a new AIControllable is targetted to the AI_A2A.
|
||||
-- When the fuel treshold is reached, the AI will continue for a given time its patrol task in orbit, while a new AIControllable is targetted to the AI_AIR.
|
||||
-- Once the time is finished, the old AI will return to the base.
|
||||
-- @param #AI_A2A self
|
||||
-- @param #number PatrolFuelThresholdPercentage The treshold in percentage (between 0 and 1) when the AIControllable is considered to get out of fuel.
|
||||
-- @param #number PatrolOutOfFuelOrbitTime The amount of seconds the out of fuel AIControllable will orbit before returning to the base.
|
||||
-- @return #AI_A2A self
|
||||
function AI_A2A:SetFuelThreshold( PatrolFuelThresholdPercentage, PatrolOutOfFuelOrbitTime )
|
||||
-- @param #AI_AIR self
|
||||
-- @param #number FuelThresholdPercentage The treshold in percentage (between 0 and 1) when the AIControllable is considered to get out of fuel.
|
||||
-- @param #number OutOfFuelOrbitTime The amount of seconds the out of fuel AIControllable will orbit before returning to the base.
|
||||
-- @return #AI_AIR self
|
||||
function AI_AIR:SetFuelThreshold( FuelThresholdPercentage, OutOfFuelOrbitTime )
|
||||
|
||||
self.PatrolFuelThresholdPercentage = PatrolFuelThresholdPercentage
|
||||
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
|
||||
self.FuelThresholdPercentage = FuelThresholdPercentage
|
||||
self.OutOfFuelOrbitTime = OutOfFuelOrbitTime
|
||||
|
||||
self.Controllable:OptionRTBBingoFuel( false )
|
||||
|
||||
@@ -381,10 +393,10 @@ end
|
||||
-- the AI will return immediately to the home base (RTB).
|
||||
-- Note that for groups, the average damage of the complete group will be calculated.
|
||||
-- So, in a group of 4 airplanes, 2 lost and 2 with damage 0.2, the damage treshold will be 0.25.
|
||||
-- @param #AI_A2A self
|
||||
-- @param #AI_AIR self
|
||||
-- @param #number PatrolDamageThreshold The treshold in percentage (between 0 and 1) when the AI is considered to be damaged.
|
||||
-- @return #AI_A2A self
|
||||
function AI_A2A:SetDamageThreshold( PatrolDamageThreshold )
|
||||
-- @return #AI_AIR self
|
||||
function AI_AIR:SetDamageThreshold( PatrolDamageThreshold )
|
||||
|
||||
self.PatrolManageDamage = true
|
||||
self.PatrolDamageThreshold = PatrolDamageThreshold
|
||||
@@ -392,14 +404,16 @@ function AI_A2A:SetDamageThreshold( PatrolDamageThreshold )
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
|
||||
-- @param #AI_A2A self
|
||||
-- @return #AI_A2A self
|
||||
-- @param #AI_AIR self
|
||||
-- @return #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_A2A:onafterStart( Controllable, From, Event, To )
|
||||
function AI_AIR:onafterStart( Controllable, From, Event, To )
|
||||
|
||||
self:__Status( 10 ) -- Check status status every 30 seconds.
|
||||
|
||||
@@ -411,16 +425,27 @@ function AI_A2A:onafterStart( Controllable, From, Event, To )
|
||||
Controllable:OptionROTVertical()
|
||||
end
|
||||
|
||||
--- Coordinates the approriate returning action.
|
||||
-- @param #AI_AIR self
|
||||
-- @return #AI_AIR self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR:onafterReturn( Controllable, From, Event, To )
|
||||
|
||||
self:__RTB( self.TaskDelay )
|
||||
|
||||
end
|
||||
|
||||
--- @param #AI_A2A self
|
||||
function AI_A2A:onbeforeStatus()
|
||||
--- @param #AI_AIR self
|
||||
function AI_AIR:onbeforeStatus()
|
||||
|
||||
return self.CheckStatus
|
||||
end
|
||||
|
||||
--- @param #AI_A2A self
|
||||
function AI_A2A:onafterStatus()
|
||||
--- @param #AI_AIR self
|
||||
function AI_AIR:onafterStatus()
|
||||
|
||||
if self.Controllable and self.Controllable:IsAlive() then
|
||||
|
||||
@@ -430,66 +455,80 @@ function AI_A2A:onafterStatus()
|
||||
|
||||
if not self:Is( "Holding" ) and not self:Is( "Returning" ) then
|
||||
local DistanceFromHomeBase = self.HomeAirbase:GetCoordinate():Get2DDistance( self.Controllable:GetCoordinate() )
|
||||
self:F({DistanceFromHomeBase=DistanceFromHomeBase})
|
||||
|
||||
if DistanceFromHomeBase > self.DisengageRadius then
|
||||
self:E( self.Controllable:GetName() .. " is too far from home base, RTB!" )
|
||||
self:I( self.Controllable:GetName() .. " is too far from home base, RTB!" )
|
||||
self:Hold( 300 )
|
||||
RTB = false
|
||||
end
|
||||
end
|
||||
|
||||
if self:Is( "Fuel" ) or self:Is( "Damaged" ) or self:Is( "LostControl" ) then
|
||||
if DistanceFromHomeBase < 5000 then
|
||||
self:E( self.Controllable:GetName() .. " is too far from home base, RTB!" )
|
||||
self:Home( "Destroy" )
|
||||
end
|
||||
end
|
||||
|
||||
-- I think this code is not requirement anymore after release 2.5.
|
||||
-- if self:Is( "Fuel" ) or self:Is( "Damaged" ) or self:Is( "LostControl" ) then
|
||||
-- if DistanceFromHomeBase < 5000 then
|
||||
-- self:E( self.Controllable:GetName() .. " is near the home base, RTB!" )
|
||||
-- self:Home( "Destroy" )
|
||||
-- end
|
||||
-- end
|
||||
|
||||
|
||||
if not self:Is( "Fuel" ) and not self:Is( "Home" ) then
|
||||
if not self:Is( "Fuel" ) and not self:Is( "Home" ) and not self:is( "Refuelling" )then
|
||||
|
||||
local Fuel = self.Controllable:GetFuelMin()
|
||||
self:F({Fuel=Fuel, PatrolFuelThresholdPercentage=self.PatrolFuelThresholdPercentage})
|
||||
if Fuel < self.PatrolFuelThresholdPercentage then
|
||||
|
||||
-- If the fuel in the controllable is below the treshold percentage,
|
||||
-- then send for refuel in case of a tanker, otherwise RTB.
|
||||
if Fuel < self.FuelThresholdPercentage then
|
||||
|
||||
if self.TankerName then
|
||||
self:E( self.Controllable:GetName() .. " is out of fuel: " .. Fuel .. " ... Refuelling at Tanker!" )
|
||||
self:I( self.Controllable:GetName() .. " is out of fuel: " .. Fuel .. " ... Refuelling at Tanker!" )
|
||||
self:Refuel()
|
||||
else
|
||||
self:E( self.Controllable:GetName() .. " is out of fuel: " .. Fuel .. " ... RTB!" )
|
||||
self:I( self.Controllable:GetName() .. " is out of fuel: " .. Fuel .. " ... RTB!" )
|
||||
local OldAIControllable = self.Controllable
|
||||
|
||||
local OrbitTask = OldAIControllable:TaskOrbitCircle( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ), self.PatrolMinSpeed )
|
||||
local TimedOrbitTask = OldAIControllable:TaskControlled( OrbitTask, OldAIControllable:TaskCondition(nil,nil,nil,nil,self.PatrolOutOfFuelOrbitTime,nil ) )
|
||||
local TimedOrbitTask = OldAIControllable:TaskControlled( OrbitTask, OldAIControllable:TaskCondition(nil,nil,nil,nil,self.OutOfFuelOrbitTime,nil ) )
|
||||
OldAIControllable:SetTask( TimedOrbitTask, 10 )
|
||||
|
||||
self:Fuel()
|
||||
RTB = true
|
||||
end
|
||||
else
|
||||
end
|
||||
end
|
||||
|
||||
if self:Is( "Fuel" ) and not self:Is( "Home" ) and not self:is( "Refuelling" ) then
|
||||
RTB = true
|
||||
end
|
||||
|
||||
-- TODO: Check GROUP damage function.
|
||||
local Damage = self.Controllable:GetLife()
|
||||
local InitialLife = self.Controllable:GetLife0()
|
||||
self:F( { Damage = Damage, InitialLife = InitialLife, DamageThreshold = self.PatrolDamageThreshold } )
|
||||
|
||||
-- If the group is damaged, then RTB.
|
||||
-- Note that a group can consist of more units, so if one unit is damaged of a group, the mission may continue.
|
||||
-- The damaged unit will RTB due to DCS logic, and the others will continue to engage.
|
||||
if ( Damage / InitialLife ) < self.PatrolDamageThreshold then
|
||||
self:E( self.Controllable:GetName() .. " is damaged: " .. Damage .. " ... RTB!" )
|
||||
self:I( self.Controllable:GetName() .. " is damaged: " .. Damage .. " ... RTB!" )
|
||||
self:Damaged()
|
||||
RTB = true
|
||||
self:SetStatusOff()
|
||||
end
|
||||
|
||||
|
||||
-- Check if planes went RTB and are out of control.
|
||||
-- We only check if planes are out of control, when they are in duty.
|
||||
if self.Controllable:HasTask() == false then
|
||||
if not self:Is( "Started" ) and
|
||||
not self:Is( "Stopped" ) and
|
||||
not self:Is( "Fuel" ) and
|
||||
not self:Is( "Damaged" ) and
|
||||
not self:Is( "Home" ) then
|
||||
if self.IdleCount >= 2 then
|
||||
if self.IdleCount >= 10 then
|
||||
if Damage ~= InitialLife then
|
||||
self:Damaged()
|
||||
else
|
||||
self:E( self.Controllable:GetName() .. " control lost! " )
|
||||
self:I( self.Controllable:GetName() .. " control lost! " )
|
||||
|
||||
self:LostControl()
|
||||
end
|
||||
else
|
||||
@@ -501,31 +540,34 @@ function AI_A2A:onafterStatus()
|
||||
end
|
||||
|
||||
if RTB == true then
|
||||
self:__RTB( 0.5 )
|
||||
self:__RTB( self.TaskDelay )
|
||||
end
|
||||
|
||||
if not self:Is("Home") then
|
||||
self:__Status( 10 )
|
||||
end
|
||||
|
||||
self:__Status( 10 )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIGroup
|
||||
function AI_A2A.RTBRoute( AIGroup, Fsm )
|
||||
function AI_AIR.RTBRoute( AIGroup, Fsm )
|
||||
|
||||
AIGroup:F( { "AI_A2A.RTBRoute:", AIGroup:GetName() } )
|
||||
AIGroup:F( { "AI_AIR.RTBRoute:", AIGroup:GetName() } )
|
||||
|
||||
if AIGroup:IsAlive() then
|
||||
Fsm:__RTB( 0.5 )
|
||||
Fsm:RTB()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIGroup
|
||||
function AI_A2A.RTBHold( AIGroup, Fsm )
|
||||
function AI_AIR.RTBHold( AIGroup, Fsm )
|
||||
|
||||
AIGroup:F( { "AI_A2A.RTBHold:", AIGroup:GetName() } )
|
||||
AIGroup:F( { "AI_AIR.RTBHold:", AIGroup:GetName() } )
|
||||
if AIGroup:IsAlive() then
|
||||
Fsm:__RTB( 0.5 )
|
||||
Fsm:__RTB( Fsm.TaskDelay )
|
||||
Fsm:Return()
|
||||
local Task = AIGroup:TaskOrbitCircle( 4000, 400 )
|
||||
AIGroup:SetTask( Task )
|
||||
@@ -534,74 +576,92 @@ function AI_A2A.RTBHold( AIGroup, Fsm )
|
||||
end
|
||||
|
||||
|
||||
--- @param #AI_A2A self
|
||||
--- @param #AI_AIR self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
function AI_A2A:onafterRTB( AIGroup, From, Event, To )
|
||||
function AI_AIR:onafterRTB( AIGroup, From, Event, To )
|
||||
self:F( { AIGroup, From, Event, To } )
|
||||
|
||||
|
||||
if AIGroup and AIGroup:IsAlive() then
|
||||
|
||||
self:E( "Group " .. AIGroup:GetName() .. " ... RTB! ( " .. self:GetState() .. " )" )
|
||||
self:I( "Group " .. AIGroup:GetName() .. " ... RTB! ( " .. self:GetState() .. " )" )
|
||||
|
||||
self:ClearTargetDistance()
|
||||
AIGroup:ClearTasks()
|
||||
--AIGroup:ClearTasks()
|
||||
|
||||
local EngageRoute = {}
|
||||
|
||||
--- Calculate the target route point.
|
||||
|
||||
local CurrentCoord = AIGroup:GetCoordinate()
|
||||
local FromCoord = AIGroup:GetCoordinate()
|
||||
local ToTargetCoord = self.HomeAirbase:GetCoordinate()
|
||||
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
|
||||
local ToAirbaseAngle = CurrentCoord:GetAngleDegrees( CurrentCoord:GetDirectionVec3( ToTargetCoord ) )
|
||||
|
||||
local Distance = CurrentCoord:Get2DDistance( ToTargetCoord )
|
||||
if not self.RTBMinSpeed and not self.RTBMaxSpeed then
|
||||
local RTBSpeedMax = AIGroup:GetSpeedMax()
|
||||
self:SetRTBSpeed( RTBSpeedMax * 0.25, RTBSpeedMax * 0.25 )
|
||||
end
|
||||
|
||||
local ToAirbaseCoord = CurrentCoord:Translate( 5000, ToAirbaseAngle )
|
||||
local RTBSpeed = math.random( self.RTBMinSpeed, self.RTBMaxSpeed )
|
||||
local ToAirbaseAngle = FromCoord:GetAngleDegrees( FromCoord:GetDirectionVec3( ToTargetCoord ) )
|
||||
|
||||
local Distance = FromCoord:Get2DDistance( ToTargetCoord )
|
||||
|
||||
local ToAirbaseCoord = FromCoord:Translate( 5000, ToAirbaseAngle )
|
||||
if Distance < 5000 then
|
||||
self:E( "RTB and near the airbase!" )
|
||||
self:I( "RTB and near the airbase!" )
|
||||
self:Home()
|
||||
return
|
||||
end
|
||||
|
||||
if not AIGroup:InAir() == true then
|
||||
self:I( "Not anymore in the air, considered Home." )
|
||||
self:Home()
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--- Create a route point of type air.
|
||||
local FromRTBRoutePoint = FromCoord:WaypointAir(
|
||||
self.PatrolAltType,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
RTBSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
--- Create a route point of type air.
|
||||
local ToRTBRoutePoint = ToAirbaseCoord:WaypointAir(
|
||||
self.PatrolAltType,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
ToTargetSpeed,
|
||||
RTBSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
self:F( { Angle = ToAirbaseAngle, ToTargetSpeed = ToTargetSpeed } )
|
||||
self:T2( { self.MinSpeed, self.MaxSpeed, ToTargetSpeed } )
|
||||
|
||||
EngageRoute[#EngageRoute+1] = ToRTBRoutePoint
|
||||
EngageRoute[#EngageRoute+1] = FromRTBRoutePoint
|
||||
EngageRoute[#EngageRoute+1] = ToRTBRoutePoint
|
||||
|
||||
local Tasks = {}
|
||||
Tasks[#Tasks+1] = AIGroup:TaskFunction( "AI_AIR.RTBRoute", self )
|
||||
|
||||
EngageRoute[#EngageRoute].task = AIGroup:TaskCombo( Tasks )
|
||||
|
||||
AIGroup:OptionROEHoldFire()
|
||||
AIGroup:OptionROTEvadeFire()
|
||||
|
||||
--- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable...
|
||||
AIGroup:WayPointInitialize( EngageRoute )
|
||||
|
||||
local Tasks = {}
|
||||
Tasks[#Tasks+1] = AIGroup:TaskFunction( "AI_A2A.RTBRoute", self )
|
||||
EngageRoute[#EngageRoute].task = AIGroup:TaskCombo( Tasks )
|
||||
|
||||
--- NOW ROUTE THE GROUP!
|
||||
AIGroup:Route( EngageRoute, 0.5 )
|
||||
AIGroup:Route( EngageRoute, self.TaskDelay )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- @param #AI_A2A self
|
||||
--- @param #AI_AIR self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
function AI_A2A:onafterHome( AIGroup, From, Event, To )
|
||||
function AI_AIR:onafterHome( AIGroup, From, Event, To )
|
||||
self:F( { AIGroup, From, Event, To } )
|
||||
|
||||
self:E( "Group " .. self.Controllable:GetName() .. " ... Home! ( " .. self:GetState() .. " )" )
|
||||
self:I( "Group " .. self.Controllable:GetName() .. " ... Home! ( " .. self:GetState() .. " )" )
|
||||
|
||||
if AIGroup and AIGroup:IsAlive() then
|
||||
end
|
||||
@@ -610,22 +670,22 @@ end
|
||||
|
||||
|
||||
|
||||
--- @param #AI_A2A self
|
||||
--- @param #AI_AIR self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
function AI_A2A:onafterHold( AIGroup, From, Event, To, HoldTime )
|
||||
function AI_AIR:onafterHold( AIGroup, From, Event, To, HoldTime )
|
||||
self:F( { AIGroup, From, Event, To } )
|
||||
|
||||
self:E( "Group " .. self.Controllable:GetName() .. " ... Holding! ( " .. self:GetState() .. " )" )
|
||||
self:I( "Group " .. self.Controllable:GetName() .. " ... Holding! ( " .. self:GetState() .. " )" )
|
||||
|
||||
if AIGroup and AIGroup:IsAlive() then
|
||||
local OrbitTask = AIGroup:TaskOrbitCircle( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ), self.PatrolMinSpeed )
|
||||
local TimedOrbitTask = AIGroup:TaskControlled( OrbitTask, AIGroup:TaskCondition( nil, nil, nil, nil, HoldTime , nil ) )
|
||||
|
||||
local RTBTask = AIGroup:TaskFunction( "AI_A2A.RTBHold", self )
|
||||
local RTBTask = AIGroup:TaskFunction( "AI_AIR.RTBHold", self )
|
||||
|
||||
local OrbitHoldTask = AIGroup:TaskOrbitCircle( 4000, self.PatrolMinSpeed )
|
||||
|
||||
--AIGroup:SetState( AIGroup, "AI_A2A", self )
|
||||
--AIGroup:SetState( AIGroup, "AI_AIR", self )
|
||||
|
||||
AIGroup:SetTask( AIGroup:TaskCombo( { TimedOrbitTask, RTBTask, OrbitHoldTask } ), 1 )
|
||||
end
|
||||
@@ -633,36 +693,47 @@ function AI_A2A:onafterHold( AIGroup, From, Event, To, HoldTime )
|
||||
end
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIGroup
|
||||
function AI_A2A.Resume( AIGroup, Fsm )
|
||||
function AI_AIR.Resume( AIGroup, Fsm )
|
||||
|
||||
AIGroup:F( { "AI_A2A.Resume:", AIGroup:GetName() } )
|
||||
AIGroup:I( { "AI_AIR.Resume:", AIGroup:GetName() } )
|
||||
if AIGroup:IsAlive() then
|
||||
Fsm:__RTB( 0.5 )
|
||||
Fsm:__RTB( Fsm.TaskDelay )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- @param #AI_A2A self
|
||||
--- @param #AI_AIR self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
function AI_A2A:onafterRefuel( AIGroup, From, Event, To )
|
||||
function AI_AIR:onafterRefuel( AIGroup, From, Event, To )
|
||||
self:F( { AIGroup, From, Event, To } )
|
||||
|
||||
self:E( "Group " .. self.Controllable:GetName() .. " ... Refuelling! ( " .. self:GetState() .. " )" )
|
||||
|
||||
if AIGroup and AIGroup:IsAlive() then
|
||||
local Tanker = GROUP:FindByName( self.TankerName )
|
||||
|
||||
if Tanker:IsAlive() and Tanker:IsAirPlane() then
|
||||
|
||||
self:I( "Group " .. self.Controllable:GetName() .. " ... Refuelling! ( " .. self:GetState() .. "), at tanker " .. self.TankerName )
|
||||
|
||||
local RefuelRoute = {}
|
||||
|
||||
--- Calculate the target route point.
|
||||
|
||||
local CurrentCoord = AIGroup:GetCoordinate()
|
||||
local FromRefuelCoord = AIGroup:GetCoordinate()
|
||||
local ToRefuelCoord = Tanker:GetCoordinate()
|
||||
local ToRefuelSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
|
||||
|
||||
--- Create a route point of type air.
|
||||
local ToRefuelRoutePoint = ToRefuelCoord:WaypointAir(
|
||||
local FromRefuelRoutePoint = FromRefuelCoord:WaypointAir(
|
||||
self.PatrolAltType,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
ToRefuelSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
--- Create a route point of type air.
|
||||
local ToRefuelRoutePoint = FromRefuelCoord:WaypointAir(
|
||||
self.PatrolAltType,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
@@ -672,8 +743,8 @@ function AI_A2A:onafterRefuel( AIGroup, From, Event, To )
|
||||
|
||||
self:F( { ToRefuelSpeed = ToRefuelSpeed } )
|
||||
|
||||
RefuelRoute[#RefuelRoute+1] = ToRefuelRoutePoint
|
||||
RefuelRoute[#RefuelRoute+1] = ToRefuelRoutePoint
|
||||
RefuelRoute[#RefuelRoute+1] = FromRefuelRoutePoint
|
||||
--RefuelRoute[#RefuelRoute+1] = ToRefuelRoutePoint
|
||||
|
||||
AIGroup:OptionROEHoldFire()
|
||||
AIGroup:OptionROTEvadeFire()
|
||||
@@ -683,7 +754,7 @@ function AI_A2A:onafterRefuel( AIGroup, From, Event, To )
|
||||
Tasks[#Tasks+1] = AIGroup:TaskFunction( self:GetClassName() .. ".Resume", self )
|
||||
RefuelRoute[#RefuelRoute].task = AIGroup:TaskCombo( Tasks )
|
||||
|
||||
AIGroup:Route( RefuelRoute, 0.5 )
|
||||
AIGroup:Route( RefuelRoute, self.TaskDelay )
|
||||
else
|
||||
self:RTB()
|
||||
end
|
||||
@@ -693,38 +764,37 @@ end
|
||||
|
||||
|
||||
|
||||
--- @param #AI_A2A self
|
||||
function AI_A2A:onafterDead()
|
||||
--- @param #AI_AIR self
|
||||
function AI_AIR:onafterDead()
|
||||
self:SetStatusOff()
|
||||
end
|
||||
|
||||
|
||||
--- @param #AI_A2A self
|
||||
--- @param #AI_AIR self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_A2A:OnCrash( EventData )
|
||||
function AI_AIR:OnCrash( EventData )
|
||||
|
||||
if self.Controllable:IsAlive() and EventData.IniDCSGroupName == self.Controllable:GetName() then
|
||||
self:E( self.Controllable:GetUnits() )
|
||||
if #self.Controllable:GetUnits() == 1 then
|
||||
self:__Crash( 1, EventData )
|
||||
self:__Crash( self.TaskDelay, EventData )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_A2A self
|
||||
--- @param #AI_AIR self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_A2A:OnEjection( EventData )
|
||||
function AI_AIR:OnEjection( EventData )
|
||||
|
||||
if self.Controllable:IsAlive() and EventData.IniDCSGroupName == self.Controllable:GetName() then
|
||||
self:__Eject( 1, EventData )
|
||||
self:__Eject( self.TaskDelay, EventData )
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_A2A self
|
||||
--- @param #AI_AIR self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_A2A:OnPilotDead( EventData )
|
||||
function AI_AIR:OnPilotDead( EventData )
|
||||
|
||||
if self.Controllable:IsAlive() and EventData.IniDCSGroupName == self.Controllable:GetName() then
|
||||
self:__PilotDead( 1, EventData )
|
||||
self:__PilotDead( self.TaskDelay, EventData )
|
||||
end
|
||||
end
|
||||
3248
Moose Development/Moose/AI/AI_Air_Dispatcher.lua
Normal file
3248
Moose Development/Moose/AI/AI_Air_Dispatcher.lua
Normal file
File diff suppressed because it is too large
Load Diff
613
Moose Development/Moose/AI/AI_Air_Engage.lua
Normal file
613
Moose Development/Moose/AI/AI_Air_Engage.lua
Normal file
@@ -0,0 +1,613 @@
|
||||
--- **AI** -- Models the process of air to ground engagement for airplanes and helicopters.
|
||||
--
|
||||
-- This is a class used in the @{AI_A2G_Dispatcher}.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_Air_Engage
|
||||
-- @image AI_Air_To_Ground_Engage.JPG
|
||||
|
||||
|
||||
|
||||
--- @type AI_AIR_ENGAGE
|
||||
-- @extends AI.AI_AIR#AI_AIR
|
||||
|
||||
|
||||
--- Implements the core functions to intercept intruders. Use the Engage trigger to intercept intruders.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- The AI_AIR_ENGAGE is assigned a @{Wrapper.Group} and this must be done before the AI_AIR_ENGAGE process can be started using the **Start** event.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- The AI will fly towards the random 3D point within the patrol zone, using a random speed within the given altitude and speed limits.
|
||||
-- Upon arrival at the 3D point, a new random 3D point will be selected within the patrol zone using the given limits.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- This cycle will continue.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- During the patrol, the AI will detect enemy targets, which are reported through the **Detected** event.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- When enemies are detected, the AI will automatically engage the enemy.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- Until a fuel or damage treshold has been reached by the AI, or when the AI is commanded to RTB.
|
||||
-- When the fuel treshold has been reached, the airplane will fly towards the nearest friendly airbase and will land.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- ## 1. AI_AIR_ENGAGE constructor
|
||||
--
|
||||
-- * @{#AI_AIR_ENGAGE.New}(): Creates a new AI_AIR_ENGAGE object.
|
||||
--
|
||||
-- ## 3. Set the Range of Engagement
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- An optional range can be set in meters,
|
||||
-- that will define when the AI will engage with the detected airborne enemy targets.
|
||||
-- The range can be beyond or smaller than the range of the Patrol Zone.
|
||||
-- The range is applied at the position of the AI.
|
||||
-- Use the method @{AI.AI_GCI#AI_AIR_ENGAGE.SetEngageRange}() to define that range.
|
||||
--
|
||||
-- ## 4. Set the Zone of Engagement
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- An optional @{Zone} can be set,
|
||||
-- that will define when the AI will engage with the detected airborne enemy targets.
|
||||
-- Use the method @{AI.AI_Cap#AI_AIR_ENGAGE.SetEngageZone}() to define that Zone.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @field #AI_AIR_ENGAGE
|
||||
AI_AIR_ENGAGE = {
|
||||
ClassName = "AI_AIR_ENGAGE",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Creates a new AI_AIR_ENGAGE object
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
-- @param DCS#Speed EngageMinSpeed (optional, default = 50% of max speed) The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Speed EngageMaxSpeed (optional, default = 75% of max speed) The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
|
||||
-- @param DCS#Altitude EngageFloorAltitude (optional, default = 1000m ) The lowest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#Altitude EngageCeilingAltitude (optional, default = 1500m ) The highest altitude in meters where to execute the engagement.
|
||||
-- @param DCS#AltitudeType EngageAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to "RADIO".
|
||||
-- @return #AI_AIR_ENGAGE
|
||||
function AI_AIR_ENGAGE:New( AI_Air, AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, AI_Air ) -- #AI_AIR_ENGAGE
|
||||
|
||||
self.Accomplished = false
|
||||
self.Engaging = false
|
||||
|
||||
local SpeedMax = AIGroup:GetSpeedMax()
|
||||
|
||||
self.EngageMinSpeed = EngageMinSpeed or SpeedMax * 0.5
|
||||
self.EngageMaxSpeed = EngageMaxSpeed or SpeedMax * 0.75
|
||||
self.EngageFloorAltitude = EngageFloorAltitude or 1000
|
||||
self.EngageCeilingAltitude = EngageCeilingAltitude or 1500
|
||||
self.EngageAltType = EngageAltType or "RADIO"
|
||||
|
||||
self:AddTransition( { "Started", "Engaging", "Returning", "Airborne", "Patrolling" }, "EngageRoute", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR_ENGAGE.
|
||||
|
||||
--- OnBefore Transition Handler for Event EngageRoute.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnBeforeEngageRoute
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event EngageRoute.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnAfterEngageRoute
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event EngageRoute.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] EngageRoute
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
|
||||
--- Asynchronous Event Trigger for Event EngageRoute.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] __EngageRoute
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
--- OnLeave Transition Handler for State Engaging.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnLeaveEngaging
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnEnter Transition Handler for State Engaging.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnEnterEngaging
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
self:AddTransition( { "Started", "Engaging", "Returning", "Airborne", "Patrolling" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR_ENGAGE.
|
||||
|
||||
--- OnBefore Transition Handler for Event Engage.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnBeforeEngage
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Engage.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnAfterEngage
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Engage.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] Engage
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Engage.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] __Engage
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
--- OnLeave Transition Handler for State Engaging.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnLeaveEngaging
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnEnter Transition Handler for State Engaging.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnEnterEngaging
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR_ENGAGE.
|
||||
|
||||
--- OnBefore Transition Handler for Event Fired.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnBeforeFired
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Fired.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnAfterFired
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Fired.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] Fired
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Fired.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] __Fired
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
self:AddTransition( "*", "Destroy", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR_ENGAGE.
|
||||
|
||||
--- OnBefore Transition Handler for Event Destroy.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnBeforeDestroy
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Destroy.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnAfterDestroy
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Destroy.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] Destroy
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Destroy.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] __Destroy
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
|
||||
self:AddTransition( "Engaging", "Abort", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR_ENGAGE.
|
||||
|
||||
--- OnBefore Transition Handler for Event Abort.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnBeforeAbort
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Abort.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnAfterAbort
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Abort.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] Abort
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Abort.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] __Abort
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
self:AddTransition( "Engaging", "Accomplish", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR_ENGAGE.
|
||||
|
||||
--- OnBefore Transition Handler for Event Accomplish.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnBeforeAccomplish
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Accomplish.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] OnAfterAccomplish
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Accomplish.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] Accomplish
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Accomplish.
|
||||
-- @function [parent=#AI_AIR_ENGAGE] __Accomplish
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
self:AddTransition( { "Patrolling", "Engaging" }, "Refuel", "Refuelling" )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- onafter event handler for Start event.
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The AI group managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR_ENGAGE:onafterStart( AIGroup, From, Event, To )
|
||||
|
||||
self:GetParent( self, AI_AIR_ENGAGE ).onafterStart( self, AIGroup, From, Event, To )
|
||||
|
||||
AIGroup:HandleEvent( EVENTS.Takeoff, nil, self )
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- onafter event handler for Engage event.
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The AI Group managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR_ENGAGE:onafterEngage( AIGroup, From, Event, To )
|
||||
|
||||
self:HandleEvent( EVENTS.Dead )
|
||||
|
||||
end
|
||||
|
||||
-- todo: need to fix this global function
|
||||
|
||||
|
||||
--- onbefore event handler for Engage event.
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR_ENGAGE:onbeforeEngage( AIGroup, From, Event, To )
|
||||
|
||||
if self.Accomplished == true then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- onafter event handler for Abort event.
|
||||
-- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The AI Group managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR_ENGAGE:onafterAbort( AIGroup, From, Event, To )
|
||||
AIGroup:ClearTasks()
|
||||
self:Return()
|
||||
end
|
||||
|
||||
|
||||
--- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR_ENGAGE:onafterAccomplish( AIGroup, From, Event, To )
|
||||
self.Accomplished = true
|
||||
self:SetDetectionOff()
|
||||
end
|
||||
|
||||
--- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_AIR_ENGAGE:onafterDestroy( AIGroup, From, Event, To, EventData )
|
||||
|
||||
if EventData.IniUnit then
|
||||
self.AttackUnits[EventData.IniUnit] = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #AI_AIR_ENGAGE self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_AIR_ENGAGE:OnEventDead( EventData )
|
||||
self:F( { "EventDead", EventData } )
|
||||
|
||||
if EventData.IniDCSUnit then
|
||||
if self.AttackUnits and self.AttackUnits[EventData.IniUnit] then
|
||||
self:__Destroy( self.TaskDelay, EventData )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIControllable
|
||||
function AI_AIR_ENGAGE.___EngageRoute( AIGroup, Fsm, AttackSetUnit )
|
||||
|
||||
Fsm:I( { "AI_AIR_ENGAGE.___EngageRoute:", AIGroup:GetName() } )
|
||||
|
||||
if AIGroup:IsAlive() then
|
||||
Fsm:__EngageRoute( Fsm.TaskDelay, AttackSetUnit )
|
||||
|
||||
--local Task = AIGroup:TaskOrbitCircle( 4000, 400 )
|
||||
--AIGroup:SetTask( Task )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP DefenderGroup The GroupGroup managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR_ENGAGE:onafterEngageRoute( DefenderGroup, From, Event, To, AttackSetUnit )
|
||||
|
||||
self:I( { DefenderGroup, From, Event, To, AttackSetUnit } )
|
||||
|
||||
local DefenderGroupName = DefenderGroup:GetName()
|
||||
|
||||
self.AttackSetUnit = AttackSetUnit -- Kept in memory in case of resume from refuel in air!
|
||||
|
||||
local AttackCount = AttackSetUnit:Count()
|
||||
|
||||
if AttackCount > 0 then
|
||||
|
||||
if DefenderGroup:IsAlive() then
|
||||
|
||||
local EngageAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
|
||||
local EngageSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
|
||||
|
||||
-- Determine the distance to the target.
|
||||
-- If it is less than 10km, then attack without a route.
|
||||
-- Otherwise perform a route attack.
|
||||
|
||||
local DefenderCoord = DefenderGroup:GetPointVec3()
|
||||
DefenderCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
|
||||
|
||||
local TargetCoord = AttackSetUnit:GetFirst():GetPointVec3()
|
||||
TargetCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
|
||||
|
||||
local TargetDistance = DefenderCoord:Get2DDistance( TargetCoord )
|
||||
local EngageDistance = ( DefenderGroup:IsHelicopter() and 5000 ) or ( DefenderGroup:IsAirPlane() and 10000 )
|
||||
|
||||
if TargetDistance <= EngageDistance * 3 then
|
||||
|
||||
self:__Engage( 0.1, AttackSetUnit )
|
||||
|
||||
else
|
||||
|
||||
local EngageRoute = {}
|
||||
local AttackTasks = {}
|
||||
|
||||
--- Calculate the target route point.
|
||||
|
||||
local FromWP = DefenderCoord:WaypointAir(
|
||||
self.PatrolAltType or "RADIO",
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
EngageSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
EngageRoute[#EngageRoute+1] = FromWP
|
||||
|
||||
self:SetTargetDistance( TargetCoord ) -- For RTB status check
|
||||
|
||||
local FromEngageAngle = DefenderCoord:GetAngleDegrees( DefenderCoord:GetDirectionVec3( TargetCoord ) )
|
||||
local ToWP = DefenderCoord:Translate( EngageDistance, FromEngageAngle, true ):WaypointAir(
|
||||
self.PatrolAltType or "RADIO",
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
EngageSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
EngageRoute[#EngageRoute+1] = ToWP
|
||||
|
||||
AttackTasks[#AttackTasks+1] = DefenderGroup:TaskFunction( "AI_AIR_ENGAGE.___EngageRoute", self, AttackSetUnit )
|
||||
EngageRoute[#EngageRoute].task = DefenderGroup:TaskCombo( AttackTasks )
|
||||
|
||||
DefenderGroup:OptionROEReturnFire()
|
||||
DefenderGroup:OptionROTEvadeFire()
|
||||
|
||||
DefenderGroup:Route( EngageRoute, self.TaskDelay )
|
||||
end
|
||||
|
||||
end
|
||||
else
|
||||
self:I( DefenderGroupName .. ": No targets found -> Going RTB")
|
||||
self:Return()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIControllable
|
||||
function AI_AIR_ENGAGE.___Engage( AIGroup, Fsm, AttackSetUnit )
|
||||
|
||||
Fsm:I( { "AI_AIR_ENGAGE.___Engage:", AIGroup:GetName() } )
|
||||
|
||||
if AIGroup:IsAlive() then
|
||||
Fsm:__Engage( Fsm.TaskDelay, AttackSetUnit )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- @param #AI_AIR_ENGAGE self
|
||||
-- @param Wrapper.Group#GROUP DefenderGroup The GroupGroup managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR_ENGAGE:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit )
|
||||
|
||||
self:F( { DefenderGroup, From, Event, To, AttackSetUnit} )
|
||||
|
||||
local DefenderGroupName = DefenderGroup:GetName()
|
||||
|
||||
self.AttackSetUnit = AttackSetUnit -- Kept in memory in case of resume from refuel in air!
|
||||
|
||||
local AttackCount = AttackSetUnit:Count()
|
||||
self:I({AttackCount = AttackCount})
|
||||
|
||||
if AttackCount > 0 then
|
||||
|
||||
if DefenderGroup:IsAlive() then
|
||||
|
||||
local EngageAltitude = math.random( self.EngageFloorAltitude or 500, self.EngageCeilingAltitude or 1000 )
|
||||
local EngageSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
|
||||
|
||||
local DefenderCoord = DefenderGroup:GetPointVec3()
|
||||
DefenderCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
|
||||
|
||||
local TargetCoord = AttackSetUnit:GetFirst():GetPointVec3()
|
||||
TargetCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
|
||||
|
||||
local TargetDistance = DefenderCoord:Get2DDistance( TargetCoord )
|
||||
local EngageDistance = ( DefenderGroup:IsHelicopter() and 5000 ) or ( DefenderGroup:IsAirPlane() and 10000 )
|
||||
|
||||
local EngageRoute = {}
|
||||
local AttackTasks = {}
|
||||
|
||||
local FromWP = DefenderCoord:WaypointAir(
|
||||
self.EngageAltType or "RADIO",
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
EngageSpeed,
|
||||
true
|
||||
)
|
||||
EngageRoute[#EngageRoute+1] = FromWP
|
||||
|
||||
self:SetTargetDistance( TargetCoord ) -- For RTB status check
|
||||
|
||||
local FromEngageAngle = DefenderCoord:GetAngleDegrees( DefenderCoord:GetDirectionVec3( TargetCoord ) )
|
||||
local ToWP = DefenderCoord:Translate( EngageDistance, FromEngageAngle, true ):WaypointAir(
|
||||
self.EngageAltType or "RADIO",
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
EngageSpeed,
|
||||
true
|
||||
)
|
||||
EngageRoute[#EngageRoute+1] = ToWP
|
||||
|
||||
if TargetDistance <= EngageDistance * 3 then
|
||||
|
||||
local AttackUnitTasks = self:CreateAttackUnitTasks( AttackSetUnit, DefenderGroup, EngageAltitude ) -- Polymorphic
|
||||
|
||||
if #AttackUnitTasks == 0 then
|
||||
self:I( DefenderGroupName .. ": No valid targets found -> Going RTB")
|
||||
self:Return()
|
||||
return
|
||||
else
|
||||
self:I( DefenderGroupName .. ": Engaging targets " )
|
||||
DefenderGroup:OptionROEOpenFire()
|
||||
DefenderGroup:OptionROTEvadeFire()
|
||||
DefenderGroup:OptionKeepWeaponsOnThreat()
|
||||
|
||||
AttackTasks[#AttackTasks+1] = DefenderGroup:TaskCombo( AttackUnitTasks )
|
||||
end
|
||||
end
|
||||
|
||||
AttackTasks[#AttackTasks+1] = DefenderGroup:TaskFunction( "AI_AIR_ENGAGE.___Engage", self, AttackSetUnit )
|
||||
EngageRoute[#EngageRoute].task = DefenderGroup:TaskCombo( AttackTasks )
|
||||
|
||||
DefenderGroup:Route( EngageRoute, self.TaskDelay )
|
||||
|
||||
end
|
||||
else
|
||||
self:I( DefenderGroupName .. ": No targets found -> returning.")
|
||||
self:Return()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIEngage
|
||||
function AI_AIR_ENGAGE.Resume( AIEngage, Fsm )
|
||||
|
||||
AIEngage:F( { "Resume:", AIEngage:GetName() } )
|
||||
if AIEngage:IsAlive() then
|
||||
Fsm:__Reset( Fsm.TaskDelay )
|
||||
Fsm:__EngageRoute( Fsm.TaskDelay, Fsm.AttackSetUnit )
|
||||
end
|
||||
|
||||
end
|
||||
409
Moose Development/Moose/AI/AI_Air_Patrol.lua
Normal file
409
Moose Development/Moose/AI/AI_Air_Patrol.lua
Normal file
@@ -0,0 +1,409 @@
|
||||
--- **AI** -- Models the process of A2G patrolling and engaging ground targets for airplanes and helicopters.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_Air_Patrol
|
||||
-- @image AI_Air_To_Ground_Patrol.JPG
|
||||
|
||||
--- @type AI_AIR_PATROL
|
||||
-- @extends AI.AI_Air#AI_AIR
|
||||
|
||||
|
||||
--- The AI_AIR_PATROL class implements the core functions to patrol a @{Zone} by an AI @{Wrapper.Group} or @{Wrapper.Group}
|
||||
-- and automatically engage any airborne enemies that are within a certain range or within a certain zone.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- The AI_AIR_PATROL is assigned a @{Wrapper.Group} and this must be done before the AI_AIR_PATROL process can be started using the **Start** event.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- The AI will fly towards the random 3D point within the patrol zone, using a random speed within the given altitude and speed limits.
|
||||
-- Upon arrival at the 3D point, a new random 3D point will be selected within the patrol zone using the given limits.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- This cycle will continue.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- During the patrol, the AI will detect enemy targets, which are reported through the **Detected** event.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- When enemies are detected, the AI will automatically engage the enemy.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- Until a fuel or damage treshold has been reached by the AI, or when the AI is commanded to RTB.
|
||||
-- When the fuel treshold has been reached, the airplane will fly towards the nearest friendly airbase and will land.
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- ## 1. AI_AIR_PATROL constructor
|
||||
--
|
||||
-- * @{#AI_AIR_PATROL.New}(): Creates a new AI_AIR_PATROL object.
|
||||
--
|
||||
-- ## 2. AI_AIR_PATROL is a FSM
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- ### 2.1 AI_AIR_PATROL States
|
||||
--
|
||||
-- * **None** ( Group ): The process is not started yet.
|
||||
-- * **Patrolling** ( Group ): The AI is patrolling the Patrol Zone.
|
||||
-- * **Engaging** ( Group ): The AI is engaging the bogeys.
|
||||
-- * **Returning** ( Group ): The AI is returning to Base..
|
||||
--
|
||||
-- ### 2.2 AI_AIR_PATROL Events
|
||||
--
|
||||
-- * **@{AI.AI_Patrol#AI_PATROL_ZONE.Start}**: Start the process.
|
||||
-- * **@{AI.AI_Patrol#AI_PATROL_ZONE.PatrolRoute}**: Route the AI to a new random 3D point within the Patrol Zone.
|
||||
-- * **@{#AI_AIR_PATROL.Engage}**: Let the AI engage the bogeys.
|
||||
-- * **@{#AI_AIR_PATROL.Abort}**: Aborts the engagement and return patrolling in the patrol zone.
|
||||
-- * **@{AI.AI_Patrol#AI_PATROL_ZONE.RTB}**: Route the AI to the home base.
|
||||
-- * **@{AI.AI_Patrol#AI_PATROL_ZONE.Detect}**: The AI is detecting targets.
|
||||
-- * **@{AI.AI_Patrol#AI_PATROL_ZONE.Detected}**: The AI has detected new targets.
|
||||
-- * **@{#AI_AIR_PATROL.Destroy}**: The AI has destroyed a bogey @{Wrapper.Unit}.
|
||||
-- * **@{#AI_AIR_PATROL.Destroyed}**: The AI has destroyed all bogeys @{Wrapper.Unit}s assigned in the CAS task.
|
||||
-- * **Status** ( Group ): The AI is checking status (fuel and damage). When the tresholds have been reached, the AI will RTB.
|
||||
--
|
||||
-- ## 3. Set the Range of Engagement
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- An optional range can be set in meters,
|
||||
-- that will define when the AI will engage with the detected airborne enemy targets.
|
||||
-- The range can be beyond or smaller than the range of the Patrol Zone.
|
||||
-- The range is applied at the position of the AI.
|
||||
-- Use the method @{AI.AI_CAP#AI_AIR_PATROL.SetEngageRange}() to define that range.
|
||||
--
|
||||
-- ## 4. Set the Zone of Engagement
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- An optional @{Zone} can be set,
|
||||
-- that will define when the AI will engage with the detected airborne enemy targets.
|
||||
-- Use the method @{AI.AI_Cap#AI_AIR_PATROL.SetEngageZone}() to define that Zone.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @field #AI_AIR_PATROL
|
||||
AI_AIR_PATROL = {
|
||||
ClassName = "AI_AIR_PATROL",
|
||||
}
|
||||
|
||||
--- Creates a new AI_AIR_PATROL object
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCS#Altitude PatrolFloorAltitude (optional, default = 1000m ) The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Altitude PatrolCeilingAltitude (optional, default = 1500m ) The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCS#Speed PatrolMinSpeed (optional, default = 50% of max speed) The minimum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#Speed PatrolMaxSpeed (optional, default = 75% of max speed) The maximum speed of the @{Wrapper.Group} in km/h.
|
||||
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO.
|
||||
-- @return #AI_AIR_PATROL
|
||||
function AI_AIR_PATROL:New( AI_Air, AIGroup, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, AI_Air ) -- #AI_AIR_PATROL
|
||||
|
||||
local SpeedMax = AIGroup:GetSpeedMax()
|
||||
|
||||
self.PatrolZone = PatrolZone
|
||||
|
||||
self.PatrolFloorAltitude = PatrolFloorAltitude or 1000
|
||||
self.PatrolCeilingAltitude = PatrolCeilingAltitude or 1500
|
||||
self.PatrolMinSpeed = PatrolMinSpeed or SpeedMax * 0.5
|
||||
self.PatrolMaxSpeed = PatrolMaxSpeed or SpeedMax * 0.75
|
||||
|
||||
-- defafult PatrolAltType to "RADIO" if not specified
|
||||
self.PatrolAltType = PatrolAltType or "RADIO"
|
||||
|
||||
self:AddTransition( { "Started", "Airborne", "Refuelling" }, "Patrol", "Patrolling" )
|
||||
|
||||
--- OnBefore Transition Handler for Event Patrol.
|
||||
-- @function [parent=#AI_AIR_PATROL] OnBeforePatrol
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event Patrol.
|
||||
-- @function [parent=#AI_AIR_PATROL] OnAfterPatrol
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event Patrol.
|
||||
-- @function [parent=#AI_AIR_PATROL] Patrol
|
||||
-- @param #AI_AIR_PATROL self
|
||||
|
||||
--- Asynchronous Event Trigger for Event Patrol.
|
||||
-- @function [parent=#AI_AIR_PATROL] __Patrol
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
--- OnLeave Transition Handler for State Patrolling.
|
||||
-- @function [parent=#AI_AIR_PATROL] OnLeavePatrolling
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnEnter Transition Handler for State Patrolling.
|
||||
-- @function [parent=#AI_AIR_PATROL] OnEnterPatrolling
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
self:AddTransition( "Patrolling", "PatrolRoute", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR_PATROL.
|
||||
|
||||
--- OnBefore Transition Handler for Event PatrolRoute.
|
||||
-- @function [parent=#AI_AIR_PATROL] OnBeforePatrolRoute
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @return #boolean Return false to cancel Transition.
|
||||
|
||||
--- OnAfter Transition Handler for Event PatrolRoute.
|
||||
-- @function [parent=#AI_AIR_PATROL] OnAfterPatrolRoute
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
|
||||
--- Synchronous Event Trigger for Event PatrolRoute.
|
||||
-- @function [parent=#AI_AIR_PATROL] PatrolRoute
|
||||
-- @param #AI_AIR_PATROL self
|
||||
|
||||
--- Asynchronous Event Trigger for Event PatrolRoute.
|
||||
-- @function [parent=#AI_AIR_PATROL] __PatrolRoute
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
|
||||
|
||||
self:AddTransition( "*", "Reset", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_AIR_PATROL.
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set the Engage Range when the AI will engage with airborne enemies.
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param #number EngageRange The Engage Range.
|
||||
-- @return #AI_AIR_PATROL self
|
||||
function AI_AIR_PATROL:SetEngageRange( EngageRange )
|
||||
self:F2()
|
||||
|
||||
if EngageRange then
|
||||
self.EngageRange = EngageRange
|
||||
else
|
||||
self.EngageRange = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- Set race track parameters. CAP flights will perform race track patterns rather than randomly patrolling the zone.
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param #number LegMin Min Length of the race track leg in meters. Default 10,000 m.
|
||||
-- @param #number LegMax Max length of the race track leg in meters. Default 15,000 m.
|
||||
-- @param #number HeadingMin Min heading of the race track in degrees. Default 0 deg, i.e. from South to North.
|
||||
-- @param #number HeadingMax Max heading of the race track in degrees. Default 180 deg, i.e. from South to North.
|
||||
-- @param #number DurationMin (Optional) Min duration before switching the orbit position. Default is keep same orbit until RTB or engage.
|
||||
-- @param #number DurationMax (Optional) Max duration before switching the orbit position. Default is keep same orbit until RTB or engage.
|
||||
-- @param #table CapCoordinates Table of coordinates of first race track point. Second point is determined by leg length and heading.
|
||||
-- @return #AI_AIR_PATROL self
|
||||
function AI_AIR_PATROL:SetRaceTrackPattern(LegMin, LegMax, HeadingMin, HeadingMax, DurationMin, DurationMax, CapCoordinates)
|
||||
|
||||
self.racetrack=true
|
||||
self.racetracklegmin=LegMin or 10000
|
||||
self.racetracklegmax=LegMax or 15000
|
||||
self.racetrackheadingmin=HeadingMin or 0
|
||||
self.racetrackheadingmax=HeadingMax or 180
|
||||
self.racetrackdurationmin=DurationMin
|
||||
self.racetrackdurationmax=DurationMax
|
||||
|
||||
if self.racetrackdurationmax and not self.racetrackdurationmin then
|
||||
self.racetrackdurationmin=self.racetrackdurationmax
|
||||
end
|
||||
|
||||
self.racetrackcapcoordinates=CapCoordinates
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @return #AI_AIR_PATROL self
|
||||
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR_PATROL:onafterPatrol( AIPatrol, From, Event, To )
|
||||
self:F2()
|
||||
|
||||
self:ClearTargetDistance()
|
||||
|
||||
self:__PatrolRoute( self.TaskDelay )
|
||||
|
||||
AIPatrol:OnReSpawn(
|
||||
function( PatrolGroup )
|
||||
self:__Reset( self.TaskDelay )
|
||||
self:__PatrolRoute( self.TaskDelay )
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIPatrol
|
||||
-- This statis method is called from the route path within the last task at the last waaypoint of the AIPatrol.
|
||||
-- Note that this method is required, as triggers the next route when patrolling for the AIPatrol.
|
||||
function AI_AIR_PATROL.___PatrolRoute( AIPatrol, Fsm )
|
||||
|
||||
AIPatrol:F( { "AI_AIR_PATROL.___PatrolRoute:", AIPatrol:GetName() } )
|
||||
|
||||
if AIPatrol:IsAlive() then
|
||||
Fsm:PatrolRoute()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
|
||||
-- @param #AI_AIR_PATROL self
|
||||
-- @param Wrapper.Group#GROUP AIPatrol The Group managed by the FSM.
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
function AI_AIR_PATROL:onafterPatrolRoute( AIPatrol, From, Event, To )
|
||||
|
||||
self:F2()
|
||||
|
||||
-- When RTB, don't allow anymore the routing.
|
||||
if From == "RTB" then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if AIPatrol:IsAlive() then
|
||||
|
||||
local PatrolRoute = {}
|
||||
|
||||
--- Calculate the target route point.
|
||||
|
||||
local CurrentCoord = AIPatrol:GetCoordinate()
|
||||
|
||||
local altitude= math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude )
|
||||
|
||||
local ToTargetCoord = self.PatrolZone:GetRandomPointVec2()
|
||||
ToTargetCoord:SetAlt( altitude )
|
||||
self:SetTargetDistance( ToTargetCoord ) -- For RTB status check
|
||||
|
||||
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
|
||||
local speedkmh=ToTargetSpeed
|
||||
|
||||
local FromWP = CurrentCoord:WaypointAir(
|
||||
self.PatrolAltType or "RADIO",
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
ToTargetSpeed,
|
||||
true
|
||||
)
|
||||
PatrolRoute[#PatrolRoute+1] = FromWP
|
||||
|
||||
if self.racetrack then
|
||||
|
||||
-- Random heading.
|
||||
local heading = math.random(self.racetrackheadingmin, self.racetrackheadingmax)
|
||||
|
||||
-- Random leg length.
|
||||
local leg=math.random(self.racetracklegmin, self.racetracklegmax)
|
||||
|
||||
-- Random duration if any.
|
||||
local duration = self.racetrackdurationmin
|
||||
if self.racetrackdurationmax then
|
||||
duration=math.random(self.racetrackdurationmin, self.racetrackdurationmax)
|
||||
end
|
||||
|
||||
-- CAP coordinate.
|
||||
local c0=self.PatrolZone:GetRandomCoordinate()
|
||||
if self.racetrackcapcoordinates and #self.racetrackcapcoordinates>0 then
|
||||
c0=self.racetrackcapcoordinates[math.random(#self.racetrackcapcoordinates)]
|
||||
end
|
||||
|
||||
-- Race track points.
|
||||
local c1=c0:SetAltitude(altitude) --Core.Point#COORDINATE
|
||||
local c2=c1:Translate(leg, heading):SetAltitude(altitude)
|
||||
|
||||
self:SetTargetDistance(c0) -- For RTB status check
|
||||
|
||||
-- Debug:
|
||||
self:T(string.format("Patrol zone race track: v=%.1f knots, h=%.1f ft, heading=%03d, leg=%d m, t=%s sec", UTILS.KmphToKnots(speedkmh), UTILS.MetersToFeet(altitude), heading, leg, tostring(duration)))
|
||||
--c1:MarkToAll("Race track c1")
|
||||
--c2:MarkToAll("Race track c2")
|
||||
|
||||
-- Task to orbit.
|
||||
local taskOrbit=AIPatrol:TaskOrbit(c1, altitude, UTILS.KmphToMps(speedkmh), c2)
|
||||
|
||||
-- Task function to redo the patrol at other random position.
|
||||
local taskPatrol=AIPatrol:TaskFunction("AI_A2A_PATROL.PatrolRoute", self)
|
||||
|
||||
-- Controlled task with task condition.
|
||||
local taskCond=AIPatrol:TaskCondition(nil, nil, nil, nil, duration, nil)
|
||||
local taskCont=AIPatrol:TaskControlled(taskOrbit, taskCond)
|
||||
|
||||
-- Second waypoint
|
||||
PatrolRoute[2]=c1:WaypointAirTurningPoint(self.PatrolAltType, speedkmh, {taskCont, taskPatrol}, "CAP Orbit")
|
||||
|
||||
else
|
||||
|
||||
--- Create a route point of type air.
|
||||
local ToWP = ToTargetCoord:WaypointAir(
|
||||
self.PatrolAltType,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
ToTargetSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
PatrolRoute[#PatrolRoute+1] = ToWP
|
||||
|
||||
local Tasks = {}
|
||||
Tasks[#Tasks+1] = AIPatrol:TaskFunction( "AI_AIR_PATROL.___PatrolRoute", self )
|
||||
PatrolRoute[#PatrolRoute].task = AIPatrol:TaskCombo( Tasks )
|
||||
|
||||
end
|
||||
|
||||
AIPatrol:OptionROEReturnFire()
|
||||
AIPatrol:OptionROTEvadeFire()
|
||||
|
||||
AIPatrol:Route( PatrolRoute, self.TaskDelay )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- @param Wrapper.Group#GROUP AIPatrol
|
||||
function AI_AIR_PATROL.Resume( AIPatrol, Fsm )
|
||||
|
||||
AIPatrol:F( { "AI_AIR_PATROL.Resume:", AIPatrol:GetName() } )
|
||||
if AIPatrol:IsAlive() then
|
||||
Fsm:__Reset( Fsm.TaskDelay )
|
||||
Fsm:__PatrolRoute( Fsm.TaskDelay )
|
||||
end
|
||||
|
||||
end
|
||||
289
Moose Development/Moose/AI/AI_Air_Squadron.lua
Normal file
289
Moose Development/Moose/AI/AI_Air_Squadron.lua
Normal file
@@ -0,0 +1,289 @@
|
||||
--- **AI** -- Models squadrons for airplanes and helicopters.
|
||||
--
|
||||
-- This is a class used in the @{AI_Air_Dispatcher} and derived dispatcher classes.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_Air_Squadron
|
||||
-- @image AI_Air_To_Air_Engage.JPG
|
||||
|
||||
|
||||
|
||||
--- @type AI_AIR_SQUADRON
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
|
||||
--- Implements the core functions modeling squadrons for airplanes and helicopters.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @field #AI_AIR_SQUADRON
|
||||
AI_AIR_SQUADRON = {
|
||||
ClassName = "AI_AIR_SQUADRON",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Creates a new AI_AIR_SQUADRON object
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #AI_AIR_SQUADRON
|
||||
function AI_AIR_SQUADRON:New( SquadronName, AirbaseName, TemplatePrefixes, ResourceCount )
|
||||
|
||||
self:I( { Air_Squadron = { SquadronName, AirbaseName, TemplatePrefixes, ResourceCount } } )
|
||||
|
||||
local AI_Air_Squadron = BASE:New() -- #AI_AIR_SQUADRON
|
||||
|
||||
AI_Air_Squadron.Name = SquadronName
|
||||
AI_Air_Squadron.Airbase = AIRBASE:FindByName( AirbaseName )
|
||||
AI_Air_Squadron.AirbaseName = AI_Air_Squadron.Airbase:GetName()
|
||||
if not AI_Air_Squadron.Airbase then
|
||||
error( "Cannot find airbase with name:" .. AirbaseName )
|
||||
end
|
||||
|
||||
AI_Air_Squadron.Spawn = {}
|
||||
if type( TemplatePrefixes ) == "string" then
|
||||
local SpawnTemplate = TemplatePrefixes
|
||||
self.DefenderSpawns[SpawnTemplate] = self.DefenderSpawns[SpawnTemplate] or SPAWN:New( SpawnTemplate ) -- :InitCleanUp( 180 )
|
||||
AI_Air_Squadron.Spawn[1] = self.DefenderSpawns[SpawnTemplate]
|
||||
else
|
||||
for TemplateID, SpawnTemplate in pairs( TemplatePrefixes ) do
|
||||
self.DefenderSpawns[SpawnTemplate] = self.DefenderSpawns[SpawnTemplate] or SPAWN:New( SpawnTemplate ) -- :InitCleanUp( 180 )
|
||||
AI_Air_Squadron.Spawn[#AI_Air_Squadron.Spawn+1] = self.DefenderSpawns[SpawnTemplate]
|
||||
end
|
||||
end
|
||||
AI_Air_Squadron.ResourceCount = ResourceCount
|
||||
AI_Air_Squadron.TemplatePrefixes = TemplatePrefixes
|
||||
AI_Air_Squadron.Captured = false -- Not captured. This flag will be set to true, when the airbase where the squadron is located, is captured.
|
||||
|
||||
self:SetSquadronLanguage( SquadronName, "EN" ) -- Squadrons speak English by default.
|
||||
|
||||
return AI_Air_Squadron
|
||||
end
|
||||
|
||||
--- Set the Name of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #string Name The Squadron Name.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetName( Name )
|
||||
|
||||
self.Name = Name
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the Name of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #string The Squadron Name.
|
||||
function AI_AIR_SQUADRON:GetName()
|
||||
|
||||
return self.Name
|
||||
end
|
||||
|
||||
--- Set the ResourceCount of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number ResourceCount The Squadron ResourceCount.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetResourceCount( ResourceCount )
|
||||
|
||||
self.ResourceCount = ResourceCount
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the ResourceCount of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #number The Squadron ResourceCount.
|
||||
function AI_AIR_SQUADRON:GetResourceCount()
|
||||
|
||||
return self.ResourceCount
|
||||
end
|
||||
|
||||
--- Add Resources to the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number Resources The Resources to be added.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:AddResources( Resources )
|
||||
|
||||
self.ResourceCount = self.ResourceCount + Resources
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Remove Resources to the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number Resources The Resources to be removed.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:RemoveResources( Resources )
|
||||
|
||||
self.ResourceCount = self.ResourceCount - Resources
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set the Overhead of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number Overhead The Squadron Overhead.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetOverhead( Overhead )
|
||||
|
||||
self.Overhead = Overhead
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the Overhead of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #number The Squadron Overhead.
|
||||
function AI_AIR_SQUADRON:GetOverhead()
|
||||
|
||||
return self.Overhead
|
||||
end
|
||||
|
||||
--- Set the Grouping of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number Grouping The Squadron Grouping.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetGrouping( Grouping )
|
||||
|
||||
self.Grouping = Grouping
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the Grouping of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #number The Squadron Grouping.
|
||||
function AI_AIR_SQUADRON:GetGrouping()
|
||||
|
||||
return self.Grouping
|
||||
end
|
||||
|
||||
--- Set the FuelThreshold of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number FuelThreshold The Squadron FuelThreshold.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetFuelThreshold( FuelThreshold )
|
||||
|
||||
self.FuelThreshold = FuelThreshold
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the FuelThreshold of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #number The Squadron FuelThreshold.
|
||||
function AI_AIR_SQUADRON:GetFuelThreshold()
|
||||
|
||||
return self.FuelThreshold
|
||||
end
|
||||
|
||||
--- Set the EngageProbability of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number EngageProbability The Squadron EngageProbability.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetEngageProbability( EngageProbability )
|
||||
|
||||
self.EngageProbability = EngageProbability
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the EngageProbability of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #number The Squadron EngageProbability.
|
||||
function AI_AIR_SQUADRON:GetEngageProbability()
|
||||
|
||||
return self.EngageProbability
|
||||
end
|
||||
|
||||
--- Set the Takeoff of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number Takeoff The Squadron Takeoff.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetTakeoff( Takeoff )
|
||||
|
||||
self.Takeoff = Takeoff
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the Takeoff of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #number The Squadron Takeoff.
|
||||
function AI_AIR_SQUADRON:GetTakeoff()
|
||||
|
||||
return self.Takeoff
|
||||
end
|
||||
|
||||
--- Set the Landing of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number Landing The Squadron Landing.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetLanding( Landing )
|
||||
|
||||
self.Landing = Landing
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the Landing of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #number The Squadron Landing.
|
||||
function AI_AIR_SQUADRON:GetLanding()
|
||||
|
||||
return self.Landing
|
||||
end
|
||||
|
||||
--- Set the TankerName of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #string TankerName The Squadron Tanker Name.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetTankerName( TankerName )
|
||||
|
||||
self.TankerName = TankerName
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the Tanker Name of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @return #string The Squadron Tanker Name.
|
||||
function AI_AIR_SQUADRON:GetTankerName()
|
||||
|
||||
return self.TankerName
|
||||
end
|
||||
|
||||
|
||||
--- Set the Radio of the Squadron.
|
||||
-- @param #AI_AIR_SQUADRON self
|
||||
-- @param #number RadioFrequency The frequency of communication.
|
||||
-- @param #number RadioModulation The modulation of communication.
|
||||
-- @param #number RadioPower The power in Watts of communication.
|
||||
-- @param #string Language The language of the radio speech.
|
||||
-- @return #AI_AIR_SQUADRON The Squadron.
|
||||
function AI_AIR_SQUADRON:SetRadio( RadioFrequency, RadioModulation, RadioPower, Language )
|
||||
|
||||
self.RadioFrequency = RadioFrequency
|
||||
self.RadioModulation = RadioModulation or radio.modulation.AM
|
||||
self.RadioPower = RadioPower or 100
|
||||
|
||||
if self.RadioSpeech then
|
||||
self.RadioSpeech:Stop()
|
||||
end
|
||||
|
||||
self.RadioSpeech = nil
|
||||
|
||||
self.RadioSpeech = RADIOSPEECH:New( RadioFrequency, RadioModulation )
|
||||
self.RadioSpeech.power = RadioPower
|
||||
self.RadioSpeech:Start( 0.5 )
|
||||
|
||||
self.RadioSpeech:SetLanguage( Language )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
2182
Moose Development/Moose/AI/AI_Escort.lua
Normal file
2182
Moose Development/Moose/AI/AI_Escort.lua
Normal file
File diff suppressed because it is too large
Load Diff
185
Moose Development/Moose/AI/AI_Escort_Dispatcher.lua
Normal file
185
Moose Development/Moose/AI/AI_Escort_Dispatcher.lua
Normal file
@@ -0,0 +1,185 @@
|
||||
--- **AI** -- (R2.5) - Models the automatic assignment of AI escorts to player flights.
|
||||
--
|
||||
-- ## Features:
|
||||
-- --
|
||||
-- * Provides the facilities to trigger escorts when players join flight slots.
|
||||
-- *
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_Escort_Dispatcher
|
||||
-- @image AI_Escort_Dispatcher.JPG
|
||||
|
||||
|
||||
--- @type AI_ESCORT_DISPATCHER
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
|
||||
--- Models the automatic assignment of AI escorts to player flights.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @field #AI_ESCORT_DISPATCHER
|
||||
AI_ESCORT_DISPATCHER = {
|
||||
ClassName = "AI_ESCORT_DISPATCHER",
|
||||
}
|
||||
|
||||
--- @field #list
|
||||
AI_ESCORT_DISPATCHER.AI_Escorts = {}
|
||||
|
||||
|
||||
--- Creates a new AI_ESCORT_DISPATCHER object.
|
||||
-- @param #AI_ESCORT_DISPATCHER self
|
||||
-- @param Core.Set#SET_GROUP CarrierSet The set of @{Wrapper.Group#GROUP} objects of carriers for which escorts are spawned in.
|
||||
-- @param Core.Spawn#SPAWN EscortSpawn The spawn object that will spawn in the Escorts.
|
||||
-- @param Wrapper.Airbase#AIRBASE EscortAirbase The airbase where the escorts are spawned.
|
||||
-- @param #string EscortName Name of the escort, which will also be the name of the escort menu.
|
||||
-- @param #string EscortBriefing A text showing the briefing to the player. Note that if no EscortBriefing is provided, the default briefing will be shown.
|
||||
-- @return #AI_ESCORT_DISPATCHER
|
||||
-- @usage
|
||||
--
|
||||
-- -- Create a new escort when a player joins an SU-25T plane.
|
||||
-- Create a carrier set, which contains the player slots that can be joined by the players, for which escorts will be defined.
|
||||
-- local Red_SU25T_CarrierSet = SET_GROUP:New():FilterPrefixes( "Red A2G Player Su-25T" ):FilterStart()
|
||||
--
|
||||
-- -- Create a spawn object that will spawn in the escorts, once the player has joined the player slot.
|
||||
-- local Red_SU25T_EscortSpawn = SPAWN:NewWithAlias( "Red A2G Su-25 Escort", "Red AI A2G SU-25 Escort" ):InitLimit( 10, 10 )
|
||||
--
|
||||
-- -- Create an airbase object, where the escorts will be spawned.
|
||||
-- local Red_SU25T_Airbase = AIRBASE:FindByName( AIRBASE.Caucasus.Maykop_Khanskaya )
|
||||
--
|
||||
-- -- Park the airplanes at the airbase, visible before start.
|
||||
-- Red_SU25T_EscortSpawn:ParkAtAirbase( Red_SU25T_Airbase, AIRBASE.TerminalType.OpenMedOrBig )
|
||||
--
|
||||
-- -- New create the escort dispatcher, using the carrier set, the escort spawn object at the escort airbase.
|
||||
-- -- Provide a name of the escort, which will be also the name appearing on the radio menu for the group.
|
||||
-- -- And a briefing to appear when the player joins the player slot.
|
||||
-- Red_SU25T_EscortDispatcher = AI_ESCORT_DISPATCHER:New( Red_SU25T_CarrierSet, Red_SU25T_EscortSpawn, Red_SU25T_Airbase, "Escort Su-25", "You Su-25T is escorted by one Su-25. Use the radio menu to control the escorts." )
|
||||
--
|
||||
-- -- The dispatcher needs to be started using the :Start() method.
|
||||
-- Red_SU25T_EscortDispatcher:Start()
|
||||
function AI_ESCORT_DISPATCHER:New( CarrierSet, EscortSpawn, EscortAirbase, EscortName, EscortBriefing )
|
||||
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #AI_ESCORT_DISPATCHER
|
||||
|
||||
self.CarrierSet = CarrierSet
|
||||
self.EscortSpawn = EscortSpawn
|
||||
self.EscortAirbase = EscortAirbase
|
||||
self.EscortName = EscortName
|
||||
self.EscortBriefing = EscortBriefing
|
||||
|
||||
self:SetStartState( "Idle" )
|
||||
|
||||
self:AddTransition( "Monitoring", "Monitor", "Monitoring" )
|
||||
|
||||
self:AddTransition( "Idle", "Start", "Monitoring" )
|
||||
self:AddTransition( "Monitoring", "Stop", "Idle" )
|
||||
|
||||
-- Put a Dead event handler on CarrierSet, to ensure that when a carrier is destroyed, that all internal parameters are reset.
|
||||
function self.CarrierSet.OnAfterRemoved( CarrierSet, From, Event, To, CarrierName, Carrier )
|
||||
self:F( { Carrier = Carrier:GetName() } )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function AI_ESCORT_DISPATCHER:onafterStart( From, Event, To )
|
||||
|
||||
self:HandleEvent( EVENTS.Birth )
|
||||
|
||||
self:HandleEvent( EVENTS.PlayerLeaveUnit, self.OnEventExit )
|
||||
self:HandleEvent( EVENTS.Crash, self.OnEventExit )
|
||||
self:HandleEvent( EVENTS.Dead, self.OnEventExit )
|
||||
|
||||
end
|
||||
|
||||
--- @param #AI_ESCORT_DISPATCHER self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_ESCORT_DISPATCHER:OnEventExit( EventData )
|
||||
|
||||
local PlayerGroupName = EventData.IniGroupName
|
||||
local PlayerGroup = EventData.IniGroup
|
||||
local PlayerUnit = EventData.IniUnit
|
||||
|
||||
self:I({EscortAirbase= self.EscortAirbase } )
|
||||
self:I({PlayerGroupName = PlayerGroupName } )
|
||||
self:I({PlayerGroup = PlayerGroup})
|
||||
self:I({FirstGroup = self.CarrierSet:GetFirst()})
|
||||
self:I({FindGroup = self.CarrierSet:FindGroup( PlayerGroupName )})
|
||||
|
||||
if self.CarrierSet:FindGroup( PlayerGroupName ) then
|
||||
if self.AI_Escorts[PlayerGroupName] then
|
||||
self.AI_Escorts[PlayerGroupName]:Stop()
|
||||
self.AI_Escorts[PlayerGroupName] = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- @param #AI_ESCORT_DISPATCHER self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_ESCORT_DISPATCHER:OnEventBirth( EventData )
|
||||
|
||||
local PlayerGroupName = EventData.IniGroupName
|
||||
local PlayerGroup = EventData.IniGroup
|
||||
local PlayerUnit = EventData.IniUnit
|
||||
|
||||
self:I({EscortAirbase= self.EscortAirbase } )
|
||||
self:I({PlayerGroupName = PlayerGroupName } )
|
||||
self:I({PlayerGroup = PlayerGroup})
|
||||
self:I({FirstGroup = self.CarrierSet:GetFirst()})
|
||||
self:I({FindGroup = self.CarrierSet:FindGroup( PlayerGroupName )})
|
||||
|
||||
if self.CarrierSet:FindGroup( PlayerGroupName ) then
|
||||
if not self.AI_Escorts[PlayerGroupName] then
|
||||
local LeaderUnit = PlayerUnit
|
||||
local EscortGroup = self.EscortSpawn:SpawnAtAirbase( self.EscortAirbase, SPAWN.Takeoff.Hot )
|
||||
self:I({EscortGroup = EscortGroup})
|
||||
|
||||
self:ScheduleOnce( 1,
|
||||
function( EscortGroup )
|
||||
local EscortSet = SET_GROUP:New()
|
||||
EscortSet:AddGroup( EscortGroup )
|
||||
self.AI_Escorts[PlayerGroupName] = AI_ESCORT:New( LeaderUnit, EscortSet, self.EscortName, self.EscortBriefing )
|
||||
self.AI_Escorts[PlayerGroupName]:FormationTrail( 0, 100, 0 )
|
||||
if EscortGroup:IsHelicopter() then
|
||||
self.AI_Escorts[PlayerGroupName]:MenusHelicopters()
|
||||
else
|
||||
self.AI_Escorts[PlayerGroupName]:MenusAirplanes()
|
||||
end
|
||||
self.AI_Escorts[PlayerGroupName]:__Start( 0.1 )
|
||||
end, EscortGroup
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Start Trigger for AI_ESCORT_DISPATCHER
|
||||
-- @function [parent=#AI_ESCORT_DISPATCHER] Start
|
||||
-- @param #AI_ESCORT_DISPATCHER self
|
||||
|
||||
--- Start Asynchronous Trigger for AI_ESCORT_DISPATCHER
|
||||
-- @function [parent=#AI_ESCORT_DISPATCHER] __Start
|
||||
-- @param #AI_ESCORT_DISPATCHER self
|
||||
-- @param #number Delay
|
||||
|
||||
--- Stop Trigger for AI_ESCORT_DISPATCHER
|
||||
-- @function [parent=#AI_ESCORT_DISPATCHER] Stop
|
||||
-- @param #AI_ESCORT_DISPATCHER self
|
||||
|
||||
--- Stop Asynchronous Trigger for AI_ESCORT_DISPATCHER
|
||||
-- @function [parent=#AI_ESCORT_DISPATCHER] __Stop
|
||||
-- @param #AI_ESCORT_DISPATCHER self
|
||||
-- @param #number Delay
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
146
Moose Development/Moose/AI/AI_Escort_Dispatcher_Request.lua
Normal file
146
Moose Development/Moose/AI/AI_Escort_Dispatcher_Request.lua
Normal file
@@ -0,0 +1,146 @@
|
||||
--- **AI** -- (R2.5) - Models the assignment of AI escorts to player flights upon request using the radio menu.
|
||||
--
|
||||
-- ## Features:
|
||||
--
|
||||
-- * Provides the facilities to trigger escorts when players join flight units.
|
||||
-- * Provide a menu for which escorts can be requested.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_ESCORT_DISPATCHER_REQUEST
|
||||
-- @image AI_ESCORT_DISPATCHER_REQUEST.JPG
|
||||
|
||||
|
||||
--- @type AI_ESCORT_DISPATCHER_REQUEST
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
|
||||
--- Models the assignment of AI escorts to player flights upon request using the radio menu.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @field #AI_ESCORT_DISPATCHER_REQUEST
|
||||
AI_ESCORT_DISPATCHER_REQUEST = {
|
||||
ClassName = "AI_ESCORT_DISPATCHER_REQUEST",
|
||||
}
|
||||
|
||||
--- @field #list
|
||||
AI_ESCORT_DISPATCHER_REQUEST.AI_Escorts = {}
|
||||
|
||||
|
||||
--- Creates a new AI_ESCORT_DISPATCHER_REQUEST object.
|
||||
-- @param #AI_ESCORT_DISPATCHER_REQUEST self
|
||||
-- @param Core.Set#SET_GROUP CarrierSet The set of @{Wrapper.Group#GROUP} objects of carriers for which escorts are requested.
|
||||
-- @param Core.Spawn#SPAWN EscortSpawn The spawn object that will spawn in the Escorts.
|
||||
-- @param Wrapper.Airbase#AIRBASE EscortAirbase The airbase where the escorts are spawned.
|
||||
-- @param #string EscortName Name of the escort, which will also be the name of the escort menu.
|
||||
-- @param #string EscortBriefing A text showing the briefing to the player. Note that if no EscortBriefing is provided, the default briefing will be shown.
|
||||
-- @return #AI_ESCORT_DISPATCHER_REQUEST
|
||||
function AI_ESCORT_DISPATCHER_REQUEST:New( CarrierSet, EscortSpawn, EscortAirbase, EscortName, EscortBriefing )
|
||||
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #AI_ESCORT_DISPATCHER_REQUEST
|
||||
|
||||
self.CarrierSet = CarrierSet
|
||||
self.EscortSpawn = EscortSpawn
|
||||
self.EscortAirbase = EscortAirbase
|
||||
self.EscortName = EscortName
|
||||
self.EscortBriefing = EscortBriefing
|
||||
|
||||
self:SetStartState( "Idle" )
|
||||
|
||||
self:AddTransition( "Monitoring", "Monitor", "Monitoring" )
|
||||
|
||||
self:AddTransition( "Idle", "Start", "Monitoring" )
|
||||
self:AddTransition( "Monitoring", "Stop", "Idle" )
|
||||
|
||||
-- Put a Dead event handler on CarrierSet, to ensure that when a carrier is destroyed, that all internal parameters are reset.
|
||||
function self.CarrierSet.OnAfterRemoved( CarrierSet, From, Event, To, CarrierName, Carrier )
|
||||
self:F( { Carrier = Carrier:GetName() } )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function AI_ESCORT_DISPATCHER_REQUEST:onafterStart( From, Event, To )
|
||||
|
||||
self:HandleEvent( EVENTS.Birth )
|
||||
|
||||
self:HandleEvent( EVENTS.PlayerLeaveUnit, self.OnEventExit )
|
||||
self:HandleEvent( EVENTS.Crash, self.OnEventExit )
|
||||
self:HandleEvent( EVENTS.Dead, self.OnEventExit )
|
||||
|
||||
end
|
||||
|
||||
--- @param #AI_ESCORT_DISPATCHER_REQUEST self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_ESCORT_DISPATCHER_REQUEST:OnEventExit( EventData )
|
||||
|
||||
local PlayerGroupName = EventData.IniGroupName
|
||||
local PlayerGroup = EventData.IniGroup
|
||||
local PlayerUnit = EventData.IniUnit
|
||||
|
||||
if self.CarrierSet:FindGroup( PlayerGroupName ) then
|
||||
if self.AI_Escorts[PlayerGroupName] then
|
||||
self.AI_Escorts[PlayerGroupName]:Stop()
|
||||
self.AI_Escorts[PlayerGroupName] = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- @param #AI_ESCORT_DISPATCHER_REQUEST self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function AI_ESCORT_DISPATCHER_REQUEST:OnEventBirth( EventData )
|
||||
|
||||
local PlayerGroupName = EventData.IniGroupName
|
||||
local PlayerGroup = EventData.IniGroup
|
||||
local PlayerUnit = EventData.IniUnit
|
||||
|
||||
if self.CarrierSet:FindGroup( PlayerGroupName ) then
|
||||
if not self.AI_Escorts[PlayerGroupName] then
|
||||
local LeaderUnit = PlayerUnit
|
||||
self:ScheduleOnce( 0.1,
|
||||
function()
|
||||
self.AI_Escorts[PlayerGroupName] = AI_ESCORT_REQUEST:New( LeaderUnit, self.EscortSpawn, self.EscortAirbase, self.EscortName, self.EscortBriefing )
|
||||
self.AI_Escorts[PlayerGroupName]:FormationTrail( 0, 100, 0 )
|
||||
if PlayerGroup:IsHelicopter() then
|
||||
self.AI_Escorts[PlayerGroupName]:MenusHelicopters()
|
||||
else
|
||||
self.AI_Escorts[PlayerGroupName]:MenusAirplanes()
|
||||
end
|
||||
self.AI_Escorts[PlayerGroupName]:__Start( 0.1 )
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Start Trigger for AI_ESCORT_DISPATCHER_REQUEST
|
||||
-- @function [parent=#AI_ESCORT_DISPATCHER_REQUEST] Start
|
||||
-- @param #AI_ESCORT_DISPATCHER_REQUEST self
|
||||
|
||||
--- Start Asynchronous Trigger for AI_ESCORT_DISPATCHER_REQUEST
|
||||
-- @function [parent=#AI_ESCORT_DISPATCHER_REQUEST] __Start
|
||||
-- @param #AI_ESCORT_DISPATCHER_REQUEST self
|
||||
-- @param #number Delay
|
||||
|
||||
--- Stop Trigger for AI_ESCORT_DISPATCHER_REQUEST
|
||||
-- @function [parent=#AI_ESCORT_DISPATCHER_REQUEST] Stop
|
||||
-- @param #AI_ESCORT_DISPATCHER_REQUEST self
|
||||
|
||||
--- Stop Asynchronous Trigger for AI_ESCORT_DISPATCHER_REQUEST
|
||||
-- @function [parent=#AI_ESCORT_DISPATCHER_REQUEST] __Stop
|
||||
-- @param #AI_ESCORT_DISPATCHER_REQUEST self
|
||||
-- @param #number Delay
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
316
Moose Development/Moose/AI/AI_Escort_Request.lua
Normal file
316
Moose Development/Moose/AI/AI_Escort_Request.lua
Normal file
@@ -0,0 +1,316 @@
|
||||
--- **Functional** -- Taking the lead of AI escorting your flight or of other AI, upon request using the menu.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Features:
|
||||
--
|
||||
-- * Escort navigation commands.
|
||||
-- * Escort hold at position commands.
|
||||
-- * Escorts reporting detected targets.
|
||||
-- * Escorts scanning targets in advance.
|
||||
-- * Escorts attacking specific targets.
|
||||
-- * Request assistance from other groups for attack.
|
||||
-- * Manage rule of engagement of escorts.
|
||||
-- * Manage the allowed evasion techniques of escorts.
|
||||
-- * Make escort to execute a defined mission or path.
|
||||
-- * Escort tactical situation reporting.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Missions:
|
||||
--
|
||||
-- [ESC - Escorting](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/master/ESC%20-%20Escorting)
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- Allows you to interact with escorting AI on your flight and take the lead.
|
||||
--
|
||||
-- Each escorting group can be commanded with a complete set of radio commands (radio menu in your flight, and then F10).
|
||||
--
|
||||
-- The radio commands will vary according the category of the group. The richest set of commands are with helicopters and airPlanes.
|
||||
-- Ships and Ground troops will have a more limited set, but they can provide support through the bombing of targets designated by the other escorts.
|
||||
--
|
||||
-- Escorts detect targets using a built-in detection mechanism. The detected targets are reported at a specified time interval.
|
||||
-- Once targets are reported, each escort has these targets as menu options to command the attack of these targets.
|
||||
-- Targets are by default grouped per area of 5000 meters, but the kind of detection and the grouping range can be altered.
|
||||
--
|
||||
-- Different formations can be selected in the Flight menu: Trail, Stack, Left Line, Right Line, Left Wing, Right Wing, Central Wing and Boxed formations are available.
|
||||
-- The Flight menu also allows for a mass attack, where all of the escorts are commanded to attack a target.
|
||||
--
|
||||
-- Escorts can emit flares to reports their location. They can be commanded to hold at a location, which can be their current or the leader location.
|
||||
-- In this way, you can spread out the escorts over the battle field before a coordinated attack.
|
||||
--
|
||||
-- But basically, the escort class provides 4 modes of operation, and depending on the mode, you are either leading the flight, or following the flight.
|
||||
--
|
||||
-- ## Leading the flight
|
||||
--
|
||||
-- When leading the flight, you are expected to guide the escorts towards the target areas,
|
||||
-- and carefully coordinate the attack based on the threat levels reported, and the available weapons
|
||||
-- carried by the escorts. Ground ships or ground troops can execute A-assisted attacks, when they have long-range ground precision weapons for attack.
|
||||
--
|
||||
-- ## Following the flight
|
||||
--
|
||||
-- Escorts can be commanded to execute a specific mission path. In this mode, the escorts are in the lead.
|
||||
-- You as a player, are following the escorts, and are commanding them to progress the mission while
|
||||
-- ensuring that the escorts survive. You are joining the escorts in the battlefield. They will detect and report targets
|
||||
-- and you will ensure that the attacks are well coordinated, assigning the correct escort type for the detected target
|
||||
-- type. Once the attack is finished, the escort will resume the mission it was assigned.
|
||||
-- In other words, you can use the escorts for reconnaissance, and for guiding the attack.
|
||||
-- Imagine you as a mi-8 pilot, assigned to pickup cargo. Two ka-50s are guiding the way, and you are
|
||||
-- following. You are in control. The ka-50s detect targets, report them, and you command how the attack
|
||||
-- will commence and from where. You can control where the escorts are holding position and which targets
|
||||
-- are attacked first. You are in control how the ka-50s will follow their mission path.
|
||||
--
|
||||
-- Escorts can act as part of a AI A2G dispatcher offensive. In this way, You was a player are in control.
|
||||
-- The mission is defined by the A2G dispatcher, and you are responsible to join the flight and ensure that the
|
||||
-- attack is well coordinated.
|
||||
--
|
||||
-- It is with great proud that I present you this class, and I hope you will enjoy the functionality and the dynamism
|
||||
-- it brings in your DCS world simulations.
|
||||
--
|
||||
-- # RADIO MENUs that can be created:
|
||||
--
|
||||
-- Find a summary below of the current available commands:
|
||||
--
|
||||
-- ## Navigation ...:
|
||||
--
|
||||
-- Escort group navigation functions:
|
||||
--
|
||||
-- * **"Join-Up":** The escort group fill follow you in the assigned formation.
|
||||
-- * **"Flare":** Provides menu commands to let the escort group shoot a flare in the air in a color.
|
||||
-- * **"Smoke":** Provides menu commands to let the escort group smoke the air in a color. Note that smoking is only available for ground and naval troops.
|
||||
--
|
||||
-- ## Hold position ...:
|
||||
--
|
||||
-- Escort group navigation functions:
|
||||
--
|
||||
-- * **"At current location":** The escort group will hover above the ground at the position they were. The altitude can be specified as a parameter.
|
||||
-- * **"At my location":** The escort group will hover or orbit at the position where you are. The escort will fly to your location and hold position. The altitude can be specified as a parameter.
|
||||
--
|
||||
-- ## Report targets ...:
|
||||
--
|
||||
-- Report targets will make the escort group to report any target that it identifies within detection range. Any detected target can be attacked using the "Attack Targets" menu function. (see below).
|
||||
--
|
||||
-- * **"Report now":** Will report the current detected targets.
|
||||
-- * **"Report targets on":** Will make the escorts to report the detected targets and will fill the "Attack Targets" menu list.
|
||||
-- * **"Report targets off":** Will stop detecting targets.
|
||||
--
|
||||
-- ## Attack targets ...:
|
||||
--
|
||||
-- This menu item will list all detected targets within a 15km range. Depending on the level of detection (known/unknown) and visuality, the targets type will also be listed.
|
||||
-- This menu will be available in Flight menu or in each Escort menu.
|
||||
--
|
||||
-- ## Scan targets ...:
|
||||
--
|
||||
-- Menu items to pop-up the escort group for target scanning. After scanning, the escort group will resume with the mission or rejoin formation.
|
||||
--
|
||||
-- * **"Scan targets 30 seconds":** Scan 30 seconds for targets.
|
||||
-- * **"Scan targets 60 seconds":** Scan 60 seconds for targets.
|
||||
--
|
||||
-- ## Request assistance from ...:
|
||||
--
|
||||
-- This menu item will list all detected targets within a 15km range, similar as with the menu item **Attack Targets**.
|
||||
-- This menu item allows to request attack support from other ground based escorts supporting the current escort.
|
||||
-- eg. the function allows a player to request support from the Ship escort to attack a target identified by the Plane escort with its Tomahawk missiles.
|
||||
-- eg. the function allows a player to request support from other Planes escorting to bomb the unit with illumination missiles or bombs, so that the main plane escort can attack the area.
|
||||
--
|
||||
-- ## ROE ...:
|
||||
--
|
||||
-- Sets the Rules of Engagement (ROE) of the escort group when in flight.
|
||||
--
|
||||
-- * **"Hold Fire":** The escort group will hold fire.
|
||||
-- * **"Return Fire":** The escort group will return fire.
|
||||
-- * **"Open Fire":** The escort group will open fire on designated targets.
|
||||
-- * **"Weapon Free":** The escort group will engage with any target.
|
||||
--
|
||||
-- ## Evasion ...:
|
||||
--
|
||||
-- Will define the evasion techniques that the escort group will perform during flight or combat.
|
||||
--
|
||||
-- * **"Fight until death":** The escort group will have no reaction to threats.
|
||||
-- * **"Use flares, chaff and jammers":** The escort group will use passive defense using flares and jammers. No evasive manoeuvres are executed.
|
||||
-- * **"Evade enemy fire":** The rescort group will evade enemy fire before firing.
|
||||
-- * **"Go below radar and evade fire":** The escort group will perform evasive vertical manoeuvres.
|
||||
--
|
||||
-- ## Resume Mission ...:
|
||||
--
|
||||
-- Escort groups can have their own mission. This menu item will allow the escort group to resume their Mission from a given waypoint.
|
||||
-- Note that this is really fantastic, as you now have the dynamic of taking control of the escort groups, and allowing them to resume their path or mission.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Authors: **FlightControl**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module AI.AI_Escort
|
||||
-- @image Escorting.JPG
|
||||
|
||||
|
||||
|
||||
--- @type AI_ESCORT_REQUEST
|
||||
-- @extends AI.AI_Escort#AI_ESCORT
|
||||
|
||||
--- AI_ESCORT_REQUEST class
|
||||
--
|
||||
-- # AI_ESCORT_REQUEST construction methods.
|
||||
--
|
||||
-- Create a new AI_ESCORT_REQUEST object with the @{#AI_ESCORT_REQUEST.New} method:
|
||||
--
|
||||
-- * @{#AI_ESCORT_REQUEST.New}: Creates a new AI_ESCORT_REQUEST object from a @{Wrapper.Group#GROUP} for a @{Wrapper.Client#CLIENT}, with an optional briefing text.
|
||||
--
|
||||
-- @usage
|
||||
-- -- Declare a new EscortPlanes object as follows:
|
||||
--
|
||||
-- -- First find the GROUP object and the CLIENT object.
|
||||
-- local EscortUnit = CLIENT:FindByName( "Unit Name" ) -- The Unit Name is the name of the unit flagged with the skill Client in the mission editor.
|
||||
-- local EscortGroup = GROUP:FindByName( "Group Name" ) -- The Group Name is the name of the group that will escort the Escort Client.
|
||||
--
|
||||
-- -- Now use these 2 objects to construct the new EscortPlanes object.
|
||||
-- EscortPlanes = AI_ESCORT_REQUEST:New( EscortUnit, EscortGroup, "Desert", "Welcome to the mission. You are escorted by a plane with code name 'Desert', which can be instructed through the F10 radio menu." )
|
||||
--
|
||||
-- @field #AI_ESCORT_REQUEST
|
||||
AI_ESCORT_REQUEST = {
|
||||
ClassName = "AI_ESCORT_REQUEST",
|
||||
}
|
||||
|
||||
--- AI_ESCORT_REQUEST.Mode class
|
||||
-- @type AI_ESCORT_REQUEST.MODE
|
||||
-- @field #number FOLLOW
|
||||
-- @field #number MISSION
|
||||
|
||||
--- MENUPARAM type
|
||||
-- @type MENUPARAM
|
||||
-- @field #AI_ESCORT_REQUEST ParamSelf
|
||||
-- @field #Distance ParamDistance
|
||||
-- @field #function ParamFunction
|
||||
-- @field #string ParamMessage
|
||||
|
||||
--- AI_ESCORT_REQUEST class constructor for an AI group
|
||||
-- @param #AI_ESCORT_REQUEST self
|
||||
-- @param Wrapper.Client#CLIENT EscortUnit The client escorted by the EscortGroup.
|
||||
-- @param Core.Spawn#SPAWN EscortSpawn The spawn object of AI, escorting the EscortUnit.
|
||||
-- @param Wrapper.Airbase#AIRBASE EscortAirbase The airbase where escorts will be spawned once requested.
|
||||
-- @param #string EscortName Name of the escort.
|
||||
-- @param #string EscortBriefing A text showing the AI_ESCORT_REQUEST briefing to the player. Note that if no EscortBriefing is provided, the default briefing will be shown.
|
||||
-- @return #AI_ESCORT_REQUEST
|
||||
-- @usage
|
||||
-- EscortSpawn = SPAWN:NewWithAlias( "Red A2G Escort Template", "Red A2G Escort AI" ):InitLimit( 10, 10 )
|
||||
-- EscortSpawn:ParkAtAirbase( AIRBASE:FindByName( AIRBASE.Caucasus.Sochi_Adler ), AIRBASE.TerminalType.OpenBig )
|
||||
--
|
||||
-- local EscortUnit = UNIT:FindByName( "Red A2G Pilot" )
|
||||
--
|
||||
-- Escort = AI_ESCORT_REQUEST:New( EscortUnit, EscortSpawn, AIRBASE:FindByName(AIRBASE.Caucasus.Sochi_Adler), "A2G", "Briefing" )
|
||||
-- Escort:FormationTrail( 50, 100, 100 )
|
||||
-- Escort:Menus()
|
||||
-- Escort:__Start( 5 )
|
||||
function AI_ESCORT_REQUEST:New( EscortUnit, EscortSpawn, EscortAirbase, EscortName, EscortBriefing )
|
||||
|
||||
local EscortGroupSet = SET_GROUP:New():FilterDeads():FilterCrashes()
|
||||
local self = BASE:Inherit( self, AI_ESCORT:New( EscortUnit, EscortGroupSet, EscortName, EscortBriefing ) ) -- #AI_ESCORT_REQUEST
|
||||
|
||||
self.EscortGroupSet = EscortGroupSet
|
||||
self.EscortSpawn = EscortSpawn
|
||||
self.EscortAirbase = EscortAirbase
|
||||
|
||||
self.LeaderGroup = self.PlayerUnit:GetGroup()
|
||||
|
||||
self.Detection = DETECTION_AREAS:New( self.EscortGroupSet, 5000 )
|
||||
self.Detection:__Start( 30 )
|
||||
|
||||
self.SpawnMode = self.__Enum.Mode.Mission
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- @param #AI_ESCORT_REQUEST self
|
||||
function AI_ESCORT_REQUEST:SpawnEscort()
|
||||
|
||||
local EscortGroup = self.EscortSpawn:SpawnAtAirbase( self.EscortAirbase, SPAWN.Takeoff.Hot )
|
||||
|
||||
self:ScheduleOnce( 0.1,
|
||||
function( EscortGroup )
|
||||
|
||||
EscortGroup:OptionROTVertical()
|
||||
EscortGroup:OptionROEHoldFire()
|
||||
|
||||
self.EscortGroupSet:AddGroup( EscortGroup )
|
||||
|
||||
local LeaderEscort = self.EscortGroupSet:GetFirst() -- Wrapper.Group#GROUP
|
||||
local Report = REPORT:New()
|
||||
Report:Add( "Joining Up " .. self.EscortGroupSet:GetUnitTypeNames():Text( ", " ) .. " from " .. LeaderEscort:GetCoordinate():ToString( self.EscortUnit ) )
|
||||
LeaderEscort:MessageTypeToGroup( Report:Text(), MESSAGE.Type.Information, self.PlayerUnit )
|
||||
|
||||
self:SetFlightModeFormation( EscortGroup )
|
||||
self:FormationTrail()
|
||||
|
||||
self:_InitFlightMenus()
|
||||
self:_InitEscortMenus( EscortGroup )
|
||||
self:_InitEscortRoute( EscortGroup )
|
||||
|
||||
--- @param #AI_ESCORT self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function EscortGroup:OnEventDeadOrCrash( EventData )
|
||||
self:F( { "EventDead", EventData } )
|
||||
self.EscortMenu:Remove()
|
||||
end
|
||||
|
||||
EscortGroup:HandleEvent( EVENTS.Dead, EscortGroup.OnEventDeadOrCrash )
|
||||
EscortGroup:HandleEvent( EVENTS.Crash, EscortGroup.OnEventDeadOrCrash )
|
||||
|
||||
end, EscortGroup
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
--- @param #AI_ESCORT_REQUEST self
|
||||
-- @param Core.Set#SET_GROUP EscortGroupSet
|
||||
function AI_ESCORT_REQUEST:onafterStart( EscortGroupSet )
|
||||
|
||||
self:F()
|
||||
|
||||
if not self.MenuRequestEscort then
|
||||
self.MainMenu = MENU_GROUP:New( self.PlayerGroup, self.EscortName )
|
||||
self.MenuRequestEscort = MENU_GROUP_COMMAND:New( self.LeaderGroup, "Request new escort ", self.MainMenu,
|
||||
function()
|
||||
self:SpawnEscort()
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
self:GetParent( self ).onafterStart( self, EscortGroupSet )
|
||||
|
||||
self:HandleEvent( EVENTS.Dead, self.OnEventDeadOrCrash )
|
||||
self:HandleEvent( EVENTS.Crash, self.OnEventDeadOrCrash )
|
||||
|
||||
end
|
||||
|
||||
--- @param #AI_ESCORT_REQUEST self
|
||||
-- @param Core.Set#SET_GROUP EscortGroupSet
|
||||
function AI_ESCORT_REQUEST:onafterStop( EscortGroupSet )
|
||||
|
||||
self:F()
|
||||
|
||||
EscortGroupSet:ForEachGroup(
|
||||
--- @param Core.Group#GROUP EscortGroup
|
||||
function( EscortGroup )
|
||||
EscortGroup:WayPointInitialize()
|
||||
|
||||
EscortGroup:OptionROTVertical()
|
||||
EscortGroup:OptionROEOpenFire()
|
||||
end
|
||||
)
|
||||
|
||||
self.Detection:Stop()
|
||||
|
||||
self.MainMenu:Remove()
|
||||
|
||||
end
|
||||
|
||||
--- Set the spawn mode to be mission execution.
|
||||
-- @param #AI_ESCORT_REQUEST self
|
||||
function AI_ESCORT_REQUEST:SetEscortSpawnMission()
|
||||
|
||||
self.SpawnMode = self.__Enum.Mode.Mission
|
||||
|
||||
end
|
||||
@@ -36,6 +36,7 @@
|
||||
-- @field #boolean ReportTargets If true, nearby targets are reported.
|
||||
-- @Field DCSTypes#AI.Option.Air.val.ROE OptionROE Which ROE is set to the FollowGroup.
|
||||
-- @field DCSTypes#AI.Option.Air.val.REACTION_ON_THREAT OptionReactionOnThreat Which REACTION_ON_THREAT is set to the FollowGroup.
|
||||
-- @field #number dtFollow Time step between position updates.
|
||||
|
||||
|
||||
--- Build large formations, make AI follow a @{Wrapper.Client#CLIENT} (player) leader or a @{Wrapper.Unit#UNIT} (AI) leader.
|
||||
@@ -106,12 +107,59 @@ AI_FORMATION = {
|
||||
FollowScheduler = nil,
|
||||
OptionROE = AI.Option.Air.val.ROE.OPEN_FIRE,
|
||||
OptionReactionOnThreat = AI.Option.Air.val.REACTION_ON_THREAT.ALLOW_ABORT_MISSION,
|
||||
dtFollow = 0.5,
|
||||
}
|
||||
|
||||
--- AI_FORMATION.Mode class
|
||||
-- @type AI_FORMATION.MODE
|
||||
-- @field #number FOLLOW
|
||||
-- @field #number MISSION
|
||||
AI_FORMATION.__Enum = {}
|
||||
|
||||
--- @type AI_FORMATION.__Enum.Formation
|
||||
-- @field #number None
|
||||
-- @field #number Line
|
||||
-- @field #number Trail
|
||||
-- @field #number Stack
|
||||
-- @field #number LeftLine
|
||||
-- @field #number RightLine
|
||||
-- @field #number LeftWing
|
||||
-- @field #number RightWing
|
||||
-- @field #number Vic
|
||||
-- @field #number Box
|
||||
AI_FORMATION.__Enum.Formation = {
|
||||
None = 0,
|
||||
Mission = 1,
|
||||
Line = 2,
|
||||
Trail = 3,
|
||||
Stack = 4,
|
||||
LeftLine = 5,
|
||||
RightLine = 6,
|
||||
LeftWing = 7,
|
||||
RightWing = 8,
|
||||
Vic = 9,
|
||||
Box = 10,
|
||||
}
|
||||
|
||||
--- @type AI_FORMATION.__Enum.Mode
|
||||
-- @field #number Mission
|
||||
-- @field #number Formation
|
||||
AI_FORMATION.__Enum.Mode = {
|
||||
Mission = "M",
|
||||
Formation = "F",
|
||||
Attack = "A",
|
||||
Reconnaissance = "R",
|
||||
}
|
||||
|
||||
--- @type AI_FORMATION.__Enum.ReportType
|
||||
-- @field #number All
|
||||
-- @field #number Airborne
|
||||
-- @field #number GroundRadar
|
||||
-- @field #number Ground
|
||||
AI_FORMATION.__Enum.ReportType = {
|
||||
Airborne = "*",
|
||||
Airborne = "A",
|
||||
GroundRadar = "R",
|
||||
Ground = "G",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- MENUPARAM type
|
||||
-- @type MENUPARAM
|
||||
@@ -125,6 +173,7 @@ AI_FORMATION = {
|
||||
-- @param Wrapper.Unit#UNIT FollowUnit The UNIT leading the FolllowGroupSet.
|
||||
-- @param Core.Set#SET_GROUP FollowGroupSet The group AI escorting the FollowUnit.
|
||||
-- @param #string FollowName Name of the escort.
|
||||
-- @param #string FollowBriefing Briefing.
|
||||
-- @return #AI_FORMATION self
|
||||
function AI_FORMATION:New( FollowUnit, FollowGroupSet, FollowName, FollowBriefing ) --R2.1
|
||||
local self = BASE:Inherit( self, FSM_SET:New( FollowGroupSet ) )
|
||||
@@ -133,13 +182,20 @@ function AI_FORMATION:New( FollowUnit, FollowGroupSet, FollowName, FollowBriefin
|
||||
self.FollowUnit = FollowUnit -- Wrapper.Unit#UNIT
|
||||
self.FollowGroupSet = FollowGroupSet -- Core.Set#SET_GROUP
|
||||
|
||||
self.FollowGroupSet:ForEachGroup(
|
||||
function( FollowGroup )
|
||||
self:E("Following")
|
||||
FollowGroup:SetState( self, "Mode", self.__Enum.Mode.Formation )
|
||||
end
|
||||
)
|
||||
|
||||
self:SetFlightRandomization( 2 )
|
||||
|
||||
self:SetStartState( "None" )
|
||||
|
||||
self:AddTransition( "*", "Stop", "Stopped" )
|
||||
|
||||
self:AddTransition( "None", "Start", "Following" )
|
||||
self:AddTransition( {"None", "Stopped"}, "Start", "Following" )
|
||||
|
||||
self:AddTransition( "*", "FormationLine", "*" )
|
||||
--- FormationLine Handler OnBefore for AI_FORMATION
|
||||
@@ -620,6 +676,16 @@ function AI_FORMATION:New( FollowUnit, FollowGroupSet, FollowName, FollowBriefin
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set time interval between updates of the formation.
|
||||
-- @param #AI_FORMATION self
|
||||
-- @param #number dt Time step in seconds between formation updates. Default is every 0.5 seconds.
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:SetFollowTimeInterval(dt) --R2.1
|
||||
self.dtFollow=dt or 0.5
|
||||
return self
|
||||
end
|
||||
|
||||
--- This function is for test, it will put on the frequency of the FollowScheduler a red smoke at the direction vector calculated for the escort to fly to.
|
||||
-- This allows to visualize where the escort is flying to.
|
||||
-- @param #AI_FORMATION self
|
||||
@@ -643,8 +709,15 @@ end
|
||||
-- @param #nubmer ZStart The start position on the Z-axis in meters for the first group.
|
||||
-- @param #number ZSpace The space between groups on the Z-axis in meters for each sequent group.
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:onafterFormationLine( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, YSpace, ZStart, ZSpace ) --R2.1
|
||||
self:F( { FollowGroupSet, From , Event ,To, XStart, XSpace, YStart, YSpace, ZStart, ZSpace } )
|
||||
function AI_FORMATION:onafterFormationLine( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, YSpace, ZStart, ZSpace, Formation ) --R2.1
|
||||
self:F( { FollowGroupSet, From , Event ,To, XStart, XSpace, YStart, YSpace, ZStart, ZSpace, Formation } )
|
||||
|
||||
XStart = XStart or self.XStart
|
||||
XSpace = XSpace or self.XSpace
|
||||
YStart = YStart or self.YStart
|
||||
YSpace = YSpace or self.YSpace
|
||||
ZStart = ZStart or self.ZStart
|
||||
ZSpace = ZSpace or self.ZSpace
|
||||
|
||||
FollowGroupSet:Flush( self )
|
||||
|
||||
@@ -662,6 +735,8 @@ function AI_FORMATION:onafterFormationLine( FollowGroupSet, From , Event , To, X
|
||||
local Vec3 = PointVec3:GetVec3()
|
||||
FollowGroup:SetState( self, "FormationVec3", Vec3 )
|
||||
i = i + 1
|
||||
|
||||
FollowGroup:SetState( FollowGroup, "Formation", Formation )
|
||||
end
|
||||
|
||||
return self
|
||||
@@ -680,7 +755,7 @@ end
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:onafterFormationTrail( FollowGroupSet, From , Event , To, XStart, XSpace, YStart ) --R2.1
|
||||
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,0,0)
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,0,0, self.__Enum.Formation.Trail )
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -699,7 +774,7 @@ end
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:onafterFormationStack( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, YSpace ) --R2.1
|
||||
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,YSpace,0,0)
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,YSpace,0,0, self.__Enum.Formation.Stack )
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -720,7 +795,7 @@ end
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:onafterFormationLeftLine( FollowGroupSet, From , Event , To, XStart, YStart, ZStart, ZSpace ) --R2.1
|
||||
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,0,YStart,0,ZStart,ZSpace)
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,0,YStart,0,-ZStart,-ZSpace, self.__Enum.Formation.LeftLine )
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -739,7 +814,7 @@ end
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:onafterFormationRightLine( FollowGroupSet, From , Event , To, XStart, YStart, ZStart, ZSpace ) --R2.1
|
||||
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,0,YStart,0,-ZStart,-ZSpace)
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,0,YStart,0,ZStart,ZSpace,self.__Enum.Formation.RightLine)
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -758,7 +833,7 @@ end
|
||||
-- @param #number ZSpace The space between groups on the Z-axis in meters for each sequent group.
|
||||
function AI_FORMATION:onafterFormationLeftWing( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, ZStart, ZSpace ) --R2.1
|
||||
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,ZStart,ZSpace)
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,-ZStart,-ZSpace,self.__Enum.Formation.LeftWing)
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -778,7 +853,7 @@ end
|
||||
-- @param #number ZSpace The space between groups on the Z-axis in meters for each sequent group.
|
||||
function AI_FORMATION:onafterFormationRightWing( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, ZStart, ZSpace ) --R2.1
|
||||
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,-ZStart,-ZSpace)
|
||||
self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,ZStart,ZSpace,self.__Enum.Formation.RightWing)
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -816,6 +891,7 @@ function AI_FORMATION:onafterFormationCenterWing( FollowGroupSet, From , Event ,
|
||||
local Vec3 = PointVec3:GetVec3()
|
||||
FollowGroup:SetState( self, "FormationVec3", Vec3 )
|
||||
i = i + 1
|
||||
FollowGroup:SetState( FollowGroup, "Formation", self.__Enum.Formation.Vic )
|
||||
end
|
||||
|
||||
return self
|
||||
@@ -875,6 +951,7 @@ function AI_FORMATION:onafterFormationBox( FollowGroupSet, From , Event , To, XS
|
||||
local Vec3 = PointVec3:GetVec3()
|
||||
FollowGroup:SetState( self, "FormationVec3", Vec3 )
|
||||
i = i + 1
|
||||
FollowGroup:SetState( FollowGroup, "Formation", self.__Enum.Formation.Box )
|
||||
end
|
||||
|
||||
return self
|
||||
@@ -893,17 +970,126 @@ function AI_FORMATION:SetFlightRandomization( FlightRandomization ) --R2.1
|
||||
end
|
||||
|
||||
|
||||
--- @param Follow#AI_FORMATION self
|
||||
function AI_FORMATION:onenterFollowing( FollowGroupSet ) --R2.1
|
||||
self:F( )
|
||||
--- Gets your escorts to flight mode.
|
||||
-- @param #AI_FORMATION self
|
||||
-- @param Wrapper.Group#GROUP FollowGroup FollowGroup.
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:GetFlightMode( FollowGroup )
|
||||
|
||||
if FollowGroup then
|
||||
FollowGroup:SetState( FollowGroup, "PreviousMode", FollowGroup:GetState( FollowGroup, "Mode" ) )
|
||||
FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Mission )
|
||||
end
|
||||
|
||||
|
||||
return FollowGroup:GetState( FollowGroup, "Mode" )
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- This sets your escorts to fly a mission.
|
||||
-- @param #AI_FORMATION self
|
||||
-- @param Wrapper.Group#GROUP FollowGroup FollowGroup.
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:SetFlightModeMission( FollowGroup )
|
||||
|
||||
if FollowGroup then
|
||||
FollowGroup:SetState( FollowGroup, "PreviousMode", FollowGroup:GetState( FollowGroup, "Mode" ) )
|
||||
FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Mission )
|
||||
else
|
||||
self.EscortGroupSet:ForSomeGroupAlive(
|
||||
--- @param Core.Group#GROUP EscortGroup
|
||||
function( FollowGroup )
|
||||
FollowGroup:SetState( FollowGroup, "PreviousMode", FollowGroup:GetState( FollowGroup, "Mode" ) )
|
||||
FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Mission )
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- This sets your escorts to execute an attack.
|
||||
-- @param #AI_FORMATION self
|
||||
-- @param Wrapper.Group#GROUP FollowGroup FollowGroup.
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:SetFlightModeAttack( FollowGroup )
|
||||
|
||||
if FollowGroup then
|
||||
FollowGroup:SetState( FollowGroup, "PreviousMode", FollowGroup:GetState( FollowGroup, "Mode" ) )
|
||||
FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Attack )
|
||||
else
|
||||
self.EscortGroupSet:ForSomeGroupAlive(
|
||||
--- @param Core.Group#GROUP EscortGroup
|
||||
function( FollowGroup )
|
||||
FollowGroup:SetState( FollowGroup, "PreviousMode", FollowGroup:GetState( FollowGroup, "Mode" ) )
|
||||
FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Attack )
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- This sets your escorts to fly in a formation.
|
||||
-- @param #AI_FORMATION self
|
||||
-- @param Wrapper.Group#GROUP FollowGroup FollowGroup.
|
||||
-- @return #AI_FORMATION
|
||||
function AI_FORMATION:SetFlightModeFormation( FollowGroup )
|
||||
|
||||
if FollowGroup then
|
||||
FollowGroup:SetState( FollowGroup, "PreviousMode", FollowGroup:GetState( FollowGroup, "Mode" ) )
|
||||
FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Formation )
|
||||
else
|
||||
self.EscortGroupSet:ForSomeGroupAlive(
|
||||
--- @param Core.Group#GROUP EscortGroup
|
||||
function( FollowGroup )
|
||||
FollowGroup:SetState( FollowGroup, "PreviousMode", FollowGroup:GetState( FollowGroup, "Mode" ) )
|
||||
FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Formation )
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Stop function. Formation will not be updated any more.
|
||||
-- @param #AI_FORMATION self
|
||||
-- @param Core.Set#SET_GROUP FollowGroupSet The following set of groups.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @pram #string To The to state.
|
||||
function AI_FORMATION:onafterStop(FollowGroupSet, From, Event, To) --R2.1
|
||||
self:E("Stopping formation.")
|
||||
end
|
||||
|
||||
--- Follow event fuction. Check if coming from state "stopped". If so the transition is rejected.
|
||||
-- @param #AI_FORMATION self
|
||||
-- @param Core.Set#SET_GROUP FollowGroupSet The following set of groups.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @pram #string To The to state.
|
||||
function AI_FORMATION:onbeforeFollow( FollowGroupSet, From, Event, To ) --R2.1
|
||||
if From=="Stopped" then
|
||||
return false -- Deny transition.
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--- @param #AI_FORMATION self
|
||||
function AI_FORMATION:onenterFollowing( FollowGroupSet ) --R2.1
|
||||
|
||||
self:T( { self.FollowUnit.UnitName, self.FollowUnit:IsAlive() } )
|
||||
if self.FollowUnit:IsAlive() then
|
||||
|
||||
local ClientUnit = self.FollowUnit
|
||||
|
||||
self:T( {ClientUnit.UnitName } )
|
||||
|
||||
local CT1, CT2, CV1, CV2
|
||||
CT1 = ClientUnit:GetState( self, "CT1" )
|
||||
|
||||
@@ -920,120 +1106,139 @@ function AI_FORMATION:onenterFollowing( FollowGroupSet ) --R2.1
|
||||
ClientUnit:SetState( self, "CV1", CV2 )
|
||||
end
|
||||
|
||||
FollowGroupSet:ForEachGroup(
|
||||
FollowGroupSet:ForEachGroupAlive(
|
||||
--- @param Wrapper.Group#GROUP FollowGroup
|
||||
-- @param Wrapper.Unit#UNIT ClientUnit
|
||||
function( FollowGroup, Formation, ClientUnit, CT1, CV1, CT2, CV2 )
|
||||
|
||||
if FollowGroup:GetState( FollowGroup, "Mode" ) == self.__Enum.Mode.Formation then
|
||||
|
||||
FollowGroup:OptionROTEvadeFire()
|
||||
FollowGroup:OptionROEReturnFire()
|
||||
self:T({Mode=FollowGroup:GetState( FollowGroup, "Mode" )})
|
||||
|
||||
local GroupUnit = FollowGroup:GetUnit( 1 )
|
||||
local FollowFormation = FollowGroup:GetState( self, "FormationVec3" )
|
||||
if FollowFormation then
|
||||
local FollowDistance = FollowFormation.x
|
||||
|
||||
local GT1 = GroupUnit:GetState( self, "GT1" )
|
||||
|
||||
if CT1 == nil or CT1 == 0 or GT1 == nil or GT1 == 0 then
|
||||
GroupUnit:SetState( self, "GV1", GroupUnit:GetPointVec3() )
|
||||
GroupUnit:SetState( self, "GT1", timer.getTime() )
|
||||
else
|
||||
local CD = ( ( CV2.x - CV1.x )^2 + ( CV2.y - CV1.y )^2 + ( CV2.z - CV1.z )^2 ) ^ 0.5
|
||||
local CT = CT2 - CT1
|
||||
|
||||
local CS = ( 3600 / CT ) * ( CD / 1000 ) / 3.6
|
||||
|
||||
local CDv = { x = CV2.x - CV1.x, y = CV2.y - CV1.y, z = CV2.z - CV1.z }
|
||||
local Ca = math.atan2( CDv.x, CDv.z )
|
||||
|
||||
FollowGroup:OptionROTEvadeFire()
|
||||
FollowGroup:OptionROEReturnFire()
|
||||
|
||||
local GroupUnit = FollowGroup:GetUnit( 1 )
|
||||
local FollowFormation = FollowGroup:GetState( self, "FormationVec3" )
|
||||
if FollowFormation then
|
||||
local FollowDistance = FollowFormation.x
|
||||
|
||||
local GT1 = GroupUnit:GetState( self, "GT1" )
|
||||
local GT2 = timer.getTime()
|
||||
local GV1 = GroupUnit:GetState( self, "GV1" )
|
||||
local GV2 = GroupUnit:GetPointVec3()
|
||||
GV2:AddX( math.random( -Formation.FlightRandomization / 2, Formation.FlightRandomization / 2 ) )
|
||||
GV2:AddY( math.random( -Formation.FlightRandomization / 2, Formation.FlightRandomization / 2 ) )
|
||||
GV2:AddZ( math.random( -Formation.FlightRandomization / 2, Formation.FlightRandomization / 2 ) )
|
||||
GroupUnit:SetState( self, "GT1", GT2 )
|
||||
GroupUnit:SetState( self, "GV1", GV2 )
|
||||
|
||||
|
||||
local GD = ( ( GV2.x - GV1.x )^2 + ( GV2.y - GV1.y )^2 + ( GV2.z - GV1.z )^2 ) ^ 0.5
|
||||
local GT = GT2 - GT1
|
||||
|
||||
|
||||
if CT1 == nil or CT1 == 0 or GT1 == nil or GT1 == 0 then
|
||||
GroupUnit:SetState( self, "GV1", GroupUnit:GetPointVec3() )
|
||||
GroupUnit:SetState( self, "GT1", timer.getTime() )
|
||||
else
|
||||
local CD = ( ( CV2.x - CV1.x )^2 + ( CV2.y - CV1.y )^2 + ( CV2.z - CV1.z )^2 ) ^ 0.5
|
||||
local CT = CT2 - CT1
|
||||
|
||||
local CS = ( 3600 / CT ) * ( CD / 1000 ) / 3.6
|
||||
|
||||
local CDv = { x = CV2.x - CV1.x, y = CV2.y - CV1.y, z = CV2.z - CV1.z }
|
||||
local Ca = math.atan2( CDv.x, CDv.z )
|
||||
|
||||
local GT1 = GroupUnit:GetState( self, "GT1" )
|
||||
local GT2 = timer.getTime()
|
||||
local GV1 = GroupUnit:GetState( self, "GV1" )
|
||||
local GV2 = GroupUnit:GetPointVec3()
|
||||
GV2:AddX( math.random( -Formation.FlightRandomization / 2, Formation.FlightRandomization / 2 ) )
|
||||
GV2:AddY( math.random( -Formation.FlightRandomization / 2, Formation.FlightRandomization / 2 ) )
|
||||
GV2:AddZ( math.random( -Formation.FlightRandomization / 2, Formation.FlightRandomization / 2 ) )
|
||||
GroupUnit:SetState( self, "GT1", GT2 )
|
||||
GroupUnit:SetState( self, "GV1", GV2 )
|
||||
|
||||
|
||||
local GD = ( ( GV2.x - GV1.x )^2 + ( GV2.y - GV1.y )^2 + ( GV2.z - GV1.z )^2 ) ^ 0.5
|
||||
local GT = GT2 - GT1
|
||||
|
||||
|
||||
-- Calculate the distance
|
||||
local GDv = { x = GV2.x - CV1.x, y = GV2.y - CV1.y, z = GV2.z - CV1.z }
|
||||
local Alpha_T = math.atan2( GDv.x, GDv.z ) - math.atan2( CDv.x, CDv.z )
|
||||
local Alpha_R = ( Alpha_T < 0 ) and Alpha_T + 2 * math.pi or Alpha_T
|
||||
local Position = math.cos( Alpha_R )
|
||||
local GD = ( ( GDv.x )^2 + ( GDv.z )^2 ) ^ 0.5
|
||||
local Distance = GD * Position + - CS * 0.5
|
||||
|
||||
-- Calculate the group direction vector
|
||||
local GV = { x = GV2.x - CV2.x, y = GV2.y - CV2.y, z = GV2.z - CV2.z }
|
||||
|
||||
-- Calculate GH2, GH2 with the same height as CV2.
|
||||
local GH2 = { x = GV2.x, y = CV2.y + FollowFormation.y, z = GV2.z }
|
||||
|
||||
-- Calculate the angle of GV to the orthonormal plane
|
||||
local alpha = math.atan2( GV.x, GV.z )
|
||||
|
||||
local GVx = FollowFormation.z * math.cos( Ca ) + FollowFormation.x * math.sin( Ca )
|
||||
local GVz = FollowFormation.x * math.cos( Ca ) - FollowFormation.z * math.sin( Ca )
|
||||
|
||||
|
||||
-- Now we calculate the intersecting vector between the circle around CV2 with radius FollowDistance and GH2.
|
||||
-- From the GeoGebra model: CVI = (x(CV2) + FollowDistance cos(alpha), y(GH2) + FollowDistance sin(alpha), z(CV2))
|
||||
local Inclination = ( Distance + FollowFormation.x ) / 10
|
||||
if Inclination < -30 then
|
||||
Inclination = - 30
|
||||
end
|
||||
local CVI = { x = CV2.x + CS * 10 * math.sin(Ca),
|
||||
y = GH2.y + Inclination, -- + FollowFormation.y,
|
||||
y = GH2.y,
|
||||
z = CV2.z + CS * 10 * math.cos(Ca),
|
||||
}
|
||||
|
||||
-- Calculate the direction vector DV of the escort group. We use CVI as the base and CV2 as the direction.
|
||||
local DV = { x = CV2.x - CVI.x, y = CV2.y - CVI.y, z = CV2.z - CVI.z }
|
||||
|
||||
-- We now calculate the unary direction vector DVu, so that we can multiply DVu with the speed, which is expressed in meters / s.
|
||||
-- We need to calculate this vector to predict the point the escort group needs to fly to according its speed.
|
||||
-- The distance of the destination point should be far enough not to have the aircraft starting to swipe left to right...
|
||||
local DVu = { x = DV.x / FollowDistance, y = DV.y, z = DV.z / FollowDistance }
|
||||
|
||||
-- Now we can calculate the group destination vector GDV.
|
||||
local GDV = { x = CVI.x, y = CVI.y, z = CVI.z }
|
||||
|
||||
local ADDx = FollowFormation.x * math.cos(alpha) - FollowFormation.z * math.sin(alpha)
|
||||
local ADDz = FollowFormation.z * math.cos(alpha) + FollowFormation.x * math.sin(alpha)
|
||||
|
||||
local GDV_Formation = {
|
||||
x = GDV.x - GVx,
|
||||
y = GDV.y,
|
||||
z = GDV.z - GVz
|
||||
}
|
||||
|
||||
if self.SmokeDirectionVector == true then
|
||||
trigger.action.smoke( GDV, trigger.smokeColor.Green )
|
||||
trigger.action.smoke( GDV_Formation, trigger.smokeColor.White )
|
||||
end
|
||||
|
||||
|
||||
|
||||
local Time = 120
|
||||
|
||||
local Speed = - ( Distance + FollowFormation.x ) / Time
|
||||
|
||||
-- Calculate the distance
|
||||
local GDv = { x = GV2.x - CV1.x, y = GV2.y - CV1.y, z = GV2.z - CV1.z }
|
||||
local Alpha_T = math.atan2( GDv.x, GDv.z ) - math.atan2( CDv.x, CDv.z )
|
||||
local Alpha_R = ( Alpha_T < 0 ) and Alpha_T + 2 * math.pi or Alpha_T
|
||||
local Position = math.cos( Alpha_R )
|
||||
local GD = ( ( GDv.x )^2 + ( GDv.z )^2 ) ^ 0.5
|
||||
local Distance = GD * Position + - CS * 0.5
|
||||
|
||||
-- Calculate the group direction vector
|
||||
local GV = { x = GV2.x - CV2.x, y = GV2.y - CV2.y, z = GV2.z - CV2.z }
|
||||
|
||||
-- Calculate GH2, GH2 with the same height as CV2.
|
||||
local GH2 = { x = GV2.x, y = CV2.y + FollowFormation.y, z = GV2.z }
|
||||
|
||||
-- Calculate the angle of GV to the orthonormal plane
|
||||
local alpha = math.atan2( GV.x, GV.z )
|
||||
|
||||
local GVx = FollowFormation.z * math.cos( Ca ) + FollowFormation.x * math.sin( Ca )
|
||||
local GVz = FollowFormation.x * math.cos( Ca ) - FollowFormation.z * math.sin( Ca )
|
||||
if Distance > -10000 then
|
||||
Speed = - ( Distance + FollowFormation.x ) / 60
|
||||
end
|
||||
|
||||
if Distance > -2500 then
|
||||
Speed = - ( Distance + FollowFormation.x ) / 20
|
||||
end
|
||||
|
||||
local GS = Speed + CS
|
||||
|
||||
|
||||
-- Now we calculate the intersecting vector between the circle around CV2 with radius FollowDistance and GH2.
|
||||
-- From the GeoGebra model: CVI = (x(CV2) + FollowDistance cos(alpha), y(GH2) + FollowDistance sin(alpha), z(CV2))
|
||||
local CVI = { x = CV2.x + CS * 10 * math.sin(Ca),
|
||||
y = GH2.y - ( Distance + FollowFormation.x ) / 5, -- + FollowFormation.y,
|
||||
z = CV2.z + CS * 10 * math.cos(Ca),
|
||||
}
|
||||
|
||||
-- Calculate the direction vector DV of the escort group. We use CVI as the base and CV2 as the direction.
|
||||
local DV = { x = CV2.x - CVI.x, y = CV2.y - CVI.y, z = CV2.z - CVI.z }
|
||||
|
||||
-- We now calculate the unary direction vector DVu, so that we can multiply DVu with the speed, which is expressed in meters / s.
|
||||
-- We need to calculate this vector to predict the point the escort group needs to fly to according its speed.
|
||||
-- The distance of the destination point should be far enough not to have the aircraft starting to swipe left to right...
|
||||
local DVu = { x = DV.x / FollowDistance, y = DV.y, z = DV.z / FollowDistance }
|
||||
|
||||
-- Now we can calculate the group destination vector GDV.
|
||||
local GDV = { x = CVI.x, y = CVI.y, z = CVI.z }
|
||||
|
||||
local ADDx = FollowFormation.x * math.cos(alpha) - FollowFormation.z * math.sin(alpha)
|
||||
local ADDz = FollowFormation.z * math.cos(alpha) + FollowFormation.x * math.sin(alpha)
|
||||
|
||||
local GDV_Formation = {
|
||||
x = GDV.x - GVx,
|
||||
y = GDV.y,
|
||||
z = GDV.z - GVz
|
||||
}
|
||||
|
||||
if self.SmokeDirectionVector == true then
|
||||
trigger.action.smoke( GDV, trigger.smokeColor.Green )
|
||||
trigger.action.smoke( GDV_Formation, trigger.smokeColor.White )
|
||||
self:F( { Distance = Distance, Speed = Speed, CS = CS, GS = GS } )
|
||||
|
||||
|
||||
-- Now route the escort to the desired point with the desired speed.
|
||||
FollowGroup:RouteToVec3( GDV_Formation, GS ) -- DCS models speed in Mps (Miles per second)
|
||||
end
|
||||
|
||||
|
||||
|
||||
local Time = 60
|
||||
|
||||
local Speed = - ( Distance + FollowFormation.x ) / Time
|
||||
local GS = Speed + CS
|
||||
if Speed < 0 then
|
||||
Speed = 0
|
||||
end
|
||||
|
||||
-- Now route the escort to the desired point with the desired speed.
|
||||
FollowGroup:RouteToVec3( GDV_Formation, GS ) -- DCS models speed in Mps (Miles per second)
|
||||
end
|
||||
end
|
||||
end,
|
||||
self, ClientUnit, CT1, CV1, CT2, CV2
|
||||
)
|
||||
|
||||
self:__Follow( -0.5 )
|
||||
|
||||
self:__Follow( -self.dtFollow )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -825,7 +825,7 @@ function AI_PATROL_ZONE:onafterStatus()
|
||||
|
||||
local Fuel = self.Controllable:GetFuelMin()
|
||||
if Fuel < self.PatrolFuelThresholdPercentage then
|
||||
self:E( self.Controllable:GetName() .. " is out of fuel:" .. Fuel .. ", RTB!" )
|
||||
self:I( self.Controllable:GetName() .. " is out of fuel:" .. Fuel .. ", RTB!" )
|
||||
local OldAIControllable = self.Controllable
|
||||
|
||||
local OrbitTask = OldAIControllable:TaskOrbitCircle( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ), self.PatrolMinSpeed )
|
||||
@@ -839,7 +839,7 @@ function AI_PATROL_ZONE:onafterStatus()
|
||||
-- TODO: Check GROUP damage function.
|
||||
local Damage = self.Controllable:GetLife()
|
||||
if Damage <= self.PatrolDamageThreshold then
|
||||
self:E( self.Controllable:GetName() .. " is damaged:" .. Damage .. ", RTB!" )
|
||||
self:I( self.Controllable:GetName() .. " is damaged:" .. Damage .. ", RTB!" )
|
||||
RTB = true
|
||||
end
|
||||
|
||||
@@ -900,7 +900,6 @@ end
|
||||
function AI_PATROL_ZONE:OnCrash( EventData )
|
||||
|
||||
if self.Controllable:IsAlive() and EventData.IniDCSGroupName == self.Controllable:GetName() then
|
||||
self:E( self.Controllable:GetUnits() )
|
||||
if #self.Controllable:GetUnits() == 1 then
|
||||
self:__Crash( 1, EventData )
|
||||
end
|
||||
|
||||
@@ -167,7 +167,7 @@ do -- ACT_ASSIGN_ACCEPT
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
function ACT_ASSIGN_ACCEPT:onenterAssigned( ProcessUnit, Task, From, Event, To )
|
||||
function ACT_ASSIGN_ACCEPT:onenterAssigned( ProcessUnit, Task, From, Event, To, TaskGroup )
|
||||
|
||||
self.Task:Assign( ProcessUnit, ProcessUnit:GetPlayerName() )
|
||||
end
|
||||
|
||||
@@ -595,18 +595,36 @@ do -- Event Handling
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any unit begins firing a weapon that has a high rate of fire. Most common with aircraft cannons (GAU-8), autocannons, and machine guns.
|
||||
-- initiator : The unit that is doing the shooing.
|
||||
-- initiator : The unit that is doing the shooting.
|
||||
-- target: The unit that is being targeted.
|
||||
-- @function [parent=#BASE] OnEventShootingStart
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any unit stops firing its weapon. Event will always correspond with a shooting start event.
|
||||
-- initiator : The unit that was doing the shooing.
|
||||
-- initiator : The unit that was doing the shooting.
|
||||
-- @function [parent=#BASE] OnEventShootingEnd
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when a new mark was added.
|
||||
-- MarkID: ID of the mark.
|
||||
-- @function [parent=#BASE] OnEventMarkAdded
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when a mark was removed.
|
||||
-- MarkID: ID of the mark.
|
||||
-- @function [parent=#BASE] OnEventMarkRemoved
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when a mark text was changed.
|
||||
-- MarkID: ID of the mark.
|
||||
-- @function [parent=#BASE] OnEventMarkChange
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -787,15 +805,17 @@ do -- Scheduling
|
||||
end
|
||||
|
||||
self.Scheduler.SchedulerObject = self.Scheduler
|
||||
--self.MasterObject = self
|
||||
|
||||
local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule(
|
||||
local ScheduleID = self.Scheduler:Schedule(
|
||||
self,
|
||||
SchedulerFunction,
|
||||
{ ... },
|
||||
Start,
|
||||
Repeat,
|
||||
RandomizeFactor,
|
||||
Stop
|
||||
Stop,
|
||||
4
|
||||
)
|
||||
|
||||
self._.Schedules[#self._.Schedules+1] = ScheduleID
|
||||
@@ -809,8 +829,10 @@ do -- Scheduling
|
||||
function BASE:ScheduleStop( SchedulerFunction )
|
||||
|
||||
self:F3( { "ScheduleStop:" } )
|
||||
|
||||
_SCHEDULEDISPATCHER:Stop( self.Scheduler, self._.Schedules[SchedulerFunction] )
|
||||
|
||||
if self.Scheduler then
|
||||
_SCHEDULEDISPATCHER:Stop( self.Scheduler, self._.Schedules[SchedulerFunction] )
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -869,6 +891,26 @@ end
|
||||
-- Log a trace (only shown when trace is on)
|
||||
-- TODO: Make trace function using variable parameters.
|
||||
|
||||
--- Set trace on.
|
||||
-- @param #BASE self
|
||||
-- @usage
|
||||
-- -- Switch the tracing On
|
||||
-- BASE:TraceOn()
|
||||
function BASE:TraceOn()
|
||||
self:TraceOnOff( true )
|
||||
end
|
||||
|
||||
--- Set trace off.
|
||||
-- @param #BASE self
|
||||
-- @usage
|
||||
-- -- Switch the tracing Off
|
||||
-- BASE:TraceOff()
|
||||
function BASE:TraceOff()
|
||||
self:TraceOnOff( false )
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Set trace on or off
|
||||
-- Note that when trace is off, no BASE.Debug statement is performed, increasing performance!
|
||||
-- When Moose is loaded statically, (as one file), tracing is switched off by default.
|
||||
@@ -883,7 +925,7 @@ end
|
||||
-- -- Switch the tracing Off
|
||||
-- BASE:TraceOnOff( false )
|
||||
function BASE:TraceOnOff( TraceOnOff )
|
||||
_TraceOnOff = TraceOnOff
|
||||
_TraceOnOff = TraceOnOff or true
|
||||
end
|
||||
|
||||
|
||||
@@ -903,8 +945,8 @@ end
|
||||
-- @param #BASE self
|
||||
-- @param #number Level
|
||||
function BASE:TraceLevel( Level )
|
||||
_TraceLevel = Level
|
||||
self:E( "Tracing level " .. Level )
|
||||
_TraceLevel = Level or 1
|
||||
self:I( "Tracing level " .. _TraceLevel )
|
||||
end
|
||||
|
||||
--- Trace all methods in MOOSE
|
||||
@@ -912,12 +954,12 @@ end
|
||||
-- @param #boolean TraceAll true = trace all methods in MOOSE.
|
||||
function BASE:TraceAll( TraceAll )
|
||||
|
||||
_TraceAll = TraceAll
|
||||
_TraceAll = TraceAll or true
|
||||
|
||||
if _TraceAll then
|
||||
self:E( "Tracing all methods in MOOSE " )
|
||||
self:I( "Tracing all methods in MOOSE " )
|
||||
else
|
||||
self:E( "Switched off tracing all methods in MOOSE" )
|
||||
self:I( "Switched off tracing all methods in MOOSE" )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -927,7 +969,7 @@ end
|
||||
function BASE:TraceClass( Class )
|
||||
_TraceClass[Class] = true
|
||||
_TraceClassMethod[Class] = {}
|
||||
self:E( "Tracing class " .. Class )
|
||||
self:I( "Tracing class " .. Class )
|
||||
end
|
||||
|
||||
--- Set tracing for a specific method of class
|
||||
@@ -940,7 +982,7 @@ function BASE:TraceClassMethod( Class, Method )
|
||||
_TraceClassMethod[Class].Method = {}
|
||||
end
|
||||
_TraceClassMethod[Class].Method[Method] = true
|
||||
self:E( "Tracing method " .. Method .. " of class " .. Class )
|
||||
self:I( "Tracing method " .. Method .. " of class " .. Class )
|
||||
end
|
||||
|
||||
--- Trace a function call. This function is private.
|
||||
@@ -967,7 +1009,7 @@ function BASE:_F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
|
||||
if DebugInfoFrom then
|
||||
LineFrom = DebugInfoFrom.currentline
|
||||
end
|
||||
env.info( string.format( "%6d(%6d)/%1s:%20s%05d.%s(%s)" , LineCurrent, LineFrom, "F", self.ClassName, self.ClassID, Function, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)" , LineCurrent, LineFrom, "F", self.ClassName, self.ClassID, Function, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1042,7 +1084,7 @@ function BASE:_T( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
|
||||
if DebugInfoFrom then
|
||||
LineFrom = DebugInfoFrom.currentline
|
||||
end
|
||||
env.info( string.format( "%6d(%6d)/%1s:%20s%05d.%s" , LineCurrent, LineFrom, "T", self.ClassName, self.ClassID, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s" , LineCurrent, LineFrom, "T", self.ClassName, self.ClassID, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1113,9 +1155,9 @@ function BASE:E( Arguments )
|
||||
LineFrom = DebugInfoFrom.currentline
|
||||
end
|
||||
|
||||
env.info( string.format( "%6d(%6d)/%1s:%20s%05d.%s(%s)" , LineCurrent, LineFrom, "E", self.ClassName, self.ClassID, Function, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)" , LineCurrent, LineFrom, "E", self.ClassName, self.ClassID, Function, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
else
|
||||
env.info( string.format( "%1s:%20s%05d(%s)" , "E", self.ClassName, self.ClassID, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
env.info( string.format( "%1s:%30s%05d(%s)" , "E", self.ClassName, self.ClassID, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1141,9 +1183,9 @@ function BASE:I( Arguments )
|
||||
LineFrom = DebugInfoFrom.currentline
|
||||
end
|
||||
|
||||
env.info( string.format( "%6d(%6d)/%1s:%20s%05d.%s(%s)" , LineCurrent, LineFrom, "I", self.ClassName, self.ClassID, Function, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)" , LineCurrent, LineFrom, "I", self.ClassName, self.ClassID, Function, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
else
|
||||
env.info( string.format( "%1s:%20s%05d(%s)" , "I", self.ClassName, self.ClassID, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
env.info( string.format( "%1s:%30s%05d(%s)" , "I", self.ClassName, self.ClassID, routines.utils.oneLineSerialize( Arguments ) ) )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -81,6 +81,7 @@ DATABASE = {
|
||||
HITS = {},
|
||||
DESTROYS = {},
|
||||
ZONES = {},
|
||||
ZONES_GOAL = {},
|
||||
}
|
||||
|
||||
local _DATABASECoalition =
|
||||
@@ -186,6 +187,7 @@ end
|
||||
function DATABASE:AddUnit( DCSUnitName )
|
||||
|
||||
if not self.UNITS[DCSUnitName] then
|
||||
self:I( { "Add UNIT:", DCSUnitName } )
|
||||
local UnitRegister = UNIT:Register( DCSUnitName )
|
||||
self.UNITS[DCSUnitName] = UNIT:Register( DCSUnitName )
|
||||
|
||||
@@ -304,16 +306,6 @@ do -- Zones
|
||||
|
||||
self.ZONES[ZoneName] = nil
|
||||
end
|
||||
|
||||
--- Finds an @{Zone} based on the zone name in the DATABASE.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string ZoneName
|
||||
-- @return Core.Zone#ZONE_BASE The found @{Zone}.
|
||||
function DATABASE:FindZone( ZoneName )
|
||||
|
||||
local ZoneFound = self.ZONES[ZoneName]
|
||||
return ZoneFound
|
||||
end
|
||||
|
||||
|
||||
--- Private method that registers new ZONE_BASE derived objects within the DATABASE Object.
|
||||
@@ -348,7 +340,39 @@ do -- Zones
|
||||
|
||||
end -- zone
|
||||
|
||||
do -- Zone_Goal
|
||||
|
||||
--- Finds a @{Zone} based on the zone name.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string ZoneName The name of the zone.
|
||||
-- @return Core.Zone#ZONE_BASE The found ZONE.
|
||||
function DATABASE:FindZoneGoal( ZoneName )
|
||||
|
||||
local ZoneFound = self.ZONES_GOAL[ZoneName]
|
||||
return ZoneFound
|
||||
end
|
||||
|
||||
--- Adds a @{Zone} based on the zone name in the DATABASE.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string ZoneName The name of the zone.
|
||||
-- @param Core.Zone#ZONE_BASE Zone The zone.
|
||||
function DATABASE:AddZoneGoal( ZoneName, Zone )
|
||||
|
||||
if not self.ZONES_GOAL[ZoneName] then
|
||||
self.ZONES_GOAL[ZoneName] = Zone
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Deletes a @{Zone} from the DATABASE based on the zone name.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string ZoneName The name of the zone.
|
||||
function DATABASE:DeleteZoneGoal( ZoneName )
|
||||
|
||||
self.ZONES_GOAL[ZoneName] = nil
|
||||
end
|
||||
|
||||
end -- Zone_Goal
|
||||
do -- cargo
|
||||
|
||||
--- Adds a Cargo based on the Cargo Name in the DATABASE.
|
||||
@@ -890,7 +914,7 @@ end
|
||||
-- @param #DATABASE self
|
||||
-- @param Core.Event#EVENTDATA Event
|
||||
function DATABASE:_EventOnBirth( Event )
|
||||
self:F2( { Event } )
|
||||
self:F( { Event } )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
if Event.IniObjectCategory == 3 then
|
||||
@@ -899,6 +923,12 @@ function DATABASE:_EventOnBirth( Event )
|
||||
if Event.IniObjectCategory == 1 then
|
||||
self:AddUnit( Event.IniDCSUnitName )
|
||||
self:AddGroup( Event.IniDCSGroupName )
|
||||
-- Add airbase if it was spawned later in the mission.
|
||||
local DCSAirbase = Airbase.getByName(Event.IniDCSUnitName)
|
||||
if DCSAirbase then
|
||||
self:I(string.format("Adding airbase %s", tostring(Event.IniDCSUnitName)))
|
||||
self:AddAirbase(Event.IniDCSUnitName)
|
||||
end
|
||||
end
|
||||
end
|
||||
if Event.IniObjectCategory == 1 then
|
||||
@@ -907,6 +937,7 @@ function DATABASE:_EventOnBirth( Event )
|
||||
local PlayerName = Event.IniUnit:GetPlayerName()
|
||||
if PlayerName then
|
||||
self:I( { "Player Joined:", PlayerName } )
|
||||
self:AddClient( Event.IniDCSUnitName )
|
||||
if not self.PLAYERS[PlayerName] then
|
||||
self:AddPlayer( Event.IniUnitName, PlayerName )
|
||||
end
|
||||
@@ -1027,7 +1058,8 @@ function DATABASE:ForEach( IteratorFunction, FinalizeFunction, arg, Set )
|
||||
return false
|
||||
end
|
||||
|
||||
local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 0.001, 0 )
|
||||
--local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 0.001, 0 )
|
||||
Schedule()
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -1166,7 +1198,7 @@ function DATABASE:OnEventNewZone( EventData )
|
||||
self:F2( { EventData } )
|
||||
|
||||
if EventData.Zone then
|
||||
self:AddZone( EventData.Zone )
|
||||
self:AddZone( EventData.Zone.ZoneName, EventData.Zone )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1222,7 +1254,7 @@ function DATABASE:_RegisterTemplates()
|
||||
|
||||
local CoalitionSide = coalition.side[string.upper(CoalitionName)]
|
||||
if CoalitionName=="red" then
|
||||
CoalitionSide=coalition.side.NEUTRAL
|
||||
CoalitionSide=coalition.side.RED
|
||||
elseif CoalitionName=="blue" then
|
||||
CoalitionSide=coalition.side.BLUE
|
||||
else
|
||||
@@ -1330,7 +1362,7 @@ end
|
||||
-- What is he hitting?
|
||||
if Event.TgtCategory then
|
||||
|
||||
if Event.IniCoalition then -- A coalition object was hit, probably a static.
|
||||
if Event.WeaponCoalition then -- A coalition object was hit, probably a static.
|
||||
-- A target got hit
|
||||
self.HITS[Event.TgtUnitName] = self.HITS[Event.TgtUnitName] or {}
|
||||
local Hit = self.HITS[Event.TgtUnitName]
|
||||
|
||||
@@ -189,7 +189,9 @@ world.event.S_EVENT_NEW_CARGO = world.event.S_EVENT_MAX + 1000
|
||||
world.event.S_EVENT_DELETE_CARGO = world.event.S_EVENT_MAX + 1001
|
||||
world.event.S_EVENT_NEW_ZONE = world.event.S_EVENT_MAX + 1002
|
||||
world.event.S_EVENT_DELETE_ZONE = world.event.S_EVENT_MAX + 1003
|
||||
world.event.S_EVENT_REMOVE_UNIT = world.event.S_EVENT_MAX + 1004
|
||||
world.event.S_EVENT_NEW_ZONE_GOAL = world.event.S_EVENT_MAX + 1004
|
||||
world.event.S_EVENT_DELETE_ZONE_GOAL = world.event.S_EVENT_MAX + 1005
|
||||
world.event.S_EVENT_REMOVE_UNIT = world.event.S_EVENT_MAX + 1006
|
||||
|
||||
|
||||
--- The different types of events supported by MOOSE.
|
||||
@@ -226,6 +228,8 @@ EVENTS = {
|
||||
DeleteCargo = world.event.S_EVENT_DELETE_CARGO,
|
||||
NewZone = world.event.S_EVENT_NEW_ZONE,
|
||||
DeleteZone = world.event.S_EVENT_DELETE_ZONE,
|
||||
NewZoneGoal = world.event.S_EVENT_NEW_ZONE_GOAL,
|
||||
DeleteZoneGoal = world.event.S_EVENT_DELETE_ZONE_GOAL,
|
||||
RemoveUnit = world.event.S_EVENT_REMOVE_UNIT,
|
||||
}
|
||||
|
||||
@@ -272,10 +276,16 @@ EVENTS = {
|
||||
-- @field Wrapper.Airbase#AIRBASE Place The MOOSE airbase object.
|
||||
-- @field #string PlaceName The name of the airbase.
|
||||
--
|
||||
-- @field weapon The weapon used during the event.
|
||||
-- @field Weapon
|
||||
-- @field WeaponName
|
||||
-- @field WeaponTgtDCSUnit
|
||||
-- @field #table weapon The weapon used during the event.
|
||||
-- @field #table Weapon
|
||||
-- @field #string WeaponName Name of the weapon.
|
||||
-- @field DCS#Unit WeaponTgtDCSUnit Target DCS unit of the weapon.
|
||||
--
|
||||
-- @field Cargo.Cargo#CARGO Cargo The cargo object.
|
||||
-- @field #string CargoName The name of the cargo object.
|
||||
--
|
||||
-- @field Core.ZONE#ZONE Zone The zone object.
|
||||
-- @field #string ZoneName The name of the zone.
|
||||
|
||||
|
||||
|
||||
@@ -456,6 +466,16 @@ local _EVENTMETA = {
|
||||
Event = "OnEventDeleteZone",
|
||||
Text = "S_EVENT_DELETE_ZONE"
|
||||
},
|
||||
[EVENTS.NewZoneGoal] = {
|
||||
Order = 1,
|
||||
Event = "OnEventNewZoneGoal",
|
||||
Text = "S_EVENT_NEW_ZONE_GOAL"
|
||||
},
|
||||
[EVENTS.DeleteZoneGoal] = {
|
||||
Order = 1,
|
||||
Event = "OnEventDeleteZoneGoal",
|
||||
Text = "S_EVENT_DELETE_ZONE_GOAL"
|
||||
},
|
||||
[EVENTS.RemoveUnit] = {
|
||||
Order = -1,
|
||||
Event = "OnEventRemoveUnit",
|
||||
@@ -794,6 +814,38 @@ do -- Event Creation
|
||||
world.onEvent( Event )
|
||||
end
|
||||
|
||||
--- Creation of a New ZoneGoal Event.
|
||||
-- @param #EVENT self
|
||||
-- @param Core.Functional#ZONE_GOAL ZoneGoal The ZoneGoal created.
|
||||
function EVENT:CreateEventNewZoneGoal( ZoneGoal )
|
||||
self:F( { ZoneGoal } )
|
||||
|
||||
local Event = {
|
||||
id = EVENTS.NewZoneGoal,
|
||||
time = timer.getTime(),
|
||||
ZoneGoal = ZoneGoal,
|
||||
}
|
||||
|
||||
world.onEvent( Event )
|
||||
end
|
||||
|
||||
|
||||
--- Creation of a ZoneGoal Deletion Event.
|
||||
-- @param #EVENT self
|
||||
-- @param Core.ZoneGoal#ZONE_GOAL ZoneGoal The ZoneGoal created.
|
||||
function EVENT:CreateEventDeleteZoneGoal( ZoneGoal )
|
||||
self:F( { ZoneGoal } )
|
||||
|
||||
local Event = {
|
||||
id = EVENTS.DeleteZoneGoal,
|
||||
time = timer.getTime(),
|
||||
ZoneGoal = ZoneGoal,
|
||||
}
|
||||
|
||||
world.onEvent( Event )
|
||||
end
|
||||
|
||||
|
||||
--- Creation of a S_EVENT_PLAYER_ENTER_UNIT Event.
|
||||
-- @param #EVENT self
|
||||
-- @param Wrapper.Unit#UNIT PlayerUnit.
|
||||
@@ -858,9 +910,9 @@ function EVENT:onEvent( Event )
|
||||
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
|
||||
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
|
||||
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
|
||||
if Event.IniGroup then
|
||||
--if Event.IniGroup then
|
||||
Event.IniGroupName = Event.IniDCSGroupName
|
||||
end
|
||||
--end
|
||||
end
|
||||
Event.IniPlayerName = Event.IniDCSUnit:getPlayerName()
|
||||
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
|
||||
@@ -912,9 +964,9 @@ function EVENT:onEvent( Event )
|
||||
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
|
||||
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
|
||||
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
|
||||
if Event.TgtGroup then
|
||||
--if Event.TgtGroup then
|
||||
Event.TgtGroupName = Event.TgtDCSGroupName
|
||||
end
|
||||
--end
|
||||
end
|
||||
Event.TgtPlayerName = Event.TgtDCSUnit:getPlayerName()
|
||||
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
|
||||
@@ -959,8 +1011,7 @@ function EVENT:onEvent( Event )
|
||||
Event.PlaceName=Event.Place:GetName()
|
||||
end
|
||||
|
||||
-- @FC: something like this should be added.
|
||||
--[[
|
||||
-- Mark points.
|
||||
if Event.idx then
|
||||
Event.MarkID=Event.idx
|
||||
Event.MarkVec3=Event.pos
|
||||
@@ -969,7 +1020,6 @@ function EVENT:onEvent( Event )
|
||||
Event.MarkCoalition=Event.coalition
|
||||
Event.MarkGroupID = Event.groupID
|
||||
end
|
||||
]]
|
||||
|
||||
if Event.cargo then
|
||||
Event.Cargo = Event.cargo
|
||||
@@ -986,7 +1036,7 @@ function EVENT:onEvent( Event )
|
||||
local PriorityEnd = PriorityOrder == -1 and 1 or 5
|
||||
|
||||
if Event.IniObjectCategory ~= Object.Category.STATIC then
|
||||
self:T( { EventMeta.Text, Event, Event.IniDCSUnitName, Event.TgtDCSUnitName, PriorityOrder } )
|
||||
self:F( { EventMeta.Text, Event, Event.IniDCSUnitName, Event.TgtDCSUnitName, PriorityOrder } )
|
||||
end
|
||||
|
||||
for EventPriority = PriorityBegin, PriorityEnd, PriorityOrder do
|
||||
|
||||
@@ -594,7 +594,17 @@ do -- FSM
|
||||
return errmsg
|
||||
end
|
||||
if self[handler] then
|
||||
self:T( "*** FSM *** " .. step .. " *** " .. params[1] .. " --> " .. params[2] .. " --> " .. params[3] )
|
||||
if step == "onafter" or step == "OnAfter" then
|
||||
self:T( ":::>" .. step .. params[2] .. " : " .. params[1] .. " >> " .. params[2] .. ">" .. step .. params[2] .. "()" .. " >> " .. params[3] )
|
||||
elseif step == "onbefore" or step == "OnBefore" then
|
||||
self:T( ":::>" .. step .. params[2] .. " : " .. params[1] .. " >> " .. step .. params[2] .. "()" .. ">" .. params[2] .. " >> " .. params[3] )
|
||||
elseif step == "onenter" or step == "OnEnter" then
|
||||
self:T( ":::>" .. step .. params[3] .. " : " .. params[1] .. " >> " .. params[2] .. " >> " .. step .. params[3] .. "()" .. ">" .. params[3] )
|
||||
elseif step == "onleave" or step == "OnLeave" then
|
||||
self:T( ":::>" .. step .. params[1] .. " : " .. params[1] .. ">" .. step .. params[1] .. "()" .. " >> " .. params[2] .. " >> " .. params[3] )
|
||||
else
|
||||
self:T( ":::>" .. step .. " : " .. params[1] .. " >> " .. params[2] .. " >> " .. params[3] )
|
||||
end
|
||||
self._EventSchedules[EventName] = nil
|
||||
local Result, Value = xpcall( function() return self[handler]( self, unpack( params ) ) end, ErrorHandler )
|
||||
return Value
|
||||
@@ -718,13 +728,13 @@ do -- FSM
|
||||
if DelaySeconds < 0 then -- Only call the event ONCE!
|
||||
DelaySeconds = math.abs( DelaySeconds )
|
||||
if not self._EventSchedules[EventName] then
|
||||
CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1 )
|
||||
CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1, nil, nil, nil, 4, true )
|
||||
self._EventSchedules[EventName] = CallID
|
||||
else
|
||||
-- reschedule
|
||||
end
|
||||
else
|
||||
CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1 )
|
||||
CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1, nil, nil, nil, 4, true )
|
||||
end
|
||||
else
|
||||
error( "FSM: An asynchronous event trigger requires a DelaySeconds parameter!!! This can be positive or negative! Sorry, but will not process this." )
|
||||
|
||||
@@ -142,6 +142,7 @@ do -- Goal
|
||||
-- @param #GOAL self
|
||||
-- @param #string PlayerName The name of the player.
|
||||
function GOAL:AddPlayerContribution( PlayerName )
|
||||
self:F({PlayerName})
|
||||
self.Players[PlayerName] = self.Players[PlayerName] or 0
|
||||
self.Players[PlayerName] = self.Players[PlayerName] + 1
|
||||
self.TotalContributions = self.TotalContributions + 1
|
||||
|
||||
@@ -238,7 +238,7 @@ do -- MENU_BASE
|
||||
self.Path = ( self.ParentMenu and "@" .. table.concat( self.MenuParentPath or {}, "@" ) or "" ) .. "@" .. self.MenuText
|
||||
self.Menus = {}
|
||||
self.MenuCount = 0
|
||||
self.MenuTime = timer.getTime()
|
||||
self.MenuStamp = timer.getTime()
|
||||
self.MenuRemoveParent = false
|
||||
|
||||
if self.ParentMenu then
|
||||
@@ -285,13 +285,31 @@ do -- MENU_BASE
|
||||
function MENU_BASE:GetMenu( MenuText )
|
||||
return self.Menus[MenuText]
|
||||
end
|
||||
|
||||
--- Sets a menu stamp for later prevention of menu removal.
|
||||
-- @param #MENU_BASE self
|
||||
-- @param MenuStamp
|
||||
-- @return #MENU_BASE
|
||||
function MENU_BASE:SetStamp( MenuStamp )
|
||||
self.MenuStamp = MenuStamp
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Gets a menu stamp for later prevention of menu removal.
|
||||
-- @param #MENU_BASE self
|
||||
-- @return MenuStamp
|
||||
function MENU_BASE:GetStamp()
|
||||
return timer.getTime()
|
||||
end
|
||||
|
||||
|
||||
--- Sets a time stamp for later prevention of menu removal.
|
||||
-- @param #MENU_BASE self
|
||||
-- @param MenuTime
|
||||
-- @param MenuStamp
|
||||
-- @return #MENU_BASE
|
||||
function MENU_BASE:SetTime( MenuTime )
|
||||
self.MenuTime = MenuTime
|
||||
function MENU_BASE:SetTime( MenuStamp )
|
||||
self.MenuStamp = MenuStamp
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -443,7 +461,7 @@ do -- MENU_MISSION
|
||||
--- Removes the main menu and the sub menus recursively of this MENU_MISSION.
|
||||
-- @param #MENU_MISSION self
|
||||
-- @return #nil
|
||||
function MENU_MISSION:Remove( MenuTime, MenuTag )
|
||||
function MENU_MISSION:Remove( MenuStamp, MenuTag )
|
||||
|
||||
MENU_INDEX:PrepareMission()
|
||||
local Path = MENU_INDEX:ParentPath( self.ParentMenu, self.MenuText )
|
||||
@@ -451,7 +469,7 @@ do -- MENU_MISSION
|
||||
|
||||
if MissionMenu == self then
|
||||
self:RemoveSubMenus()
|
||||
if not MenuTime or self.MenuTime ~= MenuTime then
|
||||
if not MenuStamp or self.MenuStamp ~= MenuStamp then
|
||||
if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then
|
||||
self:F( { Text = self.MenuText, Path = self.MenuPath } )
|
||||
if self.MenuPath ~= nil then
|
||||
@@ -537,7 +555,7 @@ do -- MENU_MISSION_COMMAND
|
||||
local MissionMenu = MENU_INDEX:HasMissionMenu( Path )
|
||||
|
||||
if MissionMenu == self then
|
||||
if not MenuTime or self.MenuTime ~= MenuTime then
|
||||
if not MenuStamp or self.MenuStamp ~= MenuStamp then
|
||||
if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then
|
||||
self:F( { Text = self.MenuText, Path = self.MenuPath } )
|
||||
if self.MenuPath ~= nil then
|
||||
@@ -666,7 +684,7 @@ do -- MENU_COALITION
|
||||
--- Removes the main menu and the sub menus recursively of this MENU_COALITION.
|
||||
-- @param #MENU_COALITION self
|
||||
-- @return #nil
|
||||
function MENU_COALITION:Remove( MenuTime, MenuTag )
|
||||
function MENU_COALITION:Remove( MenuStamp, MenuTag )
|
||||
|
||||
MENU_INDEX:PrepareCoalition( self.Coalition )
|
||||
local Path = MENU_INDEX:ParentPath( self.ParentMenu, self.MenuText )
|
||||
@@ -674,7 +692,7 @@ do -- MENU_COALITION
|
||||
|
||||
if CoalitionMenu == self then
|
||||
self:RemoveSubMenus()
|
||||
if not MenuTime or self.MenuTime ~= MenuTime then
|
||||
if not MenuStamp or self.MenuStamp ~= MenuStamp then
|
||||
if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then
|
||||
self:F( { Coalition = self.Coalition, Text = self.MenuText, Path = self.MenuPath } )
|
||||
if self.MenuPath ~= nil then
|
||||
@@ -758,14 +776,14 @@ do -- MENU_COALITION_COMMAND
|
||||
--- Removes a radio command item for a coalition
|
||||
-- @param #MENU_COALITION_COMMAND self
|
||||
-- @return #nil
|
||||
function MENU_COALITION_COMMAND:Remove( MenuTime, MenuTag )
|
||||
function MENU_COALITION_COMMAND:Remove( MenuStamp, MenuTag )
|
||||
|
||||
MENU_INDEX:PrepareCoalition( self.Coalition )
|
||||
local Path = MENU_INDEX:ParentPath( self.ParentMenu, self.MenuText )
|
||||
local CoalitionMenu = MENU_INDEX:HasCoalitionMenu( self.Coalition, Path )
|
||||
|
||||
if CoalitionMenu == self then
|
||||
if not MenuTime or self.MenuTime ~= MenuTime then
|
||||
if not MenuStamp or self.MenuStamp ~= MenuStamp then
|
||||
if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then
|
||||
self:F( { Coalition = self.Coalition, Text = self.MenuText, Path = self.MenuPath } )
|
||||
if self.MenuPath ~= nil then
|
||||
@@ -907,13 +925,13 @@ do
|
||||
|
||||
--- Removes the sub menus recursively of this MENU_GROUP.
|
||||
-- @param #MENU_GROUP self
|
||||
-- @param MenuTime
|
||||
-- @param MenuStamp
|
||||
-- @param MenuTag A Tag or Key to filter the menus to be refreshed with the Tag set.
|
||||
-- @return #MENU_GROUP self
|
||||
function MENU_GROUP:RemoveSubMenus( MenuTime, MenuTag )
|
||||
function MENU_GROUP:RemoveSubMenus( MenuStamp, MenuTag )
|
||||
|
||||
for MenuText, Menu in pairs( self.Menus or {} ) do
|
||||
Menu:Remove( MenuTime, MenuTag )
|
||||
Menu:Remove( MenuStamp, MenuTag )
|
||||
end
|
||||
|
||||
self.Menus = nil
|
||||
@@ -923,18 +941,18 @@ do
|
||||
|
||||
--- Removes the main menu and sub menus recursively of this MENU_GROUP.
|
||||
-- @param #MENU_GROUP self
|
||||
-- @param MenuTime
|
||||
-- @param MenuStamp
|
||||
-- @param MenuTag A Tag or Key to filter the menus to be refreshed with the Tag set.
|
||||
-- @return #nil
|
||||
function MENU_GROUP:Remove( MenuTime, MenuTag )
|
||||
function MENU_GROUP:Remove( MenuStamp, MenuTag )
|
||||
|
||||
MENU_INDEX:PrepareGroup( self.Group )
|
||||
local Path = MENU_INDEX:ParentPath( self.ParentMenu, self.MenuText )
|
||||
local GroupMenu = MENU_INDEX:HasGroupMenu( self.Group, Path )
|
||||
|
||||
if GroupMenu == self then
|
||||
self:RemoveSubMenus( MenuTime, MenuTag )
|
||||
if not MenuTime or self.MenuTime ~= MenuTime then
|
||||
self:RemoveSubMenus( MenuStamp, MenuTag )
|
||||
if not MenuStamp or self.MenuStamp ~= MenuStamp then
|
||||
if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then
|
||||
if self.MenuPath ~= nil then
|
||||
self:F( { Group = self.GroupID, Text = self.MenuText, Path = self.MenuPath } )
|
||||
@@ -1014,17 +1032,17 @@ do
|
||||
|
||||
--- Removes a menu structure for a group.
|
||||
-- @param #MENU_GROUP_COMMAND self
|
||||
-- @param MenuTime
|
||||
-- @param MenuStamp
|
||||
-- @param MenuTag A Tag or Key to filter the menus to be refreshed with the Tag set.
|
||||
-- @return #nil
|
||||
function MENU_GROUP_COMMAND:Remove( MenuTime, MenuTag )
|
||||
function MENU_GROUP_COMMAND:Remove( MenuStamp, MenuTag )
|
||||
|
||||
MENU_INDEX:PrepareGroup( self.Group )
|
||||
local Path = MENU_INDEX:ParentPath( self.ParentMenu, self.MenuText )
|
||||
local GroupMenu = MENU_INDEX:HasGroupMenu( self.Group, Path )
|
||||
|
||||
if GroupMenu == self then
|
||||
if not MenuTime or self.MenuTime ~= MenuTime then
|
||||
if not MenuStamp or self.MenuStamp ~= MenuStamp then
|
||||
if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then
|
||||
if self.MenuPath ~= nil then
|
||||
self:F( { Group = self.GroupID, Text = self.MenuText, Path = self.MenuPath } )
|
||||
@@ -1136,13 +1154,13 @@ do
|
||||
|
||||
--- Removes the sub menus recursively of this MENU_GROUP_DELAYED.
|
||||
-- @param #MENU_GROUP_DELAYED self
|
||||
-- @param MenuTime
|
||||
-- @param MenuStamp
|
||||
-- @param MenuTag A Tag or Key to filter the menus to be refreshed with the Tag set.
|
||||
-- @return #MENU_GROUP_DELAYED self
|
||||
function MENU_GROUP_DELAYED:RemoveSubMenus( MenuTime, MenuTag )
|
||||
function MENU_GROUP_DELAYED:RemoveSubMenus( MenuStamp, MenuTag )
|
||||
|
||||
for MenuText, Menu in pairs( self.Menus or {} ) do
|
||||
Menu:Remove( MenuTime, MenuTag )
|
||||
Menu:Remove( MenuStamp, MenuTag )
|
||||
end
|
||||
|
||||
self.Menus = nil
|
||||
@@ -1152,18 +1170,18 @@ do
|
||||
|
||||
--- Removes the main menu and sub menus recursively of this MENU_GROUP.
|
||||
-- @param #MENU_GROUP_DELAYED self
|
||||
-- @param MenuTime
|
||||
-- @param MenuStamp
|
||||
-- @param MenuTag A Tag or Key to filter the menus to be refreshed with the Tag set.
|
||||
-- @return #nil
|
||||
function MENU_GROUP_DELAYED:Remove( MenuTime, MenuTag )
|
||||
function MENU_GROUP_DELAYED:Remove( MenuStamp, MenuTag )
|
||||
|
||||
MENU_INDEX:PrepareGroup( self.Group )
|
||||
local Path = MENU_INDEX:ParentPath( self.ParentMenu, self.MenuText )
|
||||
local GroupMenu = MENU_INDEX:HasGroupMenu( self.Group, Path )
|
||||
|
||||
if GroupMenu == self then
|
||||
self:RemoveSubMenus( MenuTime, MenuTag )
|
||||
if not MenuTime or self.MenuTime ~= MenuTime then
|
||||
self:RemoveSubMenus( MenuStamp, MenuTag )
|
||||
if not MenuStamp or self.MenuStamp ~= MenuStamp then
|
||||
if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then
|
||||
if self.MenuPath ~= nil then
|
||||
self:F( { Group = self.GroupID, Text = self.MenuText, Path = self.MenuPath } )
|
||||
@@ -1263,17 +1281,17 @@ do
|
||||
|
||||
--- Removes a menu structure for a group.
|
||||
-- @param #MENU_GROUP_COMMAND_DELAYED self
|
||||
-- @param MenuTime
|
||||
-- @param MenuStamp
|
||||
-- @param MenuTag A Tag or Key to filter the menus to be refreshed with the Tag set.
|
||||
-- @return #nil
|
||||
function MENU_GROUP_COMMAND_DELAYED:Remove( MenuTime, MenuTag )
|
||||
function MENU_GROUP_COMMAND_DELAYED:Remove( MenuStamp, MenuTag )
|
||||
|
||||
MENU_INDEX:PrepareGroup( self.Group )
|
||||
local Path = MENU_INDEX:ParentPath( self.ParentMenu, self.MenuText )
|
||||
local GroupMenu = MENU_INDEX:HasGroupMenu( self.Group, Path )
|
||||
|
||||
if GroupMenu == self then
|
||||
if not MenuTime or self.MenuTime ~= MenuTime then
|
||||
if not MenuStamp or self.MenuStamp ~= MenuStamp then
|
||||
if ( not MenuTag ) or ( MenuTag and self.MenuTag and MenuTag == self.MenuTag ) then
|
||||
if self.MenuPath ~= nil then
|
||||
self:F( { Group = self.GroupID, Text = self.MenuText, Path = self.MenuPath } )
|
||||
|
||||
@@ -210,6 +210,7 @@ do -- COORDINATE
|
||||
FromParkingAreaHot = "From Parking Area Hot",
|
||||
FromRunway = "From Runway",
|
||||
Landing = "Landing",
|
||||
LandingReFuAr = "LandingReFuAr",
|
||||
}
|
||||
|
||||
--- @field COORDINATE.WaypointType
|
||||
@@ -219,6 +220,7 @@ do -- COORDINATE
|
||||
TakeOff = "TakeOffParkingHot",
|
||||
TurningPoint = "Turning Point",
|
||||
Land = "Land",
|
||||
LandingReFuAr = "LandingReFuAr",
|
||||
}
|
||||
|
||||
|
||||
@@ -342,18 +344,18 @@ do -- COORDINATE
|
||||
return x - Precision <= self.x and x + Precision >= self.x and z - Precision <= self.z and z + Precision >= self.z
|
||||
end
|
||||
|
||||
--- Returns if the 2 coordinates are at the same 2D position.
|
||||
--- Scan/find objects (units, statics, scenery) within a certain radius around the coordinate using the world.searchObjects() DCS API function.
|
||||
-- @param #COORDINATE self
|
||||
-- @param #number radius (Optional) Scan radius in meters. Default 100 m.
|
||||
-- @param #boolean scanunits (Optional) If true scan for units. Default true.
|
||||
-- @param #boolean scanstatics (Optional) If true scan for static objects. Default true.
|
||||
-- @param #boolean scanscenery (Optional) If true scan for scenery objects. Default false.
|
||||
-- @return True if units were found.
|
||||
-- @return True if statics were found.
|
||||
-- @return True if scenery objects were found.
|
||||
-- @return Unit objects found.
|
||||
-- @return Static objects found.
|
||||
-- @return Scenery objects found.
|
||||
-- @return #boolean True if units were found.
|
||||
-- @return #boolean True if statics were found.
|
||||
-- @return #boolean True if scenery objects were found.
|
||||
-- @return #table Table of MOOSE @[#Wrapper.Unit#UNIT} objects found.
|
||||
-- @return #table Table of DCS static objects found.
|
||||
-- @return #table Table of DCS scenery objects found.
|
||||
function COORDINATE:ScanObjects(radius, scanunits, scanstatics, scanscenery)
|
||||
self:F(string.format("Scanning in radius %.1f m.", radius))
|
||||
|
||||
@@ -405,18 +407,17 @@ do -- COORDINATE
|
||||
local ObjectCategory = ZoneObject:getCategory()
|
||||
|
||||
-- Check for unit or static objects
|
||||
--if (ObjectCategory == Object.Category.UNIT and ZoneObject:isExist() and ZoneObject:isActive()) then
|
||||
if (ObjectCategory == Object.Category.UNIT and ZoneObject:isExist()) then
|
||||
if ObjectCategory==Object.Category.UNIT and ZoneObject:isExist() then
|
||||
|
||||
table.insert(Units, UNIT:Find(ZoneObject))
|
||||
gotunits=true
|
||||
|
||||
elseif (ObjectCategory == Object.Category.STATIC and ZoneObject:isExist()) then
|
||||
elseif ObjectCategory==Object.Category.STATIC and ZoneObject:isExist() then
|
||||
|
||||
table.insert(Statics, ZoneObject)
|
||||
gotstatics=true
|
||||
|
||||
elseif ObjectCategory == Object.Category.SCENERY then
|
||||
elseif ObjectCategory==Object.Category.SCENERY then
|
||||
|
||||
table.insert(Scenery, ZoneObject)
|
||||
gotscenery=true
|
||||
@@ -460,18 +461,47 @@ do -- COORDINATE
|
||||
--- Add a Distance in meters from the COORDINATE orthonormal plane, with the given angle, and calculate the new COORDINATE.
|
||||
-- @param #COORDINATE self
|
||||
-- @param DCS#Distance Distance The Distance to be added in meters.
|
||||
-- @param DCS#Angle Angle The Angle in degrees.
|
||||
-- @return #COORDINATE The new calculated COORDINATE.
|
||||
function COORDINATE:Translate( Distance, Angle )
|
||||
-- @param DCS#Angle Angle The Angle in degrees. Defaults to 0 if not specified (nil).
|
||||
-- @param #boolean Keepalt If true, keep altitude of original coordinate. Default is that the new coordinate is created at the translated land height.
|
||||
-- @return Core.Point#COORDINATE The new calculated COORDINATE.
|
||||
function COORDINATE:Translate( Distance, Angle, Keepalt )
|
||||
local SX = self.x
|
||||
local SY = self.z
|
||||
local Radians = Angle / 180 * math.pi
|
||||
local Radians = (Angle or 0) / 180 * math.pi
|
||||
local TX = Distance * math.cos( Radians ) + SX
|
||||
local TY = Distance * math.sin( Radians ) + SY
|
||||
|
||||
return COORDINATE:NewFromVec2( { x = TX, y = TY } )
|
||||
|
||||
if Keepalt then
|
||||
return COORDINATE:NewFromVec3( { x = TX, y=self.y, z = TY } )
|
||||
else
|
||||
return COORDINATE:NewFromVec2( { x = TX, y = TY } )
|
||||
end
|
||||
end
|
||||
|
||||
--- Rotate coordinate in 2D (x,z) space.
|
||||
-- @param #COORDINATE self
|
||||
-- @param DCS#Angle Angle Angle of rotation in degrees.
|
||||
-- @return Core.Point#COORDINATE The rotated coordinate.
|
||||
function COORDINATE:Rotate2D(Angle)
|
||||
|
||||
if not Angle then
|
||||
return self
|
||||
end
|
||||
|
||||
local phi=math.rad(Angle)
|
||||
|
||||
local X=self.z
|
||||
local Y=self.x
|
||||
|
||||
--slocal R=math.sqrt(X*X+Y*Y)
|
||||
|
||||
local x=X*math.cos(phi)-Y*math.sin(phi)
|
||||
local y=X*math.sin(phi)+Y*math.cos(phi)
|
||||
|
||||
-- Coordinate assignment looks bit strange but is correct.
|
||||
return COORDINATE:NewFromVec3({x=y, y=self.y, z=x})
|
||||
end
|
||||
|
||||
--- Return a random Vec2 within an Outer Radius and optionally NOT within an Inner Radius of the COORDINATE.
|
||||
-- @param #COORDINATE self
|
||||
-- @param DCS#Distance OuterRadius
|
||||
@@ -532,7 +562,7 @@ do -- COORDINATE
|
||||
|
||||
--- Return the height of the land at the coordinate.
|
||||
-- @param #COORDINATE self
|
||||
-- @return #number
|
||||
-- @return #number Land height (ASL) in meters.
|
||||
function COORDINATE:GetLandHeight()
|
||||
local Vec2 = { x = self.x, y = self.z }
|
||||
return land.getHeight( Vec2 )
|
||||
@@ -837,7 +867,7 @@ do -- COORDINATE
|
||||
-- @param #number Precision The precision.
|
||||
-- @param Core.Settings#SETTINGS Settings
|
||||
-- @return #string The bearing text in degrees.
|
||||
function COORDINATE:GetBearingText( AngleRadians, Precision, Settings )
|
||||
function COORDINATE:GetBearingText( AngleRadians, Precision, Settings, Language )
|
||||
|
||||
local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS
|
||||
|
||||
@@ -853,16 +883,25 @@ do -- COORDINATE
|
||||
-- @param #number Distance The distance in meters.
|
||||
-- @param Core.Settings#SETTINGS Settings
|
||||
-- @return #string The distance text expressed in the units of measurement.
|
||||
function COORDINATE:GetDistanceText( Distance, Settings )
|
||||
function COORDINATE:GetDistanceText( Distance, Settings, Language )
|
||||
|
||||
local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS
|
||||
local Language = Language or "EN"
|
||||
|
||||
local DistanceText
|
||||
|
||||
if Settings:IsMetric() then
|
||||
DistanceText = " for " .. UTILS.Round( Distance / 1000, 2 ) .. " km"
|
||||
if Language == "EN" then
|
||||
DistanceText = " for " .. UTILS.Round( Distance / 1000, 2 ) .. " km"
|
||||
elseif Language == "RU" then
|
||||
DistanceText = " за " .. UTILS.Round( Distance / 1000, 2 ) .. " километров"
|
||||
end
|
||||
else
|
||||
DistanceText = " for " .. UTILS.Round( UTILS.MetersToNM( Distance ), 2 ) .. " miles"
|
||||
if Language == "EN" then
|
||||
DistanceText = " for " .. UTILS.Round( UTILS.MetersToNM( Distance ), 2 ) .. " miles"
|
||||
elseif Language == "RU" then
|
||||
DistanceText = " за " .. UTILS.Round( UTILS.MetersToNM( Distance ), 2 ) .. " миль"
|
||||
end
|
||||
end
|
||||
|
||||
return DistanceText
|
||||
@@ -871,14 +910,24 @@ do -- COORDINATE
|
||||
--- Return the altitude text of the COORDINATE.
|
||||
-- @param #COORDINATE self
|
||||
-- @return #string Altitude text.
|
||||
function COORDINATE:GetAltitudeText( Settings )
|
||||
function COORDINATE:GetAltitudeText( Settings, Language )
|
||||
local Altitude = self.y
|
||||
local Settings = Settings or _SETTINGS
|
||||
local Language = Language or "EN"
|
||||
|
||||
if Altitude ~= 0 then
|
||||
if Settings:IsMetric() then
|
||||
return " at " .. UTILS.Round( self.y, -3 ) .. " meters"
|
||||
if Language == "EN" then
|
||||
return " at " .. UTILS.Round( self.y, -3 ) .. " meters"
|
||||
elseif Language == "RU" then
|
||||
return " в " .. UTILS.Round( self.y, -3 ) .. " метры"
|
||||
end
|
||||
else
|
||||
return " at " .. UTILS.Round( UTILS.MetersToFeet( self.y ), -3 ) .. " feet"
|
||||
if Language == "EN" then
|
||||
return " at " .. UTILS.Round( UTILS.MetersToFeet( self.y ), -3 ) .. " feet"
|
||||
elseif Language == "RU" then
|
||||
return " в " .. UTILS.Round( self.y, -3 ) .. " ноги"
|
||||
end
|
||||
end
|
||||
else
|
||||
return ""
|
||||
@@ -924,12 +973,12 @@ do -- COORDINATE
|
||||
-- @param #number Distance The distance
|
||||
-- @param Core.Settings#SETTINGS Settings
|
||||
-- @return #string The BR Text
|
||||
function COORDINATE:GetBRText( AngleRadians, Distance, Settings )
|
||||
function COORDINATE:GetBRText( AngleRadians, Distance, Settings, Language )
|
||||
|
||||
local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS
|
||||
|
||||
local BearingText = self:GetBearingText( AngleRadians, 0, Settings )
|
||||
local DistanceText = self:GetDistanceText( Distance, Settings )
|
||||
local BearingText = self:GetBearingText( AngleRadians, 0, Settings, Language )
|
||||
local DistanceText = self:GetDistanceText( Distance, Settings, Language )
|
||||
|
||||
local BRText = BearingText .. DistanceText
|
||||
|
||||
@@ -942,13 +991,13 @@ do -- COORDINATE
|
||||
-- @param #number Distance The distance
|
||||
-- @param Core.Settings#SETTINGS Settings
|
||||
-- @return #string The BRA Text
|
||||
function COORDINATE:GetBRAText( AngleRadians, Distance, Settings )
|
||||
function COORDINATE:GetBRAText( AngleRadians, Distance, Settings, Language )
|
||||
|
||||
local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS
|
||||
|
||||
local BearingText = self:GetBearingText( AngleRadians, 0, Settings )
|
||||
local DistanceText = self:GetDistanceText( Distance, Settings )
|
||||
local AltitudeText = self:GetAltitudeText( Settings )
|
||||
local BearingText = self:GetBearingText( AngleRadians, 0, Settings, Language )
|
||||
local DistanceText = self:GetDistanceText( Distance, Settings, Language )
|
||||
local AltitudeText = self:GetAltitudeText( Settings, Language )
|
||||
|
||||
local BRAText = BearingText .. DistanceText .. AltitudeText -- When the POINT is a VEC2, there will be no altitude shown.
|
||||
|
||||
@@ -999,15 +1048,20 @@ do -- COORDINATE
|
||||
-- @param Wrapper.Airbase#AIRBASE airbase The airbase for takeoff and landing points.
|
||||
-- @param #table DCSTasks A table of @{DCS#Task} items which are executed at the waypoint.
|
||||
-- @param #string description A text description of the waypoint, which will be shown on the F10 map.
|
||||
-- @param #number timeReFuAr Time in minutes the aircraft stays at the airport for ReFueling and ReArming.
|
||||
-- @return #table The route point.
|
||||
function COORDINATE:WaypointAir( AltType, Type, Action, Speed, SpeedLocked, airbase, DCSTasks, description )
|
||||
function COORDINATE:WaypointAir( AltType, Type, Action, Speed, SpeedLocked, airbase, DCSTasks, description, timeReFuAr )
|
||||
self:F2( { AltType, Type, Action, Speed, SpeedLocked } )
|
||||
|
||||
-- Defaults
|
||||
-- Set alttype or "RADIO" which is AGL.
|
||||
AltType=AltType or "RADIO"
|
||||
|
||||
-- Speedlocked by default
|
||||
if SpeedLocked==nil then
|
||||
SpeedLocked=true
|
||||
end
|
||||
|
||||
-- Speed or default 500 km/h.
|
||||
Speed=Speed or 500
|
||||
|
||||
-- Waypoint array.
|
||||
@@ -1016,19 +1070,26 @@ do -- COORDINATE
|
||||
-- Coordinates.
|
||||
RoutePoint.x = self.x
|
||||
RoutePoint.y = self.z
|
||||
|
||||
-- Altitude.
|
||||
RoutePoint.alt = self.y
|
||||
RoutePoint.alt_type = AltType
|
||||
|
||||
-- Waypoint type.
|
||||
RoutePoint.type = Type or nil
|
||||
RoutePoint.action = Action or nil
|
||||
-- Set speed/ETA.
|
||||
RoutePoint.action = Action or nil
|
||||
|
||||
-- Speed.
|
||||
RoutePoint.speed = Speed/3.6
|
||||
RoutePoint.speed_locked = SpeedLocked
|
||||
RoutePoint.ETA=nil
|
||||
RoutePoint.ETA_locked = false
|
||||
|
||||
-- ETA.
|
||||
RoutePoint.ETA=0
|
||||
RoutePoint.ETA_locked=true
|
||||
|
||||
-- Waypoint description.
|
||||
RoutePoint.name=description
|
||||
|
||||
-- Airbase parameters for takeoff and landing points.
|
||||
if airbase then
|
||||
local AirbaseID = airbase:GetID()
|
||||
@@ -1037,31 +1098,32 @@ do -- COORDINATE
|
||||
RoutePoint.linkUnit = AirbaseID
|
||||
RoutePoint.helipadId = AirbaseID
|
||||
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
||||
RoutePoint.airdromeId = AirbaseID
|
||||
RoutePoint.airdromeId = AirbaseID
|
||||
else
|
||||
self:T("ERROR: Unknown airbase category in COORDINATE:WaypointAir()!")
|
||||
end
|
||||
end
|
||||
self:E("ERROR: Unknown airbase category in COORDINATE:WaypointAir()!")
|
||||
end
|
||||
end
|
||||
|
||||
-- Time in minutes to stay at the airbase before resuming route.
|
||||
if Type==COORDINATE.WaypointType.LandingReFuAr then
|
||||
RoutePoint.timeReFuAr=timeReFuAr or 10
|
||||
end
|
||||
|
||||
|
||||
-- ["task"] =
|
||||
-- {
|
||||
-- ["id"] = "ComboTask",
|
||||
-- ["params"] =
|
||||
-- {
|
||||
-- ["tasks"] =
|
||||
-- {
|
||||
-- }, -- end of ["tasks"]
|
||||
-- }, -- end of ["params"]
|
||||
-- }, -- end of ["task"]
|
||||
|
||||
-- Waypoint tasks.
|
||||
RoutePoint.task = {}
|
||||
RoutePoint.task.id = "ComboTask"
|
||||
RoutePoint.task.params = {}
|
||||
RoutePoint.task.params.tasks = DCSTasks or {}
|
||||
|
||||
--RoutePoint.properties={}
|
||||
--RoutePoint.properties.addopt={}
|
||||
|
||||
--RoutePoint.formation_template=""
|
||||
|
||||
-- Debug.
|
||||
self:T({RoutePoint=RoutePoint})
|
||||
|
||||
-- Return waypoint.
|
||||
return RoutePoint
|
||||
end
|
||||
|
||||
@@ -1121,6 +1183,9 @@ do -- COORDINATE
|
||||
--- Build a Waypoint Air "Landing".
|
||||
-- @param #COORDINATE self
|
||||
-- @param DCS#Speed Speed Airspeed in km/h.
|
||||
-- @param Wrapper.Airbase#AIRBASE airbase The airbase for takeoff and landing points.
|
||||
-- @param #table DCSTasks A table of @{DCS#Task} items which are executed at the waypoint.
|
||||
-- @param #string description A text description of the waypoint, which will be shown on the F10 map.
|
||||
-- @return #table The route point.
|
||||
-- @usage
|
||||
--
|
||||
@@ -1129,11 +1194,21 @@ do -- COORDINATE
|
||||
-- LandingWaypoint = LandingCoord:WaypointAirLanding( 60 )
|
||||
-- HeliGroup:Route( { LandWaypoint }, 1 ) -- Start landing the helicopter in one second.
|
||||
--
|
||||
function COORDINATE:WaypointAirLanding( Speed )
|
||||
return self:WaypointAir( nil, COORDINATE.WaypointType.Land, COORDINATE.WaypointAction.Landing, Speed )
|
||||
function COORDINATE:WaypointAirLanding( Speed, airbase, DCSTasks, description )
|
||||
return self:WaypointAir(nil, COORDINATE.WaypointType.Land, COORDINATE.WaypointAction.Landing, Speed, false, airbase, DCSTasks, description)
|
||||
end
|
||||
|
||||
|
||||
--- Build a Waypoint Air "LandingReFuAr". Mimics the aircraft ReFueling and ReArming.
|
||||
-- @param #COORDINATE self
|
||||
-- @param DCS#Speed Speed Airspeed in km/h.
|
||||
-- @param Wrapper.Airbase#AIRBASE airbase The airbase for takeoff and landing points.
|
||||
-- @param #number timeReFuAr Time in minutes, the aircraft stays at the airbase. Default 10 min.
|
||||
-- @param #table DCSTasks A table of @{DCS#Task} items which are executed at the waypoint.
|
||||
-- @param #string description A text description of the waypoint, which will be shown on the F10 map.
|
||||
-- @return #table The route point.
|
||||
function COORDINATE:WaypointAirLandingReFu( Speed, airbase, timeReFuAr, DCSTasks, description )
|
||||
return self:WaypointAir(nil, COORDINATE.WaypointType.LandingReFuAr, COORDINATE.WaypointAction.LandingReFuAr, Speed, false, airbase, DCSTasks, description, timeReFuAr or 10)
|
||||
end
|
||||
|
||||
|
||||
--- Build an ground type route point.
|
||||
@@ -1193,17 +1268,23 @@ do -- COORDINATE
|
||||
-- Loop over all airbases.
|
||||
for _,_airbase in pairs(airbases) do
|
||||
local airbase=_airbase --Wrapper.Airbase#AIRBASE
|
||||
local category=airbase:GetDesc().category
|
||||
if Category and Category==category or Category==nil then
|
||||
local dist=self:Get2DDistance(airbase:GetCoordinate())
|
||||
if closest==nil then
|
||||
distmin=dist
|
||||
closest=airbase
|
||||
else
|
||||
if dist<distmin then
|
||||
if airbase then
|
||||
local category=airbase:GetAirbaseCategory()
|
||||
if Category and Category==category or Category==nil then
|
||||
|
||||
-- Distance to airbase.
|
||||
local dist=self:Get2DDistance(airbase:GetCoordinate())
|
||||
|
||||
if closest==nil then
|
||||
distmin=dist
|
||||
closest=airbase
|
||||
end
|
||||
else
|
||||
if dist<distmin then
|
||||
distmin=dist
|
||||
closest=airbase
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1219,6 +1300,7 @@ do -- COORDINATE
|
||||
-- @return Core.Point#COORDINATE Coordinate of the nearest parking spot.
|
||||
-- @return #number Terminal ID.
|
||||
-- @return #number Distance to closest parking spot in meters.
|
||||
-- @return Wrapper.Airbase#AIRBASE#ParkingSpot Parking spot table.
|
||||
function COORDINATE:GetClosestParkingSpot(airbase, terminaltype, free)
|
||||
|
||||
-- Get airbase table.
|
||||
@@ -1233,6 +1315,7 @@ do -- COORDINATE
|
||||
local _closest=nil --Core.Point#COORDINATE
|
||||
local _termID=nil
|
||||
local _distmin=nil
|
||||
local spot=nil --Wrapper.Airbase#AIRBASE.ParkingSpot
|
||||
|
||||
-- Loop over all airbases.
|
||||
for _,_airbase in pairs(airbases) do
|
||||
@@ -1252,11 +1335,13 @@ do -- COORDINATE
|
||||
_closest=_coord
|
||||
_distmin=_dist
|
||||
_termID=_spot.TerminalID
|
||||
spot=_spot
|
||||
else
|
||||
if _dist<_distmin then
|
||||
_distmin=_dist
|
||||
_closest=_coord
|
||||
_termID=_spot.TerminalID
|
||||
spot=_spot
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1264,7 +1349,7 @@ do -- COORDINATE
|
||||
end
|
||||
end
|
||||
|
||||
return _closest, _termID, _distmin
|
||||
return _closest, _termID, _distmin, spot
|
||||
end
|
||||
|
||||
--- Gets the nearest free parking spot.
|
||||
@@ -1447,15 +1532,24 @@ do -- COORDINATE
|
||||
|
||||
--- Creates an explosion at the point of a certain intensity.
|
||||
-- @param #COORDINATE self
|
||||
-- @param #number ExplosionIntensity Intensity of the explosion in kg TNT.
|
||||
function COORDINATE:Explosion( ExplosionIntensity )
|
||||
-- @param #number ExplosionIntensity Intensity of the explosion in kg TNT. Default 100 kg.
|
||||
-- @param #number Delay Delay before explosion in seconds.
|
||||
-- @return #COORDINATE self
|
||||
function COORDINATE:Explosion( ExplosionIntensity, Delay )
|
||||
self:F2( { ExplosionIntensity } )
|
||||
trigger.action.explosion( self:GetVec3(), ExplosionIntensity )
|
||||
ExplosionIntensity=ExplosionIntensity or 100
|
||||
if Delay and Delay>0 then
|
||||
SCHEDULER:New(nil, self.Explosion, {self,ExplosionIntensity}, Delay)
|
||||
else
|
||||
trigger.action.explosion( self:GetVec3(), ExplosionIntensity )
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- Creates an illumination bomb at the point.
|
||||
-- @param #COORDINATE self
|
||||
-- @param #number power
|
||||
-- @param #number power Power of illumination bomb in Candela.
|
||||
-- @return #COORDINATE self
|
||||
function COORDINATE:IlluminationBomb(power)
|
||||
self:F2()
|
||||
trigger.action.illuminationBomb( self:GetVec3(), power )
|
||||
@@ -1752,7 +1846,7 @@ do -- COORDINATE
|
||||
|
||||
--- Returns if a Coordinate is in a certain Radius of this Coordinate in 2D plane using the X and Z axis.
|
||||
-- @param #COORDINATE self
|
||||
-- @param #COORDINATE ToCoordinate The coordinate that will be tested if it is in the radius of this coordinate.
|
||||
-- @param #COORDINATE Coordinate The coordinate that will be tested if it is in the radius of this coordinate.
|
||||
-- @param #number Radius The radius of the circle on the 2D plane around this coordinate.
|
||||
-- @return #boolean true if in the Radius.
|
||||
function COORDINATE:IsInRadius( Coordinate, Radius )
|
||||
@@ -1800,12 +1894,12 @@ do -- COORDINATE
|
||||
-- @param #COORDINATE FromCoordinate The coordinate to measure the distance and the bearing from.
|
||||
-- @param Core.Settings#SETTINGS Settings (optional) The settings. Can be nil, and in this case the default settings are used. If you want to specify your own settings, use the _SETTINGS object.
|
||||
-- @return #string The BR text.
|
||||
function COORDINATE:ToStringBRA( FromCoordinate, Settings )
|
||||
function COORDINATE:ToStringBRA( FromCoordinate, Settings, Language )
|
||||
local DirectionVec3 = FromCoordinate:GetDirectionVec3( self )
|
||||
local AngleRadians = self:GetAngleRadians( DirectionVec3 )
|
||||
local Distance = FromCoordinate:Get2DDistance( self )
|
||||
local Altitude = self:GetAltitudeText()
|
||||
return "BRA, " .. self:GetBRAText( AngleRadians, Distance, Settings )
|
||||
return "BRA, " .. self:GetBRAText( AngleRadians, Distance, Settings, Language )
|
||||
end
|
||||
|
||||
--- Return a BULLS string out of the BULLS of the coalition to the COORDINATE.
|
||||
@@ -1857,7 +1951,7 @@ do -- COORDINATE
|
||||
|
||||
local LL_Accuracy = Settings and Settings.LL_Accuracy or _SETTINGS.LL_Accuracy
|
||||
local lat, lon = coord.LOtoLL( self:GetVec3() )
|
||||
return "LL DMS, " .. UTILS.tostringLL( lat, lon, LL_Accuracy, true )
|
||||
return "LL DMS " .. UTILS.tostringLL( lat, lon, LL_Accuracy, true )
|
||||
end
|
||||
|
||||
--- Provides a Lat Lon string in Degree Decimal Minute format.
|
||||
@@ -1868,7 +1962,7 @@ do -- COORDINATE
|
||||
|
||||
local LL_Accuracy = Settings and Settings.LL_Accuracy or _SETTINGS.LL_Accuracy
|
||||
local lat, lon = coord.LOtoLL( self:GetVec3() )
|
||||
return "LL DDM, " .. UTILS.tostringLL( lat, lon, LL_Accuracy, false )
|
||||
return "LL DDM " .. UTILS.tostringLL( lat, lon, LL_Accuracy, false )
|
||||
end
|
||||
|
||||
--- Provides a MGRS string
|
||||
@@ -1880,7 +1974,7 @@ do -- COORDINATE
|
||||
local MGRS_Accuracy = Settings and Settings.MGRS_Accuracy or _SETTINGS.MGRS_Accuracy
|
||||
local lat, lon = coord.LOtoLL( self:GetVec3() )
|
||||
local MGRS = coord.LLtoMGRS( lat, lon )
|
||||
return "MGRS, " .. UTILS.tostringMGRS( MGRS, MGRS_Accuracy )
|
||||
return "MGRS " .. UTILS.tostringMGRS( MGRS, MGRS_Accuracy )
|
||||
end
|
||||
|
||||
--- Provides a coordinate string of the point, based on a coordinate format system:
|
||||
@@ -1956,7 +2050,7 @@ do -- COORDINATE
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
|
||||
-- @param Core.Settings#SETTINGS Settings (optional) The settings. Can be nil, and in this case the default settings are used. If you want to specify your own settings, use the _SETTINGS object.
|
||||
-- @return #string The coordinate Text in the configured coordinate system.
|
||||
function COORDINATE:ToStringA2A( Controllable, Settings ) -- R2.2
|
||||
function COORDINATE:ToStringA2A( Controllable, Settings, Language ) -- R2.2
|
||||
|
||||
self:F2( { Controllable = Controllable and Controllable:GetName() } )
|
||||
|
||||
@@ -1965,23 +2059,23 @@ do -- COORDINATE
|
||||
if Settings:IsA2A_BRAA() then
|
||||
if Controllable then
|
||||
local Coordinate = Controllable:GetCoordinate()
|
||||
return self:ToStringBRA( Coordinate, Settings )
|
||||
return self:ToStringBRA( Coordinate, Settings, Language )
|
||||
else
|
||||
return self:ToStringMGRS( Settings )
|
||||
return self:ToStringMGRS( Settings, Language )
|
||||
end
|
||||
end
|
||||
if Settings:IsA2A_BULLS() then
|
||||
local Coalition = Controllable:GetCoalition()
|
||||
return self:ToStringBULLS( Coalition, Settings )
|
||||
return self:ToStringBULLS( Coalition, Settings, Language )
|
||||
end
|
||||
if Settings:IsA2A_LL_DMS() then
|
||||
return self:ToStringLLDMS( Settings )
|
||||
return self:ToStringLLDMS( Settings, Language )
|
||||
end
|
||||
if Settings:IsA2A_LL_DDM() then
|
||||
return self:ToStringLLDDM( Settings )
|
||||
return self:ToStringLLDDM( Settings, Language )
|
||||
end
|
||||
if Settings:IsA2A_MGRS() then
|
||||
return self:ToStringMGRS( Settings )
|
||||
return self:ToStringMGRS( Settings, Language )
|
||||
end
|
||||
|
||||
return nil
|
||||
@@ -1992,37 +2086,38 @@ do -- COORDINATE
|
||||
-- * Uses default settings in COORDINATE.
|
||||
-- * Can be overridden if for a GROUP containing x clients, a menu was selected to override the default.
|
||||
-- @param #COORDINATE self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The controllable to retrieve the settings from, otherwise the default settings will be chosen.
|
||||
-- @param Core.Settings#SETTINGS Settings (optional) The settings. Can be nil, and in this case the default settings are used. If you want to specify your own settings, use the _SETTINGS object.
|
||||
-- @param Tasking.Task#TASK Task The task for which coordinates need to be calculated.
|
||||
-- @return #string The coordinate Text in the configured coordinate system.
|
||||
function COORDINATE:ToString( Controllable, Settings, Task )
|
||||
|
||||
self:F2( { Controllable = Controllable and Controllable:GetName() } )
|
||||
-- self:E( { Controllable = Controllable and Controllable:GetName() } )
|
||||
|
||||
local Settings = Settings or ( Controllable and _DATABASE:GetPlayerSettings( Controllable:GetPlayerName() ) ) or _SETTINGS
|
||||
|
||||
local ModeA2A = false
|
||||
self:E('A2A false')
|
||||
local ModeA2A = nil
|
||||
|
||||
if Task then
|
||||
self:E('Task ' .. Task.ClassName )
|
||||
if Task:IsInstanceOf( TASK_A2A ) then
|
||||
ModeA2A = true
|
||||
self:E('A2A true')
|
||||
else
|
||||
if Task:IsInstanceOf( TASK_A2G ) then
|
||||
ModeA2A = false
|
||||
else
|
||||
if Task:IsInstanceOf( TASK_CARGO ) then
|
||||
ModeA2A = false
|
||||
else
|
||||
ModeA2A = false
|
||||
end
|
||||
if Task:IsInstanceOf( TASK_CAPTURE_ZONE ) then
|
||||
ModeA2A = false
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
local IsAir = Controllable and Controllable:IsAirPlane() or false
|
||||
end
|
||||
|
||||
|
||||
if ModeA2A == nil then
|
||||
local IsAir = Controllable and ( Controllable:IsAirPlane() or Controllable:IsHelicopter() ) or false
|
||||
if IsAir then
|
||||
ModeA2A = true
|
||||
else
|
||||
|
||||
@@ -9,37 +9,37 @@
|
||||
--
|
||||
-- The Radio contains 2 classes : RADIO and BEACON
|
||||
--
|
||||
-- What are radio communications in DCS ?
|
||||
-- What are radio communications in DCS?
|
||||
--
|
||||
-- * Radio transmissions consist of **sound files** that are broadcasted on a specific **frequency** (e.g. 115MHz) and **modulation** (e.g. AM),
|
||||
-- * They can be **subtitled** for a specific **duration**, the **power** in Watts of the transmiter's antenna can be set, and the transmission can be **looped**.
|
||||
--
|
||||
-- How to supply DCS my own Sound Files ?
|
||||
-- How to supply DCS my own Sound Files?
|
||||
--
|
||||
-- * Your sound files need to be encoded in **.ogg** or .wav,
|
||||
-- * Your sound files should be **as tiny as possible**. It is suggested you encode in .ogg with low bitrate and sampling settings,
|
||||
-- * They need to be added in .\l10n\DEFAULT\ in you .miz file (wich can be decompressed like a .zip file),
|
||||
-- * For simplicty sake, you can **let DCS' Mission Editor add the file** itself, by creating a new Trigger with the action "Sound to Country", and choosing your sound file and a country you don't use in your mission.
|
||||
-- * For simplicity sake, you can **let DCS' Mission Editor add the file** itself, by creating a new Trigger with the action "Sound to Country", and choosing your sound file and a country you don't use in your mission.
|
||||
--
|
||||
-- Due to weird DCS quirks, **radio communications behave differently** if sent by a @{Wrapper.Unit#UNIT} or a @{Wrapper.Group#GROUP} or by any other @{Wrapper.Positionable#POSITIONABLE}
|
||||
--
|
||||
-- * If the transmitter is a @{Wrapper.Unit#UNIT} or a @{Wrapper.Group#GROUP}, DCS will set the power of the transmission automatically,
|
||||
-- * If the transmitter is a @{Wrapper.Unit#UNIT} or a @{Wrapper.Group#GROUP}, DCS will set the power of the transmission automatically,
|
||||
-- * If the transmitter is any other @{Wrapper.Positionable#POSITIONABLE}, the transmisison can't be subtitled or looped.
|
||||
--
|
||||
-- Note that obviously, the **frequency** and the **modulation** of the transmission are important only if the players are piloting an **Advanced System Modelling** enabled aircraft,
|
||||
-- like the A10C or the Mirage 2000C. They will **hear the transmission** if they are tuned on the **right frequency and modulation** (and if they are close enough - more on that below).
|
||||
-- If a FC3 airacraft is used, it will **hear every communication, whatever the frequency and the modulation** is set to. The same is true for TACAN beacons. If your aircaft isn't compatible,
|
||||
-- If an FC3 aircraft is used, it will **hear every communication, whatever the frequency and the modulation** is set to. The same is true for TACAN beacons. If your aircraft isn't compatible,
|
||||
-- you won't hear/be able to use the TACAN beacon informations.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: Hugues "Grey_Echo" Bousquet
|
||||
-- ### Authors: Hugues "Grey_Echo" Bousquet, funkyfranky
|
||||
--
|
||||
-- @module Core.Radio
|
||||
-- @image Core_Radio.JPG
|
||||
|
||||
|
||||
--- Models the radio capabilty.
|
||||
--- Models the radio capability.
|
||||
--
|
||||
-- ## RADIO usage
|
||||
--
|
||||
@@ -56,34 +56,35 @@
|
||||
-- * @{#RADIO.SetModulation}() : Sets the modulation of your transmission.
|
||||
-- * @{#RADIO.SetLoop}() : Choose if you want the transmission to be looped. If you need your transmission to be looped, you might need a @{#BEACON} instead...
|
||||
--
|
||||
-- Additional Methods to set relevant parameters if the transmiter is a @{Wrapper.Unit#UNIT} or a @{Wrapper.Group#GROUP}
|
||||
-- Additional Methods to set relevant parameters if the transmitter is a @{Wrapper.Unit#UNIT} or a @{Wrapper.Group#GROUP}
|
||||
--
|
||||
-- * @{#RADIO.SetSubtitle}() : Set both the subtitle and its duration,
|
||||
-- * @{#RADIO.NewUnitTransmission}() : Shortcut to set all the relevant parameters in one method call
|
||||
--
|
||||
-- Additional Methods to set relevant parameters if the transmiter is any other @{Wrapper.Positionable#POSITIONABLE}
|
||||
-- Additional Methods to set relevant parameters if the transmitter is any other @{Wrapper.Positionable#POSITIONABLE}
|
||||
--
|
||||
-- * @{#RADIO.SetPower}() : Sets the power of the antenna in Watts
|
||||
-- * @{#RADIO.NewGenericTransmission}() : Shortcut to set all the relevant parameters in one method call
|
||||
--
|
||||
-- What is this power thing ?
|
||||
-- What is this power thing?
|
||||
--
|
||||
-- * If your transmission is sent by a @{Wrapper.Positionable#POSITIONABLE} other than a @{Wrapper.Unit#UNIT} or a @{Wrapper.Group#GROUP}, you can set the power of the antenna,
|
||||
-- * Otherwise, DCS sets it automatically, depending on what's available on your Unit,
|
||||
-- * If the player gets **too far** from the transmiter, or if the antenna is **too weak**, the transmission will **fade** and **become noisyer**,
|
||||
-- * If the player gets **too far** from the transmitter, or if the antenna is **too weak**, the transmission will **fade** and **become noisyer**,
|
||||
-- * This an automated DCS calculation you have no say on,
|
||||
-- * For reference, a standard VOR station has a 100W antenna, a standard AA TACAN has a 120W antenna, and civilian ATC's antenna usually range between 300 and 500W,
|
||||
-- * For reference, a standard VOR station has a 100 W antenna, a standard AA TACAN has a 120 W antenna, and civilian ATC's antenna usually range between 300 and 500 W,
|
||||
-- * Note that if the transmission has a subtitle, it will be readable, regardless of the quality of the transmission.
|
||||
--
|
||||
-- @type RADIO
|
||||
-- @field Positionable#POSITIONABLE Positionable The transmiter
|
||||
-- @field #string FileName Name of the sound file
|
||||
-- @field #number Frequency Frequency of the transmission in Hz
|
||||
-- @field #number Modulation Modulation of the transmission (either radio.modulation.AM or radio.modulation.FM)
|
||||
-- @field #string Subtitle Subtitle of the transmission
|
||||
-- @field #number SubtitleDuration Duration of the Subtitle in seconds
|
||||
-- @field #number Power Power of the antenna is Watts
|
||||
-- @field #boolean Loop (default true)
|
||||
-- @field Wrapper.Controllable#CONTROLLABLE Positionable The @{#CONTROLLABLE} that will transmit the radio calls.
|
||||
-- @field #string FileName Name of the sound file played.
|
||||
-- @field #number Frequency Frequency of the transmission in Hz.
|
||||
-- @field #number Modulation Modulation of the transmission (either radio.modulation.AM or radio.modulation.FM).
|
||||
-- @field #string Subtitle Subtitle of the transmission.
|
||||
-- @field #number SubtitleDuration Duration of the Subtitle in seconds.
|
||||
-- @field #number Power Power of the antenna is Watts.
|
||||
-- @field #boolean Loop Transmission is repeated (default true).
|
||||
-- @field #string alias Name of the radio transmitter.
|
||||
-- @extends Core.Base#BASE
|
||||
RADIO = {
|
||||
ClassName = "RADIO",
|
||||
@@ -93,19 +94,19 @@ RADIO = {
|
||||
Subtitle = "",
|
||||
SubtitleDuration = 0,
|
||||
Power = 100,
|
||||
Loop = true,
|
||||
Loop = false,
|
||||
alias=nil,
|
||||
}
|
||||
|
||||
--- Create a new RADIO Object. This doesn't broadcast a transmission, though, use @{#RADIO.Broadcast} to actually broadcast
|
||||
-- If you want to create a RADIO, you probably should use @{Wrapper.Positionable#POSITIONABLE.GetRadio}() instead
|
||||
--- Create a new RADIO Object. This doesn't broadcast a transmission, though, use @{#RADIO.Broadcast} to actually broadcast.
|
||||
-- If you want to create a RADIO, you probably should use @{Wrapper.Positionable#POSITIONABLE.GetRadio}() instead.
|
||||
-- @param #RADIO self
|
||||
-- @param Wrapper.Positionable#POSITIONABLE Positionable The @{Positionable} that will receive radio capabilities.
|
||||
-- @return #RADIO Radio
|
||||
-- @return #nil If Positionable is invalid
|
||||
-- @return #RADIO The RADIO object or #nil if Positionable is invalid.
|
||||
function RADIO:New(Positionable)
|
||||
|
||||
-- Inherit base
|
||||
local self = BASE:Inherit( self, BASE:New() ) -- Core.Radio#RADIO
|
||||
|
||||
self.Loop = true -- default Loop to true (not sure the above RADIO definition actually is working)
|
||||
self:F(Positionable)
|
||||
|
||||
if Positionable:GetPointVec2() then -- It's stupid, but the only way I found to make sure positionable is valid
|
||||
@@ -113,11 +114,27 @@ function RADIO:New(Positionable)
|
||||
return self
|
||||
end
|
||||
|
||||
self:E({"The passed positionable is invalid, no RADIO created", Positionable})
|
||||
self:E({error="The passed positionable is invalid, no RADIO created!", positionable=Positionable})
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Check validity of the filename passed and sets RADIO.FileName
|
||||
--- Set alias of the transmitter.
|
||||
-- @param #RADIO self
|
||||
-- @param #string alias Name of the radio transmitter.
|
||||
-- @return #RADIO self
|
||||
function RADIO:SetAlias(alias)
|
||||
self.alias=tostring(alias)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get alias of the transmitter.
|
||||
-- @param #RADIO self
|
||||
-- @return #string Name of the transmitter.
|
||||
function RADIO:GetAlias()
|
||||
return tostring(self.alias)
|
||||
end
|
||||
|
||||
--- Set the file name for the radio transmission.
|
||||
-- @param #RADIO self
|
||||
-- @param #string FileName File name of the sound file (i.e. "Noise.ogg")
|
||||
-- @return #RADIO self
|
||||
@@ -125,49 +142,63 @@ function RADIO:SetFileName(FileName)
|
||||
self:F2(FileName)
|
||||
|
||||
if type(FileName) == "string" then
|
||||
|
||||
if FileName:find(".ogg") or FileName:find(".wav") then
|
||||
if not FileName:find("l10n/DEFAULT/") then
|
||||
FileName = "l10n/DEFAULT/" .. FileName
|
||||
end
|
||||
|
||||
self.FileName = FileName
|
||||
return self
|
||||
end
|
||||
end
|
||||
|
||||
self:E({"File name invalid. Maybe something wrong with the extension ?", self.FileName})
|
||||
self:E({"File name invalid. Maybe something wrong with the extension?", FileName})
|
||||
return self
|
||||
end
|
||||
|
||||
--- Check validity of the frequency passed and sets RADIO.Frequency
|
||||
--- Set the frequency for the radio transmission.
|
||||
-- If the transmitting positionable is a unit or group, this also set the command "SetFrequency" with the defined frequency and modulation.
|
||||
-- @param #RADIO self
|
||||
-- @param #number Frequency in MHz (Ranges allowed for radio transmissions in DCS : 30-88 / 108-152 / 225-400MHz)
|
||||
-- @param #number Frequency Frequency in MHz. Ranges allowed for radio transmissions in DCS : 30-87.995 / 108-173.995 / 225-399.975MHz.
|
||||
-- @return #RADIO self
|
||||
function RADIO:SetFrequency(Frequency)
|
||||
self:F2(Frequency)
|
||||
|
||||
if type(Frequency) == "number" then
|
||||
|
||||
-- If frequency is in range
|
||||
if (Frequency >= 30 and Frequency < 88) or (Frequency >= 108 and Frequency < 152) or (Frequency >= 225 and Frequency < 400) then
|
||||
self.Frequency = Frequency * 1000000 -- Conversion in Hz
|
||||
if (Frequency >= 30 and Frequency <= 87.995) or (Frequency >= 108 and Frequency <= 173.995) or (Frequency >= 225 and Frequency <= 399.975) then
|
||||
|
||||
-- Convert frequency from MHz to Hz
|
||||
self.Frequency = Frequency * 1000000
|
||||
|
||||
-- If the RADIO is attached to a UNIT or a GROUP, we need to send the DCS Command "SetFrequency" to change the UNIT or GROUP frequency
|
||||
if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
|
||||
self.Positionable:SetCommand({
|
||||
|
||||
local commandSetFrequency={
|
||||
id = "SetFrequency",
|
||||
params = {
|
||||
frequency = self.Frequency,
|
||||
frequency = self.Frequency,
|
||||
modulation = self.Modulation,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
self:T2(commandSetFrequency)
|
||||
self.Positionable:SetCommand(commandSetFrequency)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
end
|
||||
self:E({"Frequency is outside of DCS Frequency ranges (30-80, 108-152, 225-400). Frequency unchanged.", self.Frequency})
|
||||
|
||||
self:E({"Frequency is outside of DCS Frequency ranges (30-80, 108-152, 225-400). Frequency unchanged.", Frequency})
|
||||
return self
|
||||
end
|
||||
|
||||
--- Check validity of the frequency passed and sets RADIO.Modulation
|
||||
--- Set AM or FM modulation of the radio transmitter.
|
||||
-- @param #RADIO self
|
||||
-- @param #number Modulation either radio.modulation.AM or radio.modulation.FM
|
||||
-- @param #number Modulation Modulation is either radio.modulation.AM or radio.modulation.FM.
|
||||
-- @return #RADIO self
|
||||
function RADIO:SetModulation(Modulation)
|
||||
self:F2(Modulation)
|
||||
@@ -183,23 +214,24 @@ end
|
||||
|
||||
--- Check validity of the power passed and sets RADIO.Power
|
||||
-- @param #RADIO self
|
||||
-- @param #number Power in W
|
||||
-- @param #number Power Power in W.
|
||||
-- @return #RADIO self
|
||||
function RADIO:SetPower(Power)
|
||||
self:F2(Power)
|
||||
|
||||
if type(Power) == "number" then
|
||||
self.Power = math.floor(math.abs(Power)) --TODO Find what is the maximum power allowed by DCS and limit power to that
|
||||
return self
|
||||
else
|
||||
self:E({"Power is invalid. Power unchanged.", self.Power})
|
||||
end
|
||||
self:E({"Power is invalid. Power unchanged.", self.Power})
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Check validity of the loop passed and sets RADIO.Loop
|
||||
--- Set message looping on or off.
|
||||
-- @param #RADIO self
|
||||
-- @param #boolean Loop
|
||||
-- @param #boolean Loop If true, message is repeated indefinitely.
|
||||
-- @return #RADIO self
|
||||
-- @usage
|
||||
function RADIO:SetLoop(Loop)
|
||||
self:F2(Loop)
|
||||
if type(Loop) == "boolean" then
|
||||
@@ -232,13 +264,12 @@ function RADIO:SetSubtitle(Subtitle, SubtitleDuration)
|
||||
self:E({"Subtitle is invalid. Subtitle reset.", self.Subtitle})
|
||||
end
|
||||
if type(SubtitleDuration) == "number" then
|
||||
if math.floor(math.abs(SubtitleDuration)) == SubtitleDuration then
|
||||
self.SubtitleDuration = SubtitleDuration
|
||||
return self
|
||||
end
|
||||
self.SubtitleDuration = SubtitleDuration
|
||||
else
|
||||
self.SubtitleDuration = 0
|
||||
self:E({"SubtitleDuration is invalid. SubtitleDuration reset.", self.SubtitleDuration})
|
||||
end
|
||||
self.SubtitleDuration = 0
|
||||
self:E({"SubtitleDuration is invalid. SubtitleDuration reset.", self.SubtitleDuration})
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create a new transmission, that is to say, populate the RADIO with relevant data
|
||||
@@ -246,10 +277,10 @@ end
|
||||
-- but it will work with a UNIT or a GROUP anyway.
|
||||
-- Only the #RADIO and the Filename are mandatory
|
||||
-- @param #RADIO self
|
||||
-- @param #string FileName
|
||||
-- @param #number Frequency in MHz
|
||||
-- @param #number Modulation either radio.modulation.AM or radio.modulation.FM
|
||||
-- @param #number Power in W
|
||||
-- @param #string FileName Name of the sound file that will be transmitted.
|
||||
-- @param #number Frequency Frequency in MHz.
|
||||
-- @param #number Modulation Modulation of frequency, which is either radio.modulation.AM or radio.modulation.FM.
|
||||
-- @param #number Power Power in W.
|
||||
-- @return #RADIO self
|
||||
function RADIO:NewGenericTransmission(FileName, Frequency, Modulation, Power, Loop)
|
||||
self:F({FileName, Frequency, Modulation, Power})
|
||||
@@ -269,31 +300,43 @@ end
|
||||
-- but it will work for any @{Wrapper.Positionable#POSITIONABLE}.
|
||||
-- Only the RADIO and the Filename are mandatory.
|
||||
-- @param #RADIO self
|
||||
-- @param #string FileName
|
||||
-- @param #string Subtitle
|
||||
-- @param #number SubtitleDuration in s
|
||||
-- @param #number Frequency in MHz
|
||||
-- @param #number Modulation either radio.modulation.AM or radio.modulation.FM
|
||||
-- @param #boolean Loop
|
||||
-- @param #string FileName Name of sound file.
|
||||
-- @param #string Subtitle Subtitle to be displayed with sound file.
|
||||
-- @param #number SubtitleDuration Duration of subtitle display in seconds.
|
||||
-- @param #number Frequency Frequency in MHz.
|
||||
-- @param #number Modulation Modulation which can be either radio.modulation.AM or radio.modulation.FM
|
||||
-- @param #boolean Loop If true, loop message.
|
||||
-- @return #RADIO self
|
||||
function RADIO:NewUnitTransmission(FileName, Subtitle, SubtitleDuration, Frequency, Modulation, Loop)
|
||||
self:F({FileName, Subtitle, SubtitleDuration, Frequency, Modulation, Loop})
|
||||
|
||||
-- Set file name.
|
||||
self:SetFileName(FileName)
|
||||
local Duration = 5
|
||||
if SubtitleDuration then Duration = SubtitleDuration end
|
||||
-- SubtitleDuration argument was missing, adding it
|
||||
if Subtitle then self:SetSubtitle(Subtitle, Duration) end
|
||||
-- self:SetSubtitleDuration is non existent, removing faulty line
|
||||
-- if SubtitleDuration then self:SetSubtitleDuration(SubtitleDuration) end
|
||||
if Frequency then self:SetFrequency(Frequency) end
|
||||
if Modulation then self:SetModulation(Modulation) end
|
||||
if Loop then self:SetLoop(Loop) end
|
||||
|
||||
-- Set modulation AM/FM.
|
||||
if Modulation then
|
||||
self:SetModulation(Modulation)
|
||||
end
|
||||
|
||||
-- Set frequency.
|
||||
if Frequency then
|
||||
self:SetFrequency(Frequency)
|
||||
end
|
||||
|
||||
-- Set subtitle.
|
||||
if Subtitle then
|
||||
self:SetSubtitle(Subtitle, SubtitleDuration or 0)
|
||||
end
|
||||
|
||||
-- Set Looping.
|
||||
if Loop then
|
||||
self:SetLoop(Loop)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Actually Broadcast the transmission
|
||||
--- Broadcast the transmission.
|
||||
-- * The Radio has to be populated with the new transmission before broadcasting.
|
||||
-- * Please use RADIO setters or either @{#RADIO.NewGenericTransmission} or @{#RADIO.NewUnitTransmission}
|
||||
-- * This class is in fact pretty smart, it determines the right DCS function to use depending on the type of POSITIONABLE
|
||||
@@ -302,31 +345,38 @@ end
|
||||
-- * If your POSITIONABLE is a UNIT or a GROUP, the Power is ignored.
|
||||
-- * If your POSITIONABLE is not a UNIT or a GROUP, the Subtitle, SubtitleDuration are ignored
|
||||
-- @param #RADIO self
|
||||
-- @param #boolean viatrigger Use trigger.action.radioTransmission() in any case, i.e. also for UNITS and GROUPS.
|
||||
-- @return #RADIO self
|
||||
function RADIO:Broadcast()
|
||||
self:F()
|
||||
function RADIO:Broadcast(viatrigger)
|
||||
self:F({viatrigger=viatrigger})
|
||||
|
||||
-- If the POSITIONABLE is actually a UNIT or a GROUP, use the more complicated DCS command system
|
||||
if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
|
||||
self:T2("Broadcasting from a UNIT or a GROUP")
|
||||
self.Positionable:SetCommand({
|
||||
-- If the POSITIONABLE is actually a UNIT or a GROUP, use the more complicated DCS command system.
|
||||
if (self.Positionable.ClassName=="UNIT" or self.Positionable.ClassName=="GROUP") and (not viatrigger) then
|
||||
self:T("Broadcasting from a UNIT or a GROUP")
|
||||
|
||||
local commandTransmitMessage={
|
||||
id = "TransmitMessage",
|
||||
params = {
|
||||
file = self.FileName,
|
||||
duration = self.SubtitleDuration,
|
||||
subtitle = self.Subtitle,
|
||||
loop = self.Loop,
|
||||
}
|
||||
})
|
||||
}}
|
||||
|
||||
self:T3(commandTransmitMessage)
|
||||
self.Positionable:SetCommand(commandTransmitMessage)
|
||||
else
|
||||
-- If the POSITIONABLE is anything else, we revert to the general singleton function
|
||||
-- I need to give it a unique name, so that the transmission can be stopped later. I use the class ID
|
||||
self:T2("Broadcasting from a POSITIONABLE")
|
||||
self:T("Broadcasting from a POSITIONABLE")
|
||||
trigger.action.radioTransmission(self.FileName, self.Positionable:GetPositionVec3(), self.Modulation, self.Loop, self.Frequency, self.Power, tostring(self.ID))
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Stops a transmission
|
||||
-- This function is especially usefull to stop the broadcast of looped transmissions
|
||||
-- @param #RADIO self
|
||||
@@ -335,10 +385,10 @@ function RADIO:StopBroadcast()
|
||||
self:F()
|
||||
-- If the POSITIONABLE is a UNIT or a GROUP, stop the transmission with the DCS "StopTransmission" command
|
||||
if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
|
||||
self.Positionable:SetCommand({
|
||||
id = "StopTransmission",
|
||||
params = {}
|
||||
})
|
||||
|
||||
local commandStopTransmission={id="StopTransmission", params={}}
|
||||
|
||||
self.Positionable:SetCommand(commandStopTransmission)
|
||||
else
|
||||
-- Else, we use the appropriate singleton funciton
|
||||
trigger.action.stopRadioTransmission(tostring(self.ID))
|
||||
@@ -364,24 +414,91 @@ end
|
||||
-- Use @{#BEACON:StopRadioBeacon}() to stop it.
|
||||
--
|
||||
-- @type BEACON
|
||||
-- @field #string ClassName Name of the class "BEACON".
|
||||
-- @field Wrapper.Controllable#CONTROLLABLE Positionable The @{#CONTROLLABLE} that will receive radio capabilities.
|
||||
-- @extends Core.Base#BASE
|
||||
BEACON = {
|
||||
ClassName = "BEACON",
|
||||
Positionable = nil,
|
||||
name=nil,
|
||||
}
|
||||
|
||||
--- Create a new BEACON Object. This doesn't activate the beacon, though, use @{#BEACON.AATACAN} or @{#BEACON.Generic}
|
||||
--- Beacon types supported by DCS.
|
||||
-- @type BEACON.Type
|
||||
-- @field #number NULL
|
||||
-- @field #number VOR
|
||||
-- @field #number DME
|
||||
-- @field #number VOR_DME
|
||||
-- @field #number TACAN
|
||||
-- @field #number VORTAC
|
||||
-- @field #number RSBN
|
||||
-- @field #number BROADCAST_STATION
|
||||
-- @field #number HOMER
|
||||
-- @field #number AIRPORT_HOMER
|
||||
-- @field #number AIRPORT_HOMER_WITH_MARKER
|
||||
-- @field #number ILS_FAR_HOMER
|
||||
-- @field #number ILS_NEAR_HOMER
|
||||
-- @field #number ILS_LOCALIZER
|
||||
-- @field #number ILS_GLIDESLOPE
|
||||
-- @field #number NAUTICAL_HOMER
|
||||
-- @field #number ICLS
|
||||
BEACON.Type={
|
||||
NULL = 0,
|
||||
VOR = 1,
|
||||
DME = 2,
|
||||
VOR_DME = 3,
|
||||
TACAN = 4,
|
||||
VORTAC = 5,
|
||||
RSBN = 32,
|
||||
BROADCAST_STATION = 1024,
|
||||
HOMER = 8,
|
||||
AIRPORT_HOMER = 4104,
|
||||
AIRPORT_HOMER_WITH_MARKER = 4136,
|
||||
ILS_FAR_HOMER = 16408,
|
||||
ILS_NEAR_HOMER = 16456,
|
||||
ILS_LOCALIZER = 16640,
|
||||
ILS_GLIDESLOPE = 16896,
|
||||
NAUTICAL_HOMER = 32776,
|
||||
ICLS = 131584,
|
||||
}
|
||||
|
||||
--- Beacon systems supported by DCS. https://wiki.hoggitworld.com/view/DCS_command_activateBeacon
|
||||
-- @type BEACON.System
|
||||
-- @field #number PAR_10
|
||||
-- @field #number RSBN_5
|
||||
-- @field #number TACAN
|
||||
-- @field #number TACAN_TANKER
|
||||
-- @field #number ILS_LOCALIZER (This is the one to be used for AA TACAN Tanker!)
|
||||
-- @field #number ILS_GLIDESLOPE
|
||||
-- @field #number BROADCAST_STATION
|
||||
BEACON.System={
|
||||
PAR_10 = 1,
|
||||
RSBN_5 = 2,
|
||||
TACAN = 3,
|
||||
TACAN_TANKER = 4,
|
||||
ILS_LOCALIZER = 5,
|
||||
ILS_GLIDESLOPE = 6,
|
||||
BROADCAST_STATION = 7,
|
||||
}
|
||||
|
||||
--- Create a new BEACON Object. This doesn't activate the beacon, though, use @{#BEACON.ActivateTACAN} etc.
|
||||
-- If you want to create a BEACON, you probably should use @{Wrapper.Positionable#POSITIONABLE.GetBeacon}() instead.
|
||||
-- @param #BEACON self
|
||||
-- @param Wrapper.Positionable#POSITIONABLE Positionable The @{Positionable} that will receive radio capabilities.
|
||||
-- @return #BEACON Beacon
|
||||
-- @return #nil If Positionable is invalid
|
||||
-- @return #BEACON Beacon object or #nil if the positionable is invalid.
|
||||
function BEACON:New(Positionable)
|
||||
local self = BASE:Inherit(self, BASE:New())
|
||||
|
||||
-- Inherit BASE.
|
||||
local self=BASE:Inherit(self, BASE:New()) --#BEACON
|
||||
|
||||
-- Debug.
|
||||
self:F(Positionable)
|
||||
|
||||
-- Set positionable.
|
||||
if Positionable:GetPointVec2() then -- It's stupid, but the only way I found to make sure positionable is valid
|
||||
self.Positionable = Positionable
|
||||
self.name=Positionable:GetName()
|
||||
self:I(string.format("New BEACON %s", tostring(self.name)))
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -390,44 +507,95 @@ function BEACON:New(Positionable)
|
||||
end
|
||||
|
||||
|
||||
--- Converts a TACAN Channel/Mode couple into a frequency in Hz
|
||||
--- Activates a TACAN BEACON.
|
||||
-- @param #BEACON self
|
||||
-- @param #number TACANChannel
|
||||
-- @param #string TACANMode
|
||||
-- @return #number Frequecy
|
||||
-- @return #nil if parameters are invalid
|
||||
function BEACON:_TACANToFrequency(TACANChannel, TACANMode)
|
||||
self:F3({TACANChannel, TACANMode})
|
||||
|
||||
if type(TACANChannel) ~= "number" then
|
||||
if TACANMode ~= "X" and TACANMode ~= "Y" then
|
||||
return nil -- error in arguments
|
||||
end
|
||||
-- @param #number Channel TACAN channel, i.e. the "10" part in "10Y".
|
||||
-- @param #string Mode TACAN mode, i.e. the "Y" part in "10Y".
|
||||
-- @param #string Message The Message that is going to be coded in Morse and broadcasted by the beacon.
|
||||
-- @param #boolean Bearing If true, beacon provides bearing information. If false (or nil), only distance information is available.
|
||||
-- @param #number Duration How long will the beacon last in seconds. Omit for forever.
|
||||
-- @return #BEACON self
|
||||
-- @usage
|
||||
-- -- Let's create a TACAN Beacon for a tanker
|
||||
-- local myUnit = UNIT:FindByName("MyUnit")
|
||||
-- local myBeacon = myUnit:GetBeacon() -- Creates the beacon
|
||||
--
|
||||
-- myBeacon:ActivateTACAN(20, "Y", "TEXACO", true) -- Activate the beacon
|
||||
function BEACON:ActivateTACAN(Channel, Mode, Message, Bearing, Duration)
|
||||
self:T({channel=Channel, mode=Mode, callsign=Message, bearing=Bearing, duration=Duration})
|
||||
|
||||
-- Get frequency.
|
||||
local Frequency=UTILS.TACANToFrequency(Channel, Mode)
|
||||
|
||||
-- Check.
|
||||
if not Frequency then
|
||||
self:E({"The passed TACAN channel is invalid, the BEACON is not emitting"})
|
||||
return self
|
||||
end
|
||||
|
||||
-- This code is largely based on ED's code, in DCS World\Scripts\World\Radio\BeaconTypes.lua, line 137.
|
||||
-- I have no idea what it does but it seems to work
|
||||
local A = 1151 -- 'X', channel >= 64
|
||||
local B = 64 -- channel >= 64
|
||||
-- Beacon type.
|
||||
local Type=BEACON.Type.TACAN
|
||||
|
||||
if TACANChannel < 64 then
|
||||
B = 1
|
||||
end
|
||||
-- Beacon system.
|
||||
local System=BEACON.System.TACAN
|
||||
|
||||
if TACANMode == 'Y' then
|
||||
A = 1025
|
||||
if TACANChannel < 64 then
|
||||
A = 1088
|
||||
end
|
||||
else -- 'X'
|
||||
if TACANChannel < 64 then
|
||||
A = 962
|
||||
-- Check if unit is an aircraft and set system accordingly.
|
||||
local AA=self.Positionable:IsAir()
|
||||
if AA then
|
||||
System=5 --NOTE: 5 is how you cat the correct tanker behaviour! --BEACON.System.TACAN_TANKER
|
||||
-- Check if "Y" mode is selected for aircraft.
|
||||
if Mode~="Y" then
|
||||
self:E({"WARNING: The POSITIONABLE you want to attach the AA Tacan Beacon is an aircraft: Mode should Y !The BEACON is not emitting.", self.Positionable})
|
||||
end
|
||||
end
|
||||
|
||||
return (A + TACANChannel - B) * 1000000
|
||||
-- Attached unit.
|
||||
local UnitID=self.Positionable:GetID()
|
||||
|
||||
-- Debug.
|
||||
self:I({string.format("BEACON Activating TACAN %s: Channel=%d%s, Morse=%s, Bearing=%s, Duration=%s!", tostring(self.name), Channel, Mode, Message, tostring(Bearing), tostring(Duration))})
|
||||
|
||||
-- Start beacon.
|
||||
self.Positionable:CommandActivateBeacon(Type, System, Frequency, UnitID, Channel, Mode, AA, Message, Bearing)
|
||||
|
||||
-- Stop sheduler.
|
||||
if Duration then
|
||||
self.Positionable:DeactivateBeacon(Duration)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Activates an ICLS BEACON. The unit the BEACON is attached to should be an aircraft carrier supporting this system.
|
||||
-- @param #BEACON self
|
||||
-- @param #number Channel ICLS channel.
|
||||
-- @param #string Callsign The Message that is going to be coded in Morse and broadcasted by the beacon.
|
||||
-- @param #number Duration How long will the beacon last in seconds. Omit for forever.
|
||||
-- @return #BEACON self
|
||||
function BEACON:ActivateICLS(Channel, Callsign, Duration)
|
||||
self:F({Channel=Channel, Callsign=Callsign, Duration=Duration})
|
||||
|
||||
-- Attached unit.
|
||||
local UnitID=self.Positionable:GetID()
|
||||
|
||||
-- Debug
|
||||
self:T2({"ICLS BEACON started!"})
|
||||
|
||||
-- Start beacon.
|
||||
self.Positionable:CommandActivateICLS(Channel, UnitID, Callsign)
|
||||
|
||||
-- Stop sheduler
|
||||
if Duration then -- Schedule the stop of the BEACON if asked by the MD
|
||||
self.Positionable:DeactivateBeacon(Duration)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Activates a TACAN BEACON on an Aircraft.
|
||||
-- @param #BEACON self
|
||||
@@ -480,7 +648,7 @@ function BEACON:AATACAN(TACANChannel, Message, Bearing, BeaconDuration)
|
||||
})
|
||||
|
||||
if BeaconDuration then -- Schedule the stop of the BEACON if asked by the MD
|
||||
SCHEDULER:New( nil,
|
||||
SCHEDULER:New(nil,
|
||||
function()
|
||||
self:StopAATACAN()
|
||||
end, {}, BeaconDuration)
|
||||
@@ -591,4 +759,45 @@ function BEACON:StopRadioBeacon()
|
||||
self:F()
|
||||
-- The unique name of the transmission is the class ID
|
||||
trigger.action.stopRadioTransmission(tostring(self.ID))
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- Converts a TACAN Channel/Mode couple into a frequency in Hz
|
||||
-- @param #BEACON self
|
||||
-- @param #number TACANChannel
|
||||
-- @param #string TACANMode
|
||||
-- @return #number Frequecy
|
||||
-- @return #nil if parameters are invalid
|
||||
function BEACON:_TACANToFrequency(TACANChannel, TACANMode)
|
||||
self:F3({TACANChannel, TACANMode})
|
||||
|
||||
if type(TACANChannel) ~= "number" then
|
||||
if TACANMode ~= "X" and TACANMode ~= "Y" then
|
||||
return nil -- error in arguments
|
||||
end
|
||||
end
|
||||
|
||||
-- This code is largely based on ED's code, in DCS World\Scripts\World\Radio\BeaconTypes.lua, line 137.
|
||||
-- I have no idea what it does but it seems to work
|
||||
local A = 1151 -- 'X', channel >= 64
|
||||
local B = 64 -- channel >= 64
|
||||
|
||||
if TACANChannel < 64 then
|
||||
B = 1
|
||||
end
|
||||
|
||||
if TACANMode == 'Y' then
|
||||
A = 1025
|
||||
if TACANChannel < 64 then
|
||||
A = 1088
|
||||
end
|
||||
else -- 'X'
|
||||
if TACANChannel < 64 then
|
||||
A = 962
|
||||
end
|
||||
end
|
||||
|
||||
return (A + TACANChannel - B) * 1000000
|
||||
end
|
||||
|
||||
|
||||
|
||||
567
Moose Development/Moose/Core/RadioQueue.lua
Normal file
567
Moose Development/Moose/Core/RadioQueue.lua
Normal file
@@ -0,0 +1,567 @@
|
||||
--- **Core** - Queues Radio Transmissions.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Features:
|
||||
--
|
||||
-- * Managed Radio Transmissions.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Authors: funkyfranky
|
||||
--
|
||||
-- @module Core.RadioQueue
|
||||
-- @image Core_Radio.JPG
|
||||
|
||||
--- Manages radio transmissions.
|
||||
--
|
||||
-- @type RADIOQUEUE
|
||||
-- @field #string ClassName Name of the class "RADIOQUEUE".
|
||||
-- @field #boolean Debug Debug mode. More info.
|
||||
-- @field #string lid ID for dcs.log.
|
||||
-- @field #number frequency The radio frequency in Hz.
|
||||
-- @field #number modulation The radio modulation. Either radio.modulation.AM or radio.modulation.FM.
|
||||
-- @field Core.Scheduler#SCHEDULER scheduler The scheduler.
|
||||
-- @field #string RQid The radio queue scheduler ID.
|
||||
-- @field #table queue The queue of transmissions.
|
||||
-- @field #string alias Name of the radio.
|
||||
-- @field #number dt Time interval in seconds for checking the radio queue.
|
||||
-- @field #number delay Time delay before starting the radio queue.
|
||||
-- @field #number Tlast Time (abs) when the last transmission finished.
|
||||
-- @field Core.Point#COORDINATE sendercoord Coordinate from where transmissions are broadcasted.
|
||||
-- @field #number sendername Name of the sending unit or static.
|
||||
-- @field #boolean senderinit Set frequency was initialized.
|
||||
-- @field #number power Power of radio station in Watts. Default 100 W.
|
||||
-- @field #table numbers Table of number transmission parameters.
|
||||
-- @field #boolean checking Scheduler is checking the radio queue.
|
||||
-- @field #boolean schedonce Call ScheduleOnce instead of normal scheduler.
|
||||
-- @extends Core.Base#BASE
|
||||
RADIOQUEUE = {
|
||||
ClassName = "RADIOQUEUE",
|
||||
Debug = nil,
|
||||
lid = nil,
|
||||
frequency = nil,
|
||||
modulation = nil,
|
||||
scheduler = nil,
|
||||
RQid = nil,
|
||||
queue = {},
|
||||
alias = nil,
|
||||
dt = nil,
|
||||
delay = nil,
|
||||
Tlast = nil,
|
||||
sendercoord = nil,
|
||||
sendername = nil,
|
||||
senderinit = nil,
|
||||
power = nil,
|
||||
numbers = {},
|
||||
checking = nil,
|
||||
schedonce = nil,
|
||||
}
|
||||
|
||||
--- Radio queue transmission data.
|
||||
-- @type RADIOQUEUE.Transmission
|
||||
-- @field #string filename Name of the file to be transmitted.
|
||||
-- @field #string path Path in miz file where the file is located.
|
||||
-- @field #number duration Duration in seconds.
|
||||
-- @field #string subtitle Subtitle of the transmission.
|
||||
-- @field #number subduration Duration of the subtitle being displayed.
|
||||
-- @field #number Tstarted Mission time (abs) in seconds when the transmission started.
|
||||
-- @field #boolean isplaying If true, transmission is currently playing.
|
||||
-- @field #number Tplay Mission time (abs) in seconds when the transmission should be played.
|
||||
-- @field #number interval Interval in seconds before next transmission.
|
||||
|
||||
|
||||
--- Create a new RADIOQUEUE object for a given radio frequency/modulation.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #number frequency The radio frequency in MHz.
|
||||
-- @param #number modulation (Optional) The radio modulation. Default radio.modulation.AM.
|
||||
-- @param #string alias (Optional) Name of the radio queue.
|
||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||
function RADIOQUEUE:New(frequency, modulation, alias)
|
||||
|
||||
-- Inherit base
|
||||
local self=BASE:Inherit(self, BASE:New()) -- #RADIOQUEUE
|
||||
|
||||
self.alias=alias or "My Radio"
|
||||
|
||||
self.lid=string.format("RADIOQUEUE %s | ", self.alias)
|
||||
|
||||
if frequency==nil then
|
||||
self:E(self.lid.."ERROR: No frequency specified as first parameter!")
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Frequency in Hz.
|
||||
self.frequency=frequency*1000000
|
||||
|
||||
-- Modulation.
|
||||
self.modulation=modulation or radio.modulation.AM
|
||||
|
||||
-- Set radio power.
|
||||
self:SetRadioPower()
|
||||
|
||||
-- Scheduler.
|
||||
self.scheduler=SCHEDULER:New()
|
||||
self.scheduler:NoTrace()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Start the radio queue.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #number delay (Optional) Delay in seconds, before the radio queue is started. Default 1 sec.
|
||||
-- @param #number dt (Optional) Time step in seconds for checking the queue. Default 0.01 sec.
|
||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||
function RADIOQUEUE:Start(delay, dt)
|
||||
|
||||
self.delay=delay or 1
|
||||
|
||||
self.dt=dt or 0.01
|
||||
|
||||
self:I(self.lid..string.format("Starting RADIOQUEUE %s on Frequency %.2f MHz [modulation=%d] in %.1f seconds (dt=%.3f sec)", self.alias, self.frequency/1000000, self.modulation, delay, dt))
|
||||
|
||||
|
||||
if self.schedonce then
|
||||
self:_CheckRadioQueueDelayed(self.delta)
|
||||
else
|
||||
--self.RQid=self.scheduler:Schedule(self, self._CheckRadioQueue, {}, delay, dt)
|
||||
self.RQid=self.scheduler:Schedule(nil, RADIOQUEUE._CheckRadioQueue, {self}, delay, dt)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Stop the radio queue. Stop scheduler and delete queue.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||
function RADIOQUEUE:Stop()
|
||||
self:I(self.lid.."Stopping RADIOQUEUE.")
|
||||
self.scheduler:Stop(self.RQid)
|
||||
self.queue={}
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set coordinate from where the transmission is broadcasted.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param Core.Point#COORDINATE coordinate Coordinate of the sender.
|
||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||
function RADIOQUEUE:SetSenderCoordinate(coordinate)
|
||||
self.sendercoord=coordinate
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set name of unit or static from which transmissions are made.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #string name Name of the unit or static used for transmissions.
|
||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||
function RADIOQUEUE:SetSenderUnitName(name)
|
||||
self.sendername=name
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set radio power. Note that this only applies if no relay unit is used.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #number power Radio power in Watts. Default 100 W.
|
||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||
function RADIOQUEUE:SetRadioPower(power)
|
||||
self.power=power or 100
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set parameters of a digit.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #number digit The digit 0-9.
|
||||
-- @param #string filename The name of the sound file.
|
||||
-- @param #number duration The duration of the sound file in seconds.
|
||||
-- @param #string path The directory within the miz file where the sound is located. Default "l10n/DEFAULT/".
|
||||
-- @param #string subtitle Subtitle of the transmission.
|
||||
-- @param #number subduration Duration [sec] of the subtitle being displayed. Default 5 sec.
|
||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||
function RADIOQUEUE:SetDigit(digit, filename, duration, path, subtitle, subduration)
|
||||
|
||||
local transmission={} --#RADIOQUEUE.Transmission
|
||||
transmission.filename=filename
|
||||
transmission.duration=duration
|
||||
transmission.path=path or "l10n/DEFAULT/"
|
||||
transmission.subtitle=nil
|
||||
transmission.subduration=nil
|
||||
|
||||
-- Convert digit to string in case it is given as a number.
|
||||
if type(digit)=="number" then
|
||||
digit=tostring(digit)
|
||||
end
|
||||
|
||||
-- Set transmission.
|
||||
self.numbers[digit]=transmission
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add a transmission to the radio queue.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #RADIOQUEUE.Transmission transmission The transmission data table.
|
||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||
function RADIOQUEUE:AddTransmission(transmission)
|
||||
self:F({transmission=transmission})
|
||||
|
||||
-- Init.
|
||||
transmission.isplaying=false
|
||||
transmission.Tstarted=nil
|
||||
|
||||
-- Add to queue.
|
||||
table.insert(self.queue, transmission)
|
||||
|
||||
-- Start checking.
|
||||
if self.schedonce and not self.checking then
|
||||
self:_CheckRadioQueueDelayed()
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add a transmission to the radio queue.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #string filename Name of the sound file. Usually an ogg or wav file type.
|
||||
-- @param #number duration Duration in seconds the file lasts.
|
||||
-- @param #number path Directory path inside the miz file where the sound file is located. Default "l10n/DEFAULT/".
|
||||
-- @param #number tstart Start time (abs) seconds. Default now.
|
||||
-- @param #number interval Interval in seconds after the last transmission finished.
|
||||
-- @param #string subtitle Subtitle of the transmission.
|
||||
-- @param #number subduration Duration [sec] of the subtitle being displayed. Default 5 sec.
|
||||
-- @return #RADIOQUEUE self The RADIOQUEUE object.
|
||||
function RADIOQUEUE:NewTransmission(filename, duration, path, tstart, interval, subtitle, subduration)
|
||||
|
||||
-- Sanity checks.
|
||||
if not filename then
|
||||
self:E(self.lid.."ERROR: No filename specified.")
|
||||
return nil
|
||||
end
|
||||
if type(filename)~="string" then
|
||||
self:E(self.lid.."ERROR: Filename specified is NOT a string.")
|
||||
return nil
|
||||
end
|
||||
|
||||
if not duration then
|
||||
self:E(self.lid.."ERROR: No duration of transmission specified.")
|
||||
return nil
|
||||
end
|
||||
if type(duration)~="number" then
|
||||
self:E(self.lid.."ERROR: Duration specified is NOT a number.")
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
local transmission={} --#RADIOQUEUE.Transmission
|
||||
transmission.filename=filename
|
||||
transmission.duration=duration
|
||||
transmission.path=path or "l10n/DEFAULT/"
|
||||
transmission.Tplay=tstart or timer.getAbsTime()
|
||||
transmission.subtitle=subtitle
|
||||
transmission.interval=interval or 0
|
||||
if transmission.subtitle then
|
||||
transmission.subduration=subduration or 5
|
||||
else
|
||||
transmission.subduration=nil
|
||||
end
|
||||
|
||||
-- Add transmission to queue.
|
||||
self:AddTransmission(transmission)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Convert a number (as string) into a radio transmission.
|
||||
-- E.g. for board number or headings.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #string number Number string, e.g. "032" or "183".
|
||||
-- @param #number delay Delay before transmission in seconds.
|
||||
-- @param #number interval Interval between the next call.
|
||||
-- @return #number Duration of the call in seconds.
|
||||
function RADIOQUEUE:Number2Transmission(number, delay, interval)
|
||||
|
||||
--- Split string into characters.
|
||||
local function _split(str)
|
||||
local chars={}
|
||||
for i=1,#str do
|
||||
local c=str:sub(i,i)
|
||||
table.insert(chars, c)
|
||||
end
|
||||
return chars
|
||||
end
|
||||
|
||||
-- Split string into characters.
|
||||
local numbers=_split(number)
|
||||
|
||||
local wait=0
|
||||
for i=1,#numbers do
|
||||
|
||||
-- Current number
|
||||
local n=numbers[i]
|
||||
|
||||
-- Radio call.
|
||||
local transmission=UTILS.DeepCopy(self.numbers[n]) --#RADIOQUEUE.Transmission
|
||||
|
||||
transmission.Tplay=timer.getAbsTime()+(delay or 0)
|
||||
|
||||
if interval and i==1 then
|
||||
transmission.interval=interval
|
||||
end
|
||||
|
||||
self:AddTransmission(transmission)
|
||||
|
||||
-- Add up duration of the number.
|
||||
wait=wait+transmission.duration
|
||||
end
|
||||
|
||||
-- Return the total duration of the call.
|
||||
return wait
|
||||
end
|
||||
|
||||
|
||||
--- Broadcast radio message.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #RADIOQUEUE.Transmission transmission The transmission.
|
||||
function RADIOQUEUE:Broadcast(transmission)
|
||||
|
||||
-- Get unit sending the transmission.
|
||||
local sender=self:_GetRadioSender()
|
||||
|
||||
-- Construct file name.
|
||||
local filename=string.format("%s%s", transmission.path, transmission.filename)
|
||||
|
||||
if sender then
|
||||
|
||||
-- Broadcasting from aircraft. Only players tuned in to the right frequency will see the message.
|
||||
self:T(self.lid..string.format("Broadcasting from aircraft %s", sender:GetName()))
|
||||
|
||||
|
||||
if not self.senderinit then
|
||||
|
||||
-- Command to set the Frequency for the transmission.
|
||||
local commandFrequency={
|
||||
id="SetFrequency",
|
||||
params={
|
||||
frequency=self.frequency, -- Frequency in Hz.
|
||||
modulation=self.modulation,
|
||||
}}
|
||||
|
||||
-- Set commend for frequency
|
||||
sender:SetCommand(commandFrequency)
|
||||
|
||||
self.senderinit=true
|
||||
end
|
||||
|
||||
-- Command to tranmit the call.
|
||||
local commandTransmit={
|
||||
id = "TransmitMessage",
|
||||
params = {
|
||||
file=filename,
|
||||
duration=transmission.subduration,
|
||||
subtitle=transmission.subtitle or "",
|
||||
loop=false,
|
||||
}}
|
||||
|
||||
-- Set command for radio transmission.
|
||||
sender:SetCommand(commandTransmit)
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("file=%s, freq=%.2f MHz, duration=%.2f sec, subtitle=%s", filename, self.frequency/1000000, transmission.duration, transmission.subtitle or "")
|
||||
MESSAGE:New(text, 2, "RADIOQUEUE "..self.alias):ToAllIf(self.Debug)
|
||||
|
||||
else
|
||||
|
||||
-- Broadcasting from carrier. No subtitle possible. Need to send messages to players.
|
||||
self:T(self.lid..string.format("Broadcasting via trigger.action.radioTransmission()."))
|
||||
|
||||
-- Position from where to transmit.
|
||||
local vec3=nil
|
||||
|
||||
-- Try to get positon from sender unit/static.
|
||||
if self.sendername then
|
||||
local coord=self:_GetRadioSenderCoord()
|
||||
if coord then
|
||||
vec3=coord:GetVec3()
|
||||
end
|
||||
end
|
||||
|
||||
-- Try to get fixed positon.
|
||||
if self.sendercoord and not vec3 then
|
||||
vec3=self.sendercoord:GetVec3()
|
||||
end
|
||||
|
||||
-- Transmit via trigger.
|
||||
if vec3 then
|
||||
self:T("Sending")
|
||||
self:T( { filename = filename, vec3 = vec3, modulation = self.modulation, frequency = self.frequency, power = self.power } )
|
||||
|
||||
-- Trigger transmission.
|
||||
trigger.action.radioTransmission(filename, vec3, self.modulation, false, self.frequency, self.power)
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("file=%s, freq=%.2f MHz, duration=%.2f sec, subtitle=%s", filename, self.frequency/1000000, transmission.duration, transmission.subtitle or "")
|
||||
MESSAGE:New(string.format(text, filename, transmission.duration, transmission.subtitle or ""), 5, "RADIOQUEUE "..self.alias):ToAllIf(self.Debug)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
--- Start checking the radio queue.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @param #number delay Delay in seconds before checking.
|
||||
function RADIOQUEUE:_CheckRadioQueueDelayed(delay)
|
||||
self.checking=true
|
||||
self:ScheduleOnce(delay or self.dt, RADIOQUEUE._CheckRadioQueue, self)
|
||||
end
|
||||
|
||||
--- Check radio queue for transmissions to be broadcasted.
|
||||
-- @param #RADIOQUEUE self
|
||||
function RADIOQUEUE:_CheckRadioQueue()
|
||||
--env.info("FF check radio queue "..self.alias)
|
||||
|
||||
-- Check if queue is empty.
|
||||
if #self.queue==0 then
|
||||
-- Queue is now empty. Nothing to else to do.
|
||||
self.checking=false
|
||||
return
|
||||
end
|
||||
|
||||
-- Get current abs time.
|
||||
local time=timer.getAbsTime()
|
||||
|
||||
local playing=false
|
||||
local next=nil --#RADIOQUEUE.Transmission
|
||||
local remove=nil
|
||||
for i,_transmission in ipairs(self.queue) do
|
||||
local transmission=_transmission --#RADIOQUEUE.Transmission
|
||||
|
||||
-- Check if transmission time has passed.
|
||||
if time>=transmission.Tplay then
|
||||
|
||||
-- Check if transmission is currently playing.
|
||||
if transmission.isplaying then
|
||||
|
||||
-- Check if transmission is finished.
|
||||
if time>=transmission.Tstarted+transmission.duration then
|
||||
|
||||
-- Transmission over.
|
||||
transmission.isplaying=false
|
||||
|
||||
-- Remove ith element in queue.
|
||||
remove=i
|
||||
|
||||
-- Store time last transmission finished.
|
||||
self.Tlast=time
|
||||
|
||||
else -- still playing
|
||||
|
||||
-- Transmission is still playing.
|
||||
playing=true
|
||||
|
||||
end
|
||||
|
||||
else -- not playing yet
|
||||
|
||||
local Tlast=self.Tlast
|
||||
|
||||
if transmission.interval==nil then
|
||||
|
||||
-- Not playing ==> this will be next.
|
||||
if next==nil then
|
||||
next=transmission
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
if Tlast==nil or time-Tlast>=transmission.interval then
|
||||
next=transmission
|
||||
else
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- We got a transmission or one with an interval that is not due yet. No need for anything else.
|
||||
if next or Tlast then
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Transmission not due yet.
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- Found a new transmission.
|
||||
if next~=nil and not playing then
|
||||
self:Broadcast(next)
|
||||
next.isplaying=true
|
||||
next.Tstarted=time
|
||||
end
|
||||
|
||||
-- Remove completed calls from queue.
|
||||
if remove then
|
||||
table.remove(self.queue, remove)
|
||||
end
|
||||
|
||||
-- Check queue.
|
||||
if self.schedonce then
|
||||
self:_CheckRadioQueueDelayed()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Get unit from which we want to transmit a radio message. This has to be an aircraft for subtitles to work.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @return Wrapper.Unit#UNIT Sending aircraft unit or nil if was not setup, is not an aircraft or is not alive.
|
||||
function RADIOQUEUE:_GetRadioSender()
|
||||
|
||||
-- Check if we have a sending aircraft.
|
||||
local sender=nil --Wrapper.Unit#UNIT
|
||||
|
||||
-- Try the general default.
|
||||
if self.sendername then
|
||||
-- First try to find a unit
|
||||
sender=UNIT:FindByName(self.sendername)
|
||||
|
||||
-- Check that sender is alive and an aircraft.
|
||||
if sender and sender:IsAlive() and sender:IsAir() then
|
||||
return sender
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Get unit from which we want to transmit a radio message. This has to be an aircraft for subtitles to work.
|
||||
-- @param #RADIOQUEUE self
|
||||
-- @return Core.Point#COORDINATE Coordinate of the sender unit.
|
||||
function RADIOQUEUE:_GetRadioSenderCoord()
|
||||
|
||||
local vec3=nil
|
||||
|
||||
-- Try the general default.
|
||||
if self.sendername then
|
||||
|
||||
-- First try to find a unit
|
||||
local sender=UNIT:FindByName(self.sendername)
|
||||
|
||||
-- Check that sender is alive and an aircraft.
|
||||
if sender and sender:IsAlive() then
|
||||
return sender:GetCoordinate()
|
||||
end
|
||||
|
||||
-- Now try a static.
|
||||
local sender=STATIC:FindByName( self.sendername, false )
|
||||
|
||||
-- Check that sender is alive and an aircraft.
|
||||
if sender then
|
||||
return sender:GetCoordinate()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
405
Moose Development/Moose/Core/RadioSpeech.lua
Normal file
405
Moose Development/Moose/Core/RadioSpeech.lua
Normal file
@@ -0,0 +1,405 @@
|
||||
--- **Core** - Makes the radio talk.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Features:
|
||||
--
|
||||
-- * Send text strings using a vocabulary that is converted in spoken language.
|
||||
-- * Possiblity to implement multiple language.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Authors: FlightControl
|
||||
--
|
||||
-- @module Core.RadioSpeech
|
||||
-- @image Core_Radio.JPG
|
||||
|
||||
--- Makes the radio speak.
|
||||
--
|
||||
-- # RADIOSPEECH usage
|
||||
--
|
||||
--
|
||||
-- @type RADIOSPEECH
|
||||
-- @extends Core.RadioQueue#RADIOQUEUE
|
||||
RADIOSPEECH = {
|
||||
ClassName = "RADIOSPEECH",
|
||||
Vocabulary = {
|
||||
EN = {},
|
||||
DE = {},
|
||||
RU = {},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RADIOSPEECH.Vocabulary.EN = {
|
||||
["1"] = { "1", 0.25 },
|
||||
["2"] = { "2", 0.25 },
|
||||
["3"] = { "3", 0.30 },
|
||||
["4"] = { "4", 0.35 },
|
||||
["5"] = { "5", 0.35 },
|
||||
["6"] = { "6", 0.42 },
|
||||
["7"] = { "7", 0.38 },
|
||||
["8"] = { "8", 0.20 },
|
||||
["9"] = { "9", 0.32 },
|
||||
["10"] = { "10", 0.35 },
|
||||
["11"] = { "11", 0.40 },
|
||||
["12"] = { "12", 0.42 },
|
||||
["13"] = { "13", 0.38 },
|
||||
["14"] = { "14", 0.42 },
|
||||
["15"] = { "15", 0.42 },
|
||||
["16"] = { "16", 0.52 },
|
||||
["17"] = { "17", 0.59 },
|
||||
["18"] = { "18", 0.40 },
|
||||
["19"] = { "19", 0.47 },
|
||||
["20"] = { "20", 0.38 },
|
||||
["30"] = { "30", 0.29 },
|
||||
["40"] = { "40", 0.35 },
|
||||
["50"] = { "50", 0.32 },
|
||||
["60"] = { "60", 0.44 },
|
||||
["70"] = { "70", 0.48 },
|
||||
["80"] = { "80", 0.26 },
|
||||
["90"] = { "90", 0.36 },
|
||||
["100"] = { "100", 0.55 },
|
||||
["200"] = { "200", 0.55 },
|
||||
["300"] = { "300", 0.61 },
|
||||
["400"] = { "400", 0.60 },
|
||||
["500"] = { "500", 0.61 },
|
||||
["600"] = { "600", 0.65 },
|
||||
["700"] = { "700", 0.70 },
|
||||
["800"] = { "800", 0.54 },
|
||||
["900"] = { "900", 0.60 },
|
||||
["1000"] = { "1000", 0.60 },
|
||||
["2000"] = { "2000", 0.61 },
|
||||
["3000"] = { "3000", 0.64 },
|
||||
["4000"] = { "4000", 0.62 },
|
||||
["5000"] = { "5000", 0.69 },
|
||||
["6000"] = { "6000", 0.69 },
|
||||
["7000"] = { "7000", 0.75 },
|
||||
["8000"] = { "8000", 0.59 },
|
||||
["9000"] = { "9000", 0.65 },
|
||||
|
||||
["chevy"] = { "chevy", 0.35 },
|
||||
["colt"] = { "colt", 0.35 },
|
||||
["springfield"] = { "springfield", 0.65 },
|
||||
["dodge"] = { "dodge", 0.35 },
|
||||
["enfield"] = { "enfield", 0.5 },
|
||||
["ford"] = { "ford", 0.32 },
|
||||
["pontiac"] = { "pontiac", 0.55 },
|
||||
["uzi"] = { "uzi", 0.28 },
|
||||
|
||||
["degrees"] = { "degrees", 0.5 },
|
||||
["kilometers"] = { "kilometers", 0.65 },
|
||||
["km"] = { "kilometers", 0.65 },
|
||||
["miles"] = { "miles", 0.45 },
|
||||
["meters"] = { "meters", 0.41 },
|
||||
["mi"] = { "miles", 0.45 },
|
||||
["feet"] = { "feet", 0.29 },
|
||||
|
||||
["br"] = { "br", 1.1 },
|
||||
["bra"] = { "bra", 0.3 },
|
||||
|
||||
|
||||
["returning to base"] = { "returning_to_base", 0.85 },
|
||||
["on route to ground target"] = { "on_route_to_ground_target", 1.05 },
|
||||
["intercepting bogeys"] = { "intercepting_bogeys", 1.00 },
|
||||
["engaging ground target"] = { "engaging_ground_target", 1.20 },
|
||||
["engaging bogeys"] = { "engaging_bogeys", 0.81 },
|
||||
["wheels up"] = { "wheels_up", 0.42 },
|
||||
["landing at base"] = { "landing at base", 0.8 },
|
||||
["patrolling"] = { "patrolling", 0.55 },
|
||||
|
||||
["for"] = { "for", 0.31 },
|
||||
["and"] = { "and", 0.31 },
|
||||
["at"] = { "at", 0.3 },
|
||||
["dot"] = { "dot", 0.26 },
|
||||
["defender"] = { "defender", 0.45 },
|
||||
}
|
||||
|
||||
RADIOSPEECH.Vocabulary.RU = {
|
||||
["1"] = { "1", 0.34 },
|
||||
["2"] = { "2", 0.30 },
|
||||
["3"] = { "3", 0.23 },
|
||||
["4"] = { "4", 0.51 },
|
||||
["5"] = { "5", 0.31 },
|
||||
["6"] = { "6", 0.44 },
|
||||
["7"] = { "7", 0.25 },
|
||||
["8"] = { "8", 0.43 },
|
||||
["9"] = { "9", 0.45 },
|
||||
["10"] = { "10", 0.53 },
|
||||
["11"] = { "11", 0.66 },
|
||||
["12"] = { "12", 0.70 },
|
||||
["13"] = { "13", 0.66 },
|
||||
["14"] = { "14", 0.80 },
|
||||
["15"] = { "15", 0.65 },
|
||||
["16"] = { "16", 0.75 },
|
||||
["17"] = { "17", 0.74 },
|
||||
["18"] = { "18", 0.85 },
|
||||
["19"] = { "19", 0.80 },
|
||||
["20"] = { "20", 0.58 },
|
||||
["30"] = { "30", 0.51 },
|
||||
["40"] = { "40", 0.51 },
|
||||
["50"] = { "50", 0.67 },
|
||||
["60"] = { "60", 0.76 },
|
||||
["70"] = { "70", 0.68 },
|
||||
["80"] = { "80", 0.84 },
|
||||
["90"] = { "90", 0.71 },
|
||||
["100"] = { "100", 0.35 },
|
||||
["200"] = { "200", 0.59 },
|
||||
["300"] = { "300", 0.53 },
|
||||
["400"] = { "400", 0.70 },
|
||||
["500"] = { "500", 0.50 },
|
||||
["600"] = { "600", 0.58 },
|
||||
["700"] = { "700", 0.64 },
|
||||
["800"] = { "800", 0.77 },
|
||||
["900"] = { "900", 0.75 },
|
||||
["1000"] = { "1000", 0.87 },
|
||||
["2000"] = { "2000", 0.83 },
|
||||
["3000"] = { "3000", 0.84 },
|
||||
["4000"] = { "4000", 1.00 },
|
||||
["5000"] = { "5000", 0.77 },
|
||||
["6000"] = { "6000", 0.90 },
|
||||
["7000"] = { "7000", 0.77 },
|
||||
["8000"] = { "8000", 0.92 },
|
||||
["9000"] = { "9000", 0.87 },
|
||||
|
||||
["степени"] = { "degrees", 0.5 },
|
||||
["километров"] = { "kilometers", 0.65 },
|
||||
["km"] = { "kilometers", 0.65 },
|
||||
["миль"] = { "miles", 0.45 },
|
||||
["mi"] = { "miles", 0.45 },
|
||||
["метры"] = { "meters", 0.41 },
|
||||
["m"] = { "meters", 0.41 },
|
||||
["ноги"] = { "feet", 0.37 },
|
||||
|
||||
["br"] = { "br", 1.1 },
|
||||
["bra"] = { "bra", 0.3 },
|
||||
|
||||
|
||||
["возвращаясь на базу"] = { "returning_to_base", 1.40 },
|
||||
["на пути к наземной цели"] = { "on_route_to_ground_target", 1.45 },
|
||||
["перехват самолетов"] = { "intercepting_bogeys", 1.22 },
|
||||
["поражение наземной цели"] = { "engaging_ground_target", 1.53 },
|
||||
["захватывающие самолеты"] = { "engaging_bogeys", 1.68 },
|
||||
["колеса вверх"] = { "wheels_up", 0.92 },
|
||||
["посадка на базу"] = { "landing at base", 1.04 },
|
||||
["патрулирующий"] = { "patrolling", 0.96 },
|
||||
|
||||
["за"] = { "for", 0.27 },
|
||||
["и"] = { "and", 0.17 },
|
||||
["в"] = { "at", 0.19 },
|
||||
["dot"] = { "dot", 0.51 },
|
||||
["defender"] = { "defender", 0.45 },
|
||||
}
|
||||
|
||||
--- Create a new RADIOSPEECH object for a given radio frequency/modulation.
|
||||
-- @param #RADIOSPEECH self
|
||||
-- @param #number frequency The radio frequency in MHz.
|
||||
-- @param #number modulation (Optional) The radio modulation. Default radio.modulation.AM.
|
||||
-- @return #RADIOSPEECH self The RADIOSPEECH object.
|
||||
function RADIOSPEECH:New(frequency, modulation)
|
||||
|
||||
-- Inherit base
|
||||
local self = BASE:Inherit( self, RADIOQUEUE:New( frequency, modulation ) ) -- #RADIOSPEECH
|
||||
|
||||
self.Language = "EN"
|
||||
|
||||
self:BuildTree()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function RADIOSPEECH:SetLanguage( Langauge )
|
||||
|
||||
self.Language = Langauge
|
||||
end
|
||||
|
||||
|
||||
--- Add Sentence to the Speech collection.
|
||||
-- @param #RADIOSPEECH self
|
||||
-- @param #string RemainingSentence The remaining sentence during recursion.
|
||||
-- @param #table Speech The speech node.
|
||||
-- @param #string Sentence The full sentence.
|
||||
-- @param #string Data The speech data.
|
||||
-- @return #RADIOSPEECH self The RADIOSPEECH object.
|
||||
function RADIOSPEECH:AddSentenceToSpeech( RemainingSentence, Speech, Sentence, Data )
|
||||
|
||||
self:I( { RemainingSentence, Speech, Sentence, Data } )
|
||||
|
||||
local Token, RemainingSentence = RemainingSentence:match( "^ *([^ ]+)(.*)" )
|
||||
self:I( { Token = Token, RemainingSentence = RemainingSentence } )
|
||||
|
||||
-- Is there a Token?
|
||||
if Token then
|
||||
|
||||
-- We check if the Token is already in the Speech collection.
|
||||
if not Speech[Token] then
|
||||
|
||||
-- There is not yet a vocabulary registered for this.
|
||||
Speech[Token] = {}
|
||||
|
||||
if RemainingSentence and RemainingSentence ~= "" then
|
||||
-- We use recursion to iterate through the complete Sentence, and make a chain of Tokens.
|
||||
-- The last Speech node in the collection contains the Sentence and the Data to be spoken.
|
||||
-- This to ensure that during the actual speech:
|
||||
-- - Complete sentences are being understood.
|
||||
-- - Words without speech are ignored.
|
||||
-- - Incorrect sequence of words are ignored.
|
||||
Speech[Token].Next = {}
|
||||
self:AddSentenceToSpeech( RemainingSentence, Speech[Token].Next, Sentence, Data )
|
||||
else
|
||||
-- There is no remaining sentence, so we add speech to the Sentence.
|
||||
-- The recursion stops here.
|
||||
Speech[Token].Sentence = Sentence
|
||||
Speech[Token].Data = Data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Build the tree structure based on the language words, in order to find the correct sentences and to ignore incomprehensible words.
|
||||
-- @param #RADIOSPEECH self
|
||||
-- @return #RADIOSPEECH self The RADIOSPEECH object.
|
||||
function RADIOSPEECH:BuildTree()
|
||||
|
||||
self.Speech = {}
|
||||
|
||||
for Language, Sentences in pairs( self.Vocabulary ) do
|
||||
self:I( { Language = Language, Sentences = Sentences })
|
||||
self.Speech[Language] = {}
|
||||
for Sentence, Data in pairs( Sentences ) do
|
||||
self:I( { Sentence = Sentence, Data = Data } )
|
||||
self:AddSentenceToSpeech( Sentence, self.Speech[Language], Sentence, Data )
|
||||
end
|
||||
end
|
||||
|
||||
self:I( { Speech = self.Speech } )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Speak a sentence.
|
||||
-- @param #RADIOSPEECH self
|
||||
-- @param #string Sentence The sentence to be spoken.
|
||||
function RADIOSPEECH:SpeakWords( Sentence, Speech, Language )
|
||||
|
||||
local OriginalSentence = Sentence
|
||||
|
||||
-- lua does not parse UTF-8, so the match statement will fail on cyrillic using %a.
|
||||
-- therefore, the only way to parse the statement is to use blank, comma or dot as a delimiter.
|
||||
-- and then check if the character can be converted to a number or not.
|
||||
local Word, RemainderSentence = Sentence:match( "^[., ]*([^ .,]+)(.*)" )
|
||||
|
||||
self:I( { Word = Word, Speech = Speech[Word], RemainderSentence = RemainderSentence } )
|
||||
|
||||
|
||||
if Word then
|
||||
if Word ~= "" and tonumber(Word) == nil then
|
||||
|
||||
-- Construct of words
|
||||
Word = Word:lower()
|
||||
if Speech[Word] then
|
||||
-- The end of the sentence has been reached. Now Speech.Next should be nil, otherwise there is an error.
|
||||
if Speech[Word].Next == nil then
|
||||
self:I( { Sentence = Speech[Word].Sentence, Data = Speech[Word].Data } )
|
||||
self:NewTransmission( Speech[Word].Data[1] .. ".wav", Speech[Word].Data[2], Language .. "/" )
|
||||
else
|
||||
if RemainderSentence and RemainderSentence ~= "" then
|
||||
return self:SpeakWords( RemainderSentence, Speech[Word].Next, Language )
|
||||
end
|
||||
end
|
||||
end
|
||||
return RemainderSentence
|
||||
end
|
||||
return OriginalSentence
|
||||
else
|
||||
return ""
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Speak a sentence.
|
||||
-- @param #RADIOSPEECH self
|
||||
-- @param #string Sentence The sentence to be spoken.
|
||||
function RADIOSPEECH:SpeakDigits( Sentence, Speech, Langauge )
|
||||
|
||||
local OriginalSentence = Sentence
|
||||
|
||||
-- lua does not parse UTF-8, so the match statement will fail on cyrillic using %a.
|
||||
-- therefore, the only way to parse the statement is to use blank, comma or dot as a delimiter.
|
||||
-- and then check if the character can be converted to a number or not.
|
||||
local Digits, RemainderSentence = Sentence:match( "^[., ]*([^ .,]+)(.*)" )
|
||||
|
||||
self:I( { Digits = Digits, Speech = Speech[Digits], RemainderSentence = RemainderSentence } )
|
||||
|
||||
if Digits then
|
||||
if Digits ~= "" and tonumber( Digits ) ~= nil then
|
||||
|
||||
-- Construct numbers
|
||||
local Number = tonumber( Digits )
|
||||
local Multiple = nil
|
||||
while Number >= 0 do
|
||||
if Number > 1000 then
|
||||
Multiple = math.floor( Number / 1000 ) * 1000
|
||||
elseif Number > 100 then
|
||||
Multiple = math.floor( Number / 100 ) * 100
|
||||
elseif Number > 20 then
|
||||
Multiple = math.floor( Number / 10 ) * 10
|
||||
elseif Number >= 0 then
|
||||
Multiple = Number
|
||||
end
|
||||
Sentence = tostring( Multiple )
|
||||
if Speech[Sentence] then
|
||||
self:I( { Speech = Speech[Sentence].Sentence, Data = Speech[Sentence].Data } )
|
||||
self:NewTransmission( Speech[Sentence].Data[1] .. ".wav", Speech[Sentence].Data[2], Langauge .. "/" )
|
||||
end
|
||||
Number = Number - Multiple
|
||||
Number = ( Number == 0 ) and -1 or Number
|
||||
end
|
||||
return RemainderSentence
|
||||
end
|
||||
return OriginalSentence
|
||||
else
|
||||
return ""
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Speak a sentence.
|
||||
-- @param #RADIOSPEECH self
|
||||
-- @param #string Sentence The sentence to be spoken.
|
||||
function RADIOSPEECH:Speak( Sentence, Language )
|
||||
|
||||
self:I( { Sentence, Language } )
|
||||
|
||||
local Language = Language or "EN"
|
||||
|
||||
self:I( { Language = Language } )
|
||||
|
||||
-- If there is no node for Speech, then we start at the first nodes of the language.
|
||||
local Speech = self.Speech[Language]
|
||||
|
||||
self:I( { Speech = Speech, Language = Language } )
|
||||
|
||||
self:NewTransmission( "_In.wav", 0.52, Language .. "/" )
|
||||
|
||||
repeat
|
||||
|
||||
Sentence = self:SpeakWords( Sentence, Speech, Language )
|
||||
|
||||
self:I( { Sentence = Sentence } )
|
||||
|
||||
Sentence = self:SpeakDigits( Sentence, Speech, Language )
|
||||
|
||||
self:I( { Sentence = Sentence } )
|
||||
|
||||
-- Sentence = self:SpeakSymbols( Sentence, Speech )
|
||||
--
|
||||
-- self:I( { Sentence = Sentence } )
|
||||
|
||||
until not Sentence or Sentence == ""
|
||||
|
||||
self:NewTransmission( "_Out.wav", 0.28, Language .. "/" )
|
||||
|
||||
end
|
||||
@@ -70,11 +70,12 @@ function REPORT:Add( Text )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add a new line to a REPORT.
|
||||
--- Add a new line to a REPORT, but indented. A separator character can be specified to separate the reported lines visually.
|
||||
-- @param #REPORT self
|
||||
-- @param #string Text
|
||||
-- @param #string Text The report text.
|
||||
-- @param #string Separator (optional) The start of each report line can begin with an optional separator character. This can be a "-", or "#", or "*". You're free to choose what you find the best.
|
||||
-- @return #REPORT
|
||||
function REPORT:AddIndent( Text, Separator ) --R2.1
|
||||
function REPORT:AddIndent( Text, Separator )
|
||||
self.Report[#self.Report+1] = ( ( Separator and Separator .. string.rep( " ", self.Indent - 1 ) ) or string.rep(" ", self.Indent ) ) .. Text:gsub("\n","\n"..string.rep( " ", self.Indent ) )
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -52,8 +52,8 @@ end
|
||||
-- Nothing of this code should be modified without testing it thoroughly.
|
||||
-- @param #SCHEDULEDISPATCHER self
|
||||
-- @param Core.Scheduler#SCHEDULER Scheduler
|
||||
function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleArguments, Start, Repeat, Randomize, Stop )
|
||||
self:F2( { Scheduler, ScheduleFunction, ScheduleArguments, Start, Repeat, Randomize, Stop } )
|
||||
function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleArguments, Start, Repeat, Randomize, Stop, TraceLevel, Fsm )
|
||||
self:F2( { Scheduler, ScheduleFunction, ScheduleArguments, Start, Repeat, Randomize, Stop, TraceLevel } )
|
||||
|
||||
self.CallID = self.CallID + 1
|
||||
local CallID = self.CallID .. "#" .. ( Scheduler.MasterObject and Scheduler.MasterObject.GetClassNameAndID and Scheduler.MasterObject:GetClassNameAndID() or "" ) or ""
|
||||
@@ -84,11 +84,52 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
|
||||
self.Schedule[Scheduler][CallID].Repeat = Repeat or 0
|
||||
self.Schedule[Scheduler][CallID].Randomize = Randomize or 0
|
||||
self.Schedule[Scheduler][CallID].Stop = Stop
|
||||
|
||||
|
||||
-- This section handles the tracing of the scheduled calls.
|
||||
-- Because these calls will be executed with a delay, we inspect the place where these scheduled calls are initiated.
|
||||
-- The Info structure contains the output of the debug.getinfo() calls, which inspects the call stack for the function name, line number and source name.
|
||||
-- The call stack has many levels, and the correct semantical function call depends on where in the code AddSchedule was "used".
|
||||
-- - Using SCHEDULER:New()
|
||||
-- - Using Schedule:AddSchedule()
|
||||
-- - Using Fsm:__Func()
|
||||
-- - Using Class:ScheduleOnce()
|
||||
-- - Using Class:ScheduleRepeat()
|
||||
-- - ...
|
||||
-- So for each of these scheduled call variations, AddSchedule is the workhorse which will schedule the call.
|
||||
-- But the correct level with the correct semantical function location will differ depending on the above scheduled call invocation forms.
|
||||
-- That's where the field TraceLevel contains optionally the level in the call stack where the call information is obtained.
|
||||
-- The TraceLevel field indicates the correct level where the semantical scheduled call was invoked within the source, ensuring that function name, line number and source name are correct.
|
||||
-- There is one quick ...
|
||||
-- The FSM class models scheduled calls using the __Func syntax. However, these functions are "tailed".
|
||||
-- There aren't defined anywhere within the source code, but rather implemented as triggers within the FSM logic,
|
||||
-- and using the onbefore, onafter, onenter, onleave prefixes. (See the FSM for details).
|
||||
-- Therefore, in the call stack, at the TraceLevel these functions are mentioned as "tail calls", and the Info.name field will be nil as a result.
|
||||
-- To obtain the correct function name for FSM object calls, the function is mentioned in the call stack at a higher stack level.
|
||||
-- So when function name stored in Info.name is nil, then I inspect the function name within the call stack one level higher.
|
||||
-- So this little piece of code does its magic wonderfully, preformance overhead is neglectible, as scheduled calls don't happen that often.
|
||||
|
||||
local Info = {}
|
||||
|
||||
if debug then
|
||||
TraceLevel = TraceLevel or 2
|
||||
Info = debug.getinfo( TraceLevel, "nlS" )
|
||||
local name_fsm = debug.getinfo( TraceLevel - 1, "n" ).name -- #string
|
||||
if name_fsm then
|
||||
Info.name = name_fsm
|
||||
end
|
||||
--env.info( debug.traceback() )
|
||||
end
|
||||
|
||||
self:T3( self.Schedule[Scheduler][CallID] )
|
||||
|
||||
self.Schedule[Scheduler][CallID].CallHandler = function( CallID )
|
||||
--self:E( CallID )
|
||||
self.Schedule[Scheduler][CallID].CallHandler = function( Params )
|
||||
|
||||
local CallID = Params.CallID
|
||||
local Info = Params.Info
|
||||
local Source = Info.source or "?"
|
||||
local Line = Info.currentline or "?"
|
||||
local Name = Info.name or "?"
|
||||
|
||||
local ErrorHandler = function( errmsg )
|
||||
env.info( "Error in timer function: " .. errmsg )
|
||||
@@ -121,16 +162,25 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
|
||||
local Randomize = Schedule.Randomize or 0
|
||||
local Stop = Schedule.Stop or 0
|
||||
local ScheduleID = Schedule.ScheduleID
|
||||
local ShowTrace = Scheduler.ShowTrace
|
||||
|
||||
local Prefix = ( Repeat == 0 ) and "--->" or "+++>"
|
||||
|
||||
local Status, Result
|
||||
--self:E( { SchedulerObject = SchedulerObject } )
|
||||
if SchedulerObject then
|
||||
local function Timer()
|
||||
if ShowTrace then
|
||||
SchedulerObject:T( Prefix .. Name .. ":" .. Line .. " (" .. Source .. ")" )
|
||||
end
|
||||
return ScheduleFunction( SchedulerObject, unpack( ScheduleArguments ) )
|
||||
end
|
||||
Status, Result = xpcall( Timer, ErrorHandler )
|
||||
else
|
||||
local function Timer()
|
||||
if ShowTrace then
|
||||
self:T( Prefix .. Name .. ":" .. Line .. " (" .. Source .. ")" )
|
||||
end
|
||||
return ScheduleFunction( unpack( ScheduleArguments ) )
|
||||
end
|
||||
Status, Result = xpcall( Timer, ErrorHandler )
|
||||
@@ -161,13 +211,13 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
|
||||
self:Stop( Scheduler, CallID )
|
||||
end
|
||||
else
|
||||
self:E( "Scheduled obsolete call for CallID: " .. CallID )
|
||||
self:I( "<<<>" .. Name .. ":" .. Line .. " (" .. Source .. ")" )
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
self:Start( Scheduler, CallID )
|
||||
self:Start( Scheduler, CallID, Info )
|
||||
|
||||
return CallID
|
||||
end
|
||||
@@ -181,7 +231,7 @@ function SCHEDULEDISPATCHER:RemoveSchedule( Scheduler, CallID )
|
||||
end
|
||||
end
|
||||
|
||||
function SCHEDULEDISPATCHER:Start( Scheduler, CallID )
|
||||
function SCHEDULEDISPATCHER:Start( Scheduler, CallID, Info )
|
||||
self:F2( { Start = CallID, Scheduler = Scheduler } )
|
||||
|
||||
if CallID then
|
||||
@@ -192,13 +242,13 @@ function SCHEDULEDISPATCHER:Start( Scheduler, CallID )
|
||||
Schedule[CallID].StartTime = timer.getTime() -- Set the StartTime field to indicate when the scheduler started.
|
||||
Schedule[CallID].ScheduleID = timer.scheduleFunction(
|
||||
Schedule[CallID].CallHandler,
|
||||
CallID,
|
||||
{ CallID = CallID, Info = Info },
|
||||
timer.getTime() + Schedule[CallID].Start
|
||||
)
|
||||
end
|
||||
else
|
||||
for CallID, Schedule in pairs( self.Schedule[Scheduler] or {} ) do
|
||||
self:Start( Scheduler, CallID ) -- Recursive
|
||||
self:Start( Scheduler, CallID, Info ) -- Recursive
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -229,5 +279,9 @@ function SCHEDULEDISPATCHER:Clear( Scheduler )
|
||||
end
|
||||
end
|
||||
|
||||
function SCHEDULEDISPATCHER:NoTrace( Scheduler )
|
||||
self:F2( { Scheduler = Scheduler } )
|
||||
|
||||
Scheduler.ShowTrace = nil
|
||||
end
|
||||
|
||||
|
||||
@@ -214,9 +214,10 @@ function SCHEDULER:New( SchedulerObject, SchedulerFunction, SchedulerArguments,
|
||||
local ScheduleID = nil
|
||||
|
||||
self.MasterObject = SchedulerObject
|
||||
self.ShowTrace = true
|
||||
|
||||
if SchedulerFunction then
|
||||
ScheduleID = self:Schedule( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop )
|
||||
ScheduleID = self:Schedule( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop, 4 )
|
||||
end
|
||||
|
||||
return self, ScheduleID
|
||||
@@ -238,7 +239,7 @@ end
|
||||
-- @param #number RandomizeFactor Specifies a randomization factor between 0 and 1 to randomize the Repeat.
|
||||
-- @param #number Stop Specifies the amount of seconds when the scheduler will be stopped.
|
||||
-- @return #number The ScheduleID of the planned schedule.
|
||||
function SCHEDULER:Schedule( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop )
|
||||
function SCHEDULER:Schedule( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop, TraceLevel, Fsm )
|
||||
self:F2( { Start, Repeat, RandomizeFactor, Stop } )
|
||||
self:T3( { SchedulerArguments } )
|
||||
|
||||
@@ -256,7 +257,9 @@ function SCHEDULER:Schedule( SchedulerObject, SchedulerFunction, SchedulerArgume
|
||||
Start,
|
||||
Repeat,
|
||||
RandomizeFactor,
|
||||
Stop
|
||||
Stop,
|
||||
TraceLevel or 3,
|
||||
Fsm
|
||||
)
|
||||
|
||||
self.Schedules[#self.Schedules+1] = ScheduleID
|
||||
@@ -299,6 +302,14 @@ function SCHEDULER:Clear()
|
||||
_SCHEDULEDISPATCHER:Clear( self )
|
||||
end
|
||||
|
||||
--- No tracing for this scheduler.
|
||||
-- @param #SCHEDULER self
|
||||
-- @param #number ScheduleID (optional) The ScheduleID of the planned (repeating) schedule.
|
||||
function SCHEDULER:NoTrace()
|
||||
|
||||
_SCHEDULEDISPATCHER:NoTrace( self )
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -125,11 +125,25 @@ do -- SET_BASE
|
||||
self.Index = {}
|
||||
|
||||
self.CallScheduler = SCHEDULER:New( self )
|
||||
|
||||
|
||||
self:SetEventPriority( 2 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Clear the Objects in the Set.
|
||||
-- @param #SET_BASE self
|
||||
-- @return #SET_BASE self
|
||||
function SET_BASE:Clear()
|
||||
|
||||
for Name, Object in pairs( self.Set ) do
|
||||
self:Remove( Name )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Finds an @{Core.Base#BASE} object based on the object Name.
|
||||
-- @param #SET_BASE self
|
||||
@@ -148,7 +162,7 @@ do -- SET_BASE
|
||||
function SET_BASE:GetSet()
|
||||
self:F2()
|
||||
|
||||
return self.Set
|
||||
return self.Set or {}
|
||||
end
|
||||
|
||||
--- Gets a list of the Names of the Objects in the Set.
|
||||
@@ -327,6 +341,25 @@ do -- SET_BASE
|
||||
return self
|
||||
end
|
||||
|
||||
--- Define the SET iterator **"limit"**.
|
||||
-- @param #SET_BASE self
|
||||
-- @param #number Limit Defines how many objects are evaluated of the set as part of the Some iterators. The default is 1.
|
||||
-- @return #SET_BASE self
|
||||
function SET_BASE:SetSomeIteratorLimit( Limit )
|
||||
|
||||
self.SomeIteratorLimit = Limit or 1
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the SET iterator **"limit"**.
|
||||
-- @param #SET_BASE self
|
||||
-- @return #number Defines how many objects are evaluated of the set as part of the Some iterators.
|
||||
function SET_BASE:GetSomeIteratorLimit()
|
||||
|
||||
return self.SomeIteratorLimit or self:Count()
|
||||
end
|
||||
|
||||
|
||||
--- Filters for the defined collection.
|
||||
-- @param #SET_BASE self
|
||||
@@ -351,7 +384,6 @@ do -- SET_BASE
|
||||
for ObjectName, Object in pairs( self.Database ) do
|
||||
|
||||
if self:IsIncludeObject( Object ) then
|
||||
self:E( { "Adding Object:", ObjectName } )
|
||||
self:Add( ObjectName, Object )
|
||||
end
|
||||
end
|
||||
@@ -409,9 +441,9 @@ do -- SET_BASE
|
||||
for ObjectID, ObjectData in pairs( self.Set ) do
|
||||
if NearestObject == nil then
|
||||
NearestObject = ObjectData
|
||||
ClosestDistance = PointVec2:DistanceFromVec2( ObjectData:GetVec2() )
|
||||
ClosestDistance = PointVec2:DistanceFromPointVec2( ObjectData:GetCoordinate() )
|
||||
else
|
||||
local Distance = PointVec2:DistanceFromVec2( ObjectData:GetVec2() )
|
||||
local Distance = PointVec2:DistanceFromPointVec2( ObjectData:GetCoordinate() )
|
||||
if Distance < ClosestDistance then
|
||||
NearestObject = ObjectData
|
||||
ClosestDistance = Distance
|
||||
@@ -525,6 +557,10 @@ do -- SET_BASE
|
||||
--- Iterate the SET_BASE and derived classes and call an iterator function for the given SET_BASE, providing the Object for each element within the set and optional parameters.
|
||||
-- @param #SET_BASE self
|
||||
-- @param #function IteratorFunction The function that will be called.
|
||||
-- @param #table arg Arguments of the IteratorFunction.
|
||||
-- @param #SET_BASE Set (Optional) The set to use. Default self:GetSet().
|
||||
-- @param #function Function (Optional) A function returning a #boolean true/false. Only if true, the IteratorFunction is called.
|
||||
-- @param #table FunctionArguments (Optional) Function arguments.
|
||||
-- @return #SET_BASE self
|
||||
function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArguments )
|
||||
self:F3( arg )
|
||||
@@ -532,6 +568,63 @@ do -- SET_BASE
|
||||
Set = Set or self:GetSet()
|
||||
arg = arg or {}
|
||||
|
||||
local function CoRoutine()
|
||||
local Count = 0
|
||||
for ObjectID, ObjectData in pairs( Set ) do
|
||||
local Object = ObjectData
|
||||
self:T3( Object )
|
||||
if Function then
|
||||
if Function( unpack( FunctionArguments or {} ), Object ) == true then
|
||||
IteratorFunction( Object, unpack( arg ) )
|
||||
end
|
||||
else
|
||||
IteratorFunction( Object, unpack( arg ) )
|
||||
end
|
||||
Count = Count + 1
|
||||
-- if Count % self.YieldInterval == 0 then
|
||||
-- coroutine.yield( false )
|
||||
-- end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- local co = coroutine.create( CoRoutine )
|
||||
local co = CoRoutine
|
||||
|
||||
local function Schedule()
|
||||
|
||||
-- local status, res = coroutine.resume( co )
|
||||
local status, res = co()
|
||||
self:T3( { status, res } )
|
||||
|
||||
if status == false then
|
||||
error( res )
|
||||
end
|
||||
if res == false then
|
||||
return true -- resume next time the loop
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--self.CallScheduler:Schedule( self, Schedule, {}, self.TimeInterval, self.TimeInterval, 0 )
|
||||
Schedule()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Iterate the SET_BASE and derived classes and call an iterator function for the given SET_BASE, providing the Object for each element within the set and optional parameters.
|
||||
-- @param #SET_BASE self
|
||||
-- @param #function IteratorFunction The function that will be called.
|
||||
-- @return #SET_BASE self
|
||||
function SET_BASE:ForSome( IteratorFunction, arg, Set, Function, FunctionArguments )
|
||||
self:F3( arg )
|
||||
|
||||
Set = Set or self:GetSet()
|
||||
arg = arg or {}
|
||||
|
||||
local Limit = self:GetSomeIteratorLimit()
|
||||
|
||||
local function CoRoutine()
|
||||
local Count = 0
|
||||
for ObjectID, ObjectData in pairs( Set ) do
|
||||
@@ -545,6 +638,9 @@ do -- SET_BASE
|
||||
IteratorFunction( Object, unpack( arg ) )
|
||||
end
|
||||
Count = Count + 1
|
||||
if Count >= Limit then
|
||||
break
|
||||
end
|
||||
-- if Count % self.YieldInterval == 0 then
|
||||
-- coroutine.yield( false )
|
||||
-- end
|
||||
@@ -831,7 +927,40 @@ do -- SET_GROUP
|
||||
|
||||
return AliveSet.Set or {}
|
||||
end
|
||||
|
||||
--- Returns a report of of unit types.
|
||||
-- @param #SET_GROUP self
|
||||
-- @return Core.Report#REPORT A report of the unit types found. The key is the UnitTypeName and the value is the amount of unit types found.
|
||||
function SET_GROUP:GetUnitTypeNames()
|
||||
self:F2()
|
||||
|
||||
local MT = {} -- Message Text
|
||||
local UnitTypes = {}
|
||||
|
||||
local ReportUnitTypes = REPORT:New()
|
||||
|
||||
for GroupID, GroupData in pairs( self:GetSet() ) do
|
||||
local Units = GroupData:GetUnits()
|
||||
for UnitID, UnitData in pairs( Units ) do
|
||||
if UnitData:IsAlive() then
|
||||
local UnitType = UnitData:GetTypeName()
|
||||
|
||||
if not UnitTypes[UnitType] then
|
||||
UnitTypes[UnitType] = 1
|
||||
else
|
||||
UnitTypes[UnitType] = UnitTypes[UnitType] + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for UnitTypeID, UnitType in pairs( UnitTypes ) do
|
||||
ReportUnitTypes:Add( UnitType .. " of " .. UnitTypeID )
|
||||
end
|
||||
|
||||
return ReportUnitTypes
|
||||
end
|
||||
|
||||
--- Add a GROUP to SET_GROUP.
|
||||
-- Note that for each unit in the group that is set, a default cargo bay limit is initialized.
|
||||
-- @param Core.Set#SET_GROUP self
|
||||
@@ -1130,7 +1259,7 @@ do -- SET_GROUP
|
||||
|
||||
--- Iterate the SET_GROUP and call an iterator function for each GROUP object, providing the GROUP and optional parameters.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive GROUP in the SET_GROUP. The function needs to accept a GROUP parameter.
|
||||
-- @param #function IteratorFunction The function that will be called for all GROUP in the SET_GROUP. The function needs to accept a GROUP parameter.
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP:ForEachGroup( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
@@ -1140,6 +1269,18 @@ do -- SET_GROUP
|
||||
return self
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and call an iterator function for some GROUP objects, providing the GROUP and optional parameters.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #function IteratorFunction The function that will be called for some GROUP in the SET_GROUP. The function needs to accept a GROUP parameter.
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP:ForSomeGroup( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
self:ForSome( IteratorFunction, arg, self:GetSet() )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP object, providing the GROUP and optional parameters.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive GROUP in the SET_GROUP. The function needs to accept a GROUP parameter.
|
||||
@@ -1152,6 +1293,18 @@ do -- SET_GROUP
|
||||
return self
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and call an iterator function for some **alive** GROUP objects, providing the GROUP and optional parameters.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive GROUP in the SET_GROUP. The function needs to accept a GROUP parameter.
|
||||
-- @return #SET_GROUP self
|
||||
function SET_GROUP:ForSomeGroupAlive( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
self:ForSome( IteratorFunction, arg, self:GetAliveSet() )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP presence completely in a @{Zone}, providing the GROUP and optional parameters to the called function.
|
||||
-- @param #SET_GROUP self
|
||||
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.
|
||||
@@ -1421,6 +1574,35 @@ do -- SET_GROUP
|
||||
return Count
|
||||
end
|
||||
|
||||
--- Iterate the SET_GROUP and count how many GROUPs and UNITs are alive.
|
||||
-- @param #SET_GROUP self
|
||||
-- @return #number The number of GROUPs completely in the Zone
|
||||
-- @return #number The number of UNITS alive.
|
||||
function SET_GROUP:CountAlive()
|
||||
local CountG = 0
|
||||
local CountU = 0
|
||||
|
||||
local Set = self:GetSet()
|
||||
|
||||
for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP
|
||||
if GroupData and GroupData:IsAlive() then
|
||||
|
||||
CountG = CountG + 1
|
||||
|
||||
--Count Units.
|
||||
for _,_unit in pairs(GroupData:GetUnits()) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
if unit and unit:IsAlive() then
|
||||
CountU=CountU+1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return CountG,CountU
|
||||
end
|
||||
|
||||
----- Iterate the SET_GROUP and call an interator function for each **alive** player, providing the Group of the player and optional parameters.
|
||||
---- @param #SET_GROUP self
|
||||
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_GROUP. The function needs to accept a GROUP parameter.
|
||||
@@ -2033,6 +2215,54 @@ do -- SET_UNIT
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Get the SET of the SET_UNIT **sorted per Threat Level**.
|
||||
--
|
||||
-- @param #SET_UNIT self
|
||||
-- @param #number FromThreatLevel The TreatLevel to start the evaluation **From** (this must be a value between 0 and 10).
|
||||
-- @param #number ToThreatLevel The TreatLevel to stop the evaluation **To** (this must be a value between 0 and 10).
|
||||
-- @return #SET_UNIT self
|
||||
-- @usage
|
||||
--
|
||||
--
|
||||
function SET_UNIT:GetSetPerThreatLevel( FromThreatLevel, ToThreatLevel )
|
||||
self:F2( arg )
|
||||
|
||||
local ThreatLevelSet = {}
|
||||
|
||||
if self:Count() ~= 0 then
|
||||
for UnitName, UnitObject in pairs( self.Set ) do
|
||||
local Unit = UnitObject -- Wrapper.Unit#UNIT
|
||||
|
||||
local ThreatLevel = Unit:GetThreatLevel()
|
||||
ThreatLevelSet[ThreatLevel] = ThreatLevelSet[ThreatLevel] or {}
|
||||
ThreatLevelSet[ThreatLevel].Set = ThreatLevelSet[ThreatLevel].Set or {}
|
||||
ThreatLevelSet[ThreatLevel].Set[UnitName] = UnitObject
|
||||
self:F( { ThreatLevel = ThreatLevel, ThreatLevelSet = ThreatLevelSet[ThreatLevel].Set } )
|
||||
end
|
||||
|
||||
|
||||
local OrderedPerThreatLevelSet = {}
|
||||
|
||||
local ThreatLevelIncrement = FromThreatLevel <= ToThreatLevel and 1 or -1
|
||||
|
||||
|
||||
for ThreatLevel = FromThreatLevel, ToThreatLevel, ThreatLevelIncrement do
|
||||
self:F( { ThreatLevel = ThreatLevel } )
|
||||
local ThreatLevelItem = ThreatLevelSet[ThreatLevel]
|
||||
if ThreatLevelItem then
|
||||
for UnitName, UnitObject in pairs( ThreatLevelItem.Set ) do
|
||||
table.insert( OrderedPerThreatLevelSet, UnitObject )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return OrderedPerThreatLevelSet
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Iterate the SET_UNIT **sorted *per Threat Level** and call an interator function for each **alive** UNIT, providing the UNIT and optional parameters.
|
||||
--
|
||||
-- @param #SET_UNIT self
|
||||
@@ -2393,6 +2623,23 @@ do -- SET_UNIT
|
||||
return GroundUnitCount
|
||||
end
|
||||
|
||||
--- Returns if the @{Set} has air targets.
|
||||
-- @param #SET_UNIT self
|
||||
-- @return #number The amount of air targets in the Set.
|
||||
function SET_UNIT:HasAirUnits()
|
||||
self:F2()
|
||||
|
||||
local AirUnitCount = 0
|
||||
for UnitID, UnitData in pairs( self:GetSet() ) do
|
||||
local UnitTest = UnitData -- Wrapper.Unit#UNIT
|
||||
if UnitTest:IsAir() then
|
||||
AirUnitCount = AirUnitCount + 1
|
||||
end
|
||||
end
|
||||
|
||||
return AirUnitCount
|
||||
end
|
||||
|
||||
--- Returns if the @{Set} has friendly ground units.
|
||||
-- @param #SET_UNIT self
|
||||
-- @return #number The amount of ground targets in the Set.
|
||||
@@ -5249,4 +5496,324 @@ do -- SET_ZONE
|
||||
return nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
do -- SET_ZONE_GOAL
|
||||
|
||||
--- @type SET_ZONE_GOAL
|
||||
-- @extends Core.Set#SET_BASE
|
||||
|
||||
--- Mission designers can use the @{Core.Set#SET_ZONE_GOAL} class to build sets of zones of various types.
|
||||
--
|
||||
-- ## SET_ZONE_GOAL constructor
|
||||
--
|
||||
-- Create a new SET_ZONE_GOAL object with the @{#SET_ZONE_GOAL.New} method:
|
||||
--
|
||||
-- * @{#SET_ZONE_GOAL.New}: Creates a new SET_ZONE_GOAL object.
|
||||
--
|
||||
-- ## Add or Remove ZONEs from SET_ZONE_GOAL
|
||||
--
|
||||
-- ZONEs can be added and removed using the @{Core.Set#SET_ZONE_GOAL.AddZonesByName} and @{Core.Set#SET_ZONE_GOAL.RemoveZonesByName} respectively.
|
||||
-- These methods take a single ZONE name or an array of ZONE names to be added or removed from SET_ZONE_GOAL.
|
||||
--
|
||||
-- ## SET_ZONE_GOAL filter criteria
|
||||
--
|
||||
-- You can set filter criteria to build the collection of zones in SET_ZONE_GOAL.
|
||||
-- Filter criteria are defined by:
|
||||
--
|
||||
-- * @{#SET_ZONE_GOAL.FilterPrefixes}: Builds the SET_ZONE_GOAL with the zones having a certain text pattern of prefix.
|
||||
--
|
||||
-- Once the filter criteria have been set for the SET_ZONE_GOAL, you can start filtering using:
|
||||
--
|
||||
-- * @{#SET_ZONE_GOAL.FilterStart}: Starts the filtering of the zones within the SET_ZONE_GOAL.
|
||||
--
|
||||
-- ## SET_ZONE_GOAL iterators
|
||||
--
|
||||
-- Once the filters have been defined and the SET_ZONE_GOAL has been built, you can iterate the SET_ZONE_GOAL with the available iterator methods.
|
||||
-- The iterator methods will walk the SET_ZONE_GOAL set, and call for each airbase within the set a function that you provide.
|
||||
-- The following iterator methods are currently available within the SET_ZONE_GOAL:
|
||||
--
|
||||
-- * @{#SET_ZONE_GOAL.ForEachZone}: Calls a function for each zone it finds within the SET_ZONE_GOAL.
|
||||
--
|
||||
-- ===
|
||||
-- @field #SET_ZONE_GOAL SET_ZONE_GOAL
|
||||
SET_ZONE_GOAL = {
|
||||
ClassName = "SET_ZONE_GOAL",
|
||||
Zones = {},
|
||||
Filter = {
|
||||
Prefixes = nil,
|
||||
},
|
||||
FilterMeta = {
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
--- Creates a new SET_ZONE_GOAL object, building a set of zones.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @return #SET_ZONE_GOAL self
|
||||
-- @usage
|
||||
-- -- Define a new SET_ZONE_GOAL Object. The DatabaseSet will contain a reference to all Zones.
|
||||
-- DatabaseSet = SET_ZONE_GOAL:New()
|
||||
function SET_ZONE_GOAL:New()
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, SET_BASE:New( _DATABASE.ZONES_GOAL ) )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add ZONEs to SET_ZONE_GOAL.
|
||||
-- @param Core.Set#SET_ZONE_GOAL self
|
||||
-- @param Core.Zone#ZONE_BASE Zone A ZONE_BASE object.
|
||||
-- @return self
|
||||
function SET_ZONE_GOAL:AddZone( Zone )
|
||||
|
||||
self:Add( Zone:GetName(), Zone )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Remove ZONEs from SET_ZONE_GOAL.
|
||||
-- @param Core.Set#SET_ZONE_GOAL self
|
||||
-- @param Core.Zone#ZONE_BASE RemoveZoneNames A single name or an array of ZONE_BASE names.
|
||||
-- @return self
|
||||
function SET_ZONE_GOAL:RemoveZonesByName( RemoveZoneNames )
|
||||
|
||||
local RemoveZoneNamesArray = ( type( RemoveZoneNames ) == "table" ) and RemoveZoneNames or { RemoveZoneNames }
|
||||
|
||||
for RemoveZoneID, RemoveZoneName in pairs( RemoveZoneNamesArray ) do
|
||||
self:Remove( RemoveZoneName )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Finds a Zone based on the Zone Name.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param #string ZoneName
|
||||
-- @return Core.Zone#ZONE_BASE The found Zone.
|
||||
function SET_ZONE_GOAL:FindZone( ZoneName )
|
||||
|
||||
local ZoneFound = self.Set[ZoneName]
|
||||
return ZoneFound
|
||||
end
|
||||
|
||||
|
||||
--- Get a random zone from the set.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @return Core.Zone#ZONE_BASE The random Zone.
|
||||
-- @return #nil if no zone in the collection.
|
||||
function SET_ZONE_GOAL:GetRandomZone()
|
||||
|
||||
if self:Count() ~= 0 then
|
||||
|
||||
local Index = self.Index
|
||||
local ZoneFound = nil -- Core.Zone#ZONE_BASE
|
||||
|
||||
-- Loop until a zone has been found.
|
||||
-- The :GetZoneMaybe() call will evaluate the probability for the zone to be selected.
|
||||
-- If the zone is not selected, then nil is returned by :GetZoneMaybe() and the loop continues!
|
||||
while not ZoneFound do
|
||||
local ZoneRandom = math.random( 1, #Index )
|
||||
ZoneFound = self.Set[Index[ZoneRandom]]:GetZoneMaybe()
|
||||
end
|
||||
|
||||
return ZoneFound
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
--- Set a zone probability.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param #string ZoneName The name of the zone.
|
||||
function SET_ZONE_GOAL:SetZoneProbability( ZoneName, ZoneProbability )
|
||||
local Zone = self:FindZone( ZoneName )
|
||||
Zone:SetZoneProbability( ZoneProbability )
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Builds a set of zones of defined zone prefixes.
|
||||
-- All the zones starting with the given prefixes will be included within the set.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param #string Prefixes The prefix of which the zone name starts with.
|
||||
-- @return #SET_ZONE_GOAL self
|
||||
function SET_ZONE_GOAL:FilterPrefixes( Prefixes )
|
||||
if not self.Filter.Prefixes then
|
||||
self.Filter.Prefixes = {}
|
||||
end
|
||||
if type( Prefixes ) ~= "table" then
|
||||
Prefixes = { Prefixes }
|
||||
end
|
||||
for PrefixID, Prefix in pairs( Prefixes ) do
|
||||
self.Filter.Prefixes[Prefix] = Prefix
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Starts the filtering.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @return #SET_ZONE_GOAL self
|
||||
function SET_ZONE_GOAL:FilterStart()
|
||||
|
||||
if _DATABASE then
|
||||
|
||||
-- We initialize the first set.
|
||||
for ObjectName, Object in pairs( self.Database ) do
|
||||
if self:IsIncludeObject( Object ) then
|
||||
self:Add( ObjectName, Object )
|
||||
else
|
||||
self:RemoveZonesByName( ObjectName )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self:HandleEvent( EVENTS.NewZoneGoal )
|
||||
self:HandleEvent( EVENTS.DeleteZoneGoal )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Stops the filtering for the defined collection.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @return #SET_ZONE_GOAL self
|
||||
function SET_ZONE_GOAL:FilterStop()
|
||||
|
||||
self:UnHandleEvent( EVENTS.NewZoneGoal )
|
||||
self:UnHandleEvent( EVENTS.DeleteZoneGoal )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Handles the Database to check on an event (birth) that the Object was added in the Database.
|
||||
-- This is required, because sometimes the _DATABASE birth event gets called later than the SET_BASE birth event!
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param Core.Event#EVENTDATA Event
|
||||
-- @return #string The name of the AIRBASE
|
||||
-- @return #table The AIRBASE
|
||||
function SET_ZONE_GOAL:AddInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
|
||||
end
|
||||
|
||||
--- Handles the Database to check on any event that Object exists in the Database.
|
||||
-- This is required, because sometimes the _DATABASE event gets called later than the SET_BASE event or vise versa!
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param Core.Event#EVENTDATA Event
|
||||
-- @return #string The name of the AIRBASE
|
||||
-- @return #table The AIRBASE
|
||||
function SET_ZONE_GOAL:FindInDatabase( Event )
|
||||
self:F3( { Event } )
|
||||
|
||||
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
|
||||
end
|
||||
|
||||
--- Iterate the SET_ZONE_GOAL and call an interator function for each ZONE, providing the ZONE and optional parameters.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param #function IteratorFunction The function that will be called when there is an alive ZONE in the SET_ZONE_GOAL. The function needs to accept a AIRBASE parameter.
|
||||
-- @return #SET_ZONE_GOAL self
|
||||
function SET_ZONE_GOAL:ForEachZone( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
self:ForEach( IteratorFunction, arg, self:GetSet() )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param Core.Zone#ZONE_BASE MZone
|
||||
-- @return #SET_ZONE_GOAL self
|
||||
function SET_ZONE_GOAL:IsIncludeObject( MZone )
|
||||
self:F2( MZone )
|
||||
|
||||
local MZoneInclude = true
|
||||
|
||||
if MZone then
|
||||
local MZoneName = MZone:GetName()
|
||||
|
||||
if self.Filter.Prefixes then
|
||||
local MZonePrefix = false
|
||||
for ZonePrefixId, ZonePrefix in pairs( self.Filter.Prefixes ) do
|
||||
self:T3( { "Prefix:", string.find( MZoneName, ZonePrefix, 1 ), ZonePrefix } )
|
||||
if string.find( MZoneName, ZonePrefix, 1 ) then
|
||||
MZonePrefix = true
|
||||
end
|
||||
end
|
||||
self:T( { "Evaluated Prefix", MZonePrefix } )
|
||||
MZoneInclude = MZoneInclude and MZonePrefix
|
||||
end
|
||||
end
|
||||
|
||||
self:T2( MZoneInclude )
|
||||
return MZoneInclude
|
||||
end
|
||||
|
||||
--- Handles the OnEventNewZone event for the Set.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function SET_ZONE_GOAL:OnEventNewZoneGoal( EventData )
|
||||
|
||||
self:I( { "New Zone Capture Coalition", EventData } )
|
||||
self:I( { "Zone Capture Coalition", EventData.ZoneGoal } )
|
||||
|
||||
if EventData.ZoneGoal then
|
||||
if EventData.ZoneGoal and self:IsIncludeObject( EventData.ZoneGoal ) then
|
||||
self:I( { "Adding Zone Capture Coalition", EventData.ZoneGoal.ZoneName, EventData.ZoneGoal } )
|
||||
self:Add( EventData.ZoneGoal.ZoneName , EventData.ZoneGoal )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Handles the OnDead or OnCrash event for alive units set.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function SET_ZONE_GOAL:OnEventDeleteZoneGoal( EventData ) --R2.1
|
||||
self:F3( { EventData } )
|
||||
|
||||
if EventData.ZoneGoal then
|
||||
local Zone = _DATABASE:FindZone( EventData.ZoneGoal.ZoneName )
|
||||
if Zone and Zone.ZoneName then
|
||||
|
||||
-- When cargo was deleted, it may probably be because of an S_EVENT_DEAD.
|
||||
-- However, in the loading logic, an S_EVENT_DEAD is also generated after a Destroy() call.
|
||||
-- And this is a problem because it will remove all entries from the SET_ZONE_GOALs.
|
||||
-- To prevent this from happening, the Zone object has a flag NoDestroy.
|
||||
-- When true, the SET_ZONE_GOAL won't Remove the Zone object from the set.
|
||||
-- This flag is switched off after the event handlers have been called in the EVENT class.
|
||||
self:F( { ZoneNoDestroy=Zone.NoDestroy } )
|
||||
if Zone.NoDestroy then
|
||||
else
|
||||
self:Remove( Zone.ZoneName )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Validate if a coordinate is in one of the zones in the set.
|
||||
-- Returns the ZONE object where the coordiante is located.
|
||||
-- If zones overlap, the first zone that validates the test is returned.
|
||||
-- @param #SET_ZONE_GOAL self
|
||||
-- @param Core.Point#COORDINATE Coordinate The coordinate to be searched.
|
||||
-- @return Core.Zone#ZONE_BASE The zone that validates the coordinate location.
|
||||
-- @return #nil No zone has been found.
|
||||
function SET_ZONE_GOAL:IsCoordinateInZone( Coordinate )
|
||||
|
||||
for _, Zone in pairs( self:GetSet() ) do
|
||||
local Zone = Zone -- Core.Zone#ZONE_BASE
|
||||
if Zone:IsCoordinateInZone( Coordinate ) then
|
||||
return Zone
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -193,7 +193,20 @@
|
||||
--
|
||||
-- - @{#SETTINGS.SetMessageTime}(): Define for a specific @{Message.MESSAGE.MessageType} the duration to be displayed in seconds.
|
||||
-- - @{#SETTINGS.GetMessageTime}(): Retrieves for a specific @{Message.MESSAGE.MessageType} the duration to be displayed in seconds.
|
||||
--
|
||||
--
|
||||
-- ## 3.5) **Era** of the battle
|
||||
--
|
||||
-- The threat level metric is scaled according the era of the battle. A target that is AAA, will pose a much greather threat in WWII than on modern warfare.
|
||||
-- Therefore, there are 4 era that are defined within the settings:
|
||||
--
|
||||
-- - **WWII** era: Use for warfare with equipment during the world war II time.
|
||||
-- - **Korea** era: Use for warfare with equipment during the Korea war time.
|
||||
-- - **Cold War** era: Use for warfare with equipment during the cold war time.
|
||||
-- - **Modern** era: Use for warfare with modern equipment in the 2000s.
|
||||
--
|
||||
-- There are different API defined that you can use with the _SETTINGS object to configure your mission script to work in one of the 4 era:
|
||||
-- @{#SETTINGS.SetEraWWII}(), @{#SETTINGS.SetEraKorea}(), @{#SETTINGS.SetEraCold}(), @{#SETTINGS.SetEraModern}()
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @field #SETTINGS
|
||||
@@ -202,6 +215,19 @@ SETTINGS = {
|
||||
ShowPlayerMenu = true,
|
||||
}
|
||||
|
||||
SETTINGS.__Enum = {}
|
||||
|
||||
--- @type SETTINGS.__Enum.Era
|
||||
-- @field #number WWII
|
||||
-- @field #number Korea
|
||||
-- @field #number Cold
|
||||
-- @field #number Modern
|
||||
SETTINGS.__Enum.Era = {
|
||||
WWII = 1,
|
||||
Korea = 2,
|
||||
Cold = 3,
|
||||
Modern = 4,
|
||||
}
|
||||
|
||||
|
||||
do -- SETTINGS
|
||||
@@ -223,6 +249,7 @@ do -- SETTINGS
|
||||
self:SetMessageTime( MESSAGE.Type.Information, 30 )
|
||||
self:SetMessageTime( MESSAGE.Type.Overview, 60 )
|
||||
self:SetMessageTime( MESSAGE.Type.Update, 15 )
|
||||
self:SetEraModern()
|
||||
return self
|
||||
else
|
||||
local Settings = _DATABASE:GetPlayerSettings( PlayerName )
|
||||
@@ -838,6 +865,47 @@ do -- SETTINGS
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Configures the era of the mission to be WWII.
|
||||
-- @param #SETTINGS self
|
||||
-- @return #SETTINGS self
|
||||
function SETTINGS:SetEraWWII()
|
||||
|
||||
self.Era = SETTINGS.__Enum.Era.WWII
|
||||
|
||||
end
|
||||
|
||||
--- Configures the era of the mission to be Korea.
|
||||
-- @param #SETTINGS self
|
||||
-- @return #SETTINGS self
|
||||
function SETTINGS:SetEraKorea()
|
||||
|
||||
self.Era = SETTINGS.__Enum.Era.Korea
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Configures the era of the mission to be Cold war.
|
||||
-- @param #SETTINGS self
|
||||
-- @return #SETTINGS self
|
||||
function SETTINGS:SetEraCold()
|
||||
|
||||
self.Era = SETTINGS.__Enum.Era.Cold
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Configures the era of the mission to be Modern war.
|
||||
-- @param #SETTINGS self
|
||||
-- @return #SETTINGS self
|
||||
function SETTINGS:SetEraModern()
|
||||
|
||||
self.Era = SETTINGS.__Enum.Era.Modern
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
-- * Schedule spawning of new groups.
|
||||
-- * Put limits on the amount of groups that can be spawned, and the amount of units that can be alive at the same time.
|
||||
-- * Randomize the spawning location between different zones.
|
||||
-- * Randomize the intial positions within the zones.
|
||||
-- * Randomize the initial positions within the zones.
|
||||
-- * Spawn in array formation.
|
||||
-- * Spawn uncontrolled (for planes or helos only).
|
||||
-- * Clean up inactive helicopters that "crashed".
|
||||
@@ -319,9 +319,13 @@ function SPAWN:New( SpawnTemplatePrefix )
|
||||
self.SpawnUnControlled = false
|
||||
self.SpawnInitKeepUnitNames = false -- Overwrite unit names by default with group name.
|
||||
self.DelayOnOff = false -- No intial delay when spawning the first group.
|
||||
self.Grouping = nil -- No grouping.
|
||||
self.SpawnGrouping = nil -- No grouping.
|
||||
self.SpawnInitLivery = nil -- No special livery.
|
||||
self.SpawnInitSkill = nil -- No special skill.
|
||||
self.SpawnInitFreq = nil -- No special frequency.
|
||||
self.SpawnInitModu = nil -- No special modulation.
|
||||
self.SpawnInitRadio = nil -- No radio comms setting.
|
||||
self.SpawnInitModex = nil
|
||||
|
||||
self.SpawnGroups = {} -- Array containing the descriptions of each Group to be Spawned.
|
||||
else
|
||||
@@ -367,10 +371,14 @@ function SPAWN:NewWithAlias( SpawnTemplatePrefix, SpawnAliasPrefix )
|
||||
self.SpawnUnControlled = false
|
||||
self.SpawnInitKeepUnitNames = false -- Overwrite unit names by default with group name.
|
||||
self.DelayOnOff = false -- No intial delay when spawning the first group.
|
||||
self.Grouping = nil -- No grouping.
|
||||
self.SpawnGrouping = nil -- No grouping.
|
||||
self.SpawnInitLivery = nil -- No special livery.
|
||||
self.SpawnInitSkill = nil -- No special skill.
|
||||
|
||||
self.SpawnInitFreq = nil -- No special frequency.
|
||||
self.SpawnInitModu = nil -- No special modulation.
|
||||
self.SpawnInitRadio = nil -- No radio comms setting.
|
||||
self.SpawnInitModex = nil
|
||||
|
||||
self.SpawnGroups = {} -- Array containing the descriptions of each Group to be Spawned.
|
||||
else
|
||||
error( "SPAWN:New: There is no group declared in the mission editor with SpawnTemplatePrefix = '" .. SpawnTemplatePrefix .. "'" )
|
||||
@@ -421,7 +429,11 @@ function SPAWN:NewFromTemplate( SpawnTemplate, SpawnTemplatePrefix, SpawnAliasPr
|
||||
self.Grouping = nil -- No grouping.
|
||||
self.SpawnInitLivery = nil -- No special livery.
|
||||
self.SpawnInitSkill = nil -- No special skill.
|
||||
|
||||
self.SpawnInitFreq = nil -- No special frequency.
|
||||
self.SpawnInitModu = nil -- No special modulation.
|
||||
self.SpawnInitRadio = nil -- No radio comms setting.
|
||||
self.SpawnInitModex = nil
|
||||
|
||||
self.SpawnGroups = {} -- Array containing the descriptions of each Group to be Spawned.
|
||||
else
|
||||
error( "There is no template provided for SpawnTemplatePrefix = '" .. SpawnTemplatePrefix .. "'" )
|
||||
@@ -537,7 +549,7 @@ end
|
||||
|
||||
--- Sets the country of the spawn group. Note that the country determins the coalition of the group depending on which country is defined to be on which side for each specific mission!
|
||||
-- @param #SPAWN self
|
||||
-- @param #DCS.country Country Country id as number or enumerator:
|
||||
-- @param #number Country Country id as number or enumerator:
|
||||
--
|
||||
-- * @{DCS#country.id.RUSSIA}
|
||||
-- * @{DCS#county.id.USA}
|
||||
@@ -597,6 +609,55 @@ function SPAWN:InitSkill( Skill )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets the radio comms on or off. Same as checking/unchecking the COMM box in the mission editor.
|
||||
-- @param #SPAWN self
|
||||
-- @param #number switch If true (or nil), enables the radio comms. If false, disables the radio for the spawned group.
|
||||
-- @return #SPAWN self
|
||||
function SPAWN:InitRadioCommsOnOff(switch)
|
||||
self:F({switch=switch} )
|
||||
self.SpawnInitRadio=switch or true
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets the radio frequency of the group.
|
||||
-- @param #SPAWN self
|
||||
-- @param #number frequency The frequency in MHz.
|
||||
-- @return #SPAWN self
|
||||
function SPAWN:InitRadioFrequency(frequency)
|
||||
self:F({frequency=frequency} )
|
||||
|
||||
self.SpawnInitFreq=frequency
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set radio modulation. Default is AM.
|
||||
-- @param #SPAWN self
|
||||
-- @param #string modulation Either "FM" or "AM". If no value is given, modulation is set to AM.
|
||||
-- @return #SPAWN self
|
||||
function SPAWN:InitRadioModulation(modulation)
|
||||
self:F({modulation=modulation})
|
||||
if modulation and modulation:lower()=="fm" then
|
||||
self.SpawnInitModu=radio.modulation.FM
|
||||
else
|
||||
self.SpawnInitModu=radio.modulation.AM
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets the modex of the first unit of the group. If more units are in the group, the number is increased by one with every unit.
|
||||
-- @param #SPAWN self
|
||||
-- @param #number modex Modex of the first unit.
|
||||
-- @return #SPAWN self
|
||||
function SPAWN:InitModex(modex)
|
||||
|
||||
if modex then
|
||||
self.SpawnInitModex=tonumber(modex)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Randomizes the defined route of the SpawnTemplatePrefix group in the ME. This is very useful to define extra variation of the behaviour of groups.
|
||||
-- @param #SPAWN self
|
||||
@@ -1095,12 +1156,24 @@ function SPAWN:ReSpawn( SpawnIndex )
|
||||
return SpawnGroup
|
||||
end
|
||||
|
||||
|
||||
--- Set the spawn index to a specified index number.
|
||||
-- This method can be used to "reset" the spawn counter to a specific index number.
|
||||
-- This will actually enable a respawn of groups from the specific index.
|
||||
-- @param #SPAWN self
|
||||
-- @param #string SpawnIndex The index of the group from where the spawning will start again. The default value would be 0, which means a complete reset of the spawnindex.
|
||||
-- @return #SPAWN self
|
||||
function SPAWN:SetSpawnIndex( SpawnIndex )
|
||||
self.SpawnIndex = SpawnIndex or 0
|
||||
end
|
||||
|
||||
|
||||
--- Will spawn a group with a specified index number.
|
||||
-- Uses @{DATABASE} global object defined in MOOSE.
|
||||
-- @param #SPAWN self
|
||||
-- @param #string SpawnIndex The index of the group to be spawned.
|
||||
-- @return Wrapper.Group#GROUP The group that was spawned. You can use this group for further actions.
|
||||
function SPAWN:SpawnWithIndex( SpawnIndex )
|
||||
function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth )
|
||||
self:F2( { SpawnTemplatePrefix = self.SpawnTemplatePrefix, SpawnIndex = SpawnIndex, AliveUnits = self.AliveUnits, SpawnMaxGroups = self.SpawnMaxGroups } )
|
||||
|
||||
if self:_GetSpawnIndex( SpawnIndex ) then
|
||||
@@ -1173,6 +1246,28 @@ function SPAWN:SpawnWithIndex( SpawnIndex )
|
||||
SpawnTemplate.units[UnitID].skill = self.SpawnInitSkill
|
||||
end
|
||||
end
|
||||
|
||||
-- Set tail number.
|
||||
if self.SpawnInitModex then
|
||||
for UnitID = 1, #SpawnTemplate.units do
|
||||
SpawnTemplate.units[UnitID].onboard_num = string.format("%03d", self.SpawnInitModex+(UnitID-1))
|
||||
end
|
||||
end
|
||||
|
||||
-- Set radio comms on/off.
|
||||
if self.SpawnInitRadio then
|
||||
SpawnTemplate.communication=self.SpawnInitRadio
|
||||
end
|
||||
|
||||
-- Set radio frequency.
|
||||
if self.SpawnInitFreq then
|
||||
SpawnTemplate.frequency=self.SpawnInitFreq
|
||||
end
|
||||
|
||||
-- Set radio modulation.
|
||||
if self.SpawnInitModu then
|
||||
SpawnTemplate.modulation=self.SpawnInitModu
|
||||
end
|
||||
|
||||
-- Set country, coaliton and categroy.
|
||||
SpawnTemplate.CategoryID = self.SpawnInitCategory or SpawnTemplate.CategoryID
|
||||
@@ -1180,14 +1275,16 @@ function SPAWN:SpawnWithIndex( SpawnIndex )
|
||||
SpawnTemplate.CoalitionID = self.SpawnInitCoalition or SpawnTemplate.CoalitionID
|
||||
|
||||
|
||||
if SpawnTemplate.CategoryID == Group.Category.HELICOPTER or SpawnTemplate.CategoryID == Group.Category.AIRPLANE then
|
||||
if SpawnTemplate.route.points[1].type == "TakeOffParking" then
|
||||
SpawnTemplate.uncontrolled = self.SpawnUnControlled
|
||||
end
|
||||
end
|
||||
-- if SpawnTemplate.CategoryID == Group.Category.HELICOPTER or SpawnTemplate.CategoryID == Group.Category.AIRPLANE then
|
||||
-- if SpawnTemplate.route.points[1].type == "TakeOffParking" then
|
||||
-- SpawnTemplate.uncontrolled = self.SpawnUnControlled
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
self:HandleEvent( EVENTS.Birth, self._OnBirth )
|
||||
if not NoBirth then
|
||||
self:HandleEvent( EVENTS.Birth, self._OnBirth )
|
||||
end
|
||||
self:HandleEvent( EVENTS.Dead, self._OnDeadOrCrash )
|
||||
self:HandleEvent( EVENTS.Crash, self._OnDeadOrCrash )
|
||||
self:HandleEvent( EVENTS.RemoveUnit, self._OnDeadOrCrash )
|
||||
@@ -1341,7 +1438,7 @@ end
|
||||
-- @param Wrapper.Airbase#AIRBASE.TerminalType TerminalType (optional) The terminal type the aircraft should be spawned at. See @{Wrapper.Airbase#AIRBASE.TerminalType}.
|
||||
-- @param #boolean EmergencyAirSpawn (optional) If true (default), groups are spawned in air if there is no parking spot at the airbase. If false, nothing is spawned if no parking spot is available.
|
||||
-- @param #table Parkingdata (optional) Table holding the coordinates and terminal ids for all units of the group. Spawning will be forced to happen at exactily these spots!
|
||||
-- @return Wrapper.Group#GROUP that was spawned or nil when nothing was spawned.
|
||||
-- @return Wrapper.Group#GROUP The group that was spawned or nil when nothing was spawned.
|
||||
-- @usage
|
||||
-- Spawn_Plane = SPAWN:New( "Plane" )
|
||||
-- Spawn_Plane:SpawnAtAirbase( AIRBASE:FindByName( AIRBASE.Caucasus.Krymsk ), SPAWN.Takeoff.Cold )
|
||||
@@ -1376,12 +1473,23 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
|
||||
EmergencyAirSpawn=true
|
||||
end
|
||||
|
||||
self:F( { SpawnIndex = self.SpawnIndex } )
|
||||
|
||||
if self:_GetSpawnIndex( self.SpawnIndex + 1 ) then
|
||||
|
||||
-- Get group template.
|
||||
local SpawnTemplate = self.SpawnGroups[self.SpawnIndex].SpawnTemplate
|
||||
|
||||
self:F( { SpawnTemplate = SpawnTemplate } )
|
||||
|
||||
if SpawnTemplate then
|
||||
|
||||
-- Check if the aircraft with the specified SpawnIndex is already spawned.
|
||||
-- If yes, ensure that the aircraft is spawned at the same aircraft spot.
|
||||
|
||||
local GroupAlive = self:GetGroupFromIndex( self.SpawnIndex )
|
||||
|
||||
self:F( { GroupAlive = GroupAlive } )
|
||||
|
||||
-- Debug output
|
||||
self:T( { "Current point of ", self.SpawnTemplatePrefix, SpawnAirbase } )
|
||||
@@ -1389,10 +1497,15 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
|
||||
-- Template group, unit and its attributes.
|
||||
local TemplateGroup = GROUP:FindByName(self.SpawnTemplatePrefix)
|
||||
local TemplateUnit=TemplateGroup:GetUnit(1)
|
||||
|
||||
-- General category of spawned group.
|
||||
local group=TemplateGroup
|
||||
local istransport=group:HasAttribute("Transports") and group:HasAttribute("Planes")
|
||||
local isawacs=group:HasAttribute("AWACS")
|
||||
local isfighter=group:HasAttribute("Fighters") or group:HasAttribute("Interceptors") or group:HasAttribute("Multirole fighters") or (group:HasAttribute("Bombers") and not group:HasAttribute("Strategic bombers"))
|
||||
local isbomber=group:HasAttribute("Strategic bombers")
|
||||
local istanker=group:HasAttribute("Tankers")
|
||||
local ishelo=TemplateUnit:HasAttribute("Helicopters")
|
||||
local isbomber=TemplateUnit:HasAttribute("Bombers")
|
||||
local istransport=TemplateUnit:HasAttribute("Transports")
|
||||
local isfighter=TemplateUnit:HasAttribute("Battleplanes")
|
||||
|
||||
-- Number of units in the group. With grouping this can actually differ from the template group size!
|
||||
local nunits=#SpawnTemplate.units
|
||||
@@ -1452,15 +1565,25 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
|
||||
local spots
|
||||
|
||||
-- Spawn happens on ground, i.e. at an airbase, a FARP or a ship.
|
||||
if spawnonground then
|
||||
if spawnonground and not SpawnTemplate.parked then
|
||||
|
||||
|
||||
-- Number of free parking spots.
|
||||
local nfree=0
|
||||
|
||||
-- Set terminal type.
|
||||
local termtype=TerminalType
|
||||
if spawnonrunway then
|
||||
termtype=AIRBASE.TerminalType.Runway
|
||||
if spawnonrunway then
|
||||
if spawnonship then
|
||||
-- Looks like there are no runway spawn spots on the stennis!
|
||||
if ishelo then
|
||||
termtype=AIRBASE.TerminalType.HelicopterUsable
|
||||
else
|
||||
termtype=AIRBASE.TerminalType.OpenMedOrBig
|
||||
end
|
||||
else
|
||||
termtype=AIRBASE.TerminalType.Runway
|
||||
end
|
||||
end
|
||||
|
||||
-- Scan options. Might make that input somehow.
|
||||
@@ -1502,10 +1625,7 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
|
||||
else
|
||||
-- Fixed wing aircraft is spawned.
|
||||
if termtype==nil then
|
||||
--TODO: Add some default cases for transport, bombers etc. if no explicit terminal type is provided.
|
||||
--TODO: We don't want Bombers to spawn in shelters. But I don't know a good attribute for just fighers.
|
||||
--TODO: Some attributes are "Helicopters", "Bombers", "Transports", "Battleplanes". Need to check it out.
|
||||
if isbomber or istransport then
|
||||
if isbomber or istransport or istanker or isawacs then
|
||||
-- First we fill the potentially bigger spots.
|
||||
self:T(string.format("Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenBig))
|
||||
spots=SpawnAirbase:FindFreeParkingSpotForAircraft(TemplateGroup, AIRBASE.TerminalType.OpenBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits)
|
||||
@@ -1532,9 +1652,9 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
|
||||
|
||||
-- Get parking data.
|
||||
local parkingdata=SpawnAirbase:GetParkingSpotsTable(termtype)
|
||||
self:T2(string.format("Parking at %s, terminal type %s:", SpawnAirbase:GetName(), tostring(termtype)))
|
||||
self:T(string.format("Parking at %s, terminal type %s:", SpawnAirbase:GetName(), tostring(termtype)))
|
||||
for _,_spot in pairs(parkingdata) do
|
||||
self:T2(string.format("%s, Termin Index = %3d, Term Type = %03d, Free = %5s, TOAC = %5s, Term ID0 = %3d, Dist2Rwy = %4d",
|
||||
self:T(string.format("%s, Termin Index = %3d, Term Type = %03d, Free = %5s, TOAC = %5s, Term ID0 = %3d, Dist2Rwy = %4d",
|
||||
SpawnAirbase:GetName(), _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy))
|
||||
end
|
||||
self:T(string.format("%s at %s: free parking spots = %d - number of units = %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), nfree, nunits))
|
||||
@@ -1625,9 +1745,407 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
|
||||
|
||||
end
|
||||
|
||||
if not SpawnTemplate.parked then
|
||||
-- Translate the position of the Group Template to the Vec3.
|
||||
|
||||
SpawnTemplate.parked = true
|
||||
|
||||
for UnitID = 1, nunits do
|
||||
self:T2('Before Translation SpawnTemplate.units['..UnitID..'].x = '..SpawnTemplate.units[UnitID].x..', SpawnTemplate.units['..UnitID..'].y = '..SpawnTemplate.units[UnitID].y)
|
||||
|
||||
-- Template of the current unit.
|
||||
local UnitTemplate = SpawnTemplate.units[UnitID]
|
||||
|
||||
-- Tranlate position and preserve the relative position/formation of all aircraft.
|
||||
local SX = UnitTemplate.x
|
||||
local SY = UnitTemplate.y
|
||||
local BX = SpawnTemplate.route.points[1].x
|
||||
local BY = SpawnTemplate.route.points[1].y
|
||||
local TX = PointVec3.x + (SX-BX)
|
||||
local TY = PointVec3.z + (SY-BY)
|
||||
|
||||
if spawnonground then
|
||||
|
||||
-- Ships and FARPS seem to have a build in queue.
|
||||
if spawnonship or spawnonfarp or spawnonrunway then
|
||||
|
||||
self:T(string.format("Group %s spawning at farp, ship or runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName()))
|
||||
|
||||
-- Spawn on ship. We take only the position of the ship.
|
||||
SpawnTemplate.units[UnitID].x = PointVec3.x --TX
|
||||
SpawnTemplate.units[UnitID].y = PointVec3.z --TY
|
||||
SpawnTemplate.units[UnitID].alt = PointVec3.y
|
||||
|
||||
else
|
||||
|
||||
self:T(string.format("Group %s spawning at airbase %s on parking spot id %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), parkingindex[UnitID]))
|
||||
|
||||
-- Get coordinates of parking spot.
|
||||
SpawnTemplate.units[UnitID].x = parkingspots[UnitID].x
|
||||
SpawnTemplate.units[UnitID].y = parkingspots[UnitID].z
|
||||
SpawnTemplate.units[UnitID].alt = parkingspots[UnitID].y
|
||||
|
||||
--parkingspots[UnitID]:MarkToAll(string.format("Group %s spawning at airbase %s on parking spot id %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), parkingindex[UnitID]))
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
self:T(string.format("Group %s spawning in air at %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName()))
|
||||
|
||||
-- Spawn in air as requested initially. Original template orientation is perserved, altitude is already correctly set.
|
||||
SpawnTemplate.units[UnitID].x = TX
|
||||
SpawnTemplate.units[UnitID].y = TY
|
||||
SpawnTemplate.units[UnitID].alt = PointVec3.y
|
||||
|
||||
end
|
||||
|
||||
-- Parking spot id.
|
||||
UnitTemplate.parking = nil
|
||||
UnitTemplate.parking_id = nil
|
||||
if parkingindex[UnitID] then
|
||||
UnitTemplate.parking = parkingindex[UnitID]
|
||||
end
|
||||
|
||||
-- Debug output.
|
||||
self:T(string.format("Group %s unit number %d: Parking = %s",self.SpawnTemplatePrefix, UnitID, tostring(UnitTemplate.parking)))
|
||||
self:T(string.format("Group %s unit number %d: Parking ID = %s",self.SpawnTemplatePrefix, UnitID, tostring(UnitTemplate.parking_id)))
|
||||
self:T2('After Translation SpawnTemplate.units['..UnitID..'].x = '..SpawnTemplate.units[UnitID].x..', SpawnTemplate.units['..UnitID..'].y = '..SpawnTemplate.units[UnitID].y)
|
||||
end
|
||||
end
|
||||
|
||||
-- Set gereral spawnpoint position.
|
||||
SpawnPoint.x = PointVec3.x
|
||||
SpawnPoint.y = PointVec3.z
|
||||
SpawnPoint.alt = PointVec3.y
|
||||
|
||||
SpawnTemplate.x = PointVec3.x
|
||||
SpawnTemplate.y = PointVec3.z
|
||||
|
||||
SpawnTemplate.uncontrolled = self.SpawnUnControlled
|
||||
|
||||
-- Spawn group.
|
||||
local GroupSpawned = self:SpawnWithIndex( self.SpawnIndex )
|
||||
|
||||
-- When spawned in the air, we need to generate a Takeoff Event.
|
||||
if Takeoff == GROUP.Takeoff.Air then
|
||||
for UnitID, UnitSpawned in pairs( GroupSpawned:GetUnits() ) do
|
||||
SCHEDULER:New( nil, BASE.CreateEventTakeoff, { GroupSpawned, timer.getTime(), UnitSpawned:GetDCSObject() } , 5 )
|
||||
end
|
||||
end
|
||||
|
||||
-- Check if we accidentally spawned on the runway. Needs to be schedules, because group is not immidiately alive.
|
||||
if Takeoff~=SPAWN.Takeoff.Runway and Takeoff~=SPAWN.Takeoff.Air and spawnonairport then
|
||||
SCHEDULER:New(nil, AIRBASE.CheckOnRunWay, {SpawnAirbase, GroupSpawned, 75, true} , 1.0)
|
||||
end
|
||||
|
||||
return GroupSpawned
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Spawn a group on an @{Wrapper.Airbase} at a specific parking spot.
|
||||
-- @param #SPAWN self
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase The @{Wrapper.Airbase} where to spawn the group.
|
||||
-- @param #table Spots Table of parking spot IDs. Note that these in general are different from the numbering in the mission editor!
|
||||
-- @param #SPAWN.Takeoff Takeoff (Optional) Takeoff type, i.e. either SPAWN.Takeoff.Cold or SPAWN.Takeoff.Hot. Default is Hot.
|
||||
-- @return Wrapper.Group#GROUP The group that was spawned or nil when nothing was spawned.
|
||||
function SPAWN:SpawnAtParkingSpot(Airbase, Spots, Takeoff) -- R2.5
|
||||
self:F({Airbase=Airbase, Spots=Spots, Takeoff=Takeoff})
|
||||
|
||||
-- Ensure that Spots parameter is a table.
|
||||
if type(Spots)~="table" then
|
||||
Spots={Spots}
|
||||
end
|
||||
|
||||
-- Get template group.
|
||||
local group=GROUP:FindByName(self.SpawnTemplatePrefix)
|
||||
|
||||
-- Get number of units in group.
|
||||
local nunits=self.SpawnGrouping or #group:GetUnits()
|
||||
|
||||
-- Quick check.
|
||||
if nunits then
|
||||
|
||||
-- Check that number of provided parking spots is large enough.
|
||||
if #Spots<nunits then
|
||||
self:E("ERROR: Number of provided parking spots is less than number of units in group!")
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Table of parking data.
|
||||
local Parkingdata={}
|
||||
|
||||
-- Loop over provided Terminal IDs.
|
||||
for _,TerminalID in pairs(Spots) do
|
||||
|
||||
-- Get parking spot data.
|
||||
local spot=Airbase:GetParkingSpotData(TerminalID)
|
||||
|
||||
self:T2({spot=spot})
|
||||
|
||||
if spot and spot.Free then
|
||||
self:T(string.format("Adding parking spot ID=%d TermType=%d", spot.TerminalID, spot.TerminalType))
|
||||
table.insert(Parkingdata, spot)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if #Parkingdata>=nunits then
|
||||
return self:SpawnAtAirbase(Airbase, Takeoff, nil, nil, nil, Parkingdata)
|
||||
else
|
||||
self:E("ERROR: Could not find enough free parking spots!")
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
self:E("ERROR: Could not get number of units in group!")
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Will park a group at an @{Wrapper.Airbase}.
|
||||
--
|
||||
-- @param #SPAWN self
|
||||
-- @param Wrapper.Airbase#AIRBASE SpawnAirbase The @{Wrapper.Airbase} where to spawn the group.
|
||||
-- @param Wrapper.Airbase#AIRBASE.TerminalType TerminalType (optional) The terminal type the aircraft should be spawned at. See @{Wrapper.Airbase#AIRBASE.TerminalType}.
|
||||
-- @param #table Parkingdata (optional) Table holding the coordinates and terminal ids for all units of the group. Spawning will be forced to happen at exactily these spots!
|
||||
-- @return #nil Nothing is returned!
|
||||
function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex )
|
||||
|
||||
self:F( { SpawnIndex = SpawnIndex, SpawnMaxGroups = self.SpawnMaxGroups } )
|
||||
|
||||
-- Get position of airbase.
|
||||
local PointVec3 = SpawnAirbase:GetCoordinate()
|
||||
self:T2(PointVec3)
|
||||
|
||||
-- Set take off type. Default is hot.
|
||||
local Takeoff = SPAWN.Takeoff.Cold
|
||||
|
||||
-- Get group template.
|
||||
local SpawnTemplate = self.SpawnGroups[SpawnIndex].SpawnTemplate
|
||||
|
||||
if SpawnTemplate then
|
||||
|
||||
-- Check if the aircraft with the specified SpawnIndex is already spawned.
|
||||
-- If yes, ensure that the aircraft is spawned at the same aircraft spot.
|
||||
|
||||
local GroupAlive = self:GetGroupFromIndex( SpawnIndex )
|
||||
|
||||
-- Debug output
|
||||
self:T( { "Current point of ", self.SpawnTemplatePrefix, SpawnAirbase } )
|
||||
|
||||
-- Template group, unit and its attributes.
|
||||
local TemplateGroup = GROUP:FindByName(self.SpawnTemplatePrefix)
|
||||
local TemplateUnit=TemplateGroup:GetUnit(1)
|
||||
local ishelo=TemplateUnit:HasAttribute("Helicopters")
|
||||
local isbomber=TemplateUnit:HasAttribute("Bombers")
|
||||
local istransport=TemplateUnit:HasAttribute("Transports")
|
||||
local isfighter=TemplateUnit:HasAttribute("Battleplanes")
|
||||
|
||||
-- Number of units in the group. With grouping this can actually differ from the template group size!
|
||||
local nunits=#SpawnTemplate.units
|
||||
|
||||
-- First waypoint of the group.
|
||||
local SpawnPoint = SpawnTemplate.route.points[1]
|
||||
|
||||
-- These are only for ships and FARPS.
|
||||
SpawnPoint.linkUnit = nil
|
||||
SpawnPoint.helipadId = nil
|
||||
SpawnPoint.airdromeId = nil
|
||||
|
||||
-- Get airbase ID and category.
|
||||
local AirbaseID = SpawnAirbase:GetID()
|
||||
local AirbaseCategory = SpawnAirbase:GetDesc().category
|
||||
self:F( { AirbaseCategory = AirbaseCategory } )
|
||||
|
||||
-- Set airdromeId.
|
||||
if AirbaseCategory == Airbase.Category.SHIP then
|
||||
SpawnPoint.linkUnit = AirbaseID
|
||||
SpawnPoint.helipadId = AirbaseID
|
||||
elseif AirbaseCategory == Airbase.Category.HELIPAD then
|
||||
SpawnPoint.linkUnit = AirbaseID
|
||||
SpawnPoint.helipadId = AirbaseID
|
||||
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
||||
SpawnPoint.airdromeId = AirbaseID
|
||||
end
|
||||
|
||||
-- Set waypoint type/action.
|
||||
SpawnPoint.alt = 0
|
||||
SpawnPoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
||||
SpawnPoint.action = GROUPTEMPLATE.Takeoff[Takeoff][2] -- action
|
||||
|
||||
-- Check if we spawn on ground.
|
||||
local spawnonground=not (Takeoff==SPAWN.Takeoff.Air)
|
||||
self:T({spawnonground=spawnonground, TOtype=Takeoff, TOair=Takeoff==SPAWN.Takeoff.Air})
|
||||
|
||||
-- Check where we actually spawn if we spawn on ground.
|
||||
local spawnonship=false
|
||||
local spawnonfarp=false
|
||||
local spawnonrunway=false
|
||||
local spawnonairport=false
|
||||
if spawnonground then
|
||||
if AirbaseCategory == Airbase.Category.SHIP then
|
||||
spawnonship=true
|
||||
elseif AirbaseCategory == Airbase.Category.HELIPAD then
|
||||
spawnonfarp=true
|
||||
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
||||
spawnonairport=true
|
||||
end
|
||||
spawnonrunway=Takeoff==SPAWN.Takeoff.Runway
|
||||
end
|
||||
|
||||
-- Array with parking spots coordinates.
|
||||
local parkingspots={}
|
||||
local parkingindex={}
|
||||
local spots
|
||||
|
||||
-- Spawn happens on ground, i.e. at an airbase, a FARP or a ship.
|
||||
if spawnonground and not SpawnTemplate.parked then
|
||||
|
||||
|
||||
-- Number of free parking spots.
|
||||
local nfree=0
|
||||
|
||||
-- Set terminal type.
|
||||
local termtype=TerminalType
|
||||
|
||||
-- Scan options. Might make that input somehow.
|
||||
local scanradius=50
|
||||
local scanunits=true
|
||||
local scanstatics=true
|
||||
local scanscenery=false
|
||||
local verysafe=false
|
||||
|
||||
-- Number of free parking spots at the airbase.
|
||||
if spawnonship or spawnonfarp or spawnonrunway then
|
||||
-- These places work procedural and have some kind of build in queue ==> Less effort.
|
||||
self:T(string.format("Group %s is spawned on farp/ship/runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName()))
|
||||
nfree=SpawnAirbase:GetFreeParkingSpotsNumber(termtype, true)
|
||||
spots=SpawnAirbase:GetFreeParkingSpotsTable(termtype, true)
|
||||
elseif Parkingdata~=nil then
|
||||
-- Parking data explicitly set by user as input parameter.
|
||||
nfree=#Parkingdata
|
||||
spots=Parkingdata
|
||||
else
|
||||
if ishelo then
|
||||
if termtype==nil then
|
||||
-- Helo is spawned. Try exclusive helo spots first.
|
||||
self:T(string.format("Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterOnly))
|
||||
spots=SpawnAirbase:FindFreeParkingSpotForAircraft(TemplateGroup, AIRBASE.TerminalType.HelicopterOnly, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits)
|
||||
nfree=#spots
|
||||
if nfree<nunits then
|
||||
-- Not enough helo ports. Let's try also other terminal types.
|
||||
self:T(string.format("Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterUsable))
|
||||
spots=SpawnAirbase:FindFreeParkingSpotForAircraft(TemplateGroup, AIRBASE.TerminalType.HelicopterUsable, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits)
|
||||
nfree=#spots
|
||||
end
|
||||
else
|
||||
-- No terminal type specified. We try all spots except shelters.
|
||||
self:T(string.format("Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), termtype))
|
||||
spots=SpawnAirbase:FindFreeParkingSpotForAircraft(TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits)
|
||||
nfree=#spots
|
||||
end
|
||||
else
|
||||
-- Fixed wing aircraft is spawned.
|
||||
if termtype==nil then
|
||||
--TODO: Add some default cases for transport, bombers etc. if no explicit terminal type is provided.
|
||||
--TODO: We don't want Bombers to spawn in shelters. But I don't know a good attribute for just fighers.
|
||||
--TODO: Some attributes are "Helicopters", "Bombers", "Transports", "Battleplanes". Need to check it out.
|
||||
if isbomber or istransport then
|
||||
-- First we fill the potentially bigger spots.
|
||||
self:T(string.format("Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenBig))
|
||||
spots=SpawnAirbase:FindFreeParkingSpotForAircraft(TemplateGroup, AIRBASE.TerminalType.OpenBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits)
|
||||
nfree=#spots
|
||||
if nfree<nunits then
|
||||
-- Now we try the smaller ones.
|
||||
self:T(string.format("Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenMedOrBig))
|
||||
spots=SpawnAirbase:FindFreeParkingSpotForAircraft(TemplateGroup, AIRBASE.TerminalType.OpenMedOrBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits)
|
||||
nfree=#spots
|
||||
end
|
||||
else
|
||||
self:T(string.format("Fighter group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.FighterAircraft))
|
||||
spots=SpawnAirbase:FindFreeParkingSpotForAircraft(TemplateGroup, AIRBASE.TerminalType.FighterAircraft, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits)
|
||||
nfree=#spots
|
||||
end
|
||||
else
|
||||
-- Terminal type explicitly given.
|
||||
self:T(string.format("Plane group %s is at %s using terminal type %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), tostring(termtype)))
|
||||
spots=SpawnAirbase:FindFreeParkingSpotForAircraft(TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits)
|
||||
nfree=#spots
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Get parking data.
|
||||
local parkingdata=SpawnAirbase:GetParkingSpotsTable(termtype)
|
||||
self:T2(string.format("Parking at %s, terminal type %s:", SpawnAirbase:GetName(), tostring(termtype)))
|
||||
for _,_spot in pairs(parkingdata) do
|
||||
self:T2(string.format("%s, Termin Index = %3d, Term Type = %03d, Free = %5s, TOAC = %5s, Term ID0 = %3d, Dist2Rwy = %4d",
|
||||
SpawnAirbase:GetName(), _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy))
|
||||
end
|
||||
self:T(string.format("%s at %s: free parking spots = %d - number of units = %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), nfree, nunits))
|
||||
|
||||
-- Set this to true if not enough spots are available for emergency air start.
|
||||
local _notenough=false
|
||||
|
||||
-- Need to differentiate some cases again.
|
||||
if spawnonship or spawnonfarp or spawnonrunway then
|
||||
|
||||
-- On free spot required in these cases.
|
||||
if nfree >=1 then
|
||||
|
||||
-- All units get the same spot. DCS takes care of the rest.
|
||||
for i=1,nunits do
|
||||
table.insert(parkingspots, spots[1].Coordinate)
|
||||
table.insert(parkingindex, spots[1].TerminalID)
|
||||
end
|
||||
-- This is actually used...
|
||||
PointVec3=spots[1].Coordinate
|
||||
|
||||
else
|
||||
-- If there is absolutely no spot ==> air start!
|
||||
_notenough=true
|
||||
end
|
||||
|
||||
elseif spawnonairport then
|
||||
|
||||
if nfree>=nunits then
|
||||
|
||||
for i=1,nunits do
|
||||
table.insert(parkingspots, spots[i].Coordinate)
|
||||
table.insert(parkingindex, spots[i].TerminalID)
|
||||
end
|
||||
|
||||
else
|
||||
-- Not enough spots for the whole group ==> air start!
|
||||
_notenough=true
|
||||
end
|
||||
end
|
||||
|
||||
-- Not enough spots ==> Prepare airstart.
|
||||
if _notenough then
|
||||
|
||||
if not self.SpawnUnControlled then
|
||||
else
|
||||
self:E(string.format("WARNING: Group %s has no parking spots at %s ==> No emergency air start or uncontrolled spawning ==> No spawn!", self.SpawnTemplatePrefix, SpawnAirbase:GetName()))
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
end
|
||||
|
||||
if not SpawnTemplate.parked then
|
||||
-- Translate the position of the Group Template to the Vec3.
|
||||
|
||||
SpawnTemplate.parked = true
|
||||
|
||||
for UnitID = 1, nunits do
|
||||
self:T2('Before Translation SpawnTemplate.units['..UnitID..'].x = '..SpawnTemplate.units[UnitID].x..', SpawnTemplate.units['..UnitID..'].y = '..SpawnTemplate.units[UnitID].y)
|
||||
self:F('Before Translation SpawnTemplate.units['..UnitID..'].x = '..SpawnTemplate.units[UnitID].x..', SpawnTemplate.units['..UnitID..'].y = '..SpawnTemplate.units[UnitID].y)
|
||||
|
||||
-- Template of the current unit.
|
||||
local UnitTemplate = SpawnTemplate.units[UnitID]
|
||||
@@ -1687,33 +2205,86 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
|
||||
self:T2(string.format("Group %s unit number %d: Parking ID = %s",self.SpawnTemplatePrefix, UnitID, tostring(UnitTemplate.parking_id)))
|
||||
self:T2('After Translation SpawnTemplate.units['..UnitID..'].x = '..SpawnTemplate.units[UnitID].x..', SpawnTemplate.units['..UnitID..'].y = '..SpawnTemplate.units[UnitID].y)
|
||||
end
|
||||
|
||||
-- Set gereral spawnpoint position.
|
||||
SpawnPoint.x = PointVec3.x
|
||||
SpawnPoint.y = PointVec3.z
|
||||
SpawnPoint.alt = PointVec3.y
|
||||
|
||||
SpawnTemplate.x = PointVec3.x
|
||||
SpawnTemplate.y = PointVec3.z
|
||||
|
||||
-- Spawn group.
|
||||
local GroupSpawned = self:SpawnWithIndex( self.SpawnIndex )
|
||||
|
||||
-- When spawned in the air, we need to generate a Takeoff Event.
|
||||
if Takeoff == GROUP.Takeoff.Air then
|
||||
for UnitID, UnitSpawned in pairs( GroupSpawned:GetUnits() ) do
|
||||
SCHEDULER:New( nil, BASE.CreateEventTakeoff, { GroupSpawned, timer.getTime(), UnitSpawned:GetDCSObject() } , 1 )
|
||||
end
|
||||
end
|
||||
|
||||
-- Check if we accidentally spawned on the runway. Needs to be schedules, because group is not immidiately alive.
|
||||
if Takeoff~=SPAWN.Takeoff.Runway and Takeoff~=SPAWN.Takeoff.Air and spawnonairport then
|
||||
SCHEDULER:New(nil, AIRBASE.CheckOnRunWay, {SpawnAirbase, GroupSpawned, 75, true} , 1.0)
|
||||
end
|
||||
|
||||
return GroupSpawned
|
||||
end
|
||||
|
||||
-- Set gereral spawnpoint position.
|
||||
SpawnPoint.x = PointVec3.x
|
||||
SpawnPoint.y = PointVec3.z
|
||||
SpawnPoint.alt = PointVec3.y
|
||||
|
||||
SpawnTemplate.x = PointVec3.x
|
||||
SpawnTemplate.y = PointVec3.z
|
||||
|
||||
SpawnTemplate.uncontrolled = true
|
||||
|
||||
-- Spawn group.
|
||||
local GroupSpawned = self:SpawnWithIndex( SpawnIndex, true )
|
||||
|
||||
-- When spawned in the air, we need to generate a Takeoff Event.
|
||||
if Takeoff == GROUP.Takeoff.Air then
|
||||
for UnitID, UnitSpawned in pairs( GroupSpawned:GetUnits() ) do
|
||||
SCHEDULER:New( nil, BASE.CreateEventTakeoff, { GroupSpawned, timer.getTime(), UnitSpawned:GetDCSObject() } , 5 )
|
||||
end
|
||||
end
|
||||
|
||||
-- Check if we accidentally spawned on the runway. Needs to be schedules, because group is not immidiately alive.
|
||||
if Takeoff~=SPAWN.Takeoff.Runway and Takeoff~=SPAWN.Takeoff.Air and spawnonairport then
|
||||
SCHEDULER:New(nil, AIRBASE.CheckOnRunWay, {SpawnAirbase, GroupSpawned, 75, true} , 1.0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Will park a group at an @{Wrapper.Airbase}.
|
||||
-- This method is mostly advisable to be used if you want to simulate parking units at an airbase and be visible.
|
||||
-- Note that each point in the route assigned to the spawning group is reset to the point of the spawn.
|
||||
--
|
||||
-- All groups that are in the spawn collection and that are alive, and not in the air, are parked.
|
||||
--
|
||||
-- The @{Wrapper.Airbase#AIRBASE} object must refer to a valid airbase known in the sim.
|
||||
-- You can use the following enumerations to search for the pre-defined airbases on the current known maps of DCS:
|
||||
--
|
||||
-- * @{Wrapper.Airbase#AIRBASE.Caucasus}: The airbases on the Caucasus map.
|
||||
-- * @{Wrapper.Airbase#AIRBASE.Nevada}: The airbases on the Nevada (NTTR) map.
|
||||
-- * @{Wrapper.Airbase#AIRBASE.Normandy}: The airbases on the Normandy map.
|
||||
--
|
||||
-- Use the method @{Wrapper.Airbase#AIRBASE.FindByName}() to retrieve the airbase object.
|
||||
-- The known AIRBASE objects are automatically imported at mission start by MOOSE.
|
||||
-- Therefore, there isn't any New() constructor defined for AIRBASE objects.
|
||||
--
|
||||
-- Ships and Farps are added within the mission, and are therefore not known.
|
||||
-- For these AIRBASE objects, there isn't an @{Wrapper.Airbase#AIRBASE} enumeration defined.
|
||||
-- You need to provide the **exact name** of the airbase as the parameter to the @{Wrapper.Airbase#AIRBASE.FindByName}() method!
|
||||
--
|
||||
-- @param #SPAWN self
|
||||
-- @param Wrapper.Airbase#AIRBASE SpawnAirbase The @{Wrapper.Airbase} where to spawn the group.
|
||||
-- @param Wrapper.Airbase#AIRBASE.TerminalType TerminalType (optional) The terminal type the aircraft should be spawned at. See @{Wrapper.Airbase#AIRBASE.TerminalType}.
|
||||
-- @param #table Parkingdata (optional) Table holding the coordinates and terminal ids for all units of the group. Spawning will be forced to happen at exactily these spots!
|
||||
-- @return #nil Nothing is returned!
|
||||
-- @usage
|
||||
-- Spawn_Plane = SPAWN:New( "Plane" )
|
||||
-- Spawn_Plane:ParkAtAirbase( AIRBASE:FindByName( AIRBASE.Caucasus.Krymsk ) )
|
||||
--
|
||||
-- Spawn_Heli = SPAWN:New( "Heli")
|
||||
--
|
||||
-- Spawn_Heli:ParkAtAirbase( AIRBASE:FindByName( "FARP Cold" ) )
|
||||
--
|
||||
-- Spawn_Heli:ParkAtAirbase( AIRBASE:FindByName( "Carrier" ) )
|
||||
--
|
||||
-- Spawn_Plane:ParkAtAirbase( AIRBASE:FindByName( AIRBASE.Caucasus.Krymsk ), AIRBASE.TerminalType.OpenBig )
|
||||
--
|
||||
function SPAWN:ParkAtAirbase( SpawnAirbase, TerminalType, Parkingdata ) -- R2.2, R2.4, R2.5
|
||||
self:F( { self.SpawnTemplatePrefix, SpawnAirbase, TerminalType } )
|
||||
|
||||
self:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, 1 )
|
||||
|
||||
for SpawnIndex = 2, self.SpawnMaxGroups do
|
||||
self:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex )
|
||||
--self:ScheduleOnce( SpawnIndex * 0.1, SPAWN.ParkAircraft, self, SpawnAirbase, TerminalType, Parkingdata, SpawnIndex )
|
||||
end
|
||||
|
||||
self:SetSpawnIndex( 0 )
|
||||
|
||||
return nil
|
||||
end
|
||||
@@ -2005,10 +2576,10 @@ end
|
||||
function SPAWN:InitUnControlled( UnControlled )
|
||||
self:F2( { self.SpawnTemplatePrefix, UnControlled } )
|
||||
|
||||
self.SpawnUnControlled = UnControlled
|
||||
self.SpawnUnControlled = ( UnControlled == true ) and true or nil
|
||||
|
||||
for SpawnGroupID = 1, self.SpawnMaxGroups do
|
||||
self.SpawnGroups[SpawnGroupID].UnControlled = UnControlled
|
||||
self.SpawnGroups[SpawnGroupID].UnControlled = self.SpawnUnControlled
|
||||
end
|
||||
|
||||
return self
|
||||
@@ -2114,10 +2685,9 @@ end
|
||||
-- -- Do actions with the GroupPlane object.
|
||||
-- end
|
||||
function SPAWN:GetLastAliveGroup()
|
||||
self:F( { self.SpawnTemplatePrefixself.SpawnAliasPrefix } )
|
||||
|
||||
self.SpawnIndex = self:_GetLastIndex()
|
||||
for SpawnIndex = self.SpawnIndex, 1, -1 do
|
||||
self:F( { self.SpawnTemplatePrefix, self.SpawnAliasPrefix } )
|
||||
|
||||
for SpawnIndex = self.SpawnCount, 1, -1 do -- Added
|
||||
local SpawnGroup = self:GetGroupFromIndex( SpawnIndex )
|
||||
if SpawnGroup and SpawnGroup:IsAlive() then
|
||||
self.SpawnIndex = SpawnIndex
|
||||
@@ -2340,6 +2910,21 @@ function SPAWN:_Prepare( SpawnTemplatePrefix, SpawnIndex ) --R2.2
|
||||
SpawnTemplate.units[UnitID].unitId = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Callsign
|
||||
for UnitID = 1, #SpawnTemplate.units do
|
||||
local Callsign = SpawnTemplate.units[UnitID].callsign
|
||||
if Callsign then
|
||||
if type(Callsign) ~= "number" then -- blue callsign
|
||||
Callsign[2] = ( ( SpawnIndex - 1 ) % 10 ) + 1
|
||||
local CallsignName = SpawnTemplate.units[UnitID].callsign["name"] -- #string
|
||||
local CallsignLen = CallsignName:len()
|
||||
SpawnTemplate.units[UnitID].callsign["name"] = CallsignName:sub(1,CallsignLen) .. SpawnTemplate.units[UnitID].callsign[2] .. SpawnTemplate.units[UnitID].callsign[3]
|
||||
else
|
||||
SpawnTemplate.units[UnitID].callsign = Callsign + SpawnIndex
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self:T3( { "Template:", SpawnTemplate } )
|
||||
return SpawnTemplate
|
||||
@@ -2504,6 +3089,9 @@ function SPAWN:_TranslateRotate( SpawnIndex, SpawnRootX, SpawnRootY, SpawnX, Spa
|
||||
end
|
||||
|
||||
--- Get the next index of the groups to be spawned. This method is complicated, as it is used at several spaces.
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnIndex Spawn index.
|
||||
-- @return #number self.SpawnIndex
|
||||
function SPAWN:_GetSpawnIndex( SpawnIndex )
|
||||
self:F2( { self.SpawnTemplatePrefix, SpawnIndex, self.SpawnMaxGroups, self.SpawnMaxUnitsAlive, self.AliveUnits, #self.SpawnTemplate.units } )
|
||||
|
||||
@@ -2611,7 +3199,10 @@ function SPAWN:_OnLand( EventData )
|
||||
if self.RepeatOnLanding then
|
||||
local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup )
|
||||
self:T( { "Landed:", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } )
|
||||
self:ReSpawn( SpawnGroupIndex )
|
||||
--self:ReSpawn( SpawnGroupIndex )
|
||||
-- Delay respawn by three seconds due to DCS 2.5.4.26368 OB bug https://github.com/FlightControl-Master/MOOSE/issues/1076
|
||||
-- Bug was initially only for engine shutdown event but after ED "fixed" it, it now happens on landing events.
|
||||
SCHEDULER:New(nil, self.ReSpawn, {self, SpawnGroupIndex}, 3)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2637,7 +3228,9 @@ function SPAWN:_OnEngineShutDown( EventData )
|
||||
if Landed and self.RepeatOnEngineShutDown then
|
||||
local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup )
|
||||
self:T( { "EngineShutDown: ", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } )
|
||||
self:ReSpawn( SpawnGroupIndex )
|
||||
--self:ReSpawn( SpawnGroupIndex )
|
||||
-- Delay respawn by three seconds due to DCS 2.5.4 OB bug https://github.com/FlightControl-Master/MOOSE/issues/1076
|
||||
SCHEDULER:New(nil, self.ReSpawn, {self, SpawnGroupIndex}, 3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -195,6 +195,49 @@ function SPAWNSTATIC:SpawnFromPointVec2( PointVec2, Heading, NewName ) --R2.1
|
||||
end
|
||||
|
||||
|
||||
--- Creates a new @{Static} from a COORDINATE.
|
||||
-- @param #SPAWNSTATIC self
|
||||
-- @param Core.Point#COORDINATE Coordinate The 3D coordinate where to spawn the static.
|
||||
-- @param #number Heading (Optional) Heading The heading of the static, which is a number in degrees from 0 to 360. Default is 0 degrees.
|
||||
-- @param #string NewName (Optional) The name of the new static.
|
||||
-- @return #SPAWNSTATIC
|
||||
function SPAWNSTATIC:SpawnFromCoordinate(Coordinate, Heading, NewName) --R2.4
|
||||
self:F( { PointVec2, Heading, NewName } )
|
||||
|
||||
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
||||
|
||||
if StaticTemplate then
|
||||
|
||||
Heading=Heading or 0
|
||||
|
||||
local StaticUnitTemplate = StaticTemplate.units[1]
|
||||
|
||||
StaticUnitTemplate.x = Coordinate.x
|
||||
StaticUnitTemplate.y = Coordinate.z
|
||||
StaticUnitTemplate.alt = Coordinate.y
|
||||
|
||||
StaticTemplate.route = nil
|
||||
StaticTemplate.groupId = nil
|
||||
|
||||
StaticTemplate.name = NewName or string.format("%s#%05d", self.SpawnTemplatePrefix, self.SpawnIndex )
|
||||
StaticUnitTemplate.name = StaticTemplate.name
|
||||
StaticUnitTemplate.heading = ( Heading / 180 ) * math.pi
|
||||
|
||||
_DATABASE:_RegisterStaticTemplate( StaticTemplate, CoalitionID, CategoryID, CountryID)
|
||||
|
||||
self:F({StaticTemplate = StaticTemplate})
|
||||
|
||||
local Static = coalition.addStaticObject( self.CountryID or CountryID, StaticTemplate.units[1] )
|
||||
|
||||
self.SpawnIndex = self.SpawnIndex + 1
|
||||
|
||||
return _DATABASE:FindStatic(Static:getName())
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
--- Respawns the original @{Static}.
|
||||
-- @param #SPAWNSTATIC self
|
||||
-- @return #SPAWNSTATIC
|
||||
@@ -248,7 +291,7 @@ end
|
||||
-- @param #SPAWNSTATIC self
|
||||
-- @param Core.Zone#ZONE_BASE Zone The Zone where to spawn the static.
|
||||
-- @param #number Heading The heading of the static, which is a number in degrees from 0 to 360.
|
||||
-- @param #string (optional) The name of the new static.
|
||||
-- @param #string NewName (optional) The name of the new static.
|
||||
-- @return #SPAWNSTATIC
|
||||
function SPAWNSTATIC:SpawnFromZone( Zone, Heading, NewName ) --R2.1
|
||||
self:F( { Zone, Heading, NewName } )
|
||||
|
||||
@@ -126,6 +126,39 @@ do
|
||||
-- @param Wrapper.Positionable#POSITIONABLE Target
|
||||
-- @param #number LaserCode Laser code.
|
||||
-- @param #number Duration Duration of lasing in seconds.
|
||||
|
||||
self:AddTransition( "Off", "LaseOnCoordinate", "On" )
|
||||
|
||||
--- LaseOnCoordinate Handler OnBefore for SPOT.
|
||||
-- @function [parent=#SPOT] OnBeforeLaseOnCoordinate
|
||||
-- @param #SPOT self
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
-- @return #boolean
|
||||
|
||||
--- LaseOnCoordinate Handler OnAfter for SPOT.
|
||||
-- @function [parent=#SPOT] OnAfterLaseOnCoordinate
|
||||
-- @param #SPOT self
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
|
||||
--- LaseOnCoordinate Trigger for SPOT.
|
||||
-- @function [parent=#SPOT] LaseOnCoordinate
|
||||
-- @param #SPOT self
|
||||
-- @param Core.Point#COORDINATE Coordinate The coordinate to lase.
|
||||
-- @param #number LaserCode Laser code.
|
||||
-- @param #number Duration Duration of lasing in seconds.
|
||||
|
||||
--- LaseOn Asynchronous Trigger for SPOT
|
||||
-- @function [parent=#SPOT] __LaseOn
|
||||
-- @param #SPOT self
|
||||
-- @param #number Delay
|
||||
-- @param Wrapper.Positionable#POSITIONABLE Target
|
||||
-- @param #number LaserCode Laser code.
|
||||
-- @param #number Duration Duration of lasing in seconds.
|
||||
|
||||
|
||||
|
||||
self:AddTransition( "On", "Lasing", "On" )
|
||||
@@ -194,7 +227,8 @@ do
|
||||
return self
|
||||
end
|
||||
|
||||
--- @param #SPOT self
|
||||
--- On after LaseOn event. Activates the laser spot.
|
||||
-- @param #SPOT self
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
@@ -226,6 +260,40 @@ do
|
||||
|
||||
self:__Lasing( -1 )
|
||||
end
|
||||
|
||||
|
||||
--- On after LaseOnCoordinate event. Activates the laser spot.
|
||||
-- @param #SPOT self
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
-- @param Core.Point#COORDINATE Coordinate The coordinate at which the laser is pointing.
|
||||
-- @param #number LaserCode Laser code.
|
||||
-- @param #number Duration Duration of lasing in seconds.
|
||||
function SPOT:onafterLaseOnCoordinate(From, Event, To, Coordinate, LaserCode, Duration)
|
||||
self:F( { "LaseOnCoordinate", Coordinate, LaserCode, Duration } )
|
||||
|
||||
local function StopLase( self )
|
||||
self:LaseOff()
|
||||
end
|
||||
|
||||
self.Target = nil
|
||||
self.TargetCoord=Coordinate
|
||||
self.LaserCode = LaserCode
|
||||
|
||||
self.Lasing = true
|
||||
|
||||
local RecceDcsUnit = self.Recce:GetDCSObject()
|
||||
|
||||
self.SpotIR = Spot.createInfraRed( RecceDcsUnit, { x = 0, y = 1, z = 0 }, Coordinate:GetVec3() )
|
||||
self.SpotLaser = Spot.createLaser( RecceDcsUnit, { x = 0, y = 1, z = 0 }, Coordinate:GetVec3(), LaserCode )
|
||||
|
||||
if Duration then
|
||||
self.ScheduleID = self.LaseScheduler:Schedule( self, StopLase, {self}, Duration )
|
||||
end
|
||||
|
||||
self:__Lasing(-1)
|
||||
end
|
||||
|
||||
--- @param #SPOT self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
@@ -246,10 +314,20 @@ do
|
||||
-- @param To
|
||||
function SPOT:onafterLasing( From, Event, To )
|
||||
|
||||
if self.Target:IsAlive() then
|
||||
if self.Target and self.Target:IsAlive() then
|
||||
self.SpotIR:setPoint( self.Target:GetPointVec3():AddY(1):AddY(math.random(-100,100)/100):AddX(math.random(-100,100)/100):GetVec3() )
|
||||
self.SpotLaser:setPoint( self.Target:GetPointVec3():AddY(1):GetVec3() )
|
||||
self:__Lasing( -0.2 )
|
||||
elseif self.TargetCoord then
|
||||
|
||||
-- Wiggle the IR spot a bit.
|
||||
local irvec3={x=self.TargetCoord.x+math.random(-100,100)/100, y=self.TargetCoord.y+math.random(-100,100)/100, z=self.TargetCoord.z} --#DCS.Vec3
|
||||
local lsvec3={x=self.TargetCoord.x, y=self.TargetCoord.y, z=self.TargetCoord.z} --#DCS.Vec3
|
||||
|
||||
self.SpotIR:setPoint(irvec3)
|
||||
self.SpotLaser:setPoint(lsvec3)
|
||||
|
||||
self:__Lasing(-0.25)
|
||||
else
|
||||
self:F( { "Target is not alive", self.Target:IsAlive() } )
|
||||
end
|
||||
|
||||
@@ -70,7 +70,7 @@ do -- UserFlag
|
||||
-- local BlueVictory = USERFLAG:New( "VictoryBlue" )
|
||||
-- local BlueVictoryValue = BlueVictory:Get() -- Get the UserFlag VictoryBlue value.
|
||||
--
|
||||
function USERFLAG:Get( Number ) --R2.3
|
||||
function USERFLAG:Get() --R2.3
|
||||
|
||||
return trigger.misc.getUserFlag( self.UserFlagName )
|
||||
end
|
||||
|
||||
@@ -118,15 +118,21 @@ do -- UserSound
|
||||
--- Play the usersound to the given @{Wrapper.Group}.
|
||||
-- @param #USERSOUND self
|
||||
-- @param Wrapper.Group#GROUP Group The @{Wrapper.Group} to play the usersound to.
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the sound is played. Default 0.
|
||||
-- @return #USERSOUND The usersound instance.
|
||||
-- @usage
|
||||
-- local BlueVictory = USERSOUND:New( "BlueVictory.ogg" )
|
||||
-- local PlayerGroup = GROUP:FindByName( "PlayerGroup" ) -- Search for the active group named "PlayerGroup", that contains a human player.
|
||||
-- BlueVictory:ToGroup( PlayerGroup ) -- Play the sound that Blue has won to the player group.
|
||||
--
|
||||
function USERSOUND:ToGroup( Group ) --R2.3
|
||||
|
||||
trigger.action.outSoundForGroup( Group:GetID(), self.UserSoundFileName )
|
||||
function USERSOUND:ToGroup( Group, Delay ) --R2.3
|
||||
|
||||
Delay=Delay or 0
|
||||
if Delay>0 then
|
||||
SCHEDULER:New(nil, USERSOUND.ToGroup,{self, Group}, Delay)
|
||||
else
|
||||
trigger.action.outSoundForGroup( Group:GetID(), self.UserSoundFileName )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -120,7 +120,7 @@ ZONE_BASE = {
|
||||
-- @param #string ZoneName Name of the zone.
|
||||
-- @return #ZONE_BASE self
|
||||
function ZONE_BASE:New( ZoneName )
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
local self = BASE:Inherit( self, FSM:New() )
|
||||
self:F( ZoneName )
|
||||
|
||||
self.ZoneName = ZoneName
|
||||
@@ -442,6 +442,33 @@ function ZONE_RADIUS:New( ZoneName, Vec2, Radius )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Mark the zone with markers on the F10 map.
|
||||
-- @param #ZONE_RADIUS self
|
||||
-- @param #number Points (Optional) The amount of points in the circle. Default 360.
|
||||
-- @return #ZONE_RADIUS self
|
||||
function ZONE_RADIUS:MarkZone(Points)
|
||||
|
||||
local Point = {}
|
||||
local Vec2 = self:GetVec2()
|
||||
|
||||
Points = Points and Points or 360
|
||||
|
||||
local Angle
|
||||
local RadialBase = math.pi*2
|
||||
|
||||
for Angle = 0, 360, (360 / Points ) do
|
||||
|
||||
local Radial = Angle * RadialBase / 360
|
||||
|
||||
Point.x = Vec2.x + math.cos( Radial ) * self:GetRadius()
|
||||
Point.y = Vec2.y + math.sin( Radial ) * self:GetRadius()
|
||||
|
||||
COORDINATE:NewFromVec2(Point):MarkToAll(self:GetName())
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Bounds the zone with tires.
|
||||
-- @param #ZONE_RADIUS self
|
||||
-- @param #number Points (optional) The amount of points in the circle. Default 360.
|
||||
@@ -535,7 +562,7 @@ function ZONE_RADIUS:FlareZone( FlareColor, Points, Azimuth, AddHeight )
|
||||
local Vec2 = self:GetVec2()
|
||||
|
||||
AddHeight = AddHeight or 0
|
||||
|
||||
|
||||
Points = Points and Points or 360
|
||||
|
||||
local Angle
|
||||
@@ -618,6 +645,9 @@ function ZONE_RADIUS:GetVec3( Height )
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Scan the zone for the presence of units of the given ObjectCategories.
|
||||
-- Note that after a zone has been scanned, the zone can be evaluated by:
|
||||
--
|
||||
@@ -628,12 +658,12 @@ end
|
||||
-- * @{ZONE_RADIUS.IsNoneInZone}(): Scan if the zone is empty.
|
||||
-- @{#ZONE_RADIUS.
|
||||
-- @param #ZONE_RADIUS self
|
||||
-- @param ObjectCategories
|
||||
-- @param Coalition
|
||||
-- @param ObjectCategories An array of categories of the objects to find in the zone.
|
||||
-- @param UnitCategories An array of unit categories of the objects to find in the zone.
|
||||
-- @usage
|
||||
-- self.Zone:Scan()
|
||||
-- local IsAttacked = self.Zone:IsSomeInZoneOfCoalition( self.Coalition )
|
||||
function ZONE_RADIUS:Scan( ObjectCategories )
|
||||
function ZONE_RADIUS:Scan( ObjectCategories, UnitCategories )
|
||||
|
||||
self.ScanData = {}
|
||||
self.ScanData.Coalitions = {}
|
||||
@@ -660,9 +690,24 @@ function ZONE_RADIUS:Scan( ObjectCategories )
|
||||
if ( ObjectCategory == Object.Category.UNIT and ZoneObject:isExist() and ZoneObject:isActive() ) or
|
||||
(ObjectCategory == Object.Category.STATIC and ZoneObject:isExist()) then
|
||||
local CoalitionDCSUnit = ZoneObject:getCoalition()
|
||||
self.ScanData.Coalitions[CoalitionDCSUnit] = true
|
||||
self.ScanData.Units[ZoneObject] = ZoneObject
|
||||
self:F2( { Name = ZoneObject:getName(), Coalition = CoalitionDCSUnit } )
|
||||
local Include = false
|
||||
if not UnitCategories then
|
||||
Include = true
|
||||
else
|
||||
local CategoryDCSUnit = ZoneObject:getDesc().category
|
||||
for UnitCategoryID, UnitCategory in pairs( UnitCategories ) do
|
||||
if UnitCategory == CategoryDCSUnit then
|
||||
Include = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if Include then
|
||||
local CoalitionDCSUnit = ZoneObject:getCoalition()
|
||||
self.ScanData.Coalitions[CoalitionDCSUnit] = true
|
||||
self.ScanData.Units[ZoneObject] = ZoneObject
|
||||
self:F2( { Name = ZoneObject:getName(), Coalition = CoalitionDCSUnit } )
|
||||
end
|
||||
end
|
||||
if ObjectCategory == Object.Category.SCENERY then
|
||||
local SceneryType = ZoneObject:getTypeName()
|
||||
@@ -686,6 +731,31 @@ function ZONE_RADIUS:GetScannedUnits()
|
||||
end
|
||||
|
||||
|
||||
function ZONE_RADIUS:GetScannedSetUnit()
|
||||
|
||||
local SetUnit = SET_UNIT:New()
|
||||
|
||||
if self.ScanData then
|
||||
for ObjectID, UnitObject in pairs( self.ScanData.Units ) do
|
||||
local UnitObject = UnitObject -- DCS#Unit
|
||||
if UnitObject:isExist() then
|
||||
local FoundUnit = UNIT:FindByName( UnitObject:getName() )
|
||||
if FoundUnit then
|
||||
SetUnit:AddUnit( FoundUnit )
|
||||
else
|
||||
local FoundStatic = STATIC:FindByName( UnitObject:getName() )
|
||||
if FoundStatic then
|
||||
SetUnit:AddUnit( FoundStatic )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return SetUnit
|
||||
end
|
||||
|
||||
|
||||
function ZONE_RADIUS:CountScannedCoalitions()
|
||||
|
||||
local Count = 0
|
||||
@@ -1323,7 +1393,7 @@ end
|
||||
function ZONE_POLYGON_BASE:Flush()
|
||||
self:F2()
|
||||
|
||||
self:E( { Polygon = self.ZoneName, Coordinates = self._.Polygon } )
|
||||
self:F( { Polygon = self.ZoneName, Coordinates = self._.Polygon } )
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -1380,16 +1450,15 @@ end
|
||||
--- Smokes the zone boundaries in a color.
|
||||
-- @param #ZONE_POLYGON_BASE self
|
||||
-- @param Utilities.Utils#SMOKECOLOR SmokeColor The smoke color.
|
||||
-- @param #number Segments (Optional) Number of segments within boundary line. Default 10.
|
||||
-- @return #ZONE_POLYGON_BASE self
|
||||
function ZONE_POLYGON_BASE:SmokeZone( SmokeColor )
|
||||
function ZONE_POLYGON_BASE:SmokeZone( SmokeColor, Segments )
|
||||
self:F2( SmokeColor )
|
||||
|
||||
local i
|
||||
local j
|
||||
local Segments = 10
|
||||
Segments=Segments or 10
|
||||
|
||||
i = 1
|
||||
j = #self._.Polygon
|
||||
local i=1
|
||||
local j=#self._.Polygon
|
||||
|
||||
while i <= #self._.Polygon do
|
||||
self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } )
|
||||
@@ -1410,6 +1479,42 @@ function ZONE_POLYGON_BASE:SmokeZone( SmokeColor )
|
||||
end
|
||||
|
||||
|
||||
--- Flare the zone boundaries in a color.
|
||||
-- @param #ZONE_POLYGON_BASE self
|
||||
-- @param Utilities.Utils#FLARECOLOR FlareColor The flare color.
|
||||
-- @param #number Segments (Optional) Number of segments within boundary line. Default 10.
|
||||
-- @param DCS#Azimuth Azimuth (optional) Azimuth The azimuth of the flare.
|
||||
-- @param #number AddHeight (optional) The height to be added for the smoke.
|
||||
-- @return #ZONE_POLYGON_BASE self
|
||||
function ZONE_POLYGON_BASE:FlareZone( FlareColor, Segments, Azimuth, AddHeight )
|
||||
self:F2(FlareColor)
|
||||
|
||||
Segments=Segments or 10
|
||||
|
||||
AddHeight = AddHeight or 0
|
||||
|
||||
local i=1
|
||||
local j=#self._.Polygon
|
||||
|
||||
while i <= #self._.Polygon do
|
||||
self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } )
|
||||
|
||||
local DeltaX = self._.Polygon[j].x - self._.Polygon[i].x
|
||||
local DeltaY = self._.Polygon[j].y - self._.Polygon[i].y
|
||||
|
||||
for Segment = 0, Segments do -- We divide each line in 5 segments and smoke a point on the line.
|
||||
local PointX = self._.Polygon[i].x + ( Segment * DeltaX / Segments )
|
||||
local PointY = self._.Polygon[i].y + ( Segment * DeltaY / Segments )
|
||||
POINT_VEC2:New( PointX, PointY, AddHeight ):Flare(FlareColor, Azimuth)
|
||||
end
|
||||
j = i
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns if a location is within the zone.
|
||||
|
||||
203
Moose Development/Moose/Core/Zone_Detection.lua
Normal file
203
Moose Development/Moose/Core/Zone_Detection.lua
Normal file
@@ -0,0 +1,203 @@
|
||||
|
||||
--- The ZONE_DETECTION class, defined by a zone name, a detection object and a radius.
|
||||
-- @type ZONE_DETECTION
|
||||
-- @field DCS#Vec2 Vec2 The current location of the zone.
|
||||
-- @field DCS#Distance Radius The radius of the zone.
|
||||
-- @extends #ZONE_BASE
|
||||
|
||||
--- The ZONE_DETECTION class defined by a zone name, a location and a radius.
|
||||
-- This class implements the inherited functions from Core.Zone#ZONE_BASE taking into account the own zone format and properties.
|
||||
--
|
||||
-- ## ZONE_DETECTION constructor
|
||||
--
|
||||
-- * @{#ZONE_DETECTION.New}(): Constructor.
|
||||
--
|
||||
-- @field #ZONE_DETECTION
|
||||
ZONE_DETECTION = {
|
||||
ClassName="ZONE_DETECTION",
|
||||
}
|
||||
|
||||
--- Constructor of @{#ZONE_DETECTION}, taking the zone name, the zone location and a radius.
|
||||
-- @param #ZONE_DETECTION self
|
||||
-- @param #string ZoneName Name of the zone.
|
||||
-- @param Functional.Detection#DETECTION_BASE Detection The detection object defining the locations of the central detections.
|
||||
-- @param DCS#Distance Radius The radius around the detections defining the combined zone.
|
||||
-- @return #ZONE_DETECTION self
|
||||
function ZONE_DETECTION:New( ZoneName, Detection, Radius )
|
||||
local self = BASE:Inherit( self, ZONE_BASE:New( ZoneName ) ) -- #ZONE_DETECTION
|
||||
self:F( { ZoneName, Detection, Radius } )
|
||||
|
||||
self.Detection = Detection
|
||||
self.Radius = Radius
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Bounds the zone with tires.
|
||||
-- @param #ZONE_DETECTION self
|
||||
-- @param #number Points (optional) The amount of points in the circle. Default 360.
|
||||
-- @param DCS#country.id CountryID The country id of the tire objects, e.g. country.id.USA for blue or country.id.RUSSIA for red.
|
||||
-- @param #boolean UnBound (Optional) If true the tyres will be destroyed.
|
||||
-- @return #ZONE_DETECTION self
|
||||
function ZONE_DETECTION:BoundZone( Points, CountryID, UnBound )
|
||||
|
||||
local Point = {}
|
||||
local Vec2 = self:GetVec2()
|
||||
|
||||
Points = Points and Points or 360
|
||||
|
||||
local Angle
|
||||
local RadialBase = math.pi*2
|
||||
|
||||
--
|
||||
for Angle = 0, 360, (360 / Points ) do
|
||||
local Radial = Angle * RadialBase / 360
|
||||
Point.x = Vec2.x + math.cos( Radial ) * self:GetRadius()
|
||||
Point.y = Vec2.y + math.sin( Radial ) * self:GetRadius()
|
||||
|
||||
local CountryName = _DATABASE.COUNTRY_NAME[CountryID]
|
||||
|
||||
local Tire = {
|
||||
["country"] = CountryName,
|
||||
["category"] = "Fortifications",
|
||||
["canCargo"] = false,
|
||||
["shape_name"] = "H-tyre_B_WF",
|
||||
["type"] = "Black_Tyre_WF",
|
||||
--["unitId"] = Angle + 10000,
|
||||
["y"] = Point.y,
|
||||
["x"] = Point.x,
|
||||
["name"] = string.format( "%s-Tire #%0d", self:GetName(), Angle ),
|
||||
["heading"] = 0,
|
||||
} -- end of ["group"]
|
||||
|
||||
local Group = coalition.addStaticObject( CountryID, Tire )
|
||||
if UnBound and UnBound == true then
|
||||
Group:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Smokes the zone boundaries in a color.
|
||||
-- @param #ZONE_DETECTION self
|
||||
-- @param Utilities.Utils#SMOKECOLOR SmokeColor The smoke color.
|
||||
-- @param #number Points (optional) The amount of points in the circle.
|
||||
-- @param #number AddHeight (optional) The height to be added for the smoke.
|
||||
-- @param #number AddOffSet (optional) The angle to be added for the smoking start position.
|
||||
-- @return #ZONE_DETECTION self
|
||||
function ZONE_DETECTION:SmokeZone( SmokeColor, Points, AddHeight, AngleOffset )
|
||||
self:F2( SmokeColor )
|
||||
|
||||
local Point = {}
|
||||
local Vec2 = self:GetVec2()
|
||||
|
||||
AddHeight = AddHeight or 0
|
||||
AngleOffset = AngleOffset or 0
|
||||
|
||||
Points = Points and Points or 360
|
||||
|
||||
local Angle
|
||||
local RadialBase = math.pi*2
|
||||
|
||||
for Angle = 0, 360, 360 / Points do
|
||||
local Radial = ( Angle + AngleOffset ) * RadialBase / 360
|
||||
Point.x = Vec2.x + math.cos( Radial ) * self:GetRadius()
|
||||
Point.y = Vec2.y + math.sin( Radial ) * self:GetRadius()
|
||||
POINT_VEC2:New( Point.x, Point.y, AddHeight ):Smoke( SmokeColor )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Flares the zone boundaries in a color.
|
||||
-- @param #ZONE_DETECTION self
|
||||
-- @param Utilities.Utils#FLARECOLOR FlareColor The flare color.
|
||||
-- @param #number Points (optional) The amount of points in the circle.
|
||||
-- @param DCS#Azimuth Azimuth (optional) Azimuth The azimuth of the flare.
|
||||
-- @param #number AddHeight (optional) The height to be added for the smoke.
|
||||
-- @return #ZONE_DETECTION self
|
||||
function ZONE_DETECTION:FlareZone( FlareColor, Points, Azimuth, AddHeight )
|
||||
self:F2( { FlareColor, Azimuth } )
|
||||
|
||||
local Point = {}
|
||||
local Vec2 = self:GetVec2()
|
||||
|
||||
AddHeight = AddHeight or 0
|
||||
|
||||
Points = Points and Points or 360
|
||||
|
||||
local Angle
|
||||
local RadialBase = math.pi*2
|
||||
|
||||
for Angle = 0, 360, 360 / Points do
|
||||
local Radial = Angle * RadialBase / 360
|
||||
Point.x = Vec2.x + math.cos( Radial ) * self:GetRadius()
|
||||
Point.y = Vec2.y + math.sin( Radial ) * self:GetRadius()
|
||||
POINT_VEC2:New( Point.x, Point.y, AddHeight ):Flare( FlareColor, Azimuth )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Returns the radius around the detected locations defining the combine zone.
|
||||
-- @param #ZONE_DETECTION self
|
||||
-- @return DCS#Distance The radius.
|
||||
function ZONE_DETECTION:GetRadius()
|
||||
self:F2( self.ZoneName )
|
||||
|
||||
self:T2( { self.Radius } )
|
||||
|
||||
return self.Radius
|
||||
end
|
||||
|
||||
--- Sets the radius around the detected locations defining the combine zone.
|
||||
-- @param #ZONE_DETECTION self
|
||||
-- @param DCS#Distance Radius The radius.
|
||||
-- @return #ZONE_DETECTION self
|
||||
function ZONE_DETECTION:SetRadius( Radius )
|
||||
self:F2( self.ZoneName )
|
||||
|
||||
self.Radius = Radius
|
||||
self:T2( { self.Radius } )
|
||||
|
||||
return self.Radius
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Returns if a location is within the zone.
|
||||
-- @param #ZONE_DETECTION self
|
||||
-- @param DCS#Vec2 Vec2 The location to test.
|
||||
-- @return #boolean true if the location is within the zone.
|
||||
function ZONE_DETECTION:IsVec2InZone( Vec2 )
|
||||
self:F2( Vec2 )
|
||||
|
||||
local Coordinates = self.Detection:GetDetectedItemCoordinates() -- This returns a list of coordinates that define the (central) locations of the detections.
|
||||
|
||||
for CoordinateID, Coordinate in pairs( Coordinates ) do
|
||||
local ZoneVec2 = Coordinate:GetVec2()
|
||||
if ZoneVec2 then
|
||||
if (( Vec2.x - ZoneVec2.x )^2 + ( Vec2.y - ZoneVec2.y ) ^2 ) ^ 0.5 <= self:GetRadius() then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--- Returns if a point is within the zone.
|
||||
-- @param #ZONE_DETECTION self
|
||||
-- @param DCS#Vec3 Vec3 The point to test.
|
||||
-- @return #boolean true if the point is within the zone.
|
||||
function ZONE_DETECTION:IsVec3InZone( Vec3 )
|
||||
self:F2( Vec3 )
|
||||
|
||||
local InZone = self:IsVec2InZone( { x = Vec3.x, y = Vec3.z } )
|
||||
|
||||
return InZone
|
||||
end
|
||||
|
||||
@@ -430,6 +430,8 @@ do -- Types
|
||||
|
||||
end --
|
||||
|
||||
|
||||
|
||||
do -- Object
|
||||
|
||||
--- [DCS Class Object](https://wiki.hoggitworld.com/view/DCS_Class_Object)
|
||||
@@ -527,6 +529,126 @@ do -- CoalitionObject
|
||||
end -- CoalitionObject
|
||||
|
||||
|
||||
do -- Weapon
|
||||
|
||||
--- [DCS Class Weapon](https://wiki.hoggitworld.com/view/DCS_Class_Weapon)
|
||||
-- @type Weapon
|
||||
-- @extends #CoalitionObject
|
||||
-- @field #Weapon.flag flag enum stores weapon flags. Some of them are combination of another flags.
|
||||
-- @field #Weapon.Category Category enum that stores weapon categories.
|
||||
-- @field #Weapon.GuidanceType GuidanceType enum that stores guidance methods. Available only for guided weapon (Weapon.Category.MISSILE and some Weapon.Category.BOMB).
|
||||
-- @field #Weapon.MissileCategory MissileCategory enum that stores missile category. Available only for missiles (Weapon.Category.MISSILE).
|
||||
-- @field #Weapon.WarheadType WarheadType enum that stores warhead types.
|
||||
-- @field #Weapon.Desc Desc The descriptor of a weapon.
|
||||
|
||||
--- enum stores weapon flags. Some of them are combination of another flags.
|
||||
-- @type Weapon.flag
|
||||
-- @field LGB
|
||||
-- @field TvGB
|
||||
-- @field SNSGB
|
||||
-- @field HEBomb
|
||||
-- @field Penetrator
|
||||
-- @field NapalmBomb
|
||||
-- @field FAEBomb
|
||||
-- @field ClusterBomb
|
||||
-- @field Dispencer
|
||||
-- @field CandleBomb
|
||||
-- @field ParachuteBomb
|
||||
-- @field GuidedBomb = LGB + TvGB + SNSGB
|
||||
-- @field AnyUnguidedBomb = HEBomb + Penetrator + NapalmBomb + FAEBomb + ClusterBomb + Dispencer + CandleBomb + ParachuteBomb
|
||||
-- @field AnyBomb = GuidedBomb + AnyUnguidedBomb
|
||||
-- @field LightRocket
|
||||
-- @field MarkerRocket
|
||||
-- @field CandleRocket
|
||||
-- @field HeavyRocket
|
||||
-- @field AnyRocket = LightRocket + HeavyRocket + MarkerRocket + CandleRocket
|
||||
-- @field AntiRadarMissile
|
||||
-- @field AntiShipMissile
|
||||
-- @field AntiTankMissile
|
||||
-- @field FireAndForgetASM
|
||||
-- @field LaserASM
|
||||
-- @field TeleASM
|
||||
-- @field CruiseMissile
|
||||
-- @field GuidedASM = LaserASM + TeleASM
|
||||
-- @field TacticASM = GuidedASM + FireAndForgetASM
|
||||
-- @field AnyASM = AntiRadarMissile + AntiShipMissile + AntiTankMissile + FireAndForgetASM + GuidedASM + CruiseMissile
|
||||
-- @field SRAAM
|
||||
-- @field MRAAM
|
||||
-- @field LRAAM
|
||||
-- @field IR_AAM
|
||||
-- @field SAR_AAM
|
||||
-- @field AR_AAM
|
||||
-- @field AnyAAM = IR_AAM + SAR_AAM + AR_AAM + SRAAM + MRAAM + LRAAM
|
||||
-- @field AnyMissile = AnyASM + AnyAAM
|
||||
-- @field AnyAutonomousMissile = IR_AAM + AntiRadarMissile + AntiShipMissile + FireAndForgetASM + CruiseMissile
|
||||
-- @field GUN_POD
|
||||
-- @field BuiltInCannon
|
||||
-- @field Cannons = GUN_POD + BuiltInCannon
|
||||
-- @field AnyAGWeapon = BuiltInCannon + GUN_POD + AnyBomb + AnyRocket + AnyASM
|
||||
-- @field AnyAAWeapon = BuiltInCannon + GUN_POD + AnyAAM
|
||||
-- @field UnguidedWeapon = Cannons + BuiltInCannon + GUN_POD + AnyUnguidedBomb + AnyRocket
|
||||
-- @field GuidedWeapon = GuidedBomb + AnyASM + AnyAAM
|
||||
-- @field AnyWeapon = AnyBomb + AnyRocket + AnyMissile + Cannons
|
||||
-- @field MarkerWeapon = MarkerRocket + CandleRocket + CandleBomb
|
||||
-- @field ArmWeapon = AnyWeapon - MarkerWeapon
|
||||
|
||||
--- Weapon.Category enum that stores weapon categories.
|
||||
-- @type Weapon.Category
|
||||
-- @field SHELL
|
||||
-- @field MISSILE
|
||||
-- @field ROCKET
|
||||
-- @field BOMB
|
||||
|
||||
|
||||
--- Weapon.GuidanceType enum that stores guidance methods. Available only for guided weapon (Weapon.Category.MISSILE and some Weapon.Category.BOMB).
|
||||
-- @type Weapon.GuidanceType
|
||||
-- @field INS
|
||||
-- @field IR
|
||||
-- @field RADAR_ACTIVE
|
||||
-- @field RADAR_SEMI_ACTIVE
|
||||
-- @field RADAR_PASSIVE
|
||||
-- @field TV
|
||||
-- @field LASER
|
||||
-- @field TELE
|
||||
|
||||
|
||||
--- Weapon.MissileCategory enum that stores missile category. Available only for missiles (Weapon.Category.MISSILE).
|
||||
-- @type Weapon.MissileCategory
|
||||
-- @field AAM
|
||||
-- @field SAM
|
||||
-- @field BM
|
||||
-- @field ANTI_SHIP
|
||||
-- @field CRUISE
|
||||
-- @field OTHER
|
||||
|
||||
--- Weapon.WarheadType enum that stores warhead types.
|
||||
-- @type Weapon.WarheadType
|
||||
-- @field AP
|
||||
-- @field HE
|
||||
-- @field SHAPED_EXPLOSIVE
|
||||
|
||||
--- Returns the unit that launched the weapon.
|
||||
-- @function [parent=#Weapon] getLauncher
|
||||
-- @param #Weapon self
|
||||
-- @return #Unit
|
||||
|
||||
--- returns target of the guided weapon. Unguided weapons and guided weapon that is targeted at the point on the ground will return nil.
|
||||
-- @function [parent=#Weapon] getTarget
|
||||
-- @param #Weapon self
|
||||
-- @return #Object
|
||||
|
||||
--- returns weapon descriptor. Descriptor type depends on weapon category.
|
||||
-- @function [parent=#Weapon] getDesc
|
||||
-- @param #Weapon self
|
||||
-- @return #Weapon.Desc
|
||||
|
||||
|
||||
|
||||
Weapon = {} --#Weapon
|
||||
|
||||
end -- Weapon
|
||||
|
||||
|
||||
do -- Airbase
|
||||
|
||||
--- [DCS Class Airbase](https://wiki.hoggitworld.com/view/DCS_Class_Airbase)
|
||||
@@ -1196,7 +1318,4 @@ do -- AI
|
||||
|
||||
AI = {} --#AI
|
||||
|
||||
end -- AI
|
||||
|
||||
|
||||
|
||||
end -- AI
|
||||
@@ -125,6 +125,7 @@ end
|
||||
-- Atc_Ground = ATC_GROUND_CAUCAUS:New()
|
||||
-- Atc_Ground = ATC_GROUND_NEVADA:New()
|
||||
-- Atc_Ground = ATC_GROUND_NORMANDY:New()
|
||||
-- Atc_Ground = ATC_GROUND_PERSIANGULF:New()
|
||||
--
|
||||
-- -- Then use one of these methods...
|
||||
--
|
||||
@@ -190,6 +191,7 @@ end
|
||||
-- Atc_Ground = ATC_GROUND_CAUCAUS:New()
|
||||
-- Atc_Ground = ATC_GROUND_NEVADA:New()
|
||||
-- Atc_Ground = ATC_GROUND_NORMANDY:New()
|
||||
-- Atc_Ground = ATC_GROUND_PERSIANGULF:New()
|
||||
--
|
||||
-- -- Then use one of these methods...
|
||||
--
|
||||
@@ -273,7 +275,7 @@ function ATC_GROUND:_AirbaseMonitor()
|
||||
self:E( Taxi )
|
||||
if Taxi == false then
|
||||
local Velocity = VELOCITY:New( AirbaseMeta.KickSpeed or self.KickSpeed )
|
||||
Client:Message( "Welcome at " .. AirbaseID .. ". The maximum taxiing speed is " ..
|
||||
Client:Message( "Welcome to " .. AirbaseID .. ". The maximum taxiing speed is " ..
|
||||
Velocity:ToString() , 20, "ATC" )
|
||||
Client:SetState( self, "Taxi", true )
|
||||
end
|
||||
@@ -297,7 +299,7 @@ function ATC_GROUND:_AirbaseMonitor()
|
||||
end
|
||||
if Speeding == true then
|
||||
MESSAGE:New( "Penalty! Player " .. Client:GetPlayerName() ..
|
||||
" is kicked, due to a severe airbase traffic rule violation ...", 10, "ATC" ):ToAll()
|
||||
" has been kicked, due to a severe airbase traffic rule violation ...", 10, "ATC" ):ToAll()
|
||||
Client:Destroy()
|
||||
Client:SetState( self, "Speeding", false )
|
||||
Client:SetState( self, "Warnings", 0 )
|
||||
@@ -329,7 +331,7 @@ function ATC_GROUND:_AirbaseMonitor()
|
||||
Velocity:ToString(), 5, "ATC" )
|
||||
Client:SetState( self, "Warnings", SpeedingWarnings + 1 )
|
||||
else
|
||||
MESSAGE:New( "Penalty! Player " .. Client:GetPlayerName() .. " is kicked, due to a severe airbase traffic rule violation ...", 10, "ATC" ):ToAll()
|
||||
MESSAGE:New( "Penalty! Player " .. Client:GetPlayerName() .. " has been kicked, due to a severe airbase traffic rule violation ...", 10, "ATC" ):ToAll()
|
||||
--- @param Wrapper.Client#CLIENT Client
|
||||
Client:Destroy()
|
||||
Client:SetState( self, "Speeding", false )
|
||||
@@ -361,7 +363,7 @@ function ATC_GROUND:_AirbaseMonitor()
|
||||
Client:Message( "Warning " .. OffRunwayWarnings .. "/3! Airbase traffic rule violation! Get back on the taxi immediately!", 5, "ATC" )
|
||||
Client:SetState( self, "OffRunwayWarnings", OffRunwayWarnings + 1 )
|
||||
else
|
||||
MESSAGE:New( "Penalty! Player " .. Client:GetPlayerName() .. " is kicked, due to a severe airbase traffic rule violation ...", 10, "ATC" ):ToAll()
|
||||
MESSAGE:New( "Penalty! Player " .. Client:GetPlayerName() .. " has been kicked, due to a severe airbase traffic rule violation ...", 10, "ATC" ):ToAll()
|
||||
--- @param Wrapper.Client#CLIENT Client
|
||||
Client:Destroy()
|
||||
Client:SetState( self, "IsOffRunway", false )
|
||||
@@ -786,8 +788,6 @@ function ATC_GROUND_CAUCASUS:New( AirbaseNames )
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, ATC_GROUND:New( self.Airbases, AirbaseNames ) )
|
||||
|
||||
self.AirbaseMonitor = SCHEDULER:New( self, self._AirbaseMonitor, { self }, 0, 2, 0.05 )
|
||||
|
||||
self:SetKickSpeedKmph( 50 )
|
||||
self:SetMaximumKickSpeedKmph( 150 )
|
||||
|
||||
@@ -1000,6 +1000,15 @@ function ATC_GROUND_CAUCASUS:New( AirbaseNames )
|
||||
end
|
||||
|
||||
|
||||
--- Start SCHEDULER for ATC_GROUND_CAUCASUS object.
|
||||
-- @param #ATC_GROUND_CAUCASUS self
|
||||
-- @param RepeatScanSeconds Time in second for defining occurency of alerts.
|
||||
-- @return nothing
|
||||
function ATC_GROUND_CAUCASUS:Start( RepeatScanSeconds )
|
||||
RepeatScanSeconds = RepeatScanSeconds or 0.05
|
||||
self.AirbaseMonitor = SCHEDULER:New( self, self._AirbaseMonitor, { self }, 0, 2, RepeatScanSeconds )
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- @type ATC_GROUND_NEVADA
|
||||
@@ -1377,8 +1386,6 @@ function ATC_GROUND_NEVADA:New( AirbaseNames )
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, ATC_GROUND:New( self.Airbases, AirbaseNames ) )
|
||||
|
||||
self.AirbaseMonitor = SCHEDULER:New( self, self._AirbaseMonitor, { self }, 0, 2, 0.05 )
|
||||
|
||||
self:SetKickSpeedKmph( 50 )
|
||||
self:SetMaximumKickSpeedKmph( 150 )
|
||||
|
||||
@@ -1542,6 +1549,16 @@ function ATC_GROUND_NEVADA:New( AirbaseNames )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Start SCHEDULER for ATC_GROUND_NEVADA object.
|
||||
-- @param #ATC_GROUND_NEVADA self
|
||||
-- @param RepeatScanSeconds Time in second for defining occurency of alerts.
|
||||
-- @return nothing
|
||||
function ATC_GROUND_NEVADA:Start( RepeatScanSeconds )
|
||||
RepeatScanSeconds = RepeatScanSeconds or 0.05
|
||||
self.AirbaseMonitor = SCHEDULER:New( self, self._AirbaseMonitor, { self }, 0, 2, RepeatScanSeconds )
|
||||
end
|
||||
|
||||
|
||||
--- @type ATC_GROUND_NORMANDY
|
||||
-- @extends #ATC_GROUND
|
||||
|
||||
@@ -1557,7 +1574,7 @@ end
|
||||
--
|
||||
-- ---
|
||||
--
|
||||
-- The default maximum speed for the airbases at Caucasus is **40 km/h**. Warnings are given if this speed limit is trespassed.
|
||||
-- The default maximum speed for the airbases at Normandy is **40 km/h**. Warnings are given if this speed limit is trespassed.
|
||||
-- Players will be immediately kicked when driving faster than **100 km/h** on the taxi way.
|
||||
--
|
||||
-- The ATC\_GROUND\_NORMANDY class monitors the speed of the airplanes at the airbase during taxi.
|
||||
@@ -2031,8 +2048,6 @@ function ATC_GROUND_NORMANDY:New( AirbaseNames )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, ATC_GROUND:New( self.Airbases, AirbaseNames ) ) -- #ATC_GROUND_NORMANDY
|
||||
|
||||
self.AirbaseMonitor = SCHEDULER:New( self, self._AirbaseMonitor, { self }, 0, 2, 0.05 )
|
||||
|
||||
self:SetKickSpeedKmph( 40 )
|
||||
self:SetMaximumKickSpeedKmph( 100 )
|
||||
@@ -2316,6 +2331,856 @@ function ATC_GROUND_NORMANDY:New( AirbaseNames )
|
||||
end
|
||||
|
||||
|
||||
--- Start SCHEDULER for ATC_GROUND_NORMANDY object.
|
||||
-- @param #ATC_GROUND_NORMANDY self
|
||||
-- @param RepeatScanSeconds Time in second for defining occurency of alerts.
|
||||
-- @return nothing
|
||||
function ATC_GROUND_NORMANDY:Start( RepeatScanSeconds )
|
||||
RepeatScanSeconds = RepeatScanSeconds or 0.05
|
||||
self.AirbaseMonitor = SCHEDULER:New( self, self._AirbaseMonitor, { self }, 0, 2, RepeatScanSeconds )
|
||||
end
|
||||
|
||||
--- @type ATC_GROUND_PERSIANGULF
|
||||
-- @extends #ATC_GROUND
|
||||
|
||||
|
||||
--- # ATC\_GROUND\_PERSIANGULF, extends @{#ATC_GROUND}
|
||||
--
|
||||
-- The ATC\_GROUND\_PERSIANGULF class monitors the speed of the airplanes at the airbase during taxi.
|
||||
-- The pilots may not drive faster than the maximum speed for the airbase, or they will be despawned.
|
||||
--
|
||||
-- ---
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- ---
|
||||
--
|
||||
-- The default maximum speed for the airbases at Persian Gulf is **50 km/h**. Warnings are given if this speed limit is trespassed.
|
||||
-- Players will be immediately kicked when driving faster than **150 km/h** on the taxi way.
|
||||
--
|
||||
-- The ATC\_GROUND\_PERSIANGULF class monitors the speed of the airplanes at the airbase during taxi.
|
||||
-- The pilots may not drive faster than the maximum speed for the airbase, or they will be despawned.
|
||||
--
|
||||
-- The pilot will receive 3 times a warning during speeding. After the 3rd warning, if the pilot is still driving
|
||||
-- faster than the maximum allowed speed, the pilot will be kicked.
|
||||
--
|
||||
-- Different airbases have different maximum speeds, according safety regulations.
|
||||
--
|
||||
-- # Airbases monitored
|
||||
--
|
||||
-- The following airbases are monitored at the PersianGulf region.
|
||||
-- Use the @{Wrapper.Airbase#AIRBASE.PersianGulf} enumeration to select the airbases to be monitored.
|
||||
--
|
||||
-- * `AIRBASE.PersianGulf.Abu_Musa_Island_Airport`
|
||||
-- * `AIRBASE.PersianGulf.Al_Dhafra_AB`
|
||||
-- * `AIRBASE.PersianGulf.Al_Maktoum_Intl`
|
||||
-- * `AIRBASE.PersianGulf.Al_Minhad_AB`
|
||||
-- * `AIRBASE.PersianGulf.Bandar_Abbas_Intl`
|
||||
-- * `AIRBASE.PersianGulf.Bandar_Lengeh`
|
||||
-- * `AIRBASE.PersianGulf.Dubai_Intl`
|
||||
-- * `AIRBASE.PersianGulf.Fujairah_Intl`
|
||||
-- * `AIRBASE.PersianGulf.Havadarya`
|
||||
-- * `AIRBASE.PersianGulf.Kerman_Airport`
|
||||
-- * `AIRBASE.PersianGulf.Khasab`
|
||||
-- * `AIRBASE.PersianGulf.Lar_Airbase`
|
||||
-- * `AIRBASE.PersianGulf.Qeshm_Island`
|
||||
-- * `AIRBASE.PersianGulf.Sharjah_Intl`
|
||||
-- * `AIRBASE.PersianGulf.Shiraz_International_Airport`
|
||||
-- * `AIRBASE.PersianGulf.Sir_Abu_Nuayr`
|
||||
-- * `AIRBASE.PersianGulf.Sirri_Island`
|
||||
-- * `AIRBASE.PersianGulf.Tunb_Island_AFB`
|
||||
-- * `AIRBASE.PersianGulf.Tunb_Kochak`
|
||||
-- * `AIRBASE.PersianGulf.Sas_Al_Nakheel_Airport`
|
||||
-- * `AIRBASE.PersianGulf.Bandar_e_Jask_airfield`
|
||||
-- * `AIRBASE.PersianGulf.Abu_Dhabi_International_Airport`
|
||||
-- * `AIRBASE.PersianGulf.Al_Bateen_Airport`
|
||||
-- * `AIRBASE.PersianGulf.Kish_International_Airport`
|
||||
-- * `AIRBASE.PersianGulf.Al_Ain_International_Airport`
|
||||
-- * `AIRBASE.PersianGulf.Lavan_Island_Airport`
|
||||
-- * `AIRBASE.PersianGulf.Jiroft_Airport`
|
||||
--
|
||||
-- # Installation
|
||||
--
|
||||
-- ## In Single Player Missions
|
||||
--
|
||||
-- ATC\_GROUND is fully functional in single player.
|
||||
--
|
||||
-- ## In Multi Player Missions
|
||||
--
|
||||
-- ATC\_GROUND is functional in multi player, however ...
|
||||
--
|
||||
-- Due to a bug in DCS since release 1.5, the despawning of clients are not anymore working in multi player.
|
||||
-- To **work around this problem**, a much better solution has been made, using the **slot blocker** script designed
|
||||
-- by Ciribob.
|
||||
--
|
||||
-- With the help of __Ciribob__, this script has been extended to also kick client players while in flight.
|
||||
-- ATC\_GROUND is communicating with this modified script to kick players!
|
||||
--
|
||||
-- Install the file **SimpleSlotBlockGameGUI.lua** on the server, following the installation instructions described by Ciribob.
|
||||
--
|
||||
-- [Simple Slot Blocker from Ciribob & FlightControl](https://github.com/ciribob/DCS-SimpleSlotBlock)
|
||||
--
|
||||
-- # Script it!
|
||||
--
|
||||
-- ## 1. ATC_GROUND_PERSIANGULF Constructor
|
||||
--
|
||||
-- Creates a new ATC_GROUND_PERSIANGULF object that will monitor pilots taxiing behaviour.
|
||||
--
|
||||
-- -- This creates a new ATC_GROUND_PERSIANGULF object.
|
||||
--
|
||||
-- -- Monitor for these clients the airbases.
|
||||
-- AirbasePoliceCaucasus = ATC_GROUND_PERSIANGULF:New()
|
||||
--
|
||||
-- ATC_Ground = ATC_GROUND_PERSIANGULF:New(
|
||||
-- { AIRBASE.PersianGulf.Kerman_Airport,
|
||||
-- AIRBASE.PersianGulf.Al_Minhad_AB
|
||||
-- }
|
||||
-- )
|
||||
--
|
||||
--
|
||||
-- ## 2. Set various options
|
||||
--
|
||||
-- There are various methods that you can use to tweak the behaviour of the ATC\_GROUND classes.
|
||||
--
|
||||
-- ### 2.1 Speed limit at an airbase.
|
||||
--
|
||||
-- * @{#ATC_GROUND.SetKickSpeed}(): Set the speed limit allowed at an airbase in meters per second.
|
||||
-- * @{#ATC_GROUND.SetKickSpeedKmph}(): Set the speed limit allowed at an airbase in kilometers per hour.
|
||||
-- * @{#ATC_GROUND.SetKickSpeedMiph}(): Set the speed limit allowed at an airbase in miles per hour.
|
||||
--
|
||||
-- ### 2.2 Prevent Takeoff at an airbase. Players will be kicked immediately.
|
||||
--
|
||||
-- * @{#ATC_GROUND.SetMaximumKickSpeed}(): Set the maximum speed allowed at an airbase in meters per second.
|
||||
-- * @{#ATC_GROUND.SetMaximumKickSpeedKmph}(): Set the maximum speed allowed at an airbase in kilometers per hour.
|
||||
-- * @{#ATC_GROUND.SetMaximumKickSpeedMiph}(): Set the maximum speed allowed at an airbase in miles per hour.
|
||||
--
|
||||
-- @field #ATC_GROUND_PERSIANGULF
|
||||
ATC_GROUND_PERSIANGULF = {
|
||||
ClassName = "ATC_GROUND_PERSIANGULF",
|
||||
Airbases = {
|
||||
[AIRBASE.PersianGulf.Abu_Musa_Island_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-122813.71002344,["x"]=-31689.936027827,},
|
||||
[2]={["y"]=-122827.82488722,["x"]=-31590.105445836,},
|
||||
[3]={["y"]=-122769.5689949,["x"]=-31583.176330891,},
|
||||
[4]={["y"]=-122726.96776968,["x"]=-31614.998932862,},
|
||||
[5]={["y"]=-121293.92414543,["x"]=-31467.947715689,},
|
||||
[6]={["y"]=-121296.4904843,["x"]=-31432.018971528,},
|
||||
[7]={["y"]=-121236.18152088,["x"]=-31424.576588809,},
|
||||
[8]={["y"]=-121190.50068902,["x"]=-31458.452261875,},
|
||||
[9]={["y"]=-119839.83654246,["x"]=-31319.356695194,},
|
||||
[10]={["y"]=-119824.69514313,["x"]=-31423.293419374,},
|
||||
[11]={["y"]=-119886.80054375,["x"]=-31430.22253432,},
|
||||
[12]={["y"]=-119932.22474173,["x"]=-31395.320325706,},
|
||||
[13]={["y"]=-122813.9472789,["x"]=-31689.81193251,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Abu_Musa_Island_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-174672.06004916,["x"]=-209880.97145616,},
|
||||
[2]={["y"]=-174705.15693282,["x"]=-209923.15131918,},
|
||||
[3]={["y"]=-171819.05380065,["x"]=-212172.84298281,},
|
||||
[4]={["y"]=-171785.09826475,["x"]=-212129.87417284,},
|
||||
[5]={["y"]=-174671.96413454,["x"]=-209880.52453983,},
|
||||
},
|
||||
[2] = {
|
||||
[1]={["y"]=-174351.95872272,["x"]=-211813.88516693,},
|
||||
[2]={["y"]=-174381.29169939,["x"]=-211851.81242636,},
|
||||
[3]={["y"]=-171493.65648904,["x"]=-214102.92235002,},
|
||||
[4]={["y"]=-171464.99693831,["x"]=-214062.78788361,},
|
||||
[5]={["y"]=-174351.8628081,["x"]=-211813.4382506,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Al_Maktoum_Intl] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-111879.49046471,["x"]=-138953.80105841,},
|
||||
[2]={["y"]=-111917.23447224,["x"]=-139018.2804046,},
|
||||
[3]={["y"]=-108092.98121312,["x"]=-141406.67838426,},
|
||||
[4]={["y"]=-108052.34416748,["x"]=-141341.82058294,},
|
||||
[5]={["y"]=-111879.5412879,["x"]=-138952.87693763,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Al_Minhad_AB] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-91070.628933035,["x"]=-125989.64095162,},
|
||||
[2]={["y"]=-91072.346560159,["x"]=-126040.59722299,},
|
||||
[3]={["y"]=-87098.282779771,["x"]=-126039.41747017,},
|
||||
[4]={["y"]=-87099.632735396,["x"]=-125991.26905291,},
|
||||
[5]={["y"]=-91071.031270042,["x"]=-125987.44617225,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Bandar_Abbas_Intl] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=12988.484058788,["x"]=113979.99250505,},
|
||||
[2]={["y"]=13037.8836239,["x"]=113952.60241152,},
|
||||
[3]={["y"]=14877.313199902,["x"]=117414.37833333,},
|
||||
[4]={["y"]=14828.777486364,["x"]=117439.06043783,},
|
||||
[5]={["y"]=12988.939584604,["x"]=113979.52494386,},
|
||||
},
|
||||
[2] = {
|
||||
[1]={["y"]=13203.406014284,["x"]=113848.44907555,},
|
||||
[2]={["y"]=13258.268500181,["x"]=113818.47303925,},
|
||||
[3]={["y"]=15315.015323566,["x"]=117694.27156647,},
|
||||
[4]={["y"]=15264.815746383,["x"]=117725.22168173,},
|
||||
[5]={["y"]=13203.861540099,["x"]=113847.98151436,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Bandar_Lengeh] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-142373.15541415,["x"]=41364.94047809,},
|
||||
[2]={["y"]=-142363.30071107,["x"]=41298.112282592,},
|
||||
[3]={["y"]=-142217.57151662,["x"]=41320.35666061,},
|
||||
[4]={["y"]=-142213.00856728,["x"]=41291.838227254,},
|
||||
[5]={["y"]=-142131.44584788,["x"]=41301.534494595,},
|
||||
[6]={["y"]=-142132.58658522,["x"]=41323.778872613,},
|
||||
[7]={["y"]=-142123.17550221,["x"]=41336.041798956,},
|
||||
[8]={["y"]=-139580.45381288,["x"]=41711.022304533,},
|
||||
[9]={["y"]=-139590.04241918,["x"]=41778.350996659,},
|
||||
[10]={["y"]=-139732.41237808,["x"]=41757.089304408,},
|
||||
[11]={["y"]=-139736.7897853,["x"]=41785.646675372,},
|
||||
[12]={["y"]=-139816.41690726,["x"]=41775.641173137,},
|
||||
[13]={["y"]=-139816.00001133,["x"]=41754.58792885,},
|
||||
[14]={["y"]=-139824.1294819,["x"]=41743.748634761,},
|
||||
[15]={["y"]=-142373.20183966,["x"]=41365.161507021,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Dubai_Intl] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-89693.511670714,["x"]=-100490.47082052,},
|
||||
[2]={["y"]=-89731.488328846,["x"]=-100555.50584758,},
|
||||
[3]={["y"]=-85706.437275049,["x"]=-103076.68123933,},
|
||||
[4]={["y"]=-85669.519216262,["x"]=-103010.44994755,},
|
||||
[5]={["y"]=-89693.036962487,["x"]=-100489.9961123,},
|
||||
},
|
||||
[2] = {
|
||||
[1]={["y"]=-90797.505501889,["x"]=-99344.082465487,},
|
||||
[2]={["y"]=-90835.482160021,["x"]=-99409.11749254,},
|
||||
[3]={["y"]=-87210.216900398,["x"]=-101681.72494832,},
|
||||
[4]={["y"]=-87171.474397253,["x"]=-101619.20256393,},
|
||||
[5]={["y"]=-90797.030793662,["x"]=-99343.607757261,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Fujairah_Intl] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=5808.8716147284,["x"]=-116602.15633995,},
|
||||
[2]={["y"]=5781.9885293892,["x"]=-116666.67574476,},
|
||||
[3]={["y"]=9435.1910907931,["x"]=-118192.91910235,},
|
||||
[4]={["y"]=9459.878635843,["x"]=-118134.40047704,},
|
||||
[5]={["y"]=5808.4078522575,["x"]=-116603.31550719,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Havadarya] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-7565.4887830428,["x"]=109074.13162774,},
|
||||
[2]={["y"]=-7557.8281079193,["x"]=109030.65729641,},
|
||||
[3]={["y"]=-4987.3556518085,["x"]=109524.49147773,},
|
||||
[4]={["y"]=-4996.215358578,["x"]=109566.57508489,},
|
||||
[5]={["y"]=-7565.4936338604,["x"]=109074.32262205,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Kerman_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=70375.468628778,["x"]=456046.12685302,},
|
||||
[2]={["y"]=70297.050081575,["x"]=456015.1578105,},
|
||||
[3]={["y"]=71814.291673715,["x"]=452165.51037702,},
|
||||
[4]={["y"]=71902.918622452,["x"]=452188.46411914,},
|
||||
[5]={["y"]=70860.465673482,["x"]=454829.89695989,},
|
||||
[6]={["y"]=70862.525255971,["x"]=454892.77675983,},
|
||||
[7]={["y"]=70816.157465062,["x"]=454922.77944807,},
|
||||
[8]={["y"]=70462.749176371,["x"]=455833.38051827,},
|
||||
[9]={["y"]=70483.400377364,["x"]=455901.17880077,},
|
||||
[10]={["y"]=70453.787334431,["x"]=455974.8217628,},
|
||||
[11]={["y"]=70405.860962315,["x"]=455961.57382254,},
|
||||
[12]={["y"]=70374.689338175,["x"]=456046.51649833,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Khasab] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-534.81827307392,["x"]=-1495.070060483,},
|
||||
[2]={["y"]=-434.82912685139,["x"]=-1519.8421462589,},
|
||||
[3]={["y"]=-405.55302547993,["x"]=-1413.0969766429,},
|
||||
[4]={["y"]=-424.92029254105,["x"]=-1352.0675653224,},
|
||||
[5]={["y"]=216.05735069389,["x"]=1206.9187095195,},
|
||||
[6]={["y"]=116.42961315781,["x"]=1229.9576238247,},
|
||||
[7]={["y"]=88.253643635887,["x"]=1123.7918160128,},
|
||||
[8]={["y"]=101.1741158476,["x"]=1042.6886109249,},
|
||||
[9]={["y"]=-535.31436058928,["x"]=-1494.8762081291,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Lar_Airbase] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-183987.5454359,["x"]=169021.72039309,},
|
||||
[2]={["y"]=-183988.41292374,["x"]=168955.27082471,},
|
||||
[3]={["y"]=-180847.92031188,["x"]=168930.46175795,},
|
||||
[4]={["y"]=-180806.58653731,["x"]=168888.39641215,},
|
||||
[5]={["y"]=-180740.37934087,["x"]=168886.56748407,},
|
||||
[6]={["y"]=-180735.62412787,["x"]=168932.65647164,},
|
||||
[7]={["y"]=-180685.14571291,["x"]=168934.11961411,},
|
||||
[8]={["y"]=-180682.5852136,["x"]=169001.78995301,},
|
||||
[9]={["y"]=-183987.48111493,["x"]=169021.35002828,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Qeshm_Island] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-35140.372717152,["x"]=63373.658918509,},
|
||||
[2]={["y"]=-35098.556715749,["x"]=63320.377239302,},
|
||||
[3]={["y"]=-34991.318905699,["x"]=63408.730403557,},
|
||||
[4]={["y"]=-34984.574389344,["x"]=63401.311435566,},
|
||||
[5]={["y"]=-34991.993357335,["x"]=63313.632722947,},
|
||||
[6]={["y"]=-34956.921872287,["x"]=63265.746656824,},
|
||||
[7]={["y"]=-34917.129225791,["x"]=63261.699947011,},
|
||||
[8]={["y"]=-34832.822771349,["x"]=63337.23853019,},
|
||||
[9]={["y"]=-34915.105870884,["x"]=63436.382920614,},
|
||||
[10]={["y"]=-34906.337999622,["x"]=63478.198922017,},
|
||||
[11]={["y"]=-32728.533668488,["x"]=65307.986209216,},
|
||||
[12]={["y"]=-32676.600892552,["x"]=65299.218337954,},
|
||||
[13]={["y"]=-32623.99366498,["x"]=65334.964274638,},
|
||||
[14]={["y"]=-32626.691471522,["x"]=65388.92040548,},
|
||||
[15]={["y"]=-31822.745121968,["x"]=66067.418750826,},
|
||||
[16]={["y"]=-31777.556862387,["x"]=66068.767654097,},
|
||||
[17]={["y"]=-31691.227053039,["x"]=65974.344425122,},
|
||||
[18]={["y"]=-31606.246146962,["x"]=66042.464040311,},
|
||||
[19]={["y"]=-31602.199437148,["x"]=66084.280041714,},
|
||||
[20]={["y"]=-31632.549760747,["x"]=66124.747139846,},
|
||||
[21]={["y"]=-31727.647441358,["x"]=66134.189462744,},
|
||||
[22]={["y"]=-31734.391957713,["x"]=66141.608430735,},
|
||||
[23]={["y"]=-31632.549760747,["x"]=66225.914885176,},
|
||||
[24]={["y"]=-31673.691310515,["x"]=66277.173209477,},
|
||||
[25]={["y"]=-35140.880825624,["x"]=63373.905965825,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Sharjah_Intl] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-71668.808658476,["x"]=-93980.156242153,},
|
||||
[2]={["y"]=-75307.847363315,["x"]=-91617.097584505,},
|
||||
[3]={["y"]=-75280.458023829,["x"]=-91574.709321014,},
|
||||
[4]={["y"]=-72249.697184234,["x"]=-93529.134331507,},
|
||||
[5]={["y"]=-72179.919581256,["x"]=-93526.199759419,},
|
||||
[6]={["y"]=-72138.183444896,["x"]=-93597.933743788,},
|
||||
[7]={["y"]=-71638.654062835,["x"]=-93927.584008321,},
|
||||
[8]={["y"]=-71668.325847279,["x"]=-93979.428115206,},
|
||||
},
|
||||
[2] = {
|
||||
[1]={["y"]=-71553.225408723,["x"]=-93775.312323319,},
|
||||
[2]={["y"]=-75168.13829548,["x"]=-91426.51571111,},
|
||||
[3]={["y"]=-75125.388157445,["x"]=-91363.754870166,},
|
||||
[4]={["y"]=-71510.511081666,["x"]=-93703.252275385,},
|
||||
[5]={["y"]=-71552.247218027,["x"]=-93775.638386885,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Shiraz_International_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-353995.75579778,["x"]=382327.42294273,},
|
||||
[2]={["y"]=-354029.77009807,["x"]=382265.46199492,},
|
||||
[3]={["y"]=-349407.98049238,["x"]=379941.14030526,},
|
||||
[4]={["y"]=-349376.87025024,["x"]=380004.69408564,},
|
||||
[5]={["y"]=-353995.71101815,["x"]=382327.59771695,},
|
||||
},
|
||||
[2] = {
|
||||
[1]={["y"]=-354056.29510012,["x"]=381845.97598829,},
|
||||
[2]={["y"]=-354091.48797289,["x"]=381783.6025623,},
|
||||
[3]={["y"]=-349650.64038107,["x"]=379550.92898242,},
|
||||
[4]={["y"]=-349624.41889127,["x"]=379614.92719482,},
|
||||
[5]={["y"]=-354056.25032049,["x"]=381846.15076251,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Sir_Abu_Nuayr] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-203367.3128691,["x"]=-103017.22553918,},
|
||||
[2]={["y"]=-203373.59664477,["x"]=-103054.92819323,},
|
||||
[3]={["y"]=-202578.27577922,["x"]=-103188.26018333,},
|
||||
[4]={["y"]=-202571.37254488,["x"]=-103151.01482599,},
|
||||
[5]={["y"]=-203367.65259839,["x"]=-103016.48202662,},
|
||||
[6]={["y"]=-203291.39594004,["x"]=-102985.49774228,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Sirri_Island] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-169713.12842428,["x"]=-27766.658020853,},
|
||||
[2]={["y"]=-169682.02009414,["x"]=-27726.583172021,},
|
||||
[3]={["y"]=-169727.21866794,["x"]=-27691.632048154,},
|
||||
[4]={["y"]=-169694.28043602,["x"]=-27650.276268081,},
|
||||
[5]={["y"]=-169763.08474269,["x"]=-27598.490047901,},
|
||||
[6]={["y"]=-169825.30140298,["x"]=-27607.090586235,},
|
||||
[7]={["y"]=-171614.98889813,["x"]=-26246.247907014,},
|
||||
[8]={["y"]=-171620.85326172,["x"]=-26187.105176343,},
|
||||
[9]={["y"]=-171686.10990337,["x"]=-26138.56820961,},
|
||||
[10]={["y"]=-171716.55468456,["x"]=-26178.745338885,},
|
||||
[11]={["y"]=-171764.9668776,["x"]=-26142.810515186,},
|
||||
[12]={["y"]=-171796.29599657,["x"]=-26183.416460911,},
|
||||
[13]={["y"]=-169713.5628285,["x"]=-27766.883787223,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Tunb_Island_AFB] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-92923.634698863,["x"]=9547.6862547173,},
|
||||
[2]={["y"]=-92963.030803298,["x"]=9565.7274614215,},
|
||||
[3]={["y"]=-92934.128053782,["x"]=9619.2987996964,},
|
||||
[4]={["y"]=-92970.946842975,["x"]=9640.1014155901,},
|
||||
[5]={["y"]=-92949.591945243,["x"]=9682.8112110532,},
|
||||
[6]={["y"]=-92899.518391942,["x"]=9699.7478540817,},
|
||||
[7]={["y"]=-91969.13471408,["x"]=11464.627292768,},
|
||||
[8]={["y"]=-91983.666755417,["x"]=11515.293058512,},
|
||||
[9]={["y"]=-91960.101282978,["x"]=11557.710908902,},
|
||||
[10]={["y"]=-91921.021874517,["x"]=11539.251288825,},
|
||||
[11]={["y"]=-91893.725202275,["x"]=11589.720675632,},
|
||||
[12]={["y"]=-91859.751646175,["x"]=11571.850192366,},
|
||||
[13]={["y"]=-92922.149728329,["x"]=9547.2937058617,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Tunb_Kochak] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-109925.50271188,["x"]=8974.5666013181,},
|
||||
[2]={["y"]=-109905.7382908,["x"]=8937.53274444,},
|
||||
[3]={["y"]=-109009.93726324,["x"]=9072.2234968343,},
|
||||
[4]={["y"]=-109040.82867587,["x"]=9104.9871291834,},
|
||||
[5]={["y"]=-109925.26515172,["x"]=8974.091480998,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Sas_Al_Nakheel_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-176230.75865538,["x"]=-188732.01369812,},
|
||||
[2]={["y"]=-176274.78045186,["x"]=-188744.8049371,},
|
||||
[3]={["y"]=-175692.03171595,["x"]=-190564.17145168,},
|
||||
[4]={["y"]=-175649.7486572,["x"]=-190550.58435053,},
|
||||
[5]={["y"]=-176230.66274076,["x"]=-188731.5667818,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Bandar_e_Jask_airfield] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=155156.73167657,["x"]=-57837.031277333,},
|
||||
[2]={["y"]=155130.38996239,["x"]=-57790.475605714,},
|
||||
[3]={["y"]=157137.17872571,["x"]=-56710.411783359,},
|
||||
[4]={["y"]=157148.46631801,["x"]=-56688.071756941,},
|
||||
[5]={["y"]=157220.07198163,["x"]=-56649.035500253,},
|
||||
[6]={["y"]=157227.83220133,["x"]=-56662.204357931,},
|
||||
[7]={["y"]=157359.6383572,["x"]=-56590.481115222,},
|
||||
[8]={["y"]=157383.03659539,["x"]=-56633.044744502,},
|
||||
[9]={["y"]=155156.7940421,["x"]=-57837.149989814,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Abu_Dhabi_International_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-163964.56943899,["x"]=-189427.63621921,},
|
||||
[2]={["y"]=-164005.96838287,["x"]=-189478.90226888,},
|
||||
[3]={["y"]=-160798.22080495,["x"]=-192054.59531727,},
|
||||
[4]={["y"]=-160755.05282258,["x"]=-192002.58569997,},
|
||||
[5]={["y"]=-163964.47352437,["x"]=-189427.18930288,},
|
||||
},
|
||||
[2] = {
|
||||
[1]={["y"]=-163615.44952024,["x"]=-187144.00786922,},
|
||||
[2]={["y"]=-163656.84846411,["x"]=-187195.27391888,},
|
||||
[3]={["y"]=-160452.71811093,["x"]=-189764.86593382,},
|
||||
[4]={["y"]=-160411.94568221,["x"]=-189715.47961171,},
|
||||
[5]={["y"]=-163615.35360562,["x"]=-187143.56095289,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Al_Bateen_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-183207.51774197,["x"]=-189871.8319832,},
|
||||
[2]={["y"]=-183240.61462564,["x"]=-189914.01184622,},
|
||||
[3]={["y"]=-180748.88998479,["x"]=-191943.30402837,},
|
||||
[4]={["y"]=-180711.83076051,["x"]=-191896.52435182,},
|
||||
[5]={["y"]=-183207.42182735,["x"]=-189871.38506688,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Kish_International_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-227330.79164594,["x"]=42691.91536494,},
|
||||
[2]={["y"]=-227321.58531968,["x"]=42758.113234714,},
|
||||
[3]={["y"]=-223235.73004619,["x"]=42313.579195302,},
|
||||
[4]={["y"]=-223240.99080406,["x"]=42247.819722016,},
|
||||
[5]={["y"]=-227330.67774245,["x"]=42691.785682556,},
|
||||
},
|
||||
[2] = {
|
||||
[1]={["y"]=-227283.77911886,["x"]=42987.748941936,},
|
||||
[2]={["y"]=-227274.5727926,["x"]=43053.946811711,},
|
||||
[3]={["y"]=-222907.94761294,["x"]=42580.826755904,},
|
||||
[4]={["y"]=-222915.76510871,["x"]=42514.58376547,},
|
||||
[5]={["y"]=-227283.66521537,["x"]=42987.619259553,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Al_Ain_International_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-65165.315648901,["x"]=-209042.45716363,},
|
||||
[2]={["y"]=-65112.933878375,["x"]=-209048.84518442,},
|
||||
[3]={["y"]=-65672.013626755,["x"]=-213019.66479976,},
|
||||
[4]={["y"]=-65722.555424932,["x"]=-213013.91596964,},
|
||||
[5]={["y"]=-65165.400582791,["x"]=-209042.15059908,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Lavan_Island_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=-288099.83301495,["x"]=76353.443273049,},
|
||||
[2]={["y"]=-288119.51457685,["x"]=76302.756224611,},
|
||||
[3]={["y"]=-288070.96603401,["x"]=76283.898526152,},
|
||||
[4]={["y"]=-288085.61084238,["x"]=76247.386812114,},
|
||||
[5]={["y"]=-288032.04695421,["x"]=76224.316223573,},
|
||||
[6]={["y"]=-287991.12173627,["x"]=76245.38067398,},
|
||||
[7]={["y"]=-287489.96435675,["x"]=76037.610404141,},
|
||||
[8]={["y"]=-287497.65444594,["x"]=76017.686082159,},
|
||||
[9]={["y"]=-287453.61120787,["x"]=75998.111309685,},
|
||||
[10]={["y"]=-287419.70490555,["x"]=76007.199596905,},
|
||||
[11]={["y"]=-285642.24565503,["x"]=75279.787069797,},
|
||||
[12]={["y"]=-285625.46727862,["x"]=75239.239326815,},
|
||||
[13]={["y"]=-285570.23845628,["x"]=75217.217707782,},
|
||||
[14]={["y"]=-285555.20782742,["x"]=75252.172658628,},
|
||||
[15]={["y"]=-285505.92134673,["x"]=75231.199688121,},
|
||||
[16]={["y"]=-285484.28380792,["x"]=75284.258832895,},
|
||||
[17]={["y"]=-288099.97979219,["x"]=76354.32393647,},
|
||||
},
|
||||
},
|
||||
},
|
||||
[AIRBASE.PersianGulf.Jiroft_Airport] = {
|
||||
PointsRunways = {
|
||||
[1] = {
|
||||
[1]={["y"]=140376.87310595,["x"]=283748.07558774,},
|
||||
[2]={["y"]=140299.43760975,["x"]=283655.81201779,},
|
||||
[3]={["y"]=143008.43807723,["x"]=281517.41347718,},
|
||||
[4]={["y"]=143052.6952428,["x"]=281573.25195709,},
|
||||
[5]={["y"]=142946.60213095,["x"]=281656.5960586,},
|
||||
[6]={["y"]=142975.14179847,["x"]=281687.20381796,},
|
||||
[7]={["y"]=142932.12548801,["x"]=281724.01585287,},
|
||||
[8]={["y"]=142870.49635092,["x"]=281719.05243244,},
|
||||
[9]={["y"]=140437.35783025,["x"]=283640.84253664,},
|
||||
[10]={["y"]=140433.27045062,["x"]=283705.80267729,},
|
||||
[11]={["y"]=140376.77702493,["x"]=283747.8442964,},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
--- Creates a new ATC_GROUND_PERSIANGULF object.
|
||||
-- @param #ATC_GROUND_PERSIANGULF self
|
||||
-- @param AirbaseNames A list {} of airbase names (Use AIRBASE.PersianGulf enumerator).
|
||||
-- @return #ATC_GROUND_PERSIANGULF self
|
||||
function ATC_GROUND_PERSIANGULF:New( AirbaseNames )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, ATC_GROUND:New( self.Airbases, AirbaseNames ) ) -- #ATC_GROUND_PERSIANGULF
|
||||
|
||||
self:SetKickSpeedKmph( 50 )
|
||||
self:SetMaximumKickSpeedKmph( 150 )
|
||||
|
||||
-- These lines here are for the demonstration mission.
|
||||
-- They create in the dcs.log the coordinates of the runway polygons, that are then
|
||||
-- taken by the moose designer from the dcs.log and reworked to define the
|
||||
-- Airbases structure, which is part of the class.
|
||||
-- When new airbases are added or airbases are changed on the map,
|
||||
-- the MOOSE designer willde-comment this section and apply the changes in the demo
|
||||
-- mission, and do a re-run to create a new dcs.log, and then add the changed coordinates
|
||||
-- in the Airbases structure.
|
||||
-- So, this needs to stay commented normally once a map has been finished.
|
||||
|
||||
|
||||
--[[
|
||||
|
||||
-- Abu_Musa_Island_Airport
|
||||
do
|
||||
local VillagePrefix = "Abu_Musa_Island_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Al_Dhafra_AB
|
||||
do
|
||||
local VillagePrefix = "Al_Dhafra_AB"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
local Runway2 = GROUP:FindByName( VillagePrefix .. " 2" )
|
||||
local Zone2 = ZONE_POLYGON:New( VillagePrefix .. " 2", Runway2 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Al_Maktoum_Intl
|
||||
do
|
||||
local VillagePrefix = "Al_Maktoum_Intl"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Al_Minhad_AB
|
||||
do
|
||||
local VillagePrefix = "Al_Minhad_AB"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Bandar_Abbas_Intl
|
||||
do
|
||||
local VillagePrefix = "Bandar_Abbas_Intl"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
local Runway2 = GROUP:FindByName( VillagePrefix .. " 2" )
|
||||
local Zone2 = ZONE_POLYGON:New( VillagePrefix .. " 2", Runway2 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Bandar_Lengeh
|
||||
do
|
||||
local VillagePrefix = "Bandar_Lengeh"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Dubai_Intl
|
||||
do
|
||||
local VillagePrefix = "Dubai_Intl"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
local Runway2 = GROUP:FindByName( VillagePrefix .. " 2" )
|
||||
local Zone2 = ZONE_POLYGON:New( VillagePrefix .. " 2", Runway2 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Fujairah_Intl
|
||||
do
|
||||
local VillagePrefix = "Fujairah_Intl"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Havadarya
|
||||
do
|
||||
local VillagePrefix = "Havadarya"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Kerman_Airport
|
||||
do
|
||||
local VillagePrefix = "Kerman_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Khasab
|
||||
do
|
||||
local VillagePrefix = "Khasab"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Lar_Airbase
|
||||
do
|
||||
local VillagePrefix = "Lar_Airbase"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Qeshm_Island
|
||||
do
|
||||
local VillagePrefix = "Qeshm_Island"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Sharjah_Intl
|
||||
do
|
||||
local VillagePrefix = "Sharjah_Intl"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
local Runway2 = GROUP:FindByName( VillagePrefix .. " 2" )
|
||||
local Zone2 = ZONE_POLYGON:New( VillagePrefix .. " 2", Runway2 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Shiraz_International_Airport
|
||||
do
|
||||
local VillagePrefix = "Shiraz_International_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
local Runway2 = GROUP:FindByName( VillagePrefix .. " 2" )
|
||||
local Zone2 = ZONE_POLYGON:New( VillagePrefix .. " 2", Runway2 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Sir_Abu_Nuayr
|
||||
do
|
||||
local VillagePrefix = "Sir_Abu_Nuayr"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Sirri_Island
|
||||
do
|
||||
local VillagePrefix = "Sirri_Island"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Tunb_Island_AFB
|
||||
do
|
||||
local VillagePrefix = "Tunb_Island_AFB"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Tunb_Kochak
|
||||
do
|
||||
local VillagePrefix = "Tunb_Kochak"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Sas_Al_Nakheel_Airport
|
||||
do
|
||||
local VillagePrefix = "Sas_Al_Nakheel_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Bandar_e_Jask_airfield
|
||||
do
|
||||
local VillagePrefix = "Bandar_e_Jask_airfield"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Abu_Dhabi_International_Airport
|
||||
do
|
||||
local VillagePrefix = "Abu_Dhabi_International_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
local Runway2 = GROUP:FindByName( VillagePrefix .. " 2" )
|
||||
local Zone2 = ZONE_POLYGON:New( VillagePrefix .. " 2", Runway2 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Al_Bateen_Airport
|
||||
do
|
||||
local VillagePrefix = "Al_Bateen_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Kish_International_Airport
|
||||
do
|
||||
local VillagePrefix = "Kish_International_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
local Runway2 = GROUP:FindByName( VillagePrefix .. " 2" )
|
||||
local Zone2 = ZONE_POLYGON:New( VillagePrefix .. " 2", Runway2 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Al_Ain_International_Airport
|
||||
do
|
||||
local VillagePrefix = "Al_Ain_International_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Lavan_Island_Airport
|
||||
do
|
||||
local VillagePrefix = "Lavan_Island_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Jiroft_Airport
|
||||
do
|
||||
local VillagePrefix = "Jiroft_Airport"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
|
||||
-- Bandar_Abbas_Intl
|
||||
do
|
||||
local VillagePrefix = "Bandar_Abbas_Intl"
|
||||
local Runway1 = GROUP:FindByName( VillagePrefix .. " 1" )
|
||||
local Zone1 = ZONE_POLYGON:New( VillagePrefix .. " 1", Runway1 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
local Runway2 = GROUP:FindByName( VillagePrefix .. " 2" )
|
||||
local Zone2 = ZONE_POLYGON:New( VillagePrefix .. " 2", Runway2 ):SmokeZone(SMOKECOLOR.Red):Flush()
|
||||
end
|
||||
|
||||
--]]
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Start SCHEDULER for ATC_GROUND_PERSIANGULF object.
|
||||
-- @param #ATC_GROUND_PERSIANGULF self
|
||||
-- @param RepeatScanSeconds Time in second for defining occurency of alerts.
|
||||
-- @return nothing
|
||||
function ATC_GROUND_PERSIANGULF:Start( RepeatScanSeconds )
|
||||
RepeatScanSeconds = RepeatScanSeconds or 0.05
|
||||
self.AirbaseMonitor = SCHEDULER:New( self, self._AirbaseMonitor, { self }, 0, 2, RepeatScanSeconds )
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -286,9 +286,9 @@ do -- DESIGNATE
|
||||
-- * The status report can be automatically flashed by selecting "Status" -> "Flash Status On".
|
||||
-- * The automatic flashing of the status report can be deactivated by selecting "Status" -> "Flash Status Off".
|
||||
-- * The flashing of the status menu is disabled by default.
|
||||
-- * The method @{#DESIGNATE.FlashStatusMenu}() can be used to enable or disable to flashing of the status menu.
|
||||
-- * The method @{#DESIGNATE.SetFlashStatusMenu}() can be used to enable or disable to flashing of the status menu.
|
||||
--
|
||||
-- Designate:FlashStatusMenu( true )
|
||||
-- Designate:SetFlashStatusMenu( true )
|
||||
--
|
||||
-- The example will activate the flashing of the status menu for this Designate object.
|
||||
--
|
||||
@@ -469,12 +469,12 @@ do -- DESIGNATE
|
||||
self.CC = CC
|
||||
self.Detection = Detection
|
||||
self.AttackSet = AttackSet
|
||||
self.RecceSet = Detection:GetDetectionSetGroup()
|
||||
self.RecceSet = Detection:GetDetectionSet()
|
||||
self.Recces = {}
|
||||
self.Designating = {}
|
||||
self:SetDesignateName()
|
||||
|
||||
self.LaseDuration = 60
|
||||
self:SetLaseDuration() -- Default is 120 seconds.
|
||||
|
||||
self:SetFlashStatusMenu( false )
|
||||
self:SetFlashDetectionMessages( true )
|
||||
@@ -677,6 +677,14 @@ do -- DESIGNATE
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set the lase duration for designations.
|
||||
-- @param #DESIGNATE self
|
||||
-- @param #number LaseDuration The time in seconds a lase will continue to hold on target. The default is 120 seconds.
|
||||
-- @return #DESIGNATE
|
||||
function DESIGNATE:SetLaseDuration( LaseDuration )
|
||||
self.LaseDuration = LaseDuration or 120
|
||||
return self
|
||||
end
|
||||
|
||||
--- Generate an array of possible laser codes.
|
||||
-- Each new lase will select a code from this table.
|
||||
@@ -1000,9 +1008,9 @@ do -- DESIGNATE
|
||||
if string.find( Designating, "L", 1, true ) == nil then
|
||||
MENU_GROUP_COMMAND_DELAYED:New( AttackGroup, "Search other target", DetectedMenu, self.MenuForget, self, DesignateIndex ):SetTime( MenuTime ):SetTag( self.DesignateName )
|
||||
for LaserCode, MenuText in pairs( self.MenuLaserCodes ) do
|
||||
MENU_GROUP_COMMAND_DELAYED:New( AttackGroup, string.format( MenuText, LaserCode ), DetectedMenu, self.MenuLaseCode, self, DesignateIndex, 60, LaserCode ):SetTime( MenuTime ):SetTag( self.DesignateName )
|
||||
MENU_GROUP_COMMAND_DELAYED:New( AttackGroup, string.format( MenuText, LaserCode ), DetectedMenu, self.MenuLaseCode, self, DesignateIndex, self.LaseDuration, LaserCode ):SetTime( MenuTime ):SetTag( self.DesignateName )
|
||||
end
|
||||
MENU_GROUP_COMMAND_DELAYED:New( AttackGroup, "Lase with random laser code(s)", DetectedMenu, self.MenuLaseOn, self, DesignateIndex, 60 ):SetTime( MenuTime ):SetTag( self.DesignateName )
|
||||
MENU_GROUP_COMMAND_DELAYED:New( AttackGroup, "Lase with random laser code(s)", DetectedMenu, self.MenuLaseOn, self, DesignateIndex, self.LaseDuration ):SetTime( MenuTime ):SetTag( self.DesignateName )
|
||||
else
|
||||
MENU_GROUP_COMMAND_DELAYED:New( AttackGroup, "Stop lasing", DetectedMenu, self.MenuLaseOff, self, DesignateIndex ):SetTime( MenuTime ):SetTag( self.DesignateName )
|
||||
end
|
||||
@@ -1160,10 +1168,10 @@ do -- DESIGNATE
|
||||
|
||||
if string.find( self.Designating[Index], "L", 1, true ) == nil then
|
||||
self.Designating[Index] = self.Designating[Index] .. "L"
|
||||
self.LaseStart = timer.getTime()
|
||||
self.LaseDuration = Duration
|
||||
self:Lasing( Index, Duration, LaserCode )
|
||||
end
|
||||
self.LaseStart = timer.getTime()
|
||||
self.LaseDuration = Duration
|
||||
self:Lasing( Index, Duration, LaserCode )
|
||||
end
|
||||
|
||||
|
||||
@@ -1174,7 +1182,7 @@ do -- DESIGNATE
|
||||
|
||||
|
||||
local DetectedItem = self.Detection:GetDetectedItemByIndex( Index )
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( DetectedItem )
|
||||
local TargetSetUnit = self.Detection:GetDetectedItemSet( DetectedItem )
|
||||
|
||||
local MarkingCount = 0
|
||||
local MarkedTypes = {}
|
||||
@@ -1322,7 +1330,7 @@ do -- DESIGNATE
|
||||
local MarkedLaserCodesText = ReportLaserCodes:Text(', ')
|
||||
self.CC:GetPositionable():MessageToSetGroup( "Marking " .. MarkingCount .. " x " .. MarkedTypesText .. ", code " .. MarkedLaserCodesText .. ".", 5, self.AttackSet, self.DesignateName )
|
||||
|
||||
self:__Lasing( -30, Index, Duration, LaserCodeRequested )
|
||||
self:__Lasing( -self.LaseDuration, Index, Duration, LaserCodeRequested )
|
||||
|
||||
self:SetDesignateMenu()
|
||||
|
||||
@@ -1344,7 +1352,7 @@ do -- DESIGNATE
|
||||
end
|
||||
|
||||
local DetectedItem = self.Detection:GetDetectedItemByIndex( Index )
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( DetectedItem )
|
||||
local TargetSetUnit = self.Detection:GetDetectedItemSet( DetectedItem )
|
||||
|
||||
local Recces = self.Recces
|
||||
|
||||
@@ -1369,7 +1377,7 @@ do -- DESIGNATE
|
||||
function DESIGNATE:onafterSmoke( From, Event, To, Index, Color )
|
||||
|
||||
local DetectedItem = self.Detection:GetDetectedItemByIndex( Index )
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( DetectedItem )
|
||||
local TargetSetUnit = self.Detection:GetDetectedItemSet( DetectedItem )
|
||||
local TargetSetUnitCount = TargetSetUnit:Count()
|
||||
|
||||
local MarkedCount = 0
|
||||
@@ -1385,7 +1393,7 @@ do -- DESIGNATE
|
||||
self:F( "Smoking ..." )
|
||||
|
||||
local RecceGroup = self.RecceSet:FindNearestGroupFromPointVec2(SmokeUnit:GetPointVec2())
|
||||
local RecceUnit = RecceGroup:GetUnit( 1 )
|
||||
local RecceUnit = RecceGroup:GetUnit( 1 ) -- Wrapper.Unit#UNIT
|
||||
|
||||
if RecceUnit then
|
||||
|
||||
@@ -1414,7 +1422,7 @@ do -- DESIGNATE
|
||||
function DESIGNATE:onafterIlluminate( From, Event, To, Index )
|
||||
|
||||
local DetectedItem = self.Detection:GetDetectedItemByIndex( Index )
|
||||
local TargetSetUnit = self.Detection:GetDetectedSet( DetectedItem )
|
||||
local TargetSetUnit = self.Detection:GetDetectedItemSet( DetectedItem )
|
||||
local TargetUnit = TargetSetUnit:GetFirst()
|
||||
|
||||
if TargetUnit then
|
||||
|
||||
@@ -291,23 +291,40 @@ do -- DETECTION_BASE
|
||||
--- @type DETECTION_BASE.DetectedItems
|
||||
-- @list <#DETECTION_BASE.DetectedItem>
|
||||
|
||||
--- @type DETECTION_BASE.DetectedItem
|
||||
--- Detected item data structrue.
|
||||
-- @type DETECTION_BASE.DetectedItem
|
||||
-- @field #boolean IsDetected Indicates if the DetectedItem has been detected or not.
|
||||
-- @field Core.Set#SET_UNIT Set
|
||||
-- @field Core.Set#SET_UNIT Set -- The Set of Units in the detected area.
|
||||
-- @field Core.Zone#ZONE_UNIT Zone -- The Zone of the detected area.
|
||||
-- @field #boolean Changed Documents if the detected area has changes.
|
||||
-- @field Core.Set#SET_UNIT Set The Set of Units in the detected area.
|
||||
-- @field Core.Zone#ZONE_UNIT Zone The Zone of the detected area.
|
||||
-- @field #boolean Changed Documents if the detected area has changed.
|
||||
-- @field #table Changes A list of the changes reported on the detected area. (It is up to the user of the detected area to consume those changes).
|
||||
-- @field #number ID -- The identifier of the detected area.
|
||||
-- @field #number ID The identifier of the detected area.
|
||||
-- @field #boolean FriendliesNearBy Indicates if there are friendlies within the detected area.
|
||||
-- @field Wrapper.Unit#UNIT NearestFAC The nearest FAC near the Area.
|
||||
-- @field Core.Point#COORDINATE Coordinate The last known coordinate of the DetectedItem.
|
||||
-- @field Core.Point#COORDINATE InterceptCoord Intercept coordiante.
|
||||
-- @field #number DistanceRecce Distance in meters of the Recce.
|
||||
-- @field #number Index Detected item key. Could also be a string.
|
||||
-- @field #string ItemID ItemPrefix .. "." .. self.DetectedItemMax.
|
||||
-- @field #boolean Locked Lock detected item.
|
||||
-- @field #table PlayersNearBy Table of nearby players.
|
||||
-- @field #table FriendliesDistance Table of distances to friendly units.
|
||||
-- @field #string TypeName Type name of the detected unit.
|
||||
-- @field #string CategoryName Catetory name of the detected unit.
|
||||
-- @field #string Name Name of the detected object.
|
||||
-- @field #boolean IsVisible If true, detected object is visible.
|
||||
-- @field #number LastTime Last time the detected item was seen.
|
||||
-- @field DCS#Vec3 LastPos Last known position of the detected item.
|
||||
-- @field DCS#Vec3 LastVelocity Last recorded 3D velocity vector of the detected item.
|
||||
-- @field #boolean KnowType Type of detected item is known.
|
||||
-- @field #boolean KnowDistance Distance to the detected item is known.
|
||||
-- @field #number Distance Distance to the detected item.
|
||||
|
||||
--- DETECTION constructor.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param Core.Set#SET_GROUP DetectionSetGroup The @{Set} of GROUPs in the Forward Air Controller role.
|
||||
-- @param Core.Set#SET_GROUP DetectionSet The @{Set} of @{Group}s that is used to detect the units.
|
||||
-- @return #DETECTION_BASE self
|
||||
function DETECTION_BASE:New( DetectionSetGroup )
|
||||
function DETECTION_BASE:New( DetectionSet )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #DETECTION_BASE
|
||||
@@ -316,7 +333,7 @@ do -- DETECTION_BASE
|
||||
self.DetectedItemMax = 0
|
||||
self.DetectedItems = {}
|
||||
|
||||
self.DetectionSetGroup = DetectionSetGroup
|
||||
self.DetectionSet = DetectionSet
|
||||
|
||||
self.RefreshTimeInterval = 30
|
||||
|
||||
@@ -398,7 +415,7 @@ do -- DETECTION_BASE
|
||||
-- @param #string To The To State string.
|
||||
|
||||
self:AddTransition( "Detecting", "Detect", "Detecting" )
|
||||
self:AddTransition( "Detecting", "DetectionGroup", "Detecting" )
|
||||
self:AddTransition( "Detecting", "Detection", "Detecting" )
|
||||
|
||||
--- OnBefore Transition Handler for Event Detect.
|
||||
-- @function [parent=#DETECTION_BASE] OnBeforeDetect
|
||||
@@ -441,15 +458,18 @@ do -- DETECTION_BASE
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @param #table Units Table of detected units.
|
||||
|
||||
--- Synchronous Event Trigger for Event Detected.
|
||||
-- @function [parent=#DETECTION_BASE] Detected
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #table Units Table of detected units.
|
||||
|
||||
--- Asynchronous Event Trigger for Event Detected.
|
||||
-- @function [parent=#DETECTION_BASE] __Detected
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #number Delay The delay in seconds.
|
||||
-- @param #table Units Table of detected units.
|
||||
|
||||
self:AddTransition( "Detecting", "DetectedItem", "Detecting" )
|
||||
|
||||
@@ -540,14 +560,40 @@ do -- DETECTION_BASE
|
||||
self.DetectedObjects[DetectionObjectName].Distance = 10000000
|
||||
|
||||
end
|
||||
for DetectionGroupID, DetectionGroupData in pairs( self.DetectionSetGroup:GetSet() ) do
|
||||
--self:F( { DetectionGroupData } )
|
||||
self:F( { DetectionGroup = DetectionGroupData:GetName() } )
|
||||
self:__DetectionGroup( DetectDelay, DetectionGroupData, DetectionTimeStamp ) -- Process each detection asynchronously.
|
||||
self.DetectionCount = self.DetectionCount + 1
|
||||
DetectDelay = DetectDelay + 1
|
||||
end
|
||||
|
||||
-- Count alive(!) groups only. Solves issue #1173 https://github.com/FlightControl-Master/MOOSE/issues/1173
|
||||
self.DetectionCount = self:CountAliveRecce()
|
||||
|
||||
local DetectionInterval = self.DetectionCount / ( self.RefreshTimeInterval - 1 )
|
||||
|
||||
self:ForEachAliveRecce(
|
||||
function( DetectionGroup )
|
||||
self:__Detection( DetectDelay, DetectionGroup, DetectionTimeStamp ) -- Process each detection asynchronously.
|
||||
DetectDelay = DetectDelay + DetectionInterval
|
||||
end
|
||||
)
|
||||
|
||||
self:__Detect( -self.RefreshTimeInterval )
|
||||
|
||||
end
|
||||
|
||||
--- @param #DETECTION_BASE self
|
||||
-- @param #number The amount of alive recce.
|
||||
function DETECTION_BASE:CountAliveRecce()
|
||||
|
||||
return self.DetectionSet:CountAlive()
|
||||
|
||||
end
|
||||
|
||||
--- @param #DETECTION_BASE self
|
||||
function DETECTION_BASE:ForEachAliveRecce( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
self.DetectionSet:ForEachGroupAlive( IteratorFunction, arg )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- @param #DETECTION_BASE self
|
||||
-- @param #string From The From State string.
|
||||
@@ -555,7 +601,7 @@ do -- DETECTION_BASE
|
||||
-- @param #string To The To State string.
|
||||
-- @param Wrapper.Group#GROUP DetectionGroup The Group detecting.
|
||||
-- @param #number DetectionTimeStamp Time stamp of detection event.
|
||||
function DETECTION_BASE:onafterDetectionGroup( From, Event, To, DetectionGroup, DetectionTimeStamp )
|
||||
function DETECTION_BASE:onafterDetection( From, Event, To, Detection, DetectionTimeStamp )
|
||||
|
||||
--self:F( { DetectedObjects = self.DetectedObjects } )
|
||||
|
||||
@@ -563,16 +609,16 @@ do -- DETECTION_BASE
|
||||
|
||||
local HasDetectedObjects = false
|
||||
|
||||
if DetectionGroup:IsAlive() then
|
||||
if Detection and Detection:IsAlive() then
|
||||
|
||||
--self:T( { "DetectionGroup is Alive", DetectionGroup:GetName() } )
|
||||
|
||||
local DetectionGroupName = DetectionGroup:GetName()
|
||||
local DetectionUnit = DetectionGroup:GetUnit(1)
|
||||
local DetectionGroupName = Detection:GetName()
|
||||
local DetectionUnit = Detection:GetUnit(1)
|
||||
|
||||
local DetectedUnits = {}
|
||||
|
||||
local DetectedTargets = DetectionGroup:GetDetectedTargets(
|
||||
local DetectedTargets = Detection:GetDetectedTargets(
|
||||
self.DetectVisual,
|
||||
self.DetectOptical,
|
||||
self.DetectRadar,
|
||||
@@ -624,7 +670,7 @@ do -- DETECTION_BASE
|
||||
|
||||
local DetectedObjectVec3 = DetectedObject:getPoint()
|
||||
local DetectedObjectVec2 = { x = DetectedObjectVec3.x, y = DetectedObjectVec3.z }
|
||||
local DetectionGroupVec3 = DetectionGroup:GetVec3()
|
||||
local DetectionGroupVec3 = Detection:GetVec3()
|
||||
local DetectionGroupVec2 = { x = DetectionGroupVec3.x, y = DetectionGroupVec3.z }
|
||||
|
||||
local Distance = ( ( DetectedObjectVec3.x - DetectionGroupVec3.x )^2 +
|
||||
@@ -788,23 +834,27 @@ do -- DETECTION_BASE
|
||||
-- IsDetected = false!
|
||||
-- This is used in A2A_TASK_DISPATCHER to initiate fighter sweeping! The TASK_A2A_INTERCEPT tasks will be replaced with TASK_A2A_SWEEP tasks.
|
||||
for DetectedObjectName, DetectedObject in pairs( self.DetectedObjects ) do
|
||||
if self.DetectedObjects[DetectedObjectName].IsDetected == true and self.DetectedObjects[DetectedObjectName].DetectionTimeStamp + 60 <= DetectionTimeStamp then
|
||||
if self.DetectedObjects[DetectedObjectName].IsDetected == true and self.DetectedObjects[DetectedObjectName].DetectionTimeStamp + 300 <= DetectionTimeStamp then
|
||||
self.DetectedObjects[DetectedObjectName].IsDetected = false
|
||||
end
|
||||
end
|
||||
|
||||
self:CreateDetectionItems() -- Polymorphic call to Create/Update the DetectionItems list for the DETECTION_ class grouping method.
|
||||
|
||||
for DetectedItemID, DetectedItem in pairs( self.DetectedItems ) do
|
||||
|
||||
self:UpdateDetectedItemDetection( DetectedItem )
|
||||
|
||||
self:CleanDetectionItem( DetectedItem, DetectedItemID ) -- Any DetectionItem that has a Set with zero elements in it, must be removed from the DetectionItems list.
|
||||
|
||||
if DetectedItem then
|
||||
self:__DetectedItem( 0.1, DetectedItem )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
self:__Detect( self.RefreshTimeInterval )
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -812,7 +862,7 @@ do -- DETECTION_BASE
|
||||
|
||||
do -- DetectionItems Creation
|
||||
|
||||
-- Clean the DetectedItem table.
|
||||
--- Clean the DetectedItem table.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @return #DETECTION_BASE
|
||||
function DETECTION_BASE:CleanDetectionItem( DetectedItem, DetectedItemID )
|
||||
@@ -838,7 +888,7 @@ do -- DETECTION_BASE
|
||||
local DetectedItems = self:GetDetectedItems()
|
||||
|
||||
for DetectedItemIndex, DetectedItem in pairs( DetectedItems ) do
|
||||
local DetectedSet = self:GetDetectedSet( DetectedItem )
|
||||
local DetectedSet = self:GetDetectedItemSet( DetectedItem )
|
||||
if DetectedSet then
|
||||
DetectedSet:RemoveUnitsByName( UnitName )
|
||||
end
|
||||
@@ -1012,7 +1062,7 @@ do -- DETECTION_BASE
|
||||
--- Set the parameters to calculate to optimal intercept point.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #boolean Intercept Intercept is true if an intercept point is calculated. Intercept is false if it is disabled. The default Intercept is false.
|
||||
-- @param #number IntereptDelay If Intercept is true, then InterceptDelay is the average time it takes to get airplanes airborne.
|
||||
-- @param #number InterceptDelay If Intercept is true, then InterceptDelay is the average time it takes to get airplanes airborne.
|
||||
-- @return #DETECTION_BASE self
|
||||
function DETECTION_BASE:SetIntercept( Intercept, InterceptDelay )
|
||||
self:F2()
|
||||
@@ -1229,17 +1279,17 @@ do -- DETECTION_BASE
|
||||
|
||||
--- Returns if there are friendlies nearby the FAC units ...
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param DetectedItem
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
||||
-- @param DCS#Unit.Category Category The category of the unit.
|
||||
-- @return #boolean true if there are friendlies nearby
|
||||
function DETECTION_BASE:IsFriendliesNearBy( DetectedItem, Category )
|
||||
--self:F( { "FriendliesNearBy Test", DetectedItem.FriendliesNearBy } )
|
||||
-- self:F( { "FriendliesNearBy Test", DetectedItem.FriendliesNearBy } )
|
||||
return ( DetectedItem.FriendliesNearBy and DetectedItem.FriendliesNearBy[Category] ~= nil ) or false
|
||||
end
|
||||
|
||||
--- Returns friendly units nearby the FAC units ...
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param DetectedItem
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
||||
-- @param DCS#Unit.Category Category The category of the unit.
|
||||
-- @return #map<#string,Wrapper.Unit#UNIT> The map of Friendly UNITs.
|
||||
function DETECTION_BASE:GetFriendliesNearBy( DetectedItem, Category )
|
||||
@@ -1249,6 +1299,7 @@ do -- DETECTION_BASE
|
||||
|
||||
--- Returns if there are friendlies nearby the intercept ...
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
||||
-- @return #boolean trhe if there are friendlies near the intercept.
|
||||
function DETECTION_BASE:IsFriendliesNearIntercept( DetectedItem )
|
||||
|
||||
@@ -1257,6 +1308,7 @@ do -- DETECTION_BASE
|
||||
|
||||
--- Returns friendly units nearby the intercept point ...
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem The detected item.
|
||||
-- @return #map<#string,Wrapper.Unit#UNIT> The map of Friendly UNITs.
|
||||
function DETECTION_BASE:GetFriendliesNearIntercept( DetectedItem )
|
||||
|
||||
@@ -1265,7 +1317,8 @@ do -- DETECTION_BASE
|
||||
|
||||
--- Returns the distance used to identify friendlies near the deteted item ...
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @return #number The distance.
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem The detected item.
|
||||
-- @return #table A table of distances to friendlies.
|
||||
function DETECTION_BASE:GetFriendliesDistance( DetectedItem )
|
||||
|
||||
return DetectedItem.FriendliesDistance
|
||||
@@ -1273,6 +1326,7 @@ do -- DETECTION_BASE
|
||||
|
||||
--- Returns if there are friendlies nearby the FAC units ...
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
||||
-- @return #boolean trhe if there are friendlies nearby
|
||||
function DETECTION_BASE:IsPlayersNearBy( DetectedItem )
|
||||
|
||||
@@ -1281,6 +1335,7 @@ do -- DETECTION_BASE
|
||||
|
||||
--- Returns friendly units nearby the FAC units ...
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem The detected item.
|
||||
-- @return #map<#string,Wrapper.Unit#UNIT> The map of Friendly UNITs.
|
||||
function DETECTION_BASE:GetPlayersNearBy( DetectedItem )
|
||||
|
||||
@@ -1289,10 +1344,11 @@ do -- DETECTION_BASE
|
||||
|
||||
--- Background worker function to determine if there are friendlies nearby ...
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #table TargetData
|
||||
function DETECTION_BASE:ReportFriendliesNearBy( TargetData )
|
||||
--self:F( { "Search Friendlies", DetectedItem = TargetData.DetectedItem } )
|
||||
|
||||
local DetectedItem = TargetData.DetectedItem -- Functional.Detection#DETECTION_BASE.DetectedItem
|
||||
local DetectedItem = TargetData.DetectedItem --#DETECTION_BASE.DetectedItem
|
||||
local DetectedSet = TargetData.DetectedItem.Set
|
||||
local DetectedUnit = DetectedSet:GetFirst() -- Wrapper.Unit#UNIT
|
||||
|
||||
@@ -1376,14 +1432,14 @@ do -- DETECTION_BASE
|
||||
world.searchObjects( Object.Category.UNIT, SphereSearch, FindNearByFriendlies, TargetData )
|
||||
|
||||
DetectedItem.PlayersNearBy = nil
|
||||
local DetectionZone = ZONE_UNIT:New( "DetectionPlayers", DetectedUnit, self.FriendliesRange )
|
||||
|
||||
_DATABASE:ForEachPlayer(
|
||||
--- @param Wrapper.Unit#UNIT PlayerUnit
|
||||
function( PlayerUnitName )
|
||||
local PlayerUnit = UNIT:FindByName( PlayerUnitName )
|
||||
|
||||
if PlayerUnit and PlayerUnit:IsInZone(DetectionZone) then
|
||||
if PlayerUnit and PlayerUnit:GetCoordinate():IsInRadius( DetectedUnitCoord, self.FriendliesRange ) then
|
||||
--if PlayerUnit and PlayerUnit:IsInZone(DetectionZone) then
|
||||
|
||||
local PlayerUnitCategory = PlayerUnit:GetDesc().category
|
||||
|
||||
@@ -1514,31 +1570,31 @@ do -- DETECTION_BASE
|
||||
--- Adds a new DetectedItem to the DetectedItems list.
|
||||
-- The DetectedItem is a table and contains a SET_UNIT in the field Set.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param ItemPrefix
|
||||
-- @param DetectedItemKey The key of the DetectedItem.
|
||||
-- @param #string ItemPrefix Prefix of detected item.
|
||||
-- @param #number DetectedItemKey The key of the DetectedItem. Default self.DetectedItemMax. Could also be a string in principle.
|
||||
-- @param Core.Set#SET_UNIT Set (optional) The Set of Units to be added.
|
||||
-- @return #DETECTION_BASE.DetectedItem
|
||||
function DETECTION_BASE:AddDetectedItem( ItemPrefix, DetectedItemKey, Set )
|
||||
|
||||
local DetectedItem = {}
|
||||
local DetectedItem = {} --#DETECTION_BASE.DetectedItem
|
||||
self.DetectedItemCount = self.DetectedItemCount + 1
|
||||
self.DetectedItemMax = self.DetectedItemMax + 1
|
||||
|
||||
if DetectedItemKey then
|
||||
self.DetectedItems[DetectedItemKey] = DetectedItem
|
||||
else
|
||||
self.DetectedItems[self.DetectedItemMax] = DetectedItem
|
||||
end
|
||||
|
||||
self.DetectedItemsByIndex[self.DetectedItemMax] = DetectedItem
|
||||
|
||||
DetectedItemKey = DetectedItemKey or self.DetectedItemMax
|
||||
self.DetectedItems[DetectedItemKey] = DetectedItem
|
||||
self.DetectedItemsByIndex[DetectedItemKey] = DetectedItem
|
||||
DetectedItem.Index = DetectedItemKey
|
||||
|
||||
DetectedItem.Set = Set or SET_UNIT:New():FilterDeads():FilterCrashes()
|
||||
DetectedItem.Index = DetectedItemKey or self.DetectedItemMax
|
||||
DetectedItem.ItemID = ItemPrefix .. "." .. self.DetectedItemMax
|
||||
DetectedItem.ID = self.DetectedItemMax
|
||||
DetectedItem.Removed = false
|
||||
|
||||
if self.Locking then
|
||||
self:LockDetectedItem( DetectedItem )
|
||||
end
|
||||
|
||||
return DetectedItem
|
||||
end
|
||||
|
||||
@@ -1549,9 +1605,11 @@ do -- DETECTION_BASE
|
||||
-- @param Core.Set#SET_UNIT Set (optional) The Set of Units to be added.
|
||||
-- @param Core.Zone#ZONE_UNIT Zone (optional) The Zone to be added where the Units are located.
|
||||
-- @return #DETECTION_BASE.DetectedItem
|
||||
function DETECTION_BASE:AddDetectedItemZone( DetectedItemKey, Set, Zone )
|
||||
function DETECTION_BASE:AddDetectedItemZone( ItemPrefix, DetectedItemKey, Set, Zone )
|
||||
|
||||
local DetectedItem = self:AddDetectedItem( "AREA", DetectedItemKey, Set )
|
||||
self:F( { ItemPrefix, DetectedItemKey, Set, Zone } )
|
||||
|
||||
local DetectedItem = self:AddDetectedItem( ItemPrefix, DetectedItemKey, Set )
|
||||
|
||||
DetectedItem.Zone = Zone
|
||||
|
||||
@@ -1624,7 +1682,7 @@ do -- DETECTION_BASE
|
||||
-- @return #DETECTION_BASE.DetectedItem
|
||||
function DETECTION_BASE:GetDetectedItemByIndex( Index )
|
||||
|
||||
self:F( { DetectedItemsByIndex = self.DetectedItemsByIndex } )
|
||||
self:F( { self.DetectedItemsByIndex } )
|
||||
|
||||
local DetectedItem = self.DetectedItemsByIndex[Index]
|
||||
if DetectedItem then
|
||||
@@ -1661,7 +1719,7 @@ do -- DETECTION_BASE
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
||||
-- @return Core.Set#SET_UNIT DetectedSet
|
||||
function DETECTION_BASE:GetDetectedSet( DetectedItem )
|
||||
function DETECTION_BASE:GetDetectedItemSet( DetectedItem )
|
||||
|
||||
local DetectedSetUnit = DetectedItem and DetectedItem.Set
|
||||
if DetectedSetUnit then
|
||||
@@ -1697,6 +1755,7 @@ do -- DETECTION_BASE
|
||||
|
||||
--- Checks if there is at least one UNIT detected in the Set of the the DetectedItem.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
||||
-- @return #boolean true if at least one UNIT is detected from the DetectedSet, false if no UNIT was detected from the DetectedSet.
|
||||
function DETECTION_BASE:IsDetectedItemDetected( DetectedItem )
|
||||
|
||||
@@ -1724,6 +1783,68 @@ do -- DETECTION_BASE
|
||||
|
||||
end
|
||||
|
||||
--- Lock the detected items when created and lock all existing detected items.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @return #DETECTION_BASE
|
||||
function DETECTION_BASE:LockDetectedItems()
|
||||
|
||||
for DetectedItemID, DetectedItem in pairs( self.DetectedItems ) do
|
||||
self:LockDetectedItem( DetectedItem )
|
||||
end
|
||||
self.Locking = true
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Unlock the detected items when created and unlock all existing detected items.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @return #DETECTION_BASE
|
||||
function DETECTION_BASE:UnlockDetectedItems()
|
||||
|
||||
for DetectedItemID, DetectedItem in pairs( self.DetectedItems ) do
|
||||
self:UnlockDetectedItem( DetectedItem )
|
||||
end
|
||||
self.Locking = nil
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Validate if the detected item is locked.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
|
||||
-- @return #boolean
|
||||
function DETECTION_BASE:IsDetectedItemLocked( DetectedItem )
|
||||
|
||||
return self.Locking and DetectedItem.Locked == true
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Lock a detected item.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
|
||||
-- @return #DETECTION_BASE
|
||||
function DETECTION_BASE:LockDetectedItem( DetectedItem )
|
||||
|
||||
DetectedItem.Locked = true
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Unlock a detected item.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
|
||||
-- @return #DETECTION_BASE
|
||||
function DETECTION_BASE:UnlockDetectedItem( DetectedItem )
|
||||
|
||||
DetectedItem.Locked = nil
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Set the detected item coordinate.
|
||||
-- @param #DETECTION_BASE self
|
||||
@@ -1759,6 +1880,20 @@ do -- DETECTION_BASE
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Get a list of the detected item coordinates.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @return #table A table of Core.Point#COORDINATE
|
||||
function DETECTION_BASE:GetDetectedItemCoordinates()
|
||||
|
||||
local Coordinates = {}
|
||||
|
||||
for DetectedItemID, DetectedItem in pairs( self:GetDetectedItems() ) do
|
||||
Coordinates[DetectedItem] = self:GetDetectedItemCoordinate( DetectedItem )
|
||||
end
|
||||
|
||||
return Coordinates
|
||||
end
|
||||
|
||||
--- Set the detected item threatlevel.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE.DetectedItem The DetectedItem to calculate the threatlevel for.
|
||||
@@ -1810,13 +1945,13 @@ do -- DETECTION_BASE
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Get the detection Groups.
|
||||
--- Get the Detection Set.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @return Core.Set#SET_GROUP
|
||||
function DETECTION_BASE:GetDetectionSetGroup()
|
||||
-- @return #DETECTION_BASE self
|
||||
function DETECTION_BASE:GetDetectionSet()
|
||||
|
||||
local DetectionSetGroup = self.DetectionSetGroup
|
||||
return DetectionSetGroup
|
||||
local DetectionSet = self.DetectionSet
|
||||
return DetectionSet
|
||||
end
|
||||
|
||||
--- Find the nearest Recce of the DetectedItem.
|
||||
@@ -1828,7 +1963,7 @@ do -- DETECTION_BASE
|
||||
local NearestRecce = nil
|
||||
local DistanceRecce = 1000000000 -- Units are not further than 1000000 km away from an area :-)
|
||||
|
||||
for RecceGroupName, RecceGroup in pairs( self.DetectionSetGroup:GetSet() ) do
|
||||
for RecceGroupName, RecceGroup in pairs( self.DetectionSet:GetSet() ) do
|
||||
if RecceGroup and RecceGroup:IsAlive() then
|
||||
for RecceUnit, RecceUnit in pairs( RecceGroup:GetUnits() ) do
|
||||
if RecceUnit:IsActive() then
|
||||
@@ -1947,7 +2082,8 @@ do -- DETECTION_UNITS
|
||||
function DETECTION_UNITS:CreateDetectionItems()
|
||||
-- Loop the current detected items, and check if each object still exists and is detected.
|
||||
|
||||
for DetectedItemKey, DetectedItem in pairs( self.DetectedItems ) do
|
||||
for DetectedItemKey, _DetectedItem in pairs( self.DetectedItems ) do
|
||||
local DetectedItem=_DetectedItem --#DETECTION_BASE.DetectedItem
|
||||
|
||||
local DetectedItemSet = DetectedItem.Set -- Core.Set#SET_UNIT
|
||||
|
||||
@@ -2033,7 +2169,7 @@ do -- DETECTION_UNITS
|
||||
local DetectedFirstUnitCoord = DetectedFirstUnit:GetCoordinate()
|
||||
self:SetDetectedItemCoordinate( DetectedItem, DetectedFirstUnitCoord, DetectedFirstUnit )
|
||||
|
||||
self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table
|
||||
self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSet } ) -- Fill the Friendlies table
|
||||
self:SetDetectedItemThreatLevel( DetectedItem )
|
||||
self:NearestRecce( DetectedItem )
|
||||
|
||||
@@ -2268,7 +2404,7 @@ do -- DETECTION_TYPES
|
||||
local DetectedUnitCoord = DetectedFirstUnit:GetCoordinate()
|
||||
self:SetDetectedItemCoordinate( DetectedItem, DetectedUnitCoord, DetectedFirstUnit )
|
||||
|
||||
self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table
|
||||
self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSet } ) -- Fill the Friendlies table
|
||||
self:SetDetectedItemThreatLevel( DetectedItem )
|
||||
self:NearestRecce( DetectedItem )
|
||||
end
|
||||
@@ -2286,7 +2422,7 @@ do -- DETECTION_TYPES
|
||||
function DETECTION_TYPES:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings )
|
||||
self:F( { DetectedItem = DetectedItem } )
|
||||
|
||||
local DetectedSet = self:GetDetectedSet( DetectedItem )
|
||||
local DetectedSet = self:GetDetectedItemSet( DetectedItem )
|
||||
local DetectedItemID = self:GetDetectedItemID( DetectedItem )
|
||||
|
||||
self:T( DetectedItem )
|
||||
@@ -2402,28 +2538,67 @@ do -- DETECTION_AREAS
|
||||
-- @param Wrapper.Group#GROUP AttackGroup The group to get the settings for.
|
||||
-- @param Core.Settings#SETTINGS Settings (Optional) Message formatting settings to use.
|
||||
-- @return Core.Report#REPORT The report of the detection items.
|
||||
function DETECTION_AREAS:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings )
|
||||
function DETECTION_AREAS:DetectedItemReportMenu( DetectedItem, AttackGroup, Settings )
|
||||
self:F( { DetectedItem = DetectedItem } )
|
||||
|
||||
local DetectedItemID = self:GetDetectedItemID( DetectedItem )
|
||||
|
||||
if DetectedItem then
|
||||
local DetectedSet = self:GetDetectedSet( DetectedItem )
|
||||
local DetectedSet = self:GetDetectedItemSet( DetectedItem )
|
||||
local ReportSummaryItem
|
||||
|
||||
local DetectedZone = self:GetDetectedItemZone( DetectedItem )
|
||||
local DetectedItemCoordinate = DetectedZone:GetCoordinate()
|
||||
local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings )
|
||||
|
||||
local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedItem )
|
||||
|
||||
local Report = REPORT:New()
|
||||
Report:Add( DetectedItemID )
|
||||
Report:Add( string.format( "Threat: [%s%s]", string.rep( "■", ThreatLevelA2G ), string.rep( "□", 10-ThreatLevelA2G ) ) )
|
||||
|
||||
return Report
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Report summary of a detected item using a given numeric index.
|
||||
-- @param #DETECTION_AREAS self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
|
||||
-- @param Wrapper.Group#GROUP AttackGroup The group to get the settings for.
|
||||
-- @param Core.Settings#SETTINGS Settings (Optional) Message formatting settings to use.
|
||||
-- @return Core.Report#REPORT The report of the detection items.
|
||||
function DETECTION_AREAS:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings )
|
||||
self:F( { DetectedItem = DetectedItem } )
|
||||
|
||||
local DetectedItemID = self:GetDetectedItemID( DetectedItem )
|
||||
|
||||
if DetectedItem then
|
||||
local DetectedSet = self:GetDetectedItemSet( DetectedItem )
|
||||
local ReportSummaryItem
|
||||
|
||||
--local DetectedZone = self:GetDetectedItemZone( DetectedItem )
|
||||
local DetectedItemCoordinate = self:GetDetectedItemCoordinate( DetectedItem )
|
||||
local DetectedAir = DetectedSet:HasAirUnits()
|
||||
local DetectedAltitude = self:GetDetectedItemCoordinate( DetectedItem )
|
||||
local DetectedItemCoordText = ""
|
||||
if DetectedAir > 0 then
|
||||
DetectedItemCoordText = DetectedItemCoordinate:ToStringA2A( AttackGroup, Settings )
|
||||
else
|
||||
DetectedItemCoordText = DetectedItemCoordinate:ToStringA2G( AttackGroup, Settings )
|
||||
end
|
||||
|
||||
|
||||
local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedItem )
|
||||
local DetectedItemsCount = DetectedSet:Count()
|
||||
local DetectedItemsTypes = DetectedSet:GetTypeNames()
|
||||
|
||||
local Report = REPORT:New()
|
||||
Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText)
|
||||
Report:Add( string.format( "Threat: [%s]", string.rep( "■", ThreatLevelA2G ), string.rep( "□", 10-ThreatLevelA2G ) ) )
|
||||
Report:Add( string.format( "Threat: [%s%s]", string.rep( "■", ThreatLevelA2G ), string.rep( "□", 10-ThreatLevelA2G ) ) )
|
||||
Report:Add( string.format("Type: %2d of %s", DetectedItemsCount, DetectedItemsTypes ) )
|
||||
Report:Add( string.format("Detected: %s", DetectedItem.IsDetected and "yes" or "no" ) )
|
||||
--Report:Add( string.format("Detected: %s", DetectedItem.IsDetected and "yes" or "no" ) )
|
||||
|
||||
return Report
|
||||
end
|
||||
@@ -2741,7 +2916,7 @@ do -- DETECTION_AREAS
|
||||
if AddedToDetectionArea == false then
|
||||
|
||||
-- New detection area
|
||||
local DetectedItem = self:AddDetectedItemZone( nil,
|
||||
local DetectedItem = self:AddDetectedItemZone( "AREA", nil,
|
||||
SET_UNIT:New():FilterDeads():FilterCrashes(),
|
||||
ZONE_UNIT:New( DetectedUnitName, DetectedUnit, self.DetectionZoneRange )
|
||||
)
|
||||
@@ -2773,7 +2948,7 @@ do -- DETECTION_AREAS
|
||||
-- If there were friendlies nearby, and now there aren't any friendlies nearby, we flag the area as "changed".
|
||||
-- This is for the A2G dispatcher to detect if there is a change in the tactical situation.
|
||||
local OldFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT )
|
||||
self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table
|
||||
self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSet } ) -- Fill the Friendlies table
|
||||
local NewFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT )
|
||||
if OldFriendliesNearbyGround ~= NewFriendliesNearbyGround then
|
||||
DetectedItem.Changed = true
|
||||
@@ -2819,3 +2994,5 @@ do -- DETECTION_AREAS
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
416
Moose Development/Moose/Functional/DetectionZones.lua
Normal file
416
Moose Development/Moose/Functional/DetectionZones.lua
Normal file
@@ -0,0 +1,416 @@
|
||||
do -- DETECTION_ZONES
|
||||
|
||||
--- @type DETECTION_ZONES
|
||||
-- @field DCS#Distance DetectionZoneRange The range till which targets are grouped upon the first detected target.
|
||||
-- @field #DETECTION_BASE.DetectedItems DetectedItems A list of areas containing the set of @{Wrapper.Unit}s, @{Zone}s, the center @{Wrapper.Unit} within the zone, and ID of each area that was detected within a DetectionZoneRange.
|
||||
-- @extends Functional.Detection#DETECTION_BASE
|
||||
|
||||
--- (old, to be revised ) Detect units within the battle zone for a list of @{Core.Zone}s detecting targets following (a) detection method(s),
|
||||
-- and will build a list (table) of @{Core.Set#SET_UNIT}s containing the @{Wrapper.Unit#UNIT}s detected.
|
||||
-- The class is group the detected units within zones given a DetectedZoneRange parameter.
|
||||
-- A set with multiple detected zones will be created as there are groups of units detected.
|
||||
--
|
||||
-- ## 4.1) Retrieve the Detected Unit Sets and Detected Zones
|
||||
--
|
||||
-- The methods to manage the DetectedItems[].Set(s) are implemented in @{Functional.Detection#DECTECTION_BASE} and
|
||||
-- the methods to manage the DetectedItems[].Zone(s) is implemented in @{Functional.Detection#DETECTION_ZONES}.
|
||||
--
|
||||
-- Retrieve the DetectedItems[].Set with the method @{Functional.Detection#DETECTION_BASE.GetDetectedSet}(). A @{Core.Set#SET_UNIT} object will be returned.
|
||||
--
|
||||
-- Retrieve the formed @{Zone@ZONE_UNIT}s as a result of the grouping the detected units within the DetectionZoneRange, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZones}().
|
||||
-- To understand the amount of zones created, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZoneCount}().
|
||||
-- If you want to obtain a specific zone from the DetectedZones, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZone}() with a given index.
|
||||
--
|
||||
-- ## 4.4) Flare or Smoke detected units
|
||||
--
|
||||
-- Use the methods @{Functional.Detection#DETECTION_ZONES.FlareDetectedUnits}() or @{Functional.Detection#DETECTION_ZONES.SmokeDetectedUnits}() to flare or smoke the detected units when a new detection has taken place.
|
||||
--
|
||||
-- ## 4.5) Flare or Smoke or Bound detected zones
|
||||
--
|
||||
-- Use the methods:
|
||||
--
|
||||
-- * @{Functional.Detection#DETECTION_ZONES.FlareDetectedZones}() to flare in a color
|
||||
-- * @{Functional.Detection#DETECTION_ZONES.SmokeDetectedZones}() to smoke in a color
|
||||
-- * @{Functional.Detection#DETECTION_ZONES.SmokeDetectedZones}() to bound with a tire with a white flag
|
||||
--
|
||||
-- the detected zones when a new detection has taken place.
|
||||
--
|
||||
-- @field #DETECTION_ZONES
|
||||
DETECTION_ZONES = {
|
||||
ClassName = "DETECTION_ZONES",
|
||||
DetectionZoneRange = nil,
|
||||
}
|
||||
|
||||
|
||||
--- DETECTION_ZONES constructor.
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @param Core.Set#SET_ZONE DetectionSetZone The @{Set} of ZONE_RADIUS.
|
||||
-- @param DCS#Coalition.side DetectionCoalition The coalition of the detection.
|
||||
-- @return #DETECTION_ZONES
|
||||
function DETECTION_ZONES:New( DetectionSetZone, DetectionCoalition )
|
||||
|
||||
-- Inherits from DETECTION_BASE
|
||||
local self = BASE:Inherit( self, DETECTION_BASE:New( DetectionSetZone ) ) -- #DETECTION_ZONES
|
||||
|
||||
self.DetectionSetZone = DetectionSetZone -- Core.Set#SET_ZONE
|
||||
self.DetectionCoalition = DetectionCoalition
|
||||
|
||||
self._SmokeDetectedUnits = false
|
||||
self._FlareDetectedUnits = false
|
||||
self._SmokeDetectedZones = false
|
||||
self._FlareDetectedZones = false
|
||||
self._BoundDetectedZones = false
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- @param #DETECTION_ZONES self
|
||||
-- @param #number The amount of alive recce.
|
||||
function DETECTION_ZONES:CountAliveRecce()
|
||||
|
||||
return self.DetectionSetZone:Count()
|
||||
|
||||
end
|
||||
|
||||
--- @param #DETECTION_ZONES self
|
||||
function DETECTION_ZONES:ForEachAliveRecce( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
self.DetectionSetZone:ForEachZone( IteratorFunction, arg )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Report summary of a detected item using a given numeric index.
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
|
||||
-- @param Wrapper.Group#GROUP AttackGroup The group to get the settings for.
|
||||
-- @param Core.Settings#SETTINGS Settings (Optional) Message formatting settings to use.
|
||||
-- @return Core.Report#REPORT The report of the detection items.
|
||||
function DETECTION_ZONES:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings )
|
||||
self:F( { DetectedItem = DetectedItem } )
|
||||
|
||||
local DetectedItemID = self:GetDetectedItemID( DetectedItem )
|
||||
|
||||
if DetectedItem then
|
||||
local DetectedSet = self:GetDetectedItemSet( DetectedItem )
|
||||
local ReportSummaryItem
|
||||
|
||||
local DetectedZone = self:GetDetectedItemZone( DetectedItem )
|
||||
local DetectedItemCoordinate = DetectedZone:GetCoordinate()
|
||||
local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings )
|
||||
|
||||
local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedItem )
|
||||
local DetectedItemsCount = DetectedSet:Count()
|
||||
local DetectedItemsTypes = DetectedSet:GetTypeNames()
|
||||
|
||||
local Report = REPORT:New()
|
||||
Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText)
|
||||
Report:Add( string.format( "Threat: [%s]", string.rep( "■", ThreatLevelA2G ), string.rep( "□", 10-ThreatLevelA2G ) ) )
|
||||
Report:Add( string.format("Type: %2d of %s", DetectedItemsCount, DetectedItemsTypes ) )
|
||||
Report:Add( string.format("Detected: %s", DetectedItem.IsDetected and "yes" or "no" ) )
|
||||
|
||||
return Report
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Report detailed of a detection result.
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for.
|
||||
-- @return #string
|
||||
function DETECTION_ZONES:DetectedReportDetailed( AttackGroup ) --R2.1 Fixed missing report
|
||||
self:F()
|
||||
|
||||
local Report = REPORT:New()
|
||||
for DetectedItemIndex, DetectedItem in pairs( self.DetectedItems ) do
|
||||
local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem
|
||||
local ReportSummary = self:DetectedItemReportSummary( DetectedItem, AttackGroup )
|
||||
Report:SetTitle( "Detected areas:" )
|
||||
Report:Add( ReportSummary:Text() )
|
||||
end
|
||||
|
||||
local ReportText = Report:Text()
|
||||
|
||||
return ReportText
|
||||
end
|
||||
|
||||
|
||||
--- Calculate the optimal intercept point of the DetectedItem.
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
||||
function DETECTION_ZONES:CalculateIntercept( DetectedItem )
|
||||
|
||||
local DetectedCoord = DetectedItem.Coordinate
|
||||
-- local DetectedSpeed = DetectedCoord:GetVelocity()
|
||||
-- local DetectedHeading = DetectedCoord:GetHeading()
|
||||
--
|
||||
-- if self.Intercept then
|
||||
-- local DetectedSet = DetectedItem.Set
|
||||
-- -- todo: speed
|
||||
--
|
||||
-- local TranslateDistance = DetectedSpeed * self.InterceptDelay
|
||||
--
|
||||
-- local InterceptCoord = DetectedCoord:Translate( TranslateDistance, DetectedHeading )
|
||||
--
|
||||
-- DetectedItem.InterceptCoord = InterceptCoord
|
||||
-- else
|
||||
-- DetectedItem.InterceptCoord = DetectedCoord
|
||||
-- end
|
||||
DetectedItem.InterceptCoord = DetectedCoord
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Smoke the detected units
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @return #DETECTION_ZONES self
|
||||
function DETECTION_ZONES:SmokeDetectedUnits()
|
||||
self:F2()
|
||||
|
||||
self._SmokeDetectedUnits = true
|
||||
return self
|
||||
end
|
||||
|
||||
--- Flare the detected units
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @return #DETECTION_ZONES self
|
||||
function DETECTION_ZONES:FlareDetectedUnits()
|
||||
self:F2()
|
||||
|
||||
self._FlareDetectedUnits = true
|
||||
return self
|
||||
end
|
||||
|
||||
--- Smoke the detected zones
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @return #DETECTION_ZONES self
|
||||
function DETECTION_ZONES:SmokeDetectedZones()
|
||||
self:F2()
|
||||
|
||||
self._SmokeDetectedZones = true
|
||||
return self
|
||||
end
|
||||
|
||||
--- Flare the detected zones
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @return #DETECTION_ZONES self
|
||||
function DETECTION_ZONES:FlareDetectedZones()
|
||||
self:F2()
|
||||
|
||||
self._FlareDetectedZones = true
|
||||
return self
|
||||
end
|
||||
|
||||
--- Bound the detected zones
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @return #DETECTION_ZONES self
|
||||
function DETECTION_ZONES:BoundDetectedZones()
|
||||
self:F2()
|
||||
|
||||
self._BoundDetectedZones = true
|
||||
return self
|
||||
end
|
||||
|
||||
--- Make text documenting the changes of the detected zone.
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
||||
-- @return #string The Changes text
|
||||
function DETECTION_ZONES:GetChangeText( DetectedItem )
|
||||
self:F( DetectedItem )
|
||||
|
||||
local MT = {}
|
||||
|
||||
for ChangeCode, ChangeData in pairs( DetectedItem.Changes ) do
|
||||
|
||||
if ChangeCode == "AA" then
|
||||
MT[#MT+1] = "Detected new area " .. ChangeData.ID .. ". The center target is a " .. ChangeData.ItemUnitType .. "."
|
||||
end
|
||||
|
||||
if ChangeCode == "RAU" then
|
||||
MT[#MT+1] = "Changed area " .. ChangeData.ID .. ". Removed the center target."
|
||||
end
|
||||
|
||||
if ChangeCode == "AAU" then
|
||||
MT[#MT+1] = "Changed area " .. ChangeData.ID .. ". The new center target is a " .. ChangeData.ItemUnitType .. "."
|
||||
end
|
||||
|
||||
if ChangeCode == "RA" then
|
||||
MT[#MT+1] = "Removed old area " .. ChangeData.ID .. ". No more targets in this area."
|
||||
end
|
||||
|
||||
if ChangeCode == "AU" then
|
||||
local MTUT = {}
|
||||
for ChangeUnitType, ChangeUnitCount in pairs( ChangeData ) do
|
||||
if ChangeUnitType ~= "ID" then
|
||||
MTUT[#MTUT+1] = ChangeUnitCount .. " of " .. ChangeUnitType
|
||||
end
|
||||
end
|
||||
MT[#MT+1] = "Detected for area " .. ChangeData.ID .. " new target(s) " .. table.concat( MTUT, ", " ) .. "."
|
||||
end
|
||||
|
||||
if ChangeCode == "RU" then
|
||||
local MTUT = {}
|
||||
for ChangeUnitType, ChangeUnitCount in pairs( ChangeData ) do
|
||||
if ChangeUnitType ~= "ID" then
|
||||
MTUT[#MTUT+1] = ChangeUnitCount .. " of " .. ChangeUnitType
|
||||
end
|
||||
end
|
||||
MT[#MT+1] = "Removed for area " .. ChangeData.ID .. " invisible or destroyed target(s) " .. table.concat( MTUT, ", " ) .. "."
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return table.concat( MT, "\n" )
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Make a DetectionSet table. This function will be overridden in the derived clsses.
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @return #DETECTION_ZONES self
|
||||
function DETECTION_ZONES:CreateDetectionItems()
|
||||
|
||||
|
||||
self:F( "Checking Detected Items for new Detected Units ..." )
|
||||
|
||||
local DetectedUnits = SET_UNIT:New()
|
||||
|
||||
-- First go through all zones, and check if there are new Zones.
|
||||
-- New Zones become a new DetectedItem.
|
||||
for ZoneName, DetectionZone in pairs( self.DetectionSetZone:GetSet() ) do
|
||||
|
||||
local DetectedItem = self:GetDetectedItemByKey( ZoneName )
|
||||
|
||||
if DetectedItem == nil then
|
||||
DetectedItem = self:AddDetectedItemZone( "ZONE", ZoneName, nil, DetectionZone )
|
||||
end
|
||||
|
||||
local DetectedItemSetUnit = self:GetDetectedItemSet( DetectedItem )
|
||||
|
||||
-- Scan the zone
|
||||
DetectionZone:Scan( { Object.Category.UNIT }, { Unit.Category.GROUND_UNIT } )
|
||||
|
||||
-- For all the units in the zone,
|
||||
-- check if they are of the same coalition to be included.
|
||||
local ZoneUnits = DetectionZone:GetScannedUnits()
|
||||
for DCSUnitID, DCSUnit in pairs( ZoneUnits ) do
|
||||
local UnitName = DCSUnit:getName()
|
||||
local ZoneUnit = UNIT:FindByName( UnitName )
|
||||
local ZoneUnitCoalition = ZoneUnit:GetCoalition()
|
||||
if ZoneUnitCoalition == self.DetectionCoalition then
|
||||
if DetectedItemSetUnit:FindUnit( UnitName ) == nil and DetectedUnits:FindUnit( UnitName ) == nil then
|
||||
self:F( "Adding " .. UnitName )
|
||||
DetectedItemSetUnit:AddUnit( ZoneUnit )
|
||||
DetectedUnits:AddUnit( ZoneUnit )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Now all the tests should have been build, now make some smoke and flares...
|
||||
-- We also report here the friendlies within the detected areas.
|
||||
|
||||
for DetectedItemID, DetectedItemData in pairs( self.DetectedItems ) do
|
||||
|
||||
local DetectedItem = DetectedItemData -- #DETECTION_BASE.DetectedItem
|
||||
local DetectedSet = self:GetDetectedItemSet( DetectedItem )
|
||||
local DetectedFirstUnit = DetectedSet:GetFirst()
|
||||
local DetectedZone = self:GetDetectedItemZone( DetectedItem )
|
||||
|
||||
-- Set the last known coordinate to the detection item.
|
||||
local DetectedZoneCoord = DetectedZone:GetCoordinate()
|
||||
self:SetDetectedItemCoordinate( DetectedItem, DetectedZoneCoord, DetectedFirstUnit )
|
||||
|
||||
self:CalculateIntercept( DetectedItem )
|
||||
|
||||
-- We search for friendlies nearby.
|
||||
-- If there weren't any friendlies nearby, and now there are friendlies nearby, we flag the area as "changed".
|
||||
-- If there were friendlies nearby, and now there aren't any friendlies nearby, we flag the area as "changed".
|
||||
-- This is for the A2G dispatcher to detect if there is a change in the tactical situation.
|
||||
local OldFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT )
|
||||
self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table
|
||||
local NewFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT )
|
||||
if OldFriendliesNearbyGround ~= NewFriendliesNearbyGround then
|
||||
DetectedItem.Changed = true
|
||||
end
|
||||
|
||||
self:SetDetectedItemThreatLevel( DetectedItem ) -- Calculate A2G threat level
|
||||
--self:NearestRecce( DetectedItem )
|
||||
|
||||
|
||||
if DETECTION_ZONES._SmokeDetectedUnits or self._SmokeDetectedUnits then
|
||||
DetectedZone:SmokeZone( SMOKECOLOR.Red, 30 )
|
||||
end
|
||||
|
||||
--DetectedSet:Flush( self )
|
||||
|
||||
DetectedSet:ForEachUnit(
|
||||
--- @param Wrapper.Unit#UNIT DetectedUnit
|
||||
function( DetectedUnit )
|
||||
if DetectedUnit:IsAlive() then
|
||||
--self:T( "Detected Set #" .. DetectedItem.ID .. ":" .. DetectedUnit:GetName() )
|
||||
if DETECTION_ZONES._FlareDetectedUnits or self._FlareDetectedUnits then
|
||||
DetectedUnit:FlareGreen()
|
||||
end
|
||||
if DETECTION_ZONES._SmokeDetectedUnits or self._SmokeDetectedUnits then
|
||||
DetectedUnit:SmokeGreen()
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
if DETECTION_ZONES._FlareDetectedZones or self._FlareDetectedZones then
|
||||
DetectedZone:FlareZone( SMOKECOLOR.White, 30, math.random( 0,90 ) )
|
||||
end
|
||||
if DETECTION_ZONES._SmokeDetectedZones or self._SmokeDetectedZones then
|
||||
DetectedZone:SmokeZone( SMOKECOLOR.White, 30 )
|
||||
end
|
||||
|
||||
if DETECTION_ZONES._BoundDetectedZones or self._BoundDetectedZones then
|
||||
self.CountryID = DetectedSet:GetFirst():GetCountry()
|
||||
DetectedZone:BoundZone( 12, self.CountryID )
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- @param #DETECTION_ZONES self
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
-- @param Detection The element on which the detection is based.
|
||||
-- @param #number DetectionTimeStamp Time stamp of detection event.
|
||||
function DETECTION_ZONES:onafterDetection( From, Event, To, Detection, DetectionTimeStamp )
|
||||
|
||||
self.DetectionRun = self.DetectionRun + 1
|
||||
if self.DetectionCount > 0 and self.DetectionRun == self.DetectionCount then
|
||||
self:CreateDetectionItems() -- Polymorphic call to Create/Update the DetectionItems list for the DETECTION_ class grouping method.
|
||||
|
||||
for DetectedItemID, DetectedItem in pairs( self.DetectedItems ) do
|
||||
self:UpdateDetectedItemDetection( DetectedItem )
|
||||
self:CleanDetectionItem( DetectedItem, DetectedItemID ) -- Any DetectionItem that has a Set with zero elements in it, must be removed from the DetectionItems list.
|
||||
if DetectedItem then
|
||||
self:__DetectedItem( 0.1, DetectedItem )
|
||||
end
|
||||
end
|
||||
self:__Detect( -self.RefreshTimeInterval )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Set IsDetected flag for the DetectedItem, which can have more units.
|
||||
-- @param #DETECTION_ZONES self
|
||||
-- @return #DETECTION_ZONES.DetectedItem DetectedItem
|
||||
-- @return #boolean true if at least one UNIT is detected from the DetectedSet, false if no UNIT was detected from the DetectedSet.
|
||||
function DETECTION_ZONES:UpdateDetectedItemDetection( DetectedItem )
|
||||
|
||||
local IsDetected = true
|
||||
|
||||
DetectedItem.IsDetected = true
|
||||
|
||||
return IsDetected
|
||||
end
|
||||
|
||||
end
|
||||
@@ -872,7 +872,7 @@ function ESCORT:_AttackTarget( DetectedItem )
|
||||
EscortGroup:OptionROTPassiveDefense()
|
||||
EscortGroup:SetState( EscortGroup, "Escort", self )
|
||||
|
||||
local DetectedSet = self.Detection:GetDetectedSet( DetectedItem )
|
||||
local DetectedSet = self.Detection:GetDetectedItemSet( DetectedItem )
|
||||
|
||||
local Tasks = {}
|
||||
|
||||
@@ -895,7 +895,7 @@ function ESCORT:_AttackTarget( DetectedItem )
|
||||
|
||||
else
|
||||
|
||||
local DetectedSet = self.Detection:GetDetectedSet( DetectedItem )
|
||||
local DetectedSet = self.Detection:GetDetectedItemSet( DetectedItem )
|
||||
|
||||
local Tasks = {}
|
||||
|
||||
@@ -934,7 +934,7 @@ function ESCORT:_AssistTarget( EscortGroupAttack, DetectedItem )
|
||||
EscortGroupAttack:OptionROEOpenFire()
|
||||
EscortGroupAttack:OptionROTVertical()
|
||||
|
||||
local DetectedSet = self.Detection:GetDetectedSet( DetectedItem )
|
||||
local DetectedSet = self.Detection:GetDetectedItemSet( DetectedItem )
|
||||
|
||||
local Tasks = {}
|
||||
|
||||
@@ -956,7 +956,7 @@ function ESCORT:_AssistTarget( EscortGroupAttack, DetectedItem )
|
||||
)
|
||||
|
||||
else
|
||||
local DetectedSet = self.Detection:GetDetectedSet( DetectedItem )
|
||||
local DetectedSet = self.Detection:GetDetectedItemSet( DetectedItem )
|
||||
|
||||
local Tasks = {}
|
||||
|
||||
|
||||
1815
Moose Development/Moose/Functional/Fox.lua
Normal file
1815
Moose Development/Moose/Functional/Fox.lua
Normal file
File diff suppressed because it is too large
Load Diff
@@ -81,7 +81,7 @@
|
||||
-- @field #PSEUDOATC
|
||||
PSEUDOATC={
|
||||
ClassName = "PSEUDOATC",
|
||||
player={},
|
||||
group={},
|
||||
Debug=false,
|
||||
mdur=30,
|
||||
mrefresh=120,
|
||||
@@ -98,7 +98,7 @@ PSEUDOATC.id="PseudoATC | "
|
||||
|
||||
--- PSEUDOATC version.
|
||||
-- @field #number version
|
||||
PSEUDOATC.version="0.9.1"
|
||||
PSEUDOATC.version="0.9.2"
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -383,16 +383,23 @@ function PSEUDOATC:PlayerEntered(unit)
|
||||
local PlayerName=unit:GetPlayerName()
|
||||
local UnitName=unit:GetName()
|
||||
local CallSign=unit:GetCallsign()
|
||||
local UID=unit:GetDCSObject():getID()
|
||||
|
||||
if not self.group[GID] then
|
||||
self.group[GID]={}
|
||||
self.group[GID].player={}
|
||||
end
|
||||
|
||||
|
||||
-- Init player table.
|
||||
self.player[GID]={}
|
||||
self.player[GID].group=group
|
||||
self.player[GID].unit=unit
|
||||
self.player[GID].groupname=GroupName
|
||||
self.player[GID].unitname=UnitName
|
||||
self.player[GID].playername=PlayerName
|
||||
self.player[GID].callsign=CallSign
|
||||
self.player[GID].waypoints=group:GetTaskRoute()
|
||||
self.group[GID].player[UID]={}
|
||||
self.group[GID].player[UID].group=group
|
||||
self.group[GID].player[UID].unit=unit
|
||||
self.group[GID].player[UID].groupname=GroupName
|
||||
self.group[GID].player[UID].unitname=UnitName
|
||||
self.group[GID].player[UID].playername=PlayerName
|
||||
self.group[GID].player[UID].callsign=CallSign
|
||||
self.group[GID].player[UID].waypoints=group:GetTaskRoute()
|
||||
|
||||
-- Info message.
|
||||
local text=string.format("Player %s entered unit %s of group %s (id=%d).", PlayerName, UnitName, GroupName, GID)
|
||||
@@ -400,19 +407,26 @@ function PSEUDOATC:PlayerEntered(unit)
|
||||
MESSAGE:New(text, 30):ToAllIf(self.Debug)
|
||||
|
||||
-- Create main F10 menu, i.e. "F10/Pseudo ATC"
|
||||
self.player[GID].menu_main=missionCommands.addSubMenuForGroup(GID, "Pseudo ATC")
|
||||
local countPlayerInGroup = 0
|
||||
for _ in pairs(self.group[GID].player) do countPlayerInGroup = countPlayerInGroup + 1 end
|
||||
if countPlayerInGroup <= 1 then
|
||||
self.group[GID].menu_main=missionCommands.addSubMenuForGroup(GID, "Pseudo ATC")
|
||||
end
|
||||
|
||||
-- Create/update custom menu for player
|
||||
self:MenuCreatePlayer(GID,UID)
|
||||
|
||||
-- Create/update list of nearby airports.
|
||||
self:LocalAirports(GID)
|
||||
self:LocalAirports(GID,UID)
|
||||
|
||||
-- Create submenu of local airports.
|
||||
self:MenuAirports(GID)
|
||||
self:MenuAirports(GID,UID)
|
||||
|
||||
-- Create submenu Waypoints.
|
||||
self:MenuWaypoints(GID)
|
||||
self:MenuWaypoints(GID,UID)
|
||||
|
||||
-- Start scheduler to refresh the F10 menues.
|
||||
self.player[GID].scheduler, self.player[GID].schedulerid=SCHEDULER:New(nil, self.MenuRefresh, {self, GID}, self.mrefresh, self.mrefresh)
|
||||
self.group[GID].player[UID].scheduler, self.group[GID].player[UID].schedulerid=SCHEDULER:New(nil, self.MenuRefresh, {self, GID, UID}, self.mrefresh, self.mrefresh)
|
||||
|
||||
end
|
||||
|
||||
@@ -425,24 +439,23 @@ function PSEUDOATC:PlayerLanded(unit, place)
|
||||
|
||||
-- Gather some information.
|
||||
local group=unit:GetGroup()
|
||||
local id=group:GetID()
|
||||
local PlayerName=self.player[id].playername
|
||||
local Callsign=self.player[id].callsign
|
||||
local UnitName=self.player[id].unitname
|
||||
local GroupName=self.player[id].groupname
|
||||
local CallSign=self.player[id].callsign
|
||||
local GID=group:GetID()
|
||||
local UID=unit:GetDCSObject():getID()
|
||||
local PlayerName=self.group[GID].player[UID].playername
|
||||
local UnitName=self.group[GID].player[UID].unitname
|
||||
local GroupName=self.group[GID].player[UID].groupname
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("Player %s in unit %s of group %s (id=%d) landed at %s.", PlayerName, UnitName, GroupName, id, place)
|
||||
local text=string.format("Player %s in unit %s of group %s (id=%d) landed at %s.", PlayerName, UnitName, GroupName, GID, place)
|
||||
self:T(PSEUDOATC.id..text)
|
||||
MESSAGE:New(text, 30):ToAllIf(self.Debug)
|
||||
|
||||
-- Stop altitude reporting timer if its activated.
|
||||
self:AltitudeTimerStop(id)
|
||||
self:AltitudeTimerStop(GID,UID)
|
||||
|
||||
-- Welcome message.
|
||||
if place and self.chatty then
|
||||
local text=string.format("Touchdown! Welcome to %s. Have a nice day!", place)
|
||||
local text=string.format("Touchdown! Welcome to %s pilot %s. Have a nice day!", place,PlayerName)
|
||||
MESSAGE:New(text, self.mdur):ToGroup(group)
|
||||
end
|
||||
|
||||
@@ -457,15 +470,15 @@ function PSEUDOATC:PlayerTakeOff(unit, place)
|
||||
|
||||
-- Gather some information.
|
||||
local group=unit:GetGroup()
|
||||
local id=group:GetID()
|
||||
local PlayerName=self.player[id].playername
|
||||
local Callsign=self.player[id].callsign
|
||||
local UnitName=self.player[id].unitname
|
||||
local GroupName=self.player[id].groupname
|
||||
local CallSign=self.player[id].callsign
|
||||
local GID=group:GetID()
|
||||
local UID=unit:GetDCSObject():getID()
|
||||
local PlayerName=self.group[GID].player[UID].playername
|
||||
local CallSign=self.group[GID].player[UID].callsign
|
||||
local UnitName=self.group[GID].player[UID].unitname
|
||||
local GroupName=self.group[GID].player[UID].groupname
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("Player %s in unit %s of group %s (id=%d) took off at %s.", PlayerName, UnitName, GroupName, id, place)
|
||||
local text=string.format("Player %s in unit %s of group %s (id=%d) took off at %s.", PlayerName, UnitName, GroupName, GID, place)
|
||||
self:T(PSEUDOATC.id..text)
|
||||
MESSAGE:New(text, 30):ToAllIf(self.Debug)
|
||||
|
||||
@@ -485,30 +498,44 @@ function PSEUDOATC:PlayerLeft(unit)
|
||||
|
||||
-- Get id.
|
||||
local group=unit:GetGroup()
|
||||
local id=group:GetID()
|
||||
local GID=group:GetID()
|
||||
local UID=unit:GetDCSObject():getID()
|
||||
|
||||
if self.player[id] then
|
||||
if self.group[GID].player[UID] then
|
||||
local PlayerName=self.group[GID].player[UID].playername
|
||||
local CallSign=self.group[GID].player[UID].callsign
|
||||
local UnitName=self.group[GID].player[UID].unitname
|
||||
local GroupName=self.group[GID].player[UID].groupname
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("Player %s (callsign %s) of group %s just left unit %s.", self.player[id].playername, self.player[id].callsign, self.player[id].groupname, self.player[id].unitname)
|
||||
local text=string.format("Player %s (callsign %s) of group %s just left unit %s.", PlayerName, CallSign, GroupName, UnitName)
|
||||
self:T(PSEUDOATC.id..text)
|
||||
MESSAGE:New(text, 30):ToAllIf(self.Debug)
|
||||
|
||||
-- Stop scheduler for menu updates
|
||||
if self.player[id].schedulerid then
|
||||
self.player[id].scheduler:Stop(self.player[id].schedulerid)
|
||||
if self.group[GID].player[UID].schedulerid then
|
||||
self.group[GID].player[UID].scheduler:Stop(self.group[GID].player[UID].schedulerid)
|
||||
end
|
||||
|
||||
-- Stop scheduler for reporting alt if it runs.
|
||||
self:AltitudeTimerStop(id)
|
||||
self:AltitudeTimerStop(GID,UID)
|
||||
|
||||
-- Remove own menu.
|
||||
if self.group[GID].player[UID].menu_own then
|
||||
missionCommands.removeItemForGroup(GID,self.group[GID].player[UID].menu_own)
|
||||
end
|
||||
-- Remove main menu.
|
||||
if self.player[id].menu_main then
|
||||
missionCommands.removeItem(self.player[id].menu_main)
|
||||
-- WARNING: Remove only if last human element of group
|
||||
|
||||
local countPlayerInGroup = 0
|
||||
for _ in pairs(self.group[GID].player) do countPlayerInGroup = countPlayerInGroup + 1 end
|
||||
|
||||
if self.group[GID].menu_main and countPlayerInGroup==1 then
|
||||
missionCommands.removeItemForGroup(GID,self.group[GID].menu_main)
|
||||
end
|
||||
|
||||
-- Remove player array.
|
||||
self.player[id]=nil
|
||||
self.group[GID].player[UID]=nil
|
||||
|
||||
end
|
||||
end
|
||||
@@ -518,80 +545,94 @@ end
|
||||
|
||||
--- Refreshes all player menues.
|
||||
-- @param #PSEUDOATC self.
|
||||
-- @param #number id Group id of player unit.
|
||||
function PSEUDOATC:MenuRefresh(id)
|
||||
self:F({id=id})
|
||||
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
function PSEUDOATC:MenuRefresh(GID,UID)
|
||||
self:F({GID=GID,UID=UID})
|
||||
-- Debug message.
|
||||
local text=string.format("Refreshing menues for player %s in group %s.", self.player[id].playername, self.player[id].groupname)
|
||||
local text=string.format("Refreshing menues for player %s in group %s.", self.group[GID].player[UID].playername, self.group[GID].player[UID].groupname)
|
||||
self:T(PSEUDOATC.id..text)
|
||||
MESSAGE:New(text,30):ToAllIf(self.Debug)
|
||||
|
||||
-- Clear menu.
|
||||
self:MenuClear(id)
|
||||
self:MenuClear(GID,UID)
|
||||
|
||||
-- Create list of nearby airports.
|
||||
self:LocalAirports(id)
|
||||
self:LocalAirports(GID,UID)
|
||||
|
||||
-- Create submenu Local Airports.
|
||||
self:MenuAirports(id)
|
||||
self:MenuAirports(GID,UID)
|
||||
|
||||
-- Create submenu Waypoints etc.
|
||||
self:MenuWaypoints(id)
|
||||
self:MenuWaypoints(GID,UID)
|
||||
|
||||
end
|
||||
|
||||
--- Create player menus.
|
||||
-- @param #PSEUDOATC self.
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
function PSEUDOATC:MenuCreatePlayer(GID,UID)
|
||||
self:F({GID=GID,UID=UID})
|
||||
-- Table for menu entries.
|
||||
local PlayerName=self.group[GID].player[UID].playername
|
||||
self.group[GID].player[UID].menu_own=missionCommands.addSubMenuForGroup(GID, PlayerName, self.group[GID].menu_main)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Clear player menus.
|
||||
-- @param #PSEUDOATC self.
|
||||
-- @param #number id Group id of player unit.
|
||||
function PSEUDOATC:MenuClear(id)
|
||||
self:F(id)
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
function PSEUDOATC:MenuClear(GID,UID)
|
||||
self:F({GID=GID,UID=UID})
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("Clearing menus for player %s in group %s.", self.player[id].playername, self.player[id].groupname)
|
||||
local text=string.format("Clearing menus for player %s in group %s.", self.group[GID].player[UID].playername, self.group[GID].player[UID].groupname)
|
||||
self:T(PSEUDOATC.id..text)
|
||||
MESSAGE:New(text,30):ToAllIf(self.Debug)
|
||||
|
||||
-- Delete Airports menu.
|
||||
if self.player[id].menu_airports then
|
||||
missionCommands.removeItemForGroup(id, self.player[id].menu_airports)
|
||||
self.player[id].menu_airports=nil
|
||||
if self.group[GID].player[UID].menu_airports then
|
||||
missionCommands.removeItemForGroup(GID, self.group[GID].player[UID].menu_airports)
|
||||
self.group[GID].player[UID].menu_airports=nil
|
||||
else
|
||||
self:T2(PSEUDOATC.id.."No airports to clear menus.")
|
||||
end
|
||||
|
||||
-- Delete waypoints menu.
|
||||
if self.player[id].menu_waypoints then
|
||||
missionCommands.removeItemForGroup(id, self.player[id].menu_waypoints)
|
||||
self.player[id].menu_waypoints=nil
|
||||
if self.group[GID].player[UID].menu_waypoints then
|
||||
missionCommands.removeItemForGroup(GID, self.group[GID].player[UID].menu_waypoints)
|
||||
self.group[GID].player[UID].menu_waypoints=nil
|
||||
end
|
||||
|
||||
-- Delete report alt until touchdown menu command.
|
||||
if self.player[id].menu_reportalt then
|
||||
missionCommands.removeItemForGroup(id, self.player[id].menu_reportalt)
|
||||
self.player[id].menu_reportalt=nil
|
||||
if self.group[GID].player[UID].menu_reportalt then
|
||||
missionCommands.removeItemForGroup(GID, self.group[GID].player[UID].menu_reportalt)
|
||||
self.group[GID].player[UID].menu_reportalt=nil
|
||||
end
|
||||
|
||||
-- Delete request current alt menu command.
|
||||
if self.player[id].menu_requestalt then
|
||||
missionCommands.removeItemForGroup(id, self.player[id].menu_requestalt)
|
||||
self.player[id].menu_requestalt=nil
|
||||
if self.group[GID].player[UID].menu_requestalt then
|
||||
missionCommands.removeItemForGroup(GID, self.group[GID].player[UID].menu_requestalt)
|
||||
self.group[GID].player[UID].menu_requestalt=nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Create "F10/Pseudo ATC/Local Airports/Airport Name/" menu items each containing weather report and BR request.
|
||||
-- @param #PSEUDOATC self
|
||||
-- @param #number id Group id of player unit for which menues are created.
|
||||
function PSEUDOATC:MenuAirports(id)
|
||||
self:F(id)
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
function PSEUDOATC:MenuAirports(GID,UID)
|
||||
self:F({GID=GID,UID=UID})
|
||||
|
||||
-- Table for menu entries.
|
||||
self.player[id].menu_airports=missionCommands.addSubMenuForGroup(id, "Local Airports", self.player[id].menu_main)
|
||||
self.group[GID].player[UID].menu_airports=missionCommands.addSubMenuForGroup(GID, "Local Airports", self.group[GID].player[UID].menu_own)
|
||||
|
||||
local i=0
|
||||
for _,airport in pairs(self.player[id].airports) do
|
||||
for _,airport in pairs(self.group[GID].player[UID].airports) do
|
||||
|
||||
i=i+1
|
||||
if i > 10 then
|
||||
@@ -603,37 +644,38 @@ function PSEUDOATC:MenuAirports(id)
|
||||
local pos=AIRBASE:FindByName(name):GetCoordinate()
|
||||
|
||||
--F10menu_ATC_airports[ID][name] = missionCommands.addSubMenuForGroup(ID, name, F10menu_ATC)
|
||||
local submenu=missionCommands.addSubMenuForGroup(id, name, self.player[id].menu_airports)
|
||||
local submenu=missionCommands.addSubMenuForGroup(GID, name, self.group[GID].player[UID].menu_airports)
|
||||
|
||||
-- Create menu reporting commands
|
||||
missionCommands.addCommandForGroup(id, "Weather Report", submenu, self.ReportWeather, self, id, pos, name)
|
||||
missionCommands.addCommandForGroup(id, "Request BR", submenu, self.ReportBR, self, id, pos, name)
|
||||
missionCommands.addCommandForGroup(GID, "Weather Report", submenu, self.ReportWeather, self, GID, UID, pos, name)
|
||||
missionCommands.addCommandForGroup(GID, "Request BR", submenu, self.ReportBR, self, GID, UID, pos, name)
|
||||
|
||||
-- Debug message.
|
||||
self:T(string.format(PSEUDOATC.id.."Creating airport menu item %s for ID %d", name, id))
|
||||
self:T(string.format(PSEUDOATC.id.."Creating airport menu item %s for ID %d", name, GID))
|
||||
end
|
||||
end
|
||||
|
||||
--- Create "F10/Pseudo ATC/Waypoints/<Waypoint i> menu items.
|
||||
-- @param #PSEUDOATC self
|
||||
-- @param #number id Group id of player unit for which menues are created.
|
||||
function PSEUDOATC:MenuWaypoints(id)
|
||||
self:F(id)
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
function PSEUDOATC:MenuWaypoints(GID, UID)
|
||||
self:F({GID=GID, UID=UID})
|
||||
|
||||
-- Player unit and callsign.
|
||||
local unit=self.player[id].unit --Wrapper.Unit#UNIT
|
||||
local callsign=self.player[id].callsign
|
||||
-- local unit=self.group[GID].player[UID].unit --Wrapper.Unit#UNIT
|
||||
local callsign=self.group[GID].player[UID].callsign
|
||||
|
||||
-- Debug info.
|
||||
self:T(PSEUDOATC.id..string.format("Creating waypoint menu for %s (ID %d).", callsign, id))
|
||||
self:T(PSEUDOATC.id..string.format("Creating waypoint menu for %s (ID %d).", callsign, GID))
|
||||
|
||||
if #self.player[id].waypoints>0 then
|
||||
if #self.group[GID].player[UID].waypoints>0 then
|
||||
|
||||
-- F10/PseudoATC/Waypoints
|
||||
self.player[id].menu_waypoints=missionCommands.addSubMenuForGroup(id, "Waypoints", self.player[id].menu_main)
|
||||
self.group[GID].player[UID].menu_waypoints=missionCommands.addSubMenuForGroup(GID, "Waypoints", self.group[GID].player[UID].menu_own)
|
||||
|
||||
local j=0
|
||||
for i, wp in pairs(self.player[id].waypoints) do
|
||||
for i, wp in pairs(self.group[GID].player[UID].waypoints) do
|
||||
|
||||
-- Increase counter
|
||||
j=j+1
|
||||
@@ -647,16 +689,16 @@ function PSEUDOATC:MenuWaypoints(id)
|
||||
local name=string.format("Waypoint %d", i-1)
|
||||
|
||||
-- "F10/PseudoATC/Waypoints/Waypoint X"
|
||||
local submenu=missionCommands.addSubMenuForGroup(id, name, self.player[id].menu_waypoints)
|
||||
local submenu=missionCommands.addSubMenuForGroup(GID, name, self.group[GID].player[UID].menu_waypoints)
|
||||
|
||||
-- Menu commands for each waypoint "F10/PseudoATC/My Aircraft (callsign)/Waypoints/Waypoint X/<Commands>"
|
||||
missionCommands.addCommandForGroup(id, "Weather Report", submenu, self.ReportWeather, self, id, pos, name)
|
||||
missionCommands.addCommandForGroup(id, "Request BR", submenu, self.ReportBR, self, id, pos, name)
|
||||
missionCommands.addCommandForGroup(GID, "Weather Report", submenu, self.ReportWeather, self, GID, UID, pos, name)
|
||||
missionCommands.addCommandForGroup(GID, "Request BR", submenu, self.ReportBR, self, GID, UID, pos, name)
|
||||
end
|
||||
end
|
||||
|
||||
self.player[id].menu_reportalt = missionCommands.addCommandForGroup(id, "Talk me down", self.player[id].menu_main, self.AltidudeTimerToggle, self, id)
|
||||
self.player[id].menu_requestalt = missionCommands.addCommandForGroup(id, "Request altitude", self.player[id].menu_main, self.ReportHeight, self, id)
|
||||
self.group[GID].player[UID].menu_reportalt = missionCommands.addCommandForGroup(GID, "Talk me down", self.group[GID].player[UID].menu_own, self.AltidudeTimerToggle, self, GID, UID)
|
||||
self.group[GID].player[UID].menu_requestalt = missionCommands.addCommandForGroup(GID, "Request altitude", self.group[GID].player[UID].menu_own, self.ReportHeight, self, GID, UID)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -664,14 +706,15 @@ end
|
||||
|
||||
--- Weather Report. Report pressure QFE/QNH, temperature, wind at certain location.
|
||||
-- @param #PSEUDOATC self
|
||||
-- @param #number id Group id to which the report is delivered.
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
-- @param Core.Point#COORDINATE position Coordinates at which the pressure is measured.
|
||||
-- @param #string location Name of the location at which the pressure is measured.
|
||||
function PSEUDOATC:ReportWeather(id, position, location)
|
||||
self:F({id=id, position=position, location=location})
|
||||
function PSEUDOATC:ReportWeather(GID, UID, position, location)
|
||||
self:F({GID=GID, UID=UID, position=position, location=location})
|
||||
|
||||
-- Player unit system settings.
|
||||
local settings=_DATABASE:GetPlayerSettings(self.player[id].playername) or _SETTINGS --Core.Settings#SETTINGS
|
||||
local settings=_DATABASE:GetPlayerSettings(self.group[GID].player[UID].playername) or _SETTINGS --Core.Settings#SETTINGS
|
||||
|
||||
local text=string.format("Local weather at %s:\n", location)
|
||||
|
||||
@@ -723,23 +766,24 @@ function PSEUDOATC:ReportWeather(id, position, location)
|
||||
end
|
||||
|
||||
-- Message text.
|
||||
local text=text..string.format("Wind from %s at %s (%s).", Ds, Vs, Bd)
|
||||
local text=text..string.format("%s, Wind from %s at %s (%s).", self.group[GID].player[UID].playername, Ds, Vs, Bd)
|
||||
|
||||
-- Send message
|
||||
self:_DisplayMessageToGroup(self.player[id].unit, text, self.mdur, true)
|
||||
self:_DisplayMessageToGroup(self.group[GID].player[UID].unit, text, self.mdur, true)
|
||||
|
||||
end
|
||||
|
||||
--- Report absolute bearing and range form player unit to airport.
|
||||
-- @param #PSEUDOATC self
|
||||
-- @param #number id Group id to the report is delivered.
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
-- @param Core.Point#COORDINATE position Coordinates at which the pressure is measured.
|
||||
-- @param #string location Name of the location at which the pressure is measured.
|
||||
function PSEUDOATC:ReportBR(id, position, location)
|
||||
self:F({id=id, position=position, location=location})
|
||||
function PSEUDOATC:ReportBR(GID, UID, position, location)
|
||||
self:F({GID=GID, UID=UID, position=position, location=location})
|
||||
|
||||
-- Current coordinates.
|
||||
local unit=self.player[id].unit --Wrapper.Unit#UNIT
|
||||
local unit=self.group[GID].player[UID].unit --Wrapper.Unit#UNIT
|
||||
local coord=unit:GetCoordinate()
|
||||
|
||||
-- Direction vector from current position (coord) to target (position).
|
||||
@@ -752,7 +796,7 @@ function PSEUDOATC:ReportBR(id, position, location)
|
||||
local Bs=string.format('%03d°', angle)
|
||||
|
||||
-- Settings.
|
||||
local settings=_DATABASE:GetPlayerSettings(self.player[id].playername) or _SETTINGS --Core.Settings#SETTINGS
|
||||
local settings=_DATABASE:GetPlayerSettings(self.group[GID].player[UID].playername) or _SETTINGS --Core.Settings#SETTINGS
|
||||
|
||||
|
||||
local Rs=string.format("%.1f NM", UTILS.MetersToNM(range))
|
||||
@@ -763,18 +807,20 @@ function PSEUDOATC:ReportBR(id, position, location)
|
||||
-- Message text.
|
||||
local text=string.format("%s: Bearing %s, Range %s.", location, Bs, Rs)
|
||||
|
||||
-- Send message to player group.
|
||||
MESSAGE:New(text, self.mdur):ToGroup(self.player[id].group)
|
||||
-- Send message
|
||||
self:_DisplayMessageToGroup(self.group[GID].player[UID].unit, text, self.mdur, true)
|
||||
|
||||
end
|
||||
|
||||
--- Report altitude above ground level of player unit.
|
||||
-- @param #PSEUDOATC self
|
||||
-- @param #number id Group id to the report is delivered.
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
-- @param #number dt (Optional) Duration the message is displayed.
|
||||
-- @param #boolean _clear (Optional) Clear previouse messages.
|
||||
-- @return #number Altitude above ground.
|
||||
function PSEUDOATC:ReportHeight(id, dt, _clear)
|
||||
self:F({id=id, dt=dt})
|
||||
function PSEUDOATC:ReportHeight(GID, UID, dt, _clear)
|
||||
self:F({GID=GID, UID=UID, dt=dt})
|
||||
|
||||
local dt = dt or self.mdur
|
||||
if _clear==nil then
|
||||
@@ -791,7 +837,7 @@ function PSEUDOATC:ReportHeight(id, dt, _clear)
|
||||
end
|
||||
|
||||
-- Get height AGL.
|
||||
local unit=self.player[id].unit --Wrapper.Unit#UNIT
|
||||
local unit=self.group[GID].player[UID].unit --Wrapper.Unit#UNIT
|
||||
|
||||
if unit and unit:IsAlive() then
|
||||
|
||||
@@ -800,7 +846,7 @@ function PSEUDOATC:ReportHeight(id, dt, _clear)
|
||||
local callsign=unit:GetCallsign()
|
||||
|
||||
-- Settings.
|
||||
local settings=_DATABASE:GetPlayerSettings(self.player[id].playername) or _SETTINGS --Core.Settings#SETTINGS
|
||||
local settings=_DATABASE:GetPlayerSettings(self.group[GID].player[UID].playername) or _SETTINGS --Core.Settings#SETTINGS
|
||||
|
||||
-- Height string.
|
||||
local Hs=string.format("%d ft", UTILS.MetersToFeet(height))
|
||||
@@ -817,7 +863,7 @@ function PSEUDOATC:ReportHeight(id, dt, _clear)
|
||||
end
|
||||
|
||||
-- Send message to player group.
|
||||
self:_DisplayMessageToGroup(self.player[id].unit,_text, dt,_clear)
|
||||
self:_DisplayMessageToGroup(self.group[GID].player[UID].unit,_text, dt,_clear)
|
||||
|
||||
-- Return height
|
||||
return height
|
||||
@@ -830,47 +876,50 @@ end
|
||||
|
||||
--- Toggle report altitude reporting on/off.
|
||||
-- @param #PSEUDOATC self.
|
||||
-- @param #number id Group id of player unit.
|
||||
function PSEUDOATC:AltidudeTimerToggle(id)
|
||||
self:F(id)
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
function PSEUDOATC:AltidudeTimerToggle(GID,UID)
|
||||
self:F({GID=GID, UID=UID})
|
||||
|
||||
if self.player[id].altimerid then
|
||||
if self.group[GID].player[UID].altimerid then
|
||||
-- If the timer is on, we turn it off.
|
||||
self:AltitudeTimerStop(id)
|
||||
self:AltitudeTimerStop(GID, UID)
|
||||
else
|
||||
-- If the timer is off, we turn it on.
|
||||
self:AltitudeTimeStart(id)
|
||||
self:AltitudeTimeStart(GID, UID)
|
||||
end
|
||||
end
|
||||
|
||||
--- Start altitude reporting scheduler.
|
||||
-- @param #PSEUDOATC self.
|
||||
-- @param #number id Group id of player unit.
|
||||
function PSEUDOATC:AltitudeTimeStart(id)
|
||||
self:F(id)
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
function PSEUDOATC:AltitudeTimeStart(GID, UID)
|
||||
self:F({GID=GID, UID=UID})
|
||||
|
||||
-- Debug info.
|
||||
self:T(PSEUDOATC.id..string.format("Starting altitude report timer for player ID %d.", id))
|
||||
self:T(PSEUDOATC.id..string.format("Starting altitude report timer for player ID %d.", UID))
|
||||
|
||||
-- Start timer. Altitude is reported every ~3 seconds.
|
||||
self.player[id].altimer, self.player[id].altimerid=SCHEDULER:New(nil, self.ReportHeight, {self, id, 0.1, true}, 1, 3)
|
||||
self.group[GID].player[UID].altimer, self.group[GID].player[UID].altimerid=SCHEDULER:New(nil, self.ReportHeight, {self, GID, UID, 0.1, true}, 1, 3)
|
||||
end
|
||||
|
||||
--- Stop/destroy DCS scheduler function for reporting altitude.
|
||||
-- @param #PSEUDOATC self.
|
||||
-- @param #number id Group id of player unit.
|
||||
function PSEUDOATC:AltitudeTimerStop(id)
|
||||
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
function PSEUDOATC:AltitudeTimerStop(GID, UID)
|
||||
self:F({GID=GID,UID=UID})
|
||||
-- Debug info.
|
||||
self:T(PSEUDOATC.id..string.format("Stopping altitude report timer for player ID %d.", id))
|
||||
self:T(PSEUDOATC.id..string.format("Stopping altitude report timer for player ID %d.", UID))
|
||||
|
||||
-- Stop timer.
|
||||
if self.player[id].altimerid then
|
||||
self.player[id].altimer:Stop(self.player[id].altimerid)
|
||||
if self.group[GID].player[UID].altimerid then
|
||||
self.group[GID].player[UID].altimer:Stop(self.group[GID].player[UID].altimerid)
|
||||
end
|
||||
|
||||
self.player[id].altimer=nil
|
||||
self.player[id].altimerid=nil
|
||||
self.group[GID].player[UID].altimer=nil
|
||||
self.group[GID].player[UID].altimerid=nil
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -878,16 +927,17 @@ end
|
||||
|
||||
--- Create list of nearby airports sorted by distance to player unit.
|
||||
-- @param #PSEUDOATC self
|
||||
-- @param #number id Group id of player unit.
|
||||
function PSEUDOATC:LocalAirports(id)
|
||||
self:F(id)
|
||||
-- @param #number GID Group id of player unit.
|
||||
-- @param #number UID Unit id of player.
|
||||
function PSEUDOATC:LocalAirports(GID, UID)
|
||||
self:F({GID=GID, UID=UID})
|
||||
|
||||
-- Airports table.
|
||||
self.player[id].airports=nil
|
||||
self.player[id].airports={}
|
||||
self.group[GID].player[UID].airports=nil
|
||||
self.group[GID].player[UID].airports={}
|
||||
|
||||
-- Current player position.
|
||||
local pos=self.player[id].unit:GetCoordinate()
|
||||
local pos=self.group[GID].player[UID].unit:GetCoordinate()
|
||||
|
||||
-- Loop over coalitions.
|
||||
for i=0,2 do
|
||||
@@ -903,7 +953,7 @@ function PSEUDOATC:LocalAirports(id)
|
||||
local d=q:Get2DDistance(pos)
|
||||
|
||||
-- Add to table.
|
||||
table.insert(self.player[id].airports, {distance=d, name=name})
|
||||
table.insert(self.group[GID].player[UID].airports, {distance=d, name=name})
|
||||
|
||||
end
|
||||
end
|
||||
@@ -914,7 +964,7 @@ function PSEUDOATC:LocalAirports(id)
|
||||
end
|
||||
|
||||
-- Sort airports table w.r.t. distance to player.
|
||||
table.sort(self.player[id].airports, compare)
|
||||
table.sort(self.group[GID].player[UID].airports, compare)
|
||||
|
||||
end
|
||||
|
||||
@@ -992,3 +1042,5 @@ function PSEUDOATC:_myname(unitname)
|
||||
return string.format("%s (%s)", csign, pname)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -150,6 +150,8 @@
|
||||
-- @field #number parkingscanradius Radius in meters until which parking spots are scanned for obstacles like other units, statics or scenery.
|
||||
-- @field #boolean parkingscanscenery If true, area around parking spots is scanned for scenery objects. Default is false.
|
||||
-- @field #boolean parkingverysafe If true, parking spots are considered as non-free until a possible aircraft has left and taken off. Default false.
|
||||
-- @field #boolean despawnair If true, aircraft are despawned when they reach their destination zone. Default.
|
||||
-- @field #boolean eplrs If true, turn on EPLSR datalink for the RAT group.
|
||||
-- @extends Core.Spawn#SPAWN
|
||||
|
||||
--- Implements an easy to use way to randomly fill your map with AI aircraft.
|
||||
@@ -428,6 +430,8 @@ RAT={
|
||||
parkingscanradius=40, -- Scan radius.
|
||||
parkingscanscenery=false, -- Scan parking spots for scenery obstacles.
|
||||
parkingverysafe=false, -- Very safe option.
|
||||
despawnair=true,
|
||||
eplrs=false,
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -546,7 +550,7 @@ RAT.id="RAT | "
|
||||
--- RAT version.
|
||||
-- @list version
|
||||
RAT.version={
|
||||
version = "2.3.4",
|
||||
version = "2.3.8",
|
||||
print = true,
|
||||
}
|
||||
|
||||
@@ -717,6 +721,11 @@ function RAT:Spawn(naircraft)
|
||||
self.FLcruise=005*RAT.unit.FL2m
|
||||
end
|
||||
end
|
||||
|
||||
-- Enable helos to go to destinations 100 meters away.
|
||||
if self.category==RAT.cat.heli then
|
||||
self.mindist=50
|
||||
end
|
||||
|
||||
-- Run consistency checks.
|
||||
self:_CheckConsistency()
|
||||
@@ -1093,6 +1102,14 @@ function RAT:SetParkingSpotSafeOFF()
|
||||
return self
|
||||
end
|
||||
|
||||
--- Aircraft that reach their destination zone are not despawned. They will probably go the the nearest airbase and try to land.
|
||||
-- @param #RAT self
|
||||
-- @return #RAT RAT self object.
|
||||
function RAT:SetDespawnAirOFF()
|
||||
self.despawnair=false
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set takeoff type. Starting cold at airport, starting hot at airport, starting at runway, starting in the air.
|
||||
-- Default is "takeoff-coldorhot". So there is a 50% chance that the aircraft starts with cold engines and 50% that it starts with hot engines.
|
||||
-- @param #RAT self
|
||||
@@ -1627,6 +1644,19 @@ function RAT:Invisible()
|
||||
return self
|
||||
end
|
||||
|
||||
--- Turn EPLRS datalink on/off.
|
||||
-- @param #RAT self
|
||||
-- @param #boolean switch If true (or nil), turn EPLRS on.
|
||||
-- @return #RAT RAT self object.
|
||||
function RAT:SetEPLRS(switch)
|
||||
if switch==nil or switch==true then
|
||||
self.eplrs=true
|
||||
else
|
||||
self.eplrs=false
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- Aircraft are immortal.
|
||||
-- @param #RAT self
|
||||
-- @return #RAT RAT self object.
|
||||
@@ -1812,14 +1842,14 @@ function RAT:ATC_Delay(time)
|
||||
end
|
||||
|
||||
--- Set minimum distance between departure and destination. Default is 5 km.
|
||||
-- Minimum distance should not be smaller than maybe ~500 meters to ensure that departure and destination are different.
|
||||
-- Minimum distance should not be smaller than maybe ~100 meters to ensure that departure and destination are different.
|
||||
-- @param #RAT self
|
||||
-- @param #number dist Distance in km.
|
||||
-- @return #RAT RAT self object.
|
||||
function RAT:SetMinDistance(dist)
|
||||
self:F2(dist)
|
||||
-- Distance in meters. Absolute minimum is 500 m.
|
||||
self.mindist=math.max(500, dist*1000)
|
||||
self.mindist=math.max(100, dist*1000)
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -2149,6 +2179,11 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live
|
||||
self:_CommandImmortal(group, true)
|
||||
end
|
||||
|
||||
-- Set group to be immortal.
|
||||
if self.eplrs then
|
||||
group:CommandEPLRS(true, 1)
|
||||
end
|
||||
|
||||
-- Set ROE, default is "weapon hold".
|
||||
self:_SetROE(group, self.roe)
|
||||
|
||||
@@ -2446,7 +2481,7 @@ function RAT:_SetRoute(takeoff, landing, _departure, _destination, _waypoint)
|
||||
local VxCruiseMax
|
||||
if self.Vcruisemax then
|
||||
-- User input.
|
||||
VxCruiseMax = min(self.Vcruisemax, self.aircraft.Vmax)
|
||||
VxCruiseMax = math.min(self.Vcruisemax, self.aircraft.Vmax)
|
||||
else
|
||||
-- Max cruise speed 90% of Vmax or 900 km/h whichever is lower.
|
||||
VxCruiseMax = math.min(self.aircraft.Vmax*0.90, 250)
|
||||
@@ -3357,11 +3392,19 @@ function RAT:_GetAirportsOfMap()
|
||||
local _name=airbase:getName()
|
||||
local _myab=AIRBASE:FindByName(_name)
|
||||
|
||||
-- Add airport to table.
|
||||
table.insert(self.airports_map, _myab)
|
||||
if _myab then
|
||||
|
||||
local text="MOOSE: Airport ID = ".._myab:GetID().." and Name = ".._myab:GetName()..", Category = ".._myab:GetCategory()..", TypeName = ".._myab:GetTypeName()
|
||||
self:T(RAT.id..text)
|
||||
-- Add airport to table.
|
||||
table.insert(self.airports_map, _myab)
|
||||
|
||||
local text="MOOSE: Airport ID = ".._myab:GetID().." and Name = ".._myab:GetName()..", Category = ".._myab:GetCategory()..", TypeName = ".._myab:GetTypeName()
|
||||
self:T(RAT.id..text)
|
||||
|
||||
else
|
||||
|
||||
self:E(RAT.id..string.format("WARNING: Airbase %s does not exsist as MOOSE object!", tostring(_name)))
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -3599,13 +3642,18 @@ function RAT:Status(message, forID)
|
||||
|
||||
local text=string.format("Flight %s will be despawned NOW!", self.alias)
|
||||
self:T(RAT.id..text)
|
||||
-- Despawn old group.
|
||||
|
||||
-- Respawn group
|
||||
if (not self.norespawn) and (not self.respawn_after_takeoff) then
|
||||
local idx=self:GetSpawnIndexFromGroup(group)
|
||||
local coord=group:GetCoordinate()
|
||||
self:_Respawn(idx, coord, 0)
|
||||
end
|
||||
self:_Despawn(group, 0)
|
||||
|
||||
-- Despawn old group.
|
||||
if self.despawnair then
|
||||
self:_Despawn(group, 0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -5435,7 +5483,7 @@ function RAT:_ATCInit(airports_map)
|
||||
if not RAT.ATC.init then
|
||||
local text
|
||||
text="Starting RAT ATC.\nSimultanious = "..RAT.ATC.Nclearance.."\n".."Delay = "..RAT.ATC.delay
|
||||
self:T(RAT.id..text)
|
||||
BASE:T(RAT.id..text)
|
||||
RAT.ATC.init=true
|
||||
for _,ap in pairs(airports_map) do
|
||||
local name=ap:GetName()
|
||||
@@ -5458,7 +5506,7 @@ end
|
||||
-- @param #string name Group name of the flight.
|
||||
-- @param #string dest Name of the destination airport.
|
||||
function RAT:_ATCAddFlight(name, dest)
|
||||
self:T(string.format("%sATC %s: Adding flight %s with destination %s.", RAT.id, dest, name, dest))
|
||||
BASE:T(string.format("%sATC %s: Adding flight %s with destination %s.", RAT.id, dest, name, dest))
|
||||
RAT.ATC.flight[name]={}
|
||||
RAT.ATC.flight[name].destination=dest
|
||||
RAT.ATC.flight[name].Tarrive=-1
|
||||
@@ -5483,7 +5531,7 @@ end
|
||||
-- @param #string name Group name of the flight.
|
||||
-- @param #number time Time the fight first registered.
|
||||
function RAT:_ATCRegisterFlight(name, time)
|
||||
self:T(RAT.id.."Flight ".. name.." registered at ATC for landing clearance.")
|
||||
BASE:T(RAT.id.."Flight ".. name.." registered at ATC for landing clearance.")
|
||||
RAT.ATC.flight[name].Tarrive=time
|
||||
RAT.ATC.flight[name].holding=0
|
||||
end
|
||||
@@ -5514,7 +5562,7 @@ function RAT:_ATCStatus()
|
||||
|
||||
-- Aircraft is holding.
|
||||
local text=string.format("ATC %s: Flight %s is holding for %i:%02d. %s.", dest, name, hold/60, hold%60, busy)
|
||||
self:T(RAT.id..text)
|
||||
BASE:T(RAT.id..text)
|
||||
|
||||
elseif hold==RAT.ATC.onfinal then
|
||||
|
||||
@@ -5522,7 +5570,7 @@ function RAT:_ATCStatus()
|
||||
local Tfinal=Tnow-RAT.ATC.flight[name].Tonfinal
|
||||
|
||||
local text=string.format("ATC %s: Flight %s is on final. Waiting %i:%02d for landing event.", dest, name, Tfinal/60, Tfinal%60)
|
||||
self:T(RAT.id..text)
|
||||
BASE:T(RAT.id..text)
|
||||
|
||||
elseif hold==RAT.ATC.unregistered then
|
||||
|
||||
@@ -5530,7 +5578,7 @@ function RAT:_ATCStatus()
|
||||
--self:T(string.format("ATC %s: Flight %s is not registered yet (hold %d).", dest, name, hold))
|
||||
|
||||
else
|
||||
self:E(RAT.id.."ERROR: Unknown holding time in RAT:_ATCStatus().")
|
||||
BASE:E(RAT.id.."ERROR: Unknown holding time in RAT:_ATCStatus().")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5572,12 +5620,12 @@ function RAT:_ATCCheck()
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("ATC %s: Flight %s runway is busy. You are #%d of %d in landing queue. Your holding time is %i:%02d.", name, flight,qID, nqueue, RAT.ATC.flight[flight].holding/60, RAT.ATC.flight[flight].holding%60)
|
||||
self:T(RAT.id..text)
|
||||
BASE:T(RAT.id..text)
|
||||
|
||||
else
|
||||
|
||||
local text=string.format("ATC %s: Flight %s was cleared for landing. Your holding time was %i:%02d.", name, flight, RAT.ATC.flight[flight].holding/60, RAT.ATC.flight[flight].holding%60)
|
||||
self:T(RAT.id..text)
|
||||
BASE:T(RAT.id..text)
|
||||
|
||||
-- Clear flight for landing.
|
||||
RAT:_ATCClearForLanding(name, flight)
|
||||
@@ -5705,12 +5753,7 @@ function RAT:_ATCQueue()
|
||||
for k,v in ipairs(_queue) do
|
||||
table.insert(RAT.ATC.airport[airport].queue, v[1])
|
||||
end
|
||||
|
||||
--fvh
|
||||
--for k,v in ipairs(RAT.ATC.airport[airport].queue) do
|
||||
--print(string.format("queue #%02i flight \"%s\" holding %d seconds",k, v, RAT.ATC.flight[v].holding))
|
||||
--end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1635,7 +1635,7 @@ function SCORING:ReportScoreGroupSummary( PlayerGroup )
|
||||
self:F( { ReportMissions, ScoreMissions, PenaltyMissions } )
|
||||
|
||||
local PlayerScore = ScoreHits + ScoreDestroys + ScoreCoalitionChanges + ScoreGoals + ScoreMissions
|
||||
local PlayerPenalty = PenaltyHits + PenaltyDestroys + PenaltyCoalitionChanges + ScoreGoals + PenaltyMissions
|
||||
local PlayerPenalty = PenaltyHits + PenaltyDestroys + PenaltyCoalitionChanges + PenaltyGoals + PenaltyMissions
|
||||
|
||||
PlayerMessage =
|
||||
string.format( "Player '%s' Score = %d ( %d Score, -%d Penalties )",
|
||||
|
||||
@@ -57,8 +57,10 @@ SEAD = {
|
||||
-- -- Defends the Russian SA installations from SEAD attacks.
|
||||
-- SEAD_RU_SAM_Defenses = SEAD:New( { 'RU SA-6 Kub', 'RU SA-6 Defenses', 'RU MI-26 Troops', 'RU Attack Gori' } )
|
||||
function SEAD:New( SEADGroupPrefixes )
|
||||
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:F( SEADGroupPrefixes )
|
||||
self:F( SEADGroupPrefixes )
|
||||
|
||||
if type( SEADGroupPrefixes ) == 'table' then
|
||||
for SEADGroupPrefixID, SEADGroupPrefix in pairs( SEADGroupPrefixes ) do
|
||||
self.SEADGroupPrefixes[SEADGroupPrefix] = SEADGroupPrefix
|
||||
@@ -85,7 +87,29 @@ function SEAD:OnEventShot( EventData )
|
||||
local SEADWeaponName = EventData.WeaponName -- return weapon type
|
||||
-- Start of the 2nd loop
|
||||
self:T( "Missile Launched = " .. SEADWeaponName )
|
||||
if SEADWeaponName == "KH-58" or SEADWeaponName == "KH-25MPU" or SEADWeaponName == "AGM-88" or SEADWeaponName == "KH-31A" or SEADWeaponName == "KH-31P" then -- Check if the missile is a SEAD
|
||||
|
||||
--if SEADWeaponName == "KH-58" or SEADWeaponName == "KH-25MPU" or SEADWeaponName == "AGM-88" or SEADWeaponName == "KH-31A" or SEADWeaponName == "KH-31P" then -- Check if the missile is a SEAD
|
||||
if SEADWeaponName == "weapons.missiles.X_58" --Kh-58U anti-radiation missiles fired
|
||||
or
|
||||
SEADWeaponName == "weapons.missiles.Kh25MP_PRGS1VP" --Kh-25MP anti-radiation missiles fired
|
||||
or
|
||||
SEADWeaponName == "weapons.missiles.X_25MP" --Kh-25MPU anti-radiation missiles fired
|
||||
or
|
||||
SEADWeaponName == "weapons.missiles.X_28" --Kh-28 anti-radiation missiles fired
|
||||
or
|
||||
SEADWeaponName == "weapons.missiles.X_31P" --Kh-31P anti-radiation missiles fired
|
||||
or
|
||||
SEADWeaponName == "weapons.missiles.AGM_45A" --AGM-45A anti-radiation missiles fired
|
||||
or
|
||||
SEADWeaponName == "weapons.missiles.AGM_45" --AGM-45B anti-radiation missiles fired
|
||||
or
|
||||
SEADWeaponName == "weapons.missiles.AGM_88" --AGM-88C anti-radiation missiles fired
|
||||
or
|
||||
SEADWeaponName == "weapons.missiles.AGM_122" --AGM-122 Sidearm anti-radiation missiles fired
|
||||
or
|
||||
SEADWeaponName == "weapons.missiles.ALARM" --ALARM anti-radiation missiles fired
|
||||
then
|
||||
|
||||
local _evade = math.random (1,100) -- random number for chance of evading action
|
||||
local _targetMim = EventData.Weapon:getTarget() -- Identify target
|
||||
local _targetMimname = Unit.getName(_targetMim)
|
||||
@@ -111,47 +135,62 @@ function SEAD:OnEventShot( EventData )
|
||||
self:T( _targetskill )
|
||||
if self.TargetSkill[_targetskill] then
|
||||
if (_evade > self.TargetSkill[_targetskill].Evade) then
|
||||
|
||||
self:T( string.format("Evading, target skill " ..string.format(_targetskill)) )
|
||||
|
||||
local _targetMim = Weapon.getTarget(SEADWeapon)
|
||||
local _targetMimname = Unit.getName(_targetMim)
|
||||
local _targetMimgroup = Unit.getGroup(Weapon.getTarget(SEADWeapon))
|
||||
local _targetMimcont= _targetMimgroup:getController()
|
||||
|
||||
routines.groupRandomDistSelf(_targetMimgroup,300,'Diamond',250,20) -- move randomly
|
||||
|
||||
local SuppressedGroups1 = {} -- unit suppressed radar off for a random time
|
||||
|
||||
local function SuppressionEnd1(id)
|
||||
id.ctrl:setOption(AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.val.ALARM_STATE.GREEN)
|
||||
SuppressedGroups1[id.groupName] = nil
|
||||
end
|
||||
|
||||
local id = {
|
||||
groupName = _targetMimgroup,
|
||||
ctrl = _targetMimcont
|
||||
}
|
||||
|
||||
local delay1 = math.random(self.TargetSkill[_targetskill].DelayOff[1], self.TargetSkill[_targetskill].DelayOff[2])
|
||||
|
||||
if SuppressedGroups1[id.groupName] == nil then
|
||||
|
||||
SuppressedGroups1[id.groupName] = {
|
||||
SuppressionEndTime1 = timer.getTime() + delay1,
|
||||
SuppressionEndN1 = SuppressionEndCounter1 --Store instance of SuppressionEnd() scheduled function
|
||||
}
|
||||
}
|
||||
|
||||
Controller.setOption(_targetMimcont, AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.val.ALARM_STATE.GREEN)
|
||||
timer.scheduleFunction(SuppressionEnd1, id, SuppressedGroups1[id.groupName].SuppressionEndTime1) --Schedule the SuppressionEnd() function
|
||||
--trigger.action.outText( string.format("Radar Off " ..string.format(delay1)), 20)
|
||||
end
|
||||
|
||||
local SuppressedGroups = {}
|
||||
|
||||
local function SuppressionEnd(id)
|
||||
id.ctrl:setOption(AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.val.ALARM_STATE.RED)
|
||||
SuppressedGroups[id.groupName] = nil
|
||||
end
|
||||
|
||||
local id = {
|
||||
groupName = _targetMimgroup,
|
||||
ctrl = _targetMimcont
|
||||
}
|
||||
|
||||
local delay = math.random(self.TargetSkill[_targetskill].DelayOn[1], self.TargetSkill[_targetskill].DelayOn[2])
|
||||
|
||||
if SuppressedGroups[id.groupName] == nil then
|
||||
SuppressedGroups[id.groupName] = {
|
||||
SuppressionEndTime = timer.getTime() + delay,
|
||||
SuppressionEndN = SuppressionEndCounter --Store instance of SuppressionEnd() scheduled function
|
||||
}
|
||||
|
||||
timer.scheduleFunction(SuppressionEnd, id, SuppressedGroups[id.groupName].SuppressionEndTime) --Schedule the SuppressionEnd() function
|
||||
--trigger.action.outText( string.format("Radar On " ..string.format(delay)), 20)
|
||||
end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -356,11 +356,11 @@ do -- ZONE_CAPTURE_COALITION
|
||||
-- ZoneCaptureCoalition = ZONE_CAPTURE_COALITION:New( AttackZone, coalition.side.RED ) -- Create a new ZONE_CAPTURE_COALITION object of zone AttackZone with ownership RED coalition.
|
||||
-- ZoneCaptureCoalition:__Guard( 1 ) -- Start the Guarding of the AttackZone.
|
||||
--
|
||||
function ZONE_CAPTURE_COALITION:New( Zone, Coalition )
|
||||
function ZONE_CAPTURE_COALITION:New( Zone, Coalition, UnitCategories )
|
||||
|
||||
local self = BASE:Inherit( self, ZONE_GOAL_COALITION:New( Zone, Coalition ) ) -- #ZONE_CAPTURE_COALITION
|
||||
local self = BASE:Inherit( self, ZONE_GOAL_COALITION:New( Zone, Coalition, UnitCategories ) ) -- #ZONE_CAPTURE_COALITION
|
||||
|
||||
self:F( { Zone = Zone, Coalition = Coalition } )
|
||||
self:F( { Zone = Zone, Coalition = Coalition, UnitCategories = UnitCategories } )
|
||||
|
||||
do
|
||||
|
||||
@@ -545,6 +545,13 @@ do -- ZONE_CAPTURE_COALITION
|
||||
-- @param #ZONE_CAPTURE_COALITION self
|
||||
-- @param #number Delay
|
||||
|
||||
-- We check if a unit within the zone is hit.
|
||||
-- If it is, then we must move the zone to attack state.
|
||||
self:HandleEvent( EVENTS.Hit, self.OnEventHit )
|
||||
|
||||
-- ZoneGoal objects are added to the _DATABASE.ZONES_GOAL and SET_ZONE_GOAL sets.
|
||||
_EVENTDISPATCHER:CreateEventNewZoneGoal( self )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -552,6 +559,8 @@ do -- ZONE_CAPTURE_COALITION
|
||||
--- @param #ZONE_CAPTURE_COALITION self
|
||||
function ZONE_CAPTURE_COALITION:onenterCaptured()
|
||||
|
||||
self:F({"hello"})
|
||||
|
||||
self:GetParent( self, ZONE_CAPTURE_COALITION ).onenterCaptured( self )
|
||||
|
||||
self.Goal:Achieved()
|
||||
@@ -560,7 +569,7 @@ do -- ZONE_CAPTURE_COALITION
|
||||
|
||||
function ZONE_CAPTURE_COALITION:IsGuarded()
|
||||
|
||||
local IsGuarded = self.Zone:IsAllInZoneOfCoalition( self.Coalition )
|
||||
local IsGuarded = self:IsAllInZoneOfCoalition( self.Coalition )
|
||||
self:F( { IsGuarded = IsGuarded } )
|
||||
return IsGuarded
|
||||
end
|
||||
@@ -568,7 +577,7 @@ do -- ZONE_CAPTURE_COALITION
|
||||
|
||||
function ZONE_CAPTURE_COALITION:IsEmpty()
|
||||
|
||||
local IsEmpty = self.Zone:IsNoneInZone()
|
||||
local IsEmpty = self:IsNoneInZone()
|
||||
self:F( { IsEmpty = IsEmpty } )
|
||||
return IsEmpty
|
||||
end
|
||||
@@ -576,7 +585,7 @@ do -- ZONE_CAPTURE_COALITION
|
||||
|
||||
function ZONE_CAPTURE_COALITION:IsCaptured()
|
||||
|
||||
local IsCaptured = self.Zone:IsAllInZoneOfOtherCoalition( self.Coalition )
|
||||
local IsCaptured = self:IsAllInZoneOfOtherCoalition( self.Coalition )
|
||||
self:F( { IsCaptured = IsCaptured } )
|
||||
return IsCaptured
|
||||
end
|
||||
@@ -584,7 +593,7 @@ do -- ZONE_CAPTURE_COALITION
|
||||
|
||||
function ZONE_CAPTURE_COALITION:IsAttacked()
|
||||
|
||||
local IsAttacked = self.Zone:IsSomeInZoneOfCoalition( self.Coalition )
|
||||
local IsAttacked = self:IsSomeInZoneOfCoalition( self.Coalition )
|
||||
self:F( { IsAttacked = IsAttacked } )
|
||||
return IsAttacked
|
||||
end
|
||||
@@ -595,7 +604,7 @@ do -- ZONE_CAPTURE_COALITION
|
||||
-- @param #ZONE_CAPTURE_COALITION self
|
||||
function ZONE_CAPTURE_COALITION:Mark()
|
||||
|
||||
local Coord = self.Zone:GetCoordinate()
|
||||
local Coord = self:GetCoordinate()
|
||||
local ZoneName = self:GetZoneName()
|
||||
local State = self:GetState()
|
||||
|
||||
@@ -634,11 +643,12 @@ do -- ZONE_CAPTURE_COALITION
|
||||
|
||||
--self:GetParent( self ):onenterCaptured()
|
||||
|
||||
local NewCoalition = self.Zone:GetScannedCoalition()
|
||||
local NewCoalition = self:GetScannedCoalition()
|
||||
self:F( { NewCoalition = NewCoalition } )
|
||||
self:SetCoalition( NewCoalition )
|
||||
|
||||
self:Mark()
|
||||
self.Goal:Achieved()
|
||||
end
|
||||
|
||||
|
||||
@@ -666,14 +676,14 @@ do -- ZONE_CAPTURE_COALITION
|
||||
--BASE:GetParent( self ).onafterGuard( self )
|
||||
|
||||
if not self.SmokeScheduler then
|
||||
self.SmokeScheduler = self:ScheduleRepeat( 1, 1, 0.1, nil, self.StatusSmoke, self )
|
||||
self.SmokeScheduler = self:ScheduleRepeat( self.StartInterval, self.RepeatInterval, 0.1, nil, self.StatusSmoke, self )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ZONE_CAPTURE_COALITION:IsCaptured()
|
||||
|
||||
local IsCaptured = self.Zone:IsAllInZoneOfOtherCoalition( self.Coalition )
|
||||
local IsCaptured = self:IsAllInZoneOfOtherCoalition( self.Coalition )
|
||||
self:F( { IsCaptured = IsCaptured } )
|
||||
return IsCaptured
|
||||
end
|
||||
@@ -681,7 +691,7 @@ do -- ZONE_CAPTURE_COALITION
|
||||
|
||||
function ZONE_CAPTURE_COALITION:IsAttacked()
|
||||
|
||||
local IsAttacked = self.Zone:IsSomeInZoneOfCoalition( self.Coalition )
|
||||
local IsAttacked = self:IsSomeInZoneOfCoalition( self.Coalition )
|
||||
self:F( { IsAttacked = IsAttacked } )
|
||||
return IsAttacked
|
||||
end
|
||||
@@ -737,13 +747,13 @@ do -- ZONE_CAPTURE_COALITION
|
||||
--
|
||||
function ZONE_CAPTURE_COALITION:Start( StartInterval, RepeatInterval )
|
||||
|
||||
StartInterval = StartInterval or 15
|
||||
RepeatInterval = RepeatInterval or 15
|
||||
self.StartInterval = StartInterval or 15
|
||||
self.RepeatInterval = RepeatInterval or 15
|
||||
|
||||
if self.ScheduleStatusZone then
|
||||
self:ScheduleStop( self.ScheduleStatusZone )
|
||||
end
|
||||
self.ScheduleStatusZone = self:ScheduleRepeat( StartInterval, RepeatInterval, 0.1, nil, self.StatusZone, self )
|
||||
self.ScheduleStatusZone = self:ScheduleRepeat( self.StartInterval, self.RepeatInterval, 1.5, nil, self.StatusZone, self )
|
||||
end
|
||||
|
||||
|
||||
@@ -789,5 +799,20 @@ do -- ZONE_CAPTURE_COALITION
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #ZONE_CAPTURE_COALITION self
|
||||
-- @param Core.Event#EVENTDATA EventData The event data.
|
||||
function ZONE_CAPTURE_COALITION:OnEventHit( EventData )
|
||||
|
||||
local UnitHit = EventData.TgtUnit
|
||||
|
||||
if UnitHit then
|
||||
if UnitHit:IsInZone( self ) then
|
||||
self:Attack()
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -44,14 +44,13 @@ do -- Zone
|
||||
|
||||
--- ZONE_GOAL Constructor.
|
||||
-- @param #ZONE_GOAL self
|
||||
-- @param Core.Zone#ZONE_BASE Zone A @{Zone} object with the goal to be achieved.
|
||||
-- @param Core.Zone#ZONE_RADIUS Zone A @{Zone} object with the goal to be achieved.
|
||||
-- @return #ZONE_GOAL
|
||||
function ZONE_GOAL:New( Zone )
|
||||
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #ZONE_GOAL
|
||||
local self = BASE:Inherit( self, ZONE_RADIUS:New( Zone:GetName(), Zone:GetVec2(), Zone:GetRadius() ) ) -- #ZONE_GOAL
|
||||
self:F( { Zone = Zone } )
|
||||
|
||||
self.Zone = Zone -- Core.Zone#ZONE_BASE
|
||||
self.Goal = GOAL:New()
|
||||
|
||||
self.SmokeTime = nil
|
||||
@@ -67,6 +66,7 @@ do -- Zone
|
||||
-- @param Wrapper.Unit#UNIT DestroyedUnit The destroyed unit.
|
||||
-- @param #string PlayerName The name of the player.
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -74,7 +74,7 @@ do -- Zone
|
||||
-- @param #ZONE_GOAL self
|
||||
-- @return Core.Zone#ZONE_BASE
|
||||
function ZONE_GOAL:GetZone()
|
||||
return self.Zone
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ do -- Zone
|
||||
-- @param #ZONE_GOAL self
|
||||
-- @return #string
|
||||
function ZONE_GOAL:GetZoneName()
|
||||
return self.Zone:GetName()
|
||||
return self:GetName()
|
||||
end
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ do -- Zone
|
||||
-- @param #ZONE_GOAL self
|
||||
-- @param #SMOKECOLOR.Color FlareColor
|
||||
function ZONE_GOAL:Flare( FlareColor )
|
||||
self.Zone:FlareZone( FlareColor, math.random( 1, 360 ) )
|
||||
self:FlareZone( FlareColor, math.random( 1, 360 ) )
|
||||
end
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ do -- Zone
|
||||
|
||||
if self.SmokeTime == nil or self.SmokeTime + 300 <= CurrentTime then
|
||||
if self.SmokeColor then
|
||||
self.Zone:GetCoordinate():Smoke( self.SmokeColor )
|
||||
self:GetCoordinate():Smoke( self.SmokeColor )
|
||||
--self.SmokeColor = nil
|
||||
self.SmokeTime = CurrentTime
|
||||
end
|
||||
@@ -147,11 +147,9 @@ do -- Zone
|
||||
|
||||
local Vec3 = EventData.IniDCSUnit:getPosition().p
|
||||
self:F( { Vec3 = Vec3 } )
|
||||
local ZoneGoal = self:GetZone()
|
||||
self:F({ZoneGoal})
|
||||
|
||||
if EventData.IniDCSUnit then
|
||||
if ZoneGoal:IsVec3InZone(Vec3) then
|
||||
if self:IsVec3InZone(Vec3) then
|
||||
local PlayerHits = _DATABASE.HITS[EventData.IniUnitName]
|
||||
if PlayerHits then
|
||||
for PlayerName, PlayerHit in pairs( PlayerHits.Players or {} ) do
|
||||
|
||||
@@ -104,7 +104,7 @@ do -- ZoneGoal
|
||||
local State = self:GetState()
|
||||
self:F( { State = self:GetState() } )
|
||||
|
||||
self.Zone:Scan( { Object.Category.UNIT, Object.Category.STATIC } )
|
||||
self:Scan( { Object.Category.UNIT, Object.Category.STATIC } )
|
||||
|
||||
end
|
||||
|
||||
|
||||
125
Moose Development/Moose/Modules.lua
Normal file
125
Moose Development/Moose/Modules.lua
Normal file
@@ -0,0 +1,125 @@
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/Enums.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/Routines.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/Utils.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Core/Base.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/UserFlag.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/UserSound.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Report.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Scheduler.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/ScheduleDispatcher.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Event.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Settings.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Menu.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Zone.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Zone_Detection.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Database.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Set.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Point.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Velocity.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Message.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Fsm.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Radio.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/RadioQueue.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/RadioSpeech.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Spawn.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/SpawnStatic.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Goal.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Spot.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Object.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Identifiable.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Positionable.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Controllable.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Group.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Unit.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Client.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Static.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Airbase.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Scenery.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Cargo/Cargo.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Cargo/CargoUnit.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Cargo/CargoSlingload.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Cargo/CargoCrate.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Cargo/CargoGroup.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Scoring.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/CleanUp.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Movement.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Sead.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Escort.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/MissileTrainer.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/ATC_Ground.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Detection.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/DetectionZones.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Designate.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/RAT.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Range.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/ZoneGoal.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/ZoneGoalCoalition.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/ZoneCaptureCoalition.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Artillery.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Suppression.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/PseudoATC.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Warehouse.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Functional/Fox.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Ops/Airboss.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Ops/RecoveryTanker.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Ops/RescueHelo.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Ops/ATIS.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Balancer.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Air.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Air_Patrol.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Air_Engage.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_A2A_Patrol.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_A2A_Cap.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_A2A_Gci.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_A2A_Dispatcher.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_A2G_BAI.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_A2G_CAS.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_A2G_SEAD.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_A2G_Dispatcher.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Patrol.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cap.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cas.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Bai.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Formation.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Escort.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Escort_Request.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Escort_Dispatcher.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Escort_Dispatcher_Request.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cargo.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cargo_APC.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cargo_Helicopter.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cargo_Airplane.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cargo_Dispatcher.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cargo_Dispatcher_APC.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cargo_Dispatcher_Helicopter.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/AI/AI_Cargo_Dispatcher_Airplane.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Actions/Act_Assign.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Actions/Act_Route.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Actions/Act_Account.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Actions/Act_Assist.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/CommandCenter.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Mission.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/TaskInfo.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_Manager.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/DetectionManager.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_A2G_Dispatcher.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_A2G.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_A2A_Dispatcher.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_A2A.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_Cargo.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_Cargo_Transport.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_Cargo_CSAR.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_Cargo_Dispatcher.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_Capture_Zone.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Tasking/Task_Capture_Dispatcher.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Globals.lua' )
|
||||
1856
Moose Development/Moose/Ops/ATIS.lua
Normal file
1856
Moose Development/Moose/Ops/ATIS.lua
Normal file
File diff suppressed because it is too large
Load Diff
18007
Moose Development/Moose/Ops/Airboss.lua
Normal file
18007
Moose Development/Moose/Ops/Airboss.lua
Normal file
File diff suppressed because it is too large
Load Diff
1691
Moose Development/Moose/Ops/RecoveryTanker.lua
Normal file
1691
Moose Development/Moose/Ops/RecoveryTanker.lua
Normal file
File diff suppressed because it is too large
Load Diff
1296
Moose Development/Moose/Ops/RescueHelo.lua
Normal file
1296
Moose Development/Moose/Ops/RescueHelo.lua
Normal file
File diff suppressed because it is too large
Load Diff
@@ -144,6 +144,25 @@
|
||||
-- This is done by using the method @{#COMMANDCENTER.SetReferenceZones}().
|
||||
-- For the moment, only one Reference Zone class can be specified, but in the future, more classes will become possible.
|
||||
--
|
||||
-- ## 7. Tasks.
|
||||
--
|
||||
-- ### 7.1. Automatically assign tasks.
|
||||
--
|
||||
-- One of the most important roles of the command center is the management of tasks.
|
||||
-- The command center can assign automatically tasks to the players using the @{Tasking.CommandCenter#COMMANDCENTER.SetAutoAssignTasks}() method.
|
||||
-- When this method is used with a parameter true; the command center will scan at regular intervals which players in a slot are not having a task assigned.
|
||||
-- For those players; the tasking is enabled to assign automatically a task.
|
||||
-- An Assign Menu will be accessible for the player under the command center menu, to configure the automatic tasking to switched on or off.
|
||||
--
|
||||
-- ### 7.2. Automatically accept assigned tasks.
|
||||
--
|
||||
-- When a task is assigned; the mission designer can decide if players are immediately assigned to the task; or they can accept/reject the assigned task.
|
||||
-- Use the method @{Tasking.CommandCenter#COMMANDCENTER.SetAutoAcceptTasks}() to configure this behaviour.
|
||||
-- If the tasks are not automatically accepted; the player will receive a message that he needs to access the command center menu and
|
||||
-- choose from 2 added menu options either to accept or reject the assigned task within 30 seconds.
|
||||
-- If the task is not accepted within 30 seconds; the task will be cancelled and a new task will be assigned.
|
||||
--
|
||||
--
|
||||
-- @field #COMMANDCENTER
|
||||
COMMANDCENTER = {
|
||||
ClassName = "COMMANDCENTER",
|
||||
@@ -156,6 +175,14 @@ COMMANDCENTER = {
|
||||
CommunicationMode = "80",
|
||||
}
|
||||
|
||||
|
||||
--- @type COMMANDCENTER.AutoAssignMethods
|
||||
COMMANDCENTER.AutoAssignMethods = {
|
||||
["Random"] = 1,
|
||||
["Distance"] = 2,
|
||||
["Priority"] = 3,
|
||||
}
|
||||
|
||||
--- The constructor takes an IDENTIFIABLE as the HQ command center.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @param Wrapper.Positionable#POSITIONABLE CommandCenterPositionable
|
||||
@@ -169,21 +196,24 @@ function COMMANDCENTER:New( CommandCenterPositionable, CommandCenterName )
|
||||
self.CommandCenterName = CommandCenterName or CommandCenterPositionable:GetName()
|
||||
self.CommandCenterCoalition = CommandCenterPositionable:GetCoalition()
|
||||
|
||||
self.AutoAssignTasks = false
|
||||
|
||||
self.Missions = {}
|
||||
|
||||
self:SetAutoAssignTasks( false )
|
||||
self:SetAutoAcceptTasks( true )
|
||||
self:SetAutoAssignMethod( COMMANDCENTER.AutoAssignMethods.Distance )
|
||||
self:SetFlashStatus( false )
|
||||
|
||||
self:HandleEvent( EVENTS.Birth,
|
||||
--- @param #COMMANDCENTER self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function( self, EventData )
|
||||
if EventData.IniObjectCategory == 1 then
|
||||
local EventGroup = GROUP:Find( EventData.IniDCSGroup )
|
||||
self:E( { CommandCenter = self:GetName(), EventGroup = EventGroup:GetName(), HasGroup = self:HasGroup( EventGroup ), EventData = EventData } )
|
||||
if EventGroup and self:HasGroup( EventGroup ) then
|
||||
--self:E( { CommandCenter = self:GetName(), EventGroup = EventGroup:GetName(), HasGroup = self:HasGroup( EventGroup ), EventData = EventData } )
|
||||
if EventGroup and EventGroup:IsAlive() and self:HasGroup( EventGroup ) then
|
||||
local CommandCenterMenu = MENU_GROUP:New( EventGroup, self:GetText() )
|
||||
local MenuReporting = MENU_GROUP:New( EventGroup, "Missions Reports", CommandCenterMenu )
|
||||
local MenuMissionsSummary = MENU_GROUP_COMMAND:New( EventGroup, "Missions Status Report", MenuReporting, self.ReportMissionsStatus, self, EventGroup )
|
||||
local MenuMissionsSummary = MENU_GROUP_COMMAND:New( EventGroup, "Missions Status Report", MenuReporting, self.ReportSummary, self, EventGroup )
|
||||
local MenuMissionsDetails = MENU_GROUP_COMMAND:New( EventGroup, "Missions Players Report", MenuReporting, self.ReportMissionsPlayers, self, EventGroup )
|
||||
self:ReportSummary( EventGroup )
|
||||
local PlayerUnit = EventData.IniUnit
|
||||
@@ -442,7 +472,7 @@ function COMMANDCENTER:GetMenu( TaskGroup )
|
||||
self.CommandCenterMenus[TaskGroup] = CommandCenterMenu
|
||||
|
||||
if self.AutoAssignTasks == false then
|
||||
local AssignTaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Assign Task", CommandCenterMenu, self.AssignRandomTask, self, TaskGroup ):SetTime(MenuTime):SetTag("AutoTask")
|
||||
local AssignTaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Assign Task", CommandCenterMenu, self.AssignTask, self, TaskGroup ):SetTime(MenuTime):SetTag("AutoTask")
|
||||
end
|
||||
CommandCenterMenu:Remove( MenuTime, "AutoTask" )
|
||||
|
||||
@@ -453,23 +483,43 @@ end
|
||||
--- Assigns a random task to a TaskGroup.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @return #COMMANDCENTER
|
||||
function COMMANDCENTER:AssignRandomTask( TaskGroup )
|
||||
function COMMANDCENTER:AssignTask( TaskGroup )
|
||||
|
||||
local Tasks = {}
|
||||
local AssignPriority = 99999999
|
||||
local AutoAssignMethod = self.AutoAssignMethod
|
||||
|
||||
for MissionID, Mission in pairs( self:GetMissions() ) do
|
||||
local Mission = Mission -- Tasking.Mission#MISSION
|
||||
local MissionTasks = Mission:GetGroupTasks( TaskGroup )
|
||||
for MissionTaskName, MissionTask in pairs( MissionTasks or {} ) do
|
||||
Tasks[#Tasks+1] = MissionTask
|
||||
local MissionTask = MissionTask -- Tasking.Task#TASK
|
||||
if MissionTask:IsStatePlanned() or MissionTask:IsStateReplanned() or MissionTask:IsStateAssigned() then
|
||||
local TaskPriority = MissionTask:GetAutoAssignPriority( self.AutoAssignMethod, self, TaskGroup )
|
||||
if TaskPriority < AssignPriority then
|
||||
AssignPriority = TaskPriority
|
||||
Tasks = {}
|
||||
end
|
||||
if TaskPriority == AssignPriority then
|
||||
Tasks[#Tasks+1] = MissionTask
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local Task = Tasks[ math.random( 1, #Tasks ) ] -- Tasking.Task#TASK
|
||||
|
||||
Task:SetAssignMethod( ACT_ASSIGN_MENU_ACCEPT:New( Task.TaskBriefing ) )
|
||||
|
||||
Task:AssignToGroup( TaskGroup )
|
||||
if Task then
|
||||
|
||||
self:I( "Assigning task " .. Task:GetName() .. " using auto assign method " .. self.AutoAssignMethod .. " to " .. TaskGroup:GetName() .. " with task priority " .. AssignPriority )
|
||||
|
||||
if not self.AutoAcceptTasks == true then
|
||||
Task:SetAutoAssignMethod( ACT_ASSIGN_MENU_ACCEPT:New( Task.TaskBriefing ) )
|
||||
end
|
||||
|
||||
Task:AssignToGroup( TaskGroup )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -498,29 +548,54 @@ end
|
||||
|
||||
|
||||
--- Automatically assigns tasks to all TaskGroups.
|
||||
-- One of the most important roles of the command center is the management of tasks.
|
||||
-- When this method is used with a parameter true; the command center will scan at regular intervals which players in a slot are not having a task assigned.
|
||||
-- For those players; the tasking is enabled to assign automatically a task.
|
||||
-- An Assign Menu will be accessible for the player under the command center menu, to configure the automatic tasking to switched on or off.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @param #boolean AutoAssign true for ON and false or nil for OFF.
|
||||
function COMMANDCENTER:SetAutoAssignTasks( AutoAssign )
|
||||
|
||||
self.AutoAssignTasks = AutoAssign or false
|
||||
|
||||
local GroupSet = self:AddGroups()
|
||||
|
||||
for GroupID, TaskGroup in pairs( GroupSet:GetSet() ) do
|
||||
local TaskGroup = TaskGroup -- Wrapper.Group#GROUP
|
||||
self:GetMenu( TaskGroup )
|
||||
end
|
||||
|
||||
if self.AutoAssignTasks == true then
|
||||
self:ScheduleRepeat( 10, 30, 0, nil, self.AssignTasks, self )
|
||||
else
|
||||
self:ScheduleStop( self.AssignTasks )
|
||||
end
|
||||
|
||||
self:SetCommandCenterMenu()
|
||||
|
||||
end
|
||||
|
||||
--- Automatically accept tasks for all TaskGroups.
|
||||
-- When a task is assigned; the mission designer can decide if players are immediately assigned to the task; or they can accept/reject the assigned task.
|
||||
-- If the tasks are not automatically accepted; the player will receive a message that he needs to access the command center menu and
|
||||
-- choose from 2 added menu options either to accept or reject the assigned task within 30 seconds.
|
||||
-- If the task is not accepted within 30 seconds; the task will be cancelled and a new task will be assigned.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @param #boolean AutoAccept true for ON and false or nil for OFF.
|
||||
function COMMANDCENTER:SetAutoAcceptTasks( AutoAccept )
|
||||
|
||||
self.AutoAcceptTasks = AutoAccept or false
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Define the method to be used to assign automatically a task from the available tasks in the mission.
|
||||
-- There are 3 types of methods that can be applied for the moment:
|
||||
--
|
||||
-- 1. Random - assigns a random task in the mission to the player.
|
||||
-- 2. Distance - assigns a task based on a distance evaluation from the player. The closest are to be assigned first.
|
||||
-- 3. Priority - assigns a task based on the priority as defined by the mission designer, using the SetTaskPriority parameter.
|
||||
--
|
||||
-- The different task classes implement the logic to determine the priority of automatic task assignment to a player, depending on one of the above methods.
|
||||
-- The method @{Tasking.Task#TASK.GetAutoAssignPriority} calculate the priority of the tasks to be assigned.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @param #COMMANDCENTER.AutoAssignMethods AutoAssignMethod A selection of an assign method from the COMMANDCENTER.AutoAssignMethods enumeration.
|
||||
function COMMANDCENTER:SetAutoAssignMethod( AutoAssignMethod )
|
||||
|
||||
self.AutoAssignMethod = AutoAssignMethod or COMMANDCENTER.AutoAssignMethods.Random
|
||||
|
||||
end
|
||||
|
||||
--- Automatically assigns tasks to all TaskGroups.
|
||||
-- @param #COMMANDCENTER self
|
||||
@@ -531,12 +606,16 @@ function COMMANDCENTER:AssignTasks()
|
||||
for GroupID, TaskGroup in pairs( GroupSet:GetSet() ) do
|
||||
local TaskGroup = TaskGroup -- Wrapper.Group#GROUP
|
||||
|
||||
if self:IsGroupAssigned( TaskGroup ) then
|
||||
else
|
||||
-- Only groups with planes or helicopters will receive automatic tasks.
|
||||
-- TODO Workaround DCS-BUG-3 - https://github.com/FlightControl-Master/MOOSE/issues/696
|
||||
if TaskGroup:IsAir() then
|
||||
self:AssignRandomTask( TaskGroup )
|
||||
if TaskGroup:IsAlive() then
|
||||
self:GetMenu( TaskGroup )
|
||||
|
||||
if self:IsGroupAssigned( TaskGroup ) then
|
||||
else
|
||||
-- Only groups with planes or helicopters will receive automatic tasks.
|
||||
-- TODO Workaround DCS-BUG-3 - https://github.com/FlightControl-Master/MOOSE/issues/696
|
||||
if TaskGroup:IsAir() then
|
||||
self:AssignTask( TaskGroup )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -713,3 +792,12 @@ function COMMANDCENTER:ReportDetails( ReportGroup, Task )
|
||||
self:MessageToGroup( Report:Text(), ReportGroup )
|
||||
end
|
||||
|
||||
|
||||
--- Let the command center flash a report of the status of the subscribed task to a group.
|
||||
-- @param #COMMANDCENTER self
|
||||
function COMMANDCENTER:SetFlashStatus( Flash )
|
||||
self:F()
|
||||
|
||||
self.FlashStatus = Flash or true
|
||||
|
||||
end
|
||||
|
||||
@@ -46,6 +46,7 @@ do -- DETECTION MANAGER
|
||||
--- @type DETECTION_MANAGER
|
||||
-- @field Core.Set#SET_GROUP SetGroup The groups to which the FAC will report to.
|
||||
-- @field Functional.Detection#DETECTION_BASE Detection The DETECTION_BASE object that is used to report the detected objects.
|
||||
-- @field Tasking.CommandCenter#COMMANDCENTER CC The command center that is used to communicate with the players.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- DETECTION_MANAGER class.
|
||||
@@ -56,6 +57,9 @@ do -- DETECTION MANAGER
|
||||
Detection = nil,
|
||||
}
|
||||
|
||||
--- @field Tasking.CommandCenter#COMMANDCENTER
|
||||
DETECTION_MANAGER.CC = nil
|
||||
|
||||
--- FAC constructor.
|
||||
-- @param #DETECTION_MANAGER self
|
||||
-- @param Core.Set#SET_GROUP SetGroup
|
||||
@@ -217,13 +221,95 @@ do -- DETECTION MANAGER
|
||||
|
||||
return self._ReportDisplayTime
|
||||
end
|
||||
|
||||
|
||||
--- Set a command center to communicate actions to the players reporting to the command center.
|
||||
-- @param #DETECTION_MANAGER self
|
||||
-- @return #DETECTION_MANGER self
|
||||
function DETECTION_MANAGER:SetTacticalMenu( DispatcherMainMenuText, DispatcherMenuText )
|
||||
|
||||
local DispatcherMainMenu = MENU_MISSION:New( DispatcherMainMenuText, nil )
|
||||
local DispatcherMenu = MENU_MISSION_COMMAND:New( DispatcherMenuText, DispatcherMainMenu,
|
||||
function()
|
||||
self:ShowTacticalDisplay( self.Detection )
|
||||
end
|
||||
)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Set a command center to communicate actions to the players reporting to the command center.
|
||||
-- @param #DETECTION_MANAGER self
|
||||
-- @param Tasking.CommandCenter#COMMANDCENTER CommandCenter The command center.
|
||||
-- @return #DETECTION_MANGER self
|
||||
function DETECTION_MANAGER:SetCommandCenter( CommandCenter )
|
||||
|
||||
self.CC = CommandCenter
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Get the command center to communicate actions to the players.
|
||||
-- @param #DETECTION_MANAGER self
|
||||
-- @return Tasking.CommandCenter#COMMANDCENTER The command center.
|
||||
function DETECTION_MANAGER:GetCommandCenter()
|
||||
|
||||
return self.CC
|
||||
end
|
||||
|
||||
|
||||
--- Send an information message to the players reporting to the command center.
|
||||
-- @param #DETECTION_MANAGER self
|
||||
-- @param #table Squadron The squadron table.
|
||||
-- @param #string Message The message to be sent.
|
||||
-- @param #string SoundFile The name of the sound file .wav or .ogg.
|
||||
-- @param #number SoundDuration The duration of the sound.
|
||||
-- @param #string SoundPath The path pointing to the folder in the mission file.
|
||||
-- @param Wrapper.Group#GROUP DefenderGroup The defender group sending the message.
|
||||
-- @return #DETECTION_MANGER self
|
||||
function DETECTION_MANAGER:MessageToPlayers( Squadron, Message, DefenderGroup )
|
||||
|
||||
self:F( { Message = Message } )
|
||||
|
||||
-- if not self.PreviousMessage or self.PreviousMessage ~= Message then
|
||||
-- self.PreviousMessage = Message
|
||||
-- if self.CC then
|
||||
-- self.CC:MessageToCoalition( Message )
|
||||
-- end
|
||||
-- end
|
||||
|
||||
if self.CC then
|
||||
self.CC:MessageToCoalition( Message )
|
||||
end
|
||||
|
||||
Message = Message:gsub( "°", " degrees " )
|
||||
Message = Message:gsub( "(%d)%.(%d)", "%1 dot %2" )
|
||||
|
||||
-- Here we handle the transmission of the voice over.
|
||||
-- If for a certain reason the Defender does not exist, we use the coordinate of the airbase to send the message from.
|
||||
local RadioQueue = Squadron.RadioQueue -- Core.RadioSpeech#RADIOSPEECH
|
||||
if RadioQueue then
|
||||
local DefenderUnit = DefenderGroup:GetUnit(1)
|
||||
if DefenderUnit and DefenderUnit:IsAlive() then
|
||||
RadioQueue:SetSenderUnitName( DefenderUnit:GetName() )
|
||||
end
|
||||
RadioQueue:Speak( Message, Squadron.Language )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Reports the detected items to the @{Core.Set#SET_GROUP}.
|
||||
-- @param #DETECTION_MANAGER self
|
||||
-- @param Functional.Detection#DETECTION_BASE Detection
|
||||
-- @return #DETECTION_MANAGER self
|
||||
function DETECTION_MANAGER:ProcessDetected( Detection )
|
||||
self:E()
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -968,18 +968,19 @@ function MISSION:ReportPlayersProgress( ReportGroup )
|
||||
-- Determine how many tasks are remaining.
|
||||
for TaskID, Task in pairs( self:GetTasks() ) do
|
||||
local Task = Task -- Tasking.Task#TASK
|
||||
local TaskGoalTotal = Task:GetGoalTotal() or 0
|
||||
local TaskName = Task:GetName()
|
||||
local Goal = Task:GetGoal()
|
||||
PlayerList[TaskName] = PlayerList[TaskName] or {}
|
||||
if TaskGoalTotal ~= 0 then
|
||||
local PlayerNames = self:GetPlayerNames()
|
||||
for PlayerName, PlayerData in pairs( PlayerNames ) do
|
||||
PlayerList[TaskName][PlayerName] = string.format( 'Player (%s): Task "%s": %d%%', PlayerName, TaskName, Task:GetPlayerProgress( PlayerName ) * 100 / TaskGoalTotal )
|
||||
if Goal then
|
||||
local TotalContributions = Goal:GetTotalContributions()
|
||||
local PlayerContributions = Goal:GetPlayerContributions()
|
||||
self:F( { TotalContributions = TotalContributions, PlayerContributions = PlayerContributions } )
|
||||
for PlayerName, PlayerContribution in pairs( PlayerContributions ) do
|
||||
PlayerList[TaskName][PlayerName] = string.format( 'Player (%s): Task "%s": %d%%', PlayerName, TaskName, PlayerContributions[PlayerName] * 100 / TotalContributions )
|
||||
end
|
||||
else
|
||||
PlayerList[TaskName]["_"] = string.format( 'Player (---): Task "%s": %d%%', TaskName, 0 )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
for TaskName, TaskData in pairs( PlayerList ) do
|
||||
|
||||
@@ -856,6 +856,8 @@ do -- Group Assignment
|
||||
|
||||
CommandCenter:SetMenu()
|
||||
|
||||
self:MenuFlashTaskStatus( TaskGroup, self:GetMission():GetCommandCenter().FlashStatus )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -1111,6 +1113,11 @@ function TASK:SetAssignedMenuForGroup( TaskGroup, MenuTime )
|
||||
end
|
||||
local MarkMenu = MENU_GROUP_COMMAND:New( TaskGroup, string.format( "Mark Task Location on Map" ), TaskControl, self.MenuMarkToGroup, self, TaskGroup ):SetTime( MenuTime ):SetTag( "Tasking" )
|
||||
local TaskTypeMenu = MENU_GROUP_COMMAND:New( TaskGroup, string.format( "Report Task Details" ), TaskControl, self.MenuTaskStatus, self, TaskGroup ):SetTime( MenuTime ):SetTag( "Tasking" )
|
||||
if not self.FlashTaskStatus then
|
||||
local TaskFlashStatusMenu = MENU_GROUP_COMMAND:New( TaskGroup, string.format( "Flash Task Details" ), TaskControl, self.MenuFlashTaskStatus, self, TaskGroup, true ):SetTime( MenuTime ):SetTag( "Tasking" )
|
||||
else
|
||||
local TaskFlashStatusMenu = MENU_GROUP_COMMAND:New( TaskGroup, string.format( "Stop Flash Task Details" ), TaskControl, self.MenuFlashTaskStatus, self, TaskGroup, nil ):SetTime( MenuTime ):SetTag( "Tasking" )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1225,12 +1232,34 @@ end
|
||||
|
||||
--- Report the task status.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
function TASK:MenuTaskStatus( TaskGroup )
|
||||
|
||||
local ReportText = self:ReportDetails( TaskGroup )
|
||||
|
||||
self:T( ReportText )
|
||||
self:GetMission():GetCommandCenter():MessageTypeToGroup( ReportText, TaskGroup, MESSAGE.Type.Detailed )
|
||||
if TaskGroup:IsAlive() then
|
||||
|
||||
local ReportText = self:ReportDetails( TaskGroup )
|
||||
|
||||
self:T( ReportText )
|
||||
self:GetMission():GetCommandCenter():MessageTypeToGroup( ReportText, TaskGroup, MESSAGE.Type.Detailed )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Report the task status.
|
||||
-- @param #TASK self
|
||||
function TASK:MenuFlashTaskStatus( TaskGroup, Flash )
|
||||
|
||||
self.FlashTaskStatus = Flash
|
||||
|
||||
if self.FlashTaskStatus then
|
||||
self.FlashTaskScheduler, self.FlashTaskScheduleID = SCHEDULER:New( self, self.MenuTaskStatus, { TaskGroup }, 0, 60 )
|
||||
else
|
||||
if self.FlashTaskScheduler then
|
||||
self.FlashTaskScheduler:Stop( self.FlashTaskScheduleID )
|
||||
self.FlashTaskScheduler = nil
|
||||
self.FlashTaskScheduleID = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1709,6 +1738,23 @@ end
|
||||
|
||||
do -- Links
|
||||
|
||||
--- Set goal of a task
|
||||
-- @param #TASK self
|
||||
-- @param Core.Goal#GOAL Goal
|
||||
-- @return #TASK
|
||||
function TASK:SetGoal( Goal )
|
||||
self.Goal = Goal
|
||||
end
|
||||
|
||||
|
||||
--- Get goal of a task
|
||||
-- @param #TASK self
|
||||
-- @return Core.Goal#GOAL The Goal
|
||||
function TASK:GetGoal()
|
||||
return self.Goal
|
||||
end
|
||||
|
||||
|
||||
--- Set dispatcher of a task
|
||||
-- @param #TASK self
|
||||
-- @param Tasking.DetectionManager#DETECTION_MANAGER Dispatcher
|
||||
@@ -1786,7 +1832,7 @@ function TASK:GetPlayerCount() --R2.1 Get a count of the players.
|
||||
if PlayerGroup:IsAlive() == true then
|
||||
if self:IsGroupAssigned( PlayerGroup ) then
|
||||
local PlayerNames = PlayerGroup:GetPlayerNames()
|
||||
PlayerCount = PlayerCount + #PlayerNames
|
||||
PlayerCount = PlayerCount + ((PlayerNames) and #PlayerNames or 0) -- PlayerNames can be nil when there are no players.
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1808,7 +1854,7 @@ function TASK:GetPlayerNames() --R2.1 Get a map of the players.
|
||||
if PlayerGroup:IsAlive() == true then
|
||||
if self:IsGroupAssigned( PlayerGroup ) then
|
||||
local PlayerNames = PlayerGroup:GetPlayerNames()
|
||||
for PlayerNameID, PlayerName in pairs( PlayerNames ) do
|
||||
for PlayerNameID, PlayerName in pairs( PlayerNames or {} ) do
|
||||
PlayerNameMap[PlayerName] = PlayerGroup
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ TASKINFO = {
|
||||
ClassName = "TASKINFO",
|
||||
}
|
||||
|
||||
--- @type #TASKINFO.Detail #string A string that flags to document which level of detail needs to be shown in the report.
|
||||
--- @type TASKINFO.Detail #string A string that flags to document which level of detail needs to be shown in the report.
|
||||
--
|
||||
-- - "M" for Markings on the Map (F10).
|
||||
-- - "S" for Summary Reports.
|
||||
@@ -52,16 +52,16 @@ end
|
||||
|
||||
--- Add taskinfo.
|
||||
-- @param #TASKINFO self
|
||||
-- @param #string The info key.
|
||||
-- @param #string Key The info key.
|
||||
-- @param Data The data of the info.
|
||||
-- @param #number Order The display order, which is a number from 0 to 100.
|
||||
-- @param #TASKINFO.Detail Detail The detail Level.
|
||||
-- @param #boolean Keep (optional) If true, this would indicate that the planned taskinfo would be persistent when the task is completed, so that the original planned task info is used at the completed reports.
|
||||
-- @return #TASKINFO self
|
||||
function TASKINFO:AddInfo( Key, Data, Order, Detail, Keep )
|
||||
self.VolatileInfo:Add( Key, { Data = Data, Order = Order, Detail = Detail } )
|
||||
function TASKINFO:AddInfo( Key, Data, Order, Detail, Keep, ShowKey, Type )
|
||||
self.VolatileInfo:Add( Key, { Data = Data, Order = Order, Detail = Detail, ShowKey = ShowKey, Type = Type } )
|
||||
if Keep == true then
|
||||
self.PersistentInfo:Add( Key, { Data = Data, Order = Order, Detail = Detail } )
|
||||
self.PersistentInfo:Add( Key, { Data = Data, Order = Order, Detail = Detail, ShowKey = ShowKey, Type = Type } )
|
||||
end
|
||||
return self
|
||||
end
|
||||
@@ -124,12 +124,21 @@ end
|
||||
-- @param #TASKINFO.Detail Detail The detail Level.
|
||||
-- @param #boolean Keep (optional) If true, this would indicate that the planned taskinfo would be persistent when the task is completed, so that the original planned task info is used at the completed reports.
|
||||
-- @return #TASKINFO self
|
||||
function TASKINFO:AddCoordinate( Coordinate, Order, Detail, Keep )
|
||||
self:AddInfo( "Coordinate", Coordinate, Order, Detail, Keep )
|
||||
function TASKINFO:AddCoordinate( Coordinate, Order, Detail, Keep, ShowKey, Name )
|
||||
self:AddInfo( Name or "Coordinate", Coordinate, Order, Detail, Keep, ShowKey, "Coordinate" )
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Get the Coordinate.
|
||||
-- @param #TASKINFO self
|
||||
-- @return Core.Point#COORDINATE Coordinate
|
||||
function TASKINFO:GetCoordinate( Name )
|
||||
return self:GetData( Name or "Coordinate" )
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Add Coordinates.
|
||||
-- @param #TASKINFO self
|
||||
-- @param #list<Core.Point#COORDINATE> Coordinates
|
||||
@@ -153,7 +162,7 @@ end
|
||||
-- @param #boolean Keep (optional) If true, this would indicate that the planned taskinfo would be persistent when the task is completed, so that the original planned task info is used at the completed reports.
|
||||
-- @return #TASKINFO self
|
||||
function TASKINFO:AddThreat( ThreatText, ThreatLevel, Order, Detail, Keep )
|
||||
self:AddInfo( "Threat", ThreatText .. " [" .. string.rep( "■", ThreatLevel ) .. string.rep( "□", 10 - ThreatLevel ) .. "]", Order, Detail, Keep )
|
||||
self:AddInfo( "Threat", " [" .. string.rep( "■", ThreatLevel ) .. string.rep( "□", 10 - ThreatLevel ) .. "]:" .. ThreatText, Order, Detail, Keep )
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -297,75 +306,63 @@ function TASKINFO:Report( Report, Detail, ReportGroup, Task )
|
||||
|
||||
for Key, Data in UTILS.spairs( self.Info.Set, function( t, a, b ) return t[a].Order < t[b].Order end ) do
|
||||
|
||||
self:F( { Key = Key, Detail = Detail, Data = Data } )
|
||||
|
||||
if Data.Detail:find( Detail ) then
|
||||
local Text = ""
|
||||
if Key == "TaskName" then
|
||||
local ShowKey = ( Data.ShowKey == nil or Data.ShowKey == true )
|
||||
if Key == "TaskName" then
|
||||
Key = nil
|
||||
Text = Data.Data
|
||||
end
|
||||
if Key == "Coordinate" then
|
||||
elseif Data.Type and Data.Type == "Coordinate" then
|
||||
local Coordinate = Data.Data -- Core.Point#COORDINATE
|
||||
Text = Coordinate:ToString( ReportGroup:GetUnit(1), nil, Task )
|
||||
end
|
||||
if Key == "Threat" then
|
||||
elseif Key == "Threat" then
|
||||
local DataText = Data.Data -- #string
|
||||
Text = DataText
|
||||
end
|
||||
if Key == "Counting" then
|
||||
elseif Key == "Counting" then
|
||||
local DataText = Data.Data -- #string
|
||||
Text = DataText
|
||||
end
|
||||
if Key == "Targets" then
|
||||
elseif Key == "Targets" then
|
||||
local DataText = Data.Data -- #string
|
||||
Text = DataText
|
||||
end
|
||||
if Key == "QFE" then
|
||||
elseif Key == "QFE" then
|
||||
local Coordinate = Data.Data -- Core.Point#COORDINATE
|
||||
Text = Coordinate:ToStringPressure( ReportGroup:GetUnit(1), nil, Task )
|
||||
end
|
||||
if Key == "Temperature" then
|
||||
elseif Key == "Temperature" then
|
||||
local Coordinate = Data.Data -- Core.Point#COORDINATE
|
||||
Text = Coordinate:ToStringTemperature( ReportGroup:GetUnit(1), nil, Task )
|
||||
end
|
||||
if Key == "Wind" then
|
||||
elseif Key == "Wind" then
|
||||
local Coordinate = Data.Data -- Core.Point#COORDINATE
|
||||
Text = Coordinate:ToStringWind( ReportGroup:GetUnit(1), nil, Task )
|
||||
end
|
||||
if Key == "Cargo" then
|
||||
elseif Key == "Cargo" then
|
||||
local DataText = Data.Data -- #string
|
||||
Text = DataText
|
||||
elseif Key == "Friendlies" then
|
||||
local DataText = Data.Data -- #string
|
||||
Text = DataText
|
||||
elseif Key == "Players" then
|
||||
local DataText = Data.Data -- #string
|
||||
Text = DataText
|
||||
else
|
||||
local DataText = Data.Data -- #string
|
||||
Text = DataText
|
||||
end
|
||||
if Key == "Friendlies" then
|
||||
local DataText = Data.Data -- #string
|
||||
Text = DataText
|
||||
end
|
||||
if Key == "Players" then
|
||||
local DataText = Data.Data -- #string
|
||||
Text = DataText
|
||||
end
|
||||
|
||||
|
||||
if Line < math.floor( Data.Order / 10 ) then
|
||||
if Line == 0 then
|
||||
if Text ~= "" then
|
||||
Report:AddIndent( LineReport:Text( ", " ), "-" )
|
||||
end
|
||||
Report:AddIndent( LineReport:Text( ", " ), "-" )
|
||||
else
|
||||
if Text ~= "" then
|
||||
Report:AddIndent( LineReport:Text( ", " ) )
|
||||
end
|
||||
Report:AddIndent( LineReport:Text( ", " ) )
|
||||
end
|
||||
LineReport = REPORT:New()
|
||||
Line = math.floor( Data.Order / 10 )
|
||||
end
|
||||
|
||||
if Text ~= "" then
|
||||
LineReport:Add( ( Key and ( Key .. ":" ) or "" ) .. Text )
|
||||
LineReport:Add( ( ( Key and ShowKey == true ) and ( Key .. ": " ) or "" ) .. Text )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Report:AddIndent( LineReport:Text( ", " ) )
|
||||
|
||||
end
|
||||
|
||||
@@ -351,6 +351,26 @@ do -- TASK_A2A
|
||||
end
|
||||
end
|
||||
|
||||
--- This function is called from the @{Tasking.CommandCenter#COMMANDCENTER} to determine the method of automatic task selection.
|
||||
-- @param #TASK_A2A self
|
||||
-- @param #number AutoAssignMethod The method to be applied to the task.
|
||||
-- @param Tasking.CommandCenter#COMMANDCENTER CommandCenter The command center.
|
||||
-- @param Wrapper.Group#GROUP TaskGroup The player group.
|
||||
function TASK_A2A:GetAutoAssignPriority( AutoAssignMethod, CommandCenter, TaskGroup )
|
||||
|
||||
if AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Random then
|
||||
return math.random( 1, 9 )
|
||||
elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Distance then
|
||||
local Coordinate = self.TaskInfo:GetData( "Coordinate" )
|
||||
local Distance = Coordinate:Get2DDistance( CommandCenter:GetPositionable():GetCoordinate() )
|
||||
return math.floor( Distance )
|
||||
elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Priority then
|
||||
return 1
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -355,6 +355,27 @@ do -- TASK_A2G
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- This function is called from the @{Tasking.CommandCenter#COMMANDCENTER} to determine the method of automatic task selection.
|
||||
-- @param #TASK_A2G self
|
||||
-- @param #number AutoAssignMethod The method to be applied to the task.
|
||||
-- @param Tasking.CommandCenter#COMMANDCENTER CommandCenter The command center.
|
||||
-- @param Wrapper.Group#GROUP TaskGroup The player group.
|
||||
function TASK_A2G:GetAutoAssignPriority( AutoAssignMethod, CommandCenter, TaskGroup )
|
||||
|
||||
if AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Random then
|
||||
return math.random( 1, 9 )
|
||||
elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Distance then
|
||||
local Coordinate = self.TaskInfo:GetData( "Coordinate" )
|
||||
local Distance = Coordinate:Get2DDistance( CommandCenter:GetPositionable():GetCoordinate() )
|
||||
self:F({Distance=Distance})
|
||||
return math.floor( Distance )
|
||||
elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Priority then
|
||||
return 1
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -633,7 +633,7 @@ do -- TASK_A2G_DISPATCHER
|
||||
--DetectedSet:Flush( self )
|
||||
|
||||
local DetectedItemID = DetectedItem.ID
|
||||
local TaskIndex = DetectedItem.ID
|
||||
local TaskIndex = DetectedItem.Index
|
||||
local DetectedItemChanged = DetectedItem.Changed
|
||||
|
||||
self:F( { DetectedItemChanged = DetectedItemChanged, DetectedItemID = DetectedItemID, TaskIndex = TaskIndex } )
|
||||
@@ -649,6 +649,7 @@ do -- TASK_A2G_DISPATCHER
|
||||
if TargetSetUnit then
|
||||
if Task:IsInstanceOf( TASK_A2G_SEAD ) then
|
||||
Task:SetTargetSetUnit( TargetSetUnit )
|
||||
Task:SetDetection( Detection, DetectedItem )
|
||||
Task:UpdateTaskInfo( DetectedItem )
|
||||
TargetsReport:Add( Detection:GetChangeText( DetectedItem ) )
|
||||
else
|
||||
@@ -659,7 +660,7 @@ do -- TASK_A2G_DISPATCHER
|
||||
if TargetSetUnit then
|
||||
if Task:IsInstanceOf( TASK_A2G_CAS ) then
|
||||
Task:SetTargetSetUnit( TargetSetUnit )
|
||||
Task:SetDetection( Detection, TaskIndex )
|
||||
Task:SetDetection( Detection, DetectedItem )
|
||||
Task:UpdateTaskInfo( DetectedItem )
|
||||
TargetsReport:Add( Detection:GetChangeText( DetectedItem ) )
|
||||
else
|
||||
@@ -671,7 +672,7 @@ do -- TASK_A2G_DISPATCHER
|
||||
if TargetSetUnit then
|
||||
if Task:IsInstanceOf( TASK_A2G_BAI ) then
|
||||
Task:SetTargetSetUnit( TargetSetUnit )
|
||||
Task:SetDetection( Detection, TaskIndex )
|
||||
Task:SetDetection( Detection, DetectedItem )
|
||||
Task:UpdateTaskInfo( DetectedItem )
|
||||
TargetsReport:Add( Detection:GetChangeText( DetectedItem ) )
|
||||
else
|
||||
|
||||
@@ -1381,6 +1381,23 @@ do -- TASK_CARGO
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
--- This function is called from the @{Tasking.CommandCenter#COMMANDCENTER} to determine the method of automatic task selection.
|
||||
-- @param #TASK_CARGO self
|
||||
-- @param #number AutoAssignMethod The method to be applied to the task.
|
||||
-- @param Wrapper.Group#GROUP TaskGroup The player group.
|
||||
function TASK_CARGO:GetAutoAssignPriority( AutoAssignMethod, TaskGroup )
|
||||
|
||||
if AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Random then
|
||||
return math.random( 1, 9 )
|
||||
elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Distance then
|
||||
return 0
|
||||
elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Priority then
|
||||
return 1
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
396
Moose Development/Moose/Tasking/Task_Capture_Dispatcher.lua
Normal file
396
Moose Development/Moose/Tasking/Task_Capture_Dispatcher.lua
Normal file
@@ -0,0 +1,396 @@
|
||||
--- **Tasking** - Creates and manages player TASK_ZONE_CAPTURE tasks.
|
||||
--
|
||||
-- The **TASK_CAPTURE_DISPATCHER** allows you to setup various tasks for let human
|
||||
-- players capture zones in a co-operation effort.
|
||||
--
|
||||
-- The dispatcher will implement for you mechanisms to create capture zone tasks:
|
||||
--
|
||||
-- * As setup by the mission designer.
|
||||
-- * Dynamically capture zone tasks.
|
||||
--
|
||||
--
|
||||
--
|
||||
-- **Specific features:**
|
||||
--
|
||||
-- * Creates a task to capture zones and achieve mission goals.
|
||||
-- * Orchestrate the task flow, so go from Planned to Assigned to Success, Failed or Cancelled.
|
||||
-- * Co-operation tasking, so a player joins a group of players executing the same task.
|
||||
--
|
||||
--
|
||||
-- **A complete task menu system to allow players to:**
|
||||
--
|
||||
-- * Join the task, abort the task.
|
||||
-- * Mark the location of the zones to capture on the map.
|
||||
-- * Provide details of the zones.
|
||||
-- * Route to the zones.
|
||||
-- * Display the task briefing.
|
||||
--
|
||||
--
|
||||
-- **A complete mission menu system to allow players to:**
|
||||
--
|
||||
-- * Join a task, abort the task.
|
||||
-- * Display task reports.
|
||||
-- * Display mission statistics.
|
||||
-- * Mark the task locations on the map.
|
||||
-- * Provide details of the zones.
|
||||
-- * Display the mission briefing.
|
||||
-- * Provide status updates as retrieved from the command center.
|
||||
-- * Automatically assign a random task as part of a mission.
|
||||
-- * Manually assign a specific task as part of a mission.
|
||||
--
|
||||
--
|
||||
-- **A settings system, using the settings menu:**
|
||||
--
|
||||
-- * Tweak the duration of the display of messages.
|
||||
-- * Switch between metric and imperial measurement system.
|
||||
-- * Switch between coordinate formats used in messages: BR, BRA, LL DMS, LL DDM, MGRS.
|
||||
-- * Various other options.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ### Contributions:
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- @module Tasking.Task_Zone_Capture_Dispatcher
|
||||
-- @image Task_Zone_Capture_Dispatcher.JPG
|
||||
|
||||
do -- TASK_CAPTURE_DISPATCHER
|
||||
|
||||
--- TASK_CAPTURE_DISPATCHER class.
|
||||
-- @type TASK_CAPTURE_DISPATCHER
|
||||
-- @extends Tasking.Task_Manager#TASK_MANAGER
|
||||
-- @field TASK_CAPTURE_DISPATCHER.ZONE ZONE
|
||||
|
||||
--- @type TASK_CAPTURE_DISPATCHER.CSAR
|
||||
-- @field Wrapper.Unit#UNIT PilotUnit
|
||||
-- @field Tasking.Task#TASK Task
|
||||
|
||||
|
||||
--- Implements the dynamic dispatching of capture zone tasks.
|
||||
--
|
||||
-- The **TASK_CAPTURE_DISPATCHER** allows you to setup various tasks for let human
|
||||
-- players capture zones in a co-operation effort.
|
||||
--
|
||||
-- Let's explore **step by step** how to setup the task capture zone dispatcher.
|
||||
--
|
||||
-- # 1. Setup a mission environment.
|
||||
--
|
||||
-- It is easy, as it works just like any other task setup, so setup a command center and a mission.
|
||||
--
|
||||
-- ## 1.1. Create a command center.
|
||||
--
|
||||
-- First you need to create a command center using the @{Tasking.CommandCenter#COMMANDCENTER.New}() constructor.
|
||||
-- The command assumes that you´ve setup a group in the mission editor with the name HQ.
|
||||
-- This group will act as the command center object.
|
||||
-- It is a good practice to mark this group as invisible and invulnerable.
|
||||
--
|
||||
-- local CommandCenter = COMMANDCENTER
|
||||
-- :New( GROUP:FindByName( "HQ" ), "HQ" ) -- Create the CommandCenter.
|
||||
--
|
||||
-- ## 1.2. Create a mission.
|
||||
--
|
||||
-- Tasks work in a **mission**, which groups these tasks to achieve a joint **mission goal**. A command center can **govern multiple missions**.
|
||||
--
|
||||
-- Create a new mission, using the @{Tasking.Mission#MISSION.New}() constructor.
|
||||
--
|
||||
-- -- Declare the Mission for the Command Center.
|
||||
-- local Mission = MISSION
|
||||
-- :New( CommandCenter,
|
||||
-- "Overlord",
|
||||
-- "High",
|
||||
-- "Capture the blue zones.",
|
||||
-- coalition.side.RED
|
||||
-- )
|
||||
--
|
||||
--
|
||||
-- # 2. Dispatch a **capture zone** task.
|
||||
--
|
||||
-- So, now that we have a command center and a mission, we now create the capture zone task.
|
||||
-- We create the capture zone task using the @{#TASK_CAPTURE_DISPATCHER.AddCaptureZoneTask}() constructor.
|
||||
--
|
||||
-- ## 2.1. Create the capture zones.
|
||||
--
|
||||
-- Because a capture zone task will not generate the capture zones, you'll need to create them first.
|
||||
--
|
||||
--
|
||||
-- -- We define here a capture zone; of the type ZONE_CAPTURE_COALITION.
|
||||
-- -- The zone to be captured has the name Alpha, and was defined in the mission editor as a trigger zone.
|
||||
-- CaptureZone = ZONE:New( "Alpha" )
|
||||
-- CaptureZoneCoalitionApha = ZONE_CAPTURE_COALITION:New( CaptureZone, coalition.side.RED )
|
||||
--
|
||||
-- ## 2.2. Create a set of player groups.
|
||||
--
|
||||
-- What is also needed, is to have a set of @{Core.Group}s defined that contains the clients of the players.
|
||||
--
|
||||
-- -- Allocate the player slots, which must be aircraft (airplanes or helicopters), that can be manned by players.
|
||||
-- -- We use the method FilterPrefixes to filter those player groups that have client slots, as defined in the mission editor.
|
||||
-- -- In this example, we filter the groups where the name starts with "Blue Player", which captures the blue player slots.
|
||||
-- local PlayerGroupSet = SET_GROUP:New():FilterPrefixes( "Blue Player" ):FilterStart()
|
||||
--
|
||||
-- ## 2.3. Setup the capture zone task.
|
||||
--
|
||||
-- First, we need to create a TASK_CAPTURE_DISPATCHER object.
|
||||
--
|
||||
-- TaskCaptureZoneDispatcher = TASK_CAPTURE_DISPATCHER:New( Mission, PilotGroupSet )
|
||||
--
|
||||
-- So, the variable `TaskCaptureZoneDispatcher` will contain the object of class TASK_CAPTURE_DISPATCHER,
|
||||
-- which will allow you to dispatch capture zone tasks:
|
||||
--
|
||||
-- * for mission `Mission`, as was defined in section 1.2.
|
||||
-- * for the group set `PilotGroupSet`, as was defined in section 2.2.
|
||||
--
|
||||
-- Now that we have `TaskDispatcher` object, we can now **create the TaskCaptureZone**, using the @{#TASK_CAPTURE_DISPATCHER.AddCaptureZoneTask}() method!
|
||||
--
|
||||
-- local TaskCaptureZone = TaskCaptureZoneDispatcher:AddCaptureZoneTask(
|
||||
-- "Capture zone Alpha",
|
||||
-- CaptureZoneCoalitionAlpha,
|
||||
-- "Fly to zone Alpha and eliminate all enemy forces to capture it." )
|
||||
--
|
||||
-- As a result of this code, the `TaskCaptureZone` (returned) variable will contain an object of @{#TASK_CAPTURE_ZONE}!
|
||||
-- We pass to the method the title of the task, and the `CaptureZoneCoalitionAlpha`, which is the zone to be captured, as defined in section 2.1!
|
||||
-- This returned `TaskCaptureZone` object can now be used to setup additional task configurations, or to control this specific task with special events.
|
||||
--
|
||||
-- And you're done! As you can see, it is a small bit of work, but the reward is great.
|
||||
-- And, because all this is done using program interfaces, you can easily build a mission to capture zones yourself!
|
||||
-- Based on various events happening within your mission, you can use the above methods to create new capture zones,
|
||||
-- and setup a new capture zone task and assign it to a group of players, while your mission is running!
|
||||
--
|
||||
--
|
||||
--
|
||||
-- @field #TASK_CAPTURE_DISPATCHER
|
||||
TASK_CAPTURE_DISPATCHER = {
|
||||
ClassName = "TASK_CAPTURE_DISPATCHER",
|
||||
Mission = nil,
|
||||
Tasks = {},
|
||||
Zones = {},
|
||||
ZoneCount = 0,
|
||||
}
|
||||
|
||||
|
||||
|
||||
TASK_CAPTURE_DISPATCHER.AI_A2G_Dispatcher = nil -- AI.AI_A2G_Dispatcher#AI_A2G_DISPATCHER
|
||||
|
||||
--- TASK_CAPTURE_DISPATCHER constructor.
|
||||
-- @param #TASK_CAPTURE_DISPATCHER self
|
||||
-- @param Tasking.Mission#MISSION Mission The mission for which the task dispatching is done.
|
||||
-- @param Core.Set#SET_GROUP SetGroup The set of groups that can join the tasks within the mission.
|
||||
-- @return #TASK_CAPTURE_DISPATCHER self
|
||||
function TASK_CAPTURE_DISPATCHER:New( Mission, SetGroup )
|
||||
|
||||
-- Inherits from DETECTION_MANAGER
|
||||
local self = BASE:Inherit( self, TASK_MANAGER:New( SetGroup ) ) -- #TASK_CAPTURE_DISPATCHER
|
||||
|
||||
self.Mission = Mission
|
||||
|
||||
self:AddTransition( "Started", "Assign", "Started" )
|
||||
self:AddTransition( "Started", "ZoneCaptured", "Started" )
|
||||
|
||||
self:__StartTasks( 5 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Link a task capture dispatcher from the other coalition to understand its plan for defenses.
|
||||
-- This is used for the tactical overview, so the players also know the zones attacked by the other coalition!
|
||||
-- @param #TASK_CAPTURE_DISPATCHER self
|
||||
-- @param #TASK_CAPTURE_DISPATCHER DefenseTaskCaptureDispatcher
|
||||
function TASK_CAPTURE_DISPATCHER:SetDefenseTaskCaptureDispatcher( DefenseTaskCaptureDispatcher )
|
||||
|
||||
self.DefenseTaskCaptureDispatcher = DefenseTaskCaptureDispatcher
|
||||
end
|
||||
|
||||
|
||||
--- Get the linked task capture dispatcher from the other coalition to understand its plan for defenses.
|
||||
-- This is used for the tactical overview, so the players also know the zones attacked by the other coalition!
|
||||
-- @param #TASK_CAPTURE_DISPATCHER self
|
||||
-- @return #TASK_CAPTURE_DISPATCHER
|
||||
function TASK_CAPTURE_DISPATCHER:GetDefenseTaskCaptureDispatcher()
|
||||
|
||||
return self.DefenseTaskCaptureDispatcher
|
||||
end
|
||||
|
||||
|
||||
--- Link an AI A2G dispatcher from the other coalition to understand its plan for defenses.
|
||||
-- This is used for the tactical overview, so the players also know the zones attacked by the other AI A2G dispatcher!
|
||||
-- @param #TASK_CAPTURE_DISPATCHER self
|
||||
-- @param AI.AI_A2G_Dispatcher#AI_A2G_DISPATCHER DefenseAIA2GDispatcher
|
||||
function TASK_CAPTURE_DISPATCHER:SetDefenseAIA2GDispatcher( DefenseAIA2GDispatcher )
|
||||
|
||||
self.DefenseAIA2GDispatcher = DefenseAIA2GDispatcher
|
||||
end
|
||||
|
||||
|
||||
--- Get the linked AI A2G dispatcher from the other coalition to understand its plan for defenses.
|
||||
-- This is used for the tactical overview, so the players also know the zones attacked by the AI A2G dispatcher!
|
||||
-- @param #TASK_CAPTURE_DISPATCHER self
|
||||
-- @return AI.AI_A2G_Dispatcher#AI_A2G_DISPATCHER
|
||||
function TASK_CAPTURE_DISPATCHER:GetDefenseAIA2GDispatcher()
|
||||
|
||||
return self.DefenseAIA2GDispatcher
|
||||
end
|
||||
|
||||
|
||||
--- Add a capture zone task.
|
||||
-- @param #TASK_CAPTURE_DISPATCHER self
|
||||
-- @param #string TaskPrefix (optional) The prefix of the capture zone task.
|
||||
-- If no TaskPrefix is given, then "Capture" will be used as the TaskPrefix.
|
||||
-- The TaskPrefix will be appended with a . + a number of 3 digits, if the TaskPrefix already exists in the task collection.
|
||||
-- @param Functional.CaptureZoneCoalition#ZONE_CAPTURE_COALITION CaptureZone The zone of the coalition to be captured as the task goal.
|
||||
-- @param #string Briefing The briefing of the task to be shown to the player.
|
||||
-- @return Tasking.Task_Capture_Zone#TASK_CAPTURE_ZONE
|
||||
-- @usage
|
||||
--
|
||||
--
|
||||
function TASK_CAPTURE_DISPATCHER:AddCaptureZoneTask( TaskPrefix, CaptureZone, Briefing )
|
||||
|
||||
local TaskName = TaskPrefix or "Capture"
|
||||
if self.Zones[TaskName] then
|
||||
self.ZoneCount = self.ZoneCount + 1
|
||||
TaskName = string.format( "%s.%03d", TaskName, self.ZoneCount )
|
||||
end
|
||||
|
||||
self.Zones[TaskName] = {}
|
||||
self.Zones[TaskName].CaptureZone = CaptureZone
|
||||
self.Zones[TaskName].Briefing = Briefing
|
||||
self.Zones[TaskName].Task = nil
|
||||
self.Zones[TaskName].TaskPrefix = TaskPrefix
|
||||
|
||||
self:ManageTasks()
|
||||
|
||||
return self.Zones[TaskName] and self.Zones[TaskName].Task
|
||||
end
|
||||
|
||||
|
||||
--- Link an AI_A2G_DISPATCHER to the TASK_CAPTURE_DISPATCHER.
|
||||
-- @param #TASK_CAPTURE_DISPATCHER self
|
||||
-- @param AI.AI_A2G_Dispatcher#AI_A2G_DISPATCHER AI_A2G_Dispatcher The AI Dispatcher to be linked to the tasking.
|
||||
-- @return Tasking.Task_Capture_Zone#TASK_CAPTURE_ZONE
|
||||
function TASK_CAPTURE_DISPATCHER:Link_AI_A2G_Dispatcher( AI_A2G_Dispatcher )
|
||||
|
||||
self.AI_A2G_Dispatcher = AI_A2G_Dispatcher -- AI.AI_A2G_Dispatcher#AI_A2G_DISPATCHER
|
||||
AI_A2G_Dispatcher.Detection:LockDetectedItems()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Assigns tasks to the @{Core.Set#SET_GROUP}.
|
||||
-- @param #TASK_CAPTURE_DISPATCHER self
|
||||
-- @return #boolean Return true if you want the task assigning to continue... false will cancel the loop.
|
||||
function TASK_CAPTURE_DISPATCHER:ManageTasks()
|
||||
self:F()
|
||||
|
||||
local AreaMsg = {}
|
||||
local TaskMsg = {}
|
||||
local ChangeMsg = {}
|
||||
|
||||
local Mission = self.Mission
|
||||
|
||||
if Mission:IsIDLE() or Mission:IsENGAGED() then
|
||||
|
||||
local TaskReport = REPORT:New()
|
||||
|
||||
-- Checking the task queue for the dispatcher, and removing any obsolete task!
|
||||
for TaskIndex, TaskData in pairs( self.Tasks ) do
|
||||
local Task = TaskData -- Tasking.Task#TASK
|
||||
if Task:IsStatePlanned() then
|
||||
-- Here we need to check if the pilot is still existing.
|
||||
-- Task = self:RemoveTask( TaskIndex )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Now that all obsolete tasks are removed, loop through the Zone tasks.
|
||||
for TaskName, CaptureZone in pairs( self.Zones ) do
|
||||
|
||||
if not CaptureZone.Task then
|
||||
-- New Transport Task
|
||||
CaptureZone.Task = TASK_CAPTURE_ZONE:New( Mission, self.SetGroup, TaskName, CaptureZone.CaptureZone, CaptureZone.Briefing )
|
||||
CaptureZone.Task.TaskPrefix = CaptureZone.TaskPrefix -- We keep the TaskPrefix for further reference!
|
||||
Mission:AddTask( CaptureZone.Task )
|
||||
TaskReport:Add( TaskName )
|
||||
|
||||
-- Link the Task Dispatcher to the capture zone task, because it is used on the UpdateTaskInfo.
|
||||
CaptureZone.Task:SetDispatcher( self )
|
||||
CaptureZone.Task:UpdateTaskInfo()
|
||||
|
||||
function CaptureZone.Task.OnEnterAssigned( Task, From, Event, To )
|
||||
if self.AI_A2G_Dispatcher then
|
||||
self.AI_A2G_Dispatcher:Unlock( Task.TaskZoneName ) -- This will unlock the zone to be defended by AI.
|
||||
end
|
||||
CaptureZone.Task:UpdateTaskInfo()
|
||||
CaptureZone.Task.ZoneGoal.Attacked = true
|
||||
end
|
||||
|
||||
function CaptureZone.Task.OnEnterSuccess( Task, From, Event, To )
|
||||
--self:Success( Task )
|
||||
if self.AI_A2G_Dispatcher then
|
||||
self.AI_A2G_Dispatcher:Lock( Task.TaskZoneName ) -- This will lock the zone from being defended by AI.
|
||||
end
|
||||
CaptureZone.Task:UpdateTaskInfo()
|
||||
CaptureZone.Task.ZoneGoal.Attacked = false
|
||||
end
|
||||
|
||||
function CaptureZone.Task.OnEnterCancelled( Task, From, Event, To )
|
||||
self:Cancelled( Task )
|
||||
if self.AI_A2G_Dispatcher then
|
||||
self.AI_A2G_Dispatcher:Lock( Task.TaskZoneName ) -- This will lock the zone from being defended by AI.
|
||||
end
|
||||
CaptureZone.Task:UpdateTaskInfo()
|
||||
CaptureZone.Task.ZoneGoal.Attacked = false
|
||||
end
|
||||
|
||||
function CaptureZone.Task.OnEnterFailed( Task, From, Event, To )
|
||||
self:Failed( Task )
|
||||
if self.AI_A2G_Dispatcher then
|
||||
self.AI_A2G_Dispatcher:Lock( Task.TaskZoneName ) -- This will lock the zone from being defended by AI.
|
||||
end
|
||||
CaptureZone.Task:UpdateTaskInfo()
|
||||
CaptureZone.Task.ZoneGoal.Attacked = false
|
||||
end
|
||||
|
||||
function CaptureZone.Task.OnEnterAborted( Task, From, Event, To )
|
||||
self:Aborted( Task )
|
||||
if self.AI_A2G_Dispatcher then
|
||||
self.AI_A2G_Dispatcher:Lock( Task.TaskZoneName ) -- This will lock the zone from being defended by AI.
|
||||
end
|
||||
CaptureZone.Task:UpdateTaskInfo()
|
||||
CaptureZone.Task.ZoneGoal.Attacked = false
|
||||
end
|
||||
|
||||
-- Now broadcast the onafterCargoPickedUp event to the Task Cargo Dispatcher.
|
||||
function CaptureZone.Task.OnAfterCaptured( Task, From, Event, To, TaskUnit )
|
||||
self:Captured( Task, Task.TaskPrefix, TaskUnit )
|
||||
if self.AI_A2G_Dispatcher then
|
||||
self.AI_A2G_Dispatcher:Lock( Task.TaskZoneName ) -- This will lock the zone from being defended by AI.
|
||||
end
|
||||
CaptureZone.Task:UpdateTaskInfo()
|
||||
CaptureZone.Task.ZoneGoal.Attacked = false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
-- TODO set menus using the HQ coordinator
|
||||
Mission:GetCommandCenter():SetMenu()
|
||||
|
||||
local TaskText = TaskReport:Text(", ")
|
||||
|
||||
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
|
||||
if ( not Mission:IsGroupAssigned(TaskGroup) ) and TaskText ~= "" then
|
||||
Mission:GetCommandCenter():MessageToGroup( string.format( "%s has tasks %s. Subscribe to a task using the radio menu.", Mission:GetShortText(), TaskText ), TaskGroup )
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
@@ -47,7 +47,7 @@ do -- TASK_ZONE_GOAL
|
||||
-- @param Tasking.Mission#MISSION Mission
|
||||
-- @param Core.Set#SET_GROUP SetGroup The set of groups for which the Task can be assigned.
|
||||
-- @param #string TaskName The name of the Task.
|
||||
-- @param Core.ZoneGoal#ZONE_GOAL ZoneGoal
|
||||
-- @param Core.ZoneGoalCoalition#ZONE_GOAL_COALITION ZoneGoal
|
||||
-- @return #TASK_ZONE_GOAL self
|
||||
function TASK_ZONE_GOAL:New( Mission, SetGroup, TaskName, ZoneGoal, TaskType, TaskBriefing )
|
||||
local self = BASE:Inherit( self, TASK:New( Mission, SetGroup, TaskName, TaskType, TaskBriefing ) ) -- #TASK_ZONE_GOAL
|
||||
@@ -59,19 +59,25 @@ do -- TASK_ZONE_GOAL
|
||||
local Fsm = self:GetUnitProcess()
|
||||
|
||||
|
||||
Fsm:AddProcess ( "Planned", "Accept", ACT_ASSIGN_ACCEPT:New( self.TaskBriefing ), { Assigned = "StartMonitoring", Rejected = "Reject" } )
|
||||
|
||||
Fsm:AddTransition( "Assigned", "StartMonitoring", "Monitoring" )
|
||||
Fsm:AddTransition( "Monitoring", "Monitor", "Monitoring", {} )
|
||||
Fsm:AddTransition( "Monitoring", "RouteTo", "Monitoring" )
|
||||
Fsm:AddProcess( "Monitoring", "RouteToZone", ACT_ROUTE_ZONE:New(), {} )
|
||||
|
||||
--Fsm:AddTransition( "Accounted", "DestroyedAll", "Accounted" )
|
||||
--Fsm:AddTransition( "Accounted", "Success", "Success" )
|
||||
Fsm:AddTransition( "Rejected", "Reject", "Aborted" )
|
||||
Fsm:AddTransition( "Failed", "Fail", "Failed" )
|
||||
|
||||
self:SetTargetZone( self.ZoneGoal:GetZone() )
|
||||
|
||||
--- Test
|
||||
-- @param #FSM_PROCESS self
|
||||
-- @param Wrapper.Unit#UNIT TaskUnit
|
||||
-- @param Tasking.Task#TASK Task
|
||||
function Fsm:OnAfterAssigned( TaskUnit, Task )
|
||||
self:F( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
|
||||
|
||||
self:__StartMonitoring( 0.1 )
|
||||
self:__RouteToZone( 0.1 )
|
||||
end
|
||||
|
||||
--- Test
|
||||
-- @param #FSM_PROCESS self
|
||||
@@ -80,7 +86,6 @@ do -- TASK_ZONE_GOAL
|
||||
function Fsm:onafterStartMonitoring( TaskUnit, Task )
|
||||
self:F( { self } )
|
||||
self:__Monitor( 0.1 )
|
||||
self:__RouteTo( 0.1 )
|
||||
end
|
||||
|
||||
--- Monitor Loop
|
||||
@@ -101,7 +106,7 @@ do -- TASK_ZONE_GOAL
|
||||
-- Determine the first Unit from the self.TargetSetUnit
|
||||
|
||||
if Task:GetTargetZone( TaskUnit ) then
|
||||
self:__RouteTo( 0.1 )
|
||||
self:__RouteToZone( 0.1 )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -160,37 +165,37 @@ do -- TASK_ZONE_GOAL
|
||||
end
|
||||
|
||||
|
||||
do -- TASK_ZONE_CAPTURE
|
||||
do -- TASK_CAPTURE_ZONE
|
||||
|
||||
--- The TASK_ZONE_CAPTURE class
|
||||
-- @type TASK_ZONE_CAPTURE
|
||||
--- The TASK_CAPTURE_ZONE class
|
||||
-- @type TASK_CAPTURE_ZONE
|
||||
-- @field Core.ZoneGoalCoalition#ZONE_GOAL_COALITION ZoneGoal
|
||||
-- @extends #TASK_ZONE_GOAL
|
||||
|
||||
--- # TASK_ZONE_CAPTURE class, extends @{Tasking.TaskZoneGoal#TASK_ZONE_GOAL}
|
||||
--- # TASK_CAPTURE_ZONE class, extends @{Tasking.TaskZoneGoal#TASK_ZONE_GOAL}
|
||||
--
|
||||
-- The TASK_ZONE_CAPTURE class defines an Suppression or Extermination of Air Defenses task for a human player to be executed.
|
||||
-- The TASK_CAPTURE_ZONE class defines an Suppression or Extermination of Air Defenses task for a human player to be executed.
|
||||
-- These tasks are important to be executed as they will help to achieve air superiority at the vicinity.
|
||||
--
|
||||
-- The TASK_ZONE_CAPTURE is used by the @{Tasking.Task_A2G_Dispatcher#TASK_A2G_DISPATCHER} to automatically create SEAD tasks
|
||||
-- The TASK_CAPTURE_ZONE is used by the @{Tasking.Task_A2G_Dispatcher#TASK_A2G_DISPATCHER} to automatically create SEAD tasks
|
||||
-- based on detected enemy ground targets.
|
||||
--
|
||||
-- @field #TASK_ZONE_CAPTURE
|
||||
TASK_ZONE_CAPTURE = {
|
||||
ClassName = "TASK_ZONE_CAPTURE",
|
||||
-- @field #TASK_CAPTURE_ZONE
|
||||
TASK_CAPTURE_ZONE = {
|
||||
ClassName = "TASK_CAPTURE_ZONE",
|
||||
}
|
||||
|
||||
|
||||
--- Instantiates a new TASK_ZONE_CAPTURE.
|
||||
-- @param #TASK_ZONE_CAPTURE self
|
||||
--- Instantiates a new TASK_CAPTURE_ZONE.
|
||||
-- @param #TASK_CAPTURE_ZONE self
|
||||
-- @param Tasking.Mission#MISSION Mission
|
||||
-- @param Core.Set#SET_GROUP SetGroup The set of groups for which the Task can be assigned.
|
||||
-- @param #string TaskName The name of the Task.
|
||||
-- @param Core.ZoneGoalCoalition#ZONE_GOAL_COALITION ZoneGoalCoalition
|
||||
-- @param #string TaskBriefing The briefing of the task.
|
||||
-- @return #TASK_ZONE_CAPTURE self
|
||||
function TASK_ZONE_CAPTURE:New( Mission, SetGroup, TaskName, ZoneGoalCoalition, TaskBriefing)
|
||||
local self = BASE:Inherit( self, TASK_ZONE_GOAL:New( Mission, SetGroup, TaskName, ZoneGoalCoalition, "CAPTURE", TaskBriefing ) ) -- #TASK_ZONE_CAPTURE
|
||||
-- @return #TASK_CAPTURE_ZONE self
|
||||
function TASK_CAPTURE_ZONE:New( Mission, SetGroup, TaskName, ZoneGoalCoalition, TaskBriefing)
|
||||
local self = BASE:Inherit( self, TASK_ZONE_GOAL:New( Mission, SetGroup, TaskName, ZoneGoalCoalition, "CAPTURE", TaskBriefing ) ) -- #TASK_CAPTURE_ZONE
|
||||
self:F()
|
||||
|
||||
Mission:AddTask( self )
|
||||
@@ -206,42 +211,84 @@ do -- TASK_ZONE_CAPTURE
|
||||
"Capture Zone " .. self.TaskZoneName
|
||||
)
|
||||
|
||||
self:UpdateTaskInfo()
|
||||
self:UpdateTaskInfo( true )
|
||||
|
||||
self:SetGoal( self.ZoneGoal.Goal )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Instantiates a new TASK_ZONE_CAPTURE.
|
||||
-- @param #TASK_ZONE_CAPTURE self
|
||||
function TASK_ZONE_CAPTURE:UpdateTaskInfo()
|
||||
|
||||
|
||||
--- Instantiates a new TASK_CAPTURE_ZONE.
|
||||
-- @param #TASK_CAPTURE_ZONE self
|
||||
function TASK_CAPTURE_ZONE:UpdateTaskInfo( Persist )
|
||||
|
||||
Persist = Persist or false
|
||||
|
||||
local ZoneCoordinate = self.ZoneGoal:GetZone():GetCoordinate()
|
||||
self.TaskInfo:AddCoordinate( ZoneCoordinate, 0, "SOD" )
|
||||
self.TaskInfo:AddText( "Zone Name", self.ZoneGoal:GetZoneName(), 10, "MOD" )
|
||||
self.TaskInfo:AddText( "Zone Coalition", self.ZoneGoal:GetCoalitionName(), 11, "MOD" )
|
||||
self.TaskInfo:AddTaskName( 0, "MSOD", Persist )
|
||||
self.TaskInfo:AddCoordinate( ZoneCoordinate, 1, "SOD", Persist )
|
||||
-- self.TaskInfo:AddText( "Zone Name", self.ZoneGoal:GetZoneName(), 10, "MOD", Persist )
|
||||
-- self.TaskInfo:AddText( "Zone Coalition", self.ZoneGoal:GetCoalitionName(), 11, "MOD", Persist )
|
||||
local SetUnit = self.ZoneGoal:GetScannedSetUnit()
|
||||
local ThreatLevel, ThreatText = SetUnit:CalculateThreatLevelA2G()
|
||||
local ThreatCount = SetUnit:Count()
|
||||
self.TaskInfo:AddThreat( ThreatText, ThreatLevel, 20, "MOD", Persist )
|
||||
self.TaskInfo:AddInfo( "Remaining Units", ThreatCount, 21, "MOD", Persist, true)
|
||||
|
||||
if self.Dispatcher then
|
||||
local DefenseTaskCaptureDispatcher = self.Dispatcher:GetDefenseTaskCaptureDispatcher() -- Tasking.Task_Capture_Dispatcher#TASK_CAPTURE_DISPATCHER
|
||||
|
||||
if DefenseTaskCaptureDispatcher then
|
||||
-- Loop through all zones of the player Defenses, and check which zone has an assigned task!
|
||||
-- The Zones collection contains a Task. This Task is checked if it is assigned.
|
||||
-- If Assigned, then this task will be the task that is the closest to the defense zone.
|
||||
for TaskName, CaptureZone in pairs( DefenseTaskCaptureDispatcher.Zones or {} ) do
|
||||
local Task = CaptureZone.Task -- Tasking.Task_Capture_Zone#TASK_CAPTURE_ZONE
|
||||
if Task and Task:IsStateAssigned() then -- We also check assigned.
|
||||
-- Now we register the defense player zone information to the task report.
|
||||
self.TaskInfo:AddInfo( "Defense Player Zone", Task.ZoneGoal:GetName(), 30, "MOD", Persist )
|
||||
self.TaskInfo:AddCoordinate( Task.ZoneGoal:GetZone():GetCoordinate(), 31, "MOD", Persist, false, "Defense Player Coordinate" )
|
||||
end
|
||||
end
|
||||
end
|
||||
local DefenseAIA2GDispatcher = self.Dispatcher:GetDefenseAIA2GDispatcher() -- AI.AI_A2G_Dispatcher#AI_A2G_DISPATCHER
|
||||
|
||||
if DefenseAIA2GDispatcher then
|
||||
-- Loop through all the tasks of the AI Defenses, and check which zone is involved in the defenses and is active!
|
||||
for Defender, Task in pairs( DefenseAIA2GDispatcher:GetDefenderTasks() or {} ) do
|
||||
local DetectedItem = DefenseAIA2GDispatcher:GetDefenderTaskTarget( Defender )
|
||||
if DetectedItem then
|
||||
local DetectedZone = DefenseAIA2GDispatcher.Detection:GetDetectedItemZone( DetectedItem )
|
||||
if DetectedZone then
|
||||
self.TaskInfo:AddInfo( "Defense AI Zone", DetectedZone:GetName(), 40, "MOD", Persist )
|
||||
self.TaskInfo:AddCoordinate( DetectedZone:GetCoordinate(), 41, "MOD", Persist, false, "Defense AI Coordinate" )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
function TASK_ZONE_CAPTURE:ReportOrder( ReportGroup )
|
||||
local Coordinate = self:GetData( "Coordinate" )
|
||||
--local Coordinate = self.TaskInfo.Coordinates.TaskInfoText
|
||||
function TASK_CAPTURE_ZONE:ReportOrder( ReportGroup )
|
||||
|
||||
local Coordinate = self.TaskInfo:GetCoordinate()
|
||||
local Distance = ReportGroup:GetCoordinate():Get2DDistance( Coordinate )
|
||||
|
||||
return Distance
|
||||
end
|
||||
|
||||
|
||||
--- @param #TASK_ZONE_CAPTURE self
|
||||
--- @param #TASK_CAPTURE_ZONE self
|
||||
-- @param Wrapper.Unit#UNIT TaskUnit
|
||||
function TASK_ZONE_CAPTURE:OnAfterGoal( From, Event, To, PlayerUnit, PlayerName )
|
||||
function TASK_CAPTURE_ZONE:OnAfterGoal( From, Event, To, PlayerUnit, PlayerName )
|
||||
|
||||
self:F( { PlayerUnit = PlayerUnit } )
|
||||
self:F( { PlayerUnit = PlayerUnit, Achieved = self.ZoneGoal.Goal:IsAchieved() } )
|
||||
|
||||
if self.ZoneGoal then
|
||||
if self.ZoneGoal.Goal:IsAchieved() then
|
||||
self:Success()
|
||||
local TotalContributions = self.ZoneGoal.Goal:GetTotalContributions()
|
||||
local PlayerContributions = self.ZoneGoal.Goal:GetPlayerContributions()
|
||||
self:F( { TotalContributions = TotalContributions, PlayerContributions = PlayerContributions } )
|
||||
@@ -251,11 +298,32 @@ do -- TASK_ZONE_CAPTURE
|
||||
Scoring:_AddMissionGoalScore( self.Mission, PlayerName, "Zone " .. self.ZoneGoal:GetZoneName() .." captured", PlayerContribution * 200 / TotalContributions )
|
||||
end
|
||||
end
|
||||
self:Success()
|
||||
end
|
||||
end
|
||||
|
||||
self:__Goal( -10, PlayerUnit, PlayerName )
|
||||
end
|
||||
|
||||
--- This function is called from the @{Tasking.CommandCenter#COMMANDCENTER} to determine the method of automatic task selection.
|
||||
-- @param #TASK_CAPTURE_ZONE self
|
||||
-- @param #number AutoAssignMethod The method to be applied to the task.
|
||||
-- @param Tasking.CommandCenter#COMMANDCENTER CommandCenter The command center.
|
||||
-- @param Wrapper.Group#GROUP TaskGroup The player group.
|
||||
function TASK_CAPTURE_ZONE:GetAutoAssignPriority( AutoAssignMethod, CommandCenter, TaskGroup, AutoAssignReference )
|
||||
|
||||
if AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Random then
|
||||
return math.random( 1, 9 )
|
||||
elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Distance then
|
||||
local Coordinate = self.TaskInfo:GetCoordinate()
|
||||
local Distance = Coordinate:Get2DDistance( CommandCenter:GetPositionable():GetCoordinate() )
|
||||
return math.floor( Distance )
|
||||
elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Priority then
|
||||
return 1
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -185,7 +185,6 @@ do -- TASK_MANAGER
|
||||
-- @param #TASK_MANAGER self
|
||||
-- @return #TASK_MANAGER self
|
||||
function TASK_MANAGER:ManageTasks()
|
||||
self:E()
|
||||
|
||||
end
|
||||
|
||||
|
||||
15
Moose Development/Moose/Utilities/Enums.lua
Normal file
15
Moose Development/Moose/Utilities/Enums.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
ENUMS = {}
|
||||
|
||||
ENUMS.ROE = {
|
||||
HoldFire = 1,
|
||||
ReturnFire = 2,
|
||||
OpenFire = 3,
|
||||
WeaponFree = 4
|
||||
}
|
||||
|
||||
ENUMS.ROT = {
|
||||
NoReaction = 1,
|
||||
PassiveDefense = 2,
|
||||
EvadeFire = 3,
|
||||
Vertical = 4
|
||||
}
|
||||
@@ -21,6 +21,11 @@ routines.build = 22
|
||||
-- Utils- conversion, Lua utils, etc.
|
||||
routines.utils = {}
|
||||
|
||||
routines.utils.round = function(number, decimals)
|
||||
local power = 10^decimals
|
||||
return math.floor(number * power) / power
|
||||
end
|
||||
|
||||
--from http://lua-users.org/wiki/CopyTable
|
||||
routines.utils.deepCopy = function(object)
|
||||
local lookup_table = {}
|
||||
|
||||
@@ -43,6 +43,77 @@ BIGSMOKEPRESET = {
|
||||
HugeSmoke=7,
|
||||
}
|
||||
|
||||
--- DCS map as returned by env.mission.theatre.
|
||||
-- @type DCSMAP
|
||||
-- @field #string Caucasus Caucasus map.
|
||||
-- @field #string Normandy Normandy map.
|
||||
-- @field #string NTTR Nevada Test and Training Range map.
|
||||
-- @field #string PersianGulf Persian Gulf map.
|
||||
DCSMAP = {
|
||||
Caucasus="Caucasus",
|
||||
NTTR="Nevada",
|
||||
Normandy="Normandy",
|
||||
PersianGulf="PersianGulf"
|
||||
}
|
||||
|
||||
|
||||
--- See [DCS_enum_callsigns](https://wiki.hoggitworld.com/view/DCS_enum_callsigns)
|
||||
-- @type CALLSIGN
|
||||
CALLSIGN={
|
||||
-- Aircraft
|
||||
Aircraft={
|
||||
Enfield=1,
|
||||
Springfield=2,
|
||||
Uzi=3,
|
||||
Cold=4,
|
||||
Dodge=5,
|
||||
Ford=6,
|
||||
Chevy=7,
|
||||
Pontiac=8,
|
||||
-- A-10A or A-10C
|
||||
Hawg=9,
|
||||
Boar=10,
|
||||
Pig=11,
|
||||
Tusk=12,
|
||||
},
|
||||
-- AWACS
|
||||
AWACS={
|
||||
Overloard=1,
|
||||
Magic=2,
|
||||
Wizard=3,
|
||||
Focus=4,
|
||||
Darkstar=5,
|
||||
},
|
||||
-- Tanker
|
||||
Tanker={
|
||||
Texaco=1,
|
||||
Arco=2,
|
||||
Shell=3,
|
||||
},
|
||||
-- JTAC
|
||||
JTAC={
|
||||
Axeman=1,
|
||||
Darknight=2,
|
||||
Warrier=3,
|
||||
Pointer=4,
|
||||
Eyeball=5,
|
||||
Moonbeam=6,
|
||||
Whiplash=7,
|
||||
Finger=8,
|
||||
Pinpoint=9,
|
||||
Ferret=10,
|
||||
Shaba=11,
|
||||
Playboy=12,
|
||||
Hammer=13,
|
||||
Jaguar=14,
|
||||
Deathstar=15,
|
||||
Anvil=16,
|
||||
Firefly=17,
|
||||
Mantis=18,
|
||||
Badger=19,
|
||||
},
|
||||
} --#CALLSIGN
|
||||
|
||||
--- Utilities static class.
|
||||
-- @type UTILS
|
||||
UTILS = {
|
||||
@@ -250,7 +321,11 @@ UTILS.FeetToMeters = function(feet)
|
||||
end
|
||||
|
||||
UTILS.KnotsToKmph = function(knots)
|
||||
return knots* 1.852
|
||||
return knots * 1.852
|
||||
end
|
||||
|
||||
UTILS.KmphToKnots = function(knots)
|
||||
return knots / 1.852
|
||||
end
|
||||
|
||||
UTILS.KmphToMps = function( kmph )
|
||||
@@ -270,18 +345,37 @@ UTILS.MpsToMiph = function( mps )
|
||||
end
|
||||
|
||||
UTILS.MpsToKnots = function( mps )
|
||||
return mps * 3600 / 1852
|
||||
return mps * 1.94384 --3600 / 1852
|
||||
end
|
||||
|
||||
UTILS.KnotsToMps = function( knots )
|
||||
return knots * 1852 / 3600
|
||||
return knots / 1.94384 --* 1852 / 3600
|
||||
end
|
||||
|
||||
UTILS.CelciusToFarenheit = function( Celcius )
|
||||
return Celcius * 9/5 + 32
|
||||
end
|
||||
|
||||
--- Convert pressure from hecto Pascal (hPa) to inches of mercury (inHg).
|
||||
-- @param #number hPa Pressure in hPa.
|
||||
-- @return #number Pressure in inHg.
|
||||
UTILS.hPa2inHg = function( hPa )
|
||||
return hPa * 0.0295299830714
|
||||
end
|
||||
|
||||
--- Convert pressure from hecto Pascal (hPa) to millimeters of mercury (mmHg).
|
||||
-- @param #number hPa Pressure in hPa.
|
||||
-- @return #number Pressure in mmHg.
|
||||
UTILS.hPa2mmHg = function( hPa )
|
||||
return hPa * 0.7500615613030
|
||||
end
|
||||
|
||||
--- Convert kilo gramms (kg) to pounds (lbs).
|
||||
-- @param #number kg Mass in kg.
|
||||
-- @return #number Mass in lbs.
|
||||
UTILS.kg2lbs = function( kg )
|
||||
return kg * 2.20462
|
||||
end
|
||||
|
||||
--[[acc:
|
||||
in DM: decimal point of minutes.
|
||||
@@ -335,15 +429,16 @@ UTILS.tostringLL = function( lat, lon, acc, DMS)
|
||||
|
||||
local secFrmtStr -- create the formatting string for the seconds place
|
||||
secFrmtStr = '%02d'
|
||||
-- if acc <= 0 then -- no decimal place.
|
||||
-- secFrmtStr = '%02d'
|
||||
-- else
|
||||
-- local width = 3 + acc -- 01.310 - that's a width of 6, for example.
|
||||
-- secFrmtStr = '%0' .. width .. '.' .. acc .. 'f'
|
||||
-- end
|
||||
if acc <= 0 then -- no decimal place.
|
||||
secFrmtStr = '%02d'
|
||||
else
|
||||
local width = 3 + acc -- 01.310 - that's a width of 6, for example. Acc is limited to 2 for DMS!
|
||||
secFrmtStr = '%0' .. width .. '.' .. acc .. 'f'
|
||||
end
|
||||
|
||||
return string.format('%03d', latDeg) .. ' ' .. string.format('%02d', latMin) .. '\' ' .. string.format(secFrmtStr, latSec) .. '"' .. latHemi .. ' '
|
||||
.. string.format('%03d', lonDeg) .. ' ' .. string.format('%02d', lonMin) .. '\' ' .. string.format(secFrmtStr, lonSec) .. '"' .. lonHemi
|
||||
-- 024° 23' 12"N or 024° 23' 12.03"N
|
||||
return string.format('%03d°', latDeg) .. ' ' .. string.format('%02d', latMin) .. '\' ' .. string.format(secFrmtStr, latSec) .. '"' .. latHemi .. ' '
|
||||
.. string.format('%03d°', lonDeg) .. ' ' .. string.format('%02d', lonMin) .. '\' ' .. string.format(secFrmtStr, lonSec) .. '"' .. lonHemi
|
||||
|
||||
else -- degrees, decimal minutes.
|
||||
latMin = UTILS.Round(latMin, acc)
|
||||
@@ -367,8 +462,9 @@ UTILS.tostringLL = function( lat, lon, acc, DMS)
|
||||
minFrmtStr = '%0' .. width .. '.' .. acc .. 'f'
|
||||
end
|
||||
|
||||
return string.format('%03d', latDeg) .. ' ' .. string.format(minFrmtStr, latMin) .. '\'' .. latHemi .. ' '
|
||||
.. string.format('%03d', lonDeg) .. ' ' .. string.format(minFrmtStr, lonMin) .. '\'' .. lonHemi
|
||||
-- 024 23'N or 024 23.123'N
|
||||
return string.format('%03d°', latDeg) .. ' ' .. string.format(minFrmtStr, latMin) .. '\'' .. latHemi .. ' '
|
||||
.. string.format('%03d°', lonDeg) .. ' ' .. string.format(minFrmtStr, lonMin) .. '\'' .. lonHemi
|
||||
|
||||
end
|
||||
end
|
||||
@@ -425,6 +521,57 @@ function UTILS.spairs( t, order )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Here is a customized version of pairs, which I called kpairs because it iterates over the table in a sorted order, based on a function that will determine the keys as reference first.
|
||||
function UTILS.kpairs( t, getkey, order )
|
||||
-- collect the keys
|
||||
local keys = {}
|
||||
local keyso = {}
|
||||
for k, o in pairs(t) do keys[#keys+1] = k keyso[#keyso+1] = getkey( o ) end
|
||||
|
||||
-- if order function given, sort by it by passing the table and keys a, b,
|
||||
-- otherwise just sort the keys
|
||||
if order then
|
||||
table.sort(keys, function(a,b) return order(t, a, b) end)
|
||||
else
|
||||
table.sort(keys)
|
||||
end
|
||||
|
||||
-- return the iterator function
|
||||
local i = 0
|
||||
return function()
|
||||
i = i + 1
|
||||
if keys[i] then
|
||||
return keyso[i], t[keys[i]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Here is a customized version of pairs, which I called rpairs because it iterates over the table in a random order.
|
||||
function UTILS.rpairs( t )
|
||||
-- collect the keys
|
||||
|
||||
local keys = {}
|
||||
for k in pairs(t) do keys[#keys+1] = k end
|
||||
|
||||
local random = {}
|
||||
local j = #keys
|
||||
for i = 1, j do
|
||||
local k = math.random( 1, #keys )
|
||||
random[i] = keys[k]
|
||||
table.remove( keys, k )
|
||||
end
|
||||
|
||||
-- return the iterator function
|
||||
local i = 0
|
||||
return function()
|
||||
i = i + 1
|
||||
if random[i] then
|
||||
return random[i], t[random[i]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- get a new mark ID for markings
|
||||
function UTILS.GetMarkID()
|
||||
|
||||
@@ -512,8 +659,9 @@ end
|
||||
|
||||
--- Convert time in seconds to hours, minutes and seconds.
|
||||
-- @param #number seconds Time in seconds, e.g. from timer.getAbsTime() function.
|
||||
-- @param #boolean short (Optional) If true, use short output, i.e. (HH:)MM:SS without day.
|
||||
-- @return #string Time in format Hours:Minutes:Seconds+Days (HH:MM:SS+D).
|
||||
function UTILS.SecondsToClock(seconds)
|
||||
function UTILS.SecondsToClock(seconds, short)
|
||||
|
||||
-- Nil check.
|
||||
if seconds==nil then
|
||||
@@ -526,20 +674,28 @@ function UTILS.SecondsToClock(seconds)
|
||||
-- Seconds of this day.
|
||||
local _seconds=seconds%(60*60*24)
|
||||
|
||||
if seconds <= 0 then
|
||||
if seconds<0 then
|
||||
return nil
|
||||
else
|
||||
local hours = string.format("%02.f", math.floor(_seconds/3600))
|
||||
local mins = string.format("%02.f", math.floor(_seconds/60 - (hours*60)))
|
||||
local secs = string.format("%02.f", math.floor(_seconds - hours*3600 - mins *60))
|
||||
local days = string.format("%d", seconds/(60*60*24))
|
||||
return hours..":"..mins..":"..secs.."+"..days
|
||||
local clock=hours..":"..mins..":"..secs.."+"..days
|
||||
if short then
|
||||
if hours=="00" then
|
||||
clock=mins..":"..secs
|
||||
else
|
||||
clock=hours..":"..mins..":"..secs
|
||||
end
|
||||
end
|
||||
return clock
|
||||
end
|
||||
end
|
||||
|
||||
--- Convert clock time from hours, minutes and seconds to seconds.
|
||||
-- @param #string clock String of clock time. E.g., "06:12:35" or "5:1:30+1". Format is (H)H:(M)M:((S)S)(+D) H=Hours, M=Minutes, S=Seconds, D=Days.
|
||||
-- @param #number Seconds. Corresponds to what you cet from timer.getAbsTime() function.
|
||||
-- @return #number Seconds. Corresponds to what you cet from timer.getAbsTime() function.
|
||||
function UTILS.ClockToSeconds(clock)
|
||||
|
||||
-- Nil check.
|
||||
@@ -551,7 +707,7 @@ function UTILS.ClockToSeconds(clock)
|
||||
local seconds=0
|
||||
|
||||
-- Split additional days.
|
||||
local dsplit=UTILS.split(clock, "+")
|
||||
local dsplit=UTILS.Split(clock, "+")
|
||||
|
||||
-- Convert days to seconds.
|
||||
if #dsplit>1 then
|
||||
@@ -680,3 +836,204 @@ function UTILS.VecCross(a, b)
|
||||
return {x=a.y*b.z - a.z*b.y, y=a.z*b.x - a.x*b.z, z=a.x*b.y - a.y*b.x}
|
||||
end
|
||||
|
||||
--- Calculate the difference between two 3D vectors by substracting the x,y,z components from each other.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
-- @return DCS#Vec3 Vector c=a-b with c(i)=a(i)-b(i), i=x,y,z.
|
||||
function UTILS.VecSubstract(a, b)
|
||||
return {x=a.x-b.x, y=a.y-b.y, z=a.z-b.z}
|
||||
end
|
||||
|
||||
--- Calculate the total vector of two 3D vectors by adding the x,y,z components of each other.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
-- @return DCS#Vec3 Vector c=a+b with c(i)=a(i)+b(i), i=x,y,z.
|
||||
function UTILS.VecAdd(a, b)
|
||||
return {x=a.x+b.x, y=a.y+b.y, z=a.z+b.z}
|
||||
end
|
||||
|
||||
--- Calculate the angle between two 3D vectors.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
-- @return #number Angle alpha between and b in degrees. alpha=acos(a*b)/(|a||b|), (* denotes the dot product).
|
||||
function UTILS.VecAngle(a, b)
|
||||
|
||||
local cosalpha=UTILS.VecDot(a,b)/(UTILS.VecNorm(a)*UTILS.VecNorm(b))
|
||||
|
||||
local alpha=0
|
||||
if cosalpha>=0.9999999999 then --acos(1) is not defined.
|
||||
alpha=0
|
||||
elseif cosalpha<=-0.999999999 then --acos(-1) is not defined.
|
||||
alpha=math.pi
|
||||
else
|
||||
alpha=math.acos(cosalpha)
|
||||
end
|
||||
|
||||
return math.deg(alpha)
|
||||
end
|
||||
|
||||
--- Calculate "heading" of a 3D vector in the X-Z plane.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @return #number Heading in degrees in [0,360).
|
||||
function UTILS.VecHdg(a)
|
||||
local h=math.deg(math.atan2(a.z, a.x))
|
||||
if h<0 then
|
||||
h=h+360
|
||||
end
|
||||
return h
|
||||
end
|
||||
|
||||
--- Calculate the difference between two "heading", i.e. angles in [0,360) deg.
|
||||
-- @param #number h1 Heading one.
|
||||
-- @param #number h2 Heading two.
|
||||
-- @return #number Heading difference in degrees.
|
||||
function UTILS.HdgDiff(h1, h2)
|
||||
|
||||
-- Angle in rad.
|
||||
local alpha= math.rad(tonumber(h1))
|
||||
local beta = math.rad(tonumber(h2))
|
||||
|
||||
-- Runway vector.
|
||||
local v1={x=math.cos(alpha), y=0, z=math.sin(alpha)}
|
||||
local v2={x=math.cos(beta), y=0, z=math.sin(beta)}
|
||||
|
||||
local delta=UTILS.VecAngle(v1, v2)
|
||||
|
||||
return math.abs(delta)
|
||||
end
|
||||
|
||||
|
||||
--- Rotate 3D vector in the 2D (x,z) plane. y-component (usually altitude) unchanged.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param #number angle Rotation angle in degrees.
|
||||
-- @return DCS#Vec3 Vector rotated in the (x,z) plane.
|
||||
function UTILS.Rotate2D(a, angle)
|
||||
|
||||
local phi=math.rad(angle)
|
||||
|
||||
local x=a.z
|
||||
local y=a.x
|
||||
|
||||
local Z=x*math.cos(phi)-y*math.sin(phi)
|
||||
local X=x*math.sin(phi)+y*math.cos(phi)
|
||||
local Y=a.y
|
||||
|
||||
local A={x=X, y=Y, z=Z}
|
||||
|
||||
return A
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Converts a TACAN Channel/Mode couple into a frequency in Hz.
|
||||
-- @param #number TACANChannel The TACAN channel, i.e. the 10 in "10X".
|
||||
-- @param #string TACANMode The TACAN mode, i.e. the "X" in "10X".
|
||||
-- @return #number Frequency in Hz or #nil if parameters are invalid.
|
||||
function UTILS.TACANToFrequency(TACANChannel, TACANMode)
|
||||
|
||||
if type(TACANChannel) ~= "number" then
|
||||
return nil -- error in arguments
|
||||
end
|
||||
if TACANMode ~= "X" and TACANMode ~= "Y" then
|
||||
return nil -- error in arguments
|
||||
end
|
||||
|
||||
-- This code is largely based on ED's code, in DCS World\Scripts\World\Radio\BeaconTypes.lua, line 137.
|
||||
-- I have no idea what it does but it seems to work
|
||||
local A = 1151 -- 'X', channel >= 64
|
||||
local B = 64 -- channel >= 64
|
||||
|
||||
if TACANChannel < 64 then
|
||||
B = 1
|
||||
end
|
||||
|
||||
if TACANMode == 'Y' then
|
||||
A = 1025
|
||||
if TACANChannel < 64 then
|
||||
A = 1088
|
||||
end
|
||||
else -- 'X'
|
||||
if TACANChannel < 64 then
|
||||
A = 962
|
||||
end
|
||||
end
|
||||
|
||||
return (A + TACANChannel - B) * 1000000
|
||||
end
|
||||
|
||||
|
||||
--- Returns the DCS map/theatre as optained by env.mission.theatre
|
||||
-- @return #string DCS map name .
|
||||
function UTILS.GetDCSMap()
|
||||
return env.mission.theatre
|
||||
end
|
||||
|
||||
--- Returns the mission date. This is the date the mission started.
|
||||
-- @return #string Mission date in yyyy/mm/dd format.
|
||||
function UTILS.GetDCSMissionDate()
|
||||
local year=tostring(env.mission.date.Year)
|
||||
local month=tostring(env.mission.date.Month)
|
||||
local day=tostring(env.mission.date.Day)
|
||||
return string.format("%s/%s/%s", year, month, day)
|
||||
end
|
||||
|
||||
|
||||
--- Returns the magnetic declination of the map.
|
||||
-- Returned values for the current maps are:
|
||||
--
|
||||
-- * Caucasus +6 (East), year ~ 2011
|
||||
-- * NTTR +12 (East), year ~ 2011
|
||||
-- * Normandy -10 (West), year ~ 1944
|
||||
-- * Persian Gulf +2 (East), year ~ 2011
|
||||
-- @param #string map (Optional) Map for which the declination is returned. Default is from env.mission.theatre
|
||||
-- @return #number Declination in degrees.
|
||||
function UTILS.GetMagneticDeclination(map)
|
||||
|
||||
-- Map.
|
||||
map=map or UTILS.GetDCSMap()
|
||||
|
||||
local declination=0
|
||||
if map==DCSMAP.Caucasus then
|
||||
declination=6
|
||||
elseif map==DCSMAP.NTTR then
|
||||
declination=12
|
||||
elseif map==DCSMAP.Normandy then
|
||||
declination=-10
|
||||
elseif map==DCSMAP.PersianGulf then
|
||||
declination=2
|
||||
else
|
||||
declination=0
|
||||
end
|
||||
|
||||
return declination
|
||||
end
|
||||
|
||||
--- Checks if a file exists or not. This requires **io** to be desanitized.
|
||||
-- @param #string file File that should be checked.
|
||||
-- @return #boolean True if the file exists, false if the file does not exist or nil if the io module is not available and the check could not be performed.
|
||||
function UTILS.FileExists(file)
|
||||
if io then
|
||||
local f=io.open(file, "r")
|
||||
if f~=nil then
|
||||
io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
--- Checks the current memory usage collectgarbage("count"). Info is printed to the DCS log file. Time stamp is the current mission runtime.
|
||||
-- @param #boolean output If true, print to DCS log file.
|
||||
-- @return #number Memory usage in kByte.
|
||||
function UTILS.CheckMemory(output)
|
||||
local time=timer.getTime()
|
||||
local clock=UTILS.SecondsToClock(time)
|
||||
local mem=collectgarbage("count")
|
||||
if output then
|
||||
env.info(string.format("T=%s Memory usage %d kByte = %.2f MByte", clock, mem, mem/1024))
|
||||
end
|
||||
return mem
|
||||
end
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
|
||||
|
||||
--- @type AIRBASE
|
||||
-- @field #string ClassName Name of the class, i.e. "AIRBASE".
|
||||
-- @field #table CategoryName Names of airbase categories.
|
||||
-- @field #number activerwyno Active runway number (forced).
|
||||
-- @extends Wrapper.Positionable#POSITIONABLE
|
||||
|
||||
--- Wrapper class to handle the DCS Airbase objects:
|
||||
@@ -54,6 +57,7 @@ AIRBASE = {
|
||||
[Airbase.Category.HELIPAD] = "Helipad",
|
||||
[Airbase.Category.SHIP] = "Ship",
|
||||
},
|
||||
activerwyno=nil,
|
||||
}
|
||||
|
||||
--- Enumeration to identify the airbases in the Caucasus region.
|
||||
@@ -218,48 +222,68 @@ AIRBASE.Normandy = {
|
||||
}
|
||||
|
||||
--- These are all airbases of the Persion Gulf Map:
|
||||
--
|
||||
-- * AIRBASE.PersianGulf.Fujairah_Intl
|
||||
-- * AIRBASE.PersianGulf.Qeshm_Island
|
||||
-- * AIRBASE.PersianGulf.Sir_Abu_Nuayr
|
||||
--
|
||||
-- * AIRBASE.PersianGulf.Abu_Dhabi_International_Airport
|
||||
-- * AIRBASE.PersianGulf.Abu_Musa_Island_Airport
|
||||
-- * AIRBASE.PersianGulf.Al-Bateen_Airport
|
||||
-- * AIRBASE.PersianGulf.Al_Ain_International_Airport
|
||||
-- * AIRBASE.PersianGulf.Al_Dhafra_AB
|
||||
-- * AIRBASE.PersianGulf.Al_Maktoum_Intl
|
||||
-- * AIRBASE.PersianGulf.Al_Minhad_AB
|
||||
-- * AIRBASE.PersianGulf.Bandar_e_Jask_airfield
|
||||
-- * AIRBASE.PersianGulf.Bandar_Abbas_Intl
|
||||
-- * AIRBASE.PersianGulf.Bandar_Lengeh
|
||||
-- * AIRBASE.PersianGulf.Tunb_Island_AFB
|
||||
-- * AIRBASE.PersianGulf.Havadarya
|
||||
-- * AIRBASE.PersianGulf.Lar_Airbase
|
||||
-- * AIRBASE.PersianGulf.Sirri_Island
|
||||
-- * AIRBASE.PersianGulf.Tunb_Kochak
|
||||
-- * AIRBASE.PersianGulf.Al_Dhafra_AB
|
||||
-- * AIRBASE.PersianGulf.Dubai_Intl
|
||||
-- * AIRBASE.PersianGulf.Al_Maktoum_Intl
|
||||
-- * AIRBASE.PersianGulf.Fujairah_Intl
|
||||
-- * AIRBASE.PersianGulf.Havadarya
|
||||
-- * AIRBASE.PersianGulf.Jiroft_Airport
|
||||
-- * AIRBASE.PersianGulf.Kerman_Airport
|
||||
-- * AIRBASE.PersianGulf.Khasab
|
||||
-- * AIRBASE.PersianGulf.Al_Minhad_AB
|
||||
-- * AIRBASE.PersianGulf.Kish_International_Airport
|
||||
-- * AIRBASE.PersianGulf.Lar_Airbase
|
||||
-- * AIRBASE.PersianGulf.Lavan_Island_Airport
|
||||
-- * AIRBASE.PersianGulf.Liwa_Airbase
|
||||
-- * AIRBASE.PersianGulf.Qeshm_Island
|
||||
-- * AIRBASE.PersianGulf.Ras_Al_Khaimah_International_Airport
|
||||
-- * AIRBASE.PersianGulf.Sas_Al_Nakheel_Airport
|
||||
-- * AIRBASE.PersianGulf.Sharjah_Intl
|
||||
-- * AIRBASE.PersianGulf.Shiraz_International_Airport
|
||||
-- * AIRBASE.PersianGulf.Kerman_Airport
|
||||
-- * AIRBASE.PersianGulf.Sir_Abu_Nuayr
|
||||
-- * AIRBASE.PersianGulf.Sirri_Island
|
||||
-- * AIRBASE.PersianGulf.Tunb_Island_AFB
|
||||
-- * AIRBASE.PersianGulf.Tunb_Kochak
|
||||
-- @field PersianGulf
|
||||
AIRBASE.PersianGulf = {
|
||||
["Fujairah_Intl"] = "Fujairah Intl",
|
||||
["Qeshm_Island"] = "Qeshm Island",
|
||||
["Sir_Abu_Nuayr"] = "Sir Abu Nuayr",
|
||||
["Abu_Dhabi_International_Airport"] = "Abu Dhabi International Airport",
|
||||
["Abu_Musa_Island_Airport"] = "Abu Musa Island Airport",
|
||||
["Al_Ain_International_Airport"] = "Al Ain International Airport",
|
||||
["Al_Bateen_Airport"] = "Al-Bateen Airport",
|
||||
["Al_Dhafra_AB"] = "Al Dhafra AB",
|
||||
["Al_Maktoum_Intl"] = "Al Maktoum Intl",
|
||||
["Al_Minhad_AB"] = "Al Minhad AB",
|
||||
["Bandar_Abbas_Intl"] = "Bandar Abbas Intl",
|
||||
["Bandar_Lengeh"] = "Bandar Lengeh",
|
||||
["Tunb_Island_AFB"] = "Tunb Island AFB",
|
||||
["Bandar_e_Jask_airfield"] = "Bandar-e-Jask airfield",
|
||||
["Dubai_Intl"] = "Dubai Intl",
|
||||
["Fujairah_Intl"] = "Fujairah Intl",
|
||||
["Havadarya"] = "Havadarya",
|
||||
["Lar_Airbase"] = "Lar Airbase",
|
||||
["Sirri_Island"] = "Sirri Island",
|
||||
["Tunb_Kochak"] = "Tunb Kochak",
|
||||
["Al_Dhafra_AB"] = "Al Dhafra AB",
|
||||
["Dubai_Intl"] = "Dubai Intl",
|
||||
["Al_Maktoum_Intl"] = "Al Maktoum Intl",
|
||||
["Jiroft_Airport"] = "Jiroft Airport",
|
||||
["Kerman_Airport"] = "Kerman Airport",
|
||||
["Khasab"] = "Khasab",
|
||||
["Al_Minhad_AB"] = "Al Minhad AB",
|
||||
["Kish_International_Airport"] = "Kish International Airport",
|
||||
["Lar_Airbase"] = "Lar Airbase",
|
||||
["Lavan_Island_Airport"] = "Lavan Island Airport",
|
||||
["Liwa_Airbase"] = "Liwa Airbase",
|
||||
["Qeshm_Island"] = "Qeshm Island",
|
||||
["Ras_Al_Khaimah_International_Airport"] = "Ras Al Khaimah International Airport",
|
||||
["Sas_Al_Nakheel_Airport"] = "Sas Al Nakheel Airport",
|
||||
["Sharjah_Intl"] = "Sharjah Intl",
|
||||
["Shiraz_International_Airport"] = "Shiraz International Airport",
|
||||
["Kerman_Airport"] = "Kerman Airport",
|
||||
}
|
||||
["Sir_Abu_Nuayr"] = "Sir Abu Nuayr",
|
||||
["Sirri_Island"] = "Sirri Island",
|
||||
["Tunb_Island_AFB"] = "Tunb Island AFB",
|
||||
["Tunb_Kochak"] = "Tunb Kochak",
|
||||
}
|
||||
|
||||
--- AIRBASE.ParkingSpot ".Coordinate, ".TerminalID", ".TerminalType", ".TOAC", ".Free", ".TerminalID0", ".DistToRwy".
|
||||
-- @type AIRBASE.ParkingSpot
|
||||
@@ -291,7 +315,7 @@ AIRBASE.PersianGulf = {
|
||||
-- @field #number OpenMed 72: Open/Shelter air airplane only.
|
||||
-- @field #number OpenBig 104: Open air spawn points. Generally larger but does not guarantee large aircraft are capable of spawning there.
|
||||
-- @field #number OpenMedOrBig 176: Combines OpenMed and OpenBig spots.
|
||||
-- @field #number HelicopterUnsable 216: Combines HelicopterOnly, OpenMed and OpenBig.
|
||||
-- @field #number HelicopterUsable 216: Combines HelicopterOnly, OpenMed and OpenBig.
|
||||
-- @field #number FighterAircraft 244: Combines Shelter. OpenMed and OpenBig spots. So effectively all spots usable by fixed wing aircraft.
|
||||
AIRBASE.TerminalType = {
|
||||
Runway=16,
|
||||
@@ -304,6 +328,14 @@ AIRBASE.TerminalType = {
|
||||
FighterAircraft=244,
|
||||
}
|
||||
|
||||
--- Runway data.
|
||||
-- @type AIRBASE.Runway
|
||||
-- @field #number heading Heading of the runway in degrees.
|
||||
-- @field #string idx Runway ID: heading 070° ==> idx="07".
|
||||
-- @field #number length Length of runway in meters.
|
||||
-- @field Core.Point#COORDINATE position Position of runway start.
|
||||
-- @field Core.Point#COORDINATE endpoint End point of runway.
|
||||
|
||||
-- Registration.
|
||||
|
||||
--- Create a new AIRBASE from DCSAirbase.
|
||||
@@ -341,6 +373,26 @@ function AIRBASE:FindByName( AirbaseName )
|
||||
return AirbaseFound
|
||||
end
|
||||
|
||||
--- Find a AIRBASE in the _DATABASE by its ID.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #number id Airbase ID.
|
||||
-- @return #AIRBASE self
|
||||
function AIRBASE:FindByID(id)
|
||||
|
||||
for name,_airbase in pairs(_DATABASE.AIRBASES) do
|
||||
local airbase=_airbase --#AIRBASE
|
||||
|
||||
local aid=tonumber(airbase:GetID())
|
||||
|
||||
if aid==id then
|
||||
return airbase
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Get the DCS object of an airbase
|
||||
-- @param #AIRBASE self
|
||||
-- @return DCS#Airbase DCS airbase object.
|
||||
@@ -363,13 +415,17 @@ end
|
||||
|
||||
--- Get all airbases of the current map. This includes ships and FARPS.
|
||||
-- @param DCS#Coalition coalition (Optional) Return only airbases belonging to the specified coalition. By default, all airbases of the map are returned.
|
||||
-- @param #number category (Optional) Return only airbases of a certain category, e.g. Airbase.Category.FARP
|
||||
-- @return #table Table containing all airbase objects of the current map.
|
||||
function AIRBASE.GetAllAirbases(coalition)
|
||||
function AIRBASE.GetAllAirbases(coalition, category)
|
||||
|
||||
local airbases={}
|
||||
for _,airbase in pairs(_DATABASE.AIRBASES) do
|
||||
for _,_airbase in pairs(_DATABASE.AIRBASES) do
|
||||
local airbase=_airbase --#AIRBASE
|
||||
if (coalition~=nil and airbase:GetCoalition()==coalition) or coalition==nil then
|
||||
table.insert(airbases, airbase)
|
||||
if category==nil or category==airbase:GetAirbaseCategory() then
|
||||
table.insert(airbases, airbase)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -490,7 +546,7 @@ function AIRBASE:GetParkingSpotsCoordinates(termtype)
|
||||
|
||||
-- Put coordinates of free spots into table.
|
||||
local spots={}
|
||||
for _,parkingspot in pairs(parkingdata) do
|
||||
for _,parkingspot in ipairs(parkingdata) do
|
||||
|
||||
-- Coordinates on runway are not returned unless explicitly requested.
|
||||
if AIRBASE._CheckTerminalType(parkingspot.Term_Type, termtype) then
|
||||
@@ -533,12 +589,15 @@ function AIRBASE:GetParkingSpotsTable(termtype)
|
||||
local spots={}
|
||||
for _,_spot in pairs(parkingdata) do
|
||||
if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) then
|
||||
self:T2({_spot=_spot})
|
||||
local _free=_isfree(_spot)
|
||||
local _coord=COORDINATE:NewFromVec3(_spot.vTerminalPos)
|
||||
table.insert(spots, {Coordinate=_coord, TerminalID=_spot.Term_Index, TerminalType=_spot.Term_Type, TOAC=_spot.TO_AC, Free=_free, TerminalID0=_spot.Term_Index_0, DistToRwy=_spot.fDistToRW})
|
||||
end
|
||||
end
|
||||
|
||||
self:T2({ spots = spots } )
|
||||
|
||||
return spots
|
||||
end
|
||||
|
||||
@@ -555,7 +614,7 @@ function AIRBASE:GetFreeParkingSpotsTable(termtype, allowTOAC)
|
||||
-- Put coordinates of free spots into table.
|
||||
local freespots={}
|
||||
for _,_spot in pairs(parkingfree) do
|
||||
if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) then
|
||||
if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) and _spot.Term_Index>0 then
|
||||
if (allowTOAC and allowTOAC==true) or _spot.TO_AC==false then
|
||||
local _coord=COORDINATE:NewFromVec3(_spot.vTerminalPos)
|
||||
table.insert(freespots, {Coordinate=_coord, TerminalID=_spot.Term_Index, TerminalType=_spot.Term_Type, TOAC=_spot.TO_AC, Free=true, TerminalID0=_spot.Term_Index_0, DistToRwy=_spot.fDistToRW})
|
||||
@@ -566,6 +625,31 @@ function AIRBASE:GetFreeParkingSpotsTable(termtype, allowTOAC)
|
||||
return freespots
|
||||
end
|
||||
|
||||
--- Get a table containing the coordinates, terminal index and terminal type of free parking spots at an airbase.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #number TerminalID The terminal ID of the parking spot.
|
||||
-- @return #AIRBASE.ParkingSpot Table free parking spots. Table has the elements ".Coordinate, ".TerminalID", ".TerminalType", ".TOAC", ".Free", ".TerminalID0", ".DistToRwy".
|
||||
function AIRBASE:GetParkingSpotData(TerminalID)
|
||||
self:F({TerminalID=TerminalID})
|
||||
|
||||
-- Get parking data.
|
||||
local parkingdata=self:GetParkingSpotsTable()
|
||||
|
||||
-- Debug output.
|
||||
self:T2({parkingdata=parkingdata})
|
||||
|
||||
for _,_spot in pairs(parkingdata) do
|
||||
local spot=_spot --#AIRBASE.ParkingSpot
|
||||
self:T({TerminalID=spot.TerminalID,TerminalType=spot.TerminalType})
|
||||
if TerminalID==spot.TerminalID then
|
||||
return spot
|
||||
end
|
||||
end
|
||||
|
||||
self:E("ERROR: Could not find spot with Terminal ID="..tostring(TerminalID))
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Place markers of parking spots on the F10 map.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #AIRBASE.TerminalType termtype Terminal type for which marks should be placed.
|
||||
@@ -632,31 +716,20 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
|
||||
verysafe=false
|
||||
end
|
||||
|
||||
-- Get the size of an object.
|
||||
local function _GetObjectSize(unit,mooseobject)
|
||||
if mooseobject then
|
||||
unit=unit:GetDCSObject()
|
||||
end
|
||||
if unit and unit:isExist() then
|
||||
local DCSdesc=unit:getDesc()
|
||||
if DCSdesc.box then
|
||||
local x=DCSdesc.box.max.x+math.abs(DCSdesc.box.min.x)
|
||||
local y=DCSdesc.box.max.y+math.abs(DCSdesc.box.min.y) --height
|
||||
local z=DCSdesc.box.max.z+math.abs(DCSdesc.box.min.z)
|
||||
return math.max(x,z), x , y, z
|
||||
end
|
||||
end
|
||||
return 0,0,0,0
|
||||
end
|
||||
|
||||
-- Function calculating the overlap of two (square) objects.
|
||||
local function _overlap(object1, mooseobject1, object2, mooseobject2, dist)
|
||||
local l1=_GetObjectSize(object1, mooseobject1)
|
||||
local l2=_GetObjectSize(object2, mooseobject2)
|
||||
local safedist=(l1/2+l2/2)*1.1
|
||||
local safe = (dist > safedist)
|
||||
self:T3(string.format("l1=%.1f l2=%.1f s=%.1f d=%.1f ==> safe=%s", l1,l2,safedist,dist,tostring(safe)))
|
||||
return safe
|
||||
local function _overlap(object1, object2, dist)
|
||||
local pos1=object1 --Wrapper.Positionable#POSITIONABLE
|
||||
local pos2=object2 --Wrapper.Positionable#POSITIONABLE
|
||||
local r1=pos1:GetBoundingRadius()
|
||||
local r2=pos2:GetBoundingRadius()
|
||||
if r1 and r2 then
|
||||
local safedist=(r1+r2)*1.1
|
||||
local safe = (dist > safedist)
|
||||
self:T2(string.format("r1=%.1f r2=%.1f s=%.1f d=%.1f ==> safe=%s", r1, r2, safedist, dist, tostring(safe)))
|
||||
return safe
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- Get airport name.
|
||||
@@ -671,7 +744,7 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
|
||||
|
||||
-- Get the aircraft size, i.e. it's longest side of x,z.
|
||||
local aircraft=group:GetUnit(1)
|
||||
local _aircraftsize, ax,ay,az=_GetObjectSize(aircraft, true)
|
||||
local _aircraftsize, ax,ay,az=aircraft:GetObjectSize()
|
||||
|
||||
-- Number of spots we are looking for. Note that, e.g. grouping can require a number different from the group size!
|
||||
local _nspots=nspots or group:GetSize()
|
||||
@@ -699,13 +772,15 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
|
||||
local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE
|
||||
local _termid=parkingspot.TerminalID
|
||||
|
||||
self:T2({_termid=_termid})
|
||||
|
||||
if AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) then
|
||||
|
||||
-- Very safe uses the DCS getParking() info to check if a spot is free. Unfortunately, the function returns free=false until the aircraft has actually taken-off.
|
||||
if verysafe and (parkingspot.Free==false or parkingspot.TOAC==true) then
|
||||
|
||||
-- DCS getParking() routine returned that spot is not free.
|
||||
self:E(string.format("%s: Parking spot id %d NOT free (or aircraft has not taken off yet). Free=%s, TOAC=%s.", airport, parkingspot.TerminalID, tostring(parkingspot.Free), tostring(parkingspot.TOAC)))
|
||||
self:T(string.format("%s: Parking spot id %d NOT free (or aircraft has not taken off yet). Free=%s, TOAC=%s.", airport, parkingspot.TerminalID, tostring(parkingspot.Free), tostring(parkingspot.TOAC)))
|
||||
|
||||
else
|
||||
|
||||
@@ -717,16 +792,13 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
|
||||
|
||||
-- Check all units.
|
||||
for _,unit in pairs(_units) do
|
||||
-- Unis are now returned as MOOSE units not DCS units!
|
||||
--local _vec3=unit:getPoint()
|
||||
--local _coord=COORDINATE:NewFromVec3(_vec3)
|
||||
local _coord=unit:GetCoordinate()
|
||||
local _dist=_coord:Get2DDistance(_spot)
|
||||
local _safe=_overlap(aircraft, true, unit, true,_dist)
|
||||
local _safe=_overlap(aircraft, unit, _dist)
|
||||
|
||||
if markobstacles then
|
||||
local l,x,y,z=_GetObjectSize(unit)
|
||||
_coord:MarkToAll(string.format("Unit %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", unit:getName(),x,y,z,l,_dist, _termid, tostring(_safe)))
|
||||
local l,x,y,z=unit:GetObjectSize()
|
||||
_coord:MarkToAll(string.format("Unit %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", unit:GetName(),x,y,z,l,_dist, _termid, tostring(_safe)))
|
||||
end
|
||||
|
||||
if scanunits and not _safe then
|
||||
@@ -736,13 +808,14 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
|
||||
|
||||
-- Check all statics.
|
||||
for _,static in pairs(_statics) do
|
||||
local _static=STATIC:Find(static)
|
||||
local _vec3=static:getPoint()
|
||||
local _coord=COORDINATE:NewFromVec3(_vec3)
|
||||
local _dist=_coord:Get2DDistance(_spot)
|
||||
local _safe=_overlap(aircraft, true, static, false,_dist)
|
||||
local _safe=_overlap(aircraft,_static,_dist)
|
||||
|
||||
if markobstacles then
|
||||
local l,x,y,z=_GetObjectSize(static)
|
||||
local l,x,y,z=_static:GetObjectSize()
|
||||
_coord:MarkToAll(string.format("Static %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", static:getName(),x,y,z,l,_dist, _termid, tostring(_safe)))
|
||||
end
|
||||
|
||||
@@ -753,13 +826,14 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
|
||||
|
||||
-- Check all scenery.
|
||||
for _,scenery in pairs(_sceneries) do
|
||||
local _scenery=SCENERY:Register(scenery:getTypeName(), scenery)
|
||||
local _vec3=scenery:getPoint()
|
||||
local _coord=COORDINATE:NewFromVec3(_vec3)
|
||||
local _dist=_coord:Get2DDistance(_spot)
|
||||
local _safe=_overlap(aircraft, true, scenery, false,_dist)
|
||||
local _safe=_overlap(aircraft,_scenery,_dist)
|
||||
|
||||
if markobstacles then
|
||||
local l,x,y,z=_GetObjectSize(scenery)
|
||||
local l,x,y,z=scenery:GetObjectSize(scenery)
|
||||
_coord:MarkToAll(string.format("Scenery %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", scenery:getTypeName(),x,y,z,l,_dist, _termid, tostring(_safe)))
|
||||
end
|
||||
|
||||
@@ -771,7 +845,7 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
|
||||
-- Now check the already given spots so that we do not put a large aircraft next to one we already assigned a nearby spot.
|
||||
for _,_takenspot in pairs(validspots) do
|
||||
local _dist=_takenspot.Coordinate:Get2DDistance(_spot)
|
||||
local _safe=_overlap(aircraft, true, aircraft, true,_dist)
|
||||
local _safe=_overlap(aircraft, aircraft, _dist)
|
||||
if not _safe then
|
||||
occupied=true
|
||||
end
|
||||
@@ -779,13 +853,14 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
|
||||
|
||||
--_spot:MarkToAll(string.format("Parking spot %d free=%s", parkingspot.TerminalID, tostring(not occupied)))
|
||||
if occupied then
|
||||
self:T(string.format("%s: Parking spot id %d occupied.", airport, _termid))
|
||||
self:I(string.format("%s: Parking spot id %d occupied.", airport, _termid))
|
||||
else
|
||||
self:E(string.format("%s: Parking spot id %d free.", airport, _termid))
|
||||
self:I(string.format("%s: Parking spot id %d free.", airport, _termid))
|
||||
if nvalid<_nspots then
|
||||
table.insert(validspots, {Coordinate=_spot, TerminalID=_termid})
|
||||
end
|
||||
nvalid=nvalid+1
|
||||
self:I(string.format("%s: Parking spot id %d free. Nfree=%d/%d.", airport, _termid, nvalid,_nspots))
|
||||
end
|
||||
|
||||
end -- loop over units
|
||||
@@ -878,6 +953,14 @@ function AIRBASE:CheckOnRunWay(group, radius, despawn)
|
||||
return false
|
||||
end
|
||||
|
||||
--- Get category of airbase.
|
||||
-- @param #AIRBASE self
|
||||
-- @return #number Category of airbase from GetDesc().category.
|
||||
function AIRBASE:GetAirbaseCategory()
|
||||
return self:GetDesc().category
|
||||
end
|
||||
|
||||
|
||||
--- Helper function to check for the correct terminal type including "artificial" ones.
|
||||
-- @param #number Term_Type Termial type from getParking routine.
|
||||
-- @param #AIRBASE.TerminalType termtype Terminal type from AIRBASE.TerminalType enumerator.
|
||||
@@ -922,4 +1005,186 @@ function AIRBASE._CheckTerminalType(Term_Type, termtype)
|
||||
end
|
||||
|
||||
return match
|
||||
end
|
||||
end
|
||||
|
||||
--- Get runways data. Only for airdromes!
|
||||
-- @param #AIRBASE self
|
||||
-- @param #number magvar (Optional) Magnetic variation in degrees.
|
||||
-- @param #boolean mark (Optional) Place markers with runway data on F10 map.
|
||||
-- @return #table Runway data.
|
||||
function AIRBASE:GetRunwayData(magvar, mark)
|
||||
|
||||
-- Runway table.
|
||||
local runways={}
|
||||
|
||||
if self:GetAirbaseCategory()~=Airbase.Category.AIRDROME then
|
||||
return {}
|
||||
end
|
||||
|
||||
-- Get spawn points on runway.
|
||||
local runwaycoords=self:GetParkingSpotsCoordinates(AIRBASE.TerminalType.Runway)
|
||||
|
||||
-- Magnetic declination.
|
||||
magvar=magvar or UTILS.GetMagneticDeclination()
|
||||
|
||||
local N=#runwaycoords
|
||||
local dN=2
|
||||
local ex=false
|
||||
|
||||
local name=self:GetName()
|
||||
if name==AIRBASE.Nevada.Jean_Airport or
|
||||
name==AIRBASE.Nevada.Creech_AFB or
|
||||
name==AIRBASE.PersianGulf.Abu_Dhabi_International_Airport or
|
||||
name==AIRBASE.PersianGulf.Dubai_Intl or
|
||||
name==AIRBASE.PersianGulf.Shiraz_International_Airport or
|
||||
name==AIRBASE.PersianGulf.Kish_International_Airport then
|
||||
|
||||
N=#runwaycoords/2
|
||||
dN=1
|
||||
ex=true
|
||||
end
|
||||
|
||||
|
||||
for i=1,N,dN do
|
||||
|
||||
local j=i+1
|
||||
if ex then
|
||||
--j=N+i
|
||||
j=#runwaycoords-i+1
|
||||
end
|
||||
|
||||
-- Coordinates of the two runway points.
|
||||
local c1=runwaycoords[i] --Core.Point#COORDINATES
|
||||
local c2=runwaycoords[j] --Core.Point#COORDINATES
|
||||
|
||||
-- Heading of runway.
|
||||
local hdg=c1:HeadingTo(c2)
|
||||
|
||||
-- Runway ID: heading=070° ==> idx="07"
|
||||
local idx=string.format("%02d", UTILS.Round((hdg-magvar)/10, 0))
|
||||
|
||||
-- Runway table.
|
||||
local runway={} --#AIRBASE.Runway
|
||||
runway.heading=hdg
|
||||
runway.idx=idx
|
||||
runway.length=c1:Get2DDistance(c2)
|
||||
runway.position=c1
|
||||
runway.endpoint=c2
|
||||
|
||||
-- Debug info.
|
||||
self:T(string.format("Airbase %s: Adding runway id=%s, heading=%03d, length=%d m", self:GetName(), runway.idx, runway.heading, runway.length))
|
||||
|
||||
-- Debug mark
|
||||
if mark then
|
||||
runway.position:MarkToAll(string.format("Runway %s: true heading=%03d (magvar=%d), length=%d m", runway.idx, runway.heading, magvar, runway.length))
|
||||
end
|
||||
|
||||
-- Add runway.
|
||||
table.insert(runways, runway)
|
||||
|
||||
end
|
||||
|
||||
-- Get inverse runways
|
||||
local inverse={}
|
||||
for _,_runway in pairs(runways) do
|
||||
local r=_runway --#AIRBASE.Runway
|
||||
|
||||
local runway={} --#AIRBASE.Runway
|
||||
runway.heading=r.heading-180
|
||||
if runway.heading<0 then
|
||||
runway.heading=runway.heading+360
|
||||
end
|
||||
runway.idx=string.format("%02d", math.max(0, UTILS.Round((runway.heading-magvar)/10, 0)))
|
||||
runway.length=r.length
|
||||
runway.position=r.endpoint
|
||||
runway.endpoint=r.position
|
||||
|
||||
-- Debug info.
|
||||
self:T(string.format("Airbase %s: Adding runway id=%s, heading=%03d, length=%d m", self:GetName(), runway.idx, runway.heading, runway.length))
|
||||
|
||||
-- Debug mark
|
||||
if mark then
|
||||
runway.position:MarkToAll(string.format("Runway %s: true heading=%03d (magvar=%d), length=%d m", runway.idx, runway.heading, magvar, runway.length))
|
||||
end
|
||||
|
||||
-- Add runway.
|
||||
table.insert(inverse, runway)
|
||||
end
|
||||
|
||||
-- Add inverse runway.
|
||||
for _,runway in pairs(inverse) do
|
||||
table.insert(runways, runway)
|
||||
end
|
||||
|
||||
return runways
|
||||
end
|
||||
|
||||
--- Set the active runway in case it cannot be determined by the wind direction.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #number iactive Number of the active runway in the runway data table.
|
||||
function AIRBASE:SetActiveRunway(iactive)
|
||||
self.activerwyno=iactive
|
||||
end
|
||||
|
||||
--- Get the active runway based on current wind direction.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #number magvar (Optional) Magnetic variation in degrees.
|
||||
-- @return #AIRBASE.Runway Active runway data table.
|
||||
function AIRBASE:GetActiveRunway(magvar)
|
||||
|
||||
-- Get runways data (initialize if necessary).
|
||||
local runways=self:GetRunwayData(magvar)
|
||||
|
||||
-- Return user forced active runway if it was set.
|
||||
if self.activerwyno then
|
||||
return runways[self.activerwyno]
|
||||
end
|
||||
|
||||
-- Get wind vector.
|
||||
local Vwind=self:GetCoordinate():GetWindWithTurbulenceVec3()
|
||||
local norm=UTILS.VecNorm(Vwind)
|
||||
|
||||
-- Active runway number.
|
||||
local iact=1
|
||||
|
||||
-- Check if wind is blowing (norm>0).
|
||||
if norm>0 then
|
||||
|
||||
-- Normalize wind (not necessary).
|
||||
Vwind.x=Vwind.x/norm
|
||||
Vwind.y=0
|
||||
Vwind.z=Vwind.z/norm
|
||||
|
||||
-- Loop over runways.
|
||||
local dotmin=nil
|
||||
for i,_runway in pairs(runways) do
|
||||
local runway=_runway --#AIRBASE.Runway
|
||||
|
||||
-- Angle in rad.
|
||||
local alpha=math.rad(runway.heading)
|
||||
|
||||
-- Runway vector.
|
||||
local Vrunway={x=math.cos(alpha), y=0, z=math.sin(alpha)}
|
||||
|
||||
-- Dot product: parallel component of the two vectors.
|
||||
local dot=UTILS.VecDot(Vwind, Vrunway)
|
||||
|
||||
-- Debug.
|
||||
--env.info(string.format("runway=%03d° dot=%.3f", runway.heading, dot))
|
||||
|
||||
-- New min?
|
||||
if dotmin==nil or dot<dotmin then
|
||||
dotmin=dot
|
||||
iact=i
|
||||
end
|
||||
|
||||
end
|
||||
else
|
||||
self:E("WARNING: Norm of wind is zero! Cannot determine active runway based on wind direction.")
|
||||
end
|
||||
|
||||
return runways[iact]
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -133,7 +133,8 @@ function CLIENT:FindByName( ClientName, ClientBriefing, Error )
|
||||
end
|
||||
|
||||
function CLIENT:Register( ClientName )
|
||||
local self = BASE:Inherit( self, UNIT:Register( ClientName ) )
|
||||
|
||||
local self = BASE:Inherit( self, UNIT:Register( ClientName ) ) -- #CLIENT
|
||||
|
||||
self:F( ClientName )
|
||||
self.ClientName = ClientName
|
||||
@@ -141,7 +142,8 @@ function CLIENT:Register( ClientName )
|
||||
self.ClientAlive2 = false
|
||||
|
||||
--self.AliveCheckScheduler = routines.scheduleFunction( self._AliveCheckScheduler, { self }, timer.getTime() + 1, 5 )
|
||||
self.AliveCheckScheduler = SCHEDULER:New( self, self._AliveCheckScheduler, { "Client Alive " .. ClientName }, 1, 5 )
|
||||
self.AliveCheckScheduler = SCHEDULER:New( self, self._AliveCheckScheduler, { "Client Alive " .. ClientName }, 1, 5, 0.5 )
|
||||
self.AliveCheckScheduler:NoTrace()
|
||||
|
||||
self:F( self )
|
||||
return self
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -325,7 +325,8 @@ end
|
||||
-- So all event listeners will catch the destroy event of this group for each unit in the group.
|
||||
-- To raise these events, provide the `GenerateEvent` parameter.
|
||||
-- @param #GROUP self
|
||||
-- @param #boolean GenerateEvent true if you want to generate a crash or dead event for each unit.
|
||||
-- @param #boolean GenerateEvent If true, a crash or dead event for each unit is generated. If false, if no event is triggered. If nil, a RemoveUnit event is triggered.
|
||||
-- @param #number delay Delay in seconds before despawning the group.
|
||||
-- @usage
|
||||
-- -- Air unit example: destroy the Helicopter and generate a S_EVENT_CRASH for each unit in the Helicopter group.
|
||||
-- Helicopter = GROUP:FindByName( "Helicopter" )
|
||||
@@ -344,30 +345,36 @@ end
|
||||
-- Ship = GROUP:FindByName( "Boat" )
|
||||
-- Ship:Destroy( false ) -- Don't generate an event upon destruction.
|
||||
--
|
||||
function GROUP:Destroy( GenerateEvent )
|
||||
function GROUP:Destroy( GenerateEvent, delay )
|
||||
self:F2( self.GroupName )
|
||||
|
||||
if delay and delay>0 then
|
||||
--SCHEDULER:New(nil, GROUP.Destroy, {self, GenerateEvent}, delay)
|
||||
self:ScheduleOnce(delay, GROUP.Destroy, self, GenerateEvent)
|
||||
else
|
||||
|
||||
local DCSGroup = self:GetDCSObject()
|
||||
|
||||
if DCSGroup then
|
||||
for Index, UnitData in pairs( DCSGroup:getUnits() ) do
|
||||
if GenerateEvent and GenerateEvent == true then
|
||||
if self:IsAir() then
|
||||
self:CreateEventCrash( timer.getTime(), UnitData )
|
||||
local DCSGroup = self:GetDCSObject()
|
||||
|
||||
if DCSGroup then
|
||||
for Index, UnitData in pairs( DCSGroup:getUnits() ) do
|
||||
if GenerateEvent and GenerateEvent == true then
|
||||
if self:IsAir() then
|
||||
self:CreateEventCrash( timer.getTime(), UnitData )
|
||||
else
|
||||
self:CreateEventDead( timer.getTime(), UnitData )
|
||||
end
|
||||
elseif GenerateEvent == false then
|
||||
-- Do nothing!
|
||||
else
|
||||
self:CreateEventDead( timer.getTime(), UnitData )
|
||||
self:CreateEventRemoveUnit( timer.getTime(), UnitData )
|
||||
end
|
||||
elseif GenerateEvent == false then
|
||||
-- Do nothing!
|
||||
else
|
||||
self:CreateEventRemoveUnit( timer.getTime(), UnitData )
|
||||
end
|
||||
USERFLAG:New( self:GetName() ):Set( 100 )
|
||||
DCSGroup:destroy()
|
||||
DCSGroup = nil
|
||||
end
|
||||
USERFLAG:New( self:GetName() ):Set( 100 )
|
||||
DCSGroup:destroy()
|
||||
DCSGroup = nil
|
||||
end
|
||||
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -647,6 +654,49 @@ function GROUP:GetSize()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Count number of alive units in the group.
|
||||
-- @param #GROUP self
|
||||
-- @return #number Number of alive units. If DCS group is nil, 0 is returned.
|
||||
function GROUP:CountAliveUnits()
|
||||
self:F3( { self.GroupName } )
|
||||
local DCSGroup = self:GetDCSObject()
|
||||
|
||||
if DCSGroup then
|
||||
local units=self:GetUnits()
|
||||
local n=0
|
||||
for _,_unit in pairs(units) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
if unit and unit:IsAlive() then
|
||||
n=n+1
|
||||
end
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
--- Get the first unit of the group which is alive.
|
||||
-- @param #GROUP self
|
||||
-- @return Wrapper.Unit#UNIT First unit alive.
|
||||
function GROUP:GetFirstUnitAlive()
|
||||
self:F3({self.GroupName})
|
||||
local DCSGroup = self:GetDCSObject()
|
||||
|
||||
if DCSGroup then
|
||||
local units=self:GetUnits()
|
||||
for _,_unit in pairs(units) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
if unit and unit:IsAlive() then
|
||||
return unit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Returns the average velocity Vec3 vector.
|
||||
-- @param Wrapper.Group#GROUP self
|
||||
@@ -934,7 +984,7 @@ end
|
||||
-- @return #number The fuel state of the unit with the least amount of fuel
|
||||
-- @return #Unit reference to #Unit object for further processing
|
||||
function GROUP:GetFuelMin()
|
||||
self:F(self.ControllableName)
|
||||
self:F3(self.ControllableName)
|
||||
|
||||
if not self:GetDCSObject() then
|
||||
BASE:E( { "Cannot GetFuel", Group = self, Alive = self:IsAlive() } )
|
||||
@@ -946,10 +996,12 @@ function GROUP:GetFuelMin()
|
||||
local tmp = nil
|
||||
|
||||
for UnitID, UnitData in pairs( self:GetUnits() ) do
|
||||
tmp = UnitData:GetFuel()
|
||||
if tmp < min then
|
||||
min = tmp
|
||||
unit = UnitData
|
||||
if UnitData and UnitData:IsAlive() then
|
||||
tmp = UnitData:GetFuel()
|
||||
if tmp < min then
|
||||
min = tmp
|
||||
unit = UnitData
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1455,6 +1507,67 @@ function GROUP:InitRandomizePositionRadius( OuterRadius, InnerRadius )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set respawn coordinate.
|
||||
-- @param #GROUP self
|
||||
-- @param Core.Point#COORDINATE coordinate Coordinate where the group should be respawned.
|
||||
-- @return #GROUP self
|
||||
function GROUP:InitCoordinate(coordinate)
|
||||
self:F({coordinate=coordinate})
|
||||
self.InitCoord=coordinate
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets the radio comms on or off when the group is respawned. Same as checking/unchecking the COMM box in the mission editor.
|
||||
-- @param #GROUP self
|
||||
-- @param #boolean switch If true (or nil), enables the radio comms. If false, disables the radio for the spawned group.
|
||||
-- @return #GROUP self
|
||||
function GROUP:InitRadioCommsOnOff(switch)
|
||||
self:F({switch=switch})
|
||||
if switch==true or switch==nil then
|
||||
self.InitRespawnRadio=true
|
||||
else
|
||||
self.InitRespawnRadio=false
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets the radio frequency of the group when it is respawned.
|
||||
-- @param #GROUP self
|
||||
-- @param #number frequency The frequency in MHz.
|
||||
-- @return #GROUP self
|
||||
function GROUP:InitRadioFrequency(frequency)
|
||||
self:F({frequency=frequency})
|
||||
|
||||
self.InitRespawnFreq=frequency
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set radio modulation when the group is respawned. Default is AM.
|
||||
-- @param #GROUP self
|
||||
-- @param #string modulation Either "FM" or "AM". If no value is given, modulation is set to AM.
|
||||
-- @return #GROUP self
|
||||
function GROUP:InitRadioModulation(modulation)
|
||||
self:F({modulation=modulation})
|
||||
if modulation and modulation:lower()=="fm" then
|
||||
self.InitRespawnModu=radio.modulation.FM
|
||||
else
|
||||
self.InitRespawnModu=radio.modulation.AM
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets the modex (tail number) of the first unit of the group. If more units are in the group, the number is increased with every unit.
|
||||
-- @param #GROUP self
|
||||
-- @param #string modex Tail number of the first unit.
|
||||
-- @return #GROUP self
|
||||
function GROUP:InitModex(modex)
|
||||
self:F({modex=modex})
|
||||
if modex then
|
||||
self.InitRespawnModex=tonumber(modex)
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- Respawn the @{Wrapper.Group} at a @{Point}.
|
||||
-- The method will setup the new group template according the Init(Respawn) settings provided for the group.
|
||||
@@ -1477,29 +1590,61 @@ end
|
||||
--
|
||||
-- @param Wrapper.Group#GROUP self
|
||||
-- @param #table Template (optional) The template of the Group retrieved with GROUP:GetTemplate(). If the template is not provided, the template will be retrieved of the group itself.
|
||||
-- @param #boolean Reset Reset positions if TRUE.
|
||||
-- @return Wrapper.Group#GROUP self
|
||||
function GROUP:Respawn( Template, Reset )
|
||||
|
||||
if not Template then
|
||||
Template = self:GetTemplate()
|
||||
end
|
||||
-- Given template or get old.
|
||||
Template = Template or self:GetTemplate()
|
||||
|
||||
-- Get correct heading.
|
||||
local function _Heading(course)
|
||||
local h
|
||||
if course<=180 then
|
||||
h=math.rad(course)
|
||||
else
|
||||
h=-math.rad(360-course)
|
||||
end
|
||||
return h
|
||||
end
|
||||
|
||||
-- First check if group is alive.
|
||||
if self:IsAlive() then
|
||||
|
||||
-- Respawn zone.
|
||||
local Zone = self.InitRespawnZone -- Core.Zone#ZONE
|
||||
|
||||
-- Zone position or current group position.
|
||||
local Vec3 = Zone and Zone:GetVec3() or self:GetVec3()
|
||||
|
||||
-- From point of the template.
|
||||
local From = { x = Template.x, y = Template.y }
|
||||
|
||||
-- X, Y
|
||||
Template.x = Vec3.x
|
||||
Template.y = Vec3.z
|
||||
|
||||
--Template.x = nil
|
||||
--Template.y = nil
|
||||
|
||||
-- Debug number of units.
|
||||
self:F( #Template.units )
|
||||
|
||||
-- Reset position etc?
|
||||
if Reset == true then
|
||||
|
||||
-- Loop over units in group.
|
||||
for UnitID, UnitData in pairs( self:GetUnits() ) do
|
||||
local GroupUnit = UnitData -- Wrapper.Unit#UNIT
|
||||
self:F( GroupUnit:GetName() )
|
||||
self:F(GroupUnit:GetName())
|
||||
|
||||
if GroupUnit:IsAlive() then
|
||||
self:F( "Alive" )
|
||||
local GroupUnitVec3 = GroupUnit:GetVec3()
|
||||
self:F("Alive")
|
||||
|
||||
-- Get unit position vector.
|
||||
local GroupUnitVec3 = GroupUnit:GetVec3()
|
||||
|
||||
-- Check if respawn zone is set.
|
||||
if Zone then
|
||||
if self.InitRespawnRandomizePositionZone then
|
||||
GroupUnitVec3 = Zone:GetRandomVec3()
|
||||
@@ -1512,17 +1657,43 @@ function GROUP:Respawn( Template, Reset )
|
||||
end
|
||||
end
|
||||
|
||||
-- Coordinate where the group should be respawned.
|
||||
if self.InitCoord then
|
||||
GroupUnitVec3=self.InitCoord:GetVec3()
|
||||
end
|
||||
|
||||
-- Altitude
|
||||
Template.units[UnitID].alt = self.InitRespawnHeight and self.InitRespawnHeight or GroupUnitVec3.y
|
||||
Template.units[UnitID].x = ( Template.units[UnitID].x - From.x ) + GroupUnitVec3.x -- Keep the original x position of the template and translate to the new position.
|
||||
Template.units[UnitID].y = ( Template.units[UnitID].y - From.y ) + GroupUnitVec3.z -- Keep the original z position of the template and translate to the new position.
|
||||
Template.units[UnitID].heading = self.InitRespawnHeading and self.InitRespawnHeading or GroupUnit:GetHeading()
|
||||
|
||||
-- Unit position. Why not simply take the current positon?
|
||||
if Zone then
|
||||
Template.units[UnitID].x = ( Template.units[UnitID].x - From.x ) + GroupUnitVec3.x -- Keep the original x position of the template and translate to the new position.
|
||||
Template.units[UnitID].y = ( Template.units[UnitID].y - From.y ) + GroupUnitVec3.z -- Keep the original z position of the template and translate to the new position.
|
||||
else
|
||||
Template.units[UnitID].x=GroupUnitVec3.x
|
||||
Template.units[UnitID].y=GroupUnitVec3.z
|
||||
end
|
||||
|
||||
-- Set heading.
|
||||
Template.units[UnitID].heading = _Heading(self.InitRespawnHeading and self.InitRespawnHeading or GroupUnit:GetHeading())
|
||||
Template.units[UnitID].psi = -Template.units[UnitID].heading
|
||||
|
||||
-- Debug.
|
||||
self:F( { UnitID, Template.units[UnitID], Template.units[UnitID] } )
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
else -- Reset=false or nil
|
||||
|
||||
-- Loop over template units.
|
||||
for UnitID, TemplateUnitData in pairs( Template.units ) do
|
||||
|
||||
self:F( "Reset" )
|
||||
|
||||
-- Position from template.
|
||||
local GroupUnitVec3 = { x = TemplateUnitData.x, y = TemplateUnitData.alt, z = TemplateUnitData.y }
|
||||
|
||||
-- Respawn zone position.
|
||||
if Zone then
|
||||
if self.InitRespawnRandomizePositionZone then
|
||||
GroupUnitVec3 = Zone:GetRandomVec3()
|
||||
@@ -1535,23 +1706,59 @@ function GROUP:Respawn( Template, Reset )
|
||||
end
|
||||
end
|
||||
|
||||
-- Coordinate where the group should be respawned.
|
||||
if self.InitCoord then
|
||||
GroupUnitVec3=self.InitCoord:GetVec3()
|
||||
end
|
||||
|
||||
-- Set altitude.
|
||||
Template.units[UnitID].alt = self.InitRespawnHeight and self.InitRespawnHeight or GroupUnitVec3.y
|
||||
|
||||
-- Unit position.
|
||||
Template.units[UnitID].x = ( Template.units[UnitID].x - From.x ) + GroupUnitVec3.x -- Keep the original x position of the template and translate to the new position.
|
||||
Template.units[UnitID].y = ( Template.units[UnitID].y - From.y ) + GroupUnitVec3.z -- Keep the original z position of the template and translate to the new position.
|
||||
|
||||
-- Heading
|
||||
Template.units[UnitID].heading = self.InitRespawnHeading and self.InitRespawnHeading or TemplateUnitData.heading
|
||||
|
||||
-- Debug.
|
||||
self:F( { UnitID, Template.units[UnitID], Template.units[UnitID] } )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
self:Destroy()
|
||||
_DATABASE:Spawn( Template )
|
||||
-- Set tail number.
|
||||
if self.InitRespawnModex then
|
||||
for UnitID=1,#Template.units do
|
||||
Template.units[UnitID].onboard_num=string.format("%03d", self.InitRespawnModex+(UnitID-1))
|
||||
end
|
||||
end
|
||||
|
||||
-- Set radio frequency and modulation.
|
||||
if self.InitRespawnRadio then
|
||||
Template.communication=self.InitRespawnRadio
|
||||
end
|
||||
if self.InitRespawnFreq then
|
||||
Template.frequency=self.InitRespawnFreq
|
||||
end
|
||||
if self.InitRespawnModu then
|
||||
Template.modulation=self.InitRespawnModu
|
||||
end
|
||||
|
||||
-- Destroy old group. Dont trigger any dead/crash events since this is a respawn.
|
||||
self:Destroy(false)
|
||||
|
||||
self:T({Template=Template})
|
||||
|
||||
-- Spawn new group.
|
||||
_DATABASE:Spawn(Template)
|
||||
|
||||
-- Reset events.
|
||||
self:ResetEvents()
|
||||
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -1566,98 +1773,115 @@ end
|
||||
function GROUP:RespawnAtCurrentAirbase(SpawnTemplate, Takeoff, Uncontrolled) -- R2.4
|
||||
self:F2( { SpawnTemplate, Takeoff, Uncontrolled} )
|
||||
|
||||
-- Get closest airbase. Should be the one we are currently on.
|
||||
local airbase=self:GetCoordinate():GetClosestAirbase()
|
||||
|
||||
if airbase then
|
||||
self:F2("Closest airbase = "..airbase:GetName())
|
||||
else
|
||||
self:E("ERROR: could not find closest airbase!")
|
||||
return nil
|
||||
end
|
||||
-- Takeoff type. Default hot.
|
||||
Takeoff = Takeoff or SPAWN.Takeoff.Hot
|
||||
|
||||
-- Coordinate of the airbase.
|
||||
local AirbaseCoord=airbase:GetCoordinate()
|
||||
|
||||
-- Spawn template.
|
||||
SpawnTemplate = SpawnTemplate or self:GetTemplate()
|
||||
if self and self:IsAlive() then
|
||||
|
||||
if SpawnTemplate then
|
||||
|
||||
local SpawnPoint = SpawnTemplate.route.points[1]
|
||||
|
||||
-- These are only for ships.
|
||||
SpawnPoint.linkUnit = nil
|
||||
SpawnPoint.helipadId = nil
|
||||
SpawnPoint.airdromeId = nil
|
||||
|
||||
-- Aibase id and category.
|
||||
local AirbaseID = airbase:GetID()
|
||||
local AirbaseCategory = airbase:GetDesc().category
|
||||
-- Get closest airbase. Should be the one we are currently on.
|
||||
local airbase=self:GetCoordinate():GetClosestAirbase()
|
||||
|
||||
if AirbaseCategory == Airbase.Category.SHIP or AirbaseCategory == Airbase.Category.HELIPAD then
|
||||
SpawnPoint.linkUnit = AirbaseID
|
||||
SpawnPoint.helipadId = AirbaseID
|
||||
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
||||
SpawnPoint.airdromeId = AirbaseID
|
||||
if airbase then
|
||||
self:F2("Closest airbase = "..airbase:GetName())
|
||||
else
|
||||
self:E("ERROR: could not find closest airbase!")
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Takeoff type. Default hot.
|
||||
Takeoff = Takeoff or SPAWN.Takeoff.Hot
|
||||
|
||||
SpawnPoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
||||
SpawnPoint.action = GROUPTEMPLATE.Takeoff[Takeoff][2] -- action
|
||||
-- Coordinate of the airbase.
|
||||
local AirbaseCoord=airbase:GetCoordinate()
|
||||
|
||||
-- Get the units of the group.
|
||||
local units=self:GetUnits()
|
||||
|
||||
local x
|
||||
local y
|
||||
for UnitID=1,#units do
|
||||
-- Spawn template.
|
||||
SpawnTemplate = SpawnTemplate or self:GetTemplate()
|
||||
|
||||
if SpawnTemplate then
|
||||
|
||||
local SpawnPoint = SpawnTemplate.route.points[1]
|
||||
|
||||
-- These are only for ships.
|
||||
SpawnPoint.linkUnit = nil
|
||||
SpawnPoint.helipadId = nil
|
||||
SpawnPoint.airdromeId = nil
|
||||
|
||||
-- Aibase id and category.
|
||||
local AirbaseID = airbase:GetID()
|
||||
local AirbaseCategory = airbase:GetDesc().category
|
||||
|
||||
if AirbaseCategory == Airbase.Category.SHIP or AirbaseCategory == Airbase.Category.HELIPAD then
|
||||
SpawnPoint.linkUnit = AirbaseID
|
||||
SpawnPoint.helipadId = AirbaseID
|
||||
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
||||
SpawnPoint.airdromeId = AirbaseID
|
||||
end
|
||||
|
||||
|
||||
SpawnPoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
||||
SpawnPoint.action = GROUPTEMPLATE.Takeoff[Takeoff][2] -- action
|
||||
|
||||
-- Get the units of the group.
|
||||
local units=self:GetUnits()
|
||||
|
||||
local x
|
||||
local y
|
||||
for UnitID=1,#units do
|
||||
|
||||
local unit=units[UnitID] --Wrapper.Unit#UNIT
|
||||
|
||||
-- Get closest parking spot of current unit. Note that we look for occupied spots since the unit is currently sitting on it!
|
||||
local Parkingspot, TermialID, Distance=unit:GetCoordinate():GetClosestParkingSpot(airbase)
|
||||
|
||||
local unit=units[UnitID] --Wrapper.Unit#UNIT
|
||||
|
||||
-- Get closest parking spot of current unit. Note that we look for occupied spots since the unit is currently sitting on it!
|
||||
local Parkingspot, TermialID, Distance=unit:GetCoordinate():GetClosestParkingSpot(airbase)
|
||||
|
||||
--Parkingspot:MarkToAll("parking spot")
|
||||
self:T2(string.format("Closest parking spot distance = %s, terminal ID=%s", tostring(Distance), tostring(TermialID)))
|
||||
|
||||
-- Get unit coordinates for respawning position.
|
||||
local uc=unit:GetCoordinate()
|
||||
--uc:MarkToAll(string.format("re-spawnplace %s terminal %d", unit:GetName(), TermialID))
|
||||
|
||||
SpawnTemplate.units[UnitID].x = uc.x --Parkingspot.x
|
||||
SpawnTemplate.units[UnitID].y = uc.z --Parkingspot.z
|
||||
SpawnTemplate.units[UnitID].alt = uc.y --Parkingspot.y
|
||||
|
||||
SpawnTemplate.units[UnitID].parking = TermialID
|
||||
SpawnTemplate.units[UnitID].parking_id = nil
|
||||
|
||||
--SpawnTemplate.units[UnitID].unitId=nil
|
||||
end
|
||||
|
||||
--SpawnTemplate.groupId=nil
|
||||
|
||||
SpawnPoint.x = SpawnTemplate.units[1].x --x --AirbaseCoord.x
|
||||
SpawnPoint.y = SpawnTemplate.units[1].y --y --AirbaseCoord.z
|
||||
SpawnPoint.alt = SpawnTemplate.units[1].alt --AirbaseCoord:GetLandHeight()
|
||||
|
||||
SpawnTemplate.x = SpawnTemplate.units[1].x --x --AirbaseCoord.x
|
||||
SpawnTemplate.y = SpawnTemplate.units[1].y --y --AirbaseCoord.z
|
||||
|
||||
-- Set uncontrolled state.
|
||||
SpawnTemplate.uncontrolled=Uncontrolled
|
||||
|
||||
-- Destroy old group.
|
||||
self:Destroy(false)
|
||||
|
||||
_DATABASE:Spawn( SpawnTemplate )
|
||||
--Parkingspot:MarkToAll("parking spot")
|
||||
self:T2(string.format("Closest parking spot distance = %s, terminal ID=%s", tostring(Distance), tostring(TermialID)))
|
||||
|
||||
-- Reset events.
|
||||
self:ResetEvents()
|
||||
|
||||
return self
|
||||
-- Get unit coordinates for respawning position.
|
||||
local uc=unit:GetCoordinate()
|
||||
--uc:MarkToAll(string.format("re-spawnplace %s terminal %d", unit:GetName(), TermialID))
|
||||
|
||||
SpawnTemplate.units[UnitID].x = uc.x --Parkingspot.x
|
||||
SpawnTemplate.units[UnitID].y = uc.z --Parkingspot.z
|
||||
SpawnTemplate.units[UnitID].alt = uc.y --Parkingspot.y
|
||||
|
||||
SpawnTemplate.units[UnitID].parking = TermialID
|
||||
SpawnTemplate.units[UnitID].parking_id = nil
|
||||
|
||||
--SpawnTemplate.units[UnitID].unitId=nil
|
||||
end
|
||||
|
||||
--SpawnTemplate.groupId=nil
|
||||
|
||||
SpawnPoint.x = SpawnTemplate.units[1].x --x --AirbaseCoord.x
|
||||
SpawnPoint.y = SpawnTemplate.units[1].y --y --AirbaseCoord.z
|
||||
SpawnPoint.alt = SpawnTemplate.units[1].alt --AirbaseCoord:GetLandHeight()
|
||||
|
||||
SpawnTemplate.x = SpawnTemplate.units[1].x --x --AirbaseCoord.x
|
||||
SpawnTemplate.y = SpawnTemplate.units[1].y --y --AirbaseCoord.z
|
||||
|
||||
-- Set uncontrolled state.
|
||||
SpawnTemplate.uncontrolled=Uncontrolled
|
||||
|
||||
-- Set radio frequency and modulation.
|
||||
if self.InitRespawnRadio then
|
||||
SpawnTemplate.communication=self.InitRespawnRadio
|
||||
end
|
||||
if self.InitRespawnFreq then
|
||||
SpawnTemplate.frequency=self.InitRespawnFreq
|
||||
end
|
||||
if self.InitRespawnModu then
|
||||
SpawnTemplate.modulation=self.InitRespawnModu
|
||||
end
|
||||
|
||||
-- Destroy old group.
|
||||
self:Destroy(false)
|
||||
|
||||
-- Spawn new group.
|
||||
_DATABASE:Spawn(SpawnTemplate)
|
||||
|
||||
-- Reset events.
|
||||
self:ResetEvents()
|
||||
|
||||
return self
|
||||
end
|
||||
else
|
||||
self:E("WARNING: GROUP is not alive!")
|
||||
end
|
||||
|
||||
return nil
|
||||
@@ -1770,6 +1994,47 @@ function GROUP:InAir()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Checks whether any unit (or optionally) all units of a group is(are) airbore or not.
|
||||
-- @param Wrapper.Group#GROUP self
|
||||
-- @param #boolean AllUnits (Optional) If true, check whether all units of the group are airborne.
|
||||
-- @return #boolean True if at least one (optionally all) unit(s) is(are) airborne or false otherwise. Nil if no unit exists or is alive.
|
||||
function GROUP:IsAirborne(AllUnits)
|
||||
self:F2( self.GroupName )
|
||||
|
||||
-- Get all units of the group.
|
||||
local units=self:GetUnits()
|
||||
|
||||
if units then
|
||||
|
||||
for _,_unit in pairs(units) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
|
||||
if unit then
|
||||
|
||||
-- Unit in air or not.
|
||||
local inair=unit:InAir()
|
||||
|
||||
-- Unit is not in air and we wanted to know whether ALL units are ==> return false
|
||||
if inair==false and AllUnits==true then
|
||||
return false
|
||||
end
|
||||
|
||||
-- At least one unit is in are and we did not care which one.
|
||||
if inair==true and not AllUnits then
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
-- At least one unit is in the air.
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Returns the DCS descriptor table of the nth unit of the group.
|
||||
-- @param #GROUP self
|
||||
-- @param #number n (Optional) The number of the unit for which the dscriptor is returned.
|
||||
@@ -1800,8 +2065,8 @@ do -- Route methods
|
||||
--
|
||||
-- @param #GROUP self
|
||||
-- @param Wrapper.Airbase#AIRBASE RTBAirbase (optional) The @{Wrapper.Airbase} to return to. If blank, the controllable will return to the nearest friendly airbase.
|
||||
-- @param #number Speed (optional) The Speed, if no Speed is given, the maximum Speed of the first unit is selected.
|
||||
-- @return #GROUP
|
||||
-- @param #number Speed (optional) The Speed, if no Speed is given, 80% of maximum Speed of the group is selected.
|
||||
-- @return #GROUP self
|
||||
function GROUP:RouteRTB( RTBAirbase, Speed )
|
||||
self:F( { RTBAirbase:GetName(), Speed } )
|
||||
|
||||
@@ -1811,42 +2076,42 @@ do -- Route methods
|
||||
|
||||
if RTBAirbase then
|
||||
|
||||
local GroupPoint = self:GetVec2()
|
||||
local GroupVelocity = self:GetUnit(1):GetDesc().speedMax
|
||||
|
||||
local PointFrom = {}
|
||||
PointFrom.x = GroupPoint.x
|
||||
PointFrom.y = GroupPoint.y
|
||||
PointFrom.type = "Turning Point"
|
||||
PointFrom.action = "Turning Point"
|
||||
PointFrom.speed = GroupVelocity
|
||||
|
||||
|
||||
local PointTo = {}
|
||||
local AirbasePointVec2 = RTBAirbase:GetPointVec2()
|
||||
local AirbaseAirPoint = AirbasePointVec2:WaypointAir(
|
||||
POINT_VEC3.RoutePointAltType.BARO,
|
||||
"Land",
|
||||
"Landing",
|
||||
Speed or self:GetUnit(1):GetDesc().speedMax
|
||||
)
|
||||
-- If speed is not given take 80% of max speed.
|
||||
local Speed=Speed or self:GetSpeedMax()*0.8
|
||||
|
||||
AirbaseAirPoint["airdromeId"] = RTBAirbase:GetID()
|
||||
AirbaseAirPoint["speed_locked"] = true,
|
||||
-- Curent (from) waypoint.
|
||||
local coord=self:GetCoordinate()
|
||||
local PointFrom=coord:WaypointAirTurningPoint(nil, Speed)
|
||||
|
||||
-- Airbase coordinate.
|
||||
--local PointAirbase=RTBAirbase:GetCoordinate():SetAltitude(coord.y):WaypointAirTurningPoint(nil ,Speed)
|
||||
|
||||
-- Landing waypoint. More general than prev version since it should also work with FAPRS and ships.
|
||||
local PointLanding=RTBAirbase:GetCoordinate():WaypointAirLanding(Speed, RTBAirbase)
|
||||
|
||||
-- Waypoint table.
|
||||
local Points={PointFrom, PointLanding}
|
||||
--local Points={PointFrom, PointAirbase, PointLanding}
|
||||
|
||||
self:F(AirbaseAirPoint )
|
||||
|
||||
local Points = { PointFrom, AirbaseAirPoint }
|
||||
|
||||
self:T3( Points )
|
||||
-- Debug info.
|
||||
self:T3(Points)
|
||||
|
||||
local Template = self:GetTemplate()
|
||||
Template.route.points = Points
|
||||
self:Respawn( Template )
|
||||
|
||||
--self:Route( Points )
|
||||
-- Get group template.
|
||||
local Template=self:GetTemplate()
|
||||
|
||||
-- Set route points.
|
||||
Template.route.points=Points
|
||||
|
||||
-- Respawn the group.
|
||||
self:Respawn(Template, true)
|
||||
|
||||
-- Route the group or this will not work.
|
||||
self:Route(Points)
|
||||
else
|
||||
|
||||
-- Clear all tasks.
|
||||
self:ClearTasks()
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ### Contributions:
|
||||
-- ### Contributions: **Hardcard**, **funkyfranky**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
@@ -63,7 +63,7 @@ POSITIONABLE.__.Cargo = {}
|
||||
-- @param #string PositionableName The POSITIONABLE name
|
||||
-- @return #POSITIONABLE self
|
||||
function POSITIONABLE:New( PositionableName )
|
||||
local self = BASE:Inherit( self, IDENTIFIABLE:New( PositionableName ) )
|
||||
local self = BASE:Inherit( self, IDENTIFIABLE:New( PositionableName ) ) -- #POSITIONABLE
|
||||
|
||||
self.PositionableName = PositionableName
|
||||
return self
|
||||
@@ -310,6 +310,44 @@ function POSITIONABLE:GetCoordinate()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Returns a COORDINATE object, which is offset with respect to the orientation of the POSITIONABLE.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
-- @param #number x Offset in the direction "the nose" of the unit is pointing in meters. Default 0 m.
|
||||
-- @param #number y Offset "above" the unit in meters. Default 0 m.
|
||||
-- @param #number z Offset in the direction "the wing" of the unit is pointing in meters. z>0 starboard, z<0 port. Default 0 m.
|
||||
-- @return Core.Point#COORDINATE The COORDINATE of the offset with respect to the orientation of the POSITIONABLE.
|
||||
function POSITIONABLE:GetOffsetCoordinate(x,y,z)
|
||||
|
||||
-- Default if nil.
|
||||
x=x or 0
|
||||
y=y or 0
|
||||
z=z or 0
|
||||
|
||||
-- Vectors making up the coordinate system.
|
||||
local X=self:GetOrientationX()
|
||||
local Y=self:GetOrientationY()
|
||||
local Z=self:GetOrientationZ()
|
||||
|
||||
-- Offset vector: x meters ahead, z meters starboard, y meters above.
|
||||
local A={x=x, y=y, z=z}
|
||||
|
||||
-- Scale components of orthonormal coordinate vectors.
|
||||
local x={x=X.x*A.x, y=X.y*A.x, z=X.z*A.x}
|
||||
local y={x=Y.x*A.y, y=Y.y*A.y, z=Y.z*A.y}
|
||||
local z={x=Z.x*A.z, y=Z.y*A.z, z=Z.z*A.z}
|
||||
|
||||
-- Add up vectors in the unit coordinate system ==> this gives the offset vector relative the the origin of the map.
|
||||
local a={x=x.x+y.x+z.x, y=x.y+y.y+z.y, z=x.z+y.z+z.z}
|
||||
|
||||
-- Vector from the origin of the map to the unit.
|
||||
local u=self:GetVec3()
|
||||
|
||||
-- Translate offset vector from map origin to the unit: v=u+a.
|
||||
local v={x=a.x+u.x, y=a.y+u.y, z=a.z+u.z}
|
||||
|
||||
-- Return the offset coordinate.
|
||||
return COORDINATE:NewFromVec3(v)
|
||||
end
|
||||
|
||||
--- Returns a random @{DCS#Vec3} vector within a range, indicating the point in 3D of the POSITIONABLE within the mission.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
@@ -390,6 +428,27 @@ function POSITIONABLE:GetBoundingBox() --R2.1
|
||||
end
|
||||
|
||||
|
||||
--- Get the object size.
|
||||
-- @param #POSITIONABLE self
|
||||
-- @return DCS#Distance Max size of object in x, z or 0 if bounding box could not be obtained.
|
||||
-- @return DCS#Distance Length x or 0 if bounding box could not be obtained.
|
||||
-- @return DCS#Distance Height y or 0 if bounding box could not be obtained.
|
||||
-- @return DCS#Distance Width z or 0 if bounding box could not be obtained.
|
||||
function POSITIONABLE:GetObjectSize()
|
||||
|
||||
-- Get bounding box.
|
||||
local box=self:GetBoundingBox()
|
||||
|
||||
if box then
|
||||
local x=box.max.x+math.abs(box.min.x) --length
|
||||
local y=box.max.y+math.abs(box.min.y) --height
|
||||
local z=box.max.z+math.abs(box.min.z) --width
|
||||
return math.max(x,z), x , y, z
|
||||
end
|
||||
|
||||
return 0,0,0,0
|
||||
end
|
||||
|
||||
--- Get the bounding radius of the underlying POSITIONABLE DCS Object.
|
||||
-- @param #POSITIONABLE self
|
||||
-- @param #number mindist (Optional) If bounding box is smaller than this value, mindist is returned.
|
||||
@@ -596,6 +655,21 @@ function POSITIONABLE:GetVelocityVec3()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Get relative velocity with respect to another POSITIONABLE.
|
||||
-- @param #POSITIONABLE self
|
||||
-- @param #POSITIONABLE positionable Other positionable.
|
||||
-- @return #number Relative velocity in m/s.
|
||||
function POSITIONABLE:GetRelativeVelocity(positionable)
|
||||
self:F2( self.PositionableName )
|
||||
|
||||
local v1=self:GetVelocityVec3()
|
||||
local v2=positionable:GetVelocityVec3()
|
||||
|
||||
local vtot=UTILS.VecAdd(v1,v2)
|
||||
|
||||
return UTILS.VecNorm(vtot)
|
||||
end
|
||||
|
||||
|
||||
--- Returns the POSITIONABLE height in meters.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
@@ -656,6 +730,14 @@ function POSITIONABLE:GetVelocityMPS()
|
||||
return 0
|
||||
end
|
||||
|
||||
--- Returns the POSITIONABLE velocity in knots.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
-- @return #number The velocity in knots.
|
||||
function POSITIONABLE:GetVelocityKNOTS()
|
||||
self:F2( self.PositionableName )
|
||||
return UTILS.MpsToKnots(self:GetVelocityMPS())
|
||||
end
|
||||
|
||||
--- Returns the Angle of Attack of a positionable.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
-- @return #number Angle of attack in degrees.
|
||||
@@ -706,8 +788,8 @@ end
|
||||
|
||||
--- Returns the unit's climb or descent angle.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
-- @return #number Climb or descent angle in degrees.
|
||||
function POSITIONABLE:GetClimbAnge()
|
||||
-- @return #number Climb or descent angle in degrees. Or 0 if velocity vector norm is zero (or nil). Or nil, if the position of the POSITIONABLE returns nil.
|
||||
function POSITIONABLE:GetClimbAngle()
|
||||
|
||||
-- Get position of the unit.
|
||||
local unitpos = self:GetPosition()
|
||||
@@ -719,10 +801,17 @@ function POSITIONABLE:GetClimbAnge()
|
||||
|
||||
if unitvel and UTILS.VecNorm(unitvel)~=0 then
|
||||
|
||||
return math.asin(unitvel.y/UTILS.VecNorm(unitvel))
|
||||
|
||||
-- Calculate climb angle.
|
||||
local angle=math.asin(unitvel.y/UTILS.VecNorm(unitvel))
|
||||
|
||||
-- Return angle in degrees.
|
||||
return math.deg(angle)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Returns the pitch angle of a unit.
|
||||
@@ -1027,7 +1116,7 @@ function POSITIONABLE:MessageToSetGroup( Message, Duration, MessageSetGroup, Nam
|
||||
local DCSObject = self:GetDCSObject()
|
||||
if DCSObject then
|
||||
if DCSObject:isExist() then
|
||||
MessageSetGroup:ForEachGroup(
|
||||
MessageSetGroup:ForEachGroupAlive(
|
||||
function( MessageGroup )
|
||||
self:GetMessage( Message, Duration, Name ):ToGroup( MessageGroup )
|
||||
end
|
||||
@@ -1074,9 +1163,9 @@ end
|
||||
|
||||
--- Start Lasing a POSITIONABLE
|
||||
-- @param #POSITIONABLE self
|
||||
-- @param #POSITIONABLE Target
|
||||
-- @param #number LaserCode
|
||||
-- @param #number Duration
|
||||
-- @param #POSITIONABLE Target The target to lase.
|
||||
-- @param #number LaserCode Laser code or random number in [1000, 9999].
|
||||
-- @param #number Duration Duration of lasing in seconds.
|
||||
-- @return Core.Spot#SPOT
|
||||
function POSITIONABLE:LaseUnit( Target, LaserCode, Duration ) --R2.1
|
||||
self:F2()
|
||||
@@ -1095,6 +1184,24 @@ function POSITIONABLE:LaseUnit( Target, LaserCode, Duration ) --R2.1
|
||||
|
||||
end
|
||||
|
||||
--- Start Lasing a COORDINATE.
|
||||
-- @param #POSITIONABLE self
|
||||
-- @param Core.Point#COORDIUNATE Coordinate The coordinate where the lase is pointing at.
|
||||
-- @param #number LaserCode Laser code or random number in [1000, 9999].
|
||||
-- @param #number Duration Duration of lasing in seconds.
|
||||
-- @return Core.Spot#SPOT
|
||||
function POSITIONABLE:LaseCoordinate(Coordinate, LaserCode, Duration)
|
||||
self:F2()
|
||||
|
||||
LaserCode = LaserCode or math.random(1000, 9999)
|
||||
|
||||
self.Spot = SPOT:New(self) -- Core.Spot#SPOT
|
||||
self.Spot:LaseOnCoordinate(Coordinate, LaserCode, Duration)
|
||||
self.LaserCode = LaserCode
|
||||
|
||||
return self.Spot
|
||||
end
|
||||
|
||||
--- Stop Lasing a POSITIONABLE
|
||||
-- @param #POSITIONABLE self
|
||||
-- @return #POSITIONABLE
|
||||
@@ -1405,3 +1512,33 @@ function POSITIONABLE:SmokeBlue()
|
||||
end
|
||||
|
||||
|
||||
--- Returns true if the unit is within a @{Zone}.
|
||||
-- @param #STPOSITIONABLEATIC self
|
||||
-- @param Core.Zone#ZONE_BASE Zone The zone to test.
|
||||
-- @return #boolean Returns true if the unit is within the @{Core.Zone#ZONE_BASE}
|
||||
function POSITIONABLE:IsInZone( Zone )
|
||||
self:F2( { self.PositionableName, Zone } )
|
||||
|
||||
if self:IsAlive() then
|
||||
local IsInZone = Zone:IsVec3InZone( self:GetVec3() )
|
||||
|
||||
return IsInZone
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Returns true if the unit is not within a @{Zone}.
|
||||
-- @param #POSITIONABLE self
|
||||
-- @param Core.Zone#ZONE_BASE Zone The zone to test.
|
||||
-- @return #boolean Returns true if the unit is not within the @{Core.Zone#ZONE_BASE}
|
||||
function POSITIONABLE:IsNotInZone( Zone )
|
||||
self:F2( { self.PositionableName, Zone } )
|
||||
|
||||
if self:IsAlive() then
|
||||
local IsNotInZone = not Zone:IsVec3InZone( self:GetVec3() )
|
||||
|
||||
return IsNotInZone
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
@@ -136,13 +136,16 @@ function STATIC:Destroy( GenerateEvent )
|
||||
end
|
||||
|
||||
DCSObject:destroy()
|
||||
return true
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Get DCS object of static of static.
|
||||
-- @param #STATIC self
|
||||
-- @return DCS static object
|
||||
function STATIC:GetDCSObject()
|
||||
local DCSStatic = StaticObject.getByName( self.StaticName )
|
||||
|
||||
@@ -172,44 +175,72 @@ function STATIC:GetUnits()
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Get threat level of static.
|
||||
-- @param #STATIC self
|
||||
-- @return #number Threat level 1.
|
||||
-- @return #string "Static"
|
||||
function STATIC:GetThreatLevel()
|
||||
|
||||
return 1, "Static"
|
||||
end
|
||||
|
||||
--- Respawn the @{Wrapper.Unit} using a (tweaked) template of the parent Group.
|
||||
--- Spawn the @{Wrapper.Static} at a specific coordinate and heading.
|
||||
-- @param #STATIC self
|
||||
-- @param Core.Point#COORDINATE Coordinate The coordinate where to spawn the new Static.
|
||||
-- @param #number Heading The heading of the unit respawn.
|
||||
function STATIC:SpawnAt( Coordinate, Heading )
|
||||
-- @param #number Heading The heading of the static respawn in degrees. Default is 0 deg.
|
||||
-- @param #number Delay Delay in seconds before the static is spawned.
|
||||
function STATIC:SpawnAt( Coordinate, Heading, Delay )
|
||||
|
||||
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName )
|
||||
Heading=Heading or 0
|
||||
|
||||
if Delay and Delay>0 then
|
||||
SCHEDULER:New(nil, self.SpawnAt, {self, Coordinate, Heading}, Delay)
|
||||
else
|
||||
|
||||
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName )
|
||||
|
||||
SpawnStatic:SpawnFromPointVec2( Coordinate, Heading, self.StaticName )
|
||||
SpawnStatic:SpawnFromPointVec2( Coordinate, Heading, self.StaticName )
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Respawn the @{Wrapper.Unit} at the same location with the same properties.
|
||||
-- This is useful to respawn a cargo after it has been destroyed.
|
||||
-- @param #STATIC self
|
||||
-- @param DCS#country.id countryid The country ID used for spawning the new static.
|
||||
function STATIC:ReSpawn(countryid)
|
||||
-- @param DCS#country.id countryid The country ID used for spawning the new static. Default is same as currently.
|
||||
-- @param #number Delay Delay in seconds before static is respawned.
|
||||
function STATIC:ReSpawn(countryid, Delay)
|
||||
|
||||
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName, countryid )
|
||||
countryid=countryid or self:GetCountry()
|
||||
|
||||
if Delay and Delay>0 then
|
||||
SCHEDULER:New(nil, self.ReSpawn, {self, countryid}, Delay)
|
||||
else
|
||||
|
||||
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName, countryid )
|
||||
|
||||
SpawnStatic:ReSpawn()
|
||||
SpawnStatic:ReSpawn()
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Respawn the @{Wrapper.Unit} at a defined Coordinate with an optional heading.
|
||||
-- @param #STATIC self
|
||||
-- @param Core.Point#COORDINATE Coordinate The coordinate where to spawn the new Static.
|
||||
-- @param #number Heading The heading of the unit respawn.
|
||||
function STATIC:ReSpawnAt( Coordinate, Heading )
|
||||
-- @param #number Heading The heading of the static respawn in degrees. Default is 0 deg.
|
||||
-- @param #number Delay Delay in seconds before static is respawned.
|
||||
function STATIC:ReSpawnAt( Coordinate, Heading, Delay )
|
||||
|
||||
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName )
|
||||
Heading=Heading or 0
|
||||
|
||||
if Delay and Delay>0 then
|
||||
SCHEDULER:New(nil, self.ReSpawnAt, {self, Coordinate, Heading}, Delay)
|
||||
else
|
||||
|
||||
SpawnStatic:ReSpawnAt( Coordinate, Heading )
|
||||
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName )
|
||||
|
||||
SpawnStatic:ReSpawnAt( Coordinate, Heading )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -318,13 +318,37 @@ function UNIT:GetCallsign()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Check if an (air) unit is a client or player slot. Information is retrieved from the group template.
|
||||
-- @param #UNIT self
|
||||
-- @return #boolean If true, unit is associated with a client or player slot.
|
||||
function UNIT:IsPlayer()
|
||||
|
||||
-- Get group.
|
||||
local group=self:GetGroup()
|
||||
|
||||
-- Units of template group.
|
||||
local units=group:GetTemplate().units
|
||||
|
||||
-- Get numbers.
|
||||
for _,unit in pairs(units) do
|
||||
|
||||
-- Check if unit name matach and skill is Client or Player.
|
||||
if unit.name==self:GetName() and (unit.skill=="Client" or unit.skill=="Player") then
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
--- Returns name of the player that control the unit or nil if the unit is controlled by A.I.
|
||||
-- @param #UNIT self
|
||||
-- @return #string Player Name
|
||||
-- @return #nil The DCS Unit is not existing or alive.
|
||||
function UNIT:GetPlayerName()
|
||||
self:F2( self.UnitName )
|
||||
self:F( self.UnitName )
|
||||
|
||||
local DCSUnit = self:GetDCSObject() -- DCS#Unit
|
||||
|
||||
@@ -555,7 +579,7 @@ end
|
||||
-- @return #number The relative amount of fuel (from 0.0 to 1.0).
|
||||
-- @return #nil The DCS Unit is not existing or alive.
|
||||
function UNIT:GetFuel()
|
||||
self:F( self.UnitName )
|
||||
self:F3( self.UnitName )
|
||||
|
||||
local DCSUnit = self:GetDCSObject()
|
||||
|
||||
@@ -571,7 +595,7 @@ end
|
||||
-- @param #UNIT self
|
||||
-- @return #list<Wrapper.Unit#UNIT> A list of one @{Wrapper.Unit}.
|
||||
function UNIT:GetUnits()
|
||||
self:F2( { self.UnitName } )
|
||||
self:F3( { self.UnitName } )
|
||||
local DCSUnit = self:GetDCSObject()
|
||||
|
||||
local Units = {}
|
||||
@@ -588,8 +612,7 @@ end
|
||||
|
||||
--- Returns the unit's health. Dead units has health <= 1.0.
|
||||
-- @param #UNIT self
|
||||
-- @return #number The Unit's health value.
|
||||
-- @return #nil The DCS Unit is not existing or alive.
|
||||
-- @return #number The Unit's health value or -1 if unit does not exist any more.
|
||||
function UNIT:GetLife()
|
||||
self:F2( self.UnitName )
|
||||
|
||||
@@ -605,8 +628,7 @@ end
|
||||
|
||||
--- Returns the Unit's initial health.
|
||||
-- @param #UNIT self
|
||||
-- @return #number The Unit's initial health value.
|
||||
-- @return #nil The DCS Unit is not existing or alive.
|
||||
-- @return #number The Unit's initial health value or 0 if unit does not exist any more.
|
||||
function UNIT:GetLife0()
|
||||
self:F2( self.UnitName )
|
||||
|
||||
@@ -620,6 +642,34 @@ function UNIT:GetLife0()
|
||||
return 0
|
||||
end
|
||||
|
||||
--- Returns the unit's relative health.
|
||||
-- @param #UNIT self
|
||||
-- @return #number The Unit's relative health value, i.e. a number in [0,1] or -1 if unit does not exist any more.
|
||||
function UNIT:GetLifeRelative()
|
||||
self:F2(self.UnitName)
|
||||
|
||||
if self and self:IsAlive() then
|
||||
local life0=self:GetLife0()
|
||||
local lifeN=self:GetLife()
|
||||
return lifeN/life0
|
||||
end
|
||||
|
||||
return -1
|
||||
end
|
||||
|
||||
--- Returns the unit's relative damage, i.e. 1-life.
|
||||
-- @param #UNIT self
|
||||
-- @return #number The Unit's relative health value, i.e. a number in [0,1] or 1 if unit does not exist any more.
|
||||
function UNIT:GetDamageRelative()
|
||||
self:F2(self.UnitName)
|
||||
|
||||
if self and self:IsAlive() then
|
||||
return 1-self:GetLifeRelative()
|
||||
end
|
||||
|
||||
return 1
|
||||
end
|
||||
|
||||
--- Returns the category name of the #UNIT.
|
||||
-- @param #UNIT self
|
||||
-- @return #string Category name = Helicopter, Airplane, Ground Unit, Ship
|
||||
@@ -646,7 +696,9 @@ end
|
||||
|
||||
|
||||
--- Returns the Unit's A2G threat level on a scale from 1 to 10 ...
|
||||
-- The following threat levels are foreseen:
|
||||
-- Depending on the era and the type of unit, the following threat levels are foreseen:
|
||||
--
|
||||
-- **Modern**:
|
||||
--
|
||||
-- * Threat level 0: Unit is unarmed.
|
||||
-- * Threat level 1: Unit is infantry.
|
||||
@@ -659,13 +711,49 @@ end
|
||||
-- * Threat level 8: Unit is a Short Range SAM, radar guided.
|
||||
-- * Threat level 9: Unit is a Medium Range SAM, radar guided.
|
||||
-- * Threat level 10: Unit is a Long Range SAM, radar guided.
|
||||
--
|
||||
-- **Cold**:
|
||||
--
|
||||
-- * Threat level 0: Unit is unarmed.
|
||||
-- * Threat level 1: Unit is infantry.
|
||||
-- * Threat level 2: Unit is an infantry vehicle.
|
||||
-- * Threat level 3: Unit is ground artillery.
|
||||
-- * Threat level 4: Unit is a tank.
|
||||
-- * Threat level 5: Unit is a modern tank or ifv with ATGM.
|
||||
-- * Threat level 6: Unit is a AAA.
|
||||
-- * Threat level 7: Unit is a SAM or manpad, IR guided.
|
||||
-- * Threat level 8: Unit is a Short Range SAM, radar guided.
|
||||
-- * Threat level 10: Unit is a Medium Range SAM, radar guided.
|
||||
--
|
||||
-- **Korea**:
|
||||
--
|
||||
-- * Threat level 0: Unit is unarmed.
|
||||
-- * Threat level 1: Unit is infantry.
|
||||
-- * Threat level 2: Unit is an infantry vehicle.
|
||||
-- * Threat level 3: Unit is ground artillery.
|
||||
-- * Threat level 5: Unit is a tank.
|
||||
-- * Threat level 6: Unit is a AAA.
|
||||
-- * Threat level 7: Unit is a SAM or manpad, IR guided.
|
||||
-- * Threat level 10: Unit is a Short Range SAM, radar guided.
|
||||
--
|
||||
-- **WWII**:
|
||||
--
|
||||
-- * Threat level 0: Unit is unarmed.
|
||||
-- * Threat level 1: Unit is infantry.
|
||||
-- * Threat level 2: Unit is an infantry vehicle.
|
||||
-- * Threat level 3: Unit is ground artillery.
|
||||
-- * Threat level 5: Unit is a tank.
|
||||
-- * Threat level 7: Unit is FLAK.
|
||||
-- * Threat level 10: Unit is AAA.
|
||||
--
|
||||
--
|
||||
-- @param #UNIT self
|
||||
function UNIT:GetThreatLevel()
|
||||
|
||||
|
||||
local ThreatLevel = 0
|
||||
local ThreatText = ""
|
||||
|
||||
|
||||
local Descriptor = self:GetDesc()
|
||||
|
||||
if Descriptor then
|
||||
@@ -783,40 +871,36 @@ function UNIT:GetThreatLevel()
|
||||
|
||||
end
|
||||
|
||||
--- Triggers an explosion at the coordinates of the unit.
|
||||
-- @param #UNIT self
|
||||
-- @param #number power Power of the explosion in kg TNT. Default 100 kg TNT.
|
||||
-- @param #number delay (Optional) Delay of explosion in seconds.
|
||||
-- @return #UNIT self
|
||||
function UNIT:Explode(power, delay)
|
||||
|
||||
-- Default.
|
||||
power=power or 100
|
||||
|
||||
local DCSUnit = self:GetDCSObject()
|
||||
if DCSUnit then
|
||||
|
||||
-- Check if delay or not.
|
||||
if delay and delay>0 then
|
||||
-- Delayed call.
|
||||
SCHEDULER:New(nil, self.Explode, {self, power}, delay)
|
||||
else
|
||||
-- Create an explotion at the coordinate of the unit.
|
||||
self:GetCoordinate():Explosion(power)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Is functions
|
||||
|
||||
--- Returns true if the unit is within a @{Zone}.
|
||||
-- @param #UNIT self
|
||||
-- @param Core.Zone#ZONE_BASE Zone The zone to test.
|
||||
-- @return #boolean Returns true if the unit is within the @{Core.Zone#ZONE_BASE}
|
||||
function UNIT:IsInZone( Zone )
|
||||
self:F2( { self.UnitName, Zone } )
|
||||
|
||||
if self:IsAlive() then
|
||||
local IsInZone = Zone:IsVec3InZone( self:GetVec3() )
|
||||
|
||||
return IsInZone
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Returns true if the unit is not within a @{Zone}.
|
||||
-- @param #UNIT self
|
||||
-- @param Core.Zone#ZONE_BASE Zone The zone to test.
|
||||
-- @return #boolean Returns true if the unit is not within the @{Core.Zone#ZONE_BASE}
|
||||
function UNIT:IsNotInZone( Zone )
|
||||
self:F2( { self.UnitName, Zone } )
|
||||
|
||||
if self:IsAlive() then
|
||||
local IsInZone = not Zone:IsVec3InZone( self:GetVec3() )
|
||||
|
||||
self:T( { IsInZone } )
|
||||
return IsInZone
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Returns true if there is an **other** DCS Unit within a radius of the current 2D point of the DCS Unit.
|
||||
@@ -897,34 +981,35 @@ end
|
||||
|
||||
--- Returns true if the UNIT is in the air.
|
||||
-- @param #UNIT self
|
||||
-- @return #boolean true if in the air.
|
||||
-- @return #nil The UNIT is not existing or alive.
|
||||
-- @return #boolean Return true if in the air or #nil if the UNIT is not existing or alive.
|
||||
function UNIT:InAir()
|
||||
self:F2( self.UnitName )
|
||||
|
||||
-- Get DCS unit object.
|
||||
local DCSUnit = self:GetDCSObject() --DCS#Unit
|
||||
|
||||
if DCSUnit then
|
||||
-- Implementation of workaround. The original code is below.
|
||||
-- This to simulate the landing on buildings.
|
||||
|
||||
local UnitInAir = true
|
||||
|
||||
-- Get DCS result of whether unit is in air or not.
|
||||
local UnitInAir = DCSUnit:inAir()
|
||||
|
||||
-- Get unit category.
|
||||
local UnitCategory = DCSUnit:getDesc().category
|
||||
if UnitCategory == Unit.Category.HELICOPTER then
|
||||
|
||||
-- If DCS says that it is in air, check if this is really the case, since we might have landed on a building where inAir()=true but actually is not.
|
||||
-- This is a workaround since DCS currently does not acknoledge that helos land on buildings.
|
||||
-- Note however, that the velocity check will fail if the ground is moving, e.g. on an aircraft carrier!
|
||||
if UnitInAir==true and UnitCategory == Unit.Category.HELICOPTER then
|
||||
local VelocityVec3 = DCSUnit:getVelocity()
|
||||
local Velocity = ( VelocityVec3.x ^ 2 + VelocityVec3.y ^ 2 + VelocityVec3.z ^ 2 ) ^ 0.5 -- in meters / sec
|
||||
local Velocity = UTILS.VecNorm(VelocityVec3)
|
||||
local Coordinate = DCSUnit:getPoint()
|
||||
local LandHeight = land.getHeight( { x = Coordinate.x, y = Coordinate.z } )
|
||||
local Height = Coordinate.y - LandHeight
|
||||
if Velocity < 1 and Height <= 60 then
|
||||
UnitInAir = false
|
||||
end
|
||||
else
|
||||
UnitInAir = DCSUnit:inAir()
|
||||
end
|
||||
|
||||
|
||||
|
||||
self:T3( UnitInAir )
|
||||
return UnitInAir
|
||||
end
|
||||
|
||||
6
Moose Setup/Eclipse/Moose Loader Dynamic.launch
Normal file
6
Moose Setup/Eclipse/Moose Loader Dynamic.launch
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="C:\ProgramData\chocolatey\lib\lua51\tools\lua5.1.exe"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value=""Moose Setup\Moose_Create.lua" "D" "LOCAL" "${resource_loc:/MOOSE/Moose Development/Moose}" "${resource_loc:/MOOSE/Moose Setup}" ${resource_loc:/MOOSE_INCLUDE/Moose_Include_Dynamic}"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/MOOSE}"/>
|
||||
</launchConfiguration>
|
||||
6
Moose Setup/Eclipse/Moose Loader Static.launch
Normal file
6
Moose Setup/Eclipse/Moose Loader Static.launch
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="C:\ProgramData\chocolatey\lib\lua51\tools\lua5.1.exe"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value=""Moose Setup\Moose_Create.lua" "S" "LOCAL" "${resource_loc:/MOOSE/Moose Development/Moose}" "${resource_loc:/MOOSE/Moose Setup}" ${resource_loc:/MOOSE_INCLUDE/Moose_Include_Static}"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/MOOSE}"/>
|
||||
</launchConfiguration>
|
||||
@@ -18,3 +18,5 @@ __Moose.Include = function( IncludeFile )
|
||||
end
|
||||
|
||||
__Moose.Includes = {}
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Modules.lua' )
|
||||
|
||||
@@ -58,13 +58,27 @@ Functional/Artillery.lua
|
||||
Functional/Suppression.lua
|
||||
Functional/PseudoATC.lua
|
||||
Functional/Warehouse.lua
|
||||
Functional/Fox.lua
|
||||
|
||||
Ops/Airboss.lua
|
||||
Ops/RecoveryTanker.lua
|
||||
Ops/RescueHelo.lua
|
||||
Ops/ATIS.lua
|
||||
|
||||
AI/AI_Balancer.lua
|
||||
AI/AI_Air.lua
|
||||
AI/AI_A2A.lua
|
||||
AI/AI_A2A_Patrol.lua
|
||||
AI/AI_A2A_Cap.lua
|
||||
AI/AI_A2A_Gci.lua
|
||||
AI/AI_A2A_Dispatcher.lua
|
||||
AI/AI_A2G.lua
|
||||
AI/AI_A2G_Engage.lua
|
||||
AI/AI_A2G_BAI.lua
|
||||
AI/AI_A2G_CAS.lua
|
||||
AI/AI_A2G_SEAD.lua
|
||||
AI/AI_A2G_Patrol.lua
|
||||
AI/AI_A2G_Dispatcher.lua
|
||||
AI/AI_Patrol.lua
|
||||
AI/AI_Cap.lua
|
||||
AI/AI_Cas.lua
|
||||
@@ -100,4 +114,4 @@ Tasking/Task_Cargo_CSAR.lua
|
||||
Tasking/Task_Cargo_Dispatcher.lua
|
||||
Tasking/TaskZoneCapture.lua
|
||||
|
||||
Moose.lua
|
||||
Globals.lua
|
||||
|
||||
@@ -12,15 +12,15 @@ print( "Moose development path : " .. MooseDevelopmentPath )
|
||||
print( "Moose setup path : " .. MooseSetupPath )
|
||||
print( "Moose target path : " .. MooseTargetPath )
|
||||
|
||||
local MooseSourcesFilePath = MooseSetupPath .. "/Moose.files"
|
||||
local MooseFilePath = MooseTargetPath.."/Moose.lua"
|
||||
local MooseModulesFilePath = MooseDevelopmentPath .. "/Modules.lua"
|
||||
local LoaderFilePath = MooseTargetPath .. "/Moose.lua"
|
||||
|
||||
print( "Reading Moose source list : " .. MooseSourcesFilePath )
|
||||
print( "Reading Moose source list : " .. MooseModulesFilePath )
|
||||
|
||||
local MooseFile = io.open( MooseFilePath, "w" )
|
||||
local LoaderFile = io.open( LoaderFilePath, "w" )
|
||||
|
||||
if MooseDynamicStatic == "S" then
|
||||
MooseFile:write( "env.info( '*** MOOSE GITHUB Commit Hash ID: " .. MooseCommitHash .. " ***' )\n" )
|
||||
LoaderFile:write( "env.info( '*** MOOSE GITHUB Commit Hash ID: " .. MooseCommitHash .. " ***' )\n" )
|
||||
end
|
||||
|
||||
local MooseLoaderPath
|
||||
@@ -35,27 +35,26 @@ local MooseLoader = io.open( MooseLoaderPath, "r" )
|
||||
local MooseLoaderText = MooseLoader:read( "*a" )
|
||||
MooseLoader:close()
|
||||
|
||||
MooseFile:write( MooseLoaderText )
|
||||
LoaderFile:write( MooseLoaderText )
|
||||
|
||||
|
||||
local MooseSourcesFile = io.open( MooseSourcesFilePath, "r" )
|
||||
local MooseSourcesFile = io.open( MooseModulesFilePath, "r" )
|
||||
local MooseSource = MooseSourcesFile:read("*l")
|
||||
|
||||
while( MooseSource ) do
|
||||
|
||||
if MooseSource ~= "" then
|
||||
MooseSource = string.match( MooseSource, "Scripts/Moose/(.+)'" )
|
||||
local MooseFilePath = MooseDevelopmentPath .. "/" .. MooseSource
|
||||
if MooseDynamicStatic == "D" then
|
||||
print( "Load dynamic: " .. MooseSource )
|
||||
MooseFile:write( "__Moose.Include( 'Scripts/Moose/" .. MooseSource .. "' )\n" )
|
||||
print( "Load dynamic: " .. MooseFilePath )
|
||||
end
|
||||
if MooseDynamicStatic == "S" then
|
||||
print( "Load static: " .. MooseSource )
|
||||
print( "Load static: " .. MooseFilePath )
|
||||
local MooseSourceFile = io.open( MooseFilePath, "r" )
|
||||
local MooseSourceFileText = MooseSourceFile:read( "*a" )
|
||||
MooseSourceFile:close()
|
||||
|
||||
MooseFile:write( MooseSourceFileText )
|
||||
LoaderFile:write( MooseSourceFileText )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,13 +62,13 @@ while( MooseSource ) do
|
||||
end
|
||||
|
||||
if MooseDynamicStatic == "D" then
|
||||
MooseFile:write( "BASE:TraceOnOff( true )\n" )
|
||||
LoaderFile:write( "BASE:TraceOnOff( true )\n" )
|
||||
end
|
||||
if MooseDynamicStatic == "S" then
|
||||
MooseFile:write( "BASE:TraceOnOff( false )\n" )
|
||||
LoaderFile:write( "BASE:TraceOnOff( false )\n" )
|
||||
end
|
||||
|
||||
MooseFile:write( "env.info( '*** MOOSE INCLUDE END *** ' )\n" )
|
||||
LoaderFile:write( "env.info( '*** MOOSE INCLUDE END *** ' )\n" )
|
||||
|
||||
MooseSourcesFile:close()
|
||||
MooseFile:close()
|
||||
LoaderFile:close()
|
||||
|
||||
Reference in New Issue
Block a user