generate new hiscore table if one doesnt already exist
This commit is contained in:
parent
ea1df51d08
commit
281944bb5a
6
io.c
6
io.c
|
@ -15382,7 +15382,11 @@ void tombstone(lifeform_t *lf) {
|
||||||
limit(&maxrank, NA, 100);
|
limit(&maxrank, NA, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
centre(mainwin, C_GREY, y, "High Scores"); y++;
|
wattron(mainwin, A_BOLD);
|
||||||
|
wattron(mainwin, A_UNDERLINE);
|
||||||
|
centre(mainwin, C_CYAN, y, "High Scores"); y++;
|
||||||
|
wattroff(mainwin, A_UNDERLINE);
|
||||||
|
wattroff(mainwin, A_BOLD);
|
||||||
wattron(mainwin, A_BOLD);
|
wattron(mainwin, A_BOLD);
|
||||||
mvwprintw(mainwin, y, 0, HISCOREFORMAT, "Pos", "Score", "Name", "Job");
|
mvwprintw(mainwin, y, 0, HISCOREFORMAT, "Pos", "Score", "Name", "Job");
|
||||||
wprintw(mainwin, "Method of death"); y++;
|
wprintw(mainwin, "Method of death"); y++;
|
||||||
|
|
4
nexus.c
4
nexus.c
|
@ -1627,8 +1627,6 @@ int init(void) {
|
||||||
CC_ISROOM, B_TRUE, NA,
|
CC_ISROOM, B_TRUE, NA,
|
||||||
CC_NONE);
|
CC_NONE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// precalc sin/cos
|
// precalc sin/cos
|
||||||
for (i = 0; i < 360; i++) {
|
for (i = 0; i < 360; i++) {
|
||||||
double rads;
|
double rads;
|
||||||
|
@ -1644,6 +1642,8 @@ int init(void) {
|
||||||
tempglyph.ch = '@';
|
tempglyph.ch = '@';
|
||||||
tempglyph.colour = C_GREY;
|
tempglyph.colour = C_GREY;
|
||||||
|
|
||||||
|
inithiscores();
|
||||||
|
|
||||||
// load npc names
|
// load npc names
|
||||||
loadnpcnames();
|
loadnpcnames();
|
||||||
|
|
||||||
|
|
51
save.c
51
save.c
|
@ -34,6 +34,46 @@ extern long curtime, gamedays, gamesecs;
|
||||||
|
|
||||||
extern enum GAMEMODE gamemode;
|
extern enum GAMEMODE gamemode;
|
||||||
|
|
||||||
|
void inithiscores() {
|
||||||
|
char filename[BUFLEN];
|
||||||
|
int ok = B_FALSE;
|
||||||
|
|
||||||
|
// open database
|
||||||
|
snprintf(filename, BUFLEN, "%s/hiscores.db", DATADIR);
|
||||||
|
if (access(filename, F_OK ) == -1 ) {
|
||||||
|
char *cmd, *errmsg = NULL;
|
||||||
|
int rc;
|
||||||
|
sqlite3 *db;
|
||||||
|
// create a new hiscores db
|
||||||
|
rc = sqlite3_open(filename, &db);
|
||||||
|
if (rc) {
|
||||||
|
msg("failed to open hiscore file %s!\n", filename);
|
||||||
|
dblog("failed to open hiscore file %s!\n", filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
asprintf(&cmd, "create table hiscores(id int primary key, score longint, name varchar, job varchar, killedby varchar);");
|
||||||
|
rc = sqlite3_exec(db, cmd, NULL, NULL, &errmsg);
|
||||||
|
if (rc == SQLITE_OK) {
|
||||||
|
ok = B_TRUE;
|
||||||
|
} else {
|
||||||
|
msg("failed to create hiscore table in %s! %s\n", filename, errmsg);
|
||||||
|
dblog("failed to create hiscore table in %s! %s\n", filename, errmsg);
|
||||||
|
sqlite3_free(errmsg);
|
||||||
|
}
|
||||||
|
free(cmd);
|
||||||
|
sqlite3_close(db);
|
||||||
|
} else {
|
||||||
|
ok = B_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok != B_TRUE) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// returns TRUE if we successfully loaded a save file
|
// returns TRUE if we successfully loaded a save file
|
||||||
int loadall(void) {
|
int loadall(void) {
|
||||||
//int db = B_FALSE;
|
//int db = B_FALSE;
|
||||||
|
@ -1323,9 +1363,9 @@ int showhiscores(lifeform_t *lf, int min, int max) {
|
||||||
snprintf(hilitescoretext, BUFLEN, "%ld",hilitescore);
|
snprintf(hilitescoretext, BUFLEN, "%ld",hilitescore);
|
||||||
rc = sqlite3_exec(db, cmd, showhiscoreline, hilitescoretext, &errmsg);
|
rc = sqlite3_exec(db, cmd, showhiscoreline, hilitescoretext, &errmsg);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
msg("error readin hiscores: '%s'", errmsg);
|
msg("error %d reading hiscores: '%s'", rc, errmsg);
|
||||||
dblog("query was: '%s'", cmd);
|
dblog("query was: '%s'", cmd);
|
||||||
dblog("error readin hiscores: '%s'\n sql command: [%s]", errmsg, cmd);
|
dblog("error %d reading hiscores: '%s'\n sql command: [%s]", rc, errmsg, cmd);
|
||||||
sqlite3_free(errmsg);
|
sqlite3_free(errmsg);
|
||||||
}
|
}
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
@ -1334,6 +1374,7 @@ int showhiscores(lifeform_t *lf, int min, int max) {
|
||||||
return B_FALSE;
|
return B_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// returns player's rank in 'rank'
|
// returns player's rank in 'rank'
|
||||||
int writehiscore(lifeform_t *lf, int *rank) {
|
int writehiscore(lifeform_t *lf, int *rank) {
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
|
@ -1352,12 +1393,14 @@ int writehiscore(lifeform_t *lf, int *rank) {
|
||||||
|
|
||||||
score = calcscore(lf);
|
score = calcscore(lf);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// open database
|
// open database
|
||||||
snprintf(filename, BUFLEN, "%s/hiscores.db", DATADIR);
|
snprintf(filename, BUFLEN, "%s/hiscores.db", DATADIR);
|
||||||
rc = sqlite3_open(filename, &db);
|
rc = sqlite3_open(filename, &db);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
msg("error opening hiscore file '%s'.\n",filename);
|
msg("error %d opening hiscore file '%s'.\n",rc, filename);
|
||||||
dblog("error opening hiscore file '%s'.\n",filename);
|
dblog("error %d opening hiscore file '%s'.\n",rc, filename);
|
||||||
return B_TRUE;
|
return B_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue