Skip to content

Commit afa6f7f

Browse files
author
ruler501
committed
Add manual team control, still needs some work
1 parent b8a200a commit afa6f7f

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

source/src/bot/ac_bot_ai.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ bool CACBot::ChoosePreferredWeapon()
6868
if(WeaponInfoTable[m_pMyEnt->primary].eWeaponType == TYPE_SNIPER) sWeaponScore += 10; // At a close range, knife & pistol are strong with a sniper like primary weapon
6969
if(WeaponInfoTable[m_pMyEnt->primary].eWeaponType == TYPE_SHOTGUN) sWeaponScore -= 2; // Penalize a bit knife and pistol on close range with shotgun
7070
}
71+
72+
if(flDist < 50 && WeaponInfoTable[i].eWeaponType == TYPE_SNIPER) sWeaponScore -= 5;
7173
}
7274
else if (((flDist < WeaponInfoTable[i].flMinFireDistance) ||
7375
(flDist > WeaponInfoTable[i].flMaxFireDistance)) && i != GUN_GRENADE && i != GUN_RPG)

source/src/server.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ void serverdied(client &target, client &actor_, int damage, int gun, int style,
18861886
ts.lastspawn = -1;
18871887
// don't issue respawn yet until DEATHMILLIS has elapsed
18881888
// ts.respawn();
1889-
1889+
18901890
// log message
18911891
const int logtype = actor->type == ST_AI && target.type == ST_AI ? ACLOG_VERBOSE : ACLOG_INFO;
18921892
if (suic)
@@ -2065,6 +2065,8 @@ inline bool canspawn(client &c, bool connecting)
20652065
return true;
20662066
}
20672067

2068+
VARP(clabalance, 0, 0, 16);
2069+
VARP(rvsfbalance, 0, 0, 16);
20682070
int chooseteam(client &cl, int def = rnd(2))
20692071
{
20702072
// zombies override
@@ -2075,7 +2077,20 @@ int chooseteam(client &cl, int def = rnd(2))
20752077
return team_base(cl.team);
20762078
// team sizes
20772079
int *teamsizes = numteamclients(cl.clientnum, cl.type == ST_AI);
2078-
if(autoteam && teamsizes[TEAM_CLA] != teamsizes[TEAM_RVSF]) return teamsizes[TEAM_CLA] < teamsizes[TEAM_RVSF] ? TEAM_CLA : TEAM_RVSF;
2080+
if(clabalance || rvsfbalance){
2081+
int sendTo = teamsizes[TEAM_CLA] < teamsizes[TEAM_RVSF] ? TEAM_CLA : TEAM_RVSF;
2082+
if(teamsizes[TEAM_CLA] < teamsizes[TEAM_RVSF]){
2083+
if(teamsizes[TEAM_CLA] < clabalance) return TEAM_CLA;
2084+
else if(teamsizes[TEAM_RVSF] < rvsfbalance) return TEAM_RVSF;
2085+
else return TEAM_CLA_SPECT;
2086+
}
2087+
else{
2088+
if(teamsizes[TEAM_RVSF] < rvsfbalance) return TEAM_RVSF;
2089+
else if(teamsizes[TEAM_CLA] < clabalance) return TEAM_CLA;
2090+
else return TEAM_CLA_SPECT;
2091+
}
2092+
}
2093+
else if(autoteam && teamsizes[TEAM_CLA] != teamsizes[TEAM_RVSF]) return teamsizes[TEAM_CLA] < teamsizes[TEAM_RVSF] ? TEAM_CLA : TEAM_RVSF;
20792094
else
20802095
{ // join weaker team
20812096
int teamscore[2] = {0, 0}, sum = calcscores();
@@ -4192,7 +4207,7 @@ void process(ENetPacket *packet, int sender, int chan)
41924207
{
41934208
unsigned char hash[20];
41944209
loopi(20) hash[i] = p.get();
4195-
logline(ACLOG_INFO, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
4210+
logline(ACLOG_INFO, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
41964211
hash[0], hash[1], hash[2], hash[3],
41974212
hash[4], hash[5], hash[6], hash[7],
41984213
hash[8], hash[9], hash[10], hash[11],

source/src/serverai.h

+28-17
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ void deleteai(client &c)
6666
if(c.type != ST_AI || c.ownernum < 0)
6767
return;
6868
const int cn = c.clientnum;
69-
c.ownernum = -1;
69+
c.ownernum = -1;VARP(clabalance, 0, 0, 16);
70+
VARP(rvsfbalance, 0, 0, 16);
7071
clientdisconnect(c);
7172
sendf(NULL, 1, "ri2", SV_DELAI, cn);
7273
}
@@ -116,6 +117,9 @@ bool reassignai(int exclude = -1)
116117
return false;
117118
}
118119

120+
121+
extern int clabalance;
122+
extern int rsvfbalance;
119123
void checkai()
120124
{
121125
// check if bots are disallowed
@@ -143,22 +147,29 @@ void checkai()
143147
{
144148
int balance = 0;
145149
const int humans = numplayers(false);
146-
if(humans) switch(botbalance)
147-
{
148-
case 0: // force no bots, except for zombies
149-
if(!m_zombie(gamemode))
150-
{
151-
balance = 0;
152-
break;
153-
}
154-
// fallthrough for zombies
155-
case -1: // auto
156-
if(m_zombie(gamemode)) balance = min(zombiebalance + humans, 30); // effectively zombiebalance, but capped at 30
157-
else if(m_duke(gamemode, mutators)) balance = max(humans, maplayout_factor - 3); // 3 - 5 - 8 (6 - 8 - 11 layout factor)
158-
else if(m_team(gamemode, mutators)) balance = clamp((smapstats.spawns[0] + smapstats.spawns[1]) / 3, max(6, humans), 14);
159-
else balance = clamp(smapstats.spawns[2] / 3, max(4, humans), 10);
160-
break; // auto
161-
default: balance = max(humans, botbalance); break; // force bot count
150+
if(humans){
151+
if(!rvsfbalance && !clabalance) switch(botbalance)
152+
{
153+
case 0: // force no bots, except for zombies
154+
if(!m_zombie(gamemode))
155+
{
156+
balance = 0;
157+
break;
158+
}
159+
// fallthrough for zombies
160+
case -1: // auto
161+
if(m_zombie(gamemode)) balance = min(zombiebalance + humans, 30); // effectively zombiebalance, but capped at 30
162+
else if(m_duke(gamemode, mutators)) balance = max(humans, maplayout_factor - 3); // 3 - 5 - 8 (6 - 8 - 11 layout factor)
163+
else if(m_team(gamemode, mutators)) balance = clamp((smapstats.spawns[0] + smapstats.spawns[1]) / 3, max(6, humans), 14);
164+
else balance = clamp(smapstats.spawns[2] / 3, max(4, humans), 10);
165+
break; // auto
166+
default: balance = max(humans, botbalance); break; // force bot count
167+
}
168+
else
169+
balance = rvsfbalance + clabalance;
170+
}
171+
else{
172+
balance = -1;
162173
}
163174
if(balance > 0)
164175
{

0 commit comments

Comments
 (0)