// Hyperbolic Rogue // Copyright (C) 2011-2016 Zeno Rogue, see 'hyper.cpp' for details // routines for: initializing/closing, loading/saving, and cheating bool cblind; bool autocheat; int truelotus; int gamecount; time_t timerstart, savetime; bool timerstopped; int savecount; bool showoff = false, doCross = false; bool verless(string v, string cmp) { if(isdigit(v[0]) && isdigit(v[1])) v = "A" + v; if(isdigit(cmp[0]) && isdigit(cmp[1])) cmp = "A" + cmp; return v < cmp; } void welcomeMessage() { if(tactic::trailer) return; #if CAP_TOUR else if(tour::on) return; // displayed by tour #endif else if(princess::challenge) { kills[moVizier] = 1; princess::forceMouse = true; if(yendor::everwon) items[itGreenStone] = 99; addMessage(XLAT("Welcome to %the1 Challenge!", moPrincess)); addMessage(XLAT("The more Hypersian Rugs you collect, the harder it is.", moPrincess)); } /* if(tactic::on && isCrossroads(firstland)) { for(int i=0; igamestart(); cwt.spin = 0; cwt.mirrored = false; cwt.c->land = (geometry && !safety) ? specialland : firstland; chaosAchieved = false; if(firstland == laElementalWall) cwt.c->land = randomElementalLand(); if(tactic::on && (isGravityLand(firstland) || firstland == laOcean) && firstland != laMountain) cwt.c->land = nonbitrunc ? laCrossroads : laCrossroads2; createMov(cwt.c, 0); setdist(cwt.c, BARLEV, NULL); if((tactic::on || yendor::on || peace::on) && isCyclic(firstland)) { anthraxBonus = items[itHolyGrail]; cwt.c->mov[0]->land = firstland; if(firstland == laWhirlpool) cwt.c->mov[0]->wall = waSea; setdist(cwt.c->mov[0], BARLEV-1, cwt.c); if(!sphere && !euclid) { heptagon *h = createAlternateMap(cwt.c, 2, hsA); if(!h) printf("FAIL\n"); } } if(tactic::on && firstland == laPower) { items[itOrbSpeed] = 30; items[itOrbWinter] = 30; items[itOrbFlash] = 30; } if(tactic::on && firstland == laCaribbean) { if(hiitemsMax(itRedGem) >= 25) items[itRedGem] = min(hiitemsMax(itRedGem), 50); if(hiitemsMax(itFernFlower) >= 25) items[itFernFlower] = min(hiitemsMax(itFernFlower), 50); if(hiitemsMax(itWine) >= 25) items[itWine] = min(hiitemsMax(itWine), 50); } if(tactic::on && tactic::trailer) items[treasureType(firstland)] = trailer_cash0; tactic::lasttactic = firstland; yendor::lastchallenge = yendor::challenge; yendor::init(2); clear_euland(specialland); if(euclid && specialland == laPrincessQuest) { cell *c = euclideanAtCreate(pair_to_vec(EPX, EPY)); princess::generating = true; c->land = laPalace; for(int j=BARLEV; j>=0; j--) setdist(c, j, NULL); princess::generating = false; } if(cwt.c->land == laCrossroads2) { cwt.c->landparam = 12; createMov(cwt.c, 0)->landparam = 44; createMov(cwt.c, 0)->land = laCrossroads2; } for(int i=0; i MAXPLAYER) multi::players = 1; multi::whereto[0].d = MD_UNDECIDED; multi::cpid = 0; if(shmup::on) shmup::init(); // extern int sightrange; sightrange = 9; // cwt.c->land = laHell; items[itHell] = 10; for(int i=BARLEV; i>=0; i--) { if(tactic::trailer && cwt.c->land != laClearing) safety = trailer_safety; setdist(cwt.c, i, NULL); if(tactic::trailer) safety = false; currentmap->verify(); } if(doCross) { for(int i=0; iallcells()); i++) setdist(currentmap->allcells()[i], 8, NULL); } if(multi::players > 1 && !shmup::on) for(int i=0; itype; multi::player[i].c = cwt.c->mov[idir]; // special case -- otherwise they land on a wall if(firstland == laCrossroads2 && i == 1) multi::player[1].c = cwt.c; if(firstland == laCrossroads2 && i == 6) multi::player[6].c = createMov(createMov(cwt.c, 0), 3); setdist(cwt.c->mov[idir], 0, cwt.c); multi::player[i].spin = 0; multi::flipped[i] = true; multi::whereto[i].d = MD_UNDECIDED; } if(tactic::on && tactic::trailer) items[treasureType(firstland)] = trailer_cash1; yendor::init(3); peace::simon::init(); multi::revive_queue.clear(); #if CAP_TOUR if(tour::on) tour::presentation(tour::pmRestart); #endif if(multi::players > 1 && !shmup::on) { for(int i=0; i invorb; void addinv(eItem it) { invorb.push_back(it); } void applyBoxOrb(eItem it) { applyBoxI(it, true); invorb.push_back(it); } void list_invorb() { for(eItem it: invorb) { #if CAP_INV if(true) { inv::applyBox(it); continue; } #endif int u = 0; applyBoxNum(u); } invorb.clear(); } void applyBoxM(eMonster m, bool f = false) { fakebox[boxid] = f; boxname[boxid] = minf[m].name; monsbox[boxid] = true; applyBox(kills[m]); } void applyBoxes() { invorb.clear(); eLand lostin = laNone; applyBoxSave((int) timerstart, "time elapsed"); time_t timer = time(NULL); applyBoxSave((int) timer, "date"); applyBoxSave(gold(), "treasure collected"); applyBoxSave(tkills(), "total kills"); applyBoxNum(turncount, "turn count"); applyBoxNum(cellcount, "cells generated"); if(loading) timerstart = time(NULL); for(int i=0; iland, ""); else if(loading) firstland = safetyland = eLand(applyBoxLoad()); else lostin = eLand(savebox[boxid++]); for(int i=itOrbLightning; i<25; i++) applyBoxOrb(eItem(i)); applyBoxI(itRoyalJelly); applyBoxI(itWine); applyBoxI(itSilver); applyBoxI(itEmerald); applyBoxI(itPower); applyBoxOrb(itOrbFire); applyBoxOrb(itOrbInvis); applyBoxOrb(itOrbAether); applyBoxOrb(itOrbPsi); applyBoxM(moBug0); applyBoxM(moBug1); applyBoxM(moBug2); applyBoxM(moVineBeast); applyBoxM(moVineSpirit); applyBoxM(moLancer); applyBoxM(moFlailer); applyBoxM(moEarthElemental); applyBoxM(moDarkTroll); applyBoxM(moWitch); applyBoxM(moWitchFire); applyBoxM(moWitchFlash); applyBoxM(moWitchGhost); applyBoxM(moWitchSpeed); applyBoxM(moEvilGolem); applyBoxM(moWitchWinter); applyBoxI(itHolyGrail); applyBoxI(itGrimoire); applyBoxM(moKnight); applyBoxM(moCultistLeader); applyBoxM(moPirate); applyBoxM(moCShark); applyBoxM(moParrot); applyBoxI(itPirate); applyBoxOrb(itOrbTime); applyBoxM(moHexSnake); applyBoxM(moRedTroll); applyBoxI(itRedGem); applyBoxOrb(itOrbSpace); int geo = geometry; applyBoxNum(geo, ""); geometry = eGeometry(geo); applyBoxBool(hardcore, "hardcore"); applyBoxNum(hardcoreAt, ""); applyBoxBool(shmup::on, "shmup"); if(saving) applyBoxSave(specialland, "euclid land"); else if(loading) specialland = eLand(applyBoxLoad("euclid land")); else fakebox[boxid++] = true; applyBoxI(itCoast); applyBoxI(itWhirlpool); applyBoxI(itBombEgg); applyBoxM(moBomberbird); applyBoxM(moTameBomberbird); applyBoxM(moAlbatross); applyBoxOrb(itOrbFriend); applyBoxOrb(itOrbAir); applyBoxOrb(itOrbWater); applyBoxI(itPalace); applyBoxI(itFjord); applyBoxOrb(itOrbFrog); applyBoxOrb(itOrbDiscord); applyBoxM(moPalace); applyBoxM(moFatGuard); applyBoxM(moSkeleton); applyBoxM(moVizier); applyBoxM(moViking); applyBoxM(moFjordTroll); applyBoxM(moWaterElemental); applyBoxI(itSavedPrincess); applyBoxOrb(itOrbLove); applyBoxM(moPrincess); applyBoxM(moPrincessMoved, false); // live Princess for Safety applyBoxM(moPrincessArmedMoved, false); // live Princess for Safety applyBoxM(moMouse); applyBoxNum(princess::saveArmedHP, ""); applyBoxNum(princess::saveHP, ""); applyBoxI(itIvory); applyBoxI(itElemental); applyBoxI(itZebra); applyBoxI(itFireShard); applyBoxI(itWaterShard); applyBoxI(itAirShard); applyBoxI(itEarthShard); applyBoxM(moAirElemental); applyBoxM(moFireElemental); applyBoxM(moFamiliar); applyBoxM(moGargoyle); applyBoxM(moOrangeDog); applyBoxOrb(itOrbSummon); applyBoxOrb(itOrbMatter); applyBoxM(moForestTroll); applyBoxM(moStormTroll); applyBoxM(moOutlaw); applyBoxM(moMutant); applyBoxM(moMetalBeast); applyBoxM(moMetalBeast2); applyBoxI(itMutant); applyBoxI(itFulgurite); applyBoxI(itBounty); applyBoxOrb(itOrbLuck); applyBoxOrb(itOrbStunning); applyBoxBool(tactic::on, ""); applyBoxNum(elec::lightningfast, ""); // if(savebox[boxid]) printf("lotus = %d (lost = %d)\n", savebox[boxid], isHaunted(lostin)); if(loadingHi && isHaunted(lostin)) boxid++; else applyBoxI(itLotus); applyBoxOrb(itOrbUndeath); applyBoxI(itWindstone); applyBoxOrb(itOrbEmpathy); applyBoxM(moWindCrow); applyBoxOrb(itMutant2); applyBoxOrb(itOrbFreedom); applyBoxM(moRedFox); applyBoxBool(survivalist); if(loadingHi) applyBoxI(itLotus); else applyBoxNum(truelotus, "lotus/escape"); applyBoxBool(nonbitrunc, "heptagons only"); applyBoxI(itRose); applyBoxOrb(itOrbBeauty); applyBoxI(itCoral); applyBoxOrb(itOrb37); applyBoxOrb(itOrbEnergy); applyBoxM(moRatling); applyBoxM(moFalsePrincess); applyBoxM(moRoseLady); applyBoxM(moRoseBeauty); applyBoxBool(chaosmode, "Chaos mode"); applyBoxNum(multi::players, "shmup players"); if(multi::players < 1 || multi::players > MAXPLAYER) multi::players = 1; applyBoxM(moRatlingAvenger); // printf("applybox %d\n", shmup::players); applyBoxI(itApple); applyBoxM(moSparrowhawk); applyBoxM(moResearcher); applyBoxI(itDragon); applyBoxM(moDragonHead); applyBoxOrb(itOrbDomination); applyBoxI(itBabyTortoise); applyBoxNum(tortoise::seekbits, ""); applyBoxM(moTortoise); applyBoxOrb(itOrbShell); applyBoxNum(safetyseed); // (+18) for(int i=0; i<6; i++) { applyBoxNum(multi::treasures[i]); applyBoxNum(multi::kills[i]); applyBoxNum(multi::deaths[i]); } // (+8) applyBoxM(moDragonTail); applyBoxI(itKraken); applyBoxM(moKrakenH); applyBoxM(moKrakenT); applyBoxOrb(itOrbSword); applyBoxI(itBarrow); applyBoxM(moDraugr); applyBoxOrb(itOrbSword2); applyBoxI(itTrollEgg); applyBoxOrb(itOrbStone); bool sph; sph = false; applyBoxBool(sph, "sphere"); if(sph) geometry = gSphere; sph = false; applyBoxBool(sph, "elliptic"); if(sph) geometry = gElliptic; applyBox(princess::reviveAt); applyBoxI(itDodeca); applyBoxI(itAmethyst); applyBoxI(itSlime); applyBoxOrb(itOrbNature); applyBoxOrb(itOrbDash); addinv(itOrbRecall); applyBoxM(moBat); applyBoxM(moReptile); applyBoxM(moFriendlyIvy); applyBoxI(itGreenGrass); applyBoxI(itBull); applyBoxOrb(itOrbHorns); applyBoxOrb(itOrbBull); applyBoxM(moSleepBull); applyBoxM(moRagingBull); applyBoxM(moHerdBull); applyBoxM(moButterfly); applyBoxM(moGadfly); // 10.0: applyBoxNum(hinttoshow); // 258 addinv(itOrbMirror); addinv(itGreenStone); list_invorb(); applyBoxBool(inv::on, "inventory"); // 306 #if CAP_INV applyBoxNum(inv::rseed); #else { int u; applyBoxNum(u); } #endif // 10.1: applyBoxI(itLavaLily); applyBoxI(itHunting); applyBoxI(itBlizzard); applyBoxI(itTerra); applyBoxOrb(itOrbSide1); applyBoxOrb(itOrbSide2); applyBoxOrb(itOrbSide3); applyBoxOrb(itOrbLava); applyBoxOrb(itOrbMorph); applyBoxM(moHunterDog); applyBoxM(moIceGolem); applyBoxM(moVoidBeast); applyBoxM(moJiangshi); applyBoxM(moTerraWarrior); applyBoxM(moSalamander); applyBoxM(moLavaWolf); applyBoxOrb(itOrbSlaying); applyBoxOrb(itOrbMagnetism); applyBoxOrb(itOrbPhasing); applyBoxI(itDock); applyBoxI(itGlowCrystal); applyBoxI(itMagnet); applyBoxI(itRuins); applyBoxI(itSwitch); applyBoxM(moNorthPole); applyBoxM(moSouthPole); applyBoxM(moSwitch1); applyBoxM(moSwitch2); applyBoxM(moAltDemon); applyBoxM(moHexDemon); applyBoxM(moPair); applyBoxM(moCrusher); applyBoxM(moMonk); if(POSSCORE != boxid) printf("ERROR: %d boxes\n", boxid); } void saveBox() { boxid = 0; saving = true; applyBoxes(); saving = false; } void loadBox() { // have boxid boxid = 0; loading = true; applyBoxes(); loading = false; } void loadBoxHigh() { dynamicval sp1(multi::players, savebox[197]); dynamicval sp2(geometry, (eGeometry) savebox[116]); dynamicval sp3(shmup::on, savebox[119]); dynamicval sp4(chaosmode, savebox[196]); dynamicval sp5(nonbitrunc, savebox[186]); if(savebox[238]) geometry = gSphere; if(savebox[239]) geometry = gElliptic; if(multi::players < 1 || multi::players > MAXPLAYER) multi::players = 1; if(shmup::on && multi::players == 1) ; else { // have boxid boxid = 0; loadingHi = true; applyBoxes(); loadingHi = false; } } // certify that saves and achievements were received // in an official version of HyperRogue #if CAP_CERTIFY #include "private/certify.cpp" #else namespace anticheat { bool tampered; void save(FILE *f) {} bool load(FILE *f, score& sc, const string& ver) {return true; } int certify(const string& s, int a, int b, int c, int d=0) { return d; } int check(int cv, const string& ver, const string& s, int a, int b, int c, int d=0) { return cv==d; } void nextid(int& tid, const string& ver, int cert) { tid++; } }; #endif long long saveposition = -1; #include #include void remove_emergency_save() { #if !ISWINDOWS if(saveposition >= 0) { /* if(!timerghost) addMessage(XLAT("Emergency truncate to ") + its(saveposition)); */ if(truncate(scorefile, saveposition)) {} saveposition = -1; } #endif } void saveStats(bool emergency = false) { DEBB(DF_INIT, (debugfile,"saveStats [%s]\n", scorefile)); if(autocheat) return; #if CAP_TOUR if(tour::on) return; #endif if(randomPatternsMode) return; if(peace::on) return; if(!gold()) return; remove_emergency_save(); FILE *f = fopen(scorefile, "at"); if(!f) { // printf("Could not open the score file '%s'!\n", scorefile); addMessage(XLAT("Could not open the score file: ") + scorefile); return; } if(emergency) { saveposition = ftell(f); // if(!timerghost) addMessage(XLAT("Emergency save at ") + its(saveposition)); } if(showoff) { fclose(f); return; } time_t timer; timer = time(NULL); char sbuf[128]; strftime(sbuf, 128, "%c", localtime(&timerstart)); char buf[128]; strftime(buf, 128, "%c", localtime(&timer)); if((tactic::on || yendor::on) && !items[itOrbSafety] && !cheater) { int t = (int) (timer - timerstart); int xcode = modecode(); if(tactic::on) { int score = items[treasureType(tactic::lasttactic)]; if(score) { int c = anticheat::certify(dnameof(tactic::lasttactic), turncount, t, (int) timerstart, xcode*999 + tactic::id + 256 * score); fprintf(f, "TACTICS %s %d %d %d %d %d %d %d %d date: %s\n", VER, tactic::id, tactic::lasttactic, score, turncount, t, int(timerstart), c, xcode, buf); tactic::record(tactic::lasttactic, score); anticheat::nextid(tactic::id, VER, c); } } if(yendor::on) fprintf(f, "YENDOR %s %d %d %d %d %d %d %d %d date: %s\n", VER, yendor::lastchallenge, items[itOrbYendor], yendor::won, turncount, t, int(timerstart), anticheat::certify(yendor::won ? "WON" : "LOST", turncount, t, (int) timerstart, xcode*999 + yendor::lastchallenge + 256 * items[itOrbYendor]), xcode, buf); fclose(f); return; } fprintf(f, "HyperRogue: game statistics (version " VER ")\n"); if(cheater) fprintf(f, "CHEATER! (cheated %d times)\n", cheater); if(true) { fprintf(f, VER); if(!shmup::on) items[itOrbLife] = countMyGolems(moGolem); if(!shmup::on) items[itOrbFriend] = countMyGolems(moTameBomberbird); if(!shmup::on) kills[moPrincessMoved] = countMyGolems(moPrincess); if(!shmup::on) kills[moPrincessArmedMoved] = countMyGolems(moPrincessArmed); if(!shmup::on) princess::saveHP = countMyGolemsHP(moPrincess); if(!shmup::on) princess::saveArmedHP = countMyGolemsHP(moPrincessArmed); saveBox(); for(int i=0; i 1) fprintf(f, "Multi-player (%d players)\n", multi::players); fprintf(f, "Number of cells explored, by distance from the player:\n"); {for(int i=0; i<10; i++) fprintf(f, " %d", explore[i]);} fprintf(f, "\n"); /*for(int j=0; j= 0 && savebox[258] < coh) { hints[savebox[258]].last = savebox[1]; } loadBoxHigh(); break; } } } if(buf[0] == 'A' && buf[1] == 'C' && buf[2] == 'H') { char buf1[80], buf2[80]; sscanf(buf, "%70s%70s", buf1, buf2); if(buf2 == string("PRINCESS1")) princess::everSaved = true; if(buf2 == string("YENDOR2")) yendor::everwon = true; if(buf2 == string("CR4")) chaosUnlocked = true; } if(buf[0] == 'T' && buf[1] == 'A' && buf[2] == 'C') { ok = false; char buf1[80], ver[10]; int tid, land, score, tc, t, ts, cert; int xc = -1; sscanf(buf, "%70s%10s%d%d%d%d%d%d%d%d", buf1, ver, &tid, &land, &score, &tc, &t, &ts, &cert, &xc); eLand l2 = eLand(land); if(land == laMirror && verless(ver, "10.0")) l2 = laMirrorOld; if(xc == -1) for(xc=0; xc<32768; xc++) if(anticheat::check(cert, ver, dnameof(l2), tc, t, ts, xc*999+unsigned(tid) + 256 * score)) break; if(tid == tactic::id && (anticheat::check(cert, ver, dnameof(l2), tc, t, ts, xc*unsigned(999)+ unsigned(tid) + 256 * score))) { if(score != 0 && !(land == laOcean && verless(ver, "8.0f")) ) tactic::record(l2, score, xc); anticheat::nextid(tactic::id, ver, cert); } } if(buf[0] == 'Y' && buf[1] == 'E' && buf[2] == 'N') { char buf1[80], ver[10]; int cid, oy, won, tc, t, ts, cert=0, xc = -1; sscanf(buf, "%70s%10s%d%d%d%d%d%d%d%d", buf1, ver, &cid, &oy, &won, &tc, &t, &ts, &cert, &xc); if(xc == -1) for(xc=0; xc<32768; xc++) if(anticheat::check(cert, ver, won ? "WON" : "LOST", tc, t, ts, xc*999 + cid + 256 * oy)) break; if(won) if(anticheat::check(cert, ver, won ? "WON" : "LOST", tc, t, ts, xc*999 + cid + 256 * oy)) { if(xc == 19 && cid == 25) xc = 0; if(cid > 0 && cid < YENDORLEVELS) if(!(verless(ver, "8.0f") && oy > 1 && cid == 15)) if(!(verless(ver, "9.3b") && oy > 1 && (cid == 27 || cid == 28))) { yendor::bestscore[xc][cid] = max(yendor::bestscore[xc][cid], oy); } } } } fclose(f); if(ok && sc.box[65 + 4 + itOrbSafety - itOrbLightning]) { anticheat::tampered = tamper; // printf("box = %d (%d)\n", sc.box[65 + 4 + itOrbSafety - itOrbLightning], boxid); // printf("boxid = %d\n", boxid); for(int i=0; i gd; bool pushed() { return size(gd); } void push() { if(geometry) { printf("ERROR: push implemented only in non-hyperbolic geometry\n"); exit(1); } gamedata gdn; gdn.hmap = currentmap; gdn.cwt = cwt; gdn.viewctr = viewctr; gdn.View = View; gdn.geometry = geometry; gdn.shmup = shmup::on; gdn.hepta = nonbitrunc; gd.push_back(gdn); } void pop() { gamedata& gdn = gd[size(gd)-1]; currentmap = gdn.hmap; cwt = gdn.cwt; viewctr = gdn.viewctr; View = gdn.View; geometry = gdn.geometry; nonbitrunc = gdn.hepta; if(shmup::on) shmup::clearMonsters(); shmup::on = gdn.shmup; resetGeometry(); gd.pop_back(); bfs(); } }; void popGame() { if(gamestack::pushed()) { gamestack::pop(); } } void popAllGames() { while(gamestack::pushed()) { gamestack::pop(); } } void restartGame(char switchWhat, bool push, bool keep_screens) { if(!keep_screens) popScreenAll(); DEBB(DF_INIT, (debugfile,"restartGame\n")); if(push) gamestack::push(); else { popAllGames(); achievement_final(true); #if CAP_SAVE saveStats(); #endif for(int i=0; i