1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-24 21:37:18 +00:00
hyperrogue/system.cpp

1326 lines
35 KiB
C++
Raw Normal View History

2016-08-26 09:58:03 +00:00
// Hyperbolic Rogue
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
2016-08-26 09:58:03 +00:00
// routines for: initializing/closing, loading/saving, and cheating
namespace hr {
bool need_reset_geometry = true;
bool game_active;
2016-08-26 09:58:03 +00:00
bool cblind;
bool autocheat;
2018-04-21 15:57:30 +00:00
bool canvas_invisible;
2016-08-26 09:58:03 +00:00
int truelotus;
2017-03-23 10:53:57 +00:00
int gamecount;
2016-08-26 09:58:03 +00:00
time_t timerstart, savetime;
bool timerstopped;
int savecount;
bool showoff = false, doCross = false;
2016-08-26 09:58:03 +00:00
2018-03-29 22:20:33 +00:00
eLand top_land;
2017-07-22 23:33:27 +00:00
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;
2017-07-16 21:00:55 +00:00
return v < cmp;
}
2018-04-15 11:19:03 +00:00
bool do_use_special_land() {
return
!safety &&
2018-07-17 13:00:35 +00:00
(peace::on || tactic::on || geometry || gp::on || irr::on || randomPatternsMode || yendor::on);
2018-04-15 11:19:03 +00:00
}
hookset<bool()> *hooks_welcome_message;
2017-08-06 12:50:16 +00:00
void welcomeMessage() {
if(callhandlers(false, hooks_welcome_message)) return;
else if(tactic::trailer) return;
2017-08-06 12:50:16 +00:00
#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));
}
2017-08-06 12:50:16 +00:00
else if(randomPatternsMode)
addMessage(XLAT("Welcome to the Random Pattern mode!"));
else if(tactic::on)
addMessage(XLAT("You are playing %the1 in the Pure Tactics mode.", firstland));
else if(yendor::on)
addMessage(XLAT("Welcome to the Yendor Challenge %1!", its(yendor::challenge)));
else if(peace::on) ; // no welcome message
else if(shmup::on) ; // welcome message given elsewhere
else if(euclid)
addMessage(XLAT("Welcome to the Euclidean mode!"));
else if(sphere && specialland == laHalloween)
addMessage(XLAT("Welcome to Halloween!"));
else if(elliptic)
addMessage(XLAT("Good luck in the elliptic plane!"));
else if(sphere)
addMessage(XLAT("Welcome to Spherogue!"));
else
addMessage(XLAT("Welcome to HyperRogue!"));
2017-08-06 12:50:16 +00:00
2018-05-15 21:26:04 +00:00
if(do_use_special_land() || firstland != laIce) if(!daily::on) {
2018-04-15 11:19:03 +00:00
auto lv = land_validity(specialland);
if(lv.flags & lv::display_error_message)
addMessage(XLAT(lv.msg));
}
2017-08-06 12:50:16 +00:00
#if ISMAC
addMessage(XLAT("Press F1 or right-shift-click things for help."));
#elif !ISMOBILE
addMessage(XLAT("Press F1 or right-click things for help."));
#endif
}
2017-10-30 21:47:18 +00:00
int trailer_cash0 = 5;
int trailer_cash1 = 15;
bool trailer_safety = true;
hookset<void()> *hooks_initgame;
2016-08-26 09:58:03 +00:00
// initialize the game
void initgame() {
DEBB(DF_INIT, (debugfile,"initGame\n"));
callhooks(hooks_initgame);
2016-08-26 09:58:03 +00:00
yendor::init(1);
if(safety && safetyseed) {
shrand(safetyseed);
firstland = safetyland;
}
2018-04-15 11:19:03 +00:00
bool use_special_land = do_use_special_land();
if(use_special_land) firstland = specialland;
2016-08-26 09:58:03 +00:00
if(firstland == laNone || firstland == laBarrier)
firstland = laCrossroads;
2017-03-23 10:53:57 +00:00
if(firstland == laCrossroads5 && !tactic::on) firstland = laCrossroads2; // could not fit!
2016-08-26 09:58:03 +00:00
if(firstland == laOceanWall) firstland = laOcean;
if(firstland == laHauntedWall) firstland = laGraveyard;
2017-10-13 19:28:14 +00:00
if(firstland == laMercuryRiver) firstland = laTerracotta;
2017-03-23 10:53:57 +00:00
if(firstland == laMountain && !tactic::on) firstland = laJungle;
2018-04-15 11:19:13 +00:00
if(firstland == laPrincessQuest) firstland = laPalace;
2018-04-11 21:37:28 +00:00
if((isGravityLand(firstland) && !isCyclic(firstland)) || (firstland == laOcean && !safety))
firstland = weirdhyperbolic ? laCrossroads4 : laCrossroads;
2016-08-26 09:58:03 +00:00
cwt.c = currentmap->gamestart(); cwt.spin = 0; cwt.mirrored = false;
cwt.c->land = firstland;
2016-08-26 09:58:03 +00:00
chaosAchieved = false;
if(firstland == laElementalWall) cwt.c->land = randomElementalLand();
createMov(cwt.c, 0);
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
setdist(cwt.c, BARLEV, NULL);
2017-07-04 13:38:33 +00:00
if((tactic::on || yendor::on || peace::on) && isCyclic(firstland)) {
2016-08-26 09:58:03 +00:00
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);
2017-10-30 21:47:18 +00:00
if(!sphere && !euclid) {
heptagon *h = createAlternateMap(cwt.c, 2, hsA);
if(!h) printf("FAIL\n");
}
2016-08-26 09:58:03 +00:00
}
if(tactic::on && firstland == laPower) {
items[itOrbSpeed] = 30;
items[itOrbWinter] = 30;
items[itOrbFlash] = 30;
}
if(tactic::on && firstland == laCaribbean) {
2017-03-23 10:53:57 +00:00
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);
2016-08-26 09:58:03 +00:00
}
if(tactic::on && tactic::trailer)
2017-10-30 21:47:18 +00:00
items[treasureType(firstland)] = trailer_cash0;
2016-08-26 09:58:03 +00:00
yendor::lastchallenge = yendor::challenge;
yendor::init(2);
clear_euland(specialland);
2017-08-06 12:50:16 +00:00
if(euclid && specialland == laPrincessQuest) {
cell *c = euclideanAtCreate(pair_to_vec(EPX, EPY));
2016-08-26 09:58:03 +00:00
princess::generating = true;
c->land = laPalace;
setdist(c, 7 - getDistLimit() - genrange_bonus, NULL);
2016-08-26 09:58:03 +00:00
princess::generating = false;
}
if(cwt.c->land == laCrossroads2) {
cwt.c->landparam = 12;
createMov(cwt.c, 0)->landparam = 44;
2017-03-23 10:53:57 +00:00
createMov(cwt.c, 0)->land = laCrossroads2;
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++) sword::angle[i] = 11;
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(!safety) multi::players = vid.scfg.players;
if(multi::players < 1 || multi::players > MAXPLAYER)
multi::players = 1;
multi::whereto[0].d = MD_UNDECIDED;
multi::cpid = 0;
if(shmup::on) shmup::init();
2018-04-30 22:21:18 +00:00
#if CAP_DAILY
daily::split();
#endif
2016-08-26 09:58:03 +00:00
// extern int sightrange; sightrange = 9;
// cwt.c->land = laHell; items[itHell] = 10;
for(int i=BARLEV; i>=7 - getDistLimit() - genrange_bonus; i--) {
2017-10-30 21:47:18 +00:00
if(tactic::trailer && cwt.c->land != laClearing) safety = trailer_safety;
2016-08-26 09:58:03 +00:00
setdist(cwt.c, i, NULL);
if(tactic::trailer) safety = false;
2018-03-29 22:20:33 +00:00
currentmap->verify();
2017-03-23 10:53:57 +00:00
}
if(doCross) {
for(int i=0; i<ittypes; i++) if(itemclass(eItem(i)) == IC_TREASURE) items[i] = 50;
for(int i=0; i<motypes; i++) kills[i] = 30;
items[itSavedPrincess] = 0;
kills[moPrincessMoved] = 0;
kills[moPrincessArmedMoved] = 0;
kills[moPlayer] = 0;
}
2017-03-23 10:53:57 +00:00
if(quotient && generateAll(firstland)) {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(currentmap->allcells()); i++)
setdist(currentmap->allcells()[i], 8, NULL);
2017-03-23 10:53:57 +00:00
}
if(multi::players > 1 && !shmup::on) for(int i=0; i<numplayers(); i++) {
int idir = (3 * i) % cwt.c->type;
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], 7 - getDistLimit() - genrange_bonus, cwt.c);
2017-03-23 10:53:57 +00:00
multi::player[i].spin = 0;
multi::flipped[i] = true;
multi::whereto[i].d = MD_UNDECIDED;
2016-08-26 09:58:03 +00:00
}
if(tactic::on && tactic::trailer)
2017-10-30 21:47:18 +00:00
items[treasureType(firstland)] = trailer_cash1;
2016-08-26 09:58:03 +00:00
yendor::init(3);
2017-07-04 13:38:33 +00:00
peace::simon::init();
2017-03-23 10:53:57 +00:00
multi::revive_queue.clear();
2017-07-22 23:33:27 +00:00
#if CAP_TOUR
if(tour::on) tour::presentation(tour::pmRestart);
2017-04-08 15:18:29 +00:00
#endif
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(multi::players > 1 && !shmup::on) {
for(int i=0; i<numplayers(); i++)
makeEmpty(playerpos(i));
}
else {
for(int i=0; i<numplayers(); i++)
makeEmpty(cwt.c);
}
2016-08-26 09:58:03 +00:00
2017-07-16 21:00:55 +00:00
princess::squeaked = false;
2018-04-14 08:24:02 +00:00
clearing::current_root = NULL;
2017-07-16 21:00:55 +00:00
2016-08-26 09:58:03 +00:00
if(!safety) {
usedSafety = false;
timerstart = time(NULL); turncount = 0; rosewave = 0; rosephase = 0;
patterns::whichShape = 0;
2016-08-26 09:58:03 +00:00
noiseuntil = 0;
sagephase = 0; hardcoreAt = 0;
timerstopped = false;
savecount = 0; savetime = 0;
cheater = 0;
if(autocheat) cheater = 1;
hauntedWarning = false;
timerghost = true;
truelotus = 0;
survivalist = true;
2017-07-22 23:33:27 +00:00
#if CAP_INV
2017-07-04 13:38:33 +00:00
if(inv::on) inv::init();
#endif
2018-04-14 07:34:33 +00:00
if(!use_special_land) {
2016-08-26 09:58:03 +00:00
if(firstland != (princess::challenge ? laPalace : laIce)) cheater++;
}
2017-08-06 12:50:16 +00:00
welcomeMessage();
2016-08-26 09:58:03 +00:00
}
else {
usedSafety = true;
safety = false;
}
2017-03-23 10:53:57 +00:00
havewhat = hadwhat = 0; rosemap.clear();
2016-08-26 09:58:03 +00:00
elec::lightningfast = 0;
2017-03-23 10:53:57 +00:00
lastsafety = gold();
2016-08-26 09:58:03 +00:00
bfs();
checkmove();
2018-03-25 13:07:11 +00:00
playermoved = true;
if(quotient || sphere)
for(cell *c: currentmap->allcells()) setdist(c, 8, NULL);
if(!cheater) gamerange_bonus = genrange_bonus = 0;
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
bool havesave = true;
2017-07-22 23:33:27 +00:00
#if CAP_SAVE
2017-07-16 21:00:55 +00:00
#define MAXBOX 500
2018-07-23 03:19:06 +00:00
#define POSSCORE 354 // update this when new boxes are added!
2016-08-26 09:58:03 +00:00
struct score {
string ver;
int box[MAXBOX];
};
int savebox[MAXBOX], boxid;
bool saving, loading, loadingHi;
string boxname[MAXBOX];
bool fakebox[MAXBOX];
2017-03-23 10:53:57 +00:00
bool monsbox[MAXBOX];
2016-08-26 09:58:03 +00:00
void applyBox(int& t) {
if(saving) savebox[boxid++] = t;
else if(loading) t = savebox[boxid++];
else boxid++;
}
2017-07-16 21:00:55 +00:00
void applyBoxNum(int& i, string name) {
2016-08-26 09:58:03 +00:00
fakebox[boxid] = (name == "");
boxname[boxid] = name;
2017-03-23 10:53:57 +00:00
monsbox[boxid] = false;
2016-08-26 09:58:03 +00:00
applyBox(i);
}
void applyBoxBool(bool& b, string name = "") {
int i = b;
applyBoxNum(i, name);
2017-03-23 10:53:57 +00:00
monsbox[boxid] = false;
2016-08-26 09:58:03 +00:00
b = i;
}
// just skips the value when loading
void applyBoxSave(int i, string name = "") {
fakebox[boxid] = (name == "");
boxname[boxid] = name;
applyBox(i);
}
int applyBoxLoad(string name = "") {
fakebox[boxid] = (name == "");
boxname[boxid] = name;
int i=0; applyBox(i);
return i;
}
void applyBoxI(eItem it, bool f = false) {
boxname[boxid] = iinf[it].name;
fakebox[boxid] = f;
2017-03-23 10:53:57 +00:00
monsbox[boxid] = false;
2016-08-26 09:58:03 +00:00
if(loadingHi) {
updateHi(it, savebox[boxid++]);
}
else applyBox(items[it]);
}
2017-07-16 21:00:55 +00:00
vector<eItem> 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) {
2017-07-22 23:33:27 +00:00
#if CAP_INV
2017-07-16 21:00:55 +00:00
if(true) {
inv::applyBox(it);
continue;
}
#endif
int u = 0;
applyBoxNum(u);
}
invorb.clear();
}
2016-08-26 09:58:03 +00:00
void applyBoxM(eMonster m, bool f = false) {
fakebox[boxid] = f;
boxname[boxid] = minf[m].name;
2017-03-23 10:53:57 +00:00
monsbox[boxid] = true;
2016-08-26 09:58:03 +00:00
applyBox(kills[m]);
}
void applyBoxes() {
2017-07-16 21:00:55 +00:00
invorb.clear();
2016-08-26 09:58:03 +00:00
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");
2017-03-23 10:53:57 +00:00
if(loading) timerstart = time(NULL);
2016-08-26 09:58:03 +00:00
for(int i=0; i<itOrbLightning; i++)
if(i == 0) items[i] = 0, applyBoxI(itFernFlower);
else applyBoxI(eItem(i));
for(int i=0; i<43; i++) {
if(loading) kills[i] = 0;
bool fake =
2017-03-23 10:53:57 +00:00
i == moLesserM || i == moNone || i == moWolfMoved || i == moTentacletail ||
i == moIvyNext;
2016-08-26 09:58:03 +00:00
if(i == moWormtail) applyBoxM(moCrystalSage);
else if(i == moWormwait) applyBoxM(moFireFairy);
else if(i == moTentacleEscaping) applyBoxM(moMiner);
else if(i == moGolemMoved) applyBoxM(moIllusion);
2017-07-16 21:00:55 +00:00
else if(i == moTentaclewait) applyBoxOrb(itOrbThorns);
else if(i == moGreater) applyBoxOrb(itOrbDragon);
else if(i == moGreaterM) applyBoxOrb(itOrbIllusion);
2016-08-26 09:58:03 +00:00
else applyBoxM(eMonster(i), fake);
}
if(saving) {
2017-03-23 10:53:57 +00:00
int totaltime = savetime;
if(!timerstopped) totaltime += timer - timerstart;
applyBoxSave((int) totaltime, "time played");
2016-08-26 09:58:03 +00:00
}
else if(loading) savetime = applyBoxLoad("time played");
2017-03-23 10:53:57 +00:00
else boxname[boxid] = "time played", boxid++;
2016-08-26 09:58:03 +00:00
if(saving) savecount++;
applyBoxNum(savecount, "number of saves");
if(saving) savecount--;
applyBoxNum(cheater, "number of cheats");
2017-03-23 10:53:57 +00:00
fakebox[boxid] = true;
if(saving) applyBoxSave(items[itOrbSafety] ? safetyland : cwt.c->land, "");
2016-08-26 09:58:03 +00:00
else if(loading) firstland = safetyland = eLand(applyBoxLoad());
else lostin = eLand(savebox[boxid++]);
2017-07-16 21:00:55 +00:00
for(int i=itOrbLightning; i<25; i++) applyBoxOrb(eItem(i));
2016-08-26 09:58:03 +00:00
applyBoxI(itRoyalJelly);
applyBoxI(itWine);
applyBoxI(itSilver);
applyBoxI(itEmerald);
applyBoxI(itPower);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbFire);
applyBoxOrb(itOrbInvis);
applyBoxOrb(itOrbAether);
applyBoxOrb(itOrbPsi);
2016-08-26 09:58:03 +00:00
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);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbTime);
2016-08-26 09:58:03 +00:00
applyBoxM(moHexSnake);
applyBoxM(moRedTroll);
applyBoxI(itRedGem);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbSpace);
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
int geo = geometry;
applyBoxNum(geo, ""); geometry = eGeometry(geo);
2016-08-26 09:58:03 +00:00
applyBoxBool(hardcore, "hardcore");
2017-03-23 10:53:57 +00:00
applyBoxNum(hardcoreAt, "");
2016-08-26 09:58:03 +00:00
applyBoxBool(shmup::on, "shmup");
2017-08-06 12:50:16 +00:00
if(saving) applyBoxSave(specialland, "euclid land");
else if(loading) specialland = eLand(applyBoxLoad("euclid land"));
2017-03-23 10:53:57 +00:00
else fakebox[boxid++] = true;
2016-08-26 09:58:03 +00:00
applyBoxI(itCoast);
applyBoxI(itWhirlpool);
applyBoxI(itBombEgg);
applyBoxM(moBomberbird);
applyBoxM(moTameBomberbird);
applyBoxM(moAlbatross);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbFriend);
applyBoxOrb(itOrbAir);
applyBoxOrb(itOrbWater);
2016-08-26 09:58:03 +00:00
applyBoxI(itPalace);
applyBoxI(itFjord);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbFrog);
applyBoxOrb(itOrbDiscord);
2016-08-26 09:58:03 +00:00
applyBoxM(moPalace);
applyBoxM(moFatGuard);
applyBoxM(moSkeleton);
applyBoxM(moVizier);
applyBoxM(moViking);
applyBoxM(moFjordTroll);
applyBoxM(moWaterElemental);
applyBoxI(itSavedPrincess);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbLove);
2016-08-26 09:58:03 +00:00
applyBoxM(moPrincess);
2017-03-23 10:53:57 +00:00
applyBoxM(moPrincessMoved, false); // live Princess for Safety
applyBoxM(moPrincessArmedMoved, false); // live Princess for Safety
2016-08-26 09:58:03 +00:00
applyBoxM(moMouse);
2017-03-23 10:53:57 +00:00
applyBoxNum(princess::saveArmedHP, "");
applyBoxNum(princess::saveHP, "");
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
applyBoxI(itIvory);
2016-08-26 09:58:03 +00:00
applyBoxI(itElemental);
applyBoxI(itZebra);
applyBoxI(itFireShard);
applyBoxI(itWaterShard);
applyBoxI(itAirShard);
applyBoxI(itEarthShard);
applyBoxM(moAirElemental);
applyBoxM(moFireElemental);
2017-03-23 10:53:57 +00:00
applyBoxM(moFamiliar);
2016-08-26 09:58:03 +00:00
applyBoxM(moGargoyle);
applyBoxM(moOrangeDog);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbSummon);
applyBoxOrb(itOrbMatter);
2016-08-26 09:58:03 +00:00
applyBoxM(moForestTroll);
applyBoxM(moStormTroll);
applyBoxM(moOutlaw);
applyBoxM(moMutant);
applyBoxM(moMetalBeast);
applyBoxM(moMetalBeast2);
applyBoxI(itMutant);
applyBoxI(itFulgurite);
applyBoxI(itBounty);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbLuck);
applyBoxOrb(itOrbStunning);
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
applyBoxBool(tactic::on, "");
applyBoxNum(elec::lightningfast, "");
2016-08-26 09:58:03 +00:00
// if(savebox[boxid]) printf("lotus = %d (lost = %d)\n", savebox[boxid], isHaunted(lostin));
if(loadingHi && isHaunted(lostin)) boxid++;
else applyBoxI(itLotus);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbUndeath);
2016-08-26 09:58:03 +00:00
applyBoxI(itWindstone);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbEmpathy);
2016-08-26 09:58:03 +00:00
applyBoxM(moWindCrow);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itMutant2);
applyBoxOrb(itOrbFreedom);
2016-08-26 09:58:03 +00:00
applyBoxM(moRedFox);
applyBoxBool(survivalist);
if(loadingHi) applyBoxI(itLotus);
else applyBoxNum(truelotus, "lotus/escape");
2018-01-06 21:34:03 +00:00
applyBoxBool(nonbitrunc, "heptagons only");
2016-08-26 09:58:03 +00:00
applyBoxI(itRose);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbBeauty);
2016-08-26 09:58:03 +00:00
applyBoxI(itCoral);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrb37);
applyBoxOrb(itOrbEnergy);
2016-08-26 09:58:03 +00:00
applyBoxM(moRatling);
applyBoxM(moFalsePrincess);
applyBoxM(moRoseLady);
applyBoxM(moRoseBeauty);
applyBoxBool(chaosmode, "Chaos mode");
2017-03-23 10:53:57 +00:00
applyBoxNum(multi::players, "shmup players");
if(multi::players < 1 || multi::players > MAXPLAYER)
multi::players = 1;
2016-08-26 09:58:03 +00:00
applyBoxM(moRatlingAvenger);
// printf("applybox %d\n", shmup::players);
applyBoxI(itApple);
2017-03-23 10:53:57 +00:00
applyBoxM(moSparrowhawk);
applyBoxM(moResearcher);
2016-08-26 09:58:03 +00:00
applyBoxI(itDragon);
applyBoxM(moDragonHead);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbDomination);
2016-08-26 09:58:03 +00:00
applyBoxI(itBabyTortoise);
2017-03-23 10:53:57 +00:00
applyBoxNum(tortoise::seekbits, "");
2016-08-26 09:58:03 +00:00
applyBoxM(moTortoise);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbShell);
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
applyBoxNum(safetyseed);
2017-03-23 10:53:57 +00:00
// (+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);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbSword);
2017-03-23 10:53:57 +00:00
applyBoxI(itBarrow);
applyBoxM(moDraugr);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbSword2);
2017-03-23 10:53:57 +00:00
applyBoxI(itTrollEgg);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbStone);
2017-03-23 10:53:57 +00:00
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);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbNature);
applyBoxOrb(itOrbDash);
addinv(itOrbRecall);
2017-03-23 10:53:57 +00:00
applyBoxM(moBat);
applyBoxM(moReptile);
applyBoxM(moFriendlyIvy);
applyBoxI(itGreenGrass);
applyBoxI(itBull);
2017-07-16 21:00:55 +00:00
applyBoxOrb(itOrbHorns);
applyBoxOrb(itOrbBull);
2017-03-23 10:53:57 +00:00
applyBoxM(moSleepBull);
applyBoxM(moRagingBull);
applyBoxM(moHerdBull);
applyBoxM(moButterfly);
applyBoxM(moGadfly);
2017-07-16 21:00:55 +00:00
// 10.0:
applyBoxNum(hinttoshow); // 258
addinv(itOrbMirror);
addinv(itGreenStone);
list_invorb();
applyBoxBool(inv::on, "inventory"); // 306
2017-07-22 23:33:27 +00:00
#if CAP_INV
2017-07-16 21:00:55 +00:00
applyBoxNum(inv::rseed);
#else
{ int u; applyBoxNum(u); }
#endif
2017-10-08 12:02:03 +00:00
// 10.1:
applyBoxI(itLavaLily);
2017-10-10 12:24:39 +00:00
applyBoxI(itHunting);
2017-10-08 12:02:03 +00:00
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);
2018-01-04 12:32:11 +00:00
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);
applyBoxBool(gp::on);
applyBox(gp::param.first);
applyBox(gp::param.second);
applyBoxBool(irr::on);
applyBox(irr::cellcount);
2017-10-08 12:02:03 +00:00
2018-07-23 03:19:06 +00:00
list_invorb();
2017-03-23 10:53:57 +00:00
if(POSSCORE != boxid) printf("ERROR: %d boxes\n", boxid);
2016-08-26 09:58:03 +00:00
}
void saveBox() {
boxid = 0; saving = true; applyBoxes(); saving = false;
}
void loadBox() {
// have boxid
boxid = 0; loading = true; applyBoxes(); loading = false;
}
void loadBoxHigh() {
2017-03-23 10:53:57 +00:00
dynamicval<int> sp1(multi::players, savebox[197]);
dynamicval<eGeometry> sp2(geometry, (eGeometry) savebox[116]);
dynamicval<bool> sp3(shmup::on, savebox[119]);
dynamicval<bool> sp4(chaosmode, savebox[196]);
2018-01-06 21:34:03 +00:00
dynamicval<bool> sp5(nonbitrunc, savebox[186]);
dynamicval<bool> sp6(gp::on, savebox[341]);
dynamicval<int> sp7(gp::param.first, savebox[342]);
dynamicval<int> sp8(gp::param.second, savebox[343]);
2017-03-23 10:53:57 +00:00
if(savebox[238]) geometry = gSphere;
if(savebox[239]) geometry = gElliptic;
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(multi::players < 1 || multi::players > MAXPLAYER)
multi::players = 1;
if(shmup::on && multi::players == 1) ;
2016-08-26 09:58:03 +00:00
else {
// have boxid
boxid = 0; loadingHi = true; applyBoxes(); loadingHi = false;
}
}
// certify that saves and achievements were received
// in an official version of HyperRogue
2017-07-22 23:33:27 +00:00
#if CAP_CERTIFY
2017-07-04 13:38:33 +00:00
#include "private/certify.cpp"
2016-08-26 09:58:03 +00:00
#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;
2017-03-23 10:53:57 +00:00
void remove_emergency_save() {
2017-07-22 23:33:27 +00:00
#if !ISWINDOWS
2017-03-23 10:53:57 +00:00
if(saveposition >= 0) {
if(truncate(scorefile, saveposition)) {}
saveposition = -1;
}
#endif
}
2016-08-26 09:58:03 +00:00
void saveStats(bool emergency = false) {
DEBB(DF_INIT, (debugfile,"saveStats [%s]\n", scorefile));
2017-03-23 10:53:57 +00:00
if(autocheat) return;
2017-07-22 23:33:27 +00:00
#if CAP_TOUR
2017-04-08 15:18:29 +00:00
if(tour::on) return;
#endif
2016-08-26 09:58:03 +00:00
if(randomPatternsMode) return;
2018-05-15 21:26:04 +00:00
if(daily::on) return;
2017-07-04 13:38:33 +00:00
if(peace::on) return;
2017-07-12 16:03:53 +00:00
if(!gold()) return;
2017-03-23 10:53:57 +00:00
remove_emergency_save();
2016-08-26 09:58:03 +00:00
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);
2017-03-23 10:53:57 +00:00
// if(!timerghost) addMessage(XLAT("Emergency save at ") + its(saveposition));
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
if(showoff) { fclose(f); return; }
2016-08-26 09:58:03 +00:00
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(specialland)];
2016-08-26 09:58:03 +00:00
if(score) {
int c =
anticheat::certify(dnameof(specialland), turncount, t, (int) timerstart,
2016-08-26 09:58:03 +00:00
xcode*999 + tactic::id + 256 * score);
2018-01-06 21:05:22 +00:00
fprintf(f, "TACTICS %s %d %d %d %d %d %d %d %d date: %s\n", VER,
tactic::id, specialland, score, turncount, t, int(timerstart),
2018-01-06 21:05:22 +00:00
c, xcode, buf);
tactic::record(specialland, score);
2016-08-26 09:58:03 +00:00
anticheat::nextid(tactic::id, VER, c);
}
}
if(yendor::on)
2018-01-06 21:05:22 +00:00
fprintf(f, "YENDOR %s %d %d %d %d %d %d %d %d date: %s\n", VER,
2016-08-26 09:58:03 +00:00
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]),
2018-01-06 21:05:22 +00:00
xcode,
2016-08-26 09:58:03 +00:00
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<boxid; i++) fprintf(f, " %d", savebox[i]);
anticheat::save(f);
fprintf(f, "\n");
}
fprintf(f, "Played on: %s - %s (%d %s)\n", sbuf, buf, turncount,
shmup::on ? "knives" : "turns");
fprintf(f, "Total wealth: %d\n", gold());
fprintf(f, "Total enemies killed: %d\n", tkills());
fprintf(f, "cells generated: %d\n", cellcount);
2017-03-23 10:53:57 +00:00
if(pureHardcore()) fprintf(f, "Pure hardcore mode\n");
2018-01-06 21:34:03 +00:00
if(nonbitrunc) fprintf(f, "Heptagons only mode\n");
if(geometry) fprintf(f, "Geometry: %s\n", ginf[geometry].name);
2016-08-26 09:58:03 +00:00
if(chaosmode) fprintf(f, "Chaos mode\n");
2017-03-23 10:53:57 +00:00
if(shmup::on) fprintf(f, "Shoot-em up mode\n");
2017-07-04 13:38:33 +00:00
if(inv::on) fprintf(f, "Inventory mode\n");
2017-03-23 10:53:57 +00:00
if(multi::players > 1) fprintf(f, "Multi-player (%d players)\n", multi::players);
2016-08-26 09:58:03 +00:00
fprintf(f, "Number of cells explored, by distance from the player:\n");
2017-03-23 10:53:57 +00:00
{for(int i=0; i<10; i++) fprintf(f, " %d", explore[i]);} fprintf(f, "\n");
2016-08-26 09:58:03 +00:00
if(kills[0]) fprintf(f, "walls melted: %d\n", kills[0]);
fprintf(f, "cells travelled: %d\n", celldist(cwt.c));
fprintf(f, "\n");
for(int i=0; i<ittypes; i++) if(items[i])
fprintf(f, "%4dx %s\n", items[i], iinf[i].name);
fprintf(f, "\n");
for(int i=1; i<motypes; i++) if(kills[i])
fprintf(f, "%4dx %s\n", kills[i], minf[i].name);
fprintf(f, "\n\n\n");
2017-07-22 23:33:27 +00:00
#if ISMOBILE==0
2016-08-26 09:58:03 +00:00
DEBB(DF_INIT, (debugfile, "Game statistics saved to %s\n", scorefile));
2017-03-23 10:53:57 +00:00
if(!tactic::trailer)
addMessage(XLAT("Game statistics saved to %1", scorefile));
2016-08-26 09:58:03 +00:00
#endif
fclose(f);
}
// load the save
void loadsave() {
2017-04-08 15:18:29 +00:00
if(autocheat) return;
2017-07-22 23:33:27 +00:00
#if CAP_TOUR
2017-04-08 15:18:29 +00:00
if(tour::on) return;
#endif
2016-08-26 09:58:03 +00:00
DEBB(DF_INIT, (debugfile,"loadSave\n"));
2017-03-23 10:53:57 +00:00
gamecount = 0;
2016-08-26 09:58:03 +00:00
FILE *f = fopen(scorefile, "rt");
havesave = f;
if(!f) return;
score sc;
bool ok = false;
bool tamper = false;
2017-07-16 21:00:55 +00:00
int coh = counthints();
2016-08-26 09:58:03 +00:00
while(!feof(f)) {
char buf[120];
if(fgets(buf, 120, f) == NULL) break;
if(buf[0] == 'H' && buf[1] == 'y') {
2017-03-23 10:53:57 +00:00
gamecount++;
if(fscanf(f, "%s", buf) <= 0) break;
sc.ver = buf;
2017-07-16 21:00:55 +00:00
if(sc.ver[1] != '.') sc.ver = '0' + sc.ver;
if(verless(sc.ver, "4.4") || sc.ver == "CHEATER!") { ok = false; continue; }
2016-08-26 09:58:03 +00:00
ok = true;
for(int i=0; i<MAXBOX; i++) {
if(fscanf(f, "%d", &sc.box[i]) <= 0) {
boxid = i;
tamper = anticheat::load(f, sc, sc.ver);
for(int i=0; i<boxid; i++) savebox[i] = sc.box[i];
for(int i=boxid; i<MAXBOX; i++) savebox[i] = 0, sc.box[i] = 0;
2017-07-16 21:00:55 +00:00
if(savebox[258] >= 0 && savebox[258] < coh) {
hints[savebox[258]].last = savebox[1];
}
2016-08-26 09:58:03 +00:00
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;
2018-01-06 21:05:22 +00:00
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);
2017-07-22 23:33:27 +00:00
eLand l2 = eLand(land);
if(land == laMirror && verless(ver, "10.0")) l2 = laMirrorOld;
2018-01-06 21:05:22 +00:00
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;
2016-08-26 09:58:03 +00:00
2018-01-06 21:05:22 +00:00
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"))
2018-01-25 22:25:35 +00:00
&& !(land == laTerracotta && verless(ver, "10.3e"))
2018-01-06 21:05:22 +00:00
) tactic::record(l2, score, xc);
anticheat::nextid(tactic::id, ver, cert);
}
2016-08-26 09:58:03 +00:00
}
if(buf[0] == 'Y' && buf[1] == 'E' && buf[2] == 'N') {
char buf1[80], ver[10];
2018-01-06 21:05:22 +00:00
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)) {
2017-03-23 10:53:57 +00:00
if(xc == 19 && cid == 25) xc = 0;
2016-08-26 09:58:03 +00:00
if(cid > 0 && cid < YENDORLEVELS)
2017-07-16 21:00:55 +00:00
if(!(verless(ver, "8.0f") && oy > 1 && cid == 15))
if(!(verless(ver, "9.3b") && oy > 1 && (cid == 27 || cid == 28)))
2017-03-23 10:53:57 +00:00
{
2016-08-26 09:58:03 +00:00
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<boxid; i++) savebox[i] = sc.box[i];
for(int i=boxid; i<MAXBOX; i++) savebox[i] = 0;
// for(int i=160; i<200; i++) printf("%d: %d ", i, savebox[i]);
loadBox();
// printf("boxid = %d\n", boxid);
if(items[itHolyGrail]) {
items[itHolyGrail]--;
knighted = newRoundTableRadius();
items[itHolyGrail]++;
}
else knighted = 0;
safety = true;
if(items[itSavedPrincess] < 0) items[itSavedPrincess] = 0;
addMessage(XLAT("Game loaded."));
2017-08-06 12:50:16 +00:00
showstartmenu = false;
// reset unsavable special modes just in case
peace::on = false;
randomPatternsMode = false;
yendor::on = false;
tour::on = false;
2016-08-26 09:58:03 +00:00
}
}
#endif
namespace gamestack {
2017-03-23 10:53:57 +00:00
struct gamedata {
hrmap *hmap;
cellwalker cwt;
2018-05-18 15:34:12 +00:00
cellwalker ctover;
heptspin viewctr;
transmatrix View;
eGeometry geometry;
bool shmup;
2017-04-08 15:18:29 +00:00
bool hepta;
};
2017-03-23 10:53:57 +00:00
vector<gamedata> gd;
2018-06-22 12:47:24 +00:00
bool pushed() { return isize(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;
2018-01-06 21:34:03 +00:00
gdn.hepta = nonbitrunc;
2018-05-18 15:34:12 +00:00
gdn.ctover = centerover;
gd.push_back(gdn);
}
void pop() {
2018-06-22 12:47:24 +00:00
gamedata& gdn = gd[isize(gd)-1];
currentmap = gdn.hmap;
cwt = gdn.cwt;
viewctr = gdn.viewctr;
View = gdn.View;
geometry = gdn.geometry;
2018-01-06 21:34:03 +00:00
nonbitrunc = gdn.hepta;
if(shmup::on) shmup::clearMonsters();
shmup::on = gdn.shmup;
resetGeometry();
gd.pop_back();
2018-05-18 15:34:12 +00:00
centerover = gdn.ctover;
bfs();
}
};
void pop_game() {
2017-07-24 22:21:36 +00:00
if(gamestack::pushed()) {
gamestack::pop();
game_active = true;
2017-07-24 22:21:36 +00:00
}
}
void popAllGames() {
while(gamestack::pushed()) {
gamestack::pop();
}
}
void stop_game() {
if(!game_active) return;
DEBB(DF_INIT, (debugfile,"stop_game\n"));
achievement_final(true);
#if CAP_SAVE
saveStats();
#endif
for(int i=0; i<ittypes; i++) items[i] = 0;
lastkills = 0; for(int i=0; i<motypes; i++) kills[i] = 0;
for(int i=0; i<10; i++) explore[i] = 0;
for(int i=0; i<10; i++) for(int l=0; l<landtypes; l++)
exploreland[i][l] = 0;
for(int i=0; i<numplayers(); i++)
if(multi::playerActive(i))
multi::deaths[i]++;
#if CAP_SAVE
anticheat::tampered = false;
#endif
achievementsReceived.clear();
princess::saved = false;
princess::nodungeon = false;
princess::reviveAt = 0;
princess::forceVizier = false;
princess::forceMouse = false;
knighted = 0;
// items[itGreenStone] = 100;
clearMemory();
game_active = false;
2018-05-26 00:14:52 +00:00
#if CAP_DAILY
if(daily::on)
2018-05-25 23:29:25 +00:00
daily::turnoff();
2018-05-26 00:14:52 +00:00
#endif
}
void push_game() {
gamestack::push();
pd_from = NULL;
centerover.c = NULL;
game_active = false;
}
void switch_game_mode(char switchWhat) {
DEBB(DF_INIT, (debugfile,"switch_game_mode\n"));
switch(switchWhat) {
case rg::peace:
peace::on = !peace::on;
tactic::on = yendor::on = princess::challenge =
randomPatternsMode = inv::on = false;
break;
case rg::inv:
inv::on = !inv::on;
if(tactic::on) firstland = laIce;
tactic::on = yendor::on = princess::challenge =
randomPatternsMode = peace::on = false;
break;
case rg::chaos:
if(euclid || sphere || quotient)
geometry = gNormal;
if(tactic::on) firstland = laIce;
yendor::on = tactic::on = princess::challenge = false;
need_reset_geometry = true;
chaosmode = !chaosmode;
break;
2017-07-22 23:33:27 +00:00
#if CAP_TOUR
case rg::tour:
geometry = gNormal;
yendor::on = tactic::on = princess::challenge = peace::on = inv::on = false;
chaosmode = nonbitrunc = randomPatternsMode = irr::on = gp::on = false;
gp::param = gp::loc(1, 1);
shmup::on = false;
need_reset_geometry = true;
tour::on = !tour::on;
break;
2017-04-08 15:18:29 +00:00
#endif
case rg::bitrunc:
case rg::gp:
if(euclid6) geometry = gNormal;
nonbitrunc = !nonbitrunc; irr::on = false;
gp::on = (switchWhat == rg::gp && !gp::on);
need_reset_geometry = true;
#if CAP_TEXTURE
if(texture::config.tstate == texture::tsActive)
texture::config.tstate = texture::tsAdjusting;
if(texture::config.tstate_max == texture::tsActive)
texture::config.tstate = texture::tsAdjusting;
#endif
break;
case rg::geometry:
ors::reset();
if(geometry == targetgeometry) geometry = gNormal;
else geometry = targetgeometry;
if(chaosmode && (euclid || sphere || quotient)) chaosmode = false;
if(nonbitrunc && euclid6) nonbitrunc = false;
if(irr::on) irr::on = false;
if(gp::on && gp::param == gp::loc(1,1) && S3 == 3) {
gp::on = false; nonbitrunc = false;
}
if(gp::on && nonorientable) {
if(gp::param.second && gp::param.second != gp::param.first)
gp::param.second = 0;
}
need_reset_geometry = true;
#if CAP_TEXTURE
if(texture::config.tstate == texture::tsActive)
texture::config.tstate = texture::tsOff;
if(texture::config.tstate_max == texture::tsActive)
texture::config.tstate = texture::tsAdjusting;
#endif
break;
case rg::yendor:
yendor::on = !yendor::on;
tactic::on = false;
peace::on = false;
inv::on = false;
princess::challenge = false;
randomPatternsMode = false;
chaosmode = false;
if(!yendor::on) firstland = laIce;
break;
case rg::tactic:
tactic::on = !tactic::on;
yendor::on = false;
peace::on = false;
inv::on = false;
randomPatternsMode = false;
princess::challenge = false;
chaosmode = false;
if(!tactic::on) firstland = laIce;
break;
case rg::shmup:
shmup::on = !shmup::on;
princess::challenge = false;
break;
case rg::randpattern:
randomPatternsMode = !randomPatternsMode;
tactic::on = false;
yendor::on = false;
peace::on = false;
inv::on = false;
princess::challenge = false;
break;
case rg::princess:
princess::challenge = !princess::challenge;
firstland = princess::challenge ? laPalace : laIce;
shmup::on = false;
tactic::on = false;
yendor::on = false;
chaosmode = false;
inv::on = false;
break;
2018-05-01 17:38:42 +00:00
#if CAP_DAILY
case rg::daily:
daily::setup();
break;
case rg::daily_off:
daily::turnoff();
break;
2018-05-01 17:38:42 +00:00
#endif
2016-08-26 09:58:03 +00:00
}
}
void start_game() {
if(game_active) return;
DEBB(DF_INIT, (debugfile,"start_game\n"));
game_active = true;
if(need_reset_geometry) resetGeometry(), need_reset_geometry = false;
2016-08-26 09:58:03 +00:00
initcells();
if(randomPatternsMode) {
for(int i=0; i<landtypes; i++) {
randompattern[i] = hrandpos();
// change probability 1/5 to 2/6
if(hrand(5) == 0) {
randompattern[i] -= (randompattern[i] % 5);
}
}
if(randomPatternsMode) specialland = pickLandRPM(laNone);
2016-08-26 09:58:03 +00:00
clearMemoRPM();
}
initgame();
canmove = true;
restartGraph();
resetmusic();
resetmusic();
}
void restart_game(char switchWhat) {
popScreenAll();
popAllGames();
stop_game();
switch_game_mode(switchWhat);
start_game();
}
void stop_game_and_switch_mode(char switchWhat) {
stop_game();
switch_game_mode(switchWhat);
}
2017-07-10 18:47:38 +00:00
purehookset clearmemory;
void clearMemory() {
callhooks(clearmemory);
}
auto cgm = addHook(clearmemory, 40, [] () {
pathq.clear();
dcal.clear();
clearshadow();
2018-02-27 22:43:21 +00:00
for(int i=0; i<MAXPLAYER; i++) lastmountpos[i] = NULL;
2017-07-10 18:47:38 +00:00
seenSevenMines = false;
recallCell = NULL;
butterflies.clear();
buggycells.clear();
2018-01-02 10:15:42 +00:00
crush_next.clear();
crush_now.clear();
2018-01-26 00:45:49 +00:00
}) +
addHook(hooks_removecells, 0, [] () {
eliminate_if(crush_next, is_cell_removed);
eliminate_if(crush_now, is_cell_removed);
eliminate_if(buggycells, is_cell_removed);
eliminate_if(butterflies, [] (pair<cell*,int>& p) { return is_cell_removed(p.first); });
for(int i=0; i<SHSIZE; i++) for(int p=0; p<MAXPLAYER; p++)
set_if_removed(shpos[p][i], NULL);
});;
}