Code: Select all
_C1_1ST_1ST_RIFLE_COY_48_US_6 = {7,8,9,10} -- [C] [2102218] C1/1st/1st Rifle Company 48 - US
_1ST_VM_RIFLE_48_7 = {7} -- [P] [90,33] [212040] VM Rifle Platoon 48 (U.S. Arms)
_2ND_VM_RIFLE_48_8 = {8} -- [P] [90,32] [212040] VM Rifle Platoon 48 (U.S. Arms)
_3RD_VM_RIFLE_48_9 = {9} -- [P] [89,33] [212040] VM Rifle Platoon 48 (U.S. Arms)
_MORTAR_10 = {10} -- [P] [89,33] [211008] VM 50mm Mortars
Note that unlike the earlier _C2_1ST_5TH_RIFLE_COY_48_US_73, the _C1_1ST_1ST_RIFLE_COY_48_US_6 includes an attached indirect fire unit, _MORTAR_10. This difference is significant, as you will see by and by.
Where the heck is _C1_1ST_1ST_RIFLE_COY_48_US_6? We might start clicking around the game map, looking for those platoon trackids (in the Unit List, with Options > Unit List > Show TrackIDs toggled ON). But we are smarter than that. We use the Find Organization Dialog to do the searching for us. New to CSVN: If you click on a platoon in the Find Organization Dialog, the map will jump to that unit and select (and highlight) it.
In the screenshot, we have selected the
2nd VM Rifle 48 8[6]
where the 8 is the platoon's trackid and the [6] indicates the parent org's trackid. That [6] corresponds to the 6 in
_C1_1ST_1ST_RIFLE_COY_48_US_6
What are _C1_1ST_1ST_RIFLE_COY_48_US_6's orders? In battle_plan_b(), we see:
Code: Select all
-- _C1_1ST_1ST_RIFLE_COY_48_US_6 -- C1/1st/1st Rifle Company 48 - US
do local units = difference(_C1_1ST_1ST_RIFLE_COY_48_US_6, _MORTAR_10)
if counter_exists(_C1_1ST_1ST_RIFLE_COY_48_US_6_POST) then
local objective = counter_hex(_C1_1ST_1ST_RIFLE_COY_48_US_6_POST)
if not within(units, objective, DOWNLEFTDIR, 2) then
move_norush(units, objective, NODIR, 0, 100)
else
defend_scatter(units, objective, DOWNLEFTDIR, 2, 50, false, DEFEND_STRONG)
end
if not at(_MORTAR_10, objective) then
move_rush(_MORTAR_10, objective, NODIR, 0, 100)
else
fire_indirect_nearest_to_hex(_MORTAR_10, objective, 100, true)
end
else
defend_weak(units)
fire_indirect_nearest(_MORTAR_10, 100, true)
end
end
Before we get too deeply into that, we note that, like the earlier company, _C1_1ST_1ST_RIFLE_COY_48_US_6 has a unit/location to defend, _C1_1ST_1ST_RIFLE_COY_48_US_6_POST. That is defined, in init_variables(), as:
Code: Select all
_C1_1ST_1ST_RIFLE_COY_48_US_6_POST = random_pick({146, 490}) -- _SUPPLY_CACHE_146, _JUNGLE_FACTORY_490
That is, _C1_1ST_1ST_RIFLE_COY_48_US_6 is to defend either of unit with trackid 146 or unit with trackid 490
Code: Select all
...
_JUNGLE_FACTORY_490 = {490} -- [P] [T1: 90,38] [218809] Jungle Factory
...
_SUPPLY_CACHE_146 = {146} -- [P] [T1: 82,28] [218811] Supply Cache (VP)
...
at 50% chance or either. (See the random_pick() description in Manual/LUA_FUNCTIONS_REFERENCE.txt for more details.)
We look up those two supply units in the Schedule Dialog:
On Turn 1, they are to arrive as "reinforcements" at or around the magenta circled hexes up to 4 hexes away ("scattered"). In our first quicky auto-test run, we see these placements:
In the screenshot, _C1_1ST_1ST_RIFLE_COY_48_US_6 is circled in yellow. The supply units have appeared at hexes 80,29 and 89,39 (magenta circles), each within 4 hexes of its reinforcement default centering hex (light blue squares).
It is important to realize that such placements are random. Due to the Reinforcement system's scattering mechanism, you will never know, from one game to the next (or auto-test to the next), exactly where they will be placed. It varies! Also, the 4 does not imply that the reinforcements will scatter 4 hexes away from the default center; they might. The 4 is the number of steps in a random walk algorithm, where the steps might be outward from the default hex, but can easily be backward steps towards the center. So a 4-step random walk might in fact end up just 1 hex away, possibly even walk back to the center. The random walk algorithm allows for very wide scattering, but in practice tends to favor slight scatter over wide scatter.
It is also important to know that since
Code: Select all
function init_variables ()
-- initialize values possibly varying through the course of the scenario
-- called once only, in on_startup()
...
-- logistic defense assignments
_C1_1ST_1ST_RIFLE_COY_48_US_6_POST = random_pick({146, 490}) -- _SUPPLY_CACHE_146, _JUNGLE_FACTORY_490
...
end
once determined (at game startup), _C1_1ST_1ST_RIFLE_COY_48_US_6_POST is unvarying, never again to change through the course of the scenario (or auto-test). (This invariability need not necessarily be the case, but in this case it is.)
Meaning to say, _C1_1ST_1ST_RIFLE_COY_48_US_6 will defend one supply unit or the other. But we won't know which until actual game play (or auto-test).
Here again are _C1_1ST_1ST_RIFLE_COY_48_US_6's orders:
Code: Select all
-- _C1_1ST_1ST_RIFLE_COY_48_US_6 -- C1/1st/1st Rifle Company 48 - US
do local units = difference(_C1_1ST_1ST_RIFLE_COY_48_US_6, _MORTAR_10)
if counter_exists(_C1_1ST_1ST_RIFLE_COY_48_US_6_POST) then
local objective = counter_hex(_C1_1ST_1ST_RIFLE_COY_48_US_6_POST)
if not within(units, objective, DOWNLEFTDIR, 2) then
move_norush(units, objective, NODIR, 0, 100)
else
defend_scatter(units, objective, DOWNLEFTDIR, 2, 50, false, DEFEND_STRONG)
end
if not at(_MORTAR_10, objective) then
move_rush(_MORTAR_10, objective, NODIR, 0, 100)
else
fire_indirect_nearest_to_hex(_MORTAR_10, objective, 100, true)
end
else
defend_weak(units)
fire_indirect_nearest(_MORTAR_10, 100, true)
end
end
First off, note the
Code: Select all
do local units = difference(_C1_1ST_1ST_RIFLE_COY_48_US_6, _MORTAR_10)
(See the difference() description in Manual//LUA_FUNCTIONS_REFERENCE.txt for more details.)
In this orders 'do ... end' code block, 'units' is not the entire company; rather, it is a subset, excluding the mortars, which are handled separately from the infantry units. Why is that? It is because you will want the infantry to man the front lines, to defend or to attack, with the mortars holding back somewhat to the rear. Direct Fire Infantry unit orders are typically different from Indirect Fire unit orders. You will want to define your 'local units =' carefully because of that.
If a supply unit defense post exists
Code: Select all
if counter_exists(_C1_1ST_1ST_RIFLE_COY_48_US_6_POST) then
which it does (unlike the earlier example, where the supply unit might be UNKNOWN), we determine the hex coordinates (the 'hc') of that defense post
Code: Select all
local objective = counter_hex(_C1_1ST_1ST_RIFLE_COY_48_US_6_POST)
then, for the infantry units only
Code: Select all
if not within(units, objective, DOWNLEFTDIR, 2) then
move_norush(units, objective, NODIR, 0, 100)
else
defend_scatter(units, objective, DOWNLEFTDIR, 2, 50, false, DEFEND_STRONG)
end
if the infantry units are not within 2 hexes downward/leftward of the supply unit, they are to move (no rush!) to that objective. In a later turn, if they are within that hex arc, the 'not within() is false, so instead they should
Code: Select all
defend_scatter(units, objective, DOWNLEFTDIR, 2, 50, false, DEFEND_STRONG)
strongly defend that place up to 2 hexes downward/leftward but in randomly scattered fashion (ignore for now the '50, false').
Why DOWNLEFTDIR? Look at one of the earlier screenshots. The BX Army has reason to believe the VNA (Vietnamese National Army; not NVA!) will come down the waterways to the southwest and attack from that direction. If instead the VNA arrive by paradrop or come overland by way of the roads to the north, _C1_1ST_1ST_RIFLE_COY_48_US_6 might be defending in the wrong direction. But for now, we are willing to take that chance. Substituting NODIR for the defense directionality is something we might do in future. Even having code determining the NVA attack vector dynamically then specifying DOWNLEFTDIR or UPRIGHTDIR as appropriate, that too is possible. But for now, let's KISS this.
As for _MORTAR_10, its separate orders are to
Code: Select all
if not at(_MORTAR_10, objective) then
move_rush(_MORTAR_10, objective, NODIR, 0, 100)
else
fire_indirect_nearest_to_hex(_MORTAR_10, objective, 100, true)
end
If the mortar platoon is not at the objective, they are to move there (no rush!). Otherwise, if a later turn finds them there, they are to fire indirect at any enemy nearest that place.
(As always, for fire_indirect_nearest_to_hex() or any other standard function we use in these examples, refer to Manual/LUA_FUNCTIONS_REFERENCE.txt for more details. In a few cases, the function is not described there; it might be defined and briefly documented in user.lua, which see.)
What if counter_exists() is not true, because the supply unit has been destroyed?
Code: Select all
-- _C1_1ST_1ST_RIFLE_COY_48_US_6 -- C1/1st/1st Rifle Company 48 - US
if counter_exists(_C1_1ST_1ST_RIFLE_COY_48_US_6_POST) then
...
else
defend_weak(units)
fire_indirect_nearest(_MORTAR_10, 100, true)
end
end
In that 'else' case, the infantry units are to weakly defend in place, wherever they stand. And the mortars are to fire indirect at any nearest enemy (nearest to them, wherever they happen to be, not to any specific location).