Tie POWERLEVEL to Profiles

This commit is contained in:
SinnamonLat 2022-05-21 17:47:15 +02:00
parent 13c74efa41
commit 399272946c
6 changed files with 70 additions and 1 deletions

View file

@ -2246,6 +2246,33 @@ static void Command_connect(void)
CONS_Printf(M_GetText("You cannot connect while in a game. End this game first.\n"));
return;
}
else if (cv_currprofile.value == 0)
{
CONS_Printf(M_GetText("You cannot connect while using the Guest Profile. Use a Custom Profile to play Online.\n"));
return;
}
else if (cv_currprofile.value == -1)
{
// No profile set, we're attempting to connect from the title screen. (Discord RPC / connect command)
// Automatically apply the last profiles for every potential split player.
// Make sure Player 1's Profile ISN'T the guest profile even if we do that.
UINT8 i;
CONS_Printf(M_GetText("No Profile set, attempting to use last used Profiles...\n"));
for (i = 0; i < cv_splitplayers.value; i++)
{
if (cv_lastprofile[i].value || i > 0)
PR_ApplyProfile(cv_lastprofile[i].value, i);
else
{
CONS_Printf(M_GetText("Player 1's last used Profile is the Guest Profile, which cannot be used to play Online.\n"));
return;
}
}
CONS_Printf(M_GetText("Profiles have been automatically set according to the last used Profiles.\n"));
}
// modified game check: no longer handled
// we don't request a restart unless the filelist differs
@ -2308,6 +2335,7 @@ static void Command_connect(void)
SplitScreen_OnChange();
}
M_ClearMenus(true);
CL_ConnectToServer();
}
#endif

View file

@ -4122,6 +4122,9 @@ void G_SaveGameData(void)
FIL_WriteFile(va(pandf, srb2home, gamedatafilename), savebuffer, length);
free(savebuffer);
save_p = savebuffer = NULL;
// Also save profiles here.
PR_SaveProfiles();
}
#define VERSIONSIZE 16

View file

@ -1369,7 +1369,7 @@ static void M_DrawProfileCard(INT32 x, INT32 y, boolean greyedout, profile_t *p)
colormap = R_GetTranslationColormap(TC_DEFAULT, p->color, GTC_CACHE);
strcpy(pname, p->profilename);
skinnum = R_SkinAvailable(p->skinname);
powerlevel = 1000; // Test
powerlevel = p->powerlevels[0]; // Only display race power level.
}
// check setup_player for colormap for the card.

View file

@ -3565,9 +3565,19 @@ void M_MPOptSelectInit(INT32 choice)
{
INT16 arrcpy[3][3] = {{0,68,0}, {0,12,0}, {0,64,0}};
UINT8 i = 0, j = 0; // To copy the array into the struct
const UINT8 pid = 0;
(void)choice;
// Don't allow guest profile online
if (cv_currprofile.value == 0)
{
M_StartMessage(M_GetText("Cannot play online with\nGuest Profile.\nMake a custom Profile and try again.\n\n(Press any key)"), NULL, MM_NOTHING);
S_StartSound(NULL, sfx_s3k7b);
M_SetMenuDelay(pid);
return;
}
mpmenu.modechoice = 0;
mpmenu.ticker = 0;

View file

@ -26,6 +26,7 @@ INT32 PR_GetNumProfiles(void)
profile_t* PR_MakeProfile(const char *prname, const char *pname, const char *sname, const UINT16 col, const char *fname, UINT16 fcol, INT32 controlarray[num_gamecontrols][MAXINPUTMAPPING])
{
profile_t *new = Z_Malloc(sizeof(profile_t), PU_STATIC, NULL);
UINT8 i;
new->version = PROFILEVER;
@ -43,6 +44,10 @@ profile_t* PR_MakeProfile(const char *prname, const char *pname, const char *sna
// Copy from gamecontrol directly as we'll be setting controls up directly in the profile.
memcpy(new->controls, controlarray, sizeof(new->controls));
// Init both power levels
for (i = 0; i < PWRLV_NUMTYPES; i++)
new->powerlevels[i] = PWRLVRECORD_START;
return new;
}
@ -114,6 +119,14 @@ void PR_SaveProfiles(void)
{
FILE *f = NULL;
// save powerlevel in the current profile.
// granted we're using a profile that isn't guest, that is.
if (cv_currprofile.value > 0)
{
profile_t *pr = PR_GetProfile(cv_currprofile.value);
memcpy(&pr->powerlevels, vspowerlevel, sizeof(vspowerlevel));
}
f = fopen(va(pandf, srb2home, PROFILESFILE), "w");
if (f != NULL)
{
@ -166,6 +179,14 @@ void PR_ApplyProfile(UINT8 profilenum, UINT8 playernum)
{
profile_t *p = PR_GetProfile(profilenum);
// this CAN happen!!
if (p == NULL)
{
CONS_Printf("Profile '%d' could not be loaded as it does not exist. Guest Profile will be loaded instead.\n", profilenum);
profilenum = 0; // make sure to set this so that the cvar is set properly.
p = PR_GetProfile(0); // Use guest profile instead if things went south somehow.
}
CV_StealthSet(&cv_skin[playernum], p->skinname);
CV_StealthSetValue(&cv_playercolor[playernum], p->color);
CV_StealthSet(&cv_playername[playernum], p->playername);
@ -184,8 +205,13 @@ void PR_ApplyProfile(UINT8 profilenum, UINT8 playernum)
CV_StealthSetValue(&cv_lastprofile[playernum], profilenum);
// If we're doing this on P1, also change current profile.
// and update the powerlevel local array.
if (!playernum)
{
CV_StealthSetValue(&cv_currprofile, profilenum);
memcpy(&vspowerlevel, p->powerlevels, sizeof(p->powerlevels));
}
}
void PR_ApplyProfileLight(UINT8 profilenum, UINT8 playernum)

View file

@ -57,6 +57,8 @@ typedef struct profile_s
char follower[SKINNAMESIZE+1]; // Follower
UINT16 followercolor; // Follower color
UINT16 powerlevels[PWRLV_NUMTYPES]; // PWRLV for race & battle.
// Player-specific consvars.
// @TODO: List all of those
boolean kickstartaccel; // cv_kickstartaccel