Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new teamnames (and colors) for rpickup (Issue 297) #311

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,14 @@ typedef struct votemap_s
int admins;
} votemap_t;

typedef struct rpickupTeams_s
{
char name[5];
char topColor[3];
char bottomColor[3];
char stuffCmd[30];
} rpickupTeams_t;

extern votemap_t maps_voted[];
int vote_get_maps();

Expand Down
3 changes: 0 additions & 3 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -5235,9 +5235,6 @@ void fpslist()
}

// This is designed for pickup games and creates totally random teams(ish)
// It creates teams thus :
// Team red color 4 skin ""
// team blue color 13 skin ""
void RandomPickup()
{
int votes;
Expand Down
95 changes: 74 additions & 21 deletions src/vote.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
// vote.c: election functions by rc\sturm
#include "g_local.h"

#define MAX_PLAYERCOUNT_RPICKUP 32

// These are the built-in teams for rpickup to choose from
rpickupTeams_t builtinTeamInfo[] =
{
{"Bone", "10", "0", "color 10 0\nskin \"\"\nteam Bone\n"},
{"Teal", "11", "11", "color 11 11\nskin \"\"\nteam Teal\n"},
{"Pink", "6", "6", "color 6 6\nskin \"\"\nteam Pink\n"},
{"Gold", "5", "12", "color 5 12\nskin \"\"\nteam Gold\n"},
{"Plum", "8", "8", "color 8 8\nskin \"\"\nteam Plum\n"},
{"Wine", "4", "4", "color 4 4\nskin \"\"\nteam Wine\n"},
{"Beer", "0", "1", "color 0 1\nskin \"\"\nteam Beer\n"},
{"Weed", "3", "3", "color 3 3\nskin \"\"\nteam Weed\n"}
};

rpickupTeams_t rpTeams[3];

//void BeginPicking();
void BecomeCaptain(gedict_t *p);
void BecomeCoach(gedict_t *p);
Expand Down Expand Up @@ -623,6 +640,34 @@ void vote_check_pickup()
}
}

// This function will randomly select an entry from 'builtinTeamInfo', and copy its content
// to the '_rpTeam' parameter.
void generateTeamInfo(rpickupTeams_t *_rpTeam)
{
memcpy(_rpTeam,
&builtinTeamInfo[(int)(g_random() * (sizeof(builtinTeamInfo) / sizeof(rpickupTeams_t)))],
sizeof(rpickupTeams_t));
}

// This function will fill up 'rpTeams' with new content.
// 'rpTeams' is an array with 3 members, which contains the Team info (name and color) for rpickup
void create_rpickup_teaminfo(void)
{
memset(rpTeams, 0, sizeof(rpTeams));

generateTeamInfo(&rpTeams[0]);

do
{
generateTeamInfo(&rpTeams[1]);
} while (strcmp(rpTeams[0].name, rpTeams[1].name) == 0);

do
{
generateTeamInfo(&rpTeams[2]);
} while ((strcmp(rpTeams[0].name, rpTeams[2].name) == 0) || (strcmp(rpTeams[1].name, rpTeams[2].name) == 0));
}

// !!! do not confuse rpickup and pickup
void vote_check_rpickup(int maxRecursion)
{
Expand All @@ -631,8 +676,8 @@ void vote_check_rpickup(int maxRecursion)
gedict_t *p;
int veto;
qbool needNewRpickup = true;
// buffer reserved for 20 players (10on10). If more present, recursive auto-rpickup will not be activated
int originalTeams[20];
// buffer reserved for 32 players (16on16). If more present, recursive auto-rpickup will not be activated
int originalTeams[MAX_PLAYERCOUNT_RPICKUP];

if (match_in_progress || k_captains || k_coaches)
{
Expand All @@ -656,13 +701,18 @@ void vote_check_rpickup(int maxRecursion)

if (veto || !get_votes_req(OV_RPICKUP, true))
{
vote_clear(OV_RPICKUP);
// Real rpickup is happening
if (MAX_RPICKUP_RECUSION == maxRecursion)
{
// We create the teaminfo, but only at the first time (from the occasional repetition)
create_rpickup_teaminfo();
}

// Save the original teams, and also clear them
i = 0;
for (p = world; (p = find_plr(p));)
{
if (i < 20)
if (i < MAX_PLAYERCOUNT_RPICKUP)
{
originalTeams[i++] = p->k_teamnumber;
}
Expand All @@ -679,6 +729,7 @@ void vote_check_rpickup(int maxRecursion)
{
if (p->k_teamnumber)
{
// This is a player that we already handled
continue;
}

Expand All @@ -703,42 +754,39 @@ void vote_check_rpickup(int maxRecursion)
{
if (p->isBot)
{
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "team", "red", 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "topcolor", "4", 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "bottomcolor", "4", 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "team", rpTeams[0].name, 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "topcolor", rpTeams[0].topColor, 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "bottomcolor", rpTeams[0].bottomColor, 0);
}
else
{
stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO,
"color 4\nskin \"\"\nteam red\n");
stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "%s", rpTeams[0].stuffCmd);
}
}
else if (p->k_teamnumber == 2)
{
if (p->isBot)
{
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "team", "blue", 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "topcolor", "13", 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "bottomcolor", "13", 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "team", rpTeams[1].name, 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "topcolor", rpTeams[1].topColor, 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "bottomcolor", rpTeams[1].bottomColor, 0);
}
else
{
stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO,
"color 13\nskin \"\"\nteam blue\n");
stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "%s", rpTeams[1].stuffCmd);
}
}
else
{
if (p->isBot)
{
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "team", "yellow", 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "topcolor", "12", 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "bottomcolor", "12", 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "team", rpTeams[2].name, 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "topcolor", rpTeams[2].topColor, 0);
trap_SetBotUserInfo(NUM_FOR_EDICT(p), "bottomcolor", rpTeams[2].bottomColor, 0);
}
else
{
stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO,
"color 12\nskin \"\"\nteam yellow\n");
stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "%s", rpTeams[2].stuffCmd);
}
}

Expand All @@ -759,9 +807,9 @@ void vote_check_rpickup(int maxRecursion)
}

// check if rpickup really created new teams
if (pl_cnt <= 20)
if (pl_cnt <= MAX_PLAYERCOUNT_RPICKUP)
{
for (p = world, i = 0; (p = find_plr(p)) && i < 20 && needNewRpickup; i++)
for (p = world, i = 0; (p = find_plr(p)) && i < MAX_PLAYERCOUNT_RPICKUP && needNewRpickup; i++)
{
if (originalTeams[i] != p->k_teamnumber)
{
Expand All @@ -776,6 +824,11 @@ void vote_check_rpickup(int maxRecursion)
redtext("random pickup"), maxRecursion);
vote_check_rpickup(maxRecursion - 1);
}
else
{
// we have a new team layout, let's clear the rpickup flag
vote_clear(OV_RPICKUP);
}
}
}
}
Expand Down