# Christian Warrior Lodge decisions
decisions = {
	# Create Christian Warrior Lodge - Non-existant at start.
	create_warrior_lodge_cws_christian = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 120 #check only once every 120 months.
		
		potential = {
			NOT = {
				has_global_flag = flag_started_warrior_lodge_cws_christian
			}
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
			has_dlc = "Holy Fury"
			age = 16
			NOT = { has_religion_feature = religion_peaceful }
			religion_group = christian
			NOT = { 
				warrior_lodge_cws_christian = {
					society_has_members = yes								
				}
			}
			ai = no
		}
		
		allow = {
			is_in_society = no
			NOT = { trait = incapable }
			has_education_martial_trigger = yes
			OR = {
				has_lifestyle_martial_trigger = yes
				martial = 25
			}
			higher_tier_than = DUKE
			martial = 20
			is_inaccessible_trigger = no
			scaled_wealth = 0.75
			prestige = 1500
			ai = no
		}
		
		effect = {
			scaled_wealth = -0.75
			# prestige = -1500
			custom_tooltip = { text = create_warrior_lodge_cws_christian_tooltip }
			hidden_tooltip = {
				set_global_flag = flag_started_warrior_lodge_cws_christian 
				join_society = warrior_lodge_cws_christian
				set_society_grandmaster = yes # Set character as Grand Master
				add_society_currency_massive_effect = yes
					spawn_good_commander_effect = yes
					new_character = { join_society = warrior_lodge_cws_christian }
					spawn_good_commander_effect = yes
					new_character = { join_society = warrior_lodge_cws_christian }
					spawn_good_commander_effect = yes
					new_character = { join_society = warrior_lodge_cws_christian }
					spawn_good_commander_effect = yes
					new_character = { join_society = warrior_lodge_cws_christian }
					spawn_good_commander_effect = yes
					new_character = { join_society = warrior_lodge_cws_christian }
					spawn_good_commander_effect = yes
					new_character = { join_society = warrior_lodge_cws_christian }
				any_vassal = {
					limit = {
						ai = yes
						can_join_society = warrior_lodge_cws_christian
					}
					random = { chance = 75 join_society = warrior_lodge_cws_christian }
				}
				any_neighbor_independent_ruler = {
					limit = {
						ai = yes
						can_join_society = warrior_lodge_cws_christian
					}
					random = { chance = 35 join_society = warrior_lodge_cws_christian }
				}
				any_player = {
					limit = {
						OR = {
							religion_group = christian
							is_within_diplo_range = ROOT
						}
					}
					narrative_event = { id = CWS.25026 }
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
}

settlement_decisions = {
	#Power, rank 3: Christian Fortifications
	warrior_lodge_christian_fortifications = {
		ai_check_interval = 80 #check only once every 80 months.
		filter = owned
		ai_target_filter = owned
		is_high_prio = yes
		
		from_potential = {
			is_playable = yes
			is_nomadic = no
			is_adult = yes
			higher_tier_than = BARON
			has_dlc = "Holy Fury"
			society_member_of = warrior_lodge_cws_christian
			society_rank >= 3
			religion_group = christian
		}
		
		potential = {
			holder_scope = {
				character = FROM
			}
			OR = { 
				AND = { 
					holding_type = tribal
					NAND = { 
						OR = { 
							has_building = tb_hillfort_4
							is_building = tb_hillfort_4
						}
						OR = { 
							has_building = tb_defensive_fortifications_4
							is_building = tb_defensive_fortifications_4
						}
					}
				}
				AND = { 
					holding_type = castle
					NAND = { 
						OR = { 
							has_building = ca_wall_5
							has_building = ca_con_wall_6
							is_building = ca_wall_5
						}
						OR = { 
							has_building = ca_wall_q_5
							is_building = ca_wall_q_5
						}
					}
				}
			}
		}
		allow = { #Now it's going to get ugly...
			show_only_failed_conditions = yes
			FROM = { has_society_currency_minor_trigger = yes }
			OR = { 
				conditional_tooltip = {
					trigger = { 
						holding_type = tribal
						NOT = { has_building = tb_hillfort_4 } 
					}
					AND = { 
						holding_type = tribal
						hidden_tooltip = { NOT = { has_building = tb_hillfort_4 } } 
						OR = { 
							AND = { 
								custom_tooltip = { 
									text = tooltip_can_build_tb_hillfort_1
									hidden_tooltip = { 
										NOR = { 
											is_building = tb_hillfort_1 
											has_building = tb_hillfort_1 
										}
										location = { TECH_CASTLE_CONSTRUCTION = 0 }
									}
								}
							}
							AND = { 
								custom_tooltip = { 
									text = tooltip_can_build_tb_hillfort_2
									hidden_tooltip = { 
										has_building = tb_hillfort_1
										NOR = { 
											is_building = tb_hillfort_2 
											has_building = tb_hillfort_2 
										}
										location = { TECH_CASTLE_CONSTRUCTION = 0 }
									}
								}
							}
							AND = { 
								custom_tooltip = { 
									text = tooltip_can_build_tb_hillfort_3
									hidden_tooltip = { 
										has_building = tb_hillfort_2
										NOR = { 
											is_building = tb_hillfort_3 
											has_building = tb_hillfort_3 
										}
										location = { TECH_CASTLE_CONSTRUCTION = 1 }
									}
								}
							}
							AND = { 
								custom_tooltip = { 
									text = tooltip_can_build_tb_hillfort_4
									hidden_tooltip = { 
										has_building = tb_hillfort_3
										NOR = { 
												is_building = tb_hillfort_4 
												has_building = tb_hillfort_4 
											}
										location = { TECH_CASTLE_CONSTRUCTION = 1 }
									}
								}
							}
						}
					}
				}
				conditional_tooltip = {
					trigger = { 
						holding_type = tribal
						OR = { 
							is_building = tb_hillfort_4
							has_building = tb_hillfort_4
							can_build_hillfort_trigger = no
						}
					}
					AND = { 
						holding_type = tribal
						hidden_tooltip = { 
							OR = { 
								is_building = tb_hillfort_4 #Prioritize hillfort first, as is more important.
								has_building = tb_hillfort_4
								can_build_hillfort_trigger = no
							}
							NOR = { 
								is_building = tb_defensive_fortifications_4
								has_building = tb_defensive_fortifications_4
							}
						}
						OR = { 
							AND = { 
								custom_tooltip = { 
									text = tooltip_can_build_tb_defensive_fortifications_1
									hidden_tooltip = { 
										NOR = { 
											is_building = tb_defensive_fortifications_1 
											has_building = tb_defensive_fortifications_1
										}
										location = { TECH_CASTLE_CONSTRUCTION = 0 }
									}
								}
							}
							AND = { 
								custom_tooltip = { 
									text = tooltip_can_build_tb_defensive_fortifications_2 
									hidden_tooltip = { 
										has_building = tb_defensive_fortifications_1
										NOR = { 
											is_building = tb_defensive_fortifications_2 
											has_building = tb_defensive_fortifications_2 
										}
										location = { TECH_CASTLE_CONSTRUCTION = 0 }
									}
								}
							}
							AND = { 
								custom_tooltip = { 
									text = tooltip_can_build_tb_defensive_fortifications_3
									hidden_tooltip = { 
										has_building = tb_defensive_fortifications_2
										NOR = { 
											is_building = tb_defensive_fortifications_3 
											has_building = tb_defensive_fortifications_3 
										}
										location = { TECH_CASTLE_CONSTRUCTION = 1 }
									}
								}
							}
							AND = { 
								custom_tooltip = { 
									text = tooltip_can_build_tb_defensive_fortifications_4
									hidden_tooltip = { 
										has_building = tb_defensive_fortifications_3
										NOR = { 
											is_building = tb_defensive_fortifications_4 
											has_building = tb_defensive_fortifications_4 
										}
										location = { TECH_CASTLE_CONSTRUCTION = 1 }
									}
								}
							}
						}
					}
				}
				conditional_tooltip = {
					trigger = { 
						holding_type = castle
						NOT = { has_building = ca_wall_5 }
					}
					AND = { 
						holding_type = castle
						hidden_tooltip = { NOT = { has_building = ca_wall_5 } }
						custom_tooltip = { 
							text = tooltip_can_build_ca_wall_1
							hidden_tooltip = { 
								OR = { 
									AND = { 
										NOR = { 
											is_building = ca_wall_1 
											has_building = ca_wall_1
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 0 }
									}
									AND = { 
										has_building = ca_wall_1
										NOR = { 
											is_building = ca_wall_2 
											has_building = ca_wall_2
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 2 }
									}
									AND = { 
										has_building = ca_wall_2
										NOR = { 
											is_building = ca_wall_3 
											has_building = ca_wall_3
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 4 }
									}
									AND = { 
										has_building = ca_wall_3
										NOR = { 
											is_building = ca_wall_4 
											has_building = ca_wall_4
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 6 }
									}
									AND = { 
										has_building = ca_wall_4
										NOR = { 
											is_building = ca_wall_5 
											has_building = ca_wall_5
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 8 }
									}
								}
							}
						}
					}
				}
				conditional_tooltip = {
					trigger = { 
						holding_type = castle
						OR = { 
							is_building = ca_wall_5 
							has_building = ca_wall_5 
							can_build_walls_trigger = no
						}
					}
					AND = { 
						holding_type = castle
						hidden_tooltip = { 
							OR = { 
								is_building = ca_wall_5 #Prioritize walls first, as they give more benefits.
								has_building = ca_wall_5 
								can_build_walls_trigger = no
							}
							NOR = { 
								is_building = ca_wall_q_5
								has_building = ca_wall_q_5
							}
						}
						custom_tooltip = { 
							text = tooltip_can_build_ca_wall_q_1
							hidden_tooltip = { 
								OR = { 
									AND = { 
										NOR = { 
											is_building = ca_wall_q_1
											has_building = ca_wall_q_1
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 0 }
									}
									AND = { 
										has_building = ca_wall_q_1
										NOR = { 
											is_building = ca_wall_q_2 
											has_building = ca_wall_q_2
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 1 }
									}
									AND = { 
										has_building = ca_wall_q_2
										NOR = { 
											is_building = ca_wall_q_3 
											has_building = ca_wall_q_3
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 3 }
									}
									AND = { 
										has_building = ca_wall_q_3
										NOR = { 
											is_building = ca_wall_q_4 
											has_building = ca_wall_q_4 
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 5 }
									}
									AND = { 
										has_building = ca_wall_q_4
										NOR = { 
											is_building = ca_wall_q_5 
											has_building = ca_wall_q_5
										}
										location = { TECH_FORTIFICATIONS_CONSTRUCTION = 7 }
									}
								}
							}
						}
					}
				}
			}
		}
		effect = {
			FROM = { 
				detract_society_currency_minor_effect = yes 
				hidden_tooltip = { 
					random_list = { 
						33 = { sound_effect = baltic_holds_01 } 
						33 = { sound_effect = baltic_holds_02 } 
						33 = { sound_effect = baltic_holds_03 } 
					}
				}
			}
			
			if = {
				limit = {
					holding_type = castle
					can_build_walls_trigger = yes
					NOR = { 
						has_building = ca_wall_5
						is_building = ca_wall_5 
					}
				}
				if = { 
				limit = { 
					has_building = ca_wall_4
					NOR = { 
						is_building = ca_wall_5 
					}
					location = { TECH_FORTIFICATIONS_CONSTRUCTION = 8 }
					}
					add_building = ca_wall_5
					hidden_tooltip = { FROM = { character_event = { id = HF.25068 } } }
				}
				else_if = { 
				limit = { 
					has_building = ca_wall_3
					NOR = { 
						is_building = ca_wall_4 
					}
					location = { TECH_FORTIFICATIONS_CONSTRUCTION = 6 }
					}
					add_building = ca_wall_4
					hidden_tooltip = { FROM = { character_event = { id = HF.25068 } } }
				}
				else_if = { 
				limit = { 
					has_building = ca_wall_2
					NOR = { 
						is_building = ca_wall_3 
					}
					location = { TECH_FORTIFICATIONS_CONSTRUCTION = 4 }
					}
					add_building = ca_wall_3
					hidden_tooltip = { FROM = { character_event = { id = HF.25068 } } }
				}
				else_if = { 
					limit = { 
						has_building = ca_wall_1
						NOR = { 
							is_building = ca_wall_2 
						}
						location = { TECH_FORTIFICATIONS_CONSTRUCTION = 2 }
					}
					add_building = ca_wall_2
					hidden_tooltip = { FROM = { character_event = { id = HF.25068 } } }
				}
				else_if = { 
					limit = { 
						NOR = { 
							is_building = ca_wall_1 
							has_building = ca_wall_1 
						}
						location = { TECH_FORTIFICATIONS_CONSTRUCTION = 0 }
					}
					add_building = ca_wall_1
					hidden_tooltip = { FROM = { character_event = { id = HF.25068 } } }
				}
				break = yes
			}
			if = {
				limit = {
					holding_type = castle
					NOR = { 
						has_building = ca_wall_q_5
						is_building = ca_wall_q_5 
					}
					OR = { 
						is_building = ca_wall_5 
						has_building = ca_wall_5 
						can_build_walls_trigger = no
					}
				}
				if = { 
				limit = { 
					has_building = ca_wall_q_4
					NOR = { 
						is_building = ca_wall_q_5 
					}
					location = { TECH_FORTIFICATIONS_CONSTRUCTION = 7 }
					}
					add_building = ca_wall_q_5
					hidden_tooltip = { FROM = { character_event = { id = HF.25069 } } }
				}
				else_if = { 
				limit = { 
					has_building = ca_wall_q_3
					NOR = { 
						is_building = ca_wall_q_4 
					}
					location = { TECH_FORTIFICATIONS_CONSTRUCTION = 5 }
					}
					add_building = ca_wall_q_4
					hidden_tooltip = { FROM = { character_event = { id = HF.25069 } } }
				}
				else_if = { 
				limit = { 
					has_building = ca_wall_q_2
					NOR = { 
						is_building = ca_wall_q_3 
					}
					location = { TECH_FORTIFICATIONS_CONSTRUCTION = 3 }
					}
					add_building = ca_wall_q_3
					hidden_tooltip = { FROM = { character_event = { id = HF.25069 } } }
				}
				else_if = { 
				limit = { 
					has_building = ca_wall_q_1
					NOR = { 
						is_building = ca_wall_q_2 
					}
					location = { TECH_FORTIFICATIONS_CONSTRUCTION = 1 }
					}
					add_building = ca_wall_q_2
					hidden_tooltip = { FROM = { character_event = { id = HF.25069 } } }
				}
				else_if = { 
				limit = { 
					NOR = { 
						is_building = ca_wall_q_1
						has_building = ca_wall_q_1
					}
					location = { TECH_FORTIFICATIONS_CONSTRUCTION = 0 }
					}
					add_building = ca_wall_q_1
					hidden_tooltip = { FROM = { character_event = { id = HF.25069 } } }
				}
			}
			if = {
				limit = {
					holding_type = tribal
					can_build_hillfort_trigger = yes
					NOR = { 
						has_building = tb_hillfort_4
						is_building = tb_hillfort_4 
					}
				}
				if = { 
				limit = { 
					has_building = tb_hillfort_3
					NOR = { 
						is_building = tb_hillfort_4 
					}
					location = { TECH_CASTLE_CONSTRUCTION = 1 }
					}
					add_building = tb_hillfort_4
					hidden_tooltip = { FROM = { character_event = { id = HF.25067 } } }
				}
				else_if = { 
				limit = { 
					has_building = tb_hillfort_2
					NOR = { 
						is_building = tb_hillfort_3 
					}
					location = { TECH_CASTLE_CONSTRUCTION = 0 }
					}
					add_building = tb_hillfort_3
					hidden_tooltip = { FROM = { character_event = { id = HF.25066 } } }
				}
				else_if = { 
				limit = { 
					has_building = tb_hillfort_1
					NOR = { 
						is_building = tb_hillfort_2 
					}
					location = { TECH_CASTLE_CONSTRUCTION = 0 }
					}
					add_building = tb_hillfort_2
					hidden_tooltip = { FROM = { character_event = { id = HF.25065 } } }
				}
				else_if = { 
				limit = { 
					NOR = { 
						is_building = tb_hillfort_1
						has_building = tb_hillfort_1
					}
					location = { TECH_CASTLE_CONSTRUCTION = 0 }
					}
					add_building = tb_hillfort_1
					hidden_tooltip = { FROM = { character_event = { id = HF.25064 } } }
				}
				break = yes
			}
			if = {
				limit = {
					holding_type = tribal
					NOR = { 
						has_building = tb_defensive_fortifications_4  
						is_building = tb_defensive_fortifications_4  
					}
					OR = { 
						is_building = tb_hillfort_4 
						has_building = tb_hillfort_4 
						can_build_hillfort_trigger = no
					}
				}
				if = { 
				limit = { 
					has_building = tb_defensive_fortifications_3
					NOR = { 
						is_building = tb_defensive_fortifications_4 
					}
					location = { TECH_CASTLE_CONSTRUCTION = 1 }
					}
					add_building = tb_defensive_fortifications_4
					hidden_tooltip = { FROM = { character_event = { id = HF.25063 } } }
				}
				else_if = { 
				limit = { 
					has_building = tb_defensive_fortifications_2
					NOR = { 
						is_building = tb_defensive_fortifications_3 
					}
					location = { TECH_CASTLE_CONSTRUCTION = 0 }
					}
					add_building = tb_defensive_fortifications_3
					hidden_tooltip = { FROM = { character_event = { id = HF.25062 } } }
				}
				else_if = { 
				limit = { 
					has_building = tb_defensive_fortifications_1
					NOR = { 
						is_building = tb_defensive_fortifications_2 
					}
					location = { TECH_CASTLE_CONSTRUCTION = 0 }
					}
					add_building = tb_defensive_fortifications_2
					hidden_tooltip = { FROM = { character_event = { id = HF.25061 } } }
				}
				else_if = { 
				limit = { 
					NOR = { 
						is_building = tb_defensive_fortifications_1 
						has_building = tb_defensive_fortifications_1
					}
					location = { TECH_CASTLE_CONSTRUCTION = 0 }
					}
					add_building = tb_defensive_fortifications_1
					hidden_tooltip = { FROM = { character_event = { id = HF.25060 } } }
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
}