# =====================
# 朝鲜官僚资产阶级危机 - 脚本效果
# =====================

# 初始化危机变�?
CZD_crisis_initialize_variables = {
	if = {
		limit = {
			NOT = { has_variable = CZD_bureaucratic_bourgeoisie_power }
		}
		set_variable = { var = CZD_bureaucratic_bourgeoisie_power value = 0 }
	}
	if = {
		limit = {
			NOT = { has_variable = CZD_counterrevolution_level }
		}
		set_variable = { var = CZD_counterrevolution_level value = 0 }
	}
	if = {
		limit = {
			NOT = { has_variable = CZD_purge_intensity }
		}
		set_variable = { var = CZD_purge_intensity value = 0 }
	}
	if = {
		limit = {
			NOT = { has_variable = CZD_revolutionary_momentum }
		}
		set_variable = { var = CZD_revolutionary_momentum value = 0 }
	}
}

# 触发危机开�?
CZD_crisis_trigger_start = {
	country_event = { id = czd_crisis.1 }
}

# 历史路线 - 出身成分制度
CZD_crisis_apply_songbun = {
	country_event = { id = czd_crisis.10 }
}

# 历史路线 - 秘密警察网络
CZD_crisis_apply_secret_police = {
	country_event = { id = czd_crisis.11 }
}

# 历史路线 - 革命血�?
CZD_crisis_apply_bloodline = {
	country_event = { id = czd_crisis.12 }
}

# 历史路线 - 十大原则
CZD_crisis_apply_ten_principles = {
	country_event = { id = czd_crisis.13 }
}

# 历史路线 - 红色王朝
CZD_crisis_apply_red_dynasty = {
	country_event = { id = czd_crisis.14 }
}

# 激进路�?- 政治危机
CZD_crisis_apply_political_crisis = {
	country_event = { id = czd_crisis.20 }
}

# 激进路�?- 打碎旧世�?
CZD_crisis_apply_break_old_world = {
	country_event = { id = czd_crisis.21 }
}

# 激进路�?- 红色风暴
CZD_crisis_apply_red_storm = {
	country_event = { id = czd_crisis.22 }
}

# 激进路�?- 革命十字路口
CZD_crisis_revolutionary_crossroads = {
	country_event = { id = czd_crisis.23 }
}

# 五丈原路�?- 燃尽光芒
CZD_crisis_apply_wuzhangyuan_purge = {
	country_event = { id = czd_crisis.30 }
}

# 五丈原路�?- 最后结局
CZD_crisis_apply_wuzhangyuan_ending = {
	country_event = { id = czd_crisis.31 }
}

# 世界解放路线 - 国际革命号角
CZD_crisis_apply_world_liberation_fervor = {
	country_event = { id = czd_crisis.40 }
}

# 世界解放路线 - 最后结局
CZD_crisis_apply_world_liberation_ending = {
	country_event = { id = czd_crisis.41 }
}

# 增加官僚资产阶级力量
CZD_crisis_increase_bureaucratic_power = {
	add_to_variable = { var = CZD_bureaucratic_bourgeoisie_power value = 5 }
	add_to_variable = { var = CZD_bureaucratic_bourgeoisie value = 5 }
	clamp_variable = {
		var = CZD_bureaucratic_bourgeoisie_power
		min = 0
		max = 100
	}
	clamp_variable = {
		var = CZD_bureaucratic_bourgeoisie
		min = 0
		max = 100
	}
}

# 减少官僚资产阶级力量
CZD_crisis_decrease_bureaucratic_power = {
	add_to_variable = { var = CZD_bureaucratic_bourgeoisie_power value = -5 }
	add_to_variable = { var = CZD_bureaucratic_bourgeoisie value = -5 }
	clamp_variable = {
		var = CZD_bureaucratic_bourgeoisie_power
		min = 0
		max = 100
	}
	clamp_variable = {
		var = CZD_bureaucratic_bourgeoisie
		min = 0
		max = 100
	}
}

# 增加反革命程�?
CZD_crisis_increase_counterrevolution = {
	add_to_variable = { var = CZD_counterrevolution_level value = 5 }
	clamp_variable = {
		var = CZD_counterrevolution_level
		min = 0
		max = 100
	}
}

# 增加清洗力度
CZD_crisis_increase_purge = {
	add_to_variable = { var = CZD_purge_intensity value = 5 }
	clamp_variable = {
		var = CZD_purge_intensity
		min = 0
		max = 100
	}
}

# 增加革命动能
CZD_crisis_increase_momentum = {
	add_to_variable = { var = CZD_revolutionary_momentum value = 5 }
	clamp_variable = {
		var = CZD_revolutionary_momentum
		min = 0
		max = 100
	}
}

# 检查是否应触发危机
CZD_crisis_check_trigger = {
	if = {
		limit = {
			check_variable = { var = CZD_bureaucratic_bourgeoisie_power value > 60 compare = greater_than }
			NOT = { has_country_flag = CZD_crisis_started }
		}
		CZD_crisis_trigger_start = yes
	}
}

# 清理所有危机相关国民精�?
CZD_crisis_cleanup_ideas = {
	if = {
		limit = { has_idea = CZD_escalating_class_contradictions }
		remove_ideas = CZD_escalating_class_contradictions
	}
	if = {
		limit = { has_idea = CZD_political_crisis }
		remove_ideas = CZD_political_crisis
	}
	if = {
		limit = { has_idea = CZD_break_the_old_world }
		remove_ideas = CZD_break_the_old_world
	}
	if = {
		limit = { has_idea = CZD_red_storm }
		remove_ideas = CZD_red_storm
	}
	if = {
		limit = { has_idea = CZD_purge_ongoing }
		remove_ideas = CZD_purge_ongoing
	}
	if = {
		limit = { has_idea = CZD_revolutionary_fervor }
		remove_ideas = CZD_revolutionary_fervor
	}
	if = {
		limit = { has_idea = CZD_party_split }
		remove_ideas = CZD_party_split
	}
	if = {
		limit = { has_idea = CZD_final_reckoning }
		remove_ideas = CZD_final_reckoning
	}
}

# =====================================================
# 难以入眠的夜晚 - 章节进展追踪
# =====================================================

# 检查并推进章节
CZD_sleepless_check_chapter_progress = {
	# 检查第一章进度 (需要触发3个事件)
	if = {
		limit = {
			NOT = { has_country_flag = CZD_sleepless_chapter_1_done }
			check_variable = { CZD_sleepless_chapter_1_count > 2 }
		}
		set_country_flag = CZD_sleepless_chapter_1_done
		custom_effect_tooltip = czd_sleepless_chapter_1_complete_tt
	}
	# 检查第二章进度
	if = {
		limit = {
			has_country_flag = CZD_sleepless_chapter_1_done
			NOT = { has_country_flag = CZD_sleepless_chapter_2_done }
			check_variable = { CZD_sleepless_chapter_2_count > 2 }
		}
		set_country_flag = CZD_sleepless_chapter_2_done
		custom_effect_tooltip = czd_sleepless_chapter_2_complete_tt
	}
	# 检查第三章进度
	if = {
		limit = {
			has_country_flag = CZD_sleepless_chapter_2_done
			NOT = { has_country_flag = CZD_sleepless_chapter_3_done }
			check_variable = { CZD_sleepless_chapter_3_count > 2 }
		}
		set_country_flag = CZD_sleepless_chapter_3_done
		custom_effect_tooltip = czd_sleepless_chapter_3_complete_tt
	}
	# 检查第四章进度
	if = {
		limit = {
			has_country_flag = CZD_sleepless_chapter_3_done
			NOT = { has_country_flag = CZD_sleepless_chapter_4_done }
			check_variable = { CZD_sleepless_chapter_4_count > 2 }
		}
		set_country_flag = CZD_sleepless_chapter_4_done
		custom_effect_tooltip = czd_sleepless_chapter_4_complete_tt
	}
	# 检查第五章进度
	if = {
		limit = {
			has_country_flag = CZD_sleepless_chapter_4_done
			NOT = { has_country_flag = CZD_sleepless_chapter_5_done }
			check_variable = { CZD_sleepless_chapter_5_count > 2 }
		}
		set_country_flag = CZD_sleepless_chapter_5_done
		custom_effect_tooltip = czd_sleepless_chapter_5_complete_tt
	}
	# 检查第六章进度
	if = {
		limit = {
			has_country_flag = CZD_sleepless_chapter_5_done
			NOT = { has_country_flag = CZD_sleepless_chapter_6_done }
			check_variable = { CZD_sleepless_chapter_6_count > 2 }
		}
		set_country_flag = CZD_sleepless_chapter_6_done
		custom_effect_tooltip = czd_sleepless_chapter_6_complete_tt
	}
}

# 初始化难以入眠的夜晚变量
CZD_sleepless_initialize = {
	if = {
		limit = { NOT = { has_variable = CZD_sleepless_chapter_1_count } }
		set_variable = { CZD_sleepless_chapter_1_count = 0 }
	}
	if = {
		limit = { NOT = { has_variable = CZD_sleepless_chapter_2_count } }
		set_variable = { CZD_sleepless_chapter_2_count = 0 }
	}
	if = {
		limit = { NOT = { has_variable = CZD_sleepless_chapter_3_count } }
		set_variable = { CZD_sleepless_chapter_3_count = 0 }
	}
	if = {
		limit = { NOT = { has_variable = CZD_sleepless_chapter_4_count } }
		set_variable = { CZD_sleepless_chapter_4_count = 0 }
	}
	if = {
		limit = { NOT = { has_variable = CZD_sleepless_chapter_5_count } }
		set_variable = { CZD_sleepless_chapter_5_count = 0 }
	}
	if = {
		limit = { NOT = { has_variable = CZD_sleepless_chapter_6_count } }
		set_variable = { CZD_sleepless_chapter_6_count = 0 }
	}
}

# 记录第一章事件触发
CZD_sleepless_chapter_1_event_triggered = {
	CZD_sleepless_initialize = yes
	add_to_variable = { CZD_sleepless_chapter_1_count = 1 }
	CZD_sleepless_check_chapter_progress = yes
}

# 记录第二章事件触发
CZD_sleepless_chapter_2_event_triggered = {
	add_to_variable = { CZD_sleepless_chapter_2_count = 1 }
	CZD_sleepless_check_chapter_progress = yes
}

# 记录第三章事件触发
CZD_sleepless_chapter_3_event_triggered = {
	add_to_variable = { CZD_sleepless_chapter_3_count = 1 }
	CZD_sleepless_check_chapter_progress = yes
}

# 记录第四章事件触发
CZD_sleepless_chapter_4_event_triggered = {
	add_to_variable = { CZD_sleepless_chapter_4_count = 1 }
	CZD_sleepless_check_chapter_progress = yes
}

# 记录第五章事件触发
CZD_sleepless_chapter_5_event_triggered = {
	add_to_variable = { CZD_sleepless_chapter_5_count = 1 }
	CZD_sleepless_check_chapter_progress = yes
}

# 记录第六章事件触发
CZD_sleepless_chapter_6_event_triggered = {
	add_to_variable = { CZD_sleepless_chapter_6_count = 1 }
	CZD_sleepless_check_chapter_progress = yes
}


