mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-10-26 03:17:39 +00:00
better mode handling
This commit is contained in:
107
scores.cpp
107
scores.cpp
@@ -8,7 +8,6 @@ score *currentgame;
|
||||
int scoresort = 2;
|
||||
int scoredisplay = 1;
|
||||
int scorefrom = 0;
|
||||
int scoremode = 0;
|
||||
bool scorerev = false;
|
||||
|
||||
bool scorecompare(const score& s1, const score &s2) {
|
||||
@@ -19,16 +18,60 @@ bool fakescore() {
|
||||
return fakebox[scoredisplay];
|
||||
}
|
||||
|
||||
string csub(const string& str, int q) {
|
||||
int i = 0;
|
||||
for(int j=0; j<q && i<size(str); j++) getnext(str.c_str(), i);
|
||||
return str.substr(0, i);
|
||||
}
|
||||
|
||||
int colwidth() {
|
||||
if(scoredisplay == 0) return 5;
|
||||
if(scoredisplay == 1) return 16;
|
||||
if(scoredisplay == 5) return 8;
|
||||
if(scoredisplay == POSSCORE) return 8;
|
||||
return 4;
|
||||
}
|
||||
|
||||
bool isHardcore(score *S) {
|
||||
return S->box[117] && S->box[118] < PUREHARDCORE_LEVEL;
|
||||
}
|
||||
|
||||
int modediff(score *S) {
|
||||
int diff = 0;
|
||||
eGeometry g = (eGeometry) S->box[116];
|
||||
if(S->box[238]) g = gSphere;
|
||||
if(S->box[239]) g = gElliptic;
|
||||
if(max(S->box[197], 1) != multi::players) diff += 8;
|
||||
if(S->box[186] != purehepta) diff += 16;
|
||||
if(S->box[196] != chaosmode) diff += 32;
|
||||
if(S->box[119] != shmup::on) diff += 64;
|
||||
if(pureHardcore() && !isHardcore(S)) diff += 128;
|
||||
if(g != gNormal && S->box[120] != euclidland)
|
||||
diff += 256;
|
||||
if(g != geometry) {
|
||||
diff += 512;
|
||||
}
|
||||
return -diff;
|
||||
}
|
||||
|
||||
string modedesc(score *S) {
|
||||
eGeometry g = (eGeometry) S->box[116];
|
||||
if(S->box[238]) g = gSphere;
|
||||
if(S->box[239]) g = gElliptic;
|
||||
string s = geometrynames_short[g];
|
||||
if(g != gNormal) s += " " + csub(XLATT1((eLand) S->box[120]), 3);
|
||||
if(S->box[186]) s += "/7";
|
||||
if(S->box[196]) s += "/C";
|
||||
if(S->box[119]) s += "/s";
|
||||
if(S->box[197] > 1) s += "/P" + its(S->box[197]);
|
||||
if(isHardcore(S)) s += "/h";
|
||||
return s;
|
||||
}
|
||||
|
||||
string displayfor(score* S, bool shorten = false) {
|
||||
// printf("S=%p, scoredisplay = %d\n", S, scoredisplay);
|
||||
if(S == NULL) {
|
||||
if(scoredisplay == POSSCORE) return "mode";
|
||||
string str = XLATN(boxname[scoredisplay]);
|
||||
if(!shorten) return str;
|
||||
if(scoredisplay == 0 || scoredisplay == 65) return XLAT("time");
|
||||
@@ -39,9 +82,7 @@ string displayfor(score* S, bool shorten = false) {
|
||||
if(scoredisplay == 67) return XLAT("cheats");
|
||||
if(scoredisplay == 66) return XLAT("saves");
|
||||
if(scoredisplay == 197) return XLAT("players");
|
||||
int i = 0;
|
||||
for(int j=0; j<5; j++) if(i < size(str)) getnext(str.c_str(), i);
|
||||
return str.substr(0, i);
|
||||
return csub(str, 5);
|
||||
}
|
||||
if(scoredisplay == 0 || scoredisplay == 65) {
|
||||
char buf[20];
|
||||
@@ -52,6 +93,7 @@ string displayfor(score* S, bool shorten = false) {
|
||||
snprintf(buf, 20, "%d:%02d", t/60, t%60);
|
||||
return buf;
|
||||
}
|
||||
if(scoredisplay == POSSCORE) return modedesc(S);
|
||||
if(scoredisplay == 1) {
|
||||
time_t tim = S->box[1];
|
||||
char buf[128]; strftime(buf, 128, "%c", localtime(&tim));
|
||||
@@ -71,11 +113,6 @@ void sortScores() {
|
||||
}
|
||||
}
|
||||
|
||||
void shiftScoreDisplay(int delta) {
|
||||
scoredisplay = (scoredisplay + POSSCORE + delta) % POSSCORE, scorerev = false;
|
||||
if(fakescore()) shiftScoreDisplay(delta);
|
||||
}
|
||||
|
||||
int curcol;
|
||||
|
||||
vector<int> columns;
|
||||
@@ -90,7 +127,7 @@ void showPickScores() {
|
||||
|
||||
scorerev = false;
|
||||
|
||||
for(int i=0; i<POSSCORE; i++) {
|
||||
for(int i=0; i<=POSSCORE; i++) {
|
||||
scoredisplay = i;
|
||||
if(!fakescore()) {
|
||||
string s = displayfor(NULL);
|
||||
@@ -126,7 +163,7 @@ void showPickScores() {
|
||||
if(uni >= '1' && uni <= '9') uni = uni + 1000 - '1';
|
||||
else if(uni >= 1000 && uni < 1000 + size(pickscore_options)) {
|
||||
scoredisplay = pickscore_options[uni - 1000].second;
|
||||
for(int i=0; i<POSSCORE; i++)
|
||||
for(int i=0; i<=POSSCORE; i++)
|
||||
if(columns[i] == scoredisplay) swap(columns[i], columns[curcol]);
|
||||
popScreen();
|
||||
}
|
||||
@@ -137,7 +174,10 @@ void showPickScores() {
|
||||
|
||||
void show() {
|
||||
|
||||
if(columns.size() == 0) for(int i=0; i<POSSCORE; i++) columns.push_back(i);
|
||||
if(columns.size() == 0) {
|
||||
columns.push_back(POSSCORE);
|
||||
for(int i=0; i<POSSCORE; i++) columns.push_back(i);
|
||||
}
|
||||
int y = vid.fsize * 5/2;
|
||||
int bx = vid.fsize;
|
||||
getcstat = 0;
|
||||
@@ -146,7 +186,7 @@ void show() {
|
||||
displaystr(bx*8, vid.fsize, 0, vid.fsize, XLAT("ver"), forecolor, 16);
|
||||
|
||||
int at = 9;
|
||||
for(int i=0; i<POSSCORE; i++) {
|
||||
for(int i=0; i<=POSSCORE; i++) {
|
||||
scoredisplay = columns[i];
|
||||
if(bx*at > vid.xres) break;
|
||||
if(displaystr(bx*at, vid.fsize, 0, vid.fsize, displayfor(NULL, true), i == curcol ? 0xFFD500 : forecolor, 0))
|
||||
@@ -163,17 +203,6 @@ void show() {
|
||||
|
||||
score& S(scores[id]);
|
||||
|
||||
bool wrongtype = false;
|
||||
|
||||
wrongtype |= (euclid && (!S.box[116] || S.box[120] != euclidland));
|
||||
wrongtype |= (!euclid && S.box[116]);
|
||||
|
||||
wrongtype |= (scoremode == 1 && !S.box[119]);
|
||||
wrongtype |= (scoremode != 1 && S.box[119]);
|
||||
wrongtype |= (scoremode == 2 && (!S.box[117] || S.box[118] >= PUREHARDCORE_LEVEL));
|
||||
|
||||
if(wrongtype) { id++; continue; }
|
||||
|
||||
if(omit) { omit--; rank++; id++; continue; }
|
||||
|
||||
bool cur = S.box[MAXBOX-1];
|
||||
@@ -191,7 +220,7 @@ void show() {
|
||||
displaystr(bx*8, y, 0, vid.fsize, S.ver, col, 16);
|
||||
|
||||
int at = 9;
|
||||
for(int i=0; i<POSSCORE; i++) {
|
||||
for(int i=0; i<=POSSCORE; i++) {
|
||||
scoredisplay = columns[i];
|
||||
if(bx*at > vid.xres) break;
|
||||
at += colwidth();
|
||||
@@ -205,27 +234,18 @@ void show() {
|
||||
int i0 = vid.yres - vid.fsize;
|
||||
int xr = vid.xres / 80;
|
||||
|
||||
string modes =
|
||||
scoremode == 0 ? XLAT(", m - mode: normal") :
|
||||
scoremode == 1 ? XLAT(", m - mode: shoot'em up") :
|
||||
scoremode == 2 ? XLAT(", m - mode: hardcore only") :
|
||||
"?";
|
||||
|
||||
if(euclid) modes += XLAT(" (E:%1)", euclidland);
|
||||
|
||||
displayButton(xr*10, i0, IFM("s - ") + XLAT("sort"), 's', 8);
|
||||
displayButton(xr*25, i0, IFM("t - ") + XLAT("choose"), 't', 8);
|
||||
displayButton(xr*40, i0, IFM("0 - ") + XLAT("play"), '0', 8);
|
||||
displayButton(xr*65, i0, IFM("m - ") + modes.substr(6), 'm', 8);
|
||||
displayButton(xr*30, i0, IFM("t - ") + XLAT("choose"), 't', 8);
|
||||
displayButton(xr*50, i0, IFM("0 - ") + XLAT("play"), '0', 8);
|
||||
|
||||
keyhandler = [] (int sym, int uni) {
|
||||
if(sym == SDLK_LEFT || sym == SDLK_KP4 || sym == 'h' || sym == 'a') {
|
||||
if(curcol > 0) curcol--;
|
||||
}
|
||||
else if(sym == SDLK_RIGHT || sym == SDLK_KP6 || sym == 'l' || sym == 'd') {
|
||||
if(curcol < POSSCORE-1) curcol++;
|
||||
if(curcol < POSSCORE) curcol++;
|
||||
}
|
||||
else if(sym >= 1000 && sym < 1000+POSSCORE)
|
||||
else if(sym >= 1000 && sym <= 1000+POSSCORE)
|
||||
curcol = sym - 1000;
|
||||
else if(sym == 't') { mapeditor::infix = ""; pushScreen(showPickScores); }
|
||||
else if(sym == SDLK_UP || sym == 'k' || sym == 'w')
|
||||
@@ -237,7 +257,6 @@ void show() {
|
||||
else if(sym == PSEUDOKEY_WHEELDOWN)
|
||||
scorefrom++;
|
||||
else if(sym == 's') sortScores();
|
||||
else if(sym == 'm') { scoremode++; scoremode %= 3; }
|
||||
else if(doexiton(sym, uni)) popScreen();
|
||||
|
||||
static int scoredragy;
|
||||
@@ -296,6 +315,7 @@ void load() {
|
||||
sc.box[0] = sc.box[1] - sc.box[0]; // could not save then
|
||||
|
||||
if(sc.box[2] == 0) continue; // do not list zero scores
|
||||
sc.box[POSSCORE] = modediff(&sc);
|
||||
|
||||
if(ok && boxid > 20) scores.push_back(sc);
|
||||
}
|
||||
@@ -304,6 +324,7 @@ void load() {
|
||||
saveBox();
|
||||
score sc;
|
||||
for(int i=0; i<POSSCORE; i++) sc.box[i] = savebox[i];
|
||||
sc.box[POSSCORE] = 0;
|
||||
sc.box[MAXBOX-1] = 1; sc.ver = "NOW";
|
||||
scores.push_back(sc);
|
||||
|
||||
@@ -312,12 +333,10 @@ void load() {
|
||||
// addMessage(its(size(scores))+" games have been recorded in "+scorefile);
|
||||
pushScreen(show);
|
||||
boxid = 0; applyBoxes();
|
||||
scoresort = 2; reverse(scores.begin(), scores.end());
|
||||
scoremode = 0;
|
||||
if(shmup::on) scoremode = 1;
|
||||
else if(hardcore) scoremode = 2;
|
||||
reverse(scores.begin(), scores.end());
|
||||
scorefrom = 0;
|
||||
stable_sort(scores.begin(), scores.end(), scorecompare);
|
||||
scoresort = 2; stable_sort(scores.begin(), scores.end(), scorecompare);
|
||||
scoresort = POSSCORE; stable_sort(scores.begin(), scores.end(), scorecompare);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user