鋼鐵雄心4中的 AI 可以在許多方面修改. 以下文件主要處理 AI:
- /Hearts of Iron IV/common/ai_areas
- /Hearts of Iron IV/common/ai_focuses
- /Hearts of Iron IV/common/ai_peace
- /Hearts of Iron IV/common/ai_strategy
- /Hearts of Iron IV/common/ai_strategy_plans
- /Hearts of Iron IV/common/ai_templates
- /Hearts of Iron IV/common/ai_attitudes.txt
- /Hearts of Iron IV/common/ai_personalities.txt
許多其他給玩家提供選擇的地方應附有 AI 傾向來表達 AI 對各選項的權衡,這些地方使用ai_will_do。
AI 傾向
這部分內容可能已不適合當前版本,最後更新於1.8。 |
正如在許多文件中看到的那樣,ai_will_do mb是一個為 AI 提供決策時權重的參數。在功能上它與 mean_time_to_happen 非常相似。它與其使用相同的修正系統,儘管它對 base 和 factor 有不同的解釋。
注意:AI 對這個參數的運算結果不是完全遵從的,而通常與 probability-proportional-to-size sampling 類似。
base
(Type: scoped variable, default: 1) 在應用其他修改前的基礎數值。
factor
(Type: number (with 3 decimal places), default: 1) 應用於計算的係數,
例子
ai_will_do = { base = 10.5 # may also be a variable # If the country is Germany, set the value to 0, # causing an early end of the evaluation. modifier = { tag = GER factor = 0 } modifier = { is_major = yes add = 1 } modifier = { factor = 3 add = 2.5 tag = FRA } factor = 2 }
假設正常計算,對於GER(德國) 結果為0,對於FRA(法國)結果為74,對於其餘主要國家為23,對於次要國家則為21。
AI 區域
這部分內容可能已不適合當前版本,最後更新於1.8。 |
/Hearts of Iron IV/common/ai_areas 直接控制了陸地省份在有命名的 AI 區域的分配。但它們只被下文定義的 AI 策略 area_priority
使用。 每個省份只被分配到一個 AI 區域,並且是第一個匹配的區域。沒必要將每個省份都分給 AI 區域,但未被分配的不能被 area_priority
策略調用。
在省份的 debug tooltip 可以看到 AI 區域。
這是一個通用示例:
<area name> = { # Used to add continents continents = { <continent> } # Used to add specific strategic regions strategic_regions = { <strategic region ids> } }
AI 國策
AI 和平策略
這部分內容可能已不適合當前版本,最後更新於1.5。 |
/Hearts of Iron IV/common/ai_peace 中的文件控制了 AI 如何完成和平會議。
There are five types of peace behaviour一共有 5 種 AI 和平策略:
- 內戰
- 民主主義
- 共產主義
- 法西斯主義
- 默認
和平會議一共有 5 種和平行動:
- 吞併國家
- 解放國家
- 傀儡國家
- 獲取土地
- 改變政府(原版民主主義專屬)
這是一個通用示例:
<type>_peace = { # Determines when this peace AI is used by the AI (ROOT is taker, FROM is giver) enable = { <triggers> } # Random factors applied to AI decision making when determining which # peace option to use. annex_randomness = <int> liberate_randomness = <int> puppet_randomness = <int> take_states_randomness = <int> force_government_randomness = <int> # Weighting towards the option. (ROOT is taker, FROM is giver) <peace option> = { factor = <float> <triggers> modifier = { factor = <float> <triggers> } } }
AI 策略
這部分內容可能已不適合當前版本,最後更新於1.8。 |
AI 策略影響在特定策略考量 (types) 中,其他 AI 組件中的決策形成,這也可以是定向的。例如一個國家可以在策略上對保護另一國家有興趣,而不考慮當前外交與同盟關係;或者它更傾向於訓練某一特定類型的師。
在結構層面,一個 AI 策略只有 4 個參數:type
,value
,id
,以及 target
。只有部分類型的 AI 策略使用了 id
和/或 target
。本來,4 個參數都是整型,但如果 type
先被指定,那麼id
參數可以用名字來調用對應的值(參考下文表格)。target_country
是另一種設置 target
的方式。它接受一個國家下標或國家 Tag,並會檢查其是否指向了一個可用的國家。
AI 會自己生成動態策略,但想添加靜態策略也是可行的。靜態策略的主要被/Hearts of Iron IV/common/ai_strategy中的 AI 策略條目 或 AI 策略計劃 定義(見下文)。領導人特質(/Hearts of Iron IV/common/country_leader中)可以修改 AI 策略,當特質攜帶者成為國家領導人時。獨立的策略也可以用add_ai_strategy命令直接添加(例如事件·,國策中,等等)。
一個國家有效的 AI 策略保存在保存文件中,作為該國的ai
屬性。
類型
定義 ai_strategy 時, 類型決定了 AI 策略改變的方面。 抵抗運動 dlc 中新增的 AI 策略可以在 common/ai_strategy/default.txt 中找到。
Type ID | Type | ID | Description | |
---|---|---|---|---|
45 | added_military_to_civilian_factory_ratio | Alters the Military-to-Civilian factory ratio. | ||
28 | air_factory_balance | Alters the Air factory ratio. | ||
8 | alliance | <tag> | Nudges diplomatic AI towards forming an alliance with another specified country. | |
3 | antagonize | <tag> | Nudges diplomatic AI towards being meaner to another specified country. | |
33 | area_priority | <ai_area> | Encourages the military AI to target specified AI area. | |
4 | befriend | <tag> | Nudges diplomatic AI towards being nicer to another specified country. | |
10 | build_airplane | Unused. | ||
11 | build_army | <unit role> | Orders the AI to build a type of division or equipment (as in air planes or ships) that belong to the specified unit role. | |
12 | build_building | <building> | Orders the AI to build a specific building in a specific location. Uses target to specify the state location. | |
9 | build_ship | Unused. | ||
56 | building_target | <building> | Orders the AI to build towards specified amount of <building>. This includes those already owned and acquired by trade (Civilian Factory). | |
1 | colonize | Unused. | ||
0 | conquer | <tag> | Encourages the military AI to target specified tag. | |
6 | consider_weak | <tag> | Nudges the AI disposition towards considering the specified tag weak. | |
17 | contain | <tag> | Nudges the diplomatic AI towards taking actions against another country, such as guaranteeing their future potential enemies. | |
41 | declare_war | <tag> | Nudges the AI disposition towards declaring war against the specified tag. | |
48 | dockyard_to_military_factory_ratio | Alters the Dockyard-to-Military factory ratio. | ||
49 | dont_defend_ally_borders | <tag> | Nudges the AI disposition towards not defending the specified ally's borders. | |
44 | dont_join_wars_with | <tag> | Nudges the AI disposition towards not defending the target country when the specified tag is involved. Uses target_country to define the target country. | |
29 | equipment_production_factor | <unit type> | Alters the equipment production disposition for the specified unit type. | |
31 | equipment_production_min_factories | <unit type> | Sets the minimum factory count needed to start equipment production for the specified unit type. | |
26 | equipment_stockpile_surplus_ratio | Sets the base equipment stockpile surplus value. | ||
30 | equipment_variant_production_factor | <equipment> | Alters the equipment variant production disposition for the specified equipment. | |
2 | explore | Unused. | ||
46 | factory_build_score_factor | Modifies the AI build disposition for a state. Uses target to specific the target state. | ||
50 | force_defend_ally_borders | Unused. | ||
15 | garrison | <integer> (scale of 100) | Used in ai_strategies/SOV.txt, USA.txt, ENG.txt how much of the army should be kept on garrison duty | |
32 | ignore | <tag> | Nudges the AI disposition towards ignoring the specified tag. | |
42 | ignore_army_incompetence | Sets the AI disposition towards ignoring army incompetence. | ||
47 | ignore_claim | <tag> | Sets AI ignorance of claims against the specified tag. Accepts 1 as a value. | |
7 | influence | Unused. | ||
18 | invade | <tag> | Nudges the AI disposition towards invading the specified tag. | |
21 | land_xp_spend_priority | Unused. | ||
37 | naval_avoid_region | <strategic region> | Alters AI avoidance of the specified strategic region navally. | |
35 | occupation_policy | <tag> | Determines the occupation policy towards the specified tag. Accepts values 0 to 3. | |
40 | pp_spend_amount |
|
Sets the amount allowed for spending Political Power on the specified action. | |
22 | pp_spend_priority |
|
Sets the priority for spending Political Power on the specified action. | |
38 | prepare_for_war | <tag> | it nudges the AI to plan an attack ahead of time for a possible war with target | |
5 | protect | <tag> | Nudges the diplomatic AI of a country to try to defend another specified country. | |
13 | research_tech | <technology> | Orders the AI to research a specific technology, if possible. | |
20 | role_ratio | <unit role> | Out of the entire army, this is the ratio (in %) of that unit role that the army should have. Roles can be defined arbitrarily in ai_templates. | |
39 | save_equipment | <equipment> | Makes the AI save equipment of the specified type to the set value. | |
34 | send_volunteers_desire | <tag> | Alters AI disposition towards sending volunteers to the specified tag. | |
43 | spare_unit_factor | Sets the spare unit factor. Used to encourage AI to send more units off to assist in allied fronts and not garrison their home territory. | ||
36 | support | <tag> | Alters AI disposition towards supporting the specified tag against partisans. | |
23 | template_prio | <unit type> | Sets the template priority of the specified unit type for the AI. | |
24 | template_xp_reserve | Sets the XP reserved needed for the AI to consider template changes. | ||
61 | force_build_armies | Added in 1.6.2, to force AI build armies... Mainly used for China to prepare for war against Japan | ||
19 | unit_ratio | <unit type> | Out of the entire army, this is the ratio (in %) of that unit type that the army should have. | |
25 | equipment_design_priority | |||
58 | production_upgrade_desire_offset | <equipment> | ||
put_unit_buffers | See ai_strategy/default.txt | Used to tell AI to garrison certain states |
AI 策略條目
一個策略條目包含了一個或多個 AI 策略,並定義了應用的時機和方式。在一個國家檢查一個條目的時候,只有在enable
為真以及abort
為空或假時才會激活這個條目。條目將在abort
非空且為真時,或者填寫了abort_when_not_enabled
且enable
為假時被廢除。
一個逆(reversed) 條目工作的方法卻不同。如果條目在ai_strategy
中作為id
引用且enable_reverse
為空或真,條目將對源國家激活。然後此條目將對目標國家檢查。如果target_array
和/或targets
有設置,它們將用作可能的目標;否則,所有國家都作為可能的目標。enable
和abort
觸發器將對每個目標檢查。如果一個國家通過了檢查,那麼條目中所有ai_strategy
的將對源國家激活,同時從目標中移除他們的id
。
屬性/參數
- allowed: (type: AND trigger) 在遊戲開始時只評估一次,因此條件應該是靜態的 (例如
tag = GER
或is_historical_focus_on = yes
). 如果未通過條目,它將不再被檢查以提高性能。 - enable: (type: AND trigger) 激活條目 (除非 abort 非空且為真).
- abort: (type: AND trigger) 若非空且為真,廢除該條目。
- abort_when_not_enabled: (type: yes/no, default: no) 若為真,則在
enable
為假時廢除該條目。 - ai_strategy: (type: AI strategy, may appear multiple times) 在條目激活後應用的 AI 策略。
- reversed: (type: yes/no, default: no) 使用上文所述的逆語義。
- enable_reverse: type: AND trigger) 源國家通過逆觸發器向目標國家傳遞的另一個觸發器
- target_array: (type: variable) 包含反向目標的數組變量, 例如
neighbors
,exiles
或enemies
. - targets: (type: list of variables) 獨立的反向目標列表, 例如
{ GER ENG FRA }
AI 策略計劃
這部分內容可能已不適合當前版本,最後更新於1.5。 |
/Hearts of Iron IV/common/ai_strategy_plans 中的文件定義了特定 Tag 的全面 AI 行為,用以模擬歷史上的戰略計劃。
這是一個通用示例:
<strategy_plan> = { name = <name> # Name of the plan desc = <desc> # Description of the plan # When this plan is enabled. enable = { <triggers> } # When this plan is aborted. abort = { <triggers> } # Defines which national focuses the AI picks first during this plan. ai_national_focuses = { <focus> # AI picks top downwards } # Defines which technology categories the AI has weighting towards/against during this plan. research = { <category> = <weight> } # Defines which ideas the AI has weighting towards/against during this plan. ideas = { <idea> = <weight> } # Defines which traits the AI has weighting towards/against during this plan. traits = { <trait> = <weight> } # Defines AI strategies to apply during this plan. ai_strategy = { <strategy attributes> } # Defines pick weights for specific focuses during this plan. focus_factors = { <focus> = <weight> } # Keep small, as it is used as a factor for some things (such as research needs) # Recommended around 1.0. Useful for relation between plans weight = { factor = 1.0 modifier = { factor = 1.0 } } }
AI 模板
這部分內容可能已不適合當前版本,最後更新於1.5。 |
/Hearts of Iron IV/common/ai_templates中的文件定義了 AI 角色所使用的模板,以指明其使用的模板。
角色是 AI 模板系統的核心。它們可以任意創建,允許 Modders 創建自定義角色。
分配給某個角色的每個模板將組成一個組,然後以每個可用模板的適應度得來確定在特定時刻為角色使用哪個模板。
這是一個通用示例:
<role_template_name> = { # Defines the actual role(s) the template covers. roles = { <roles> } # Restricts the template to only the specified tags. Optional. available_for = { <tags> } # Blocks the template for the specified tags. Optional. blocked_for = { <tags> } # Determines which existing templates are included in this role match_to_count = <float> # By default 0.5 # Determines the importance of the role template, highest importance is the role used by the AI. upgrade_prio = { factor = <float> # Base factor # Modifies the base factor modifier = { factor = <float> <triggers> } } # A template that belongs to this role. Multiple are allowed per role template. <template_name> = { # Determines the importance of the template amoungst other templates listed within the same role. upgrade_prio = { factor = <float> # Base factor # Modifies the base factor modifier = { factor = <float> <triggers> } } # Determines which template the AI will assign to a deployment line for a role. Highest score wins. production_prio = { factor = <float> # Base factor # Modifies the base factor modifier = { factor = <float> <triggers> } } # Determines the requirement to upgrade in field can_upgrade_in_field = { <triggers> } custom_icon = <int> reinforce_prio = <int> target_width = <float> width_weight = <float> column_swap_factor = <float> # Determines the weights for each stat for this template. # Order determines which stat the value affects. stat_weights = { <float> #-- default_morale <float> #-- defense <float> #-- breakthrough <float> #-- hardness <float> #-- soft_attack <float> #-- hard_attack <float> #-- recon <float> #-- entrenchment <float> #-- initiative <float> #-- casualty_trickleback <float> #-- supply_consumption_factor <float> #-- supply_consumption <float> #-- suppression <float> #-- suppression_factor <float> #-- experience_loss_factor <float> #-- equipment_capture_factor #-- Air Values <float> #-- air_attack #-- Common Values <float> #-- max_organisation <float> #-- max_strength <float> #-- maximum_speed <float> #-- armor_value <float> #-- ap_attack <float> #-- reliability <float> #-- reliability_factor <float> #-- weight <float> #-- build_cost_ic } # target_template = { weight = <float> match_value = <float> support = { <support unit> = <amount> } regiments = { <unit> = <amount> } } allowed_types = { <units> } replace_at_match = <float> replace_with = <template> target_min_match = <float> } }
文檔 | 效果 • 條件 • 定義 • 修正 • 修正列表 • 作用域 • 本地化 • 行動 • Data structures (Flags, Event targets, Country tag aliases, Variables, Arrays) |
編寫腳本 | AI • AI focuses • Autonomous states • Balances of power • 劇本 • 建築 • Characters and traits • Cosmetic tags • 國家 • 師 • 決議 • 裝備 • 事件 • 內閣/民族精神 • 意識形態 • 國策 • 資源 • Scripted GUI • 科技 • 單位 |
地圖 | 地圖 • 地區 • 補給區域 • 戰略區域 |
圖形圖像 | 界面 • 圖形資產 • 實體 • 後特效 • 離子效果 • 字體 |
裝飾性 | 肖像 • 命名列表 • 音樂 • 音效 |
其他 | 控制台指令 • 故障排除 • 模組結構 • 成就代碼分析 |