@TOTAL_NUM_OF_ARTICLES = 186

# use the effect name without the "d_" in the console
d_world_news_console_commands = {
	log = D_WORLD_NEWS_CONSOLE_COMMANDS_TT
	log = "   world_news_console_commands"
	log = "   open_newspaper"
	log = "   close_newspaper"
	log = "   open_newspaper_settings"
	log = "   close_newspaper_settings"
	log = "   set_test_article_into_newspaper"
	log = "   create_new_weekly_newspaper_edition"
	log = "   list_countries_with_custom_newspaper_headers"
	log = "   get_total_num_of_newspaper_articles"
	log = "   list_current_newspaper_article_ids"
	log = " "
	log = D_WORLD_NEWS_CONSOLE_COMMANDS_TT_2
}

d_open_newspaper = {
	FROM = {
		specify_current_newspaper_for_load = yes
		set_variable = { show_newspaper_window = 1 }
		clear_variable = show_newspaper_topbar_alert
		if = {
			limit = {
				NOT = { has_country_flag = disable_newspaper_sounds }
			}
			scoped_sound_effect = "newspaper_page_sounds"
		}
	}
	log = D_OPEN_NEWSPAPER_TT
}

d_close_newspaper = {
	FROM = {
		clear_variable = show_newspaper_window
		clear_variable = show_newspaper_topbar_alert
		clear_variable = show_newspaper_archive_window
		if = {
			limit = {
				NOT = { has_country_flag = disable_newspaper_sounds }
			}
			scoped_sound_effect = "newspaper_close_sound"
		}
		clear_displayed_newspaper_variables = yes
	}
	log = D_CLOSE_NEWSPAPER_TT
}

d_open_newspaper_settings = {
	FROM = {
		set_variable = { show_newspaper_alert_settings_window = 1 }
	}
	log = D_OPEN_NEWSPAPER_SETTINGS_TT
}

d_close_newspaper_settings = {
	FROM = {
		clear_variable = show_newspaper_alert_settings_window
	}
	log = D_CLOSE_NEWSPAPER_SETTINGS_TT
}

d_set_test_article_into_newspaper = {
	if = {
		limit = {
			is_debug = yes
		}
		FROM = {
			set_temp_variable = { current_max_articles = @TOTAL_NUM_OF_ARTICLES }
			if = {
				limit = {
					check_variable = { args^num = 2 }
				}
				set_temp_variable = { article_id = args^0 }
				set_temp_variable = { article_index = args^1 }
				round_temp_variable = article_id
				round_temp_variable = article_index
				clamp_temp_variable = {
					var = article_id
					min = 1
					max = @TOTAL_NUM_OF_ARTICLES
				}
				clamp_temp_variable = {
					var = article_index
					min = 0
					max = 7
				}
				if = {
					limit = {
						NOT = { is_in_array = { global.newspaper_articles = article_id } }
					}
					set_id_for_article_index = yes
					log = D_SET_TEST_ARTICLE_INTO_NEWSPAPER_TT
					log = D_SET_TEST_ARTICLE_INTO_NEWSPAPER_TT_2
					reload_current_newspaper_for_everyone = yes
				}
				else = {
					log = D_SET_TEST_ARTICLE_INTO_NEWSPAPER_TT_ARTICLE_ALREADY_IN_NEWSPAPER
				}
			}
			else = {
				log = D_SET_TEST_ARTICLE_INTO_NEWSPAPER_TT_INVALID_ARGUMENTS
			}
		}
	}
	else = {
		log = NEWSPAPER_CONSOLE_COMMAND_ONLY_WITH_DEBUG_MODE
	}
}

d_create_new_weekly_newspaper_edition = {
	if = {
		limit = {
			is_debug = yes
		}
		FROM = {
			generate_new_weekly_newspaper_edition_effect = yes
		}
		log = D_CREATE_NEW_WEEKLY_NEWSPAPER_EDITION_TT
	}
	else = {
		log = NEWSPAPER_CONSOLE_COMMAND_ONLY_WITH_DEBUG_MODE
	}
}

d_list_countries_with_custom_newspaper_headers = {
	log = D_LIST_COUNTRIES_WITH_CUSTOM_NEWSPAPER_HEADERS_TT
	every_country = {
		limit = {
			OR = {
				AND = {
					country_has_custom_newspaper_header = yes
					var:original_tag = {
						tag = PREV
					}
				}
				has_cosmetic_tag = OTT_UNIFIED
				has_cosmetic_tag = OTT_UNIFIED_fascism
				has_cosmetic_tag = OTT_UNIFIED_communism
				has_cosmetic_tag = OTT_UNIFIED_democratic
				has_cosmetic_tag = OTT_UNIFIED_neutrality
				has_cosmetic_tag = OTT_SULTANATE
				has_cosmetic_tag = OTT_SULTANATE_fascism
				has_cosmetic_tag = OTT_SULTANATE_communism
				has_cosmetic_tag = OTT_SULTANATE_democratic
				has_cosmetic_tag = OTT_SULTANATE_neutrality
			}
		}
		log = "   - [This.GetNameWithFlag]"
	}
}

d_get_total_num_of_newspaper_articles = {
	set_temp_variable = { current_max_articles = @TOTAL_NUM_OF_ARTICLES }
	log = D_GET_TOTAL_NUM_OF_NEWSPAPER_ARTICLES_TT
}

d_list_current_newspaper_article_ids = {
	if = {
		limit = {
			is_debug = yes
		}
		log = D_LIST_CURRENT_NEWSPAPER_ARTICLE_IDS_TT
		FROM = {
			if = {
				limit = {
					check_variable = { display_newspaper_articles^num > 0 }
				}
				for_each_loop = {
					array = display_newspaper_articles
					value = v
					index = i
					set_temp_variable = { article_id = v }
					set_temp_variable = { article_index = i }
					log = D_LIST_CURRENT_NEWSPAPER_ARTICLE_IDS_ENTRY_TT
				}
			}
			else = {
				for_each_loop = {
					array = global.newspaper_articles
					value = v
					index = i
					set_temp_variable = { article_id = v }
					set_temp_variable = { article_index = i }
					log = D_LIST_CURRENT_NEWSPAPER_ARTICLE_IDS_ENTRY_TT
				}
			}
		}
	}
	else = {
		log = NEWSPAPER_CONSOLE_COMMAND_ONLY_WITH_DEBUG_MODE
	}
}