1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*
This file handles the cheat dialogs and the high score file
*/
#ifdef unix
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include <stdio.h>
#include "SDL_endian.h"
#include "Maelstrom_Globals.h"
#include "load.h"
#include "dialog.h"
#define MAELSTROM_SCORES "Maelstrom-Scores"
#define NUM_SCORES 10 // Do not change this!
/* Everyone can write to scores file if defined to 0 */
#define SCORES_PERMMASK 022
#define CLR_DIALOG_WIDTH 281
#define CLR_DIALOG_HEIGHT 111
Bool gNetScores = 0;
Scores hScores[NUM_SCORES];
void LoadScores(void)
{
SavePath path;
SDL_RWops *scores_src;
int i;
/* Try to load network scores, if we can */
if ( gNetScores ) {
if ( NetLoadScores() == 0 )
return;
else {
mesg("Using local score file\n\n");
gNetScores = 0;
}
}
memset(&hScores, 0, sizeof(hScores));
scores_src = SDL_RWFromFile(path.Path(MAELSTROM_SCORES), "rb");
/* Debian change: try to load the scores from the old system location
* in case there are no local scores */
if ( scores_src == NULL ) {
scores_src = SDL_RWFromFile("/var/games/Maelstrom-Scores", "rb");
}
if ( scores_src != NULL ) {
for ( i=0; i<NUM_SCORES; ++i ) {
SDL_RWread(scores_src, hScores[i].name,
sizeof(hScores[i].name), 1);
hScores[i].wave = SDL_ReadBE32(scores_src);
hScores[i].score = SDL_ReadBE32(scores_src);
}
SDL_RWclose(scores_src);
}
}
void SaveScores(void)
{
SavePath path;
SDL_RWops *scores_src;
int i;
#ifdef unix
int omask;
#endif
/* Don't save network scores */
if ( gNetScores )
return;
#ifdef unix
omask=umask(SCORES_PERMMASK);
#endif
scores_src = SDL_RWFromFile(path.Path(MAELSTROM_SCORES), "wb");
if ( scores_src != NULL ) {
for ( i=0; i<NUM_SCORES; ++i ) {
SDL_RWwrite(scores_src, hScores[i].name,
sizeof(hScores[i].name), 1);
SDL_WriteBE32(scores_src, hScores[i].wave);
SDL_WriteBE32(scores_src, hScores[i].score);
}
SDL_RWclose(scores_src);
} else {
error("Warning: Couldn't save scores to %s\n",
path.Path(MAELSTROM_SCORES));
}
#ifdef unix
umask(omask);
#endif
}
/* Just show the high scores */
void PrintHighScores(void)
{
int i;
LoadScores();
/* FIXME! -- Put all lines into a single formatted message */
printf("Name Score Wave\n");
for ( i=0; i<NUM_SCORES; ++i ) {
printf("%-20s %-3.1u %u\n", hScores[i].name,
hScores[i].score, hScores[i].wave);
}
}
static int do_clear;
static int Clear_callback(void) {
do_clear = 1;
return(1);
}
static int Cancel_callback(void) {
do_clear = 0;
return(1);
}
int ZapHighScores(void)
{
MFont *chicago;
Maclike_Dialog *dialog;
int X, Y;
SDL_Surface *splash;
Mac_Button *clear;
Mac_Button *cancel;
/* Set up all the components of the dialog box */
#ifdef CENTER_DIALOG
X=(SCREEN_WIDTH-CLR_DIALOG_WIDTH)/2;
Y=(SCREEN_HEIGHT-CLR_DIALOG_HEIGHT)/2;
#else /* The way it is on the original Maelstrom */
X=179;
Y=89;
#endif
if ( (chicago = fontserv->NewFont("Chicago", 12)) == NULL ) {
error("Can't use Chicago font!\n");
return(0);
}
if ( (splash = Load_Title(screen, 102)) == NULL ) {
error("Can't load score zapping splash!\n");
delete chicago;
return(0);
}
dialog = new Maclike_Dialog(X, Y, CLR_DIALOG_WIDTH, CLR_DIALOG_HEIGHT,
screen);
dialog->Add_Image(splash, 4, 4);
do_clear = 0;
clear = new Mac_Button(99, 74, BUTTON_WIDTH, BUTTON_HEIGHT,
"Clear", chicago, fontserv, Clear_callback);
dialog->Add_Dialog(clear);
cancel = new Mac_DefaultButton(99+BUTTON_WIDTH+14, 74,
BUTTON_WIDTH, BUTTON_HEIGHT,
"Cancel", chicago, fontserv, Cancel_callback);
dialog->Add_Dialog(cancel);
/* Run the dialog box */
dialog->Run();
/* Clean up and return */
screen->FreeImage(splash);
delete chicago;
delete dialog;
if ( do_clear ) {
memset(hScores, 0, sizeof(hScores));
SaveScores();
gLastHigh = -1;
}
return(do_clear);
}
#define LVL_DIALOG_WIDTH 346
#define LVL_DIALOG_HEIGHT 136
static int do_level;
static int Level_callback(void) {
do_level = 1;
return(1);
}
static int Cancel2_callback(void) {
do_level = 0;
return(1);
}
int GetStartLevel(void)
{
static const char *Ltext1 =
"Enter the level to start from (1-40). This";
static const char *Ltext2 =
"disqualifies you from a high score...";
static const char *Ltext3 = "Level:";
static const char *Ltext4 = "Lives:";
MFont *chicago;
Maclike_Dialog *dialog;
SDL_Surface *splash;
SDL_Surface *text1, *text2, *text3, *text4;
static const char *turbotext = "Turbofunk On";
int x, y, X, Y;
Mac_Button *doit;
Mac_Button *cancel;
Mac_NumericEntry *numeric_entry;
Mac_CheckBox *checkbox;
int startlevel=10, startlives=5, turbofunk=0;
/* Set up all the components of the dialog box */
if ( (chicago = fontserv->NewFont("Chicago", 12)) == NULL ) {
error("Can't use Chicago font!\n");
return(0);
}
if ( (splash = GetCIcon(screen, 103)) == NULL ) {
error("Can't load alien level splash!\n");
delete chicago;
return(0);
}
X=(SCREEN_WIDTH-LVL_DIALOG_WIDTH)/2;
Y=(SCREEN_HEIGHT-LVL_DIALOG_HEIGHT)/2;
dialog = new Maclike_Dialog(X, Y, LVL_DIALOG_WIDTH, LVL_DIALOG_HEIGHT,
screen);
x = y = 14;
dialog->Add_Image(splash, x, y);
x += (splash->w+14);
text1 = fontserv->TextImage(Ltext1,chicago,STYLE_NORM,0x00,0x00,0x00);
dialog->Add_Image(text1, x, y);
y += (text1->h+2);
text2 = fontserv->TextImage(Ltext2, chicago, STYLE_NORM,
0x00, 0x00, 0x00);
dialog->Add_Image(text2, x, y);
do_level = 0;
cancel = new Mac_Button(166, 96, 73, BUTTON_HEIGHT,
"Cancel", chicago, fontserv, Cancel2_callback);
dialog->Add_Dialog(cancel);
doit = new Mac_DefaultButton(166+73+14, 96, BUTTON_WIDTH, BUTTON_HEIGHT,
"Do it!", chicago, fontserv, Level_callback);
dialog->Add_Dialog(doit);
numeric_entry = new Mac_NumericEntry(X, Y, chicago, fontserv);
numeric_entry->Add_Entry(78, 60, 3, 1, &startlevel);
text3 = fontserv->TextImage(Ltext3,chicago,STYLE_NORM,0x00,0x00,0x00);
dialog->Add_Image(text3, 78-text3->w-2, 60+3);
numeric_entry->Add_Entry(78, 86, 3, 0, &startlives);
text4 = fontserv->TextImage(Ltext4,chicago,STYLE_NORM,0x00,0x00,0x00);
dialog->Add_Image(text4, 78-text3->w-2, 86+3);
dialog->Add_Dialog(numeric_entry);
checkbox = new Mac_CheckBox(&turbofunk, 136, 64, turbotext,
chicago, fontserv);
dialog->Add_Dialog(checkbox);
/* Run the dialog box */
dialog->Run(EXPAND_STEPS);
/* Clean up and return */
screen->FreeImage(splash);
fontserv->FreeText(text1);
fontserv->FreeText(text2);
fontserv->FreeText(text3);
fontserv->FreeText(text4);
delete chicago;
delete dialog;
if ( do_level ) {
if ( ! startlives || (startlives > 40) )
startlives = 3;
gStartLives = startlives;
if ( startlevel > 40 )
startlevel = 0;
gStartLevel = startlevel;
gNoDelay = turbofunk;
return(gStartLevel);
}
return(0);
}
|