diff --git a/data.c b/data.c index 27bd798..8854f12 100755 --- a/data.c +++ b/data.c @@ -174,8 +174,10 @@ void initcommands(void) { addcommand(CMD_UP, '<', "Go up stairs."); addcommand(CMD_DOWN, '>', "Go down stairs, enter a shop/portal."); addcommand(CMD_GO, 'G', "Go to a set position (pathfind)."); + addcommand(CMD_EXPLORE, 'z', "Auto-explore the current level"); // Actions - addcommand(CMD_AGAIN, 'g', "Repeat last action."); + addcommand(CMD_AGAIN, 'g', "Repeat last action (do aGain)."); + addcommand(CMD_REPEATSPELL, 'p', "RePeat last spell/ability."); addcommand(CMD_REST, '.', "Rest once."); addcommand(CMD_PICKUP, ',', "Pick up something from the ground."); addcommand(CMD_COMMS, 'c', "Chat/Communicate with someone."); diff --git a/defs.h b/defs.h index a92bb8f..b33c43a 100755 --- a/defs.h +++ b/defs.h @@ -3748,6 +3748,7 @@ enum FLAG { F_CAREFULMOVE, // moving slowly on purpose to avoid slipping. F_AUTOCMD, // val0 = how many times to repeat this F_LASTCMD, // text[0] = last command performed, v0/1 = x/y of cell, v2=various + F_LASTSPELL, // val0=id of last spell cast, for player only F_WILLTHROW, // this lf will treat obid v0 as a thrown missile. F_CANSTUDY, // lf can study spells from school v0 F_CANLEARN, // lf is able to learn skill val0 @@ -4373,8 +4374,9 @@ enum FLAG { F_XRAYVIS, //val0=num of walls we can see through F_CANSEETHROUGHMAT, //val0=kind of material you can see through F_CANSEETHROUGHLF, // larger lifeforms don't block los for us - F_PATHFINDING, // you are following a path via 'G' + F_PATHFINDING, // you are following a path via 'G' or 'z' // to coords v0,v1 on mapid v2 + // str = G or z F_SPRINTING, // you are sprinting. F_WOUNDING, // increase all damage done by this lf by v0 F_WINDSHIELD,// has a windshield protecting against missiles of speed @@ -4752,6 +4754,7 @@ enum COMMAND { CMD_DROP, CMD_DROPMULTI, CMD_EAT, + CMD_EXPLORE, CMD_FIRE, CMD_FIRENEW, CMD_FORCEATTACK, @@ -4778,6 +4781,7 @@ enum COMMAND { CMD_QUAFF, CMD_QUIT, CMD_READ, + CMD_REPEATSPELL, CMD_REST, CMD_RESTFULL, CMD_SAVEQUIT, diff --git a/find_unused_letters.sh b/find_unused_letters.sh new file mode 100755 index 0000000..81d7d36 --- /dev/null +++ b/find_unused_letters.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo {a..z} {A..Z} | tr ' ' '\n' | egrep -v $(grep addcom *.c | grep -v '//' | grep -v \\\\ | awk -F\' '{print $2}' | egrep "[a-zA-Z]" | tr '\n' '|' | sed 's/^|//;s/|$//') diff --git a/io.c b/io.c index dc2f325..8264ff1 100755 --- a/io.c +++ b/io.c @@ -11272,6 +11272,9 @@ void handleinput(void) { case CMD_GO: // go somewhere (pathfind) startpathfind(); break; + case CMD_EXPLORE: // autoexplore + startexplore(B_TRUE); + break; case CMD_HELP: // help dohelp('?'); break; @@ -11313,6 +11316,14 @@ void handleinput(void) { case CMD_MEMMAGIC: // 'M'emorise magic/ability shortcut domemmagic(); break; + case CMD_REPEATSPELL: // 're'p'eat last spell/ability + f = hasflag(player->flags, F_LASTSPELL); + if (f) { + domagic(f->val[0], NA, NA); + } else { + msg("There is no previous spell to repeat."); + } + break; case CMD_UP: // go up if (isprone(player)) { standup(player); @@ -15262,6 +15273,33 @@ void showpath(lifeform_t *lf) { restoregamewindows(); } + +// TODO: not quite working. sometimes seems to flip back and forth between 2 positions +int startexplore(int announce) { + cell_t *c; + c = get_explore_target(player); + if (!c) { + msg("Can't find any unknown cells to explore."); + return B_TRUE; + } + killflagsofid(player->flags, F_PATHFINDING); + + if (ai_createpathto(player, c)) { + addflag(player->flags, F_PATHFINDING, c->x, c->y, player->cell->map->id, "z"); + //msg("Going from %d,%d to unexplored %d,%d", player->cell->x, player->cell->y, c->x, c->y); + if (announce) { + msg("Starting auto-explore."); + } else { + msg("Continuing auto-explore."); + } + } else { + msg("Pathfind failed from %d,%d to unexplored %d,%d", player->cell->x, player->cell->y, c->x, c->y); + } + + + return B_FALSE; +} + void startpathfind(void) { cell_t *c = NULL; c = askcoords("Go to where?", "Goto->", TT_NONE, player, UNLIMITED, LOF_DONTNEED, B_FALSE); @@ -15274,11 +15312,10 @@ void startpathfind(void) { (haslos(player, c) && !cellwalkable(player, c, NULL))) { msg("You don't know how to get there."); return; - } // try to find path. if (ai_createpathto(player, c)) { - addflag(player->flags, F_PATHFINDING, c->x, c->y, player->cell->map->id, NULL); + addflag(player->flags, F_PATHFINDING, c->x, c->y, player->cell->map->id, "G"); } else { msg("You don't know how to get there."); } diff --git a/io.h b/io.h index ce224f7..8ff43c5 100755 --- a/io.h +++ b/io.h @@ -158,6 +158,7 @@ int showhiscoreline(void *hilitescore, int ncols, char **argv, char **colname); void showlfarmour(lifeform_t *lf); void showlfstats(lifeform_t *lf, int showall); void showpath(lifeform_t *lf); +int startexplore(int announce); void startpathfind(void); void textwithcol(WINDOW *win, char *buf); void textwithcol_real(WINDOW *win, char *buf, int resetcolatend); diff --git a/lf.c b/lf.c index dadd4ed..3dd2043 100755 --- a/lf.c +++ b/lf.c @@ -2156,6 +2156,11 @@ int castspell(lifeform_t *lf, enum OBTYPE sid, lifeform_t *targlf, object_t *tar // lose mp losemp(lf, cost); + // remember spell for rePeat command + if (isplayer(lf)) { + modflag(lf->flags, F_LASTSPELL, sid, NA, NA, NULL); + } + // spell fails? // miscast chance? if (isplayer(lf) && !hasjob(lf, J_GOD)) { @@ -26512,6 +26517,10 @@ int useability(lifeform_t *lf, enum OBTYPE aid, lifeform_t *who, cell_t *where) cwflag = lfhasflagval(lf, F_CANWILL, aid, NA, NA, NULL); rv = abilityeffects(lf, aid, where, who, cwflag); + // remember ability for rePeat command + if (isplayer(lf)) { + modflag(lf->flags, F_LASTSPELL, aid, NA, NA, NULL); + } if (!rv) { flag_t *f; diff --git a/map.c b/map.c index a299420..5641d82 100755 --- a/map.c +++ b/map.c @@ -5,6 +5,7 @@ #include #include #include +#include "ai.h" #include "astar.h" #include "attack.h" #include "defs.h" @@ -3044,6 +3045,62 @@ cell_t *get_closest_adjcell(cell_t *src, cell_t *dst) { return NULL; } +// find the closest known & walkable cell, with an adjacent unknown one +// note: only works when lf == player at the moment +cell_t *get_explore_target(lifeform_t *lf) { + int i; + int maxdist = MAXOF(MAX_MAPW, MAX_MAPH); + cell_t *src, **poss, *sel = NULL; + int x,y; + int nposs; + if (!lf) return NULL; + src = lf->cell; + for (i = 1;(i< maxdist && !sel); i++) { + int nok = 0; + nposs = 0; + poss = malloc(sizeof(cell_t *)*(i+2)*4); + //msg("player is %d,%d, dist %d.", lf->cell->x, lf->cell->y, i); + //msg("Box is %d,%d to %d, %d.", lf->cell->x - i, lf->cell->y - i, + // lf->cell->x + i, lf->cell->y + i); + for (y = lf->cell->y - i; y <= lf->cell->y + i; y++) { + for (x = lf->cell->x - i; x <= lf->cell->x + i; ) { + cell_t *newcell = NULL; + + //msg("Checking %d,%d.",x, y); + newcell = getcellat(lf->cell->map,x,y); + if (newcell) { + nok++; + if (newcell->known != KG_UNKNOWN && + cellwalkable(lf, newcell, NULL) && + countadjcellsknown(newcell, B_FALSE, DT_COMPASS)) { + poss[nposs] = newcell; + nposs++; + } + } + + + // change x based on where we are in te square of + // possible cells + if (y == lf->cell->y - i || y== lf->cell->y + i) { + x++; + } else { + x += (i*2); + } + } + } + //msg("%d/%d possible cells at distance %d.",nposs, nok, i); + if (nposs) { + sel = poss[rnd(0,nposs-1)]; + } + free(poss); + if (nok == 0) { + // no valid cells + break; + } + } + return sel; +} + int getdoorlockdiff(int depth) { return 70 + (depth*3); } @@ -3456,6 +3513,31 @@ int countadjcellswithflag(cell_t *cell, enum FLAG fid, int dirtype) { return count; } +int countadjcellsknown(cell_t *cell, int wantknown, int dirtype) { + int d; + int count = 0; + int start,end; + cell_t *newcell; + if (dirtype == DT_ORTH) { + start = D_N; + end = D_W; + } else { // ie. DT_COMPASS + start = DC_N; + end = DC_NW; + } + for (d = start; d <= end; d++) { + newcell = getcellindir(cell, d); + if (newcell) { + if (wantknown && (newcell->known != KG_UNKNOWN)) { + count++; + } else if (!wantknown && (newcell->known == KG_UNKNOWN)) { + count++; + } + } + } + return count; +} + int countadjcellsoftype(cell_t *cell, enum CELLTYPE id, int dirtype) { int d; int count = 0; @@ -7963,6 +8045,15 @@ void forgetcells(map_t *map, int amt) { } } +cell_t *getcellindirdist(cell_t *src, int dir, int dist) { + cell_t *c = src; + int i; + for (i = 0; (i < dist && c); i++) { + c = getcellindir(c,dir); + } + return c; +} + cell_t *getcellindir(cell_t *cell, int dir) { cell_t *newcell; int newx,newy; diff --git a/map.h b/map.h index 82f92fd..22707f2 100755 --- a/map.h +++ b/map.h @@ -72,6 +72,7 @@ object_t *gettopobject(cell_t *where, int forglyph); //void calclight(map_t *map); int calcroompos(map_t *map, int w, int h, int xmargin, int ymargin, int *bx, int *by, int force, int stayclose); int compassdir(int orthdir); +int countadjcellsknown(cell_t *cell, int wantknown, int dirtype); int countadjcellsoftype(cell_t *cell, enum CELLTYPE id, int dirtype); int countadjrooms(cell_t *cell, int dirtype); int countadjcellswithflag(cell_t *cell, enum FLAG fid, int dirtype); @@ -141,8 +142,10 @@ room_t *findroom(map_t *m, int roomid); map_t *findsurfaceexitmap(map_t *m); void forgetcells(map_t *map, int amt); cell_t *getcellindir(cell_t *cell, int dir); +cell_t *getcellindirdist(cell_t *src, int dir, int dist); enum TEMPERATURE getcelltemp(cell_t *c, int *actualtemp); vault_t *getcellvault(cell_t *c); +cell_t *get_explore_target(lifeform_t *lf); cell_t *getclosestroomcell(lifeform_t *lf, int roomid); int getnewdigdir(cell_t *cell, int lastdir, int turnpct, int *moved); int getobchance(int habitat); diff --git a/nexus.c b/nexus.c index 160afaf..d35fa40 100755 --- a/nexus.c +++ b/nexus.c @@ -1145,7 +1145,9 @@ void donextturn(map_t *map) { // pathfinding? if (donormalmove && isplayer(who)) { - if (lfhasflag(who, F_PATHFINDING)) { + flag_t *pff; + pff = lfhasflag(who, F_PATHFINDING); + if (pff) { cell_t *c; // follow..... c = ai_getnextcellinpath(who); @@ -1175,8 +1177,16 @@ void donextturn(map_t *map) { } } } else { + int keepgoing = B_FALSE; msg("Arrived at destination."); + if (streq(pff->text, "z")) { + keepgoing = B_TRUE; + } stoppathfinding(who); + if (keepgoing) { + startexplore(B_FALSE); + } + } } }