Jump to content


Photo

AI Q & A


  • Please log in to reply
111 replies to this topic

#1 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 30 October 2006 - 03:06 PM

I thought I'd start a thread to discuss a long ignored part of modding AI.
AI can be a very tedious proccess but it's worth it to play against your own units.
I'm still new to AI scripting so if anyone has any questions or solutions I hope we can all post it here so that we can more discussion about this and make it easier.

I'll start with a question when scripting AI I sometimes find Flags I was wondering if it was possible to edit/create new flags ?.

Break dancing into the hearts of millions


#2 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 30 October 2006 - 04:49 PM

a flag is a boolean in WB (if you're familiar with programming) and you can create and change them with scripts in the Scripting category
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#3 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 31 October 2006 - 04:03 PM

I half got that.thanks perhaps you could elaborate.
do you know where i'd find them?

Break dancing into the hearts of millions


#4 Celeglin

Celeglin

    Silhouette of a Serenade

  • Hosted
  • 2,468 posts
  • Projects:The Elven Alliance, Rhovanion Alliance
  •  T3A Team Chamber Member

Posted 01 November 2006 - 01:38 AM

Well I've finally gotten my Elven AI to work... after a fashion (I really, really need to work on it). The thing I was missing was this: you have to add the new faction to the playerlist on every single skirmish map. Very tedious.

However, when I did this, for some reason random factions have been just losing right on start up (first time was the AI Elves, second and third time was a Mordor enemy) on my test map. And they don't totally "lose"... They're out of the game, but their citadel is still there and the buildings they were starting to build are just sitting there at 0%... Come to think of it, the citadel may have not really been there... I seem to remember not being able to target it. Aaanyway, has anyone ever seen this happen while doing anything AI/map scripting related?

Posted Image
Posted Image


#5 Hebblewhite

Hebblewhite

    Artificially Intelligent

  • Project Team
  • 131 posts
  • Location:North Wales, UK
  • Projects:WOP-AI (bfme AI plugin), Darkness Rising, Rhovanian Alliance
  •  Mysterious AI Guy...

Posted 01 November 2006 - 02:42 PM

a flag is a boolean in WB (if you're familiar with programming) and you can create and change them with scripts in the Scripting category


Many of the important flags for Heros (for example!) can be found in "lib_hero_behaviours". A great example of the use of flags is that of the weapons toggle.

Coding a weapon toggle (such as bow to sword) is pretty easy, but getting the AI system to recognise and use the ability is slightly more tricky because you need to set up OBJECT STATES.

These are (as 2PlayGames said) boolean values used by the system to find out the current activities a given object may be engaged in. Have a look at Faramir in "lib_hero_behaviours", and you'll see he has 3 seperate scripts, and 2 STATES (or flags) working together to get the toggle to work.

The 3 scripts are:

1) b_Faramir - Use Switch Init - A toggle initialiser that tells the game whcih weapon he is using when you first buy him. This sets our first STATE ('AI_FARAMIR_USING_BOW') to true at the start of a game.

Obviously... if you create new heros that begin with a sword, this would be a little different :p

2) b_Faramir - Use Switch to Sword on High Threat - This sets our second STATE ('AI_FARAMIR_USING_SWORD') to true and AI_FARAMIR_USING_BOW to false when the threat level to our hero is judged to be high.

What we classify as high can be changed easily be manipulating the values in the script. I'M RAMBLING HERE I KNOW... but it's relevant in BFME1 because many OBJECT STATES are constantly changing in relation to other scripts that are always "testing" for certain things to happen the game.

So... upgrades (units and bases) work in the same way. Only instead of testing threat levels, we want to know how much money we have, what buildings we have and also what our opponent has in his base (yes the AI system cheats and can see your base at all times!).

Finally, our third Faramir script:

3) b_Faramir - Use Switch to Bow on No Threat - This is basically the opposite of script number 2 (above).


In short, if I wanted to add another hero that can toggle weapons, I could simply use Faramir as an example, and then create my own set of scripts and OBJECT STATES that will allow the AI system to toggle weapons given certain situations that are measurable.

The flags for buildings and regular units are scattered around the other various library files. Look for economy, upgrade and formation behaviours for a start :p


Cheers,

Hebblewhite.

P.S. If people have any specific questions or problems with your AI then don't be afraid to PM me! I'm always willing to trouble shoot or advise in any way I can.
Reassuringly Expensive...

Blade with whom I have lived,
Blade with whom I now die,
Serve right and justice one last time,
Seek one last heart of evil,
Still one last life of pain,
Cut well old friend, and then... farewell


Posted Image

#6 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 02 November 2006 - 04:09 PM

thanks that helped.much appreciated.
Do you know where i'd find the flags for factions so that the AI will build my faction without adding it to the map I saw a flag called g_getenemy_factionname or something like that these flags seem to be the ones i need to create.

Break dancing into the hearts of millions


#7 Hebblewhite

Hebblewhite

    Artificially Intelligent

  • Project Team
  • 131 posts
  • Location:North Wales, UK
  • Projects:WOP-AI (bfme AI plugin), Darkness Rising, Rhovanian Alliance
  •  Mysterious AI Guy...

Posted 02 November 2006 - 06:35 PM

thanks that helped.much appreciated.
Do you know where i'd find the flags for factions so that the AI will build my faction without adding it to the map I saw a flag called g_getenemy_factionname or something like that these flags seem to be the ones i need to create.



Here's a ROUGH guide to setting up faction AI: :lol:


You should not have to add any specifics at all to an actual map regarding a faction (unless you are creating some kind of single player/scripted event).

The map making process is very generic in that you add your base and economy plots, and then set up teams using the editor in world builder. At no time do we start saying "this plot is only for mordor" etc. etc. We only think of a map as a container for up to 8 teams (the actual teams at that point are irrelevant).


To get a new faction working properaly is a fair amount of work (and beware of crashes - worldbuilder has caught me out on a few occasions... so keep track of what you have added as you go).

Firstly, you will need to add your "ai_myfaction.map". This is main brain behind your faction, and contains all of the scripts regarding hero and unit teams. You will also set up your attack waves, and patrol teams for the early, mid and late game phases - IMPORTANT because without them your faction will never try to attack you!

Secondly, you need to create an "ai_myfactionskirmish.map". This relates to the first map file, and initialises all of the skirmish values and STATES for easy, medium and hard armies.

It also tells the AI system which ecomony plots to build at, and selects the basic strategy that the team will adopt. Gondor for example will choose one of turtle, infantry, balanced and cavalry. As you will guess... it determines the kind of units that will be built and where they are deployed. The level of aggression is set up in the previous map file we just talked about.

One of the most important parts of this map file is "g_Init - Initialize AI Subsystems". This sets your faction as an enemy (or ally!), along with the important flags like AI_Attack, AI_Defend, AI_Economy, AI_Predictive_Building, AI_Spells and AI_Upgrades.

Actually, it sets them all to true, so you will to add your faction entries to all of the relevant map files such as "ai _desires.map", "ai_upgrade_execution.map", "ai_spell_execution.map" "ai_predictive_building.map" and also the defend, attack and economy behaviour map files.

Last but not least, you need to edit two other files "ai_initialise.map" and "multiplayer_start_teams.map"

ai_initialise is where the faction names are assigned to base flags (you need to add an entry for your own faction). Heres an example (using Lothlorien as a new faction):

g_Init - Set Lothlorien Faction
***IF***
Player (This Player) is Faction Name: Lothlorien

***Actions If True***
Set Flag named 'AI Faction Lothlorien' to TRUE

You would then need to modify "g_Init - Initialize Upgrade Values", and add any new entries for upgrades that may be unique to your new faction (if there are any of course!).

In multiplayer_start_teams.map, you set how many units you start a match with (depending on command points). You need to add a TEAM entry aswell as a SCRIPT entry.

The team entry is basically the same as you would do in "ai_myfaction", where you set assignment a unit object (such as GondorFighterHorde) to a team with max/min values of 2 (1 for Isengard).

The script then checks to see how many players have entered the game, and then spawns an instance of your start team if required. An example for our lothlorien faction would be:

*** IF ***
Player '<This Player>' is Faction Name: Lothlorien
*AND* Is this a Less Than 5 player game.
*** THEN ***
Spawn an instance of Team 'Start Team - Lothlorien' at Unit 'START_BASE'.


Just to finish (I'll shut up in a minute, I promise! :p ), the act of assigning ownership to base flags happens in "ai_mp_inherit_management.map" and some of the scripts used in multiplayer_start_teams.map are imported from here.


Ok... after all that, what I'm saying is you will have edited a fair proportion of the original library map files, and added 3 or 4 new ones of your own. What you should do now is have a bash at it, and then come back with some specific questions so I can help you troubleshoot!

I hope this at least points you in the right direction!


Cheers,

Hebblewhite.

P.S. Thanks Mastermind!

Edited by Hebblewhite, 02 November 2006 - 07:42 PM.

Reassuringly Expensive...

Blade with whom I have lived,
Blade with whom I now die,
Serve right and justice one last time,
Seek one last heart of evil,
Still one last life of pain,
Cut well old friend, and then... farewell


Posted Image

#8 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 03 November 2006 - 11:34 AM

I did it
reading your post made me look through the libaries and I found Lib-enemy-dertimination and relised by accident that you can simply rename the flags and then press apply I know have the AI working on 2 of the Skirmish maps I just have to finish the rest of them.It's the only think I had to do.
Thanks you were a big help and the last post of yours will definetly help others.
I think this topic should be stickied.although i'm a little biased :lol:

Edited by erkenbrand the cut, 03 November 2006 - 11:35 AM.

Break dancing into the hearts of millions


#9 Hebblewhite

Hebblewhite

    Artificially Intelligent

  • Project Team
  • 131 posts
  • Location:North Wales, UK
  • Projects:WOP-AI (bfme AI plugin), Darkness Rising, Rhovanian Alliance
  •  Mysterious AI Guy...

Posted 03 November 2006 - 11:56 AM

Glad I could help! (One of these days I should write a proper tutorial on this stuff).
Reassuringly Expensive...

Blade with whom I have lived,
Blade with whom I now die,
Serve right and justice one last time,
Seek one last heart of evil,
Still one last life of pain,
Cut well old friend, and then... farewell


Posted Image

#10 Celeglin

Celeglin

    Silhouette of a Serenade

  • Hosted
  • 2,468 posts
  • Projects:The Elven Alliance, Rhovanion Alliance
  •  T3A Team Chamber Member

Posted 05 November 2006 - 03:26 AM

P.S. If people have any specific questions or problems with your AI then don't be afraid to PM me! I'm always willing to trouble shoot or advise in any way I can.


*points at his earlier post*

Posted Image
Posted Image


#11 Hebblewhite

Hebblewhite

    Artificially Intelligent

  • Project Team
  • 131 posts
  • Location:North Wales, UK
  • Projects:WOP-AI (bfme AI plugin), Darkness Rising, Rhovanian Alliance
  •  Mysterious AI Guy...

Posted 06 November 2006 - 08:31 PM

P.S. If people have any specific questions or problems with your AI then don't be afraid to PM me! I'm always willing to trouble shoot or advise in any way I can.


*points at his earlier post*


A few questions:

1) Have you checked your entries in "ai_mp_inherit_management.map" ...?

2) Does this error only occur on the same map, or all MP maps ...?

- If its one map, are you sure you added the original base plots correctly (just a thought, but you never know!)

i.e. You have your "PlyrCivilian" entry for each of the base plots, and a team entry "SkirmishElves" (no actual values, just a default entry) ...?

3) When it happens, does it affect all of the AI players, or only one of them etc. ...?
Reassuringly Expensive...

Blade with whom I have lived,
Blade with whom I now die,
Serve right and justice one last time,
Seek one last heart of evil,
Still one last life of pain,
Cut well old friend, and then... farewell


Posted Image

#12 Radspakr Wolfbane

Radspakr Wolfbane

    The John Farnham of modding

  • Members
  • 7,722 posts
  • Location:less than 5 meters from my bed
  • Projects:Comeback tour
  •  The Retired Beard

Posted 18 January 2007 - 04:56 PM

I've added my own plots to the game the AI doesn't build them though.
I wanted to add in a new naming thing like BASE_FLAG_x
I've called mine HAVEN_FLAG_x i've added them to object list and the lib that handles building the Plots can't remember what it's called but it still doesn't work oh I can get them to build the Haven plot in late game if I call it BASE_FLAG_x.
any assistance on this would be great.

Break dancing into the hearts of millions


#13 Hebblewhite

Hebblewhite

    Artificially Intelligent

  • Project Team
  • 131 posts
  • Location:North Wales, UK
  • Projects:WOP-AI (bfme AI plugin), Darkness Rising, Rhovanian Alliance
  •  Mysterious AI Guy...

Posted 03 June 2007 - 04:25 PM

Hi All!

How is everyone ...? It's my first post in a little while...

Anyhow, I have been finalising the AI systems of my personal mod and have picked up on a couple of things that may be of interest.

1) ALL of the "give targeted units experience" type hero spells are broken in terms of the AI. If you glance at hero behaviours you notice the "Action" for each of the spells merely triggers the ability, but does not actually use it correctly:

For example, Sarumans Speech Craft looks like this:

Team '<This Team>' use Ability 'Command_SpecialAbilitySpeechCraft'


This fires the spell, but doesnt actually apply it to any specific units ;)


To make it work, you'll need to change all spells of this type to the following:

Player '<This Player>' fire Special power 'SpecialAbilityKingsFavor' on nearest object of 'Horde_Units' to Team '<This Team>' owned by Player '<This Player>'

Note: Yes... Saruman's Speech Craft is a clone of Thoeden's Kings Favour. You will need to change the special ability name as appropriate.

2) I have been working feverishly to get my spell system to work correctly. For example, I have a "Bruinen White Horses" power that summons white river stallions. To make your AI system purchase and USE the spell correctly, you need to force recruitment of the units spawned, or else they will appear and stand there until they expire...

OR they will defend themselves if attacked on the spot, or attack nearby units/buildings but not actually hunt, move around, toggle weapons or make use of abilites etc. if just left alone.

To solve this, open "AI_Spell_Execution.ini" and add a timer in Good or Evil behaviours (such as "Recruit White Horses"), that will count down and then run a team recruitment script when it reaches zero. The actual recruitment script lives in "Spells-Recruitment".

The standard time set by EA seems to be 6 seconds... this is why units such as the Balrog occasionally seem to hang around for a short time before doing anything useful.

Reduce this time to increase AI your effectiveness... and make sure you add your own timer if you have new spells or else they will not work correctly.

Note: The team you actually recruit obviously need to be added to the "lib_objects_lists", "ai_my_faction" and "ai_my_faction_skirmish" (change faction names as appropriate!).

All such summon spells seems to be working correctly so far with this method (in that my AI system will purchase and use units effectively), but my testing time is a bit limited these days!

Hope this is useful! (it's nice to be back!)


Cheers,

Hebblewhite.

Edited by Hebblewhite, 03 June 2007 - 04:25 PM.

Reassuringly Expensive...

Blade with whom I have lived,
Blade with whom I now die,
Serve right and justice one last time,
Seek one last heart of evil,
Still one last life of pain,
Cut well old friend, and then... farewell


Posted Image

#14 ched

ched

    .

  • Undead
  • 4,431 posts
  • Location:Angers (France)
  • Projects:Rhovanion Alliance
  •  T3A Team Chamber Member
  • Division:BFME
  • Job:Previous Division Leader

Posted 03 June 2007 - 05:08 PM

You rock.
Seriously, no one has ever been involved as much as you have in getting around understanding the shady BfME1 AI.

Thank you for everything Hebblewhite.
Software is like sex; it's better when it's free ~Linus Torvald

#15 Lauri

Lauri

    Old man Lauri

  • Hosted
  • 10,436 posts
  • Location:Norway
  • Projects:The 4th Age
  •  The very worst T3A Team Chamber Member

Posted 03 June 2007 - 05:31 PM

you, totally! :p

Anyways, now that your back...

You don't happen to know how I make new names thingies?
More precies, how do I make a new AI_HERO_FARAMIR? (only, instead of FARAMIR, I want MORGON)
And if that is something that's not really important, then well... tell me ;)

T4A_Logo_-_article.png

The 4th Age version 0.8 has been released: Link


#16 ched

ched

    .

  • Undead
  • 4,431 posts
  • Location:Angers (France)
  • Projects:Rhovanion Alliance
  •  T3A Team Chamber Member
  • Division:BFME
  • Job:Previous Division Leader

Posted 03 June 2007 - 06:36 PM

I think I can answer this ;) The answer lies in object_list.map (name may not be accurate)
Software is like sex; it's better when it's free ~Linus Torvald

#17 Hebblewhite

Hebblewhite

    Artificially Intelligent

  • Project Team
  • 131 posts
  • Location:North Wales, UK
  • Projects:WOP-AI (bfme AI plugin), Darkness Rising, Rhovanian Alliance
  •  Mysterious AI Guy...

Posted 03 June 2007 - 07:22 PM

Thanks for complements! Seriously, it's nice to know that my work is actually of value to somebody! (Now I can rest easy that my Phd is not a complete waste of my time! LoL).

Lauri: (Long time, no see - or posting anyway!) I'm not quite sure what you're looking for... you want to re-name the AI_FARAMIR stuff...? Or you want to create something similar for a completely new hero...?

Ched was right when he mentioned "lib_object_lists.ini". That should always be your first port of call when creating a new hero. You need it to add your hero object to the correct faction and its respective lists of buildable units (sorted by classification).

The AI_FARAMIR stuff appears in "lib_hero_behaviors". AI_FARAMIR is used to initiate the "Set Unit Reference" script that you can see in the Faramir Object Team (in ai_Gondor). It's main purpose is that it acts as a kind of variable name to refer to the Faramir object in the AI from that point onwards (and any other hordes that happen to be part of Faramirs' "team").

This is Faramirs reference declaration:

*** IF ***
Team '<This Team>' has one or more units.
*** THEN ***
Find 'GondorFaramir' Owned by Player '<This Player>' nearest team Team '<This Team>' and reference as UnitRef 'AI_HERO_FARAMIR'


You can create another one easily. Just copy the whole script and then change the AI_FARAMIR to AI_MORGON instead.

You'll need a bunch of these if you're new hero has a weapons toggle etc. (that's basically how the AI keeps track of whats going on!).


Cheers,

Hebblewhite.

Edited by Hebblewhite, 03 June 2007 - 07:24 PM.

Reassuringly Expensive...

Blade with whom I have lived,
Blade with whom I now die,
Serve right and justice one last time,
Seek one last heart of evil,
Still one last life of pain,
Cut well old friend, and then... farewell


Posted Image

#18 Lauri

Lauri

    Old man Lauri

  • Hosted
  • 10,436 posts
  • Location:Norway
  • Projects:The 4th Age
  •  The very worst T3A Team Chamber Member

Posted 03 June 2007 - 08:00 PM

Thanks man! :p
I tried to just rename it to AI_HERO_MORGON, but it just said that it was a missing thing.... but now it works though, really thanks! ;) Stick around for awhile, I'm about to do the Isengard AI for KotW, could maybe use your help ;) Although, I'm pretty skilled with the basic AI for now (ie, no new faction).... or better, add me to MSN, even thought I feel I have you ;)

Thanks again! Now my AI will do as told, even better than before! :D (not really :p )

T4A_Logo_-_article.png

The 4th Age version 0.8 has been released: Link


#19 Hebblewhite

Hebblewhite

    Artificially Intelligent

  • Project Team
  • 131 posts
  • Location:North Wales, UK
  • Projects:WOP-AI (bfme AI plugin), Darkness Rising, Rhovanian Alliance
  •  Mysterious AI Guy...

Posted 03 June 2007 - 08:16 PM

If by missing you mean you see something like this "[???]" in the preview mode, then it's literally because your referencing a flag, script or object that does not exist.

There are actually quite a few errors left over from EA's development... the "libraries.ini" file is littered with them!



Cheers,

Hebblewhite.
Reassuringly Expensive...

Blade with whom I have lived,
Blade with whom I now die,
Serve right and justice one last time,
Seek one last heart of evil,
Still one last life of pain,
Cut well old friend, and then... farewell


Posted Image

#20 Hebblewhite

Hebblewhite

    Artificially Intelligent

  • Project Team
  • 131 posts
  • Location:North Wales, UK
  • Projects:WOP-AI (bfme AI plugin), Darkness Rising, Rhovanian Alliance
  •  Mysterious AI Guy...

Posted 06 June 2007 - 10:27 PM

Hi All!

Today (well this evening actually!), I have been correcting the AI base repair abilities. More specifically, Gondor and Rohans ability to rebuild base walls after they have been destroyed (I find it a little strange that this wasn't implemented originally - but there are actually some issues with the whole idea...).

The secret to this lies in "ai_defend_execution.map". You need to create a dummy team (lets call it "Wall Building Team" for arguments sake), that essentially has no units. You can then use it as we would an "egg" to summon objects or FX. In this case, you want the "team" to activate a command button. This is exactly how the AI sysem decides when to re-build his citadel after an attack...

You then need to add a script that goes something like this:

*** IF ***
Flag named 'AI_On' IS TRUE
*AND* Flag named 'AI_Defend_On' IS TRUE
*AND* Team 'AI Base Team' has Less Than threat level 10.00 within radius 300.00
*AND* Counter 'g_Economy_Current_Money' IS Greater Than or Equal To 4000
*** THEN ***
Team 'Wall Building Team' use Ability 'Command_ConstructGondorWall'.

The above script works only for Gondor (obviously). So you can either create a script for each faction, or if you're feeling clever, build one that will detect the faction and act accordingly. Remember that the command buttons for Gondor and Rohan walls are different...

You don't need to add anything to a faction specific ai-map file because all scripts in "ai_defend_execution" are imported automatically.

Issues: It costs money to replace walls, and a lot of it... ideally, you need to work this in with specific game stages (such as mid - late build executions). Or you will end up with an easy target... i.e. knock down the walls, let the AI re-build and then attack because it has no money!

Anyway, play around with it and you'll soon have you good factions using a bit more common sense when trying to "defend" a base.


Cheers,

Hebblewhite.

Edited by Hebblewhite, 06 June 2007 - 10:34 PM.

Reassuringly Expensive...

Blade with whom I have lived,
Blade with whom I now die,
Serve right and justice one last time,
Seek one last heart of evil,
Still one last life of pain,
Cut well old friend, and then... farewell


Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users