From ad0311509771d2eff59967d8c28a3a8a278b44ae Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 10 Aug 2019 02:16:48 +0200 Subject: [PATCH] further cleanup --- basegraph.cpp | 13 +++ commandline.cpp | 70 +++++++++----- config.cpp | 100 +++++++++++++++++++ control.cpp | 2 +- dialogs.cpp | 2 +- game.cpp | 11 ++- geom-exp.cpp | 2 +- help.cpp | 2 +- hyper.h | 253 +----------------------------------------------- models.cpp | 5 + quit.cpp | 2 +- shmup.cpp | 2 +- system.cpp | 27 ++++++ 13 files changed, 210 insertions(+), 281 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index 4925a794..147eb263 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -971,6 +971,19 @@ EX bool displaychr(int x, int y, int shift, int size, char chr, color_t col) { } #endif +#if HDR +struct msginfo { + int stamp; + time_t rtstamp; + int gtstamp; + int turnstamp; + char flashout; + char spamtype; + int quantity; + string msg; + }; +#endif + vector msgs; vector gamelog; diff --git a/commandline.cpp b/commandline.cpp index 0b166d0f..23bd98f8 100644 --- a/commandline.cpp +++ b/commandline.cpp @@ -6,8 +6,8 @@ namespace hr { #if CAP_COMMANDLINE EX const char *scorefile = "hyperrogue.log"; -namespace arg { -eLand readland(const string& ss) { +EX namespace arg { +EX eLand readland(const string& ss) { if(ss == "II") return laCrossroads2; if(ss == "III") return laCrossroads3; if(ss == "IV") return laCrossroads4; @@ -19,7 +19,7 @@ eLand readland(const string& ss) { return laNone; } -eItem readItem(const string& ss) { +EX eItem readItem(const string& ss) { for(int i=0; i, version " VER "\n"); @@ -55,36 +55,60 @@ EX void initializeCLI() { #endif } -namespace arg { - vector argument; - int pos; +EX namespace arg { + EX int curphase; - void lshift() { pos++; } + vector argument; + EX int pos; + + EX void lshift() { pos++; } void unshift() { pos--; } - void shift() { + EX void shift() { lshift(); if(pos >= isize(argument)) { printf("Missing parameter\n"); exit(1); } } - bool nomore() { return pos >= isize(argument); } + EX bool nomore() { return pos >= isize(argument); } - const string& args() { return argument[pos]; } - const char* argcs() { return args().c_str(); } - int argi() { return atoi(argcs()); } - unsigned arghex() { return strtoll(argcs(), NULL, 16); } - ld argf() { return parseld(args()); } - bool argis(const string& s) { if(args()[0] == '-' && args()[1] == '-') return args().substr(1) == s; return args() == s; } + EX const string& args() { return argument[pos]; } + EX const char* argcs() { return args().c_str(); } + EX int argi() { return atoi(argcs()); } + EX unsigned arghex() { return strtoll(argcs(), NULL, 16); } + EX ld argf() { return parseld(args()); } + EX bool argis(const string& s) { if(args()[0] == '-' && args()[1] == '-') return args().substr(1) == s; return args() == s; } - void init(int argc, char **argv) { for(int i=0; i x) arg::phaseerror(x); else if(arg::curphase < x) return 2; } + #define PHASEFROM(x) { if(arg::curphase < x) return 2; } + + #define TOGGLE(x, param, act) \ + else if(args()[0] == '-' && args()[1] == x && !args()[2]) { PHASEFROM(2); showstartmenu = false; act; } \ + else if(args()[0] == '-' && args()[1] == x && args()[2] == '1') { PHASEFROM(2); showstartmenu = false; if(!param) act; } \ + else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2); showstartmenu = false; if(param) act; } + + #endif + + EX void cheat() { autocheat = true; cheater++; timerghost = false; } + + EX void init(int argc, char **argv) { for(int i=0; i *hooks_args; namespace arg { - int curphase; auto ah = addHook(hooks_args, 0, readCommon); diff --git a/config.cpp b/config.cpp index 43aaff8e..65cde672 100644 --- a/config.cpp +++ b/config.cpp @@ -4,6 +4,106 @@ namespace hr { +#if HDR +struct supersaver { + string name; + virtual string save() = 0; + virtual void load(const string& s) = 0; + virtual bool dosave() = 0; + virtual void reset() = 0; + virtual ~supersaver() {}; + }; + +typedef vector> saverlist; + +extern saverlist savers; + +#if CAP_CONFIG + +template struct dsaver : supersaver { + T& val; + T dft; + bool dosave() { return val != dft; } + void reset() { val = dft; } + dsaver(T& val) : val(val) { } + }; + +template struct saver : dsaver {}; + +template void addsaver(T& i, U name, V dft) { + auto s = make_shared> (i); + s->dft = dft; + s->name = name; + savers.push_back(s); + } + +template void addsaver(T& i, string name) { + addsaver(i, name, i); + } + +template struct saverenum : supersaver { + T& val; + T dft; + bool dosave() { return val != dft; } + void reset() { val = dft; } + saverenum(T& v) : val(v) { } + string save() { return its(int(val)); } + void load(const string& s) { val = (T) atoi(s.c_str()); } + }; + +template void addsaverenum(T& i, U name, T dft) { + auto s = make_shared> (i); + s->dft = dft; + s->name = name; + savers.push_back(s); + } + +template void addsaverenum(T& i, U name) { + addsaverenum(i, name, i); + } + +template<> struct saver : dsaver { + saver(int& val) : dsaver(val) { } + string save() { return its(val); } + void load(const string& s) { val = atoi(s.c_str()); } + }; + +template<> struct saver : dsaver { + saver(char& val) : dsaver(val) { } + string save() { return its(val); } + void load(const string& s) { val = atoi(s.c_str()); } + }; + +template<> struct saver : dsaver { + saver(bool& val) : dsaver(val) { } + string save() { return val ? "yes" : "no"; } + void load(const string& s) { val = isize(s) && s[0] == 'y'; } + }; + +template<> struct saver : dsaver { + saver(unsigned& val) : dsaver(val) { } + string save() { return itsh(val); } + void load(const string& s) { val = (unsigned) strtoll(s.c_str(), NULL, 16); } + }; + +template<> struct saver : dsaver { + saver(string& val) : dsaver(val) { } + string save() { return val; } + void load(const string& s) { val = s; } + }; + +template<> struct saver : dsaver { + saver(ld& val) : dsaver(val) { } + string save() { return fts(val, 10); } + void load(const string& s) { + if(s == "0.0000000000e+000") ; // ignore! + else val = atof(s.c_str()); + } + }; +#endif + +#endif + EX ld bounded_mine_percentage = 0.1; EX int bounded_mine_quantity, bounded_mine_max; diff --git a/control.cpp b/control.cpp index 283a476d..31131dba 100644 --- a/control.cpp +++ b/control.cpp @@ -253,7 +253,7 @@ EX void checkpanjoy(double t) { #endif -bool quitmainloop = false; +EX bool quitmainloop = false; EX bool doexiton(int sym, int uni) { if(sym == SDLK_ESCAPE) return true; diff --git a/dialogs.cpp b/dialogs.cpp index 6ee2142a..e0687af5 100644 --- a/dialogs.cpp +++ b/dialogs.cpp @@ -16,7 +16,7 @@ namespace hr { -const char* COLORBAR = "###"; +EX const char* COLORBAR = "###"; EX namespace dialog { diff --git a/game.cpp b/game.cpp index 1f82f0f3..48c6f9b4 100644 --- a/game.cpp +++ b/game.cpp @@ -112,7 +112,7 @@ EX int explore[10], exploreland[10][landtypes], landcount[landtypes]; EX map > hiitems; bool orbused[ittypes], lastorbused[ittypes]; EX bool playermoved = true; // center on the PC? -bool flipplayer = true; // flip the player image after move, do not flip after attack +EX bool flipplayer = true; // flip the player image after move, do not flip after attack EX int cheater = 0; // did the player cheat? int anthraxBonus = 0; // for using Safety in tactical Camelot @@ -415,7 +415,10 @@ EX int killtypes() { return res; } -eGravity gravity_state, last_gravity_state; +#if HDR +enum eGravity { gsNormal, gsLevitation, gsAnti }; +#endif +EX eGravity gravity_state, last_gravity_state; bool bird_disruption(cell *c) { return c->cpdist <= 5 && items[itOrbGravity]; @@ -8602,6 +8605,10 @@ EX bool movepcto(int d, int subdir IS(1), bool checkonly IS(false)) { return true; } +#if HDR +inline bool movepcto(const movedir& md) { return movepcto(md.d, md.subdir); } +#endif + /* bool isPsiTarget(cell *dst) { return dst->cpdist > 1 && diff --git a/geom-exp.cpp b/geom-exp.cpp index d754607b..9a15064a 100644 --- a/geom-exp.cpp +++ b/geom-exp.cpp @@ -447,7 +447,7 @@ void ge_select_tiling(const vector& lst) { dialog::display(); } -string current_proj_name() { +EX string current_proj_name() { if(pmodel != mdDisk || nonisotropic) return models::get_model_name(pmodel); else if(hyperbolic && vid.alpha == 1) diff --git a/help.cpp b/help.cpp index 9d2a57c5..4cd49b27 100644 --- a/help.cpp +++ b/help.cpp @@ -173,7 +173,7 @@ void buildHelpText() { #endif } -void buildCredits() { +EX void buildCredits() { help = ""; help += XLAT("game design, programming, texts and graphics by Zeno Rogue \n\n"); if(lang() != 0) diff --git a/hyper.h b/hyper.h index 7dae78b2..baee68d3 100644 --- a/hyper.h +++ b/hyper.h @@ -674,13 +674,6 @@ inline cellwalker operator+ (heptspin hs, cth_t) { return cellwalker(hs.at->c7, // kill count for Graveyard/Hive #define R100 (big_unlock ? 500 : 100) -string XLAT(string x); // translate the sentence x -string XLATN(string x); // translate the sentence x -string cts(char c); // character to string -string its(int i); // int to string -string itsh8(int i); // int to string (8 hex digits) -string itsh(int i); // int to string - // size casted to int, to prevent warnings and actual errors caused by the unsignedness of x.size() template int isize(const T& x) {return x.size(); } @@ -689,33 +682,6 @@ template int isize(const T& x) {return x.size(); } namespace anticheat { extern bool tampered; } #define HRANDMAX 0x7FFFFFFF -namespace rg { - // possible parameters e.g. for restart_game and wrongmode - static const char nothing = 0; - static const char peace = 'P'; - static const char inv = 'i'; - static const char chaos = 'C'; - static const char tactic = 't'; - static const char tour = 'T'; - static const char yendor = 'y'; - static const char shmup = 's'; - static const char randpattern = 'r'; - static const char princess = 'p'; - static const char daily = 'd'; - static const char daily_off = 'D'; - static const char racing = 'R'; - static const char dualmode = 'U'; - - // wrongmode only -- marks 'global' achievements not related to the current mode - static const char global = 'x'; - // wrongmode only -- change vid.scfg.players then restart_game(rg::nothing) instead - static const char multi = 'm'; - // wrongmode only -- mark achievements for special geometries/variations - static const char special_geometry = 'g'; - } - -enum orbAction { roMouse, roKeyboard, roCheck, roMouseForce, roMultiCheck, roMultiGo }; - namespace hive { void createBugArmy(cell *c); } namespace whirlpool { void generate(cell *wto); } namespace whirlwind { void generate(cell *wto); } @@ -740,15 +706,8 @@ struct movedir { cell *tgt; // for MD_USE_ORB: target cell }; -void activateActiv(cell *c, bool msg); - // shmup -string csname(charstyle& cs); -void initcs(charstyle& cs); - -extern bool flipplayer; - template class hookset : public map> {}; typedef hookset *purehookset; @@ -972,106 +931,20 @@ inline int operator - (PPR x, PPR y) { return int(x) - int(y); } #define OUTLINE_FORE ((forecolor << 8) + 0xFF) #define OUTLINE_BACK ((backcolor << 8) + 0xFF) -inline string pick123() { return cts('1' + rand() % 3); } -inline string pick12() { return cts('1' + rand() % 2); } - -extern int detaillevel; -extern bool quitmainloop; - -enum eGravity { gsNormal, gsLevitation, gsAnti }; -extern eGravity gravity_state, last_gravity_state; - #define IFM(x) (mousing?"":x) -extern bool viewdists; - -void preventbarriers(cell *c); - -bool passable_for(eMonster m, cell *w, cell *from, flagtype extra); - -void beastcrash(cell *c, cell *beast); - -int angledist(int t, int d1, int d2); -int angledist(cell *c, int d1, int d2); - -void setcameraangle(bool b); +enum orbAction { roMouse, roKeyboard, roCheck, roMouseForce, roMultiCheck, roMultiGo }; #define MODELCOUNT ((int) mdGUARD) void drawShape(pair* coords, int qty, color_t color); #define pmodel (vid.vpmodel) -string current_proj_name(); - -inline bool mdAzimuthalEqui() { return among(pmodel, mdEquidistant, mdEquiarea, mdEquivolume); } - -inline bool mdBandAny() { return among(pmodel, mdBand, mdBandEquidistant, mdBandEquiarea, mdSinusoidal); } color_t darkena(color_t c, int lev, int a); #define SHSIZE 16 -namespace anims { void animate_parameter(ld &x, string f, const reaction_t& r); } - -extern bool timerghost; -extern bool autocheat; -extern int cheater; - -namespace arg { -#if CAP_COMMANDLINE - - void lshift(); - void unshift(); - - void shift(); - - const string& args(); - const char* argcs(); - int argi(); - ld argf(); - bool argis(const string& s); - bool nomore(); - unsigned arghex(); - - inline void shift_arg_formula(ld& x, const reaction_t& r = reaction_t()) { shift(); x = argf(); - #if CAP_ANIMATIONS - anims::animate_parameter(x, args(), r); - #endif - } - - void init(int _argc, char **_argv); - - void launch_dialog(const reaction_t& r = reaction_t()); - - extern int curphase; - - void phaseerror(int x); - - // returned values: 0 = ok, 1 = not recognized, 2 = shift phase - int readCommon(); - int readLocal(); - -// an useful macro -#define PHASE(x) { if(arg::curphase > x) arg::phaseerror(x); else if(arg::curphase < x) return 2; } -#define PHASEFROM(x) { if(arg::curphase < x) return 2; } - - inline void cheat() { autocheat = true; cheater++; timerghost = false; } - -#define TOGGLE(x, param, act) \ -else if(args()[0] == '-' && args()[1] == x && !args()[2]) { PHASEFROM(2); showstartmenu = false; act; } \ -else if(args()[0] == '-' && args()[1] == x && args()[2] == '1') { PHASEFROM(2); showstartmenu = false; if(!param) act; } \ -else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2); showstartmenu = false; if(param) act; } - - - void read(int phase); - - eLand readland(const string& ss); - eItem readItem(const string& ss); - eMonster readMonster(const string& ss); - -#endif - } - #if CAP_TOUR namespace tour { extern bool on; @@ -1228,25 +1101,7 @@ template V callhandlers(V zero, hookset *h, U&. return zero; } -struct msginfo { - int stamp; - time_t rtstamp; - int gtstamp; - int turnstamp; - char flashout; - char spamtype; - int quantity; - string msg; - }; - -int watercolor(int phase); -bool doHighlight(); -void buildHelpText(); -void buildCredits(); -void setAppropriateOverview(); -bool quitsaves(); - -extern const char* COLORBAR; +string XLAT(string); #define GLERR(call) glError(call, __FILE__, __LINE__) @@ -1503,107 +1358,6 @@ template array make_array(T a, T b, T c, T d) { array x; x[0 template array make_array(T a, T b, T c) { array x; x[0] = a; x[1] = b; x[2] = c; return x; } template array make_array(T a, T b) { array x; x[0] = a; x[1] = b; return x; } -struct supersaver { - string name; - virtual string save() = 0; - virtual void load(const string& s) = 0; - virtual bool dosave() = 0; - virtual void reset() = 0; - virtual ~supersaver() {}; - }; - -typedef vector> saverlist; - -extern saverlist savers; - -#if CAP_CONFIG - -template struct dsaver : supersaver { - T& val; - T dft; - bool dosave() { return val != dft; } - void reset() { val = dft; } - dsaver(T& val) : val(val) { } - }; - -template struct saver : dsaver {}; - -template void addsaver(T& i, U name, V dft) { - auto s = make_shared> (i); - s->dft = dft; - s->name = name; - savers.push_back(s); - } - -template void addsaver(T& i, string name) { - addsaver(i, name, i); - } - -template struct saverenum : supersaver { - T& val; - T dft; - bool dosave() { return val != dft; } - void reset() { val = dft; } - saverenum(T& v) : val(v) { } - string save() { return its(int(val)); } - void load(const string& s) { val = (T) atoi(s.c_str()); } - }; - -template void addsaverenum(T& i, U name, T dft) { - auto s = make_shared> (i); - s->dft = dft; - s->name = name; - savers.push_back(s); - } - -template void addsaverenum(T& i, U name) { - addsaverenum(i, name, i); - } - -template<> struct saver : dsaver { - saver(int& val) : dsaver(val) { } - string save() { return its(val); } - void load(const string& s) { val = atoi(s.c_str()); } - }; - -template<> struct saver : dsaver { - saver(char& val) : dsaver(val) { } - string save() { return its(val); } - void load(const string& s) { val = atoi(s.c_str()); } - }; - -template<> struct saver : dsaver { - saver(bool& val) : dsaver(val) { } - string save() { return val ? "yes" : "no"; } - void load(const string& s) { val = isize(s) && s[0] == 'y'; } - }; - -template<> struct saver : dsaver { - saver(unsigned& val) : dsaver(val) { } - string save() { return itsh(val); } - void load(const string& s) { val = (unsigned) strtoll(s.c_str(), NULL, 16); } - }; - -template<> struct saver : dsaver { - saver(string& val) : dsaver(val) { } - string save() { return val; } - void load(const string& s) { val = s; } - }; - -string fts(ld val, int prec); -string itsh(int x); - -template<> struct saver : dsaver { - saver(ld& val) : dsaver(val) { } - string save() { return fts(val, 10); } - void load(const string& s) { - if(s == "0.0000000000e+000") ; // ignore! - else val = atof(s.c_str()); - } - }; - -#endif - namespace daily { extern bool on; extern int daily_id; @@ -1736,6 +1490,3 @@ static const color_t NOCOLOR = 0; #define IS(z) #define EX -namespace hr { - inline bool movepcto(const movedir& md) { return movepcto(md.d, md.subdir); } - } diff --git a/models.cpp b/models.cpp index 12258d70..34b608f9 100644 --- a/models.cpp +++ b/models.cpp @@ -96,6 +96,11 @@ EX namespace polygonal { pair compute(ld x, ld y) { return compute(x,y,deg); } EX } +#if HDR +inline bool mdAzimuthalEqui() { return among(pmodel, mdEquidistant, mdEquiarea, mdEquivolume); } +inline bool mdBandAny() { return among(pmodel, mdBand, mdBandEquidistant, mdBandEquiarea, mdSinusoidal); } +#endif + EX namespace models { EX string formula = "z^2"; diff --git a/quit.cpp b/quit.cpp index de0e06b1..4b9141c6 100644 --- a/quit.cpp +++ b/quit.cpp @@ -3,7 +3,7 @@ namespace hr { -bool quitsaves() { return (items[itOrbSafety] && CAP_SAVE && !archimedean); } +EX bool quitsaves() { return (items[itOrbSafety] && CAP_SAVE && !archimedean); } EX bool needConfirmationEvenIfSaved() { return canmove && (gold() >= 30 || tkills() >= 50) && !cheater; diff --git a/shmup.cpp b/shmup.cpp index 63ef771e..b625c49d 100644 --- a/shmup.cpp +++ b/shmup.cpp @@ -82,7 +82,7 @@ struct monster { using namespace multi; -eItem targetRangedOrbKey(orbAction a); +eItem targetRangedOrbKey(enum orbAction a); eItem keyresult[MAXPLAYER]; ld fabsl(ld x) { return x>0?x:-x; } diff --git a/system.cpp b/system.cpp index 8aca82a3..5eb2600b 100644 --- a/system.cpp +++ b/system.cpp @@ -6,6 +6,33 @@ namespace hr { +#if HDR +namespace rg { + // possible parameters e.g. for restart_game and wrongmode + static const char nothing = 0; + static const char peace = 'P'; + static const char inv = 'i'; + static const char chaos = 'C'; + static const char tactic = 't'; + static const char tour = 'T'; + static const char yendor = 'y'; + static const char shmup = 's'; + static const char randpattern = 'r'; + static const char princess = 'p'; + static const char daily = 'd'; + static const char daily_off = 'D'; + static const char racing = 'R'; + static const char dualmode = 'U'; + + // wrongmode only -- marks 'global' achievements not related to the current mode + static const char global = 'x'; + // wrongmode only -- change vid.scfg.players then restart_game(rg::nothing) instead + static const char multi = 'm'; + // wrongmode only -- mark achievements for special geometries/variations + static const char special_geometry = 'g'; + } +#endif + EX bool game_active; EX bool cblind;