Skip to content

Commit

Permalink
GAME: Improve support for Q3 items and game types
Browse files Browse the repository at this point in the history
- fix item_haste name, there was an e missing
- remove item_enviro (there is no item_climber to replace with)
- add replacements for Q3 holdables teleporter (floater) and medkit (killerducks)
- add replacement for armor_combat (padshield)
- g_q3Items also will also check against Q3 game types (taken from Byrillium mod)
  • Loading branch information
kai-li-wop committed Oct 30, 2023
1 parent 47e1ad5 commit b18d6f2
Showing 1 changed file with 74 additions and 6 deletions.
80 changes: 74 additions & 6 deletions code/game/g_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,16 @@ static const replacePair_t q3ToWopItems[] = {{"weapon_gauntlet", "weapon_punchy"
{"ammo_bfg", "ammo_imperius"},

{"item_quad", "item_padpower"},
{"item_enviro", "item_climber"},
{"item_hast", "item_speedy"},
{"item_flight", "item_jump"},
{"item_haste", "item_speedy"},
{"item_flight", "item_jumper"},
{"item_invis", "item_visionless"},
{"item_regen", "item_revival"},
{"item_armor_combat", "item_armor_padshield"},
{"item_armor_body", "item_armor_padshield"},

{"holdable_teleporter", "holdable_floater"},
{"holdable_medkit", "holdable_killerducks"},

{"team_CTF_redflag", "team_CTL_redlolly"},
{"team_CTF_blueflag", "team_CTL_bluelolly"},
{"team_CTF_redplayer", "team_redplayer"},
Expand All @@ -375,6 +378,50 @@ static const replacePair_t spawnpointReplacements[] = {{"team_redplayer", "info_
{"team_bluespawn", "info_player_deathmatch"},
{NULL, NULL}};

/*
===================
G_ValueIncludesGametype
Returns whether value includes gametype.
If g_q3Items is enabled, will also check against Q3 gametype names.
===================
*/
static qboolean G_ValueIncludesGametype(const char *value, gametype_t gametype) {
const char *gametypeName;
char *s;

// Order needs to match gametype_t of WoP
static const char *gametypeNames[] = {"ffa", "tournament", "single", "spray", "lps", "ctkd",
"team", "freeze", "ctl", "sptp", "balloon"};
static const char *gametypeNamesQ3[] = {"ffa", "tournament", "single", NULL, NULL, NULL,
"team", NULL, "ctf", NULL, NULL};

if ((gametype < GT_FFA) || (gametype >= GT_MAX_GAME_TYPE)) {
return qfalse;
}
gametypeName = gametypeNames[gametype];

s = strstr(value, gametypeName);
if (!s) {
if (g_q3Items.integer) {
gametypeName = gametypeNamesQ3[gametype];
if (NULL == gametypeName) {
return qfalse;
}

s = strstr(value, gametypeName);
if (s) {
return qtrue;
}
}

return qfalse;
}

return qtrue;
}


/*
===================
G_SpawnGEntityFromSpawnVars
Expand All @@ -391,8 +438,8 @@ static void G_SpawnGEntityFromSpawnVars(void) {
const char *gametypeName;
const gitem_t *item;

static const char *gametypeNames[] = {"ffa", "tournament", "single", "spray", "lps", "ctkd",
"team", "freeze", "ctl", "sptp", "balloon"};
static const char *gametypeNames[] = {"ffa", "tournament", "single", "spray", "lps", "ctkd",
"team", "freeze", "ctl", "sptp", "balloon"};
CASSERT(ARRAY_LEN(gametypeNames) == GT_MAX_GAME_TYPE);

// get the next free entity
Expand All @@ -406,6 +453,9 @@ static void G_SpawnGEntityFromSpawnVars(void) {
if (g_q3Items.integer) {
for (i = 0; q3ToWopItems[i].s; i++) {
if (Q_stricmp(ent->classname, q3ToWopItems[i].s) == 0) {
G_Printf("Spawning (Q3 items): replacing entity " S_COLOR_YELLOW "%s" S_COLOR_WHITE
" with " S_COLOR_YELLOW "%s" S_COLOR_WHITE ".\n",
ent->classname, q3ToWopItems[i].r);
ent->classname = (const char *)q3ToWopItems[i].r;
break;
}
Expand Down Expand Up @@ -506,7 +556,25 @@ static void G_SpawnGEntityFromSpawnVars(void) {
}
}

for (item = (bg_itemlist + 1); item->classname; item++) {
if (G_SpawnString("gametype", NULL, &value)) {
if (!G_ValueIncludesGametype(value, g_gametype.integer)) {
G_Printf("Spawning: not spawning " S_COLOR_YELLOW "%s" S_COLOR_WHITE " due to gametype key.\n",
ent->classname);
G_FreeEntity(ent);
return;
}
}

if (G_SpawnString("notGametype", NULL, &value)) {
if (G_ValueIncludesGametype(value, g_gametype.integer)) {
G_Printf("Spawning: not spawning " S_COLOR_YELLOW "%s" S_COLOR_WHITE " due to notGametype key.\n",
ent->classname);
G_FreeEntity(ent);
return;
}
}

for (item = (bg_itemlist + 1); item->classname; item++) {
if (strcmp(item->classname, ent->classname) == 0) {
RegisterItem(item);
break;
Expand Down

0 comments on commit b18d6f2

Please sign in to comment.