| 11-30-2002, 09:54 PM | #1 |
JonahDean, did you have any success in improving the AI staying/fleeing behaviour in fights ? |
| 11-30-2002, 11:55 PM | #2 |
Guest | Well, unfortunately, I was never able the code to actually make the attack group to flee work right. The code telling them WHEN to flee goes off without a hitch, though right now it's simply tied to the average HP % of the group using CaptainReadiness(). The actual fleeing part I still haven't gotten quite right however. There isn't a function in common.ai to tell the units to return home and ignore any attackers. I haven't had much success with common.j functions either, but I haven't really had a lot of time to work on it lately. Writing some fairly reasonable code to tell the units when to flee shouldn't be too hard. My current idea is to use the unit counting functions to count the number of each type on both sides. Each unit would then be given a point value based on relative power (ie. tier 3 melee would be worth more than tier 1 melee), and the total point value of each army could be calculated, and then as long as the computers army stays a certain number of points above the opposing army, the computer will say and fight, otherwise it will flee. This threshold would be controlled by an 'aggression level' parameter. A lower aggression level would cause the AI to flee sooner. For example, and aggression of 0 might make the AI flee if the opposing army's point value is equal (or just a little lower even), whereas an aggression of 5 might tell the AI to stay and fight even if the opposing army has a higher point value. It might flesh out something like this: Aggression level 0: Computer will flee if opposing army's point value is greater than 50% of its army's point value. Aggression level 1: Computer will flee if opposing army's point value is greater than 75% of its army's point value Aggression level 2: Computer will flee if opposing army's point value is equal to or greater than its army's point value Aggression level 3: Computer will fight until its army's point value is less than 75% of the opposing army's point value Aggression level 4: Computer will fight until its army's point value is less than 50% of the opposing army's point value Obviously these could be tweaked to allow for more categories, or to allow for a 'fight to the death' or 'always run' scenario, but that's the basics of it. I haven't actually written any code to implement this yet (mostly due to lack of time) but it shouldn't be too hard. The hard part is getting the AI to flee and not stutter-step the whole way back to base. The only problem I can forsee is in multi-player games. I'm not sure how to figure out which opponent the AI is fighting (so you know which player's units to count). |
| 12-01-2002, 10:23 AM | #3 |
That aggression level part is a great idea. I think I will try to implement it that way. To compare the strength I think the food usage of the units will be a good measure of their strength. When I get the current attack group a direct move command should prevent them from stuttering. To get the currently fighting units on both sides it might work to take the units in a certain range from an anchor. The problem is which unit to use as an anchor. The first choice would of course be the heroes. But what to do when all the heroes die? But that should work quite well most of the time. Thanks. |
| 12-01-2002, 02:55 PM | #4 |
Guest | Using the food totals to calculate power is a good idea, I hadn't even thought of that. I set up my function like CommonSleepUntilTargetDead() from common.ai basically. Just add something to the loop to check the powers of the armies, and exit the loop when the threshold defined by the aggression level is reached. Then put the retreat code after the loop. That seemed to work fine when I just used CaptainReadiness() to trigger the retreat. You could probably come up with a good way of doing it, but that's a place to start. :gsmile: |
