The last thing we'll want to do is allow the player to check what their current stats are.
To do this we'll be creating one more dialogue window. This one will be accessible to the Player at all times, by holding down the Capslock key.
We'll write our function, CheckPlayerStats(), at the bottom of WL_DRAW:
void CheckPlayerStats (void)
{
char tempstr[2];
CenterWindow(10,10);
fontnumber = 1;
US_CPrint("Stats");
fontnumber = 0;
// Display the player's current level
US_Print("Level: ");
itoa (gamestate.lvl+1, tempstr, 10);
US_Print(tempstr);
fontnumber = 1; //switching back to large font
// Display Strength
US_Print("\n\nSTR - ");
itoa (gamestate.str, tempstr, 10);
US_Print(tempstr);
// Display Endurance
US_Print("\nEND - ");
itoa (gamestate.end, tempstr, 10);
US_Print(tempstr);
// Display Speed
US_Print("\nSPD - ");
itoa (gamestate.spd, tempstr, 10);
US_Print(tempstr);
}
Here we have a simple dialogue box generated with CenterWindow(), but when calling the text to display we're doing something different.
You can see several instances of US_CPrint() and US_Print() that function much like what we have worked with earlier in the guide, but we are also calling something called itoa().
itoa() is a standard function of C++ programming, and allows us to convert an integer variable into a string of text. It takes 3 variables, in the following format:
itoa (variable, character variable, radix);
First it takes the variable to be converted - which in the case of the above code will be the variable for the player's level, and each attribute. Then, the character variable that the converted string will be saved into. Finally, the value of radix determines how the value of the first variable is converted. By specifying a radix of 10, we are ensuring the result is the decimal (regular numerical) value of our variable.
We are using the tempstr character variable we have created at the top of this function to store and display each value in turn. It can currently store two characters, but if you're going to have displays that go into the hundreds you may want to change this to 3.
Now, we need to call our new function when the game detects the player presses the Capslock key. For that we scroll up a little in WL_DRAW to find the ThreeDRefresh() function. This is a critical function for the game and should be edited with care.
Inside of the function we can find the following code (This might differ depending on source port):
//
// draw all the scaled images
//
DrawScaleds(); // draw scaled stuff
#if defined(USE_FEATUREFLAGS) && defined(USE_RAIN)
if(GetFeatureFlags() & FF_RAIN)
DrawRain();
#endif
#if defined(USE_FEATUREFLAGS) && defined(USE_SNOW)
if(GetFeatureFlags() & FF_SNOW)
DrawSnow();
#endif
DrawPlayerWeapon (); // draw player's hands
if(Keyboard[sc_Tab] && viewsize == 21 && gamestate.weapon != -1)
ShowActStatus();
We can see as an example of code functioning similarly to what we want to accomplish - if the player is using the fullscreen display that hides the statusbar, the game will check if the player is holding down the TAB key, and if they are it will display the statusbar for them.
We'll add our lines directly underneath:
DrawPlayerWeapon (); // draw player's hands
if(Keyboard[sc_Tab] && viewsize == 21 && gamestate.weapon != -1)
ShowActStatus();
if (Keyboard[sc_CapsLock])
CheckPlayerStats();
The game now checks for if the player has hit the Capslock key, and if they have it will attempt to run CheckPlayerStats().
You'll find if you try to compile now, you will get an error from this use of CheckPlayerStats(). That is because we defined our function after ThreeDRefresh(). We need to define CheckPlayerStats() earlier. We could move the entire function up, but instead, we'll just add a declaration that the variable exists at the top of WL_DRAW:
//
// refresh variables
//
fixed viewx,viewy; // the focal point
short viewangle;
fixed viewsin,viewcos;
void TransformActor (objtype *ob);
void BuildTables (void);
void ClearScreen (void);
int CalcRotate (objtype *ob);
void DrawScaleds (void);
void CheckPlayerStats (void);
Now that we have declared the existence of CheckPlayerStats() before ThreeDRefresh(), your code should now compile, and pressing the Capslock key should display your current stats: