Monday, September 18, 2017

CMANO - Making Tactical Decision Aids - The Lua Gag Reel Episode 1

In my previous entry, I praised WarfareSims for their farsighted decision to extend the CMANO's base code with the wide capabilities, simplicity and memory management benefits of the Lua scripting language.



I deeply appreciate the interest that many of you have expressed for knowing how I did put together my tactical decision aid, but I have to confess that I dread that you will be disappointed. I'm no programmer, and I grabbed pieces of code from here and there to put together this Frankenstein project. I apologize in advance, as you may see improper coding techniques and some inconsistencies in the logic of my entire scenario.

Without further ado, here is what I did.

If you remember from my previous post, the sequence of events was:
  1. The scenario starts
    1. A counter is initialized. This counter keeps track of a series recursive ship vs sub simulation runs
    2. Units are added to the scenario
      1. The US warship is placed in the center and give a course due south, at flank speed
      2. A DPRK sub is placed 50 miles from the US ship and given a patrol area delineated by the reference points above
    3. If the US warship remains undetected and reaches an escape area south of the DPRK patrol's area
      1. All units are deleted
      2. The counter mentioned in 1.1 is advanced
      3. New units are generated
        1. A US warship is placed in the center and give a course due south, at flank speed
        2. A DPRK sub is placed 50 miles from the US ship and given a patrol area delineated by the reference points above. The DPRK sub initial position is not the same as the one used in the previous simulation run. This initial position is advanced clockwise from the initial position of the US warship
    4. If the US warship is detected
      1. A marker reference point is made at the initial position of the DPRK sub. The marker is labelled "Danger" because this an initial sub position that will generate a headache for the US commander.
      2. All units are deleted
      3. The counter mentioned in 1.1 is advanced
      4. New units are generated
        1. Same as 3.1
        2. Same as 3.2
The CMANO scenario editor allows the player to glue together special actions within events. Events are triggered by triggers and conditioned by conditions :) . This is because many times, you want an special action (strike hostile nation's port)  to happen when something has happened (i.e. a friendly ship was attacked, a trigger) and a condition is met (i.e. you have the means to strike nearby the target, a condition).

The logical hierarchy goes: Events do happen when Triggers are triggered, Conditions are met. The output is actions. 

The beauty of all this is that conditions and actions can be Lua scripts. And when you unleash a Lua script, the world moon is at your feet.

So, let's start with the events.

Events

I'm first going to list the events that mark the course of this scenario.

  1. The scenario starts. In the editor, I created an event named Scenario Start Event
    1. A counter is initialized. This counter keeps track of a series recursive ship vs sub simulation runs
    2. Units are added to the scenario
      1. The US warship is placed in the center and give a course due south, at flank speed
      2. A DPRK sub is placed 50 miles from the US ship and given a patrol area delineated by the reference points above
    3. If the US warship remains undetected and reaches an escape area south of the DPRK patrol's area. In the editor I created an event named US Warship has Escaped from the Area.
      1. All units are deleted
      2. The counter mentioned in 1.1 is advanced
      3. New units are generated
        1. A US warship is placed in the center and give a course due south, at flank speed
        2. A DPRK sub is placed 50 miles from the US ship and given a patrol area delineated by the reference points above. The DPRK sub initial position is not the same as the one used in the previous simulation run. This initial position is advanced clockwise from the initial position of the US warship
    4. If the US warship is detected. In the editor I created an event named US Warship Was Detected.
      1. A marker reference point is made at the initial position of the DPRK sub. The marker is labelled "Danger" because this an initial sub position that will generate a headache for the US commander.
      2. All units are deleted
      3. The counter mentioned in 1.1 is advanced
      4. New units are generated
        1. Same as 3.1
        2. Same as 3.2
My list of events.

And let's take a cursory look at the triggers, conditions and events that make up every event.


The Scenario Start Event: One trigger, no conditions, and two actions.

The US Warship has Escaped from the Area event: one trigger, no conditions, two actions.

The US Warship Was Detected event: one trigger, no conditions, three actions.

It is a very good practice to draft an outline of what you want to happen from the very start. 

For beginners, it is also helpful to add the word "Event", "Condition" and "Action" while naming events, conditions and actions. This is a thing I practiced only partially (see above). When you are tired, it is very easy to loose track if you are editing a trigger or an action. The potential for shenanigans is an exponential function of the numbers of logical entities you have playing around.

In the next episode, let's get into some Lua.

Cheers,


3 comments:

Anonymous said...

You're a very brave man for diving into all that!

As a programmer, I can tell you that your notes on drafting an outline and naming things appropriately will help you a ton. Minimizing confusion is key. I'm looking forward to seeing what you can cook up!

-tFS (theFlyingDouble-Immelman)

JC said...

How are you? It's amateurs night! :p

Thanks for reading,

xxup said...

Gripping stuff. I can't wait for the next instalment. Thank you for doing this for us.