diff --git a/io.c b/io.c index 592aa1d..b1c8b0a 100755 --- a/io.c +++ b/io.c @@ -15382,7 +15382,11 @@ void tombstone(lifeform_t *lf) { 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); mvwprintw(mainwin, y, 0, HISCOREFORMAT, "Pos", "Score", "Name", "Job"); wprintw(mainwin, "Method of death"); y++; diff --git a/nexus.c b/nexus.c index 4d63ebd..160afaf 100755 --- a/nexus.c +++ b/nexus.c @@ -1627,8 +1627,6 @@ int init(void) { CC_ISROOM, B_TRUE, NA, CC_NONE); - - // precalc sin/cos for (i = 0; i < 360; i++) { double rads; @@ -1644,6 +1642,8 @@ int init(void) { tempglyph.ch = '@'; tempglyph.colour = C_GREY; + inithiscores(); + // load npc names loadnpcnames(); diff --git a/save.c b/save.c index 9ed283f..0f77ad6 100755 --- a/save.c +++ b/save.c @@ -34,6 +34,46 @@ extern long curtime, gamedays, gamesecs; 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 int loadall(void) { //int db = B_FALSE; @@ -1323,9 +1363,9 @@ int showhiscores(lifeform_t *lf, int min, int max) { snprintf(hilitescoretext, BUFLEN, "%ld",hilitescore); rc = sqlite3_exec(db, cmd, showhiscoreline, hilitescoretext, &errmsg); if (rc != SQLITE_OK) { - msg("error readin hiscores: '%s'", errmsg); + msg("error %d reading hiscores: '%s'", rc, errmsg); 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); } free(cmd); @@ -1334,6 +1374,7 @@ int showhiscores(lifeform_t *lf, int min, int max) { return B_FALSE; } + // returns player's rank in 'rank' int writehiscore(lifeform_t *lf, int *rank) { sqlite3 *db; @@ -1352,12 +1393,14 @@ int writehiscore(lifeform_t *lf, int *rank) { score = calcscore(lf); + + // open database snprintf(filename, BUFLEN, "%s/hiscores.db", DATADIR); rc = sqlite3_open(filename, &db); if (rc) { - msg("error opening hiscore file '%s'.\n",filename); - dblog("error opening hiscore file '%s'.\n",filename); + msg("error %d opening hiscore file '%s'.\n",rc, filename); + dblog("error %d opening hiscore file '%s'.\n",rc, filename); return B_TRUE; } diff --git a/save.h b/save.h index 342e408..a252649 100755 --- a/save.h +++ b/save.h @@ -1,5 +1,6 @@ #include "defs.h" +void inithiscores(); int loadall(void); int loadflagpile(FILE *f, flagpile_t *fp); int loadknowledge(FILE *f);