From af0d8f244d04cd55bd3caa8fc0600be8b61304d6 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Fri, 27 May 2011 02:50:59 +0000 Subject: [PATCH] - [+] 's' = slowwalk(lf, dir). ask which dir if not given and player. - [+] adds F_SNEAKING - [+] calls trymove - [+] removes F_SNEAKING - [+] effects: - [+] move slowly (2 times normal) - [+] never slip - [+] bonus on stealth check --- ai.c | 13 +++++++------ defs.h | 1 + flag.c | 17 +++++++++-------- io.c | 8 ++++++-- lf.c | 11 +++++++++++ move.c | 49 +++++++++++++++++++++++++++++++++++++------------ move.h | 1 + nexus.c | 2 +- 8 files changed, 73 insertions(+), 29 deletions(-) diff --git a/ai.c b/ai.c index e18b3aa..c080edd 100644 --- a/ai.c +++ b/ai.c @@ -385,7 +385,7 @@ flag_t *aigoto(lifeform_t *lf, cell_t *c, enum MOVEREASON why, void *data, int t if (lfhasflagval(lf, F_IGNORECELL, c->x, c->y, NA, NULL)) { char lfname[BUFLEN]; getlfname(lf, lfname); - dblog(".oO { %s cannot go to targecell %d,%d due to f_ignorecell flag }", lfname, c->x, c->y); + if (db) dblog(".oO { %s cannot go to targecell %d,%d due to f_ignorecell flag }", lfname, c->x, c->y); return NULL; } @@ -1492,16 +1492,17 @@ int aispellok(lifeform_t *lf, enum OBTYPE spellid, lifeform_t *victim, enum FLAG flag_t *willflag; flag_t *srflag; int srange = 5; - srflag = lfhasflag(lf, F_SWOOPRANGE); - if (srflag) { - srange = srflag->val[0]; - } willflag = lfhasflagval(lf, F_CANWILL, ot->id, NA, NA, NULL); if (willflag) { texttospellopts(f->text, NULL, NULL, NULL, &srange); if (!srange) srange = 5; } + // override... + srflag = lfhasflag(lf, F_SWOOPRANGE); + if (srflag) { + srange = srflag->val[0]; + } if (!haslof(lf->cell, victim->cell, LOF_NEED,NULL)) { @@ -1538,7 +1539,7 @@ int aispellok(lifeform_t *lf, enum OBTYPE spellid, lifeform_t *victim, enum FLAG } } if (!specificcheckok) { - dblog(".oO { cant cast %s - specific spell check failed }", ot ? ot->name : "?unkownspell?"); + if (db) dblog(".oO { cant cast %s - specific spell check failed }", ot ? ot->name : "?unkownspell?"); return B_FALSE; } diff --git a/defs.h b/defs.h index af94f42..b43c373 100644 --- a/defs.h +++ b/defs.h @@ -1792,6 +1792,7 @@ enum FLAG { F_HOMELEVOB, // when this monster is auto generated on a level, place // between v0 and v1 objects of type 'text' somewhere on // the level. + F_SNEAK, // 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_CANLEARN, // lf is able to learn skill val0 diff --git a/flag.c b/flag.c index 050e4f0..a93d1bc 100644 --- a/flag.c +++ b/flag.c @@ -27,6 +27,8 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, lifeform_t *lf; flag_t *f; map_t *redolight = NULL; + int redrawscreenatend = B_FALSE; + int redrawstatatend = B_FALSE; int i; // identified things mean all new flags are autmaticlaly known. @@ -170,8 +172,8 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, } } // player flags which cause a redraw - if (flagcausesredraw(f->pile->owner, f->id)) needredraw = B_TRUE; - if (flagcausesstatredraw(f->pile->owner, f->id)) statdirty = B_TRUE; + if (flagcausesredraw(f->pile->owner, f->id)) redrawscreenatend = B_TRUE; + if (flagcausesstatredraw(f->pile->owner, f->id)) redrawstatatend = B_TRUE; } else if (f->pile->ob) { if (announceobflaggain(f->pile->ob, f)) { f->known = B_TRUE; @@ -201,14 +203,17 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, } } - if ((gamemode == GM_GAMESTARTED) && (needredraw || statdirty || redolight)) { + if ((gamemode == GM_GAMESTARTED) && (redrawscreenatend || redrawstatatend || redolight)) { if (redolight) { dblog("CALCINGLIGHT from flag\n"); - needredraw = B_TRUE; + redrawscreenatend = B_TRUE; calclight(redolight); precalclos(player); } dblog("DRAWINGSCREEN from flag\n"); + + if (redrawscreenatend) needredraw = B_TRUE; + if (redrawstatatend) statdirty = B_TRUE; drawscreen(); } return f; @@ -426,10 +431,6 @@ void killflag(flag_t *f) { int redostat = B_FALSE; int redoscreen = B_FALSE; - if (f->id == F_SIZE) { - dblog("xxx"); - } - lf = f->pile->owner; if (gamemode == GM_GAMESTARTED) { diff --git a/io.c b/io.c index bcc1f45..9ea2e38 100644 --- a/io.c +++ b/io.c @@ -5064,7 +5064,7 @@ void drawlevelfor(lifeform_t *lf) { return; } - dbtimestart("drawscreen"); + //dbtimestart("drawscreen"); map = lf->cell->map; needredraw = B_FALSE; @@ -5114,7 +5114,7 @@ void drawlevelfor(lifeform_t *lf) { if (db) dblog("ending DRAWLEVEL"); sprintf(buf, "end. ndrawn was %d",ndrawn); - dbtimeend(buf); + //dbtimeend(buf); // move cursor to the player's position and blit if (ndrawn) { drawcursor(); @@ -5815,6 +5815,7 @@ void handleinput(void) { case 'n': trymove(player, chartodir(ch), B_TRUE); break; + // running case 'H': case 'J': case 'K': @@ -5825,6 +5826,9 @@ void handleinput(void) { case 'N': tryrun(player, chartodir(ch)); break; + case 's': // slowwalk + trysneak(player, D_NONE); + break; case '.': // wait addflag(player->flags, F_LASTCMD, NA, NA, NA, temp); if (count > 1) { diff --git a/lf.c b/lf.c index 1163251..9eb690c 100644 --- a/lf.c +++ b/lf.c @@ -4207,10 +4207,16 @@ int getmovespeed(lifeform_t *lf) { break; } + + if (lfhasflag(lf, F_SNEAK)) { + speed *= 2; + } + if (speed < 1) speed = 1; adjustspeedforwater(lf, &speed); + return speed; } @@ -12048,6 +12054,11 @@ int real_skillcheck(lifeform_t *lf, enum CHECKTYPE ct, int diff, int mod, int *r sumflags(lf->flags, F_ENHANCESEARCH, &bonus, NULL, NULL); othermod += bonus; } else if (ct == SC_STEALTH) { + if (attrib > 0) { + if (lfhasflag(lf, F_SNEAK)) { + othermod += 3; + } + } if (isairborne(lf)) { othermod += 5; } diff --git a/move.c b/move.c index 8d154ab..be102bd 100644 --- a/move.c +++ b/move.c @@ -1179,10 +1179,12 @@ int moveto(lifeform_t *lf, cell_t *newcell, int onpurpose, int dontclearmsg) { object_t *o,*nexto; object_t *slipob; - slip = getslipperyness(newcell, &slipob); - if (slip && !skillcheck(lf, SC_SLIP, slip, 0)) { - slipon(lf, slipob); - } + if (!lfhasflag(lf, F_SNEAK)) { + slip = getslipperyness(newcell, &slipob); + if (slip && !skillcheck(lf, SC_SLIP, slip, 0)) { + slipon(lf, slipob); + } + } // activate traps for (o = newcell->obpile->first ; o ; o = nexto ) { @@ -1476,6 +1478,26 @@ int tryrun(lifeform_t *lf, int dir) { return B_FALSE; } +int trysneak(lifeform_t *lf, int dir) { + if (dir == D_NONE) { + if (isplayer(lf)) { + char ques[BUFLEN]; + char ch; + sprintf(ques, "Carefully %s in which direction (- to cancel)", getmoveverb(lf)); + ch = askchar(ques, "yuhjklbn.-","-", B_FALSE); + dir = chartodir(ch); + if (dir == D_NONE) return B_TRUE; + } else { + return B_TRUE; + } + } + addflag(lf->flags, F_SNEAK, NA, NA, NA, NULL); + trymove(lf, dir, B_TRUE); + killflagsofid(lf->flags, F_SNEAK); + + return B_FALSE; +} + // try to pull lifeform towards cell c (or next to it) int pullnextto(lifeform_t *lf, cell_t *c) { int dir; @@ -1660,14 +1682,17 @@ int initiatemove(lifeform_t *lf, cell_t *cell, int *didmsg) { if (!isairborne(lf)) { int slip; object_t *slipob; - slip = getslipperyness(lf->cell, &slipob); - if (slip && !skillcheck(lf, SC_SLIP, slip, 0)) { - slipon(lf, slipob); - if (didmsg) *didmsg = B_TRUE; - // don't move - reason = E_OK; - return B_TRUE; - } + + if (!lfhasflag(lf, F_SNEAK)) { + slip = getslipperyness(lf->cell, &slipob); + if (slip && !skillcheck(lf, SC_SLIP, slip, 0)) { + slipon(lf, slipob); + if (didmsg) *didmsg = B_TRUE; + // don't move + reason = E_OK; + return B_TRUE; + } + } } // check for cursed objects in new cell + animals diff --git a/move.h b/move.h index c23964e..1b71066 100644 --- a/move.h +++ b/move.h @@ -27,5 +27,6 @@ void swapplaces(lifeform_t *lf1, lifeform_t *lf2, int onpurpose); int teleportto(lifeform_t *lf, cell_t *c, int wantsmoke); int trymove(lifeform_t *lf, int dir, int onpurpose); int tryrun(lifeform_t *lf, int dir); +int trysneak(lifeform_t *lf, int dir); int walkoffmap(lifeform_t *lf, int dir, int onpurpose); int willmove(lifeform_t *lf, int dir, enum ERROR *error); diff --git a/nexus.c b/nexus.c index 6ac9221..f9300f5 100644 --- a/nexus.c +++ b/nexus.c @@ -983,7 +983,7 @@ int rollhitdice(lifeform_t *lf) { int roll = 0; int i; float mod; - int db = B_TRUE; + int db = B_FALSE; f = hasflag(lf->flags, F_HITDICE); if (f) {