/*
==================
BotSetupAlternateRoutesBB
==================
*/

void BotSetupAlternateRoutesBB(void) {

    vec3_t start, end, temporigin;
    int entnum;
    int areanum;
    int areas[10];
    int dist_red, dist_blue;
    int r_count;
    int b_count;
    int base_dist, alert_area;
    gentity_t	*ent;

    if (altroutegoals_setup == qtrue)
        return;

    if (gametype < GT_CTF)
        return;

    r_count = 0;
    b_count = 0;

    //used to get the distance between bases and thier flags
    //then and alert area around the base
    base_dist = trap_AAS_AreaTravelTimeToGoalArea(ctf_redflag.areanum,
                ctf_redflag.origin, ctf_blueflag.areanum, TFL_DEFAULT);

    alert_area = base_dist * 0.35;

    BotAI_Print(PRT_MESSAGE, " \n");
    BotAI_Print(PRT_MESSAGE, "^5Base Distances - %i^7\n", base_dist;

                BotAI_Print(PRT_MESSAGE, "^5Base Alert Zone - %i^7\n", alert_area);
                BotAI_Print(PRT_MESSAGE, " \n");

                /*
                Used to collect item to populate the Alternate routeing
                with Game enities
                */
                for (entnum = 0; entnum < MAX_GENTITIES; entnum++) {

                ent = &g_entities[entnum]
                          ;

                    if (

                        !Q_stricmp(ent->classname, "item_armor_body") ||
                        !Q_stricmp(ent->classname, "item_armor_combat") ||
                        !Q_stricmp(ent->classname, "item_health_large") ||
                        !Q_stricmp(ent->classname, "item_health_mega") ||
                        !Q_stricmp(ent->classname, "item_health_small") ||
                        !Q_stricmp(ent->classname, "item_health") ||
                        /*
                                                !Q_stricmp(ent->classname, "item_armor_shard") ||
                                                !Q_stricmp(ent->classname, "ammo_bullets") ||
                                                !Q_stricmp(ent->classname, "ammo_cells") ||
                                                !Q_stricmp(ent->classname, "ammo_grenades") ||
                                                !Q_stricmp(ent->classname, "ammo_lightning") ||
                                                !Q_stricmp(ent->classname, "ammo_rockets") ||
                                                !Q_stricmp(ent->classname, "ammo_shells") ||
                                                !Q_stricmp(ent->classname, "ammo_slugs") ||
                                                */
                        !Q_stricmp(ent->classname, "weapon_grenadelauncher") ||
                        !Q_stricmp(ent->classname, "weapon_lightning") ||
                        !Q_stricmp(ent->classname, "weapon_machinegun") ||
                        !Q_stricmp(ent->classname, "weapon_plasmagun") ||
                        !Q_stricmp(ent->classname, "weapon_railgun") ||
                        !Q_stricmp(ent->classname, "weapon_rocketlauncher") ||
                        !Q_stricmp(ent->classname, "weapon_shotgun") ||
                        !Q_stricmp(ent->classname, "item_botroam") //||
                        //!Q_stricmp(ent->classname, "target_location")
                    ) {

                        //BotAI_Print(PRT_MESSAGE, "^5Item - %s^7\n", ent->classname);

                        if (ent->s.origin) {

                            VectorCopy(ent->s.origin, temporigin);

                            VectorCopy(temporigin, start);
                            start[2] -= 32;
                            VectorCopy(temporigin, end);
                            end[2] += 32;

                            areanum = trap_AAS_TraceAreas(start, end, areas, NULL, 10);

                            //BotAI_Print(PRT_MESSAGE, "^5Item - %s : Area - %i^7\n", ent->classname, areas[0]);

                            if (areas[0] && trap_AAS_AreaReachability(areas[0])) {

                                dist_blue = trap_AAS_AreaTravelTimeToGoalArea(areas[0],
                                            temporigin, ctf_blueflag.areanum, TFL_DEFAULT|TFL_GRAPPLEHOOK);

                                dist_red = trap_AAS_AreaTravelTimeToGoalArea(areas[0],
                                           temporigin, ctf_redflag.areanum, TFL_DEFAULT|TFL_GRAPPLEHOOK);

                                if (dist_blue < alert_area &&
                                        b_count < MAX_ALTROUTEGOALS) {

                                    b_count++ ;
                                    VectorCopy(temporigin, blue_altroutegoals[b_count].origin);
                                    blue_altroutegoals[b_count].areanum = areas[0];

                                    BotAI_Print(PRT_MESSAGE, "^4Blue - ^5%s : Distance from base - %i^7\n",
                                                ent->classname, dist_blue);

                                } else if (dist_red < alert_area &&
                                           r_count < MAX_ALTROUTEGOALS) {

                                    r_count++ ;
                                    VectorCopy(temporigin, red_altroutegoals[r_count].origin);
                                    red_altroutegoals[r_count].areanum = areas[0];

                                    BotAI_Print(PRT_MESSAGE, "^1Red - ^5%s : Distance from base - %i^7\n",
                                                ent->classname, dist_red);
                                }
                            }
                        }
                    }
                }

                red_numaltroutegoals = r_count;
                blue_numaltroutegoals = b_count;

                if (r_count && b_count) {
                BotAI_Print(PRT_MESSAGE, " \n")
                    ;
                    BotAI_Print(PRT_MESSAGE, "^2Alternate Routing - Enabled^7\n");
                    BotAI_Print(PRT_MESSAGE, " \n");

                    altroutegoals_setup = qtrue;

                } else {
                    BotAI_Print(PRT_MESSAGE, " \n");
                    BotAI_Print(PRT_MESSAGE, "^2Alternate Routing - Disabled^7\n");
                    BotAI_Print(PRT_MESSAGE, " \n");
                }

            }
