Skip to content
New issue

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

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

Already on GitHub? # to your account

Add "Select Random Weapons" mp menu #577

Merged
merged 4 commits into from
Feb 22, 2025
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
55 changes: 55 additions & 0 deletions src/game/mplayer/mplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ struct modeldef *var800acc28[18];
struct mpweaponset g_MpWeaponSets[12];
s32 g_MpWeaponSetNum;

#ifndef PLATFORM_N64
u8 g_MpWeaponSetRandomFilters[NUM_MPWEAPONS];
s32 g_MpWeaponRandomFilterNum;
#endif

#if VERSION >= VERSION_NTSC_1_0
const char var7f1b8a00[] = "||||||||||||| Starting game... players %d\n";
#endif
Expand Down Expand Up @@ -507,6 +512,12 @@ void mpPlayerSetDefaults(s32 playernum, bool autonames)
for (i = 0; i < ARRAYCOUNT(g_PlayerConfigsArray); i++) {
g_PlayerConfigsArray[playernum].gunfuncs[i] = 0;
}

#ifndef PLATFORM_N64
for (i = 0; i < ARRAYCOUNT(g_MpWeapons); i++) {
g_MpWeaponSetRandomFilters[i] = 1;
}
#endif
}

void func0f1881d4(s32 index)
Expand Down Expand Up @@ -1157,10 +1168,40 @@ void func0f18913c(void)
}
}

#ifndef PLATFORM_N64
void mpSetRandomWeapons(u8 weapons[])
{
s32 lockcount = 0;
s32 index = 0;
s32 i;

for (i = 0; i < NUM_MPWEAPONS; i++) {
if (challengeIsFeatureUnlocked(g_MpWeapons[i].unlockfeature)) {
if (g_MpWeaponSetRandomFilters[i] == 1) {
weapons[index] = i - lockcount;
index++;
}
} else {
lockcount++;
}
}

if (index == 0) {
weapons[0] = 0; // optionindex (shifted by unlocked weapons, but usually 0 is "Nothing")
g_MpWeaponRandomFilterNum = 1;
} else {
g_MpWeaponRandomFilterNum = index;
}
}
#endif

void mpApplyWeaponSet(void)
{
s32 i;
u8 *ptr;
#ifndef PLATFORM_N64
u8 randomweapons[NUM_MPWEAPONS];
#endif

if (g_MpWeaponSetNum >= 0 && g_MpWeaponSetNum < ARRAYCOUNT(g_MpWeaponSets)) {
if (challengeIsFeatureUnlocked(g_MpWeaponSets[g_MpWeaponSetNum].requirefeatures[0])
Expand Down Expand Up @@ -1198,17 +1239,31 @@ void mpApplyWeaponSet(void)
}
}
} else if (g_MpWeaponSetNum == WEAPONSET_RANDOM) {
#ifdef PLATFORM_N64
s32 numoptions = mpGetNumWeaponOptions();

for (i = 0; i < ARRAYCOUNT(g_MpSetup.weapons); i++) {
mpSetWeaponSlot(i, rngRandom() % numoptions);
}
#else
mpSetRandomWeapons(randomweapons);
for (i = 0; i < ARRAYCOUNT(g_MpSetup.weapons); i++) {
mpSetWeaponSlot(i, randomweapons[rngRandom() % g_MpWeaponRandomFilterNum]);
}
#endif
} else if (g_MpWeaponSetNum == WEAPONSET_RANDOMFIVE) {
#ifdef PLATFORM_N64
s32 numoptions = mpGetNumWeaponOptions() - 2;

for (i = 0; i < 5; i++) {
mpSetWeaponSlot(i, rngRandom() % numoptions + 1);
}
#else
mpSetRandomWeapons(randomweapons);
for (i = 0; i < 5; i++) {
mpSetWeaponSlot(i, randomweapons[rngRandom() % g_MpWeaponRandomFilterNum]);
}
#endif

mpSetWeaponSlot(i, mpGetNumWeaponOptions() - 1);
}
Expand Down
157 changes: 157 additions & 0 deletions src/game/mplayer/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,155 @@ struct menudialogdef g_MpSaveSetupExistsMenuDialog = {
};

#ifndef PLATFORM_N64
MenuItemHandlerResult mpSelectRandomWeaponListHandler(s32 operation, struct menuitem *item, union handlerdata *data)
{
static const char *labels[] = {
"Select Dark",
"Select Classic",
"Select All",
"Select None",
};

switch (operation) {
case MENUOP_GETOPTIONCOUNT:
data->list.value = mpGetNumWeaponOptions() + 4;
break;
case MENUOP_GETOPTIONTEXT:
{
s32 numweapons = mpGetNumWeaponOptions();

if (data->list.value < numweapons) {
return (uintptr_t) mpGetWeaponLabel(data->list.value);
} else {
return (intptr_t)labels[data->list.value - numweapons];
}
}
case MENUOP_SET:
{
s32 numweapons = mpGetNumWeaponOptions();
s32 mpweaponnum = data->list.value;
s32 optionindex = mpweaponnum;
s32 i;

if (data->list.value < numweapons) {
if (data->list.unk04 == 0) {
for (i = 0; i <= mpweaponnum; i++) {
if (challengeIsFeatureUnlocked(g_MpWeapons[i].unlockfeature) == 0) {
mpweaponnum++;
}

optionindex = mpweaponnum;
}

g_MpWeaponSetRandomFilters[optionindex] = 1 - g_MpWeaponSetRandomFilters[optionindex];
}
} else {
s32 index = data->list.value - numweapons;

switch (index) {
case 0:
// Select Dark
for (i = 0; i < ARRAYCOUNT(g_MpWeapons); i++) {
if ((i >= MPWEAPON_NONE && i <= MPWEAPON_COMBATBOOST) || i >= MPWEAPON_SHIELD) {
g_MpWeaponSetRandomFilters[i] = 1;
} else {
g_MpWeaponSetRandomFilters[i] = 0;
}
}
break;
case 1:
// Select Classic
for (i = 0; i < ARRAYCOUNT(g_MpWeapons); i++) {
if (i >= MPWEAPON_PP9I && i <= MPWEAPON_RCP45) {
g_MpWeaponSetRandomFilters[i] = 1;
} else {
g_MpWeaponSetRandomFilters[i] = 0;
}
}
break;
case 2:
// Select All
for (i = 0; i < ARRAYCOUNT(g_MpWeapons); i++) {
g_MpWeaponSetRandomFilters[i] = 1;
}
break;
case 3:
// Select None
for (i = 0; i < ARRAYCOUNT(g_MpWeapons); i++) {
g_MpWeaponSetRandomFilters[i] = 0;
}
break;
}
}
}
break;
case MENUOP_GETSELECTEDINDEX:
data->list.value = 0x000fffff;
break;
case MENUOP_GETLISTITEMCHECKBOX:
{
s32 numweapons = mpGetNumWeaponOptions();
s32 mpweaponnum = data->list.value;
s32 optionindex = mpweaponnum;
s32 i;

if (data->list.value < numweapons) {

for (i = 0; i <= mpweaponnum; i++) {
if (challengeIsFeatureUnlocked(g_MpWeapons[i].unlockfeature) == 0) {
mpweaponnum++;
}

optionindex = mpweaponnum;
}

data->list.unk04 = g_MpWeaponSetRandomFilters[optionindex];
}
}
break;
}

return 0;
}

struct menuitem g_MpSelectRandomWeaponsMenuItems[] = {
{
MENUITEMTYPE_LIST,
0,
MENUITEMFLAG_LOCKABLEMINOR,
0x00000078,
0x0000004d,
mpSelectRandomWeaponListHandler,
},
{ MENUITEMTYPE_END },
};

struct menudialogdef g_MpSelectRandomWeaponsMenuDialog = {
MENUDIALOGTYPE_DEFAULT,
(uintptr_t)"Select Weapons",
g_MpSelectRandomWeaponsMenuItems,
NULL,
MENUDIALOGFLAG_LITERAL_TEXT,
NULL,
};

MenuItemHandlerResult menuhandlerMpSelectRandomWeapons(s32 operation, struct menuitem *item, union handlerdata *data)
{
switch (operation) {
case MENUOP_CHECKDISABLED:
case MENUOP_CHECKHIDDEN:
if (g_MpWeaponSetNum == WEAPONSET_RANDOM
|| g_MpWeaponSetNum == WEAPONSET_RANDOMFIVE) {
return false;
}
return true;
case MENUOP_SET:
menuPushDialog(&g_MpSelectRandomWeaponsMenuDialog);
}

return 0;
}

MenuItemHandlerResult menuhandlerMpAutoRandomWeapon(s32 operation, struct menuitem *item, union handlerdata *data)
{
static const char *labels[] = {
Expand Down Expand Up @@ -1220,6 +1369,14 @@ struct menuitem g_MpWeaponsMenuItems[] = {
menuhandlerMpWeaponSetDropdown,
},
#ifndef PLATFORM_N64
{
MENUITEMTYPE_SELECTABLE,
0,
MENUITEMFLAG_LITERAL_TEXT,
(uintptr_t)"Select Weapons\n",
0,
menuhandlerMpSelectRandomWeapons,
},
{
MENUITEMTYPE_DROPDOWN,
0,
Expand Down
3 changes: 3 additions & 0 deletions src/include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ extern s32 g_MusicDisableMpDeath;
extern s32 g_BgunGeMuzzleFlashes;
extern s32 g_FileAutoSelect;

extern u8 g_MpWeaponSetRandomFilters[NUM_MPWEAPONS];
extern s32 g_MpWeaponRandomFilterNum;

#define PLAYER_EXTCFG() g_PlayerExtCfg[g_Vars.currentplayerstats->mpindex & 3]
#define PLAYER_DEFAULT_FOV (PLAYER_EXTCFG().fovy)

Expand Down
3 changes: 3 additions & 0 deletions src/include/game/mplayer/mplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ s32 func0f189058(bool full);
s32 func0f189088(void);
char *mpGetWeaponSetName(s32 arg0);
void func0f18913c(void);
#ifndef PLATFORM_N64
void mpSetRandomWeapons(u8 weapons[]);
#endif
void mpApplyWeaponSet(void);
void mpSetWeaponSet(s32 weaponsetnum);
void func0f1895e8(void);
Expand Down
Loading