Add Review
Subscribe
Nominate
Submit Media
RSS
Taret Blade Development Diary - Chapter 2: Intelligent Artificing
Shadowtext- 12/09/2007 12:25 PM
- 491 views
I got back to work on Taret Blade for the first time in forever today. Today's focus was Artificial Intelligence. I already had pathfinding taken care of, so this part is just figuring out how enemies and neutrals (and maybe AI-allies) will decide to move.
Determining the Target
The first thing I decided was that units were going to have to have a limit to how far ahead they could think. I figured that they would need to have an opponent within a certain range to even bother trying to attack. The range would be based on the unit's movement range, and expand depending whether the AI was set to offensive, defensive or cowardly.
I was trying to figure out how to let them decide what the best target would be. I considered having the enemy measure the unit's stats or abilities....but since I'm not using traditional levelling, that could be quite a challenge. Luckily, an idea presented itself.
I was never that into Final Fantasy 11, but I did play for a while, and a concept that I picked up from playing it was "Hate." The actions a character take adds to a hidden hate meter, and enemies would go after whoever had the most hate. Different actions drew different amounts of hate based on how dangerous they were to the enemy. Healers were considered among the most dangerous, for example, because they kept the party going. It's a great little concept, and I decided to steal it.
So here's how it works in Taret Blade: each unit has a "hate" variable. It's a simple integer that starts at zero. Each action has a "hate" stat as well, and when the unit uses the action, that action's hate stat is added to the unit's hate variable. Thus, hate increases every time the hero takes an action.
I figured that it'd be good to also have hate constantly deplete, so I set up a constant HATE_DECAY_RATE and decrease the unit's Hate by that amount each turn, to a minimum of zero. For now I'll set HATE_DECAY_RATE to 1, but that's an arbitrary amount and will likely change during play testing.
So here's what happens:
1.) The AI unit determines which units are in its "awareness range."
2.) It checks which faction each of these units belongs to.
3.) If it's an enemy faction, the unit is added to an array of targets.
4.) The array is sorted by each unit's Hate level, highest to lowest.
5.) The AI determines if it can attack any of the units on the array this turn, and if so, targets whichever one of these has the highest Hate.
6.) If there is no enemy unit in attack range, the AI moves to the point nearest its most hated enemy.
7.) The AI checks to see if it has any buffs it can cast on itself.
8.) If not, it defends.
There'll probably also be a rule that takes precedence stating that if the AI can heal itself and its HP is below a certain threshold, it will do that instead, and move as far away from all enemies as possible.
Multiple Targets
I don't know exactly how I'm going to handle this just yet. It'd be a lot easier to just have the most hated enemy get targetted and then figure out if there's a way to hit any other enemies at the same time....the other option trying to figure out what combinations are available and which ones have the highest combined Hate, which would be processor intensive and also potentially brain melting.
Factions
I mentioned this earlier, so I thought I'd cover what it meant. There are several factions in the game, each with an entry in the Faction database. Each unit has a faction that it belongs to, and its faction determines whether other units are enemies, allies, or neutrals to it.
While each faction has some flavor text associated with it, as far as system stuff goes the Faction object is just an object that has an array with a value for each of the factions (including itself, though this value is mostly ignored), and this value can be FTUDE_FRIENDLY, FTUDE_NEUTRAL, or FTUDE_AGGRESSIVE. I'll let you guess what these constants signify.
Of course this just determines who will be attacked, not how they'll be attacked. I'll cover that next time.
Determining the Target
The first thing I decided was that units were going to have to have a limit to how far ahead they could think. I figured that they would need to have an opponent within a certain range to even bother trying to attack. The range would be based on the unit's movement range, and expand depending whether the AI was set to offensive, defensive or cowardly.
I was trying to figure out how to let them decide what the best target would be. I considered having the enemy measure the unit's stats or abilities....but since I'm not using traditional levelling, that could be quite a challenge. Luckily, an idea presented itself.
I was never that into Final Fantasy 11, but I did play for a while, and a concept that I picked up from playing it was "Hate." The actions a character take adds to a hidden hate meter, and enemies would go after whoever had the most hate. Different actions drew different amounts of hate based on how dangerous they were to the enemy. Healers were considered among the most dangerous, for example, because they kept the party going. It's a great little concept, and I decided to steal it.
So here's how it works in Taret Blade: each unit has a "hate" variable. It's a simple integer that starts at zero. Each action has a "hate" stat as well, and when the unit uses the action, that action's hate stat is added to the unit's hate variable. Thus, hate increases every time the hero takes an action.
I figured that it'd be good to also have hate constantly deplete, so I set up a constant HATE_DECAY_RATE and decrease the unit's Hate by that amount each turn, to a minimum of zero. For now I'll set HATE_DECAY_RATE to 1, but that's an arbitrary amount and will likely change during play testing.
So here's what happens:
1.) The AI unit determines which units are in its "awareness range."
2.) It checks which faction each of these units belongs to.
3.) If it's an enemy faction, the unit is added to an array of targets.
4.) The array is sorted by each unit's Hate level, highest to lowest.
5.) The AI determines if it can attack any of the units on the array this turn, and if so, targets whichever one of these has the highest Hate.
6.) If there is no enemy unit in attack range, the AI moves to the point nearest its most hated enemy.
7.) The AI checks to see if it has any buffs it can cast on itself.
8.) If not, it defends.
There'll probably also be a rule that takes precedence stating that if the AI can heal itself and its HP is below a certain threshold, it will do that instead, and move as far away from all enemies as possible.
Multiple Targets
I don't know exactly how I'm going to handle this just yet. It'd be a lot easier to just have the most hated enemy get targetted and then figure out if there's a way to hit any other enemies at the same time....the other option trying to figure out what combinations are available and which ones have the highest combined Hate, which would be processor intensive and also potentially brain melting.
Factions
I mentioned this earlier, so I thought I'd cover what it meant. There are several factions in the game, each with an entry in the Faction database. Each unit has a faction that it belongs to, and its faction determines whether other units are enemies, allies, or neutrals to it.
While each faction has some flavor text associated with it, as far as system stuff goes the Faction object is just an object that has an array with a value for each of the factions (including itself, though this value is mostly ignored), and this value can be FTUDE_FRIENDLY, FTUDE_NEUTRAL, or FTUDE_AGGRESSIVE. I'll let you guess what these constants signify.
Of course this just determines who will be attacked, not how they'll be attacked. I'll cover that next time.










