Skip to content

Commit

Permalink
Reworked port conditions to allow for >1 port per state
Browse files Browse the repository at this point in the history
  • Loading branch information
Anbeeld committed Feb 12, 2025
1 parent 2252ff3 commit 4679b16
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 71 deletions.
113 changes: 93 additions & 20 deletions common/script_values/buildings_values.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,36 @@ brc_port = {
# Don't build and delete if exists
if = {
limit = {
# State borders change very rapidly in the first years
current_date >= 460.1.1
# Don't delete anything while at war
owner = {
war = no
}
# Don't ever delete the last port we have country wide
OR = {
# Can build mine or farm, has some other territory to build port in or it's not needed
AND = {
is_territory_with_preference_for_mine_or_farm = yes
OR = {
province_of_territory_should_have_port = no
any_other_non_important_territory_in_same_province_has_or_is_building_or_can_build_port = yes
}
}
# Is not a city, some other territory in the province already has the port that we don't plan to delete
owner.num_of_ports > 1
num_of_port_building > 1
}
OR = {
# Handle non-city territories where state has too much ports
AND = {
has_city_status = no
any_other_non_important_territory_in_same_province_has_or_is_building_port = yes
# If mine or farm, delete if more than enough ports or can build it somewhere without mine or farm
trigger_if = {
limit = {
is_territory_with_preference_for_mine_or_farm = yes
}
OR = {
territory_state_has_more_than_enough_ports = yes
territory_state_can_build_new_port_elsewhere_without_mine_or_farm = yes
}
}
# If not, delete if more than enough ports and there's no mine or farm that wants it port deleted
trigger_else = {
territory_state_has_more_than_enough_ports = yes
territory_state_has_port_elsewhere_with_mine_or_farm = no
}
}
# Tier >=2 ports in countries that don't want any mega ports
AND = {
Expand Down Expand Up @@ -81,7 +94,7 @@ brc_port = {
brc_wants_port = yes
}
value = brc_territory_importance
multiply = brc_40
multiply = brc_80
}
else = {
value = 0
Expand Down Expand Up @@ -502,27 +515,87 @@ brc_territory_importance = {
}
}

num_of_owned_territories_in_same_province = {
num_of_territories_in_state = {
value = 0
state = {
every_state_province = {
add = 1
}
every_state_province = {
add = 1
}
}

num_of_territories_in_same_state = {
value = 0
add = state.num_of_territories_in_state
}

population_cap_minus_3 = {
value = population_cap
subtract = 3
}

territory_port_level_including_construction = {
value = num_of_port_building
if = {
limit = {
has_specific_construction = port_building
can_have_port = no
}
value = 0
}
else = {
value = num_of_port_building
if = {
limit = {
has_specific_construction = port_building
}
add = 1
}
}
}

num_of_ports_wanted_in_territory_state = {
value = 0
if = {
limit = {
save_temporary_scope_as = territory
OR = {
num_of_territories_in_same_state >= 5
# Country has no ports and there's no state where we can build one by the usual rules
owner = {
country_has_at_least_one_port_including_construction = no
NOT = {
any_country_state = {
num_of_territories_in_state >= 5
any_state_province = {
can_build_port = yes
}
}
}
}
# No nearby state of same owner with port, should connect to mainland by water
NOT = {
area = {
any_neighbor_area = {
any_area_province = {
owner = scope:territory.owner
has_or_is_building_port = yes
}
}
}
}
}
}
add = 1
# +1 in big states where at least 50% of territories can have port
if = {
limit = {
num_of_territories_in_same_state >= 10
state = {
any_state_province = {
percent >= 0.50
can_have_port = yes
}
}
}
add = 1
}
}
}

Expand Down Expand Up @@ -574,7 +647,7 @@ level_of_mega_port_wanted = 3
num_of_mega_ports_wanted = {
value = 0

# 1 per every 25 coastal territories
# 1 per every 35 coastal territories
every_owned_province = {
limit = {
OR = {
Expand All @@ -584,7 +657,7 @@ num_of_mega_ports_wanted = {
}
add = 1
}
divide = 25
divide = 35
floor = yes

# Base value depending on rank so they always want at least some
Expand Down
100 changes: 49 additions & 51 deletions common/scripted_triggers/buildings_triggers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,9 @@
brc_needs_port = {
trigger_if = {
limit = {
owner = {
num_of_ports < 1
}
}
OR = {
state = {
is_capital_state = yes
}
owner.capital_scope = {
any_territory_in_same_province_can_build_port = no
}
territory_state_has_enough_ports = no
}
is_best_territory_for_port_in_province = yes
is_best_territory_for_new_port_in_state = yes
}
trigger_else = {
# OR instead of trigger_else_if so they don't block each other in edge cases
Expand Down Expand Up @@ -55,16 +45,8 @@ brc_needs_port = {
}
}
brc_wants_port = {
OR = {
AND = {
has_city_status = yes
has_or_is_building_port = no
}
AND = {
province_of_territory_should_have_port = yes
is_best_territory_for_port_in_province = yes
}
}
has_city_status = yes
has_or_is_building_port = no
}

# Academy
Expand Down Expand Up @@ -244,81 +226,97 @@ can_build_port = {
free_building_slots > 0
}

province_of_territory_should_have_port = {
can_build_new_port = {
can_build_port = yes
has_or_is_building_port = no
}

country_has_at_least_one_port_including_construction = {
OR = {
is_territory_of_capital_province = yes
num_of_owned_territories_in_same_province >= 5
owner.capital_scope = {
any_territory_in_same_province_has_or_is_building_port = no
num_of_ports > 0 # In-built trigger first for performance
any_owned_province = {
territory_port_level_including_construction > 0
}
}
}

any_territory_in_same_province_has_or_is_building_port = {
state = {
any_state_province = {
has_or_is_building_port = yes
territory_state_has_enough_ports = {
save_temporary_scope_as = territory
OR = {
num_of_ports_wanted_in_territory_state = 0
state = {
any_state_province = {
count >= scope:territory.num_of_ports_wanted_in_territory_state
territory_port_level_including_construction > 0
}
}
}
}

any_territory_in_same_province_can_build_port = {
state = {
any_state_province = {
can_build_port = yes
territory_state_has_more_than_enough_ports = {
save_temporary_scope_as = territory
OR = {
num_of_ports_wanted_in_territory_state = 0
state = {
any_state_province = {
count > scope:territory.num_of_ports_wanted_in_territory_state
territory_port_level_including_construction > 0
}
}
}
}

any_other_city_territory_in_same_province_can_build_port = {
is_best_territory_for_new_port_in_state = {
territory_port_level_including_construction < 1
OR = {
has_city_status = yes
territory_state_can_build_new_port_elsewhere_in_city = no
}
OR = {
is_territory_with_preference_for_mine_or_farm = no
territory_state_can_build_new_port_elsewhere_without_mine_or_farm = no
}
}

territory_state_can_build_new_port_elsewhere_in_city = {
save_temporary_scope_as = territory
state = {
any_state_province = {
NOT = {
this = scope:territory
}
has_city_status = yes
can_build_port = yes
can_build_new_port = yes
}
}
}

any_other_non_important_territory_in_same_province_has_or_is_building_port = {
territory_state_has_port_elsewhere_with_mine_or_farm = {
save_temporary_scope_as = territory
state = {
any_state_province = {
NOT = {
this = scope:territory
}
has_or_is_building_port = yes
is_territory_with_preference_for_mine_or_farm = no
is_territory_with_preference_for_mine_or_farm = yes
}
}
}

any_other_non_important_territory_in_same_province_has_or_is_building_or_can_build_port = {
territory_state_can_build_new_port_elsewhere_without_mine_or_farm = {
save_temporary_scope_as = territory
state = {
any_state_province = {
NOT = {
this = scope:territory
}
OR = {
has_or_is_building_port = yes
can_build_port = yes
}
can_build_new_port = yes
is_territory_with_preference_for_mine_or_farm = no
}
}
}

is_best_territory_for_port_in_province = {
OR = {
has_city_status = yes
any_other_city_territory_in_same_province_can_build_port = no
}
}

has_wanted_num_of_high_tier_ports = {
save_temporary_scope_as = territory_owner
OR = {
Expand Down

0 comments on commit 4679b16

Please sign in to comment.