From 644d84956b406e7606cedec63aaa0e84399cb666 Mon Sep 17 00:00:00 2001 From: div0 Date: Sat, 5 May 2007 20:02:15 +0000 Subject: [PATCH] make minplayers only check active players; gib eye fix; keyhunt fixes git-svn-id: svn://svn.icculus.org/nexuiz/branches/nexuiz-2.0@2496 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/default.cfg | 2 +- data/game_reset.cfg | 5 +++ data/qcsrc/server/bots.qc | 72 ++++++++++++++++++++++++++++++++-- data/qcsrc/server/cl_player.qc | 2 + data/qcsrc/server/defs.qh | 1 + data/qcsrc/server/runematch.qc | 32 +++++++-------- data/qcsrc/server/teamplay.qc | 24 +++++++++--- 7 files changed, 113 insertions(+), 25 deletions(-) diff --git a/data/default.cfg b/data/default.cfg index 5933ca2e5..f0ae9da84 100644 --- a/data/default.cfg +++ b/data/default.cfg @@ -724,7 +724,7 @@ alias g_maplist_shufflenow "qc_cmd rpn /g_maplist g_maplist shuffle def" // key hunt set g_keyhunt 0 -set g_balance_keyhunt_delay_return 30 +set g_balance_keyhunt_delay_return 60 set g_balance_keyhunt_delay_round 5 set g_balance_keyhunt_delay_tracking 10 set g_balance_keyhunt_delay_fadeout 2 diff --git a/data/game_reset.cfg b/data/game_reset.cfg index 2932353a9..534e973d5 100644 --- a/data/game_reset.cfg +++ b/data/game_reset.cfg @@ -21,4 +21,9 @@ set gamecfg 0 set g_respawn_mapsettings_delay 0 set g_respawn_mapsettings_waves 0 +// prepare for loading a mapcfg +set timelimit 0 +set fraglimit 0 +set g_keyhunt_teams 0 + set exit_cfg empty.cfg diff --git a/data/qcsrc/server/bots.qc b/data/qcsrc/server/bots.qc index e5be3df65..f18337bb1 100644 --- a/data/qcsrc/server/bots.qc +++ b/data/qcsrc/server/bots.qc @@ -1899,10 +1899,64 @@ entity() bot_spawn = return bot; }; +void CheckAllowedTeams(); void GetTeamCounts(entity other); float c1, c2, c3, c4; +void() bot_removefromlargestteam = +{ + local float besttime, bestcount, thiscount; + local entity best, head; + CheckAllowedTeams(); + GetTeamCounts(world); + dprint("c1 = ", ftos(c1), "\n"); + dprint("c2 = ", ftos(c2), "\n"); + dprint("c3 = ", ftos(c3), "\n"); + dprint("c4 = ", ftos(c4), "\n"); + head = findchainfloat(isbot, TRUE); + if (!head) + return; + best = head; + besttime = head.createdtime; + bestcount = 0; + while (head) + { + if(head.team == COLOR_TEAM1) + thiscount = c1; + else if(head.team == COLOR_TEAM2) + thiscount = c2; + else if(head.team == COLOR_TEAM3) + thiscount = c3; + else if(head.team == COLOR_TEAM4) + thiscount = c4; + else + thiscount = 0; + if (thiscount > bestcount) + { + bestcount = thiscount; + besttime = head.createdtime; + best = head; + } + else if (thiscount == bestcount && besttime < head.createdtime) + { + besttime = head.createdtime; + best = head; + } + head = head.chain; + } + currentbots = currentbots - 1; + dprint("Removing from a ", ftos(bestcount), " players team!\n"); + dropclient(best); +}; + void() bot_removenewest = { local float besttime; local entity best, head; + + if(teams_matter) + { + bot_removefromlargestteam(); + return; + } + head = findchainfloat(isbot, TRUE); if (!head) return; @@ -2021,7 +2075,8 @@ float botframe_spawnedwaypoints; float botframe_nextthink; void() bot_serverframe = { - float realplayers, bots; + float realplayers, bots, activerealplayers; + entity head; if (intermission_running) return; @@ -2029,12 +2084,21 @@ void() bot_serverframe = if (time < 2) return; - realplayers = player_count - currentbots; + activerealplayers = 0; + realplayers = 0; + + FOR_EACH_REALCLIENT(head) + { + if(head.classname == "player") + ++activerealplayers; + ++realplayers; + } // add/remove bots if needed to make sure there are at least // minplayers+bot_number, or remove all bots if no one is playing // But don't remove bots immediately on level change, as the real players // usually haven't rejoined yet + bots_would_leave = FALSE; if (realplayers || cvar("bot_join_empty") || (currentbots > 0 && time < 5)) { float realminplayers, minplayers; @@ -2045,7 +2109,9 @@ void() bot_serverframe = realminbots = cvar("bot_number"); minbots = max(0, floor(realminbots)); - bots = min(max(minbots, minplayers - realplayers), maxclients - realplayers); + bots = min(max(minbots, minplayers - activerealplayers), maxclients - realplayers); + if(bots > minbots) + bots_would_leave = TRUE; } else { diff --git a/data/qcsrc/server/cl_player.qc b/data/qcsrc/server/cl_player.qc index 5455183ce..d556d4992 100644 --- a/data/qcsrc/server/cl_player.qc +++ b/data/qcsrc/server/cl_player.qc @@ -44,6 +44,8 @@ void CopyBody(float keepvelocity) self.solid = oldself.solid; self.takedamage = oldself.takedamage; self.think = oldself.think; + self.gibrandom = oldself.gibrandom; + self.customizeentityforclient = oldself.customizeentityforclient; if (keepvelocity == 1) self.velocity = oldself.velocity; self.oldvelocity = self.velocity; diff --git a/data/qcsrc/server/defs.qh b/data/qcsrc/server/defs.qh index e5eb9ab0e..0572558b2 100644 --- a/data/qcsrc/server/defs.qh +++ b/data/qcsrc/server/defs.qh @@ -7,6 +7,7 @@ string string_null; float player_count; float currentbots; +float bots_would_leave; float lms_lowest_lives; float lms_next_place; float() LMS_NewPlayerLives; diff --git a/data/qcsrc/server/runematch.qc b/data/qcsrc/server/runematch.qc index 81c3deea6..faae39f54 100644 --- a/data/qcsrc/server/runematch.qc +++ b/data/qcsrc/server/runematch.qc @@ -342,7 +342,7 @@ void DropAllRunes(entity pl) entity rune, curse; float rcount, ccount, r, c, rand, prevent_same, numtodrop, tries; - entity c1, r1, c2, r2; + entity curse1, rune1, curse2, rune2; rune = curse = world; rcount = ccount = r = c = 0; @@ -400,29 +400,29 @@ void DropAllRunes(entity pl) // pair rune and curse - r1 = rune; - c1 = curse; - r2 = c1.enemy; - c2 = r1.enemy; + rune1 = rune; + curse1 = curse; + rune2 = curse1.enemy; + curse2 = rune1.enemy; - if(r1 != r2) // not already attached to each other + if(rune1 != rune2) // not already attached to each other { - r1.enemy = c1; - c1.enemy = r1; - setattachment(c1, r1, ""); - r2.enemy = c2; - c2.enemy = r2; - setattachment(c2, r2, ""); - //DropRune(pl, r2); + rune1.enemy = curse1; + curse1.enemy = rune1; + setattachment(curse1, rune1, ""); + rune2.enemy = curse2; + curse2.enemy = rune2; + setattachment(curse2, rune2, ""); + //DropRune(pl, rune2); //ccount = ccount - 1; //rcount = rcount - 1; } - DropRune(pl, r1); + DropRune(pl, rune1); if(numtodrop <=0) { - r1.think = rune_respawn; - r1.nextthink = time; + rune1.think = rune_respawn; + rune1.nextthink = time; } numtodrop = numtodrop - 1; diff --git a/data/qcsrc/server/teamplay.qc b/data/qcsrc/server/teamplay.qc index 1bb3975cd..34edaa63d 100644 --- a/data/qcsrc/server/teamplay.qc +++ b/data/qcsrc/server/teamplay.qc @@ -579,7 +579,7 @@ float PlayerValue(entity p) void GetTeamCounts(entity ignore) { entity head; - float value; + float value, bvalue; // now count how many players are on each team already // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around) @@ -590,12 +590,16 @@ void GetTeamCounts(entity ignore) if(head != ignore)// && head.netname != "") { value = PlayerValue(head); + if(clienttype(head) == CLIENTTYPE_BOT) + bvalue = value; + else + bvalue = 0; if(head.team == COLOR_TEAM1) { if(c1 >= 0) { c1 = c1 + value; - cb1 = cb1 + value; + cb1 = cb1 + bvalue; } } if(head.team == COLOR_TEAM2) @@ -603,7 +607,7 @@ void GetTeamCounts(entity ignore) if(c2 >= 0) { c2 = c2 + value; - cb2 = cb2 + value; + cb2 = cb2 + bvalue; } } if(head.team == COLOR_TEAM3) @@ -611,7 +615,7 @@ void GetTeamCounts(entity ignore) if(c3 >= 0) { c3 = c3 + value; - cb3 = cb3 + value; + cb3 = cb3 + bvalue; } } if(head.team == COLOR_TEAM4) @@ -619,7 +623,7 @@ void GetTeamCounts(entity ignore) if(c4 >= 0) { c4 = c4 + value; - cb4 = cb4 + value; + cb4 = cb4 + bvalue; } } } @@ -676,6 +680,16 @@ float FindSmallestTeam(entity pl, float ignore_pl) // 2 doesn't seem to work though... balance_type = 1; + if(bots_would_leave) + if(pl.classname != "player") + if(clienttype(pl) != CLIENTTYPE_BOT) + { + c1 -= cb1 * 255.0/256; + c2 -= cb2 * 255.0/256; + c3 -= cb3 * 255.0/256; + c4 -= cb4 * 255.0/256; + } + if(balance_type == 1) { if(c1 >= 0 && (c1 < smallestteam_count || (c1 <= smallestteam_count && team1_score < smallestteam_score))) -- 2.39.2