]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/bot.qc
Fix typo
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / bot.qc
index 4f0b8d01d0a38238d262572ff7378288ab64892d..bc9c0e18e94b16dd7af86d528abc7e9b71c22882 100644 (file)
@@ -170,6 +170,26 @@ void bot_setnameandstuff(entity this)
        }
        else
        {
+               entity balance = TeamBalance_CheckAllowedTeams(NULL);
+               TeamBalance_GetTeamCounts(balance, NULL);
+               int smallest_team = -1;
+               int smallest_count = -1;
+               if (teamplay)
+               {
+                       for (int i = 1; i <= AvailableTeams(); ++i)
+                       {
+                               // NOTE if (autocvar_g_campaign && autocvar_g_campaign_forceteam == i)
+                               // TeamBalance_GetNumberOfPlayers(balance, i); returns the number of players + 1
+                               // since it keeps a spot for the real player in the desired team
+                               int count = TeamBalance_GetNumberOfPlayers(balance, i);
+                               if (smallest_count < 0 || count < smallest_count)
+                               {
+                                       smallest_team = i;
+                                       smallest_count = count;
+                               }
+                       }
+               }
+               TeamBalance_Destroy(balance);
                RandomSelection_Init();
                while((readfile = fgets(file)))
                {
@@ -177,18 +197,33 @@ void bot_setnameandstuff(entity this)
                                continue;
                        if(substring(readfile, 0, 1) == "#")
                                continue;
+                       // NOTE if the line is empty tokenizebyseparator(readfile, "\t")
+                       // will create 1 empty token because there's no separator (bug?)
+                       if (readfile == "")
+                               continue;
                        tokens = tokenizebyseparator(readfile, "\t");
                        if(tokens == 0)
                                continue;
                        s = argv(0);
-                       prio = 1;
+                       prio = 0;
+                       bool conflict = false;
                        FOREACH_CLIENT(IS_BOT_CLIENT(it), {
-                               if(s == it.cleanname)
+                               if (s == it.cleanname)
                                {
-                                       prio = 0;
+                                       conflict = true;
                                        break;
                                }
                        });
+                       if (!conflict)
+                               prio += 1;
+                       if (teamplay && !(autocvar_bot_vs_human && AvailableTeams() == 2))
+                       {
+                               int forced_team = stof(argv(5));
+                               if (!Team_IsValidIndex(forced_team))
+                                       forced_team = 0;
+                               if (!forced_team || forced_team == smallest_team)
+                                       prio += 2;
+                       }
                        RandomSelection_AddString(readfile, 1, prio);
                }
                readfile = RandomSelection_chosen_string;
@@ -211,7 +246,10 @@ void bot_setnameandstuff(entity this)
        if(argv(4) != "" && stof(argv(4)) >= 0) bot_pants = argv(4);
        else bot_pants = ftos(floor(random() * 15));
 
-       this.bot_forced_team = stof(argv(5));
+       if (teamplay && !(autocvar_bot_vs_human && AvailableTeams() == 2))
+               this.bot_forced_team = stof(argv(5));
+       else
+               this.bot_forced_team = 0;
 
        prio = 6;
 
@@ -241,6 +279,9 @@ void bot_setnameandstuff(entity this)
        READSKILL(bot_thinkskill, 1, 0.5); // think skill
        READSKILL(bot_aiskill, 2, 0); // "ai" skill
 
+       if (file >= 0 && argv(prio) != "")
+               LOG_INFOF("^1Warning^7: too many parameters for bot %s, please check format of %s", bot_name, autocvar_bot_config_file);
+
        this.bot_config_loaded = true;
 
        // this is really only a default, TeamBalance_JoinBestTeam is called later
@@ -344,7 +385,7 @@ void bot_custom_weapon_priority_setup()
        tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_close)," ");
 
        c = 0;
-       for(i=0; i < tokens && i < Weapons_COUNT; ++i){
+       for(i=0; i < tokens && c < Weapons_COUNT; ++i){
                w = stof(argv(i));
                if ( w >= WEP_FIRST && w <= WEP_LAST) {
                        bot_weapons_close[c] = w;
@@ -427,7 +468,7 @@ void bot_clientconnect(entity this)
                bot_setclientfields(this);
        }
 
-       if (Team_IsValidIndex(this.bot_forced_team))
+       if (teamplay && Team_IsValidIndex(this.bot_forced_team))
        {
                SetPlayerTeam(this, this.bot_forced_team, TEAM_CHANGE_MANUAL);
        }
@@ -577,6 +618,7 @@ void bot_calculate_stepheightvec()
        stepheightvec = autocvar_sv_stepheight * '0 0 1';
        jumpheight_vec = (autocvar_sv_jumpvelocity ** 2) / (2 * autocvar_sv_gravity) * '0 0 1';
        jumpstepheightvec = stepheightvec + jumpheight_vec * 0.85; // reduce it a bit to make the jumps easy
+       jumpheight_time = autocvar_sv_jumpvelocity / autocvar_sv_gravity;
 }
 
 bool bot_fixcount()
@@ -753,7 +795,7 @@ void bot_serverframe()
                if(botframe_cachedwaypointlinks)
                {
                        if(!botframe_loadedforcedlinks)
-                               waypoint_load_links_hardwired();
+                               waypoint_load_hardwiredlinks();
                }
                else
                {