// IW6 GSC SOURCE
// Generated by https://github.com/xensik/gsc-tool

main()
{
    setup_callbacks();
}

setup_callbacks()
{
    level.agent_funcs["civ_hvt"] = [];
    level.agent_funcs["civ_hvt"]["spawn"] = ::onspawn;
    level.agent_funcs["civ_hvt"]["think"] = ::agentthink;
    level.agent_funcs["civ_hvt"]["on_killed"] = ::onagentkilled;
    level.agent_funcs["civ_hvt"]["on_damaged"] = maps\mp\agents\_agents::on_agent_player_damaged;
    level.agent_funcs["civ_hvt"]["on_damaged_finished"] = maps\mp\agents\_agents::agent_damage_finished;
}

onspawn( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    self.hvtisfollowing = 0;
    maps\mp\agents\_agents::spawn_agent_player( var_0, var_1, var_2, var_3, var_4, var_5 );
    thread handleplayeruse();
}

onagentkilled( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 )
{
    self.defendnode = undefined;
    self.hvttrigger makeunusable();
    self.hvttrigger = undefined;
    self.body = self cloneagent( var_8 );
    thread maps\mp\gametypes\_damage::delaystartragdoll( self.body, var_6, var_5, var_4, var_0, var_3 );

    if ( isdefined( self.onkilledcallback ) )
        self [[ self.onkilledcallback ]]( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8 );

    maps\mp\agents\_agent_utility::deactivateagent();
    self.owner notify( "hvt_killed" );
}

agentthink()
{
    self notify( "agent_think" );
    self endon( "agent_think" );
    self endon( "death" );
    self endon( "disconnect" );
    level endon( "game_ended" );
    self endon( "owner_disconnect" );

    for (;;)
    {
        if ( self.hvtisfollowing )
        {
            followthink();
            continue;
        }

        waitthink( 150 );
    }
}

waitthink( var_0 )
{
    self botsetstance( "none" );
    self botclearscriptgoal();
    maps\mp\bots\_bots_strategy::bot_disable_tactical_goals();
    var_1 = self.owner maps\mp\agents\_agent_utility::getvalidspawnpathnodenearplayer();
    self.cur_defend_node = undefined;
    self.bot_defending = 1;
    self.bot_defending_center = var_1.origin;
    self.bot_defending_radius = var_0;
    self.cur_defend_stance = "crouch";
    self.bot_defending_type = "protect";

    for ( var_2 = ""; var_2 != "goal"; self.cur_defend_node = undefined )
    {
        self.cur_defend_node = var_1;
        self botsetscriptgoalnode( self.cur_defend_node, "tactical" );
        var_2 = common_scripts\utility::waittill_any_return( "goal", "bad_path" );
        self.node_closest_to_defend_center = var_1;
    }

    childthread maps\mp\bots\_bots_strategy::defense_watch_entrances_at_goal();
    self waittill( "hvt_toggle" );
}

followthink()
{
    self botclearscriptgoal();
    maps\mp\bots\_bots_strategy::bot_disable_tactical_goals();

    if ( !maps\mp\bots\_bots_util::bot_is_guarding_player( self.owner ) )
        maps\mp\bots\_bots_strategy::bot_guard_player( self.owner, 250 );

    self waittill( "hvt_toggle" );
}

handleplayeruse()
{
    level endon( "game_ended" );
    self endon( "death" );

    if ( !isdefined( self.hvttrigger ) )
    {
        self.hvttrigger = spawn( "script_model", self.origin );
        self.hvttrigger linkto( self );
    }

    self.hvttrigger makeusable();

    foreach ( var_1 in level.players )
    {
        if ( var_1 != self.owner )
        {
            self.hvttrigger disableplayeruse( var_1 );
            continue;
        }

        self.hvttrigger enableplayeruse( var_1 );
    }

    thread waitforplayerconnect();

    for (;;)
    {
        setfollowerhintstring();
        self.hvttrigger waittill( "trigger", var_1 );
        self.hvtisfollowing = !self.hvtisfollowing;
        self notify( "hvt_toggle" );
    }
}

setfollowerhintstring()
{
    var_0 = &"MP_HVT_FOLLOW";

    if ( self.hvtisfollowing )
        var_0 = &"MP_HVT_WAIT";

    self.hvttrigger sethintstring( var_0 );
}

waitforplayerconnect()
{
    level endon( "game_ended" );
    self endon( "death" );

    for (;;)
    {
        level waittill( "connected", var_0 );
        self.hvttrigger disableplayeruse( var_0 );
    }
}
