I'm trying to put together a little script repository for myself of functions to use, and I want to build a script that will cause a task group to sail as a group, proceed along a series of waypoints at a set speed, wait at some waypoints and then recommence their transit at a certain time, RAS along the way and finally rebase themselves when they get to the other end.
Ideally, I'd like to get the script to place waypoints on created reference points that I place on the map so that it would be easier to define a PIM in the future.
Ideally, I'd like someone to coach me through this rather than just outright writing the code for me. This is supposed to be an exercise in learning a bit of LUA, but I'm not exactly a code guru.
Thanks in advance!
- Bashkire
EDIT:
221429ZMAR2023 - TitaniumTrout has suggested that I attempt to walk before running - which he probably has a point with - and to break up my long script into separate segments for ease of testing. To that end, I'm posting my segments below and removing the long version above.
221940ZMAR2023 - Updated scripts with working versions.
272214ZMAR2023 - Updated re-basing script with working version.
212305ZMAY2023 - Updated scripts with the PIM broken into 2 legs for ease of conducting Suez Transit.
Code: Select all
-------------------------------------
----- Define GUIDs -----
-------------------------------------
----- Working -----
----- Ships
unit_albion = ScenEdit_GetUnit({side = "Royal Navy", name = "[L 14] HMS Albion [Albion Class]"})
albion = unit_albion.guid
-----print (albion)
unit_daring = ScenEdit_GetUnit({side = "Royal Navy", name = "[D 32] HMS Daring [Type 45]"})
daring = unit_daring.guid
-----print (daring)
unit_lancaster = ScenEdit_GetUnit({side = "Royal Navy", name = "[F 229] HMS Lancaster [Type 23]"})
lancaster = unit_lancaster.guid
-----print (lancaster)
unit_westminster = ScenEdit_GetUnit({side = "Royal Navy", name = "[F 237] HMS Westminster [Type 23]"})
westminster = unit_westminster.guid
-----print (westminster)
unit_tidespring = ScenEdit_GetUnit({side = "Royal Navy", name = "[A 136] RFA Tidespring [Tide Class]"})
tidespring = unit_tidespring.guid
-----print (tidespring)
----- Aircraft
unit_chinook_1 = ScenEdit_GetUnit ({side = "Royal Navy", name = "Workhorse 1"})
chinook_1 = unit_chinook_1.guid
-----print (chinook_1)
unit_chinook_2 = ScenEdit_GetUnit ({side = "Royal Navy", name = "Workhorse 2"})
chinook_2 = unit_chinook_2.guid
-----print (chinook_2)
----- Bases
base_souda = ScenEdit_GetUnit({side = "Royal Navy", name = "NSA Souda Bay"})
souda = base_souda.guid
-----print (souda)
base_sgiPort = ScenEdit_GetUnit ({side = "St. George's Island", name = "St. George's Island Commercial Port and Naval Base"})
sgiPort = base_sgiPort.guid
-----print (sgiPort)
base_sgiAirport = ScenEdit_GetUnit ({side = "St. George's Island", name = "St. George's Island International Airport and Air Base"})
sgiAirport = base_sgiAirport.guid
-----print (sgiAirport)
Code: Select all
-------------------------------------
----- Units Set Sail -----
-------------------------------------
----- Working -----
unit_albion:Launch(true)
unit_daring:Launch(true)
unit_lancaster:Launch(true)
unit_westminster:Launch(true)
unit_tidespring:Launch(true)
Code: Select all
-------------------------------------
----- Create Group -----
-------------------------------------
----- Working -----
unit_albion.group = "TG 214"
unit_daring.group = "TG 214"
unit_lancaster.group = "TG 214"
unit_westminster.group = "TG 214"
unit_tidespring.group = "TG 214"
TG214 = ScenEdit_GetUnit({guid=unit_albion.group.guid})
TG214.group.lead = unit_albion.guid
Code: Select all
-------------------------------------
----- Set Formation -----
-------------------------------------
----- Working -----
TG214Heading = unit_albion.heading
-----print("TG214 Heading " .. TG214Heading)
station2 = TG214Heading-60
if station2 <0
then
station2 = station2+360
end
if station2 >360
then
station2 = station2-360
end
-----print("Station 2: " .. station2)
station3 = TG214Heading+60
if station3 <0
then
station3 = station3+360
end
if station3 >360
then
station3 = station3-360
end
-----print("Station 3: " .. station3)
station4 = TG214Heading-180
if station4 <0
then
station4 = station4+360
end
if station4 >360
then
station4 = station4-360
end
-----print("Station 4: " .. station4)
unit_daring.formation = {type = "Relative", sprint = false, bearing = TG214Heading, distance = 5}
unit_lancaster.formation = {type = "Relative", sprint = false, bearing = station2, distance = 4}
unit_westminster.formation = {type = "Relative", sprint = false, bearing = station3, distance = 4}
unit_tidespring.formation = {type = "Relative", sprint = false, bearing = station4, distance = 0.5}
Code: Select all
-------------------------------------
----- Create PIM - Leg 1 -----
-------------------------------------
----- Working -----
TG214Course1 = {}
table.insert (TG214Course1, {latitude = 35.4937989469592, longitude = 24.2427923255052, description = "AA", desiredSpeed=18.0}) ----- 162000ZSEP2022
table.insert (TG214Course1, {latitude = 35.5336551146554, longitude = 24.9697100962326, description = "BB"}) ----- 162158ZSEP2022
table.insert (TG214Course1, {latitude = 35.4362140625729, longitude = 26.3732438434947, description = "CC"}) ----- 170148ZSEP2022
table.insert (TG214Course1, {latitude = 31.6629092209283, longitude = 32.4239367498279, description = "DD"}) ----- 172248ZSEP2022
----- Task group at anchor
----- Starts moving to EE at 180214ZSEP2022
TG214.course = TG214Course1
Code: Select all
-------------------------------------
----- Create PIM - Leg 2 -----
-------------------------------------
----- Working -----
TG214Course2 = {}
table.insert (TG214Course2, {latitude = 31.2843387727463, longitude = 32.3530901412483, description = "EE", desiredSpeed=18.0}) ----- 180330ZSEP 2022
----- Start of Suez transit
table.insert (TG214Course2, {latitude = 29.923971369994, longitude = 32.5500272692784, description = "FF"}) ----- 181420ZSEP2022
----- End of Suez transit
table.insert (TG214Course2, {latitude = 29.8164816330461, longitude = 32.5470903159812, description = "GG"}) ----- 181456ZSEP2022
table.insert (TG214Course2, {latitude = 29.414482754459, longitude = 32.6377674345322, description = "HH"}) ----- 181618ZSEP2022
table.insert (TG214Course2, {latitude = 28.5384244631035, longitude = 33.1155268896664, description = "II"}) ----- 181933ZSEP2022
table.insert (TG214Course2, {latitude = 27.7407702092935, longitude = 33.8221197239452, description = "JJ"}) ----- 182255ZSEP2022
table.insert (TG214Course2, {latitude = 27.2738446731173, longitude = 34.5181003169432, description = "KK"}) ----- 190130ZSEP2022
table.insert (TG214Course2, {latitude = 13.7608347724828, longitude = 42.4114180210723, description = "LL"}) ----- 210452ZSEP2022
table.insert (TG214Course2, {latitude = 12.1498531203117, longitude = 43.8040899421419, description = "MM"}) ----- 211154ZSEP2022
table.insert (TG214Course2, {latitude = 12.0803923307178, longitude = 44.8166120863782, description = "NN"}) ----- 211512ZSEP2022
table.insert (TG214Course2, {latitude = 12.9104302903057, longitude = 50.2211191228355, description = "OO"}) ----- 220902ZSEP2022
table.insert (TG214Course2, {latitude = 12.6543053701253, longitude = 53.1276826153152, description = "PP"}) ----- 221831ZSEP2022
TG214.course = TG214Course2
Code: Select all
-------------------------------------
----- Conduct RAS -----
-------------------------------------
----- Not Working -----
----- Ships do not fully refuel when multiple arrive at tanker at the same time.
----- Possible workaround: define times to RAS in order to stagger unit arrivals?
ScenEdit_RefuelUnit ({side = "Royal Navy", guid = albion, tanker = tidespring})
ScenEdit_RefuelUnit ({side = "Royal Navy", guid = daring, tanker = tidespring})
ScenEdit_RefuelUnit ({side = "Royal Navy", guid = lancaster, tanker = tidespring})
ScenEdit_RefuelUnit ({side = "Royal Navy", guid = westminster, tanker = tidespring})
Code: Select all
-------------------------------------
----- Assign New Bases -----
-------------------------------------
----- Working -----
ScenEdit_SetUnit({side="Royal Navy", unitname=albion, base=sgiPort})
ScenEdit_SetUnit({side="Royal Navy", unitname=daring, base=sgiPort})
ScenEdit_SetUnit({side="Royal Navy", unitname=lancaster, base=sgiPort})
ScenEdit_SetUnit({side="Royal Navy", unitname=westminster, base=sgiPort})
ScenEdit_SetUnit({side="Royal Navy", unitname=tidespring, base=sgiPort})
ScenEdit_SetUnit({side="Royal Navy", unitname=chinook_1, base=sgiAirport})
ScenEdit_SetUnit({side="Royal Navy", unitname=chinook_2, base=sgiAirport})