Jump to content

Recommended Posts

Posted (edited)

I came up with this to serve as a temporary solution to how the AI reacts. It will come down to what is more important for your mission, do you have to see the bombers dropping their bombs and shooting back at the fighters, or do you want them to stay in formation. With the AI programmed the way they are, you have to choose which works best for you.

 

For this to work, you have to disable the offensive and defensive abilities of the bomber (set up a single aircraft in the group, this is so you can create custom formations with the following command).

 

Screen_160607_053340_zpsv2scm905.jpg~original

 

 

The code for the bombing is really quite simple. I had initially stripped down and reworked the flak script to create it, but looking at the results, would have been simpler to just do it directly. Had I been more of a coder, would have realised this from the start:

 

Carpet bombing script:

 

--[[
Script: Modified flakv3_2.lua to simulate carpet bombing
Author: Stonehouse of RAAF No457 vSQD - Carpet bombing modifications by Shahdoh
Date: 27/02/2015
Prerequisites: 
*Mistv3.3a or higher must be loaded prior to this script being used.
*The script must be loaded prior to any of the functions being run. ie ensure that Mist and this script is loaded before any carpet bombing is triggered
*Load on a MISSION START trigger using DO SCRIPT FILE 

Update log:


--]]
do
--global constants
cbDmg = 500
--100 strength explosive to represent 250 lb bomb


--[[
Name: cBomb
Parameters: 
_parm1 = the name of the associated trigger zone for the bomber.  Valid values are the name of the zone exactly as it appears in the ME

Example of usage: 

Do
cBomb('Allied_BG1_001')
End


--]]

function cbomb(cbparm1)
	local cbpos = Unit.getByName(cbparm1):getPosition().p  

	--get a random point in the zone 
	local cbnewpoint = mist.getRandPointInCircle(cbpos, 50) 

	--taking into account terrain height generate a vec3 position at the random point in the zone at a random altitude 
	local nvec3 = { 
	x = cbnewpoint.x, 
	y = land.getHeight(cbnewpoint), 
	z = cbnewpoint.y 
	} 

	-- create a single explosion at the position 
	trigger.action.explosion(nvec3, cbDmg)
end


end --script

 

 

It simply tracks the location of the aircraft, once it is in a designated trigger area, gets its position, randomizes it a small bit for bomb floating around due to winds or whatever, and then creates the explosion on the ground. This is setup on each individual bomber so that if that bomber is destroyed or diverted even, it wont be in the trigger area and thus, no "bombs" dropped. Only creates explosions for the bomber that is in the zone. 1 bomber, 1 series of explosions, 30 bombers, 30 sets of explosions, roughly, but directly linked, to the location of those bombers.

 

If you are concerned about the number of bombs per bomber, adjust the size of your trigger area with the airspeed you have the bombers set to, so that the number of seconds inside the trigger area matches the loadout of the bomber. Crude, yes but it works.

 

For the bombers defense, I again reworked the flak script so that a moving trigger area follows the bomber, currently set at 300m. When the enemy a/c gets inside that zone, it randomizes a chance to hit, currently set to 2.5%(checks on the standard timing of 1 per second). When it does, creates a minimized flak explosion in a random location around the fighter, intended to only pepper the fighter with damage. When the fighter gets within 100m, the chance goes up to 4%. I used the ability to allow for multiple guns per bomber, just like the number of flak guns on the ground, but in testing, even just 1 at that low percent chance to hit is quite effective.

 

This bubble is around each and every bomber, thus have the bombers in a good formation, and they will protect each other, get one separated and it becomes easier prey.

 

Bomber Defense script:

 

do
--global constants
--1 strength explosive to represent 50 cal guns hitting target
_BDDmg = .75
_maxRng = 300 --max effective range is 500m

--[[
Name: bdGuns
Parameters:
_bdparm1 = the side to be attacked by the bombers defensive guns. Valid values are red or blue 
_bdparm2 = the name of the associated moving unit being defended by the guns. Valid values are the name of the unit exactly as it appears in the ME
_bdparm3 = number of guns between 1 and 4 (that can be directed to any 1 position around the aircraft)

Example of usage: 

Do
bdGuns('blue','Unit #01',2)
End


--]]
function bdGuns(_bdparm1, _bdparm2, _bdparm3)

	--parameters 
	local _bdside = _bdparm1-- eg 'blue'
	local _bdUnit = _bdparm2 -- eg 'Unit #01'
	local _bdnumofguns = _bdparm3 -- eg integer value like 2 or 3

	-- init table
	local bdsidePlanes = {}


	--set number of guns to 1 if less than zero passed in.
	if ((_bdnumofguns < 1) or (_bdnumofguns == nil)) then 
		_bdnumofguns = 1 
	end

	--set number of guns to 4 if more than 4 passed in. Forcing max of 4 guns per trigger action
	if _bdnumofguns > 4 then 
		_bdnumofguns = 4 
	end

	-- get units for side 
	if _bdside == 'red' then 
		bdsidePlanes = mist.makeUnitTable({'[red][plane]','[red][helicopters]'}) 
	else
		bdsidePlanes = mist.makeUnitTable({'[blue][plane]','[blue][helicopters]'}) 
	end --get side

	-- set up table entry for defense zone
	local _BDunits = {}
	_BDunits[1] = _bdUnit

	-- get the target units in the defense zone
	local bdinZoneUnits = mist.getUnitsInMovingZones(bdsidePlanes, _BDunits, _maxRng, 'sphere') 
	local bdinZoneUnitsClose = mist.getUnitsInMovingZones(bdsidePlanes, _BDunits, 100, 'sphere') 


	-- for each target
		if (#bdinZoneUnits > 0) then
			for x = 1, _bdnumofguns do
			local hitchance = mist.random(1,1000)
--        trigger.action.outText('Hitchance: '..hitchance..' from: '.._bdUnit, 5)
			
				if (#bdinZoneUnitsClose > 0) and hitchance < 40 or hitchance < 25 then
			
		--get target aircraft
				local c = mist.random(1,#bdinZoneUnits)
		-- get current position 
				local _bdtargetpos = bdinZoneUnits[c]:getPosition().p
				local bdnewpoint = mist.getRandPointInCircle(_bdtargetpos, 7, 3) 
				local bdvec3 = { 
				x = bdnewpoint.x, 
				y = _bdtargetpos.y, 
				z = bdnewpoint.y 
				} 
		-- explode the shell, strength of attack between 1 and max damage (throwing some luck into the mix)
					trigger.action.explosion(bdvec3, _BDDmg)
				end	
			end --for loop
		end --units exist in zone
end --bdGuns

end --script

 

 

These both set up in the Mission editor like setting up the flak areas, examples are in the code remarks.

 

Video of this in action:

 

 

Will be using these in my WWII campaign idea: http://forums.eagle.ru/showthread.php?t=167940

 

/Salute

Edited by Shahdoh
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...