Command Modern Air Naval Operations : Lua Repository #3 – Weather

Weather in CMANO is one of those things you don’t think about until suddenly you can’t attack a target. Then you realize that the world is alive below you. As a scenario designer it’s one of those things that can really fill out your scenario and bring it to life. We’ll explore a few simple methods to give both random weather and one neat trick to make scheduled weather that saves you from making dozens of triggers!

ScenEdit_SetWeather(math.random(0,25), math.random(0,50), math.random(0,10)/10.0, math.random(0,9))

At the most basic we use the ScenEdit_SetWeather function. In the above text we make weather completely random from top to bottom.

ScenEdit_SetWeather (temperature, rainfall, undercloud, seastate)

The first variable is temperature. You can make this positive, negative, or a range as above. Now if you want a range to be something tighter than 0 to 25, or -50 to -20, just use math.random(-33,-20). Rainfall is what the second table looks like. Undercloud is a bit more difficult to describe. It’s a range of shitty and nasty weather ranging from light clouds all the way to pea soup.

Cloud Cover 1 : Thick Fog 0-2k Ft, solid cloud cover 7 - 36k ft
Cloud Cover 0.9 : Thin Fog 0-2k ft, solid cloud cover 7 - 36k ft
Cloud Cover 0.8 : Solid middle clouds 7-16k ft, moderate high clouds 30-36k ft
Cloud Cover 0.7 : Moderate middle clouds 7 - 16k ft, light high clouds 27 - 30k ft
Cloud Cover 0.6 : Moderate high clouds 25-28k ft
Cloud Cover 0.5 : Moderate middle clouds 7-16k ft
Cloud Cover 0.4 : Moderate low clouds 2-7k ft
Cloud Cover 0.3 : Light High Clouds 20-23k ft
Cloud Cover 0.2 : Light middle clouds 10-16k ft
Cloud Cover 0.1 : Light low clouds 5 - 7k ft
Cloud Cover 0 : Clear Sky
Rain 0 : No Rain
Rain 1-4 : Very Light Rain
Rain 5-9 : Light Rain
Rain 10-19 : Moderate Rain
Rain 20-29 : Heavy Rain
Rain 30-39 : Very Heavy Rain
Rain 40-50 : Extreme Rain

Sea state relates to the Beaufort Sea State Scale. It is something immensely interesting on shore, but terrifying at sea. I don’t know exactly what variables a 9 sea would create in the game, longer deck times on a carrier? More difficulty finding a sub? But it’s good to keep it in mind.

Putting it into practice

One of the easiest way to do it is to set a trigger that is a Scenario is Loaded trigger. Then have the action be our random script above, except tweak the ranges to be realistic for your theater of operation. North Sea in December? Low temps. Thick clouds. Strong seas. Western Iraq in summer? High temps. No clouds. No seas. (Hopefully!) One play through might get the best possible weather for that time of year and the next might get more interesting weather.

But weather changes. Sometimes rapidly. So how do we deal with that? We have a trigger called Regular Time that will fire the trigger in whatever time scale you set ranging from one second to one hour. Our action will look like below.

The Regular Time Trigger will make the weather change once an hour. The temperature will vary between 15 and 25 degrees celsius, the rain will vary from state zero to ten, cloud cover from 0.4 to 0.6 and sea state from zero to nine. Plus we’ll notify the player.

But what if we want the player to get told the forecast by Floyd the weather man?

local weather = ScenEdit_GetWeather()
local printed_weather = "The weather has changed. The temperature is now " .. ". Rainfall is " .. ". The cloud level is " .. ". Sea State is " .. "."
ScenEdit_SpecialMessage("blufor", printed_weather)

This will show you the current weather but it’s not really reader friendly. weather.undercloud is just a number. Now we’d need to make a way to compare the undercloud value and output something useful.

ScenEdit_SetWeather(math.random(15,25), math.random(0,10), math.random(4,6)*0.1, math.random(0,9))
local weather = ScenEdit_GetWeather()
local display_undercloud
local cleanUndercloud = math.floor(weather.undercloud*10)
if cleanUndercloud == 4 then
display_undercloud = "Moderate low clouds 2-7k ft"
elseif cleanUndercloud == 5 then
display_undercloud = "Moderate middle clouds 7-16k ft"
elseif cleanUndercloud == 6 then
display_undercloud = "Moderate high clouds 25-28k ft"
display_undercloud = "Sharknado!"
local printed_weather = "The weather has changed. The temperature is now " .. ". Rainfall is " .. ". The cloud level is " ..display_undercloud .. ". Sea State is " .. "."
ScenEdit_SpecialMessage("blufor", printed_weather)

Now that all looks intimidating but we’re setting the weather, assigning it to the variable weather, and this is where it gets tricky. As our number is a decimal sometimes we get 0.5, and other times we 0.500000634545 or some such nonsense. This will cause you grief it you try to compare it to 0.5. So now we are setting the variable cleanUndercloud to be an integer (whole number) that is bounded by our weather.undercloud value times 10.

If all else, just trust me. This is where programming can be cool. You don’t need to know how this works, you just need to know how to grab bits that work and tack them onto other bits that work.

Finally we run it through an if else block and compare the values. If it’s what we want then we assign a text string to the display_undercloud variable. Then our printed_weather string is a concatenation (how’s that for a fancy programming word) of variables into something useful. Our special message outputs all of that to the player on side blufor!

We could improve this with a display for rain levels too, but you get the idea.

Scripted Weather

But what if you want a narrative of weather? I’ll give props to Apache and Peter at the CMANO Discord for inspiring this one. Thanks guys!

You can store a variable in CMANO using ScenEdit_SetKeyValue and later get it with ScenEdit_GetKeyValue. But another clever way to do it is to create a side, say named Weather, and assign it a score.

Now you can script weather depending on the score count. So once an hour the side Weather will get 1 more point. You could make a trigger to check the side points and when it reaches a number you want it fires. (Or use ScenEdit_GetScore inside of an event action) Then for actions you can set the weather you want and deliver an event action message that not only gives the current forecast but also tells the player what to expect at the next time change.

It can be a bit more work to set it up, but you can add html images (Use imgur) and give the player an actual weather map.

Area Weather

This method is kind of gamey. CMANO doesn’t model weather fronts or areas of weather. If you set weather it’s a global change. One way around it is you can set a trigger for when a unit enters an area to change the weather. Maybe a task force from a carrier crosses over land. The weather between sea and land could be drastically different. The issue becomes now the whole game is that different weather type now.

For an attack mission or smaller scenario where things aren’t all stretched out it’d probably work fine. For a massive scenario with multiple threats. Not so much.

Just make sure you notify the player when the weather changes. Otherwise it can be really frustrating to wonder why exactly none of your LGB’s can get dropped on targets.



Gamer, Author, Engineer, Dad.

Leave a Reply

Next ArticleCommand Modern Air Naval Operations : Lua Repository #4 Random Traffic