![]() |
|
|
#1 |
|
Demon Lord
Join Date: Sep 2003
Location: Israel
Posts: 598
|
ToEE's AI
It seems that ToEE's AI and strategy.tab haven't been well documented in Co8 yet, so I figured it's time we changed this. I'm actually new to this myself, but I think I got the basics, though some work remains to be done.
So, how does ToEE's combat AI work? Quite simply, any critter seems to read off of a list of commands stored in the strategy.tab file. protos.tab 'AI Strategy Type' field assigns these command lists to NPCs and creatures. E.g. - open up protos.tab with the ToEE World Builder, look up proto 14111 (Noble Salamander) and you'll see his strategy type is 'Salamander', which has a corresponding entry in the strategy.tab file. If no particular strategy is assigned, then it probably uses the Default entry. (or maybe the first entry? needs testing!) How do I interpret all the mumbo jumbo inside strategy.tab? The strategy.tab format mostly seems to be as follows: [strategy name][tab][command][tabx3][command][tabx3]...[command][bunch of tabs] For instance, let's take a look at the new AI for Belsornig I'm working on. Code:
Belsornig New AI (71) use potion target threatened cast single 'Hold Person' class_cleric 2 attack threatened clear target target ranged target closest target high ac cast area 'Unholy Blight' domain_evil 4 cast area 'Dispel Magic' class_cleric 3 cast area 'Sound Burst' class_cleric 2 clear target target self cast single 'Divine Power' class_cleric 4 clear target attack approach Code:
Belsornig New AI(71)[tab]use potion[tab][tab][tab]target threatened[tab][tab][tab]cast single[tab][tab]'Hold Person' class_cleric 2[tab]attack threateend[tab][tab][tab]clear target[tab][tab][tab]... The way ToEE seems to process these commands is to start from the beginning of the list every new round, and try to execute them in sequence until the NPC runs out of actions. So, taking Belsornig's AI for example, the AI would try to do something like this:
edit 30.10.09: I used to think that the target commands had some clever interaction with each other, this doesn't appear to be the case. E.g. commands like 'target closest', 'target high ac' etc. will simply override all previous targeting commands and pick a single new target. And yes, that means there are currently redundant commands in Belsornig's AI. Hey, the AI's pretty stupid! Can't I make it smarter than that? Yes, there is a way. Credit goes to Livonya's ingenuity for this. While ultimately the AI will follow the set of instructions as specified in the strategy.tab, the strategy type itself can be swapped via scripting: Code:
obj.obj_set_int(obj_f_critter_strategy, #) So, what a clever modder can do, is write some scripting to test how many enemies are close, what classes they are, what the party alignment is, what spell conditions are in effect, who is wounded and how badly, etc., and determine the appropriate strategy.tab entry accordingly. (some new entries may have to be custom tailored, of course) The script should go in the creature's san_start_combat - the script that fires at the beginning of the NPC's round. In pseudo code, such a script may look like this: Code:
def san_start_combat( attachee, triggerer ): if important friend is hurt: switch to 'cast heal spells' strategy return if enemy is buffed: switch to 'cast dispel magic' strategy return if party is non-evil aligned: switch to 'cast unholy blight' strategy return if none of the above: switch to 'ordinary' strategy return What AI commands are available? Here is a list of commands taken from the temple.dll file and an explanation of what they do. The commands can roughly be divided into targeting, movement, spell casting, ability usage, and attacks. Most of them have been tested in a controlled environment (so to speak), but some require more testing still.
Last edited by Sitra Achara; 2 Weeks Ago at 02:10 PM. |
|
|
|
|
|
#2 |
|
Gophers, consarn it!
Join Date: Oct 2004
Location: Sydney
Posts: 9,553
|
Re: ToEE's AI
Very helpful
I can already see a few ways to improve the Mad Wizard. Can I just confirm I have no idea what 'partial charge' does, nor did Liv when I ask her, and the 'sniper' / 'partial charge' strategy line (#8 in KotB) is ugly in practise as it just makes the NPC approach the party rather than shoot them.'Target threatened' will cause the NPC to keep hitting an enemy on the ground, where-as 'target closest' will cause the NPC to ignore unconscious foes (the difference between whether or not an NPC follows through and kills you when you are -5 on the ground, or whether he just goes and attacks someone else). 5' step is indeed essential for bowmen and spell-casters, but of limited value for melee - the NPC will try to take a 5' step every round, and just as likely step away from the target and end up doing nothing. Liv therefore implemented a script whereby the NPC monitors their health, and if they need to use a healing potion their strategy is changed to one with 5' step / 'use potion', then it is changed back again. 'Power attack' can be switched on but not, I believe, off again. 'Expertise' may be the same. Some of the spell ones are interchangable, as they no doubt appear. 'Target self' / 'Cast Area' can be used for friendly AoE spells, like Bless and Bane, but 'Target Self' / 'Cast Single' works too. While there are limited ways to implement cast-on-demand, one way is to create a potion that simulates a spell, then monitor when it is best to use it, then create that potion in the NPC's inventory and if 'use potion' is the first thing (as it should be, so the NPC uses healing potions as needed) they will automatically use it. This is how the Skeletal Priest, God bless him, knows to pull 'Death Knell' at just the right moment. It even has a counter to make sure he doesn't try it more times than he would have the necessary spell slots.
__________________
My blog! http://rpg-rant.blogspot.com/ My webcomic! http://rpg-rant.blogspot.com/2007/08/kecik-1.html
Last edited by Shiningted; August 9th, 2008 at 05:21 AM. |
|
|
|
|
|
#3 |
|
Dont mention the war
Join Date: May 2008
Location: Taiwan
Posts: 932
|
Re: ToEE's AI
Sorry for joining in blind (50% miss chance), but this is Partial Charge from SRD:
If you are able to take only a standard action or a move action on your turn, you can still charge, but you are only allowed to move up to your speed (instead of up to double your speed). You can’t use this option unless you are restricted to taking only a standard action or move action on your turn. Perhaps it is a command that is used in conjunction with Diehard? |
|
|
|
|
|
#4 | |
|
Hungry Ghoul
Join Date: Aug 2008
Location: UK, Hiding in a cave to avoid the rain
Posts: 32
|
Re: ToEE's AI
Quote:
Or when Slowed? |
|
|
|
|
|
|
#5 |
|
Dont mention the war
Join Date: May 2008
Location: Taiwan
Posts: 932
|
Re: ToEE's AI
Yes, Slowed restricts a creature to single (aka partial) actions. Zombies are the famous partial chargers. They can also be slowed but not reduced to less than a single action per turn.
However, I am not sure if the RAW Partial Charge is the same as what the modders were discussing above. |
|
|
|
|
|
#6 |
|
Bastard Maestro
Join Date: Apr 2004
Posts: 5,575
|
Re: ToEE's AI
Helpful strategy.tab tip: if you use Excel to edit this file (I believe Ranth suggested that sometime, and it does work quite well as far as all the tabs and putting stuff in the right place goes), take care to check your edits with a different program afterward. It seems that Excel takes the liberty of removing the first single quotation mark (') from spell names. Some of the time. So you might have a spell entry called
Code:
Cure Light Wounds' class_cleric 1
__________________
SUPER MODERATOR, Circle of Eight Forums |
|
|
|
|
|
#7 |
|
Demon Lord
Join Date: Sep 2003
Location: Israel
Posts: 598
|
Re: ToEE's AI
Note on factions:
Mobs who have the '0' faction might get attacked by other critters, even if they share other factions. Case in point: Aern and his Hydra would get attacked by their fellow Fire Temple members, even though I gave them the Fire Temple faction (5). They also had faction 0; removing it stopped the friendly fire situation (amusing as it was ).Faction 6 (Water Temple) doesn't seem to cause this. Haven't tested with other factions. More Experiments:
Last edited by Sitra Achara; October 30th, 2009 at 04:26 AM. |
|
|
|
|
|
#8 |
|
Demon Lord
Join Date: Sep 2003
Posts: 773
|
Re: ToEE's AI
Sitra Achara -
I got your private message on the Codex forum. The Strategy.tab is primitive. A lot of the commands do NOT work. They do nothing. Before I stopped modding TOEE (the second time) I created an alternate way to control the AI by changing the creatures Strategy.tab reference line. This way I could create very simply Strategy.tab routines, but write very, very detailed AI scripts that would change the Strategy.tab reference each round. That way a single creature can use 5 foot step, charge, feint, etc... depending on the situation. That would be impossible using the Strategy.tab alone. It worked fantastic, and was way, way, way more effective than messing with the Strategy.tab itself. At some point I posted how to do this with some examples of how to do it. I couldn't seem to find the thread, perhaps it is in the private Keep On The Borderlands area... I couldn't figure out how to get back into that area. Maybe someone can point you to that thread. If you are serious about working with TOEE AI then I really suggest you check that out. In my opinion it was a massive step forward in TOEE AI, but it was also a work around that Troika never intended. It was only possible because other TOEE mod folks figured out how to make creatures store unique numbers. I am super rusty with TOEE scripting, and I don't want to get pulled back in. I spent way, way, way too much time with TOEE scripting and had to get back to real life... no time to get sucked back into the void again... I am not good with moderation... always all the way in or all the way out it seems. Anyway, a lot can be done with the TOEE AI by combining scripting with Strategy.tab reference switching. You should look into that... Hopefully someone can point you to my original thread... and I assume others may have radically improved on what I was doing by now. If you can't find that thread, and if no one ever points you there... and you are curious about it then send me another private message and I will see if I can't find it on my hard drive and re-post it for you. Good luck with it. TOEE has a great engine, if only the Troika folks could have fixed a few more core problems... ugh... makes me so frustrated. The greatest RPG combat engine ever designed ruined by the lack of time and the rush to get a product out the door before it was finished... a real travesty. It still makes me angry to this day. Livonya PS: Yeah, it must be in the private Keep On The Borderlands forum area as I did a search for all the threads I ever started and that thread is not there... maybe someone can help you get to that or copy/paste it over into this thread.
__________________
When you doubt your powers, you lend power to your doubts. Last edited by Livonya; October 30th, 2009 at 10:37 AM. |
|
|
|
|
|
#9 |
|
Demon Lord
Join Date: Sep 2003
Location: Israel
Posts: 598
|
Re: ToEE's AI
Hi Liv,
I'm aware of your work - I've mentioned it in the middle of the long-ass first post In fact, messing with it in the first place is the reason I'm investigating the AI commands further now. What I hoped for was to further optimize AI for reach weapons (for when it is in the player's hands as well as the AI's), and try to find a solution for the Spiritual Weapon / Summoned Creatures exploit. Certainly the san_start_combat scripting can be used to great effect, but one must have a solid grasp of strategy.tab commands in order to properly utilize it. Except for a certain few commands, I think I have a much better understanding of it now, through lots of testing. I've documented some of the testing itself in the second post, and the results I've obtained in the first. Ted, could you find the relevant thread in the KotB forum and post it here, if there's anything it could add? |
|
|
|
|
|
#10 |
|
Gophers, consarn it!
Join Date: Oct 2004
Location: Sydney
Posts: 9,553
|
Re: ToEE's AI
Yah, I'll have a look. Needless to say, the Livonya.py file I just threw into 5.6 is the main thing you needed.
__________________
My blog! http://rpg-rant.blogspot.com/ My webcomic! http://rpg-rant.blogspot.com/2007/08/kecik-1.html
|
|
|
|
|
|
#11 |
|
Bastard Maestro
Join Date: Apr 2004
Posts: 5,575
|
Re: ToEE's AI
Odd discovery: enemy spellcasters may cast spells that are in their spell lists (in protos.tab) but that don't appear in their strategy.tab assignments.
Specifically, I added cantrips to a wizard's spell list that don't appear in his strategy entry, and he started casting them after he was out of all his other spells. Did a good job of it too.
__________________
SUPER MODERATOR, Circle of Eight Forums |
|
|
|
|
|
#12 |
|
Gophers, consarn it!
Join Date: Oct 2004
Location: Sydney
Posts: 9,553
|
Re: ToEE's AI
Confirmed
__________________
My blog! http://rpg-rant.blogspot.com/ My webcomic! http://rpg-rant.blogspot.com/2007/08/kecik-1.html
|
|
|
|
|
|
#13 |
|
Demon Lord
Join Date: Sep 2003
Location: Israel
Posts: 598
|
Re: ToEE's AI
What AI routine was he using? Did he have commands other than spell casting after the spell list? (attack, etc)
What were his targets? Did they match the targeting commands? Does this only apply to cantrips? Were the spells offensive spells or defensive spells, and were they appropriately cast on friend/foe? |
|
|
|
|
|
#14 |
|
Bastard Maestro
Join Date: Apr 2004
Posts: 5,575
|
Re: ToEE's AI
Wow, that's a lot of questions ... just play around with the 'Wizard' strategy and see what you find.
__________________
SUPER MODERATOR, Circle of Eight Forums |
|
|
|
|
|
#15 | |
|
Bastard Maestro
Join Date: Apr 2004
Posts: 5,575
|
Re: ToEE's AI
Quote:
Too bad, I could really have used this feature in one of the upcoming Verbomod battles. ![]() (Livonya's also got a custom 'change strategy' script in Livonya.py that doesn't work either.)
__________________
SUPER MODERATOR, Circle of Eight Forums |
|
|
|
|
|
|
#16 |
|
Demon Lord
Join Date: Sep 2003
Location: Israel
Posts: 598
|
Re: ToEE's AI
No way! I've tested it many times on my computer, and it worked fine.
Can you post the script that breaks the san_start_combat function? |
|
|
|
|
|
#17 |
|
Bastard Maestro
Join Date: Apr 2004
Posts: 5,575
|
Re: ToEE's AI
Sure, from memory it was basically:
Code:
def san_start_combat( attachee, triggerer ): leader = game.leader if ( (attachee.map == 5093) and (game.global_flags[954] == 1) ): obj.obj_set_int(obj_f_critter_strategy, 20) elif ( (game.quests[67].state == qs_accepted) and (game.global_flags[963] == 0) ): game.counters[0] = game.counters[0] + 1 if (game.counters[0] >= 2): for pc in game.party: if pc.type == obj_t_pc: attachee.ai_shitlist_remove( pc ) game.global_flags[963] = 1 leader.begin_dialog( attachee, 1 ) return SKIP_DEFAULT return RUN_DEFAULT IIRC, it actually broke the entire file (or I assume it did), because the following san_first_heartbeat script from the same file stopped working after the strategy thing was added: Code:
def san_first_heartbeat( attachee, triggerer ): if (attachee.map == 5093 and game.global_vars[960] == 3): attachee.object_flag_unset(OF_OFF) elif ( (game.party[0].reputation_has(35) == 1) and (attachee.map == 5121) ): attachee.object_flag_unset(OF_OFF) elif ( (game.party[0].reputation_has(35) == 0) and (attachee.map == 5121) ): attachee.object_flag_set(OF_OFF) return RUN_DEFAULT 'from toee import *' and 'from utilities import *' are invoked at the start of the file.
__________________
SUPER MODERATOR, Circle of Eight Forums |
|
|
|
|
|
#18 |
|
Demon Lord
Join Date: Sep 2003
Location: Israel
Posts: 598
|
Re: ToEE's AI
That's probably because the object handle "obj" is undefined and points to nothing
![]() Try attachee.obj_set_int(...) instead. |
|
|
|
|
|
#19 |
|
Bastard Maestro
Join Date: Apr 2004
Posts: 5,575
|
Re: ToEE's AI
Yay, it works.
Only now, the mobs with changed AI seem to go to *no* AI (they return to their original coordinates and just stand there) after they kill a target, for reasons I can't begin to fathom. ![]() Thanks though, at least it's half-way working. [edit] Seemed to fix it with a 'return RUN_DEFAULT' after the AI change script.
__________________
SUPER MODERATOR, Circle of Eight Forums Last edited by Gaear; 1 Week Ago at 09:29 PM. |
|
|
|