Welcome to Unknown Horizons

Aug 13, 2012

Combat AI Update part 3


Category:Coding Summer of Code 
Posted by: kiryx

Hello everyone!

Welcome back to the last part of my combat AI update. I hope you've enjoyed it so far.
I already talked briefly about the need to have some sort o communication between the two main situation detectors - CombatManager and StrategyManager. After all, both of the components indirectly operate on the same set of ships. We had to make sure that they don't accidentally step on each other's toes. Again, there's more than one way to do this, here's what seems to work well:
Let's first introduce states each ship can take:
  1. 'idle'
  2. 'on_a_mission'
Idle ships are handled by CombatManager, so any free wandering pirate that is hostile, will be attacked by an idle ship (thanks to CombatManager). Ships on a mission are usually already being taken care of by StrategyManager, so it's worth noting who has the upper hand in case of idle ships:
We assume StrategyManager is privileged to any idle ship, so he can create missions and use said ships to form a fleet. In that case CombatManager can no longer use them.
CombatManager's work isn't done here. It scans the environment around ships on a mission as well, but he can't take action directly. What he does is request StrategyManager to pause given mission. This way we assure that our fleet isn't indifferent to enemies shooting at it, just because StrategyManager decided to send it on a peaceful scouting trip. In order to make pausing possible we had to model every mission as a finite state machine (I had it easy since gscai's did that last year). Which later proved to be useful when writing saving/loading for each mission.

Example scenario

Let's look at the scenario below:
Two AI players (AI-1 - red, AI-2 - blue) share the same island. StrategyManager checks for such conditions, so as soon as any ships are available, it will create a mission to attack the enemy.
Circles around each fleet (in this case single ships) is the range in which CombatManager "sees" things. Each player does not notice each other just yet.
After a while, ships get close enough for CombatManager's to take the handles. Notice that the ship on the right reacted first - it is because CombatManager does not scan the world every game tick, but every N ticks. To avoid lag spikes, CombatManagers are desynchronized, thus red player happened to respond earlier.
Since ships were on a mission, each CombatManager has to request StrategManager to pause current mission in order to resolve unexpected combat along the way.
Both StrategyManagers agree to pause the mission, the combat begins.
Combat ends when CombatManager can't see any ships around anymore (i.e. enemy fled, or was destroyed). In this case blue player won the skirmish. Mission is resumed to previous state for AI-2 and canceled for AI-1 since all of the fleet ships were destroyed. AI-2 continues the mission.

Summary

Currently the whole architecture and communication between components is done. Early on I divided my work into modeling flow, Component's interface etc., and the real AI work which is putting knowledge into the whole system.
Currently I'm working on new Conditions and BehaviorComponents to make things more interesting.
I can't wait to have it merged eventually and get your feedback ;)
Bye!
 
Add a comment for this news:
Comment Title:

Your Name:

Your Email Address:

Additional Comments: