• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

unmerged(174159)

Still Alive
2 Badges
Oct 18, 2009
4.525
54
  • Crusader Kings II
  • Darkest Hour

ARE YOU A WIZARD?!
IF SO, WE NEED YOU!


AI fixing is one of the most difficult to perfect but also one of the most rewarding disciplines. It is a hard art to perfect, but when done right, can be amazing. Plenty of Mods suffer from poor AI optimisation - so a place where those who are in the know, can teach and show their skills in the art can only be a good thing. Right?
This is also the place to put your general AI questions etc.

"Do not meddle in the affairs of wizards, for they are subtle and quick to anger."
-Gildor Inglorion
 
Last edited:
  • 1Like
Reactions:
Any good online resources for existing AI files? That would be quicker than writing them all out by one's self
 
I was planning to contact Lothos with some quick questions about AI in this game engine. FODD mod has AI files for every nation but I have done so little testing and customisation apart from setting trade, tech and diplomacy priorities. I have no idea how the various land, air and naval AI settings actually influence AI nation behaviour. If I get an answer from Lothos, I'll share it here.

AI testing could be very time consuming.

Cheers,
Sword
 
On that note, would it be permissible to perhaps post some of this documentation online? I know most people come here looking for answers rather than nosing around their install folder.
 
DH AI Modding Documentation said:
Code:
# NOTE: Parameters marked "CHANGE" or "NEW" are not yet implemented.

switch = [yes/no]            # Default is "yes". If turned off, the AI will not automatically try to switch to a more appropriate AI file every year.

# Inter-Agent distribution variables

flags = {
      testflag = yes
      invade_albania = no
      assist_finland = no
    }

# Modifier to chance that country will accept a demand for territory.
claim_acceptance = X 

# The countries we will demand territory from if we have claims on them.
demand_claims = {
    EST
    LAT
    ROM
    LIT
    FIN
}

# The countries we will set free if we control their territory.
liberate = {
    LIT
    FIN
}


# Special resistance against "influence" by the listed nations. Value range = [0 - 10]
resistance = { 
    ROM = 8
}

# Country tags listed with a value specifying how much we want to destroy them.
combat = {
    ENG = 60
    FRA = 70
}
# Countries listed here are considered withing our 'sphere of influence'. We will strive to guarantee their independence.
protect = {
    TUR = 100
    DAN = 100
}
# Countries listed here are considered our natural allies. We will try to influence them and ally with them.
befriend = {
    TUR = 100
    DAN = 100
}

# Provinces with an assigned priority. These are strategic goals for the AI (it will try to take them in wars and demand them in peace treaties.)
target = {
    324 = 50 # 1 - 100
}


upgrading = 0.1        #max % of ic used on this slider.
reinforcement = 0.1    #max % of ic used on this slider.

desperation = 0.3    #If more than this % of ic is occupied by enemy, panic and build militia hordes.


# The ETA at which the AI uses strat. redeploy.
strat_redeploy_threshold = [days]

# Proportion of divisions that may be strategically redeploying at the same time. Default: 0.25
max_redeploying = X

# if the ai should use offensive supply
use_offensive_supply = yes/no

# only use offensive supply if the fuel needed for it is less than this divided by unit strength. Default: 100
max_fuel_offensive = x

#if ai should evacuate troops from island with low value
evac_islands = yes/no

# The "war monger" value affects the propensity of a country for declaring wars:
war = 50

# The tendency of a nation to create and accept alliances, and accept military access. The higher the value, the more "neutral" the nation. NOTE: this does not affect the tendency of a nation to start wars.
neutrality = 0 # Total neutrality at about 100 to 150

max_front_ratio            = X        # The max wanted friendly-to-enemy division ratio along the front. Default is 4.0.
max_front_ratios = {             # Override the default against specific countries. Ignored against humans.
    FIN = 2.0 
    ... 
}

# Proportion of our land divisions that we are prepared to relinquish control over.
# NOTE: Do not set too low - the AI must be allowed to give over control of its forces in "allied war zones". Default: 0.75.
exp_force_ratio            = 0.75

# Will never send exp. forces _overseas_ to these countries:
# NOTE: May still give some to neighboring allies though.
no_exp_forces_to = {
    TAG
    ...
}

max_garrison_prop        = [0.0-1.0]     # The war-time desired proportion of troops allocated to garrison duty
min_garrison_prop        = [0.0-1.0]     # The war-time minimum proportion of troops allocated to garrison duty
# NOTE: In areas without fronts, _all_ land units are controlled by the Garrison AI (except forces preparing for an invasion.)

construction = {
    max_factor            = [0.0-1.0]        # Proportion of Production IC that should be used for province buildings.

    AA_batteries         = [yes/no/atwar/not_atwar]    # yes = all the time, no = none, atwar = build during wars, not_atwar = build during peace
    max_AA_level        = X                # Don't improve beyond this level.
    AA_provs            = { ... }        # List of prioritized provinces

    coastal_fort         = [yes/no/atwar/not_atwar]
    max_coastal_level    = X                # Don't improve beyond this level.
    coastal_fort_provs    = { ... }        # List of prioritized provinces

    radar_station         = [yes/no/atwar/not_atwar]
    max_radar            = X                # Don't improve beyond this level.
    radar_provs            = { ... }        # List of prioritized provinces

    air_base             = [yes/no/atwar/not_atwar]
    max_air_base        = X                # Don't improve beyond this level.
    air_base_provs        = { ... }        # List of prioritized provinces

    naval_base             = [yes/no/atwar/not_atwar]
    max_naval_base        = X                # Don't improve beyond this level.
    naval_base_provs        = { ... }    # List of prioritized provinces

    land_fort            = [yes/no/atwar/not_atwar]
    max_land_level        = X                # Don't improve land forts beyond this level.
    fort_borders = {                    # Build land forts along these borders
        GER,
        ITA,
        ...
    }
    fort_provs        = { ... }    # List of prioritized provinces

    ic_at_war            = [yes/no]         # Normally, we always build IC if there is a large resource surplus. The exception could be during wars.
    force_ic_until        = X                # Ignore presence of a resource surplus and build IC anyway, until year X. (Useful for countries anticipating expansion.)
    ic_end_year            = X                # Stop building IC at the end of year X.
    IC_provs            = { ... }        # List of prioritized provinces

    nuclear_reactor = [yes/no/atwar/not_atwar]    
    nuclear_reactor_prov = province                #province ai will try to build nuclear reactors in
    max_nuclear = 10                    #max nuclear reactor size ai will try to get
    rocket_test = [yes/no/atwar/not_atwar]                        
    rocket_test_prov = province                #province to build rocket test site in
    max_rocket = 10                     #max rocket test site size
}

garrison = {

    # OVERSEAS GARRISONING:
    defend_overseas_beaches = [yes/no] # "no" is default

    # Basic need is X divisions per area where X is: number of provinces - attrition provinces
    home_multiplier = X # In home area, multiply basic need by X. Default: 0.5
    overseas_multiplier = X # In other area, multiply basic need by X. Default: 0.3333
    home_peace_cap = X # If at peace, we need at most X divisions in our capital area.
    war_zone_odds = X  # Default: 2.0 (strive to transport in 2x enemy nr of divisions)
    area_multiplier = { # If an area contains a specific province, multiply the basic need by value (overrides overseas_multiplier, but if it is the home area it is ignored.)
        155 = 1.5
        ....
    }

    # PRIORITIES:

    beach = 50                    # Beach prio
    capital = 100                # Our capital
    human_border = 210            # Ignored for allied human players
    war_target = 100            # The next country targeted for attack by this AI

    reserves = 20    # bonus for provinces just behind a frontline.

    opposing_alliance = 100        # For neutrals, all alliances are "opposing"
    claim_threat = 100            # If we are neutral, countries with claims on us get this
    unstable_border    = 50        # Bordering countries at war with someone else get this

    # Borders with specific countries
    country_priorities = {
        ENG = 30
        FRA = -1     # Override "opposing_alliance", "claim_threat" and "unstable_border" values and set to 0.
        ...
        ...
    }

    # Specific provinces
    province_priorities = {
        527 = 50     # Province 527 has prio 50
        1123 = -1    # Negative value will override _all_ other priorities and set to 0.
        ...
    }
    
    ignore = {
        1123    #Will set prio to 0...
    }

    key_point_prio_mult        = [Value]    # Value * key point value in a province = prio for that province
}

front = {
    river =         x       (What to multiply attacking power with if crossing a river. < 1.0 is an advantage..)

    # the following modifies the odds-strength for defender.   (1.0 = no difference.)
    largefort     = x #for forts above level 6.
    smallfort    = x #for forts 6 and below
    occupied    = x #for surrounded pocket at enemy territory
    owned        = x #for surrounded pocket at own territory

    #Odds modifiying variables
    # the following is to reduce odds-strength for attacker.
    frozen_attack     = 0.50
    snow_attack     = 0.50
    blizzard_attack = 0.25
    storm_attack     = 0.60
    muddy_attack     = 0.75

    #reduces the size of odds in total.. (1.0 = no difference, 0.5 = halved.)
    jungle_attack     = 0.85
    mountain_attack    = 0.60
    swamp_attack     = 0.60
    forest_attack     = 0.85
    hill_attack     = 0.75
    urban_attack     = 0.40
    
    # Proportion of divisions in a front province that may be used to support the defense of neighboring provinces. Default 0.33
    support_defense_prop = X

    recklessness         =     [0-3]
    
    # Even - Distribute forces evenly along the whole front.
    # Reactive - Try to match enemy troop concentrations.
    # Defensive - More troops in strategically important provinces (IC, Victory Points, Oil, etc)
    # Offensive - Concentrate more troops where the enemy us weak
    # Operational Defensive - The fewer avenues of escape, the less troops (to avoid encirclement.)
    distrib_vs_ai         =     [even/reactive/defensive/offensive/op_defensive]
    distrib_vs_human     =     [even/reactive/defensive/offensive/op_defensive]

    # Countries we do not counter-attack for a certain number of days
    enemy_handicap = {
        # NOTE: These values are ignored for human-controlled enemies.
        # CAUTION: Values apply for _every_new_ war with a set nation.
        ENG = 100
        FRA = 120
        ...
        ...
    }

    passivity = { # Against specified enemies.
        # Valid values: 0-100 (%)
        ENG = 0
        FRA = 50
        ...
        ...
    }
    
    province_priorities = {
        527 = 0.2    #Only assign 20% of desired forces to cover the province 527
        ...
    }
    

    reserve_prop            =     [0.0-1.0]    # Maximum proportion of total divisions in a front allowed to remain behind the front line ( HQs and divisions needing to recover.)

    panic_ratio_vs_ai        =    X    # Front requests more troops if outnumbered by this factor. NOTE: this results in troops being drawn from garrison duties, etc, so set HIGH.
    panic_ratio_vs_human    =    X    # Front requests more troops if outnumbered by this factor. NOTE: this results in troops being drawn from garrison duties, etc, so set HIGH.

    enemy_reinf_days         =     X    # Count enemy units less than X days from a target province in odds calculations

    base_attack_odds        =    X    # Will attack at X odds or better
    min_attack_odds            =    X    # If stalemated for a long period, may go as low as these attack odds
    max_attack_odds            =    X    # Don't use more force than necessary to reach these odds
    reinforce_odds            =    X     # Send in more troops if the attacking force is at these odds
    withdraw_odds            =     X    # Break off attacks and withdraw at these odds
    # NOTE: the calculations for retreating from _defensive_ positions are too complex to condense to a few variables
    # NOTE: will _also_ retreat if the average organization is too low
}

military = {
    relative_build_scheme     = [yes/no]    # Should the AI strive to maintain a relative balance between unit types [yes] or simply allocate percentages (see below) of the total production [no]. Default: yes

    max_batch_peace = 800                    # Max production run length in DAYS while at peace
    max_batch_war = 500                         # Max production run length in DAYS while at war with no home front
    max_batch_home_front = 190                # Max production run length in DAYS while at war with home fronts
    # NOTE: AI production run size is also limited by other factors, such as Total IC capacity, days until end of scenario, and desperation.

# Example Build scheme:
    infantry =         3
    cavalry =         0
    motorized =     5
    mechanized =     6
    light_armor =     0
    armor =         10
    paratrooper =     0
    marine =         6
    bergsjaeger =     3
    garrison =         0
    hq =             2
    militia =         0
                    # 35 %

    multi_role =     7
    interceptor =     3
    strategic_bomber = 4
    tactical_bomber = 6
    naval_bomber =     5
    cas =             5
    transport_plane = 0
    flying_bomb =     0
    flying_rocket = 0
                    # 35 %

    battleship =     2
    light_cruiser = 4
    heavy_cruiser = 3
    battlecruiser = 0
    destroyer =     6
    carrier =         6
    escort_carrier = 0
    submarine =     4
    nuclear_submarine = 0
    transport =     5
                    # 30 %
# NOTE: The sum _must_ be exactly 100%!


# Brigade preferences:
# (% of eligible division types that should be built with a certain brigade type)
# Land types:
    artillery            =    15
    sp_artillery        =    5
    rocket_artillery    =    0
    sp_rocket_artillery    =    2
    anti_tank            =    3
    tank_destroyer        =    5
    light_armor_brigade    =    0
    heavy_armor            =    0
    super_heavy_armor    =    0
    armored_car            =    0
    anti_air            =    5
    police                =    0
    engineer            =     5
# Sum of these should be <= 100

# Naval types:
    cag                =    100
# Sum of these should be <= 100

#The AI will always build escort fighters when it builds tactical bombers and strategic bombers.



}


# bomber is now obsolete and NOT USED AT ALL replace and use Air Marshal instead

air_marshal = {
    icxdayscostfactor = 10.0        # How to value true industrial cost when calculating expect causalties
    manpowercostfactor = 100.0        # How to value manpower cost when calculating expect causalties
    destructionriskthreashold = 0.2        # when to fear a divisiopn might be destroyed

    airsuperioritydesirability = 10.0    # desirability is a multiplier used when calcualting the mission desirability
    airsuperioritylosstolerance = 1.0    # tolerance is the required kill:loss ration expected to do mission, 2.0 accept twice the losses of your enemy, 0.5 accept half
    groundattacklosstolerance = 1.0
    groundattackdesirability = 1.0
    interdictionlosstolerance = 1.5
    inderdictiondesirability = 1.0
    logisticalstrikelosstolerance = 4.5
    logisticalstrikeefficency = 0.01    # efficency is a tweakable param to adjust according to how much actual damage comes from doing this mission (not to be confused with desirability)
    logisticalstrikedesirability = 100000.0
    runwaycrateringlosstolerance = 1.5
    runwaycrateringefficency = 0.01
    runwaycrateringdesirability = 20000.0
    strategicstriketolerance = 4.5
    strategicstrikeefficency = 0.01
    strategicstrikedesirability = 1000000.0
    installationstriketolerance = 1.5
    installationstrikeefficency = 0.01
    installationstrikedesirability = 10.0
    navalstriketolerance = 1.0
    navalstrikedesirability = 10.0
    portstriketolerance = 1.0
    portstrikedesirability = 9.0
    portstriketolerance = 1.0
    portstrikedesirability = 0.0


    # You can have any number of task forces, but if you add one you must add ALL the kinds you want
    # as then the defaults aren't set.
    
    # The defaults currently are:
    taskforcetype = { 
        name = "Air Superiority" # Name can be anything and is only used to ease debugging
        
        desiredratio = 0.400 # What ratio taskforces of this type should a nation try to form?        
        
        rangeweight = 10.000 # How important the range for an air divisions in this taskforce-type?
        airkillpowerweight = 2000.000 # How important is an air divisions ability to kill air in this taskforce-type?
        hardkillpowerweight = 0.000 
        softkillpowerweight = 0.000  
        navalkillpowerweight = 0.000 
        strategickillpowerweight = 0.000 
        
        transportcapacityweight = -1000000.000 # A huge negative number here keeps transports out of this taskforce-type
        
        airvulnurabilityweight = -1.000  # How bad is being vulnurable to enemy air (vulnurable is a mix of cost and defence value)
        surfacevulnurabilityweight = 0.000 
        
        # What AI missions should this task force consider?
        # Idle is the "mission" the AI is on when doing nothing,
        # Reorganize is the "mission" the AI is on when trying to reform its
        # air OOB to be more optimal. The other missions listed here correspond
        # to the standard tactical missions AND a rebase to the best airbase.
        
        # Possible missions are:             
        idle = yes 
        reorganize = yes 
        air_superiority = yes 
        #Others not supported by the "Air Superiority" default taskforce type
        #interdiction
        #ground_attack
        #logistical_strike
        #runway_cratering
        #strategic_bombardment
        #installation_strike
        #naval_strike
        #port_strike
        #convoy_air_raiding
        #airborne_assault
        #air_supply    
    } 
    
    # the other defaults
    taskforcetype = { name = "Soft Bombing" desiredratio = 0.200 rangeweight = 10.000 airkillpowerweight = 0.000 hardkillpowerweight = 0.000 softkillpowerweight = 2000.000 navalkillpowerweight = 0.000 strategickillpowerweight = 0.000 transportcapacityweight = -1000000.000 airvulnurabilityweight = 0.000 surfacevulnurabilityweight = -1.000 idle = yes reorganize = yes interdiction = yes ground_attack = yes } 
    taskforcetype = { name = "Hard Bombing" desiredratio = 0.100 rangeweight = 10.000 airkillpowerweight = 0.000 hardkillpowerweight = 2000.000 softkillpowerweight = 0.000 navalkillpowerweight = 0.000 strategickillpowerweight = 0.000 transportcapacityweight = -1000000.000 airvulnurabilityweight = 0.000 surfacevulnurabilityweight = -1.000 idle = yes reorganize = yes interdiction = yes ground_attack = yes } 
    taskforcetype = { name = "Strategic Bombing" desiredratio = 0.100 rangeweight = 10.000 airkillpowerweight = 0.000 hardkillpowerweight = 0.000 softkillpowerweight = 0.000 navalkillpowerweight = 0.000 strategickillpowerweight = 2000.000 transportcapacityweight = -1000000.000 airvulnurabilityweight = -0.500 surfacevulnurabilityweight = -0.500 idle = yes reorganize = yes logistical_strike = yes runway_cratering = yes strategic_bombardment = yes installation_strike = yes } 
    taskforcetype = { name = "Naval Bombing" desiredratio = 0.100 rangeweight = 10.000 airkillpowerweight = 0.000 hardkillpowerweight = 0.000 softkillpowerweight = 0.000 navalkillpowerweight = 2000.000 strategickillpowerweight = 0.000 transportcapacityweight = -1000000.000 airvulnurabilityweight = 0.000 surfacevulnurabilityweight = -1.000 idle = yes reorganize = yes naval_strike = yes port_strike = yes convoy_air_raiding = yes } 
    taskforcetype = { name = "Airlift" desiredratio = 0.100 rangeweight = 10.000 airkillpowerweight = 0.000 hardkillpowerweight = -2000.000 softkillpowerweight = -2000.000 navalkillpowerweight = 0.000 strategickillpowerweight = -2000.000 transportcapacityweight = 1000000.000 airvulnurabilityweight = -1.000 surfacevulnurabilityweight = 0.000 idle = yes reorganize = yes airborne_assault = yes air_supply = yes } 

}



#The number of leaders of a given type is equal to the number of units multiplied with the leader_rartio.
#For example if you have 101 land units and land_field_marsal = 0.02 you will have two field marshals.
#For example if you have 101 sea units and sea_admiral = 0.06 you will have six admirals.
leader_ratio = {
    land_field_marshal =0.02
    land_general =0.031
    land_lt_general =0.41

    sea_grand_admiral =0.02
    sea_admiral =0.061
    sea_vice_admiral =0.401

    air_marshal =0.02
    air_general =0.091
    air_lt_General =0.11



}



#Factors regarding amphibious invasions by ai.
invasion = {
      #for evaluating specific province target.
    base = 1.0                        # Relative modifier. (lower = specific targets much more important.)
    random = 1.0                    # How big a random range.  (1.0 = 1%)
    coastal = 1.0                   # increase to avoid coastal forts more.
    beach = 1.0                     # higher, avoid worst beaches.
    distance = 1.0                  # higher = avoid long distance.
    max_distance = 20.0                # ignore distances at higher distance than this.. 1 = 100km ingame.
    pocket = 1.0                    # prioritise pockets, ie provinces with no adjacent controlled by same.
    island = 1.0                    # prioritise taking pure islands.
    enemy = 1.0                     # higher = much more wary of troops in province.
    adjacentenemy = 1.0             # higher = much more wary of troops nearby
    air_base    = 0.1               # add this priority for air bases within adjacentenemy
    naval_base    = 0.1                # add this priority for naval bases within adjacentenemy
    air_support    = 0.1               # add this priority for beaches within reach of air_bases
    ignore = [yes/no]                # Launch invasions even if we have a home front. Default: no.
    province_priorities = [yes/no]    # Invade only provinces from target = { … } list with priority higher then 0. Default: no.
    
    redirect      = priority/nearest/home   # priority refers to targets in the AI file,
                                            # nearest is the closest enemy beach where the AI has
                                            # good attack odds and home is to return back to port

    #specific provinces can be targetted to get special bonuses..
    target = {
        898 = 1000 # Invasion of South Sicily (898) has super high priority. Negative values preclude invasions there.
    }
}

#Factors controlling the naval AI
admiral = {
    #specific provinces can be targetted to get special bonuses..
    target = {
        592 = 200 # patrolling the south north sea have a big priority.
        ...
    }

    #This is used to determine that it's a core seazone and its control is important.
    core = {
        592
        ...
    }
    
    #Which provinces to use as bases..
    base = {
        592
        ...
    }
    
    #Which areas to ignore.
    ignore = {
        #PLEASE NOTE THAT ITS AREAS..  Not province-names
        "northern baltic"
        "southern baltic"
    }

    min_org        = 95%    # NEW: Percent of org gained back before the unit can leave port
    min_dmg        = 95%   # NEW: Percent of dmg gained back before the unit can leave port
    return_org     = 60%     # NEW: PERCENT OF ORG LOST BEFORE RETURNING TO PORT applies to all fleets/ships
    return_dmg     = 50%     # NEW: PERCENT OF DMG LOST BEFORE RETURNING TO PORT for repairs applies to all fleets/ships

}


# Factors to modify for technological development.
technology = {
    endgoal = { ... }            #list of endgoals to achieve.
    preference = { ... }        # list of techs to give bonus too.
    ignore = { ... }             # Techs we will never research

    #preference to weight importance of research in these field.s
    armor = 2.0
    infantry = 3.0
    industry = 2.5
    aircraft = 0.6
    naval = 0.1
    land_doctrines = 4.0
    air_doctrines = 0.9
    naval_doctrines = 0.1
    secret_weapons = 0.4
}

# Factors to modify Trade Agreements.
trade = {
    favored = {
        TAG = X      # Preferred Countries to trade resources with.
    }
    embargo = {
        TAG          # Will not trade resources with these countries.
    }
    
    # A threshold for when the AI should cancel trade agreements. Default is 4.0. A lower value means the AI will be more eager to cancel bad deals.
    cancel_deal_threshold = X        

    # These override the resource values in "db\resource_values.csv" for this AI unless set to -1 (default.)
    energy =             -1
    rare_materials =     -1
    metal =                -1
    oil =                 -1
    supplies =             -1
    money =             -1
}

# Factors to modify Tech Sharing
tech_sharing = {
    favored = {
        TAG = X      # Preferred Countries to trade techs with. Higher value also means better techs.
        ...
    }
    embargo = {
        TAG          # Will not trade techs with these countries.
        ...
    }
    not = {
        ID          # List of techs never to trade.
        ...
    }
    prioritized
        ID = X      # Priority to accepting trades with these techs.
        ...
    }
}

#prevents ai from accepting peace deals

ferocity = yes

#controls how much forces ai can send to different countries (not implemented internally)

exp_force_ratios = {
    USA = 0.75
    ENG = 0.25
} 



################################################## #########
# SPY
################################################## #########



spyprefs =
{
percentage_on_spies = 0.2
#percentage_on_spies: the amount of the income a country will spend on intelligence.

percentage_foreign_mission = 0.7
#The amount of the income a country will spend on intelligence.

spyprefsdata =
{
    country_priorities= 10
    #Is an integer value between 0 and 10. The higher the value is the more spy actions will be preformed in the target nation.

    number_of_spies10
    #This is the number of spies a nation desire too has in the target nation.

    min_number_of_spies = 2
    #When this number is reacted a nation will start to do spy action in the target nation.
    
    #All the values below must be integers.
    steal_blueprint = 10
    minister_assassination = 15
    smear_campaign = 1
    coup = 1
    sabotage_industry = 10
    nuclear_sabotage = 0
    found_partisans = 0
    massmedia = 0
    counter_espionage = 2
    disrupt_techteam = 1

    #The target country.
    country = USA
}

# when country is the same as the AI file that data will be used for intelligence protecting the country i.e. counter espionage.
spyprefsdata = 
{
    NumberOfSpies = 3
    counter_espionage =  10
    country =     GER
}

#An Example :

#steal_blueprint = 10
#minister_assassination = 1
#sabotage_industry = 20

#In the long run the nation will perform 10 more “steal_blueprint” then minister_assassination and 10 more “sabotage_industry” then “steal_blueprint”.}
Code:
Invasion AI (Armageddon / Darkest Hour 1.00)

1. Controlled AIs do not invade
2. invasion = yes    #Allow/Disallow invasions
3. ignore    = yes     #Should launch invasions if there is home front (land border with enemy at the area where the capital is)?
4. Check for available transports. Used to determine max invasions:
    TP > 40 -> 4
    TP > 20 -> 3
    TP > 10 -> 2
    TP > 1    -> 1
5. Check for currently started invasions (this includes invasions still in preparation). Should be less the the number calculated in (4)
6. Creates a list of all curent enemies
7. help_allies     = yes/no. Check if there is ally (country in the same alliance!!!) in need:
    - AI country should be at war
    - The ally should not be in no_exp_forces_to = { } list!!!
    - The ally should be AI controlled too
    - Allies are checked one by one, starting with the first country in the alliance
    - All land areas controlled by that ally are checked one by one. First arrea that has a port, is war zone and the ally needs more divisions is returned.
8. List of all available for invasion land units is created. That excludes all units currently in combat, borbardment, retreat, loaded on ships/transport planes, garrisons, locked for movement, paratroops, located in front provinces or already assigned to a front or for transportation.
9. Then the best unit (highest score) for invasion is selected among the list created in (8). This is based on factors like (- for negative, + for positive):
    - Cuurent Location lacking units * 10
    - Distance to the target province (usually it is 0 as target is not set yet)
    - Average STR damage for the unit (0 to 100)
    + Count of Marines * 100
    + Count of MTN * 50
    - Count of MIL * 50
    - Count of CAV * 10
    - -100 points if the unit is originally from another country
    -/+ -100 points if the unit is in the Home area and home is treaten (bordering enemy) ELSE +150 points
10. Check for a port in Home Area. If not -> halts all invasions.
11. Takes the enemies list created in (6) and search for best invasion target. For each enemy country, for every land area:
    - skip areas already targeted by another invasion
    - skip areas without provinces that can be invaded by sea
    - skip areas which sea provinces cannot be reached (pass Suez, Gibraltar etc.)
    For each province in area check:
    - skip no coast or no beach provinces
    - skip provinces with no, less or equal to 0.0 priority set in target = { ... } list if province_priorities parameter is set to "yes" 
    - skip islands with value less then 50 points or no positive value in target = { ... } list (NEW for Darkest Hour). Value = VP * 100 + Naval Base * 10 + Air base * 10 + Max IC * 20 + Oil prod. * 10 + Rares prod. * 10 + Metal prod. * 2 + Energy prod.
    - skip provinces already targeted for invasion
    - skip Rebel controlled provinces if prov. owner is another country
    Calculates needed for invasion divisions. This is quite complex logic, taking into account enemy units on the beach and provinces around, distance to the targeted province, defending units type and strength, friendly units in the area that could help and so on.
    - skip province if there is an Ally in need (7) and needed invasion force is more then 3 divisions
    - skip province if needed invasion force is more then then the size of the best unit (9).
    - skip province if there are not enough TPs available: (All TPs / (1 + current invasions)) < (Needed Div / 2)
    - skip province if its value in target = { ... } list is less then 0. Doesn't skip provinces not in the list!!!
    Calculates invasion score of the province: 
        score = target = { ... } value / (<base> value + 0.01) # Province not found in the list gets 0 score
        score = score + (10 * [Max of 1 or rounded <random> value from AI prefs]) # In total this random component adds 10 or more points (80 for random = 8.0)
    - skip province if naval distance to it is greater then <max_distance>
    - Reduce score based on distance and <distance> AI parameter:
        score = score - (10 * distance * <distance>)
    - Reduce score if there are defending enemy units in the province and coastal forts:
        score = score - ( 100 * Coastal level in the province * <coastal> )
    - Modifies score of island provinces(areas with just one province) using <island> AI parameter:
        score = score + ( (<island> - 1)*1000)
    - Modifies score of areas with just one province by <pocket>. Note: this applies to islands too!
        score = score + ( <pocket> - 1)*1000)
    - Reduce score if there are land units in the province, based on <enemy> AI parameter:
        score = score - ( <enemy> * total land unit size in the province * 200 )
    - Modifies score if there is air base in the province by <air_base> AI parameter:
        score = score + ( <air_base> * Air base size * 100 )
    - Modifies score if there is naval base in the province by <naval_base> AI parameter:
        score = score + ( <naval_base> * Naval base size * 100 )    
    Check enemy neighboring provinces that are not impassable. For each province modify score by:
        score = score - ( <adjacentenemy> * total land unit size in the province * 20 )
        score = score + ( <air_base> * Air base size * 20 )
        score = score + ( <naval_base> * Naval base size * 20 )
    NOTE: Skip province if any of the adjacent provinces is allied controlled!!!
    Check if this province scores are higher then all currently checked and only if it is so:
    Check for closest staging province (from which we can launch the invasion). Allied provinces that can be reached are checked too.
        - skip province if distance to it from the closest staging province (calculated above) is highre then <max_staging_distance> AI parameter
        - else select this province as best target for invasion
12. Return if no good invasion province was found, else continue
13. Calculates again needed invasion army size, this time to for the selected target. It could be a at least 1 unit and is set to 3 if there are anough units, transports and enemy area has more then 3 provinces
14. Calculatest best province to launch invasion from. Allied provinces included too:
    - province should be coastal
    - province should have naval base
    - province should not be already selected for another invasion
    - distance from that province to invasion target should be less then <max_staging_distance> AI parameter
    - province should have a sea zone
    - that sea zone should be reachable from the country (Suez, Gibraltar Panama etc. could prevent access to it)
    - Modify score by distance from staging to invasion target province:
        score = -(Naval Distance between the two)
    - Modify score if selected for the invasion army:
        is already in the province (score = score + Army size*2) 
        or in the same area (score = score + Army size) 
    - Modify score if this province is in the home area (where the capital is)
        score = score + 3
    - Check if the province is in staging_province = { ... } list and adds bonus if so:
        score = score + 7
    - Check if this is the only province in the area (could be an island or province surrounded by another countries). If so reduce score by 4:
        score = score -4
    Check if current province scores are higher then the previous best and if so selects this one as best staging province. Then check the rest.
15. Return if no good staging province was found in (14)
16. Move selected invasion army (9) to the staging province (14) if not already there. Marks the army as invasion force prints to invasions.txt:
    "%s(COUNTRY) initializing invasion of %s(TARGET PROV) with %i(INVASION FORCE SIZE) (%i)(CALCULATED NEEDED SIZE) divisions from %s (STAGING PROVINCE)"
        
    
    
DEFAULT VALUES:
    
    _bInvade                    = true;

    _vBase                        =    1.0f;
    _vRandom                    =    1.0f;
    _vCoastal                    =    1.0f;
    _vBeach                        =    1.0f;
    _vDistance                    =    1.0f;
    _vMaxDistance                =    99999.0f;
    _vMaxStagingDistance        =    10.0f;
    _vPocket                    =    1.0f;
    _vIsland                    =    1.0f;
    _vEnemy                        =    1.0f;
    _vAdjacentEnemy                =    1.0f;

    _vAirBase                    =    0.1f;
    _vNavalBase                    =    0.1f;
    _vAirSupport                =    0.1f;

    _nRedirMode                    = _HOIIR_NEAREST_;

    _Ignore                        = false;
    _bHelpAllies                = true;
    
    
EXAMPLE:
    
    invasion            = yes    #Allow/Disallow invasions
     base                = 0.1    #Relative modifier. (lower = specific targets much more important.)    target value / (THIS + 0.01)
    random                = 8.0    #How big a random range.  (1.0 = 1%)
    coastal                = 0.1    #increase to avoid coastal forts more. (CF level * this * 100)
    beach                = 0.1    #higher, avoid worst beaches.
    max_distance          = 250.0  #About the distance from Japan to Batavia    NOTE: In-game distnace = This * 100 (km)
    max_staging_distance = 250    # How far should the staging area be from the target invasion point; NOTE: In-game distnace = This * 100 (km)
    distance            = 0.1    #higher = avoid long distance.
    pocket                = 20.0    #prioritise pockets, ie provinces with no adjacent controlled by same. Applies to islands too. (this - 1) * 1000
    island                = 0.1    #prioritise taking pure islands (one province). (this - 1) * 1000
    enemy                = 2.0    #higher = much more vary of troops in province.    ( this * total land unit size in the province * 200 )
    adjacentenemy         = 2.0    #higher = much more vary of troops nearby
    air_base            = 1.5     #Bonus to air bases( this * Air base size * 100 ), ( this* Air base size * 20 ) for adjacent enemy provinces
    naval_base             = 0.1     #Bonus to naval bases( this * Naval base size * 100 ), ( this* Air Naval size * 20 ) for adjacent enemy provinces
    air_support         = 3.0         # NOT USED!
    redirect             = priority     # NOT USED!
    ignore                = no    #Should launch invasions if there is home front?
    help_allies         = no     #[yes/no] Should send troops to help allied invasions too?
    
    staging_province = { ... }    # Adds bonus (+7) for provinces in that list when searching for best province to launch invasion from
    target = { ... }            # skip provinces with value less then 0

Enjoy
 
Last edited:
  • 1Like
Reactions:
When a country changes tag (eg, command = { type = country which = xxx } ) does its AI get reset to the default or does it retain the AI of its previous TAG?
 
How exactely do the mechanics behind
Code:
switch = [yes/no]            # Default is "yes". If turned off, the AI will not automatically try to switch to a more appropriate AI file every year.
and
Code:
flags = {
   testflag = yes
   invade_albania = no
   assist_finland = no
}

work? How is "a more appropriate AI file" defined? is that given just by the filename name (eg: USA_1984.ai)? Is it based on the flags? A combination of that?

Thanks for the input!
 
flags = {
testflag = yes
invade_albania = no
assist_finland = no
}

FLAGS... FLAGS... FLAGS...

What are flags?
I understand from the event notes, that a flag is something that is "a message" for either everyone, or (local) for that particular country.

BUT.. in looking at other people's events (especially the devs), I see flags tied into events. I don't understand why?

I think some are a placement for "this is linked to an ai file" of similar name.
Other times, the flag seems to "do something"..??

trigger = {
OR = {
alliance = { country = GER country = ITA }
AND = {
flag = JAP_Anti_comintern_pact
random = 10
}
AND = {
flag = NO_JAP_Anti_comintern_pact
random = 5
}.....

above code: ........... two choices, random 10 & 5... flag = NO_JAP_Anti-comintern_pact... it must link to a text file somewhere? Else it doesn't make sense...


I have searched every file to see if I can find any mention of flags, for particular instances of a flag, but haven't found any ... Searched all the docs, even Lothos's manual....

What are flags and what do they do ?... Is there a text file that contains the details of the "flag".
... Where is this file?

Please:rolleyes:
 
Last edited:
You can set or clear flags via events commands. They are then used as events triggers.
For instance an event can set the "Cold War" flag, which can be used as a trigger for CW specific decisions/events.

.. so I can use a flag as a trigger... will help with following event strings...

Very good! Thanks for clearing that up Fernando. CHEERS! :D
 
The AI's mobilisation events seem to be controlled by checking the MOB1 through MOB10 flags and adding and subtracting manpower depending on whether it's at war or not. Does that mean we shouldn't touch any of the MOB flags except for the AI loaded at the game's start? And does the AI never get a "reserves arrive" event to bump up land forces strength?
 
Unless I've missed something important, a flag is just another word for http://en.wikipedia.org/wiki/Boolean_data_type
Basically, yes.
Does that mean we shouldn't touch any of the MOB flags except for the AI loaded at the game's start?
As a general rule no, you should not touch them, unless you want to change the mobilization level of a country at scenario start.
And does the AI never get a "reserves arrive" event to bump up land forces strength?
Yes, it does, it's the same for everyone. Unless it is already mobilized at scenario start and the reserves already arrived
 
i want to stop canada from allying with UK, how do i do this?
 
befriend = {
CAN = 0
ENG = 0
}

For ENG and CAN respectively
 
I think it only ever adds new or overwrites existing fields so if the starting AI had a high befriend it would never be overwritten