-------------------------------------------------
--              Damage AND Health
-------------------------------------------------

function p.xar_get_level_mod_damage_out(delta) 
    if (delta == -1) then return 0.5 end
    return 1.0
end

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

function p.type_init(id)
    game_ment_type_init.player_proj(id)
    ia_ment_set_builtin_var_f(id, "__ttl", 2.0)
    ia_ment_set_builtin_var_i(id, "__extra_min_levels", 1)
    ia_ment_set_builtin_var_f(id, "__radius", 0.001)
    ia_ment_set_builtin_var_s(id, "__mesh", "dummy")
    ia_ment_new_static_var_b(id, "identifies", true)
end

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

function p.on_level_travel(
    inst_id, level,
    start_vec,
    end_vec)
    --Getting level info.
    local start_level = ga_ment_get_i(inst_id, "__start_level")
    local diff = start_level - level

    if diff > 0 then return end

    local args = {}
    args.level = level
    args.pos_start = start_vec
    args.pos_end = end_vec
    args.ttl_min = 0.5
    args.ttl_max = 0.5
    args.size_min = 0.1
    args.size_max = 0.1
    args.color = std.vec(1.0, 1.0, 1.0)
    args.fade_time_min = 0.5
    args.fade_time_max = 0.5
    args.speed_min = 0.0
    args.speed_max = 0.0
    args.tex = "particle_2"
    args.radius_min = 0.0
    args.radius_max = 0.0
    args.avg_len = 1.0
    args.use_min_dist = false
    ga_particle_trail(args)
end

-------------------------------------------------
--         Movement Hitting Callbacks
-------------------------------------------------

function p.on_ment_hit(
    source_inst_id,
    target_inst_id,
    level, lp, normal)
--
    local args = {}
    args.source_inst_id = source_inst_id
    args.target_inst_id = target_inst_id
    args.level = level
    args.lp = lp
    args.normal = normal
    --
    local ret = game_ment_hit.process_hit_and_got_hit(args)
    return ret.terminal_hit
end

function p.on_block_hit(
    inst_id,
    level, bp, lp,
    normal_side, normal)
--
    local start_level = ga_ment_get_i(inst_id, "__start_level")
    local sllp = ga_convert_lp(level, start_level, lp).value

    --Sparks.
    for i = 0,5 do
        local dir = {}
        dir.x = normal.x + (ga_randf() - 0.5)
        dir.y = normal.y + (ga_randf() - 0.5)
        dir.z = normal.z + (ga_randf() - 0.5)

        local args = {}
        args.level = start_level
        args.pos = sllp
        args.ttl = 2.0
        args.size = 0.4
        args.color = std.vec(1.0, 1.0, 0.0)
        args.fade_time = 0.5
        args.vel = std.vec_scale(dir, 0.5)
        args.tex = "particle_2"
        args.use_min_dist = false
        ga_particle_add(args)
    end
    return true
end
