﻿# 2.6.2 — Educate the Realm: an explicit anti-grind cultural breakthrough system.
# The lifetime charge is the scarce resource; currencies are intentionally irrelevant.

ddm_prepare_educate_realm_effect = {
    if = { limit = { NOT = { has_variable = ddm_educate_realm_uses } } set_variable = { name = ddm_educate_realm_uses value = 0 } }
    set_variable = { name = ddm_educate_realm_remaining value = 4 }
    change_variable = { name = ddm_educate_realm_remaining subtract = var:ddm_educate_realm_uses }
    if = { limit = { var:ddm_educate_realm_remaining < 0 } set_variable = { name = ddm_educate_realm_remaining value = 0 } }
    set_variable = { name = ddm_educate_realm_breakthrough_count value = 0 }
    if = { limit = { highest_held_title_tier = tier_duchy } set_variable = { name = ddm_educate_realm_breakthrough_count value = 1 } }
    else_if = { limit = { highest_held_title_tier = tier_kingdom } set_variable = { name = ddm_educate_realm_breakthrough_count value = 2 } }
    else_if = { limit = { OR = { highest_held_title_tier = tier_empire highest_held_title_tier = tier_hegemony } } set_variable = { name = ddm_educate_realm_breakthrough_count value = 3 } }
}

ddm_educate_realm_breakthrough_effect = {
    ddm_prepare_educate_realm_effect = yes
    if = {
        limit = { var:ddm_educate_realm_remaining > 0 var:ddm_educate_realm_breakthrough_count > 0 exists = culture }
        # add_random_innovation only chooses innovations currently available to the culture; if the
        # culture has fewer eligible discoveries remaining than the ruler's rank allowance, the extras
        # naturally no-op rather than reaching into a future era.
        culture = { add_random_innovation = yes }
        if = { limit = { var:ddm_educate_realm_breakthrough_count >= 2 } culture = { add_random_innovation = yes } }
        if = { limit = { var:ddm_educate_realm_breakthrough_count >= 3 } culture = { add_random_innovation = yes } }
        set_variable = { name = ddm_educate_realm_last_count value = var:ddm_educate_realm_breakthrough_count }
        change_variable = { name = ddm_educate_realm_uses add = 1 }
        ddm_prepare_educate_realm_effect = yes
        send_interface_toast = { type = event_toast_effect_good title = DDM_EDUCATE_REALM_TOAST left_icon = root }
    }
}
