Deck Cycles in LUA
Posted: Thu Sep 30, 2021 12:03 pm
				
				 In CMO is that you're not confined to operating carriers in deck cycles.  That being said it's commonplace for pairs of CVs to operate in 12 hour deck cycles consisting of 6 hours of daylight and 6 hours of night in order to provide 24 hour flight operations between the two of them.  The thing is, there isn't a good way to impose deck cycles on the player, which is both a good and a bad thing.  It's good in the sense that it's allows one to experiment with alternative doctrines, but its bad in the sense that it can lead to unrealistically high sortie rates if the player chooses to push the limits.  This is my stab at imposing deck cycles on a player at scenario start:
 
 
This first part sets up some constants. The gb and gw are just guids for the paired aircraft carriers in your scenario. They are used to define an array. Feel free to modify that part to suit your scenario.
 
 
When this script is paired with a ScenarioLoad triggered event, the following code will randomly choose a carrier from the above array.
 
This loops over the aircraft in on the selected inActiveCvn and sets them to a reserve loadout with a ready time of 12 hours.
 
You should be able to paste all of the above code in order in a single LuaScript action without trouble.
			This first part sets up some constants. The gb and gw are just guids for the paired aircraft carriers in your scenario. They are used to define an array. Feel free to modify that part to suit your scenario.
Code: Select all
 -- This script determines which CVN is currently in the active phase of its deck cycle.
 gb = 'GWKW9V-0HMC21A9CO9FE'   -- USS George W. Bush
 gw ='GWKW9V-0HMC21A9COA5M'  -- USS George Washington
 cvns = {gb, gw}
 
 reserveLoadout = 3
 oneDeckCycle = 12 * 60 -- 12 hours
 When this script is paired with a ScenarioLoad triggered event, the following code will randomly choose a carrier from the above array.
Code: Select all
 -- coin flip choose which of the two cvns gets to be active.  The other will have the aircraft placed in a "reserve." state
 math.randomseed (os.time ())
 if (math.random() < 0.5) then
      cvnI = 1
 else 
      cvnI = 2
 end
 
 inActiveCvnGuid = cvns[cvnI]
 
 inActiveCvn = ScenEdit_GetUnit( { guid = inActiveCvnGuid  } )
 inActiveAircraft = inActiveCvn.assignedUnits.Aircraft
 This loops over the aircraft in on the selected inActiveCvn and sets them to a reserve loadout with a ready time of 12 hours.
Code: Select all
 for acIdx, acId in ipairs( inActiveAircraft )
 do
     ScenEdit_SetLoadout({UnitName=acId , LoadoutID=reserveLoadout, IgnoreMagazines=true, TimeToReady_Minutes=oneDeckCycle }) 
 end
 
 You should be able to paste all of the above code in order in a single LuaScript action without trouble.
