From 670307f9938bf3d0cfc4039b434f2e3df406d266 Mon Sep 17 00:00:00 2001 From: Jonaeru Date: Sun, 24 Mar 2024 17:46:15 +0900 Subject: [PATCH] port: add random weapon selection and auto random mp option (WIP) --- src/game/mplayer/mplayer.c | 38 +++++++++++++++++ src/game/mplayer/setup.c | 84 ++++++++++++++++++++++++++++++++++++++ src/include/constants.h | 8 ++++ 3 files changed, 130 insertions(+) diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index 20270b1ed..866c0149c 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -1069,22 +1069,40 @@ s32 func0f188f9c(s32 arg0) s32 func0f189058(bool full) { +#ifndef PLATFORM_N64 + return mpCountWeaponSetThing(full ? ARRAYCOUNT(g_MpWeaponSets) + 4 : ARRAYCOUNT(g_MpWeaponSets)); +#else return mpCountWeaponSetThing(full ? ARRAYCOUNT(g_MpWeaponSets) + 3 : ARRAYCOUNT(g_MpWeaponSets)); +#endif } s32 func0f189088(void) { +#ifndef PLATFORM_N64 + return mpCountWeaponSetThing(ARRAYCOUNT(g_MpWeaponSets) + 3); +#else return mpCountWeaponSetThing(ARRAYCOUNT(g_MpWeaponSets) + 2); +#endif } char *mpGetWeaponSetName(s32 index) { index = func0f188f9c(index); +#ifndef PLATFORM_N64 + if (index < 0 || index >= ARRAYCOUNT(g_MpWeaponSets) + 3) { +#else if (index < 0 || index >= ARRAYCOUNT(g_MpWeaponSets) + 2) { +#endif return langGet(L_MPWEAPONS_041); // "Custom" } +#ifndef PLATFORM_N64 + if (index == ARRAYCOUNT(g_MpWeaponSets) + 2) { + return (char *)"Random (Selection)\n"; // "Random (Selection)" + } +#endif + if (index == ARRAYCOUNT(g_MpWeaponSets) + 1) { return langGet(L_MPWEAPONS_042); // "Random" } @@ -1198,6 +1216,16 @@ void mpApplyWeaponSet(void) } mpSetWeaponSlot(i, mpGetNumWeaponOptions() - 1); +#ifndef PLATFORM_N64 + } else if (g_MpWeaponSetNum == WEAPONSET_RANDOMSELECTION) { + s32 numoptions = mpGetNumWeaponOptions() - 2; + + for (i = 0; i < 5; i++) { + mpSetWeaponSlot(i, random() % numoptions + 1); + } + + mpSetWeaponSlot(i, mpGetNumWeaponOptions() - 1); +#endif } } @@ -2458,6 +2486,16 @@ void mpEndMatch(void) challengeConsiderMarkingComplete(); } +#ifndef PLATFORM_N64 + if (g_MpSetup.options & MPOPTION_AUTORANDOM_WEAPON) { + if (g_MpWeaponSetNum == WEAPONSET_RANDOM + || g_MpWeaponSetNum == WEAPONSET_RANDOMFIVE + || g_MpWeaponSetNum == WEAPONSET_RANDOMSELECTION) { + mpApplyWeaponSet(); + } + } +#endif + func0f0f820c(NULL, -6); } diff --git a/src/game/mplayer/setup.c b/src/game/mplayer/setup.c index 87b99860d..a07307244 100644 --- a/src/game/mplayer/setup.c +++ b/src/game/mplayer/setup.c @@ -31,6 +31,10 @@ struct menudialogdef g_MpChangeTeamNameMenuDialog; struct menudialogdef g_MpEditSimulantMenuDialog; struct menudialogdef g_MpSaveSetupNameMenuDialog; +#ifndef PLATFORM_N64 +extern s32 g_MpWeaponSetNum; +#endif + MenuItemHandlerResult menuhandlerMpDropOut(s32 operation, struct menuitem *item, union handlerdata *data) { if (operation == MENUOP_SET) { @@ -1160,6 +1164,60 @@ struct menudialogdef g_MpSaveSetupExistsMenuDialog = { NULL, }; +#ifndef PLATFORM_N64 +struct menuitem g_MpSelectWeaponsMenuItems[] = { + { + MENUITEMTYPE_LIST, + 0, + MENUITEMFLAG_LOCKABLEMINOR, + 0x00000078, + 0x0000004d, + mpSelectTuneListHandler, // FIXME + }, + { MENUITEMTYPE_END }, +}; + +struct menudialogdef g_MpSelectWeaponsMenuDialog = { + MENUDIALOGTYPE_DEFAULT, + (uintptr_t)"Select Weapons", + g_MpSelectWeaponsMenuItems, + NULL, + MENUDIALOGFLAG_LITERAL_TEXT, + NULL, +}; + +MenuItemHandlerResult menuhandlerMpWeaponSelection(s32 operation, struct menuitem *item, union handlerdata *data) +{ + switch (operation) { + case MENUOP_CHECKDISABLED: + case MENUOP_CHECKHIDDEN: + if (g_MpWeaponSetNum == WEAPONSET_RANDOMSELECTION) { + return false; + } + return true; + case MENUOP_SET: + menuPushDialog(&g_MpSelectWeaponsMenuDialog); + } + + return 0; +} + +MenuItemHandlerResult menuhandlerMpAutoRandomWeapon(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 || + g_MpWeaponSetNum == WEAPONSET_RANDOMSELECTION) { + return false; + } + return true; + } + + return menuhandlerMpCheckboxOption(operation, item, data); +} +#endif + struct menuitem g_MpWeaponsMenuItems[] = { { MENUITEMTYPE_DROPDOWN, @@ -1241,6 +1299,32 @@ struct menuitem g_MpWeaponsMenuItems[] = { 0, NULL, }, +#ifndef PLATFORM_N64 + { + MENUITEMTYPE_CHECKBOX, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Auto Random\n", + MPOPTION_AUTORANDOM_WEAPON, + menuhandlerMpAutoRandomWeapon, + }, + { + MENUITEMTYPE_SELECTABLE, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Select Weapons\n", + 0, + menuhandlerMpWeaponSelection, + }, + { + MENUITEMTYPE_SEPARATOR, + 0, + 0, + 0, + 0, + menuhandlerMpAutoRandomWeapon, + }, +#endif { MENUITEMTYPE_SELECTABLE, 0, diff --git a/src/include/constants.h b/src/include/constants.h index e51ec894a..8f41e96d8 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -2890,6 +2890,7 @@ #define MPOPTION_PAC_HIGHLIGHTTARGET 0x00080000 #define MPOPTION_PAC_SHOWONRADAR 0x00100000 #define MPOPTION_SPAWNWITHWEAPON 0x00200000 +#define MPOPTION_AUTORANDOM_WEAPON 0x00400000 #define MPPAUSEMODE_UNPAUSED 0 #define MPPAUSEMODE_PAUSED 1 @@ -4511,9 +4512,16 @@ enum weaponnum { #define WEAPONFLAG_AIMTRACK 0x40000000 // Allow drawing red box around targets in aim mode #define WEAPONFLAG_FIRETOACTIVATE 0x80000000 // For devices/gadgets +#ifndef PLATFORM_N64 +#define WEAPONSET_RANDOMFIVE 0x0c +#define WEAPONSET_RANDOM 0x0d +#define WEAPONSET_RANDOMSELECTION 0x0e +#define WEAPONSET_CUSTOM 0x0f +#else #define WEAPONSET_RANDOMFIVE 0x0c #define WEAPONSET_RANDOM 0x0d #define WEAPONSET_CUSTOM 0x0e +#endif #define WEATHERTYPE_RAIN 0 #define WEATHERTYPE_SNOW 1