-------------------------------------------------
--            Type Init Function
-------------------------------------------------

function p.__type_init(id)
    game_ment_type_init.player_proj(id)
    ia_ment_set_builtin_var_i(id, "__extra_min_levels", 2)
    ia_ment_set_builtin_var_f(id, "__radius", 1.0) --Will set.
    ia_ment_set_builtin_var_s(id, "__mesh", "rocket1_explosion")
    ia_ment_set_builtin_var_f(id, "__ttl", 1.0)

    --The level in which the rocket was launched.
    ia_ment_new_var_f(id, "launch_level", -1, 60*60)
end

-------------------------------------------------
--              Inst Functions
-------------------------------------------------

function p.__on_add_to_live_world(inst_id)
    local mode = 1
    p.spawn_helper1(inst_id, mode)
end

function p.spawn_helper1(inst_id, mode)
    local wep = 4
    local base_radius = game_wep_modes.get_radius(wep, mode)
    base_radius = base_radius * 0.25
    p.spawn_helper2(inst_id, base_radius)
end

function p.spawn_helper2(inst_id, base_radius)
    local radius = base_radius
    local launch_level = ga_ment_get_f(inst_id, "launch_level")
    local ment_level = ga_ment_get_level(inst_id)
    local scale_factor = ga_level_scale_factor(launch_level, ment_level)
    radius = radius * scale_factor.value
    ga_ment_set_f(inst_id, "__radius", radius)
    --
    local duration = 1.0
    p.start_death_animation(inst_id, duration)
end

function p.start_death_animation(inst_id, duration)
    if ga_ment_get_s(inst_id, "__death_anim") ~= "" then return end
    --
    ga_ment_set_s(inst_id, "__death_anim", "alpha_fade")
    ga_ment_set_f(inst_id, "__death_anim_alpha_fade_alpha1", 0.75)
    ga_ment_set_f(inst_id, "__death_anim_alpha_fade_alpha2", 0.0)
    local game_time = ga_get_game_time()
    ga_ment_set_f(inst_id, "__death_anim_start", game_time)
    ga_ment_set_f(inst_id, "__death_anim_end", game_time + duration)
end
