The 3rd Age

RC Mod

RC Mod

This Mod makes many changes to the original game, adds a whole new BFME 1 mode and much more.

Button for The 3rd AgeButton for The Dwarf HoldsButton for The Elven AllianceButton for Helm's Deep Last HopeButton for GothmogtheOrcButton for BFME+Button for The Four AgesButton for HDR HeadquartersButton for Middle Earth CenterButton for Project Perfect Mod

Become an affiliate!

   

Quick Lists

Top Rated Popular New Updated Last Comments Users

Register and log in to move these advertisements down

In-depth AI Coding

Avatar of Sulherokhh

Sulherokhh

Category: Code
Level: Expert
Created: Wednesday October 3, 2007 - 6:28
Updated: Friday August 27, 2010 - 19:26
Views: 28459
Summary: The beginning of a comprehensive guide to AI-modding for BfME2

Rating

Staff says

4.8

Members say

4.9

Average

4.9/5.0

20 votes

Page 1 2 3 4 5 6 7 8 9 10 11
C. HAL 9000: Powerful AI In Need Of Brainsurgery.

Introduction to the SkirmishAI_2 (continued from page 2)

This now is the works. I will show you how the skirmish AI is set up, What constitutes the basic parts. This will enable you both to fine tune the existing faction's AI and provide the tools you need to add a new faction. As is shown on the TOC on page one, i have broken down the SkirmishAI tutorial into several parts, starting with the most basic references, continuing with the central AI coding segments and finalizing it with the script-remnants and novelties. So let's begin.

I will now repeat the list, so you know what to expect from the next pages:


C1. General SkirmishAI Setup (this page)
  • This will explain how the scripted parts of the AI are referenced in the ini code (important only for SpellPurchase and for any CustomAIScripts you want to implement) and it will give you an overview of the 'PlayerTemplate'

  • C2. General SkirmishAI_1 and _2 Settings: 'aidata.ini' (page 10)
  • Here you will find general settings like pathfinding, threat assessment and several other AI- and not-AI-related settings. I will explain which ones are for SkirmishAI_1, which are for SkirmishAI_2, which are for both and which ones i have no idea about. Some are really important and i will mention them again in Chapter C3.

  • C3. General SkirmishAI_2 Settings: 'skirmishaidata.ini' (page 11)
  • Here you will find the core settings for SkirmishAI_2. I will provide an overview of the different sections before going into them in detail, one by one. Also i am going to explain how the relevant data and settings tie in with code/data located in different areas of modding, like the .BSE-files, aidata.ini, AttackPriorities. Also i will point to some crippling limitations and will suggest a few ways to get around them.




  • C1. General SkirmishAI Setup - The SkirmishAI_2 Setup - Important references.

    The starting point of any faction's skirmish AI is the faction setup itself. It is found in the file 'data\ini\playertemplate.ini' that contains all the basic features any faction, AI or player, inherits when chosen at the start of a skirmish or campaign game. So let's take a look at the small parts. I will start from top to bottom, including short descriptions of the entries that are not AI specific, in case you are wondering what they are for. What follows is ---- Almost Totally Verified ----


    ---- PLAYERTEMPLATE

    data\ini\playertemplate.ini (sample entry from Isengard)
    This is what we are going to look at:
                  
    Code
    PlayerTemplate FactionIsengard
        Side = Isengard
        PlayableSide = Yes
        Evil = Yes
        StartMoney = 0
        MaxLevelMP = #DIVIDE( PLAYER_MAX_PURCHASE_POINTS_DEFAULT PLAYER_PURCHASE_POINTS_GRANTED )
        MaxLevelSP = #DIVIDE( PLAYER_MAX_PURCHASE_POINTS_EVIL PLAYER_PURCHASE_POINTS_GRANTED )
        PreferredColor = R:216 G:175 B:48
        StartingBuilding = IsengardFortress
        StartingUnit0 = IsengardPorter
        StartingUnitOffset0 = X:1 Y:230 Z:0
        StartingUnit1 = IsengardPorter
        StartingUnitOffset1 = X:1 Y:150 Z:0
        StartingUnitTacticalWOTR = IsengardPorter
        StartingUnitTacticalWOTR = IsengardPorter
        IntrinsicSciences = SCIENCE_EVIL
        IntrinsicSciencesMP = SCIENCE_ISENGARD
        DefaultPlayerAIType = IsengardSkirmishAI
        SpellBook = EvilSpellBook
        SpellBookMp = IsengardSpellBook
        PurchaseScienceCommandSet = EvilSpellStoreCommandSet
        PurchaseScienceCommandSetMP = IsengardSpellStoreCommandSet
        DisplayName = INI:FactionIsengard
        BeaconName = MultiplayerBeacon
        LightPointsUpSound = IsengardLightPointsUp
        ObjectiveAddedSound = Gui_MissionObjectiveNew
        ObjectiveCompletedSound = Gui_MissionObjectiveCompleted
        BuildableHeroesMP = CreateAHero IsengardLurtz IsengardSharku IsengardWormTongue IsengardSaruman
        BuildableRingHeroesMP = MordorSauron_RingHero
        InitialUpgrades = Upgrade_IsengardDualEconomyChoice Upgrade_IsengardFaction Upgrade_EvilDualEconomyChoice
        SpellStoreCurrentPowerLabel = APT:SpellStoreCurrentRingPower
        SpellStoreMaximumPowerLabel = APT:SpellStoreMaximumRingPower
        ResourceModifierObjectFilter = RESOURCE_MODIFIER_OBJECT_FILTER
        ResourceModifierValues = 100 100 100 95 90 85 80 75 71 68 66
        MultiSelectionPortrait = UPIsengard_Army
        LoadScreenMusic = Shell2MusicForLoadScreen
    End



    And now in detail...:
                  
    Code
    Side = Isengard

  • This is also used by scripts when checking the faction (spell purchase, music).

  •               
    Code
    PlayableSide = Yes

  • You want to be able to play this faction, right?

  •               
    Code
    Evil = Yes

  • Hardcoded reference for campaigns and probably more stuff.

  •               
    Code
    StartMoney = 0

  • This is on top of what you can set as starting resources in the game setup.

  •               
    Code
    MaxLevelMP = #DIVIDE( PLAYER_MAX_PURCHASE_POINTS_DEFAULT PLAYER_PURCHASE_POINTS_GRANTED )
    MaxLevelSP = #DIVIDE( PLAYER_MAX_PURCHASE_POINTS_EVIL PLAYER_PURCHASE_POINTS_GRANTED )

  • Maximum 'experience points' your faction can gain to buy SpellBook powers in skirmish/multiplayer mode (MP) and campaign mode (SP).

  •               
    Code
    PreferredColor = R:175 G:49 B:33

  • RGB settings for favourite house color. Pretty irrelevant, since you can pick colors by hand.

  •               
    Code
    StartingBuilding = IsengardFortress

  • Vital. It identifies the Object placed on the starting position. It unpacks into a 'base' (a .bse file containing the central keep + the 6-7 buildplots) If you are setting up a new faction, this is what you need badly: a new fortress.

  •               
    Code
    StartingUnit0 = IsengardPorter
    StartingUnitOffset0 = X:1 Y:230 Z:0
    StartingUnit1 = IsengardPorter
    StartingUnitOffset1 = X:1 Y:150 Z:0
    StartingUnitTacticalWOTR = IsengardPorter
    StartingUnitTacticalWOTR = IsengardPorter

  • Starting units and their starting positions relative to the preplaced fortress (MP only). You can append more entries to this list (0, 1, and continuing with 2, 3 etc.).

  •               
    Code
    IntrinsicSciences = SCIENCE_EVIL
    IntrinsicSciencesMP = SCIENCE_ISENGARD

  • Basic Science which is a prerequisite for the rest of the faction's Spell Book powers (campaign/skirmish)

  •               
    Code
    DefaultPlayerAIType = IsengardSkirmishAI

  • VERY IMPORTANT REFERENCE (see at end of this section)

  •               
    Code
    SpellBook = EvilSpellBook
    SpellBookMp = IsengardSpellBook

  • SpellBook Objects that contain the SpecialPowers of the SpellBooks and the CommandSets to execute them.

  •               
    Code
    PurchaseScienceCommandSet = EvilSpellStoreCommandSet
    PurchaseScienceCommandSetMP = IsengardSpellStoreCommandSet

  • This identifies the CommandSet used for the spell purchase menues (campaign/skirmish)

  •               
    Code
    DisplayName = INI:FactionIsengard
    BeaconName = MultiplayerBeacon

  • String references from 'lotr.str/lotr.csf'

  •               
    Code
    LightPointsUpSound = IsengardLightPointsUp
    ObjectiveAddedSound = Gui_MissionObjectiveNew
    ObjectiveCompletedSound = Gui_MissionObjectiveCompleted

  • Sound references from either 'sounds.ini' or 'eva.ini'

  •               
    Code
    BuildableHeroesMP = CreateAHero IsengardLurtz IsengardSharku IsengardWormTongue IsengardSaruman
    BuildableRingHeroesMP = MordorSauron_RingHero

  • Objects built using the Respawn buttons of fortress CommandSets. Only relevant for human player (and SkirmishAI_1)!
  • The entries are IRRELEVANT for SkirmishAI_2!!!

  •               
    Code
    InitialUpgrades = Upgrade_IsengardDualEconomyChoice Upgrade_IsengardFaction Upgrade_EvilDualEconomyChoice

  • Starting PLAYER (global) upgrades (somewhat like the SCIENCES) which can be used to identify the faction within codes by the 'TriggeredBy =' -line in various behaviours.

  •               
    Code
    SpellStoreCurrentPowerLabel = APT:SpellStoreCurrentRingPower
    SpellStoreMaximumPowerLabel = APT:SpellStoreMaximumRingPower

  • I never checked, but i assume this are grfical elements of the SpellBook powers stuff (the filling circles etc.)

  •               
    Code
    ResourceModifierObjectFilter = RESOURCE_MODIFIER_OBJECT_FILTER
    ResourceModifierValues = 100 100 100 95 90 85 80 75 71 68 66

  • This list can be changed and extended as you wish. It reduces the output of resource buildings after the first 3 are built, presumably to a) give a losing player still a chance and b) reflect the fact that later structures are built farther from the economic center. The macro RESOURCE_MODIFIER_OBJECT_FILTER is defined in 'gamedata.ini' and lists all standard resource buildings. Only those objects in the list will count for this reduction.

  •               
    Code
    MultiSelectionPortrait = UPIsengard_Army

  • If you select more than one troop type, this is what the portrait will look like.

  •               
    Code
    LoadScreenMusic = Shell2MusicForLoadScreen

  • Custom music when starting a skirmish game while playing this faction. Defined in 'music.ini' (it's a variable multisound).



  • ********************
    In the faction setup, we have come across the following vital piece of code:
                  
    Code
    DefaultPlayerAIType = IsengardSkirmishAI

    This entry will lead us to the next file...




    ---- PLAYERAITYPES

    In the file 'data\ini\playeraitypes.ini' you will find the following code (here is the Isengard section):
                  
    Code
    PlayerAIType IsengardAI
        LibraryMap = "Libraries\AI_Men Of The West\AI_Men Of The West.map"
    End

    PlayerAIType IsengardSkirmishAI
        LibraryMap = "Libraries\AI_Men Of The West\AI_Men Of The West.map"
    End


    These two are the reference names of the script pack used for the AI. If you look over them you will find that ALL OF THEM use the same files, 'AI_Men Of The West.map'. This was different in BfMe1, where every faction had it's own pack. For SkirmishAI_2 this isn't needed. 'AI_Men Of The West.map' doesn't inherit any Faction-specific scripts. In fact the only piece of real interest contained in it are the scripts for SpellPurchase, which has it's own routines to distinguish between the factions. In case you are aiming to adjust the AI via scripts (or even completely overhauling the AI), this is where you can reference a new pack.


    - continued on next page -

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Comments

    Display order: Newest first | Page: 1, 2

    Prolong - Thursday July 29, 2010 - 9:21

    Very nice guide, even though it never got finished there is still a ton of great information here.

    Elrond99 - Sunday February 15, 2009 - 7:52

    Thanks for updating the Tutorial
    It´s great to hear that it´s possible to make a new AI from scratch

    Can´t wait for section F, custom AI scripts, that sounds really interesting
    Especially since I know D and E already ;)

    Sulherokhh (Team Chamber Member) - Saturday February 14, 2009 - 21:19

    After 'D. The Faction Base and Fortress', i guess.
    If you are asking for a date, you are asking the wrong guy. I don't have one. I work on modding related stuff mostly when i find the time and the mood strikes me. It's supposed to be fun, right? :)

    Edit: But i might do it before the fortress and base setup. Depends on, well, which kind of work is going to be most interesting to me at the time. Scripts should be easier to do then the Basebuilding stuff, but a bit more to write as well, at least if i am going to do it right. I am starting to ramble... :O

    jakonic - Saturday February 14, 2009 - 12:05

    when will be finished Spell Purchase Scripts???please answer

    Sulherokhh (Team Chamber Member) - Thursday November 29, 2007 - 17:26

    I sure will...

    Edit: Do you have any particular requests? If i have done it already, it shouldn't be hard to post a solution here. If it's not, chances are that i was going to look into it anyway. Except for the general skirmishsetup and bases, since those will require extesive explanations which i was planning to do anyway when i find the time.

    So shoot! :)

    Rob38 (Team Chamber Member) - Thursday November 29, 2007 - 11:00

    This is by far one of my favorite tutorials on T3A! Please continue to add more :)

    Sulherokhh (Team Chamber Member) - Wednesday October 3, 2007 - 23:07

    I am glad you can put it to use, Rob! Your feedback means a lot to me. :D

    Rob38 (Team Chamber Member) - Wednesday October 3, 2007 - 22:27

    Amazing! I also found a way to recognize if a player is controlled by the AI, but this looks to be a much easier method to use. Thank you for all your wonderful knowledge as there is some really cool stuff in here.

    Sulherokhh (Team Chamber Member) - Wednesday October 3, 2007 - 19:18

    I'll split it up. Let's see what would be a good way. - Edit: Done. I hope you like it.

    Crashdoc - Wednesday October 3, 2007 - 16:48

    Nice findings and interesting ways to use them. Thanks for sharing the knowledge!

    Go to top

     

    "One site to rule them all, one site to find them,
    one site to host them all, and on the network bind them."

     
    10:00:35