diff --git a/commandline.cpp b/commandline.cpp new file mode 100644 index 00000000..c2710ac2 --- /dev/null +++ b/commandline.cpp @@ -0,0 +1,428 @@ +#if CAP_COMMANDLINE +const char *scorefile = "hyperrogue.log"; +const char *conffile = "hyperrogue.ini"; +string levelfile = "hyperrogue.lev"; +string picfile = "hyperrogue.pic"; +const char *musicfile = ""; +const char *loadlevel = NULL; + +eLand readland(const char *s) { + string ss = s; + if(ss == "II") return laCrossroads2; + if(ss == "III") return laCrossroads3; + if(ss == "IV") return laCrossroads4; + if(ss == "V") return laCrossroads5; + for(int l=0; l, version " VER "\n"); + +#ifndef NOLICENSE + printf("released under GNU General Public License version 2 and thus\n"); + printf("comes with absolutely no warranty; see COPYING for details\n"); +#endif + + #ifdef FHS + static string sbuf, cbuf; + if(getenv("HOME")) { + sbuf = getenv("HOME"); sbuf += "/."; sbuf += scorefile; + cbuf = getenv("HOME"); cbuf += "/."; cbuf += conffile; + scorefile = sbuf.c_str(); + conffile = cbuf.c_str(); + } + #endif + } + +int arg::readCommon() { + if(argis("-c")) { PHASE(1); shift(); conffile = args(); } + else if(argis("-s")) { PHASE(1); shift(); scorefile = args(); } + else if(argis("-m")) { PHASE(1); shift(); musicfile = args(); } +#if CAP_SDLAUDIO + else if(argis("-se")) { PHASE(1); shift(); wheresounds = args(); } +#endif +#if CAP_EDIT + else if(argis("-lev")) { shift(); levelfile = args(); } + else if(argis("-pic")) { shift(); picfile = args(); } + else if(argis("-load")) { PHASE(3); shift(); mapstream::loadMap(loadlevel); } +#endif + else if(argis("-canvas")) { + firstland = specialland = laCanvas; + shift(); + if(args()[1] == 0) mapeditor::whichCanvas = args()[0]; + else mapeditor::canvasback = strtol(args(), NULL, 16); + } + else if(argis("-back")) { + shift(); backcolor = strtol(args(), NULL, 16); + } + else if(argis("-borders")) { + shift(); bordcolor = strtol(args(), NULL, 16); + } + else if(argis("-fore")) { + shift(); forecolor = strtol(args(), NULL, 16); + } + else if(argis("-W2")) { + shift(); cheatdest = readland(args()); autocheat = true; + showstartmenu = false; + } + else if(argis("-W")) { + shift(); + firstland0 = firstland = specialland = readland(args()); autocheat = true; + showstartmenu = false; + } + else if(argis("-I")) { + PHASE(3) cheater++; timerghost = false; + shift(); eItem i = readItem(args()); + shift(); items[i] = argi(); + } + else if(argis("-IP")) { + PHASE(3) cheater++; timerghost = false; + shift(); eItem i = readItem(args()); + shift(); int q = argi(); + placeItems(q, i); + } + else if(argis("-ambush")) { + // make all ambushes use the given number of dogs + // example: hyper -W Hunt -IP Shield 1 -ambush 60 + PHASE(3) cheater++; timerghost = false; + shift(); ambushval = argi(); + } + else if(argis("-M")) { + PHASE(3) cheater++; timerghost = false; + shift(); eMonster m = readMonster(args()); + shift(); int q = argi(); + printf("m = %s q = %d\n", dnameof(m), q); + restoreGolems(q, m, 7); + } + else if(argis("-L")) { + printf("Treasures:\n"); + for(int i=1; i - fieldpattern: quotient by the given (must be followed by qpar)\n"); + printf(" -qpar - fieldpattern: use the given prime instead of 43\n"); + printf(" -cs - fieldpattern: set subpath to the given (cannot be followed by qpar)\n"); + printf(" -csp - fieldpattern: find the subpath of order (cannot be followed by qpar)\n"); + printf(" -S* - toggle Shmup\n"); + printf(" -P n - switch Shmup number of players (n=1..7)\n"); + printf(" -PM - switch the model index\n"); + printf(" -H* - toggle Hardcore\n"); + printf(" -T* - toggle Tactical\n"); + printf(" -7* - toggle heptagonal mode\n"); + printf(" -C* - toggle Chaos mode\n"); + printf(" -R* - toggle Random Pattern\n"); + printf(" -Y id - enable Yendor, level id\n"); + printf(" -D - disable all the special game modes\n"); + printf(" -L - list of features\n"); + printf(" -debugf 7 - output debugging information to hyperrogue-debug.txt\n"); + printf(" -debuge 7 - output debugging information to stderr\n"); + printf(" -offline - don't connect to Steam (for Steam versions)\n"); + printf(" -I ITEM n - start with n of ITEM (activates cheat and disables ghosts)\n"); + printf(" -fix - fix the seed\n"); + printf("Toggles: -o0 disables, -o1 enables, -o switches"); + printf("Not all options are documented, see hyper.cpp"); + exit(0); + } + else if(ca::readArg()) ; + else return 1; + return 0; + } + +purehookset hooks_config; + +hookset *hooks_args; + +namespace arg { + int argc; char **argv; + int curphase; + + auto ah = addHook(hooks_args, 0, readCommon); + + void read(int phase) { + curphase = phase; + callhooks(hooks_config); + while(argc) { + for(auto& h: *hooks_args) { + int r = h.second(); if(r == 2) return; if(r == 0) { lshift(); goto cont; } + } + printf("Unknown option: %s\n", args()); + exit(3); + cont: ; + } + } + } +#endif diff --git a/compileunits.h b/compileunits.h index 993a01f7..076cf57b 100644 --- a/compileunits.h +++ b/compileunits.h @@ -81,6 +81,7 @@ bool inv::on; #if ISMOBILE==0 #include #endif +#include "commandline.cpp" #endif #if IN_CU(1) diff --git a/hyper.cpp b/hyper.cpp index ee02988a..75ba1d41 100644 --- a/hyper.cpp +++ b/hyper.cpp @@ -40,402 +40,6 @@ void moreStack() { } #endif -eLand readland(const char *s) { - string ss = s; - if(ss == "II") return laCrossroads2; - if(ss == "III") return laCrossroads3; - if(ss == "IV") return laCrossroads4; - if(ss == "V") return laCrossroads5; - for(int l=0; l, version " VER "\n"); - -#ifndef NOLICENSE - printf("released under GNU General Public License version 2 and thus\n"); - printf("comes with absolutely no warranty; see COPYING for details\n"); -#endif - - #ifdef FHS - static string sbuf, cbuf; - if(getenv("HOME")) { - sbuf = getenv("HOME"); sbuf += "/."; sbuf += scorefile; - cbuf = getenv("HOME"); cbuf += "/."; cbuf += conffile; - scorefile = sbuf.c_str(); - conffile = cbuf.c_str(); - } - #endif - } - -int arg::readCommon() { - if(argis("-c")) { PHASE(1); shift(); conffile = args(); } - else if(argis("-s")) { PHASE(1); shift(); scorefile = args(); } - else if(argis("-m")) { PHASE(1); shift(); musicfile = args(); } -#if CAP_SDLAUDIO - else if(argis("-se")) { PHASE(1); shift(); wheresounds = args(); } -#endif -#if CAP_EDIT - else if(argis("-lev")) { shift(); levelfile = args(); } - else if(argis("-pic")) { shift(); picfile = args(); } - else if(argis("-load")) { PHASE(3); shift(); mapstream::loadMap(loadlevel); } -#endif - else if(argis("-canvas")) { - firstland = specialland = laCanvas; - shift(); - if(args()[1] == 0) mapeditor::whichCanvas = args()[0]; - else mapeditor::canvasback = strtol(args(), NULL, 16); - } - else if(argis("-back")) { - shift(); backcolor = strtol(args(), NULL, 16); - } - else if(argis("-borders")) { - shift(); bordcolor = strtol(args(), NULL, 16); - } - else if(argis("-fore")) { - shift(); forecolor = strtol(args(), NULL, 16); - } - else if(argis("-W2")) { - shift(); cheatdest = readland(args()); autocheat = true; - showstartmenu = false; - } - else if(argis("-W")) { - shift(); - firstland0 = firstland = specialland = readland(args()); autocheat = true; - showstartmenu = false; - } - else if(argis("-I")) { - PHASE(3) cheater++; timerghost = false; - shift(); eItem i = readItem(args()); - shift(); items[i] = argi(); - } - else if(argis("-IP")) { - PHASE(3) cheater++; timerghost = false; - shift(); eItem i = readItem(args()); - shift(); int q = argi(); - placeItems(q, i); - } - else if(argis("-ambush")) { - // make all ambushes use the given number of dogs - // example: hyper -W Hunt -IP Shield 1 -ambush 60 - PHASE(3) cheater++; timerghost = false; - shift(); ambushval = argi(); - } - else if(argis("-M")) { - PHASE(3) cheater++; timerghost = false; - shift(); eMonster m = readMonster(args()); - shift(); int q = argi(); - printf("m = %s q = %d\n", dnameof(m), q); - restoreGolems(q, m, 7); - } - else if(argis("-L")) { - printf("Treasures:\n"); - for(int i=1; i - fieldpattern: quotient by the given (must be followed by qpar)\n"); - printf(" -qpar - fieldpattern: use the given prime instead of 43\n"); - printf(" -cs - fieldpattern: set subpath to the given (cannot be followed by qpar)\n"); - printf(" -csp - fieldpattern: find the subpath of order (cannot be followed by qpar)\n"); - printf(" -S* - toggle Shmup\n"); - printf(" -P n - switch Shmup number of players (n=1..7)\n"); - printf(" -PM - switch the model index\n"); - printf(" -H* - toggle Hardcore\n"); - printf(" -T* - toggle Tactical\n"); - printf(" -7* - toggle heptagonal mode\n"); - printf(" -C* - toggle Chaos mode\n"); - printf(" -R* - toggle Random Pattern\n"); - printf(" -Y id - enable Yendor, level id\n"); - printf(" -D - disable all the special game modes\n"); - printf(" -L - list of features\n"); - printf(" -debugf 7 - output debugging information to hyperrogue-debug.txt\n"); - printf(" -debuge 7 - output debugging information to stderr\n"); - printf(" -offline - don't connect to Steam (for Steam versions)\n"); - printf(" -I ITEM n - start with n of ITEM (activates cheat and disables ghosts)\n"); - printf(" -fix - fix the seed\n"); - printf("Toggles: -o0 disables, -o1 enables, -o switches"); - printf("Not all options are documented, see hyper.cpp"); - exit(0); - } - else if(ca::readArg()) ; - else return 1; - return 0; - } - hookset *hooks_main; #ifndef NOMAIN @@ -445,11 +49,15 @@ int main(int argc, char **argv) { #if ISLINUX moreStack(); #endif +#endif +#if CAP_COMMANDLINE arg::init(argc, argv); initializeCLI(); #endif initAll(); +#if CAP_COMMANDLINE arg::read(3); +#endif if(showstartmenu) pushScreen(showStartMenu); mainloop(); @@ -458,30 +66,4 @@ int main(int argc, char **argv) { return 0; } #endif - -#if CAP_COMMANDLINE -purehookset hooks_config; - -hookset *hooks_args; - -namespace arg { - int argc; char **argv; - int curphase; - - auto ah = addHook(hooks_args, 0, readCommon); - - void read(int phase) { - curphase = phase; - callhooks(hooks_config); - while(argc) { - for(auto& h: *hooks_args) { - int r = h.second(); if(r == 2) return; if(r == 0) { lshift(); goto cont; } - } - printf("Unknown option: %s\n", args()); - exit(3); - cont: ; - } - } - } -#endif #endif