﻿je_agricultural_development = {
	icon = "gfx/interface/icons/goods_icons/coffee.dds"

	group = je_group_historical_content
	
	is_shown_when_inactive = {
		c:BRZ ?= this
		has_dlc_feature = rp1_content
	}

	possible = {
		has_technology_researched = intensive_agriculture
		any_scope_state = {
			count >= 2
			is_capital = no
			has_building = building_coffee_plantation
			has_building = building_livestock_ranch
			is_incorporated = yes
		}
		country_has_building_group_levels = {
			type = bg_plantations
			value  >= 50
		}
		custom_tooltip = {
			text = is_not_in_other_market_tt
			ROOT.market_capital = {
				owner = ROOT
			}
		}
	}

	immediate = {
		ig:ig_landowners = {
			save_scope_as = landowners_ig
		}
		market_capital.market = {
			mg:coffee = {
				save_scope_as = coffee_scope
			}
		}
		root = {
			save_scope_as = brazil_scope
		}
		set_variable = coffee_with_milk_1_active
		trigger_event = { id = coffee_with_milk.1 }
	}

	on_monthly_pulse = {
		random_events = {
			100 = 0
			10 = coffee_with_milk.2
			10 = coffee_with_milk.3
		}
	}

	complete = {
		OR = {
			leading_producer_of = g:meat
			leading_producer_of = g:coffee
			leading_producer_of = g:sugar
		}
		trigger_if = {
			limit = {
				has_variable = coffee_with_milk_1_active
			}
			scope:journal_entry = {
				is_goal_complete = yes
			}
		}
		trigger_else = {
			custom_tooltip = {
				text = je_agricultural_development_goal_dummy
				always = no
			}
		}
		country_has_building_group_levels = {
			type = bg_plantations
			value  >= 125
		} 
	}

	on_complete = {
		trigger_event = { id = coffee_with_milk.5 }
		set_variable = agricultural_dev_done
	}

	current_value = {
		value = scope:coffee_scope.market_goods_buy_orders
	}

	goal_add_value = {
		value = scope:coffee_scope.market_goods_buy_orders
		multiply = 2.5
	}

	fail = {
		custom_tooltip = {
			text = is_in_other_market_tt
			ROOT.market_capital = {
				NOT = {
					owner = ROOT
				}
			}
		}
	}

	invalid = {
		NOT = {
			any_scope_state = {
				count >= 2
				is_capital = no
				has_building = building_coffee_plantation
				has_building = building_livestock_ranch
				is_incorporated = yes
			}
		}
	}

	weight = 100

	progressbar = yes

	should_be_pinned_by_default = yes
}

je_coffee_with_milk = {
	icon = "gfx/interface/icons/event_icons/event_scales.dds"

	group = je_group_historical_content

	is_shown_when_inactive = {
		has_dlc_feature = rp1_content
		OR = {
			custom_tooltip = {
				text = agricultural_development_complete_tt
				has_variable = agricultural_dev_done
			}
			has_journal_entry = je_agricultural_development
		}
	}

	possible = {
		ig:ig_landowners = {
			is_powerful = yes
		}
		any_scope_state = {
			count >= 2
			is_capital = no
			has_building = building_coffee_plantation
			has_building = building_livestock_ranch
			is_incorporated = yes
		}
		OR = {
			has_law = law_type:law_landed_voting
			has_law = law_type:law_wealth_voting
		}
		country_has_building_group_levels = {
			type = bg_plantations
			value  >= 100
		} 
	}

	immediate = {
		ig:ig_landowners = {
			save_scope_as = landowners_ig
		}
		root = {
			save_scope_as = brazil_scope
		}
		set_variable = { name = coffee_with_milk_progress value = 0 }
		trigger_event = { id = coffee_with_milk.4 popup = yes }
	}

	on_monthly_pulse = {
		effect = {
			if = {
				limit = {
					OR = {
						has_law = law_type:law_tenant_farmers
						has_law = law_type:law_serfdom
					}
					ig:ig_landowners = {
						is_powerful = yes
						is_in_government = yes
					}
				}
				change_variable = { name = coffee_with_milk_progress add = 1 }
			}
			else_if = {
				limit = {
					NOR = {
						has_law = law_type:law_tenant_farmers
						has_law = law_type:law_serfdom
					}
					ig:ig_landowners = {
						is_in_government = no
					}
				}
				change_variable = { name = coffee_with_milk_progress subtract = 1 }
			}
		}
		random_events = {
			500 = 0
			25 = coffee_with_milk.6
			250 = coffee_with_milk.7
			100 = coffee_with_milk.8
			25 = coffee_with_milk.9
			25 = coffee_with_milk.10
			100 = coffee_with_milk.11
			25 = coffee_with_milk.15
			25 = coffee_with_milk.16
		}
	}

	complete = {
		OR = {
			custom_tooltip = {
				text = coffee_with_milk_0_tt
				var:coffee_with_milk_progress <= 0
				has_variable = je_coffee_with_milk_start
			}
			custom_tooltip = {
				text = coffee_with_milk_100_tt
				var:coffee_with_milk_progress >= 240
				has_variable = je_coffee_with_milk_start
			}
		}
	}

	on_complete = {
		if = {
			limit = {
				var:coffee_with_milk_progress >= 120
			}
			trigger_event = { id = coffee_with_milk.12 }
			set_variable = completed_coffee_and_milk_je_landowners
		}
		else_if = {
			limit = {
				var:coffee_with_milk_progress < 120
			}
			trigger_event = { id = coffee_with_milk.13 }
		}
	}

	fail = {
		has_law = law_type:law_collectivized_agriculture
	}

	on_fail = {
		trigger_event = { id = coffee_with_milk.14 }
	}

	invalid = {
		NOT = {
			any_scope_state = {
				count >= 2
				is_capital = no
				has_building = building_coffee_plantation
				has_building = building_livestock_ranch
				is_incorporated = yes
			}
		}
	}

	current_value = {
		value = var:coffee_with_milk_progress
	}
	
	goal_add_value = {
		add = 240
	}

	weight = 100

	progressbar = yes

	should_be_pinned_by_default = yes
}
