Earlier, I had written
For the remainder of the scenario, the 1st/22nd & 3rd/22nd continue to assault OBJECTIVES[11] without success. Should we call in airstrikes?
Before now, we had no scripting for airstrikes. The new Enhanced Air Support system was implemented well after this Rung Sat scenario was scripted two or more years ago. It is high time we begin scripting airstrikes!
In my user.lua, I have defined a new function, order_airstrike(), copied below. You don't need to understand how the following code works; you just use it. But for the record:
Code: Select all
-- order_airstrike() -- at actprob chance, from the given aircraft pool, possibly order a randomly selected aircraft to airstrike a randomly selected target hex from the given target list; for non objectives hexes, if verified_only is true, the potential target hex must be spotted
function order_airstrike (trackids, hcs, actprob, verified_only)
...
actprob = actprob or 100
verified_only = verified_only or false
local side = counter_side(trackids[1])
local other = other_side(side)
if chance(actprob) then
local aircraft = UNKNOWN
for i=1, #trackids do -- arbitrary cap on # iterations
local ac = random_pick(trackids)
if not has_flag(counter_more_flags(ac), DROPPEDPAYLOAD) then
aircraft = ac
break
end
end
if (aircraft == UNKNOWN) then return false end
local thc = HEXUNKNOWN
for i=1, #hcs do -- arbitrary cap on # iterations
local hc = random_pick(hcs)
-- enemy-held objectives always okay
if objective_owner(hc) == other then
thc = hc
break
-- if require verification (if verified_only is true), enemy occupied target hex only okay if spotted
elseif verified_only then
if occupied(hc, other) and
has_spotted(hc) then
thc = hc
break
end
-- if don't require verification (if verified_only is false, the default), any target hex okay
elseif not verified_only then
thc = hc
break
end
end
if (thc == HEXUNKNOWN) then return false end
airstrike(aircraft, thc)
return true
end
return false
end
How might we use it?
In VN_550921_Rung_Sat.lua, I have consolidated the many individual aircraft stanzas (created by csmklua.pl)
Code: Select all
-- _DOUGLAS_B26_INVADER_BOMBS_509 -- Douglas B-26 Invader {Bombs}
do local units = _DOUGLAS_B26_INVADER_BOMBS_509
end
-- _DOUGLAS_B26_INVADER_BOMBS_510 -- Douglas B-26 Invader {Bombs}
do local units = _DOUGLAS_B26_INVADER_BOMBS_510
end
...
into one, all-encompassing units list
Code: Select all
local airstrikes = 0
do local units = join({_DOUGLAS_B26_INVADER_BOMBS_509, _DOUGLAS_B26_INVADER_BOMBS_510, _DOUGLAS_B26_INVADER_BOMBS_511, _DOUGLAS_B26_INVADER_BOMBS_512, _DOUGLAS_B26_INVADER_BOMBS_513, _DOUGLAS_B26_INVADER_BOMBS_514, _DOUGLAS_B26_INVADER_BOMBS_515, _DOUGLAS_B26_INVADER_BOMBS_516, _GRUMMAN_F8F_BEARCAT_ROCKETS_503, _GRUMMAN_F8F_BEARCAT_ROCKETS_504, _GRUMMAN_F8F_BEARCAT_ROCKETS_505, _GRUMMAN_F8F_B\
EARCAT_ROCKETS_506, _GRUMMAN_F8F_BEARCAT_ROCKETS_507, _GRUMMAN_F8F_BEARCAT_ROCKETS_508})
if air_support(VNA_SIDE) > airstrikes then
order_airstrike(units, _ASSAULT_HCS_VNA, 75, true) -- or 100?
airstrikes = airstrikes + 1
end
end
airstrikes is a
local variable applicable only in the current battle_plan_a() function call to keep track of the number of airstrikes we have ordered
for this go around. Every time an airstrike is ordered, we increment the airstrikes count by one.
Only if the available air_support() exceeds the airstrikes count do we hand out airstrike orders, i.e., call the order_airstrike() function.
In the example, the hcs input to the order_airstrike() function is _ASSAULT_HCS_VNA. What is that? Something we have set up in the scenario on_hex_assault() trigger function:
Code: Select all
function on_hex_assault (hc, side) -- DO NOT REMOVE
_ASSAULT_HCS_VNA = _ASSAULT_HCS_VNA or {}
if side == VNA_SIDE then
_ASSAULT_HCS_VNA[#_ASSAULT_HCS_VNA+1] = hc
end
end
Every time a hex is assaulted, for the VNA_SIDE only (since only they have aircraft), we add the assault hc to the _ASSAULT_HCS_VNA list.
After the first VNA assault, for example at hex 45,42, we might have this:
rober@Rob10rto /cygdrive/c/Games/Matrix Games/Vietnam/vietnam
$ egrep _ASSAULT_HCS_VNA 'VN_550921_Rung_Sat TEST TRIAL.btl'
l
_ASSAULT_HCS_VNA:{"45,42"}
(Note that since _ASSAULT_HCS_VNA
is a global variable, it is saved in the scenario .btl file. We can inspect its value, if we wish, in the manner shown.)
After a second assault, for example at hex 42,55, we might then have this:
rober@Rob10rto /cygdrive/c/Games/Matrix Games/Vietnam/vietnam
$ egrep _ASSAULT_HCS_VNA 'VN_550921_Rung_Sat TEST TRIAL.btl'
l
_ASSAULT_HCS_VNA:{"45,42","42,55"}
And so on.
Some ways into the scenario, we might have:
rober@Rob10rto /cygdrive/c/Games/Matrix Games/Vietnam/vietnam
$ egrep _ASSAULT_HCS_VNA 'VN_550921_Rung_Sat TEST TRIAL.btl'
l
_ASSAULT_HCS_VNA:{"45,42","42,55","53,37","42,55","42,55","42,55","42,54","44,51","49,54","49,54","49,54","49,54","49,54"}
Among those 13 recorded assaults:
- hex 45,42 was assaulted once, 1 in 13
- hex 42,55 was assaulted 4 times out of 13
- hex 53,37 was assaulted once, 1 in 13
- hex 42,54 was assaulted once, 1 in 13
- hex 44,51 was assaulted once, 1 in 13
- hex 49,54 was assaulted 5 times out of 13
Evidently hexes 42,55 (4 out of 13) and 49,54 (5 out of 13) were tough, repeated assaults, while the others were all easily taken on a single assault attempt. Where should we prioritize assigning airstrikes? To the tough cases, of course.
In order_airstrike(), we prioritize the tough cases by means of the random_pick() call:
Code: Select all
for i=1, #hcs do -- arbitrary cap on # iterations
local hc = random_pick(hcs)
...
thc = hc [hc is the designated target, maybe]
...
end
In other words, the more times an assault hex appears in the _ASSAULT_HCS_VNA list, the more likely it will be targeted.
But only if it is an enemy-held Objective, or is verified enemy occupied, or we don't care about verification so target the first randomly picked hex from the list. (See the order_airstrike() function definition above for details.)
If an assault hex is a friendly held Objective and/or is friendly occupied, we don't target it for airstrikes if the verified_only input is set to 'true' -- probably a good idea always.
Earlier in the order_airstrike() function, we randomly select an aircraft from the trackids input but only if it has not DROPPEDPAYLOAD.
If we don't have a suitable aircraft and/or we don't have a suitable target hex, the order_airstrike() function
Code: Select all
...
if (aircraft == UNKNOWN) then return false end
...
if (thc == HEXUNKNOWN) then return false end
...
returns 'false', there is no ordered airstrike.
Otherwise
we order the airstrike by means of the standard CSEE airstrike() function, but
Code: Select all
function order_airstrike (trackids, hcs, actprob, verified_only)
...
if chance(actprob) then
[maybe order an airstrike, maybe not; if so return true]
end
return false
end
only if 'chance(actprob)' is true.
In the scenario Lua script, we have
Code: Select all
order_airstrike(units, _ASSAULT_HCS_VNA, 75, true) -- or 100?
which is to say maybe order an airstrike
- from among the available, suitable (not yet dropped payload) aircraft
- target a suitable assault hex (not yet friendly occupied, verified only)
- at only 75% chance of considering it anyway
Whew! That's complicated! Again:
You don't really need to understand the gory details, just make use of the functions and techniques.
Does this too work?