Skip to content

Commit

Permalink
team names
Browse files Browse the repository at this point in the history
  • Loading branch information
themuffinator committed Sep 14, 2024
1 parent b9eec89 commit 9fb8b97
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 132 deletions.
48 changes: 24 additions & 24 deletions src/g_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,16 +1594,16 @@ team_t PickTeam(int ignore_client_num) {
return TEAM_FREE;

if (level.num_playing_blue > level.num_playing_red)
return TEAM_RED;
return TEAM_SOLDIERS;

if (level.num_playing_red > level.num_playing_blue)
return TEAM_BLUE;
return TEAM_PREDATOR;

// equal team count, so join the team with the lowest score
if (level.team_scores[TEAM_BLUE] > level.team_scores[TEAM_RED])
return TEAM_RED;
if (level.team_scores[TEAM_RED] > level.team_scores[TEAM_BLUE])
return TEAM_BLUE;
if (level.team_scores[TEAM_PREDATOR] > level.team_scores[TEAM_SOLDIERS])
return TEAM_SOLDIERS;
if (level.team_scores[TEAM_SOLDIERS] > level.team_scores[TEAM_PREDATOR])
return TEAM_PREDATOR;

// equal team scores, so join team with lowest total individual scores
int iscore_red = 0, iscore_blue = 0;
Expand All @@ -1614,23 +1614,23 @@ team_t PickTeam(int ignore_client_num) {
if (!game.clients[i].pers.connected)
continue;

if (game.clients[i].sess.team == TEAM_RED) {
if (game.clients[i].sess.team == TEAM_SOLDIERS) {
iscore_red += game.clients[i].resp.score;
continue;
}
if (game.clients[i].sess.team == TEAM_BLUE) {
if (game.clients[i].sess.team == TEAM_PREDATOR) {
iscore_blue += game.clients[i].resp.score;
continue;
}
}

if (iscore_blue > iscore_red)
return TEAM_RED;
return TEAM_SOLDIERS;
if (iscore_red > iscore_blue)
return TEAM_BLUE;
return TEAM_PREDATOR;

// otherwise just randomly select a team
return brandom() ? TEAM_RED : TEAM_BLUE;
return brandom() ? TEAM_SOLDIERS : TEAM_PREDATOR;
}

/*
Expand Down Expand Up @@ -1676,8 +1676,8 @@ void BroadcastTeamChange(gentity_t *ent, int old_team, bool inactive, bool silen
t = "You are now spectating.";
}
break;
case TEAM_RED:
case TEAM_BLUE:
case TEAM_SOLDIERS:
case TEAM_PREDATOR:
s = G_Fmt("{} joined the {} Team.\n", name, Teams_TeamName(ent->client->sess.team)).data();
t = G_Fmt("You have joined the {} Team.\n", Teams_TeamName(ent->client->sess.team)).data();
break;
Expand Down Expand Up @@ -1721,8 +1721,8 @@ static bool AllowTeamSwitch(gentity_t *ent, team_t desired_team) {
if (Teams()) {
if (g_teamplay_force_balance->integer) {
// We allow a spread of two
if ((desired_team == TEAM_RED && (level.num_playing_red - level.num_playing_blue > 1)) ||
(desired_team == TEAM_BLUE && (level.num_playing_blue - level.num_playing_red > 1))) {
if ((desired_team == TEAM_SOLDIERS && (level.num_playing_red - level.num_playing_blue > 1)) ||
(desired_team == TEAM_PREDATOR && (level.num_playing_blue - level.num_playing_red > 1))) {
gi.LocClient_Print(ent, PRINT_HIGH, "{} has too many players.\n", Teams_TeamName(desired_team));
return false; // ignore the request
}
Expand Down Expand Up @@ -1796,7 +1796,7 @@ int TeamBalance(bool force) {
if (delta < 2)
return level.num_playing_red - level.num_playing_blue;

team_t stack_team = level.num_playing_red > level.num_playing_blue ? TEAM_RED : TEAM_BLUE;
team_t stack_team = level.num_playing_red > level.num_playing_blue ? TEAM_SOLDIERS : TEAM_PREDATOR;

size_t count = 0;
int index[MAX_CLIENTS_KEX/2];
Expand Down Expand Up @@ -1830,7 +1830,7 @@ int TeamBalance(bool force) {
if (cl->sess.team != stack_team)
continue;

cl->sess.team = stack_team == TEAM_RED ? TEAM_BLUE : TEAM_RED;
cl->sess.team = stack_team == TEAM_SOLDIERS ? TEAM_PREDATOR : TEAM_SOLDIERS;

//TODO: queue this change in round-based games
ClientRespawn(&g_entities[cl - game.clients + 1]);
Expand Down Expand Up @@ -1871,7 +1871,7 @@ bool TeamShuffle() {
// determine max team size based from active players
int maxteam = ceil(level.num_playing_clients / 2);
int count_red = 0, count_blue = 0;
team_t setteam = join_red ? TEAM_RED : TEAM_BLUE;
team_t setteam = join_red ? TEAM_SOLDIERS : TEAM_PREDATOR;

// create random array
for (size_t i = 0; i < MAX_CLIENTS_KEX; i++) {
Expand Down Expand Up @@ -1906,18 +1906,18 @@ bool TeamShuffle() {
continue;

if (count_red >= maxteam || count_red > count_blue)
setteam = TEAM_BLUE;
setteam = TEAM_PREDATOR;
else if (count_blue >= maxteam || count_blue > count_red)
setteam = TEAM_RED;
setteam = TEAM_SOLDIERS;

ent->client->sess.team = setteam;

if (setteam == TEAM_RED)
if (setteam == TEAM_SOLDIERS)
count_red++;
else count_blue++;

join_red ^= true;
setteam = join_red ? TEAM_RED : TEAM_BLUE;
setteam = join_red ? TEAM_SOLDIERS : TEAM_PREDATOR;
}

return true;
Expand Down Expand Up @@ -2087,8 +2087,8 @@ static void Cmd_Team_f(gentity_t *ent) {
case TEAM_FREE:
gi.LocClient_Print(ent, PRINT_HIGH, "You are in the match.\n");
break;
case TEAM_RED:
case TEAM_BLUE:
case TEAM_SOLDIERS:
case TEAM_PREDATOR:
gi.LocClient_Print(ent, PRINT_HIGH, "Your team: {}\n", Teams_TeamName(ent->client->sess.team));
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions src/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ enum team_t {
TEAM_NONE,
TEAM_SPECTATOR,
TEAM_FREE,
TEAM_RED,
TEAM_BLUE,
TEAM_SOLDIERS,
TEAM_PREDATOR,
TEAM_NUM_TEAMS
};

Expand Down Expand Up @@ -2333,7 +2333,7 @@ void InitItems();
void SetItemNames();
gitem_t *FindItem(const char *pickup_name);
gitem_t *FindItemByClassname(const char *classname);
gentity_t *Drop_Item(gentity_t *ent, gitem_t *item);
gentity_t *Drop_Item(gentity_t *ent, gitem_t *item);
void SetRespawn(gentity_t *ent, gtime_t delay, bool hide_self = true);
void Change_Weapon(gentity_t *ent);
bool SpawnItem(gentity_t *ent, gitem_t *item);
Expand Down
74 changes: 37 additions & 37 deletions src/g_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ static void InitGame() {

level.locked[TEAM_SPECTATOR] = false;
level.locked[TEAM_FREE] = false;
level.locked[TEAM_RED] = false;
level.locked[TEAM_BLUE] = false;
level.locked[TEAM_SOLDIERS] = false;
level.locked[TEAM_PREDATOR] = false;

*level.weapon_count = { 0 };

Expand Down Expand Up @@ -815,7 +815,7 @@ void Match_Start() {
level.warmup_requisite = warmupreq_t::WARMUP_REQ_NONE;
level.warmup_notice_time = 0_sec;

level.team_scores[TEAM_RED] = level.team_scores[TEAM_BLUE] = 0;
level.team_scores[TEAM_SOLDIERS] = level.team_scores[TEAM_PREDATOR] = 0;

level.total_player_deaths = 0;

Expand Down Expand Up @@ -979,12 +979,12 @@ static void CheckDMRoundState(void) {

for (auto ec : active_clients()) {
switch (ec->client->sess.team) {
case TEAM_RED:
case TEAM_SOLDIERS:
count_red++;
if (!ec->client->eliminated)
count_living_red++;
break;
case TEAM_BLUE:
case TEAM_PREDATOR:
count_blue++;
if (!ec->client->eliminated)
count_living_blue++;
Expand All @@ -995,16 +995,16 @@ static void CheckDMRoundState(void) {
// check eliminated first
if (!count_living_red && count_living_blue) {
int points = 1;
G_AdjustTeamScore(TEAM_BLUE, points);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(eliminated {})\n", Teams_TeamName(TEAM_BLUE), Teams_TeamName(TEAM_RED));
G_AdjustTeamScore(TEAM_PREDATOR, points);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(eliminated {})\n", Teams_TeamName(TEAM_PREDATOR), Teams_TeamName(TEAM_SOLDIERS));
gi.positioned_sound(world->s.origin, world, CHAN_AUTO | CHAN_RELIABLE, gi.soundindex("ctf/flagcap.wav"), 1, ATTN_NONE, 0);
Round_End();
return;
}
if (!count_living_blue && count_living_red) {
int points = 1;
G_AdjustTeamScore(TEAM_RED, points);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(eliminated {})\n", Teams_TeamName(TEAM_RED), Teams_TeamName(TEAM_BLUE));
G_AdjustTeamScore(TEAM_SOLDIERS, points);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(eliminated {})\n", Teams_TeamName(TEAM_SOLDIERS), Teams_TeamName(TEAM_PREDATOR));
gi.positioned_sound(world->s.origin, world, CHAN_AUTO | CHAN_RELIABLE, gi.soundindex("ctf/flagcap.wav"), 1, ATTN_NONE, 0);
Round_End();
return;
Expand All @@ -1013,12 +1013,12 @@ static void CheckDMRoundState(void) {
// hit the round time limit, check any other winning conditions
if (level.time >= level.round_state_timer) {
if (level.num_living_red > level.num_living_blue) {
G_AdjustTeamScore(TEAM_RED, 1);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(players remaining: {} vs {})\n", Teams_TeamName(TEAM_RED), level.num_living_red, level.num_living_blue);
G_AdjustTeamScore(TEAM_SOLDIERS, 1);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(players remaining: {} vs {})\n", Teams_TeamName(TEAM_SOLDIERS), level.num_living_red, level.num_living_blue);
gi.positioned_sound(world->s.origin, world, CHAN_AUTO | CHAN_RELIABLE, gi.soundindex("ctf/flagcap.wav"), 1, ATTN_NONE, 0);
} else if (level.num_living_blue > level.num_living_red) {
G_AdjustTeamScore(TEAM_BLUE, 1);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(players remaining: {} vs {})\n", Teams_TeamName(TEAM_BLUE), level.num_living_blue, level.num_living_red);
G_AdjustTeamScore(TEAM_PREDATOR, 1);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(players remaining: {} vs {})\n", Teams_TeamName(TEAM_PREDATOR), level.num_living_blue, level.num_living_red);
gi.positioned_sound(world->s.origin, world, CHAN_AUTO | CHAN_RELIABLE, gi.soundindex("ctf/flagcap.wav"), 1, ATTN_NONE, 0);
} else {
int total_health_red = 0, total_health_blue = 0;
Expand All @@ -1027,22 +1027,22 @@ static void CheckDMRoundState(void) {
if (ec->health <= 0)
continue;
switch (ec->client->sess.team) {
case TEAM_RED:
case TEAM_SOLDIERS:
total_health_red += ec->health;
break;
case TEAM_BLUE:
case TEAM_PREDATOR:
total_health_blue += ec->health;
break;
}
}

if (total_health_red > total_health_blue) {
G_AdjustTeamScore(TEAM_RED, 1);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(total health: {} vs {})\n", Teams_TeamName(TEAM_RED), total_health_red, total_health_blue);
G_AdjustTeamScore(TEAM_SOLDIERS, 1);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(total health: {} vs {})\n", Teams_TeamName(TEAM_SOLDIERS), total_health_red, total_health_blue);
gi.positioned_sound(world->s.origin, world, CHAN_AUTO | CHAN_RELIABLE, gi.soundindex("ctf/flagcap.wav"), 1, ATTN_NONE, 0);
} else if (total_health_blue > total_health_red) {
G_AdjustTeamScore(TEAM_BLUE, 1);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(total health: {} vs {})\n", Teams_TeamName(TEAM_BLUE), total_health_blue, total_health_red);
G_AdjustTeamScore(TEAM_PREDATOR, 1);
gi.LocBroadcast_Print(PRINT_CENTER, "{} wins the round!\n(total health: {} vs {})\n", Teams_TeamName(TEAM_PREDATOR), total_health_blue, total_health_red);
gi.positioned_sound(world->s.origin, world, CHAN_AUTO | CHAN_RELIABLE, gi.soundindex("ctf/flagcap.wav"), 1, ATTN_NONE, 0);
} else {
gi.LocBroadcast_Print(PRINT_CENTER, "Round draw!");
Expand Down Expand Up @@ -1429,7 +1429,7 @@ static bool ScoreIsTied(void) {
return false;

if (Teams())
return level.team_scores[TEAM_RED] == level.team_scores[TEAM_BLUE];
return level.team_scores[TEAM_SOLDIERS] == level.team_scores[TEAM_PREDATOR];

return game.clients[level.sorted_clients[0]].resp.score == game.clients[level.sorted_clients[1]].resp.score;
}
Expand Down Expand Up @@ -1545,7 +1545,7 @@ void CalculateRanks() {
level.follow2 = ec->client - game.clients;

if (teams) {
if (cl->sess.team == TEAM_RED) {
if (cl->sess.team == TEAM_SOLDIERS) {
level.num_playing_red++;
if (cl->pers.health > 0)
level.num_living_red++;
Expand All @@ -1568,9 +1568,9 @@ void CalculateRanks() {
// in team games, rank is just the order of the teams, 0=red, 1=blue, 2=tied
for (size_t i = 0; i < level.num_connected_clients; i++) {
cl = &game.clients[level.sorted_clients[i]];
if (level.team_scores[TEAM_RED] == level.team_scores[TEAM_BLUE]) {
if (level.team_scores[TEAM_SOLDIERS] == level.team_scores[TEAM_PREDATOR]) {
cl->resp.rank = 2;
} else if (level.team_scores[TEAM_RED] > level.team_scores[TEAM_BLUE]) {
} else if (level.team_scores[TEAM_SOLDIERS] > level.team_scores[TEAM_PREDATOR]) {
cl->resp.rank = 0;
} else {
cl->resp.rank = 1;
Expand Down Expand Up @@ -2070,12 +2070,12 @@ void CheckDMExitRules() {

// find the winner and broadcast it
if (teams) {
if (level.team_scores[TEAM_RED] > level.team_scores[TEAM_BLUE]) {
QueueIntermission(G_Fmt("{} Team WINS with a final score of {} to {}.\n", Teams_TeamName(TEAM_RED), level.team_scores[TEAM_RED], level.team_scores[TEAM_BLUE]).data(), false, false);
if (level.team_scores[TEAM_SOLDIERS] > level.team_scores[TEAM_PREDATOR]) {
QueueIntermission(G_Fmt("{} Team WINS with a final score of {} to {}.\n", Teams_TeamName(TEAM_SOLDIERS), level.team_scores[TEAM_SOLDIERS], level.team_scores[TEAM_PREDATOR]).data(), false, false);
return;
}
if (level.team_scores[TEAM_BLUE] > level.team_scores[TEAM_RED]) {
QueueIntermission(G_Fmt("{} Team WINS with a final score of {} to {}.\n", Teams_TeamName(TEAM_BLUE), level.team_scores[TEAM_BLUE], level.team_scores[TEAM_RED]).data(), false, false);
if (level.team_scores[TEAM_PREDATOR] > level.team_scores[TEAM_SOLDIERS]) {
QueueIntermission(G_Fmt("{} Team WINS with a final score of {} to {}.\n", Teams_TeamName(TEAM_PREDATOR), level.team_scores[TEAM_PREDATOR], level.team_scores[TEAM_SOLDIERS]).data(), false, false);
return;
}
} else {
Expand All @@ -2091,12 +2091,12 @@ void CheckDMExitRules() {

if (mercylimit->integer > 0) {
if (teams) {
if (level.team_scores[TEAM_RED] >= level.team_scores[TEAM_BLUE] + mercylimit->integer) {
QueueIntermission(G_Fmt("{} hit the mercylimit ({}).", Teams_TeamName(TEAM_RED), mercylimit->integer).data(), true, false);
if (level.team_scores[TEAM_SOLDIERS] >= level.team_scores[TEAM_PREDATOR] + mercylimit->integer) {
QueueIntermission(G_Fmt("{} hit the mercylimit ({}).", Teams_TeamName(TEAM_SOLDIERS), mercylimit->integer).data(), true, false);
return;
}
if (level.team_scores[TEAM_BLUE] >= level.team_scores[TEAM_RED] + mercylimit->integer) {
QueueIntermission(G_Fmt("{} hit the mercylimit ({}).", Teams_TeamName(TEAM_BLUE), mercylimit->integer).data(), true, false);
if (level.team_scores[TEAM_PREDATOR] >= level.team_scores[TEAM_SOLDIERS] + mercylimit->integer) {
QueueIntermission(G_Fmt("{} hit the mercylimit ({}).", Teams_TeamName(TEAM_PREDATOR), mercylimit->integer).data(), true, false);
return;
}
}
Expand All @@ -2110,12 +2110,12 @@ void CheckDMExitRules() {
if (!scorelimit) return;

if (teams) {
if (level.team_scores[TEAM_RED] >= scorelimit) {
QueueIntermission(G_Fmt("{} WINS! (hit the {} limit)", Teams_TeamName(TEAM_RED), GT_ScoreLimitString()).data(), false, false);
if (level.team_scores[TEAM_SOLDIERS] >= scorelimit) {
QueueIntermission(G_Fmt("{} WINS! (hit the {} limit)", Teams_TeamName(TEAM_SOLDIERS), GT_ScoreLimitString()).data(), false, false);
return;
}
if (level.team_scores[TEAM_BLUE] >= scorelimit) {
QueueIntermission(G_Fmt("{} WINS! (hit the {} limit)", Teams_TeamName(TEAM_BLUE), GT_ScoreLimitString()).data(), false, false);
if (level.team_scores[TEAM_PREDATOR] >= scorelimit) {
QueueIntermission(G_Fmt("{} WINS! (hit the {} limit)", Teams_TeamName(TEAM_PREDATOR), GT_ScoreLimitString()).data(), false, false);
return;
}
} else {
Expand Down Expand Up @@ -2153,12 +2153,12 @@ void Teams_CalcRankings(std::array<uint32_t, MAX_CLIENTS> &player_ranks) {
return;

// we're all winners.. or losers. whatever
if (level.team_scores[TEAM_RED] == level.team_scores[TEAM_BLUE]) {
if (level.team_scores[TEAM_SOLDIERS] == level.team_scores[TEAM_PREDATOR]) {
player_ranks.fill(1);
return;
}

team_t winning_team = (level.team_scores[TEAM_RED] > level.team_scores[TEAM_BLUE]) ? TEAM_RED : TEAM_BLUE;
team_t winning_team = (level.team_scores[TEAM_SOLDIERS] > level.team_scores[TEAM_PREDATOR]) ? TEAM_SOLDIERS : TEAM_PREDATOR;

for (auto player : active_clients())
if (player->client->pers.spawned && ClientIsPlaying(player->client))
Expand Down
Loading

0 comments on commit 9fb8b97

Please sign in to comment.