Per advice from the Doctor (Professor Samuel Joseph), I plan on using a simplified approach. This routine utilizes a simplified grading method based on distance and bearing and a fuzzy logic selection method. Each enemy object is given a grade with the top five targets going into a target list. Each target in the list is weighted in favor of the top target, and a target is randomly selected from this list.
Here's the outline:
1.
Initialize global variables
a.
Set up flight variables
i. Set
up the transform variable (vTrans)
ii. Set
up the FlightControl variable (vFlightControl)
iii. Set
up a update variable (vNextUpdate)
iv. Set
up mission target
v. Set
up current target as null
b.
Set up weapon variables
i. Set
up a max ammo variable (vMaxAmmo)
ii. Set
up a gun burst variable (vBurst)
2.
Flight control AI
a.
If fighter has sufficient fuel (less than 10%
fuel), has ammo and is combat capable (greater than 25% structure remaining)
execute maneuvering routines.
i. Iterate
through all targets in the DradisList
1.
Check for collision zones
2.
Catalogue eligible targets into a target list
(limited to five targets) using range and direction parameters
ii. If
the fighter is in a collision zone or if there is a collision alert via
raycasting in front of the ship
1.
Execute avoidance routines
2.
End loop
iii. Target
selection
1.
If the target list is empty
a.
Check for a mission target; set mission target
as current target
2.
If the target list is not empty
a.
Calculate probability baseline by adding an
iteration of the targets in the target list (5+4+3+2+1 = 15).
b.
Generate a random number based on baseline
number (1-15)
c.
Calculate number of item selected by iterating
through the number of targets in the target list (1-5 = 1, 6-10 = 2, etc…)
d.
Make the target associate with calculated number
the current target
iv. Maneuver
the ship
1.
If there is a current target
a.
Get the distance from current target
b.
Get the size of the current target
c.
Set an disengagement distance as size * 50
d.
If ship is within the disengagement distance
i. Set
disengagement flag as true
e.
If disengagement flag is true
i. Move
away from target
ii. If
distance is twice the disengagement distance then set disengagement flag to
false
f.
Otherwise move towards the current target
2.
Otherwise return to base
b.
Return to base
i. If
home base is null
1.
Find the closest friendly carrier ship
2.
Set home base to found ship
ii. If
home base is still null
1.
Slow to zero by applying inertial dampeners
2.
Wait for something to change
iii. Otherwise
1.
Get closest landing zone
2.
Set approach point as closest landing zone
3.
If final point is null
a.
Move towards approach point
b.
If distance to approach point is less than 50
i. get
final point
ii. deploy
landing gears
4.
Otherwise
a.
Move towards final point
b.
If distance is less than 50 to final point
i. Apply
inertial dampeners
ii. Set
landed timer to current time plus five seconds
c.
If landed timer is greater than zero
i. If
landed timer is greater than current time
ii. Remove
ship from game
3.
Fire control AI routines
a.
For gun controls
i. Get
closest friendly target within firing parameters (range and direction)
ii. If
friendly target exists don’t fire
iii. Otherwise
1.
Get the closest enemy target within firing
parameters (range and direction)
2.
If there is an eligible target
a.
If firing timer is greater than current time
i. Fire
the guns
ii. Set
firing timer to ammo rate to current time
iii. Add
one to burst fire variable
iv. If
burst fire is equal to or greater than maximum burst
1.
Set firing timer to current time plus three
seconds
2.
Set burst fire to zero
b.
Otherwise reduce burst fire by one if burst fire
is greater than zero
b.
For missiles
i. If
missile target is null
1.
If mission target is eligible for lock (bearing
and distance)
a.
If lock target is null
i. Set
lock target to mission target
ii. Set
lock timer to current time plus three seconds
b.
If lock timer is less than current time
i. Set
missile target to lock target
ii. Set
lock target to null
2.
Otherwise if current target is eligible for lock
a.
If there is no mission target and current target
is eligible for lock
i. If
lock target is null
1.
Set lock target to current target
2.
Set lock timer to current time plus three seconds
ii. If
lock timer is less than current time
1.
Set missile target to lock target
2.
Set lock target to null
ii. Otherwise
1.
If missiles are available (timer check and
missile capacity)
a.
Fire missile at missile target
This is just a preliminary routine, and I'll probably have to polish it. The current plan is to place these update routines in the FixedUpdate() section. FixedUpdate() updates ten times a second in the current setup; Update() updates every frame. FixedUpdate() should minimize the resource usage and make the fighters fly smoother. It will also allow for the careful control of the burst fire feature for the fighter's guns.Like I said, it is a simple routine. As the game progresses, I'll add routines and complexity on top of this routine. Or, I'll replace it completely in future prototypes. I'm on prototype two; prototype three might see a departure from this set up.
Got the target selection done. The routine now generates a list and selects a target based on a random value. It keeps that target for three seconds before looking for a new target. Three seconds is a default value and can (will) be changed by placing a value into the UpdateInterval method.
ReplyDeleteManuevering the ship is up next. I'm skipping the avoidance routine for right now; that part is going to be headache. I'll wait until I have a function movement system before tackling it.
It shoots and evades. Now, I just got to get it run away when it takes too much damage.
ReplyDeleteI just need to the missile firing procedures and the escape routines. Everything else seems to be working...
ReplyDelete