作用域

本頁面所適用的版本可能已經過時,最後更新於1.9

作用域選擇實體以檢查條件或實施指令

作用域後面一般都會跟着大括號:

<scope_name> = {
	#这个作用域中要实施的东西。
}

但是並不是所有後面有大括號的東西都是作用域:有一些是功能模塊(option, trigger, mean_time_to_happen,...),operator (AND), 流控制語句 (if, limit),或者是複雜條件或者指令的分句。

作用域轉換類型

有不同的作用域轉換運算符。

  • 條件(Condition):條件作用域和其他條件一樣返回布爾值。
  • 指令(Command):指令作用域和其他指令一樣對新作用域施加效果。
  • 兼容(Both):這種作用域可以有以上兩種用途。

大多數通用作用域轉換運算符都有四種不同的形式。

名稱 描述
all_<name> 條件,所有都必須達到子條件。
any_<name> 條件,至少有一個達到子條件。
every_<name> 指令,施加在所有子作用域上。
random_<name> 指令,施加在某一子作用域上。

作用域列表

請注意以下內容:

如果一個作用域的觸發器一欄為,那麼你可以檢查它的條件。
如果一個作用域的效果一欄為,那麼你可以對它施加指令。
作用域 描述 樣例 觸發器 效果 來自作用域 改變作用域到 加入的遊戲版本
all_unit_leader 檢查是否當前國家作用域的所有將領滿足了條件。 all_unit_leader = { ... } X 國家 將領 1.5
any_unit_leader 檢查是否當前國家作用域有任意將領滿足了條件。 any_unit_leader = { ... } X 國家 將領 1.5
all_army_leader 檢查是否當前國家作用域的所有陸軍將領滿足了條件。 all_unit_leader = { ... } X 國家 將領 1.5
any_army_leader 檢查是否當前國家作用域有任意陸軍將領滿足了條件。 all_unit_leader = { ... } X 國家 將領 1.5
all_navy_leader 檢查是否當前國家作用域的所有海軍將領滿足了條件。 all_navy_leader = { ... } X 國家 將領 1.5
any_navy_leader 檢查是否當前國家作用域有任意海軍將領滿足了條件。 all_navy_leader = { ... } X 國家 將領 1.5
random_unit_leader 指向當前國家作用域的一個隨機將領。 random_unit_leader = { ... } X 國家 將領 1.5
every_unit_leader 指向當前國家作用域的每一個將領。 every_unit_leader = { ... } X 國家 將領 1.5
random_army_leader 指向當前國家作用域的一個隨機陸軍將領。 random_army_leader = { ... } X 國家 將領 1.5
every_army_leader 指向當前國家作用域的每一個陸軍將領。 every_army_leader = { ... } X 國家 將領 1.5
random_navy_leader 指向當前國家作用域的一個隨機海軍將領。 random_navy_leader = { ... } X 國家 將領 1.5
every_navy_leader 指向當前國家作用域的每一個海軍將領。 every_navy_leader = { ... } X 國家 將領 1.5
global_every_army_leader 指向世界上所有國家的每一個陸軍將領。(如果你知道國家的話最好用every_army_leader) global_every_army_leader = { ... } X 國家 將領 1.5
OVERLORD 指向當前作用域的宗主國,如果當前作用域是附屬國。 RAJ = { OVERLORD = { ... } } 國家 國家 1.3
TAG 指向tag對應的特定國家。 FRA = { ... } 任意 國家 1.0
any_country 檢查世界上的任意國家。(包括當前作用域,如果不想包含的話參見any_other_country) any_country = { ... } X 任意 國家 1.0
any_country_with_original_tag Targets any country with current scope's original tag any_country_with_original_tag = { ... } X 任意 國家 1.9
any_neighbor_country 檢查當前作用域的任意相鄰國家。 any_neighbor_country = { ... } X 國家 國家 1.0
any_home_area_neighbor_country 檢查與當前作用域本土(核心地區)相鄰的任意國家。 any_home_area_neighbor_country = { ... } X 任意 國家 1.0
any_guaranteed_country 檢查當前作用域保障獨立的任意國家。 any_guaranteed_country = { ... } X 國家 國家 1.9
any_allied_country 檢查當前作用域結盟的任意國家。 any_allied_country = { ... } X 國家 國家 1.0
any_other_country 檢查世界上的任意其他國家(不包括當前作用域)。 any_other_country = { ... } X 國家 國家 1.0
any_enemy_country 檢查當前作用域的任意敵對國家。 any_enemy_country = { ... } X 國家 國家 1.0
any_occupied_country 檢查被當前作用域佔領的任意國家。 any_occupied_country = { ... } X 國家 國家 1.9
all_neighbor_country 檢查當前作用域的所有相鄰國家。 all_neighbor_country = { ... } X 國家 國家 1.0
all_country 檢查世界上的所有國家。 all_country = { ... } X 任意 國家 1.0
all_country_with_original_tag Targets all country with current scope's original tag all_country_with_original_tag = { ... } X 任意 國家 1.9
all_allied_country 檢查當前作用域結盟的所有國家。 all_allied_country = { ... } X 國家 國家 1.9
all_guaranteed_country 檢查當前作用域保障獨立的所有國家。 all_guaranteed_country = { ... } X 國家 國家 1.9
all_enemy_country 檢查當前作用域的所有敵對國家。 all_enemy_country = { ... } X 國家 國家 1.0
all_occupied_country 檢查被當前作用域佔領的所有國家。 all_occupied_country = { ... } X 國家 國家 1.9
state_id 指向地區id對應的特定地區。 145 = { ... } 任意 地區 1.0
any_state 檢查世界上的任意地區。 any_state = { ... } X 任意 地區 1.0
any_controlled_state 檢查當前作用域控制的任意地區。 any_controlled_state = { ... } X 國家 地區 1.9
any_owned_state 檢查當前作用域擁有的任意地區。 any_owned_state = { ... } X 國家 地區 1.0
any_neighbor_state 檢查與當前作用域相鄰的任意地區。 any_neighbor_state = { ... } X 地區 地區 1.0
all_state 檢查世界上的所有地區。 all_state = { ... } X 任意 地區 1.0
all_owned_state 檢查當前作用域擁有的所有地區。 all_owned_state = { ... } X 國家 地區 1.0
all_neighbor_state 檢查與當前作用域相鄰的所有地區。 all_neighbor_state = { ... } X 地區 地區 1.0
all_owned_state 檢查當前作用域擁有的所有地區。 all_owned_state = { ... } X 國家 地區 1.0
all_controlled_state 檢查當前作用域控制的所有地區。 all_controlled_state = { ... } X 國家 地區 1.9
every_country 指向世界上的每一個國家。(包括當前作用域,如果不想包含的話參見every_other_country) every_country = { ... } X 任意 國家 1.0
every_country_with_original_tag every_country_with_original_tag = { original_tag_to_check = TAG limit = { ... } ... } X 任意 國家 1.9
every_other_country 指向世界上的每一個其他國家(不包括當前作用域)。 every_other_country = { ... } X 國家 國家 1.0
every_neighbor_country 指向當前作用域的每一個鄰國。 every_neighbor_country = { ... } X 國家 國家 1.0
every_enemy_country 指向當前作用域的每一個敵對國家。 every_enemy_country = { ... } X 國家 國家 1.0
every_occupied_country 指向當前作用域佔領的每一個國家。 every_occupied_country = { ... } X 國家 國家 1.9
random_country 指向世界上的一個隨機國家。(包括當前作用域) random_country = { ... } X 任意 國家 1.0
random_country_with_original_tag Targets a random country with original tag random_country_with_original_tag = { original_tag_to_check = TAG limit = {...} ... } X 任意 國家 1.9
random_neighbor_country 指向當前作用域的一個隨機鄰國。 random_neighbor_country = { ... } X 國家 國家 1.0
random_enemy_country 指向當前作用域的一個隨機敵對國家。 random_enemy_country = { ... } X 國家 國家 1.0
random_occupied_country 指向當前作用域佔領的一個隨機國家。 random_occupied_country = { ... } X 國家 國家 1.9
random_state 指向一個隨機地區。 random_state = { ... } X 任意 地區 1.0
random_owned_state 指向當前作用域擁有的一個隨機地區。 random_owned_state = { ... } X 國家 地區 1.0
random_controlled_state 指向當前作用域控制的一個隨機地區。 random_controlled_state = { prioritize = { <stateID> <stateID> } to pick those states first if they fulfill the limit ... } X 國家 地區 1.9
random_owned_controlled_state 指向當前作用域擁有並控制的一個隨機地區。 random_owned_controlled_state = { ... } X 國家 地區 1.3
random_neighbor_state 指向與當前作用域相鄰的一個隨機地區。 random_neighbor_state = { ... } X 地區 地區 1.0
every_state 指向世界上的每一個地區。 every_state = { ... } X 地區 地區 1.0
every_controlled_state 指向當前作用域控制的每一個地區。 every_controlled_state = { ... } X 國家 地區 1.9
every_owned_state 指向當前作用域擁有的每一個地區。 every_owned_state = { ... } X 國家 地區 1.0
every_neighbor_state 指向與當前作用域相鄰的每一個地區。 every_neighbor_state = { ... } X 地區 地區 1.0
capital_scope 指向當前作用域的首都地區。 capital_scope = { ... } 國家 地區 1.0
owner scope 指向當前作用域的擁有者。 owner = { ... } X 地區 國家 1.0
controller scope 指向當前作用域的控制者。 controller = { ... } X 地區 國家 1.0
all_operative_leader 檢查當前作用域的所有特工。 all_operative_leader = { ... } X 國家/Operation 特工 1.9
any_operative_leader 檢查當前作用域的任意特工。 any_operative_leader = { ... } X 國家/Operation 特工 1.9
every_operative 指向當前作用域的每一個特工。 every_operative = { ... } X 國家/Operation 特工 1.9
random_operative 指向當前作用域的一個隨機特工。 random_operative = { ... } X 國家/Operation 特工 1.9

NOTE: Some of these scopes may have no countries/states that match the criteria

作用域限制

可以使用limit語句限定條件來縮小作用域的範圍。很簡單地在一個作用域(如every_neighbor_country)中插入語句,放入所需的條件(如有多於5個軍工廠)。然後在寫完limit語句後,放入指令(如給與軍事通行權)來影響特定的作用域。這裏有一個小例子:

every_neighbor_country = { # 指向作用域相邻的每一个国家
	limit = {
		num_of_military_factories > 5 # 添加拥有多于5个军工厂的限制
	}
	give_military_access = ROOT #将军事通行权给与拥有多于5个军工厂的每个邻国
}

作用域之間的移動

有許多能夠跨作用域執行效果或檢查觸發器的連結。所有的連結都可以用於效果或觸發器,儘管不是所有指令和條件(即效果和觸發器)都接受它們,或者是作用域本身。

連結 描述 樣例
ROOT 定位這個效果或觸發器所在的根(腳本進入的第一個作用域)國家,無視其它任何作用域。
ENG = {
	FRA = {
		GER = {
			declare_war_on = {
				target = ROOT
				type = annex_everything
			}
		}
	}
} #德国对英国宣战。(假设在前面再没有作用域了)
THIS 定位當前作用域。
random_state = {
    add_resource = {
        type = oil
        amount = 50
        state = THIS
    }
}#资源会加到随机的地区(random_state)。
PREV 定位上一個作用域。
FRA = {
	random_country = {
		GER = {
			declare_war_on = {
				target = PREV
				type = annex_everything
			}
		}
	}
} #德国对随机国家宣战(random_country)。

FROM 決議中,定位到目標決議的目標。

事件中,定位到向你發送這個事件的tag(如適用),例如德國向意大利發送了一個事件。

declare_war_on = {
    target = FROM
    type = annex_everything
}
FROM = {
    load_oob = defend_ourselves
}

FROM和PREV可以向前多次定位作用域,方法是在.後面繼續加FROM或PREV。例如,FROM.FROMPREV.PREV.PREV。 In this example of chaining these links, two arms factories are built in two random states of a random country, and PREV.PREV is used to ensure the second state is not the same as the first state.

random_country = { #1st scope [1]
    random_owned_state = { # 2nd scope [1,2]
        add_extra_state_shared_building_slots = 2
        add_building_construction = {
            type = arms_factory
            level = 2
            instant_build = yes
        }
        PREV = { #from random_owned_state(#2nd) to random_country(#1st). [1,2,1]
            random_owned_state = { #new second scope [1,2_old,1,2_new]
                limit = { NOT = { state = PREV.PREV } } # The first PREV scopes back to the country, the second scopes back to the first random state <Value:1,2_old,̶1̶,̶̶̶2̶̶̶_̶̶̶n̶̶̶e̶̶̶w>
                add_extra_state_shared_building_slots = 2 #Note: We used PREV.PREV to get a value, but didn't actually enter that scope. [1,2_old,1,2_new]
                add_building_construction = {
                    type = arms_factory
                    level = 2
                    instant_build = yes
                }
            }
        }
    }
}

References