#include "../../config/campaign.lua"
#include "../../script/helpers/entity.lua"

function init()
    locs = FindLocations("championship_cup")
    for i = 1, #locs do repeat
        local loc = locs[i]
        local championship_idx = tonumber(GetTagValue(loc, "championship_cup"))
        local _, campaign = GetChampionshipByIndex(championship_idx)
        if not campaign then break end

        local reward = GetInt("savegame.mod.campaign"..campaign)
        local reward_name
        if reward == 4 then
            reward_name = "gold"
        elseif reward == 3 then
            reward_name = "silver"
        elseif reward == 2 then
            reward_name = "bronze"
        else break end
        local reward_upper = reward_name:upper()

        if championship_idx == 5 then
            reward_name = reward_name .. "_docks"
        end
        Spawn('<vox rot="0.0 180.0 0.0" file="MOD/m_lobby/vox/chalice_rewards.vox" tags="unbreakable" desc="loc@CHAMPIONSHIP_CUP_'.. championship_idx ..',loc@REWARD_'.. reward_upper ..'" prop="true" object="'.. championship_idx ..'_'.. reward_name ..'"/>', GetLocationTransform(loc), true, true)
    until true end

    cEntity:EnqueueDeletion()
end
