Merge pull request #577 from jonaeru/mp-random-weapon-filter

Add "Select Random Weapons" mp menu
This commit is contained in:
fgsfds authored and GitHub committed 2025-02-22 11:16:56 +01:00
commit 176b4282fc
4 files changed
+218

No files matched your search

+55
View File
@@ -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
@@ -508,6 +513,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)
@@ -1158,10 +1169,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])
@@ -1199,17 +1240,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);
}
+157
View File
@@ -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[] = {
@@ -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,
+3
View File
@@ -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)
+3
View File
@@ -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);