on_actions = {
    on_startup = {
        effect = {
            if = {
                limit = { has_global_flag = rl_setup_complete NOT = { has_global_flag = rl_ruleset_configured } }
                set_global_flag = rl_ruleset_configured
                set_global_flag = rl_ruleset_standard
                clr_global_flag = rl_ruleset_hardcore
            }
            if = {
                limit = { has_global_flag = rl_setup_complete NOT = { has_global_flag = rl_hc_replace_mode_configured } }
                set_global_flag = rl_hc_replace_mode_configured
                set_global_flag = rl_hc_manual_replace
                clr_global_flag = rl_hc_auto_replace_weakest
            }
            if = {
                limit = { has_global_flag = rl_setup_complete NOT = { has_global_flag = rl_counterpower_configured } }
                every_country = {
                    limit = { is_ai = no }
                    rl_migrate_v36_counterpower = yes
                }
            }
            # v3.7.0: the setup is read from the game rules instead of in-game events
            if = {
                limit = { NOT = { has_global_flag = rl_setup_complete } }
                random_country = {
                    limit = { is_ai = no }
                    rl_apply_game_rule_setup = yes
                }
            }
        }
    }
    on_weekly = {
        effect = {
            if = {
                limit = { NOT = { has_global_flag = rl_setup_complete } is_ai = no }
                rl_apply_game_rule_setup = yes
            }
            else_if = {
                limit = { has_global_flag = rl_setup_complete NOT = { has_global_flag = rl_v24_configured } is_ai = no }
                rl_apply_game_rule_frequency = yes
                rl_apply_game_rule_rarity = yes
                rl_sync_rarity_distribution = yes
                set_global_flag = rl_v24_configured
                set_global_flag = rl_v241_configured
            }
            else_if = {
                limit = { has_global_flag = rl_setup_complete has_global_flag = rl_v24_configured NOT = { has_global_flag = rl_v241_configured } is_ai = no }
                rl_apply_game_rule_rarity = yes
                rl_sync_rarity_distribution = yes
                set_global_flag = rl_v241_configured
            }
            else_if = {
                limit = {
                    has_global_flag = rl_setup_complete
                    OR = { has_global_flag = rl_freq_weekly has_global_flag = rl_freq_biweekly }
                    OR = { has_global_flag = rl_mode_all AND = { has_global_flag = rl_mode_player_only is_ai = no } }
                }
                rl_initialize_country = yes
                rl_handle_weekly_offer_schedule = yes
            }
            # v3.8.0: deliver queued offers and clear stale offer state
            if = {
                limit = { has_global_flag = rl_setup_complete is_ai = no }
                rl_offer_clear_stale_state = yes
                rl_offer_queue_pump = yes
            }
            # v3.8.3: keep the TOTAL division training time above -100 % (other sources can change at any time)
            if = {
                limit = { has_global_flag = rl_setup_complete }
                rl_weekly_training_time_check = yes
            }
        }
    }
    on_monthly = {
        effect = {
            if = {
                limit = { has_global_flag = rl_setup_complete has_global_flag = rl_mode_player_only is_ai = no }
                rl_update_global_player_only_escalation = yes
            }
            # v3.8.0: AI countries that missed a counterpower update (e.g. newly released nations) catch up monthly
            else_if = {
                limit = { has_global_flag = rl_setup_complete has_global_flag = rl_mode_player_only is_ai = yes }
                rl_v38_apply_ai_counterpower_if_outdated = yes
            }
            if = {
                limit = { NOT = { has_global_flag = rl_setup_complete } is_ai = no }
                rl_apply_game_rule_setup = yes
            }
            else_if = {
                limit = {
                    has_global_flag = rl_setup_complete
                    OR = { has_global_flag = rl_mode_all AND = { has_global_flag = rl_mode_player_only is_ai = no } }
                }
                rl_initialize_country = yes
                rl_run_monthly_specials = yes
                rl_handle_monthly_offer_schedule = yes
            }
        }
    }
}
