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

port: add random weapon selection and auto random mp option (WIP) #3

Closed
wants to merge 1 commit into from
Closed
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
38 changes: 38 additions & 0 deletions src/game/mplayer/mplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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);
}

Expand Down
84 changes: 84 additions & 0 deletions src/game/mplayer/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down