############################################################
##            Elite Recruitment Common Helpers            ##
############################################################
##                                                        ##
## Common helper effects to add flavor to the Elite       ##
## Recruitment mod.                                       ##
##                                                        ##
############################################################

# Assign a random age to the base character
assign_random_adult_age_effect = {
  random_list = {
    1 = {} # Stays 16
    2 = { add_age = 1 } # Becomes 17
    3 = { add_age = 2 } # Becomes 18
    4 = { add_age = 3 } # Becomes 19
    5 = { add_age = 4 } # Becomes 20
    5 = { add_age = 5 } # Becomes 21
    5 = { add_age = 6 } # Becomes 22
    5 = { add_age = 7 } # Becomes 23
    5 = { add_age = 8 } # Becomes 24
    5 = { add_age = 9 } # Becomes 25
    4 = { add_age = 10 } # Becomes 26
    4 = { add_age = 11 } # Becomes 27
    4 = { add_age = 12 } # Becomes 28
    4 = { add_age = 13 } # Becomes 29
    4 = { add_age = 14 } # Becomes 30
    3 = { add_age = 15 } # Becomes 31
    3 = { add_age = 16 } # Becomes 32
    3 = { add_age = 17 } # Becomes 33
    3 = { add_age = 18 } # Becomes 34
    3 = { add_age = 19 } # Becomes 35
    2 = { add_age = 20 } # Becomes 36
    2 = { add_age = 21 } # Becomes 37
    2 = { add_age = 22 } # Becomes 38
    2 = { add_age = 23 } # Becomes 39
    2 = { add_age = 24 } # Becomes 40
    1 = { add_age = 25 } # Becomes 41
    1 = { add_age = 26 } # Becomes 42
    1 = { add_age = 27 } # Becomes 43
    1 = { add_age = 28 } # Becomes 44
    1 = { add_age = 29 } # Becomes 45
    1 = { add_age = 30 } # Becomes 46
    1 = { add_age = 31 } # Becomes 47
    1 = { add_age = 32 } # Becomes 48
    1 = { add_age = 33 } # Becomes 49
    1 = { add_age = 34 } # Becomes 50
  }
}

# Assign religion-specific traits to the base character
assign_religion_traits_effect = {
  if = {
    limit = { has_dharmic_religion_trigger = yes }

    # Priest caste (brahmin) for a clergy recruit flagged elite_recruit_chaplain (the chaplain);
    # the warrior caste (kshatriya) for everyone else.
    if = {
      limit = { has_character_flag = elite_recruit_chaplain }
      add_trait = brahmin
    }
    else = {
      add_trait = kshatriya
    }
    character_event = { id = RoI.30121 }
  } else_if = {
    limit = {
      OR = {
        religion_openly_hellenic_or_reformed_trigger = yes
        has_religion_feature = religion_astrology
      }
    }

    add_western_zodiac_trait_effect = yes
  }

  if = {
    limit = {
      has_religion_feature = religion_no_leader
      religion_group = pagan_group
    }

    random_list = {
      5 = { add_trait = pagan_branch_1 }
      25 = { add_trait = pagan_branch_2 }
      25 = { add_trait = pagan_branch_3 }
      25 = { add_trait = pagan_branch_4 }
    }
  }
}

# Per-role recruitment costs, all scaled together by the single elite_recruitment
# tier rule. Gold uses scaled_wealth (a fraction of yearly income) backed by a firm
# min floor, so the charge stays meaningful even for low-income rulers; for most
# small and mid realms it is the floor, not the income fraction, that binds. Each
# role's secondary currency suits its office: Prestige for the secular advisors,
# Piety for the chaplain. Modicum is the default tier and the rule-absent fallback.

# Marshal: balanced gold and Prestige.
pay_elite_marshal_cost_effect = {
  if = {
    limit = { has_game_rule = { name = elite_recruitment value = pittance } }
    scaled_wealth = { value = -0.125 min = -8 }
    prestige = -25
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = trifle } }
    scaled_wealth = { value = -0.25 min = -15 }
    prestige = -50
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = bounty } }
    scaled_wealth = { value = -1.0 min = -60 }
    prestige = -200
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = fortune } }
    scaled_wealth = { value = -2.0 min = -120 }
    prestige = -400
  }
  else = { # modicum
    scaled_wealth = { value = -0.5 min = -30 }
    prestige = -100
  }
}

# Steward: heaviest gold, lightest Prestige.
pay_elite_steward_cost_effect = {
  if = {
    limit = { has_game_rule = { name = elite_recruitment value = pittance } }
    scaled_wealth = { value = -0.25 min = -12 }
    prestige = -5
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = trifle } }
    scaled_wealth = { value = -0.5 min = -25 }
    prestige = -10
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = bounty } }
    scaled_wealth = { value = -2.0 min = -100 }
    prestige = -50
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = fortune } }
    scaled_wealth = { value = -4.0 min = -200 }
    prestige = -100
  }
  else = { # modicum
    scaled_wealth = { value = -1.0 min = -50 }
    prestige = -25
  }
}

# Chancellor: light gold, heaviest Prestige.
pay_elite_chancellor_cost_effect = {
  if = {
    limit = { has_game_rule = { name = elite_recruitment value = pittance } }
    scaled_wealth = { value = -0.0625 min = -5 }
    prestige = -35
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = trifle } }
    scaled_wealth = { value = -0.125 min = -10 }
    prestige = -75
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = bounty } }
    scaled_wealth = { value = -0.5 min = -40 }
    prestige = -300
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = fortune } }
    scaled_wealth = { value = -1.0 min = -80 }
    prestige = -600
  }
  else = { # modicum
    scaled_wealth = { value = -0.25 min = -20 }
    prestige = -150
  }
}

# Spymaster: more gold than Prestige.
pay_elite_spymaster_cost_effect = {
  if = {
    limit = { has_game_rule = { name = elite_recruitment value = pittance } }
    scaled_wealth = { value = -0.1875 min = -10 }
    prestige = -10
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = trifle } }
    scaled_wealth = { value = -0.375 min = -20 }
    prestige = -25
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = bounty } }
    scaled_wealth = { value = -1.5 min = -80 }
    prestige = -100
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = fortune } }
    scaled_wealth = { value = -3.0 min = -160 }
    prestige = -200
  }
  else = { # modicum
    scaled_wealth = { value = -0.75 min = -40 }
    prestige = -50
  }
}

# Chaplain: heaviest Piety, a little gold.
pay_elite_chaplain_cost_effect = {
  if = {
    limit = { has_game_rule = { name = elite_recruitment value = pittance } }
    scaled_wealth = { value = -0.0625 min = -5 }
    piety = -35
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = trifle } }
    scaled_wealth = { value = -0.125 min = -10 }
    piety = -75
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = bounty } }
    scaled_wealth = { value = -0.5 min = -40 }
    piety = -300
  }
  else_if = {
    limit = { has_game_rule = { name = elite_recruitment value = fortune } }
    scaled_wealth = { value = -1.0 min = -80 }
    piety = -600
  }
  else = { # modicum
    scaled_wealth = { value = -0.25 min = -20 }
    piety = -150
  }
}
