Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Missile Raid function

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Missile Raid function Page: [1]
Login
Message << Older Topic   Newer Topic >>
Missile Raid function - 10/12/2019 12:20:45 AM   
SeaQueen


Posts: 1136
Joined: 4/14/2007
From: Washington D.C.
Status: offline
I've often been frustrated with how using missions on the computer controlled side for GLCMs and TBMs tends to result in overly conservative raids, because the AI tends to try to allocate weapons efficiently. The problem with this is that in order for a raid to be successful, you often want to build a certain amount of overkill in to account for interceptors. In order to solve that problem, I wrote this code. It allows the computer controlled side to easily follow a specific raid schedule (e.g. at time X fire Y at Z). The rest of the code I posted in this thread is an example of how I might use it notionally to model a coordinated strike by PLAAF/PLARF forces on Guam. In practice, it would have to be customized to your particular scenario. The important take away is less the specific code and more the technique.

-- returns the contact id of a unit whose guid is known
-- use of this function avoids the need to shoot work off the contact list which is dynamic and makes it 
-- hard to bake in fire plans
function getContactIdOfUnit( sd, unitId )
  local contactList = ScenEdit_GetContacts(sd)
  local unitContactId
  for i, con in ipairs( contactList ) do
    local cnt = ScenEdit_GetContact({side=sd, guid=con.guid})
    if (cnt.actualunitid == unitId) then
        unitContactId = cnt.guid
      break
    end
  end
  return unitContactId 
end

-- launches a raid with the "participatingUnits" firing a defined salvo size at "targetList."
-- "participatingUnits" and "targetList" are just lists of guids for the shooters and targets, respectively
function missileRaid( side, participatingUnits, targetList, wpnId, salvoSize )
  local tgtContactId 
  for i, u in ipairs( participatingUnits ) do
    local attacker = ScenEdit_GetUnit( {guid=u} )
    for j, tgt in ipairs( targetList ) do
      tgtContactId =  getContactIdOfUnit(side, tgt)
      if ( tgtContactId  ~= nil ) then   -- accounts for targets not on the contact list
        for k, mnt in ipairs( attacker.mounts ) do        
          for l, wpn in ipairs( mnt.mount_weapons ) do           
             if ( wpn.wpn_dbid == wpnId ) then 
               if ( wpn.wpn_current > 0 ) then 
                  ScenEdit_AttackContact(attacker.guid, tgtContactId, {mode='ManualWeaponAlloc', mount=mnt.mount_dbid, weapon=wpnId, qty=salvoSize  })
               end
            end
          end
        end
      end
    end
  end
end


< Message edited by SeaQueen -- 10/18/2019 1:57:10 PM >
Post #: 1
RE: Missile Raid function - 10/12/2019 11:29:25 AM   
SeaQueen


Posts: 1136
Joined: 4/14/2007
From: Washington D.C.
Status: offline
To be used with the above functions, I wrote this code which sets the firing time for Time Triggers. I'd run this at scenario load in order to ensures that the right number of TBM/GLCMs get fired at the right time:

I could probably modify the code to use for ALCMs/SLCMs but I'd have to take into account the position of the launch platform somehow since they move. If I did it that way, then I could have them fly or sail out to their launch baskets and fire at a specific time for coordination purposes. I need to think about that one more. I also included a "rolex" variable to add an arbitrary time offset to the whole war. I don't use it at this point, but someday I might.

-- scenario timing constants

oneMinute = 60
fiveMinutes = 5 * oneMinute
fifteenMinutes = 15 * oneMinute
oneHour = 60*oneMinute 
threeHours = 3 * oneHour
sixHours = 6 * oneHour
oneDay = 24*oneHour 

-- randomizes time on target so that I don't know exactly when the raid will come
mainStrikeMedianTimeOnTarget = os.time{ year=2020, month=6, day=21, hour=14, min= 00, sec=0 }
rolex = 0


-- the +/- three hours ensures the strike will occur within a 6 hour launch window.  It could be whatever you want.
mainStrikeTimeOnTarget = mainStrikeMedianTimeOnTarget  + math.random( (-1*threeHours) , threeHours ) + rolex

-- typically I'll put this code in a separate LUA action, just for modularity, but there's no reason it can't
-- be in the same as the above code it just depends on how you roll.

-- SEAD dedicated strikes will arrive on target five minutes prior to the main strike (480 kts * 5 min = 40 Nmi)

local seadTimeOnTarget = mainStrikeTimeOnTarget - fiveMinutes 

-- andersenAFB is just the guid of the target for that portion of the raid, it could be anywhere.  I just used
-- andersen because I developed the code for a Guam raid scenario.  Change as it suits your purposes.  
-- Similarly, "firstBnFirstBgd," "secondBnFirstBgd," etc. are set to guids of TBM battalions

local distanceFromFirstBnFirstBgdToAndersen = Tool_Range( firstBnFirstBgd , andersenAFB)
local distanceFromFirstBnSecondBgdToAndersen = Tool_Range( firstBnSecondBgd , andersenAFB)

local distanceFromSecondBnFirstBgdToAndersen = Tool_Range( secondBnFirstBgd , andersenAFB)
local distanceFromSecondBnSecondBgdToAndersen = Tool_Range( secondBnSecondBgd , andersenAFB)

local missileSpeed = 7500 

local missileFirstBnFirstBgdFlyoutTime = (distanceFromFirstBnFirstBgdToAndersen / missileSpeed ) * oneHour
local missileFirstBnSecondBgdFlyoutTime = (distanceFromFirstBnSecondBgdToAndersen / missileSpeed) * oneHour

local missileSecondBnFirstBgdFlyoutTime = ( distanceFromSecondBnFirstBgdToAndersen / missileSpeed ) * oneHour
local missileSecondBnSecondBgdFlyoutTime = ( distanceFromSecondBnSecondBgdToAndersen / missileSpeed) * oneHour

local tbmFirstBnFirstBgdSeadMissionStartTime = seadTimeOnTarget - missileFirstBnFirstBgdFlyoutTime 
local tbmFirstBnSecondBgdSeadMissionStartTime = seadTimeOnTarget - missileFirstBnSecondBgdFlyoutTime

local tbmSecondBnFirstBgdMainStrikeMissionStartTime = mainStrikeTimeOnTarget - missileSecondBnFirstBgdFlyoutTime 
local tbmSecondBnSecondBgdMainStrikeMissionStartTime = mainStrikeTimeOnTarget - missileSecondBnSecondBgdFlyoutTime

local tbmFirstBnFirstBgdSEADMissionTrigger = ScenEdit_GetEvent('Launch Northern TBM SEAD Raid', 2)
local tbmFirstBnSecondBgdSEADMissionTrigger = ScenEdit_GetEvent('Time For Southern TBM Raid - SEAD Wave', 2)

local tbmFirstBnFirstBgdSEADMissionEvent = ScenEdit_GetEvent('Launch Southern TBM SEAD Raid', 1)
local tbmFirstBnSecondBgdSEADMissionEvent = ScenEdit_GetEvent('Launch Northern TBM SEAD Raid', 1)

local tbmSecondBnFirstBgdMainMissionEvent = ScenEdit_GetEvent('Launch Southern TBM Main Raid', 1)
local tbmSecondBnSecondBgdMainMissionEvent = ScenEdit_GetEvent('Launch Northern TBM Main Raid', 1)

local tbmFirstBnFirstBgdSEADMissionTriggerID =  tbmFirstBnFirstBgdSEADMissionEvent.details.triggers[1].Time.ID
local tbmFirstBnSecondBgdSEADMissionTriggerID =  tbmFirstBnSecondBgdSEADMissionEvent.details.triggers[1].Time.ID
local tbmSecondBnFirstBgdMainMissionTriggerID =  tbmSecondBnFirstBgdMainMissionEvent.details.triggers[1].Time.ID
local tbmSecondBnSecondBgdMainMissionTriggerID = tbmSecondBnSecondBgdMainMissionEvent.details.triggers[1].Time.ID

ScenEdit_SetTrigger( {Description=tbmFirstBnFirstBgdSEADMissionTriggerID,  Time=os.date('%m/%d/%Y %I:%M:%S %p', tbmFirstBnFirstBgdSeadMissionStartTime )    } )
ScenEdit_SetTrigger( {Description=tbmFirstBnSecondBgdSEADMissionTriggerID ,  Time=os.date('%m/%d/%Y %I:%M:%S %p', tbmFirstBnSecondBgdSeadMissionStartTime )    } )

ScenEdit_SetTrigger( {Description=tbmSecondBnFirstBgdMainMissionTriggerID  ,  Time=os.date('%m/%d/%Y %I:%M:%S %p', tbmSecondBnFirstBgdMainStrikeMissionStartTime )    } )
ScenEdit_SetTrigger( {Description= tbmSecondBnSecondBgdMainMissionTriggerID ,  Time=os.date('%m/%d/%Y %I:%M:%S %p', tbmSecondBnSecondBgdMainStrikeMissionStartTime )    } )


Not sure this is displayed correctly.

< Message edited by SeaQueen -- 10/12/2019 3:44:44 PM >

(in reply to SeaQueen)
Post #: 2
RE: Missile Raid function - 10/12/2019 11:39:19 AM   
SeaQueen


Posts: 1136
Joined: 4/14/2007
From: Washington D.C.
Status: offline
Not displaying correctly...

< Message edited by SeaQueen -- 10/12/2019 1:01:19 PM >

(in reply to SeaQueen)
Post #: 3
RE: Missile Raid function - 10/12/2019 11:40:37 AM   
SeaQueen


Posts: 1136
Joined: 4/14/2007
From: Washington D.C.
Status: offline
Definitely not displayed correctly...

(in reply to SeaQueen)
Post #: 4
RE: Missile Raid function - 10/12/2019 1:01:40 PM   
SeaQueen


Posts: 1136
Joined: 4/14/2007
From: Washington D.C.
Status: offline
Finally, the Time trigger (in this case 'Launch Southern TBM Main Raid') fires a LUA action similar to this:

"andersenRnwys" and "andersenFuel" are just arrays of guids containing the target set.

local mainStkRnwyShooters = { secondBnSecondBgd }  
local mainStkFuelShooters = { thirdBnSecondBgd,  fourthBnSecondBgd}  

-- shoots a salvo of 2 per target at the runways
missileRaid('CHN', mainStkRnwyShooters, andersenRnwys, df26Id, 2)

-- shoots a salvo of 1 per target at the POL storage facilities
missileRaid('CHN', mainStkFuelShooters, andersenFuel, df26Id, 1)


< Message edited by SeaQueen -- 10/12/2019 4:19:25 PM >

(in reply to SeaQueen)
Post #: 5
RE: Missile Raid function - 10/12/2019 2:19:27 PM   
KnightHawk75

 

Posts: 198
Joined: 11/15/2018
Status: offline
Good stuff.

(in reply to SeaQueen)
Post #: 6
RE: Missile Raid function - 10/12/2019 2:54:08 PM   
SeaQueen


Posts: 1136
Joined: 4/14/2007
From: Washington D.C.
Status: offline
This code sets the mission start times for the ALCM equipped bombers so that it's automatically coordinated with the TBM raid. Typically I would run this at scenario load as well, so that everything gets aligned from the start.

-- SEAD dedicated strikes will arrive on target five minutes prior to the main strike (480 kts * 5 min = 40 Nmi)
-- note these mission start times hang off the mainStrikeTimeOnTarget calculated in the earlier code

local seadTimeOnTarget = mainStrikeTimeOnTarget - fiveMinutes 

local distanceFromLeiyangToAndersen = Tool_Range(leiyangAB, andersenAFB)
local distanceFromLeiyangToKD20LaunchBasket = distanceFromLeiyangToAndersen - kd20Range

local aircraftSpeed = 420 -- knots
local kd20speed = 500 -- knots
local aircraftFlyoutTime = ( distanceFromLeiyangToKD20LaunchBasket / aircraftSpeed ) * oneHour -- conversion factor applied (hours to seconds)
local kd20FlyoutTime = ( kd20Range / kd20speed ) * oneHour -- conversion factor applied (hours to seconds)

local H6KSeadMissionStartTime = seadTimeOnTarget - ( aircraftFlyoutTime + kd20FlyoutTime )
local H6KMainStrikeMissionStartTime = mainStrikeTimeOnTarget -  ( aircraftFlyoutTime + kd20FlyoutTime )

local H6KSeadMission = ScenEdit_GetMission('CHN', 'SEAD Strike (H6K)')
ScenEdit_SetMission('CHN', H6KSeadMission.guid,  {starttime=os.date('%m/%d/%Y %I:%M:%S %p',H6KSeadMissionStartTime)})

local H6KOpenedParkingStrikeMission = ScenEdit_GetMission('CHN', 'Strike - Opened Parking (H6K)')
ScenEdit_SetMission('CHN', H6KOpenedParkingStrikeMission.guid,  {starttime=os.date('%m/%d/%Y %I:%M:%S %p',H6KMainStrikeMissionStartTime)})


< Message edited by SeaQueen -- 10/13/2019 12:59:12 PM >

(in reply to SeaQueen)
Post #: 7
RE: Missile Raid function - 10/12/2019 3:18:06 PM   
Whicker

 

Posts: 644
Joined: 6/20/2018
Status: offline
if you put it in a quote it will work - for some reason the code tag has max height so it gets screwed up like that.

(in reply to SeaQueen)
Post #: 8
RE: Missile Raid function - 10/12/2019 3:21:28 PM   
SeaQueen


Posts: 1136
Joined: 4/14/2007
From: Washington D.C.
Status: offline
Fixed it.

(in reply to Whicker)
Post #: 9
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Missile Raid function Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.133