From 22ffe3b84e8a946966ca3b0e7a3666e4e6173a00 Mon Sep 17 00:00:00 2001 From: "Derek S. Ray" Date: Thu, 23 Apr 2015 23:04:35 -0400 Subject: [PATCH 1/3] initial pass for toning down Elbereth --- include/extern.h | 2 +- src/engrave.c | 14 +++++++++++--- src/monmove.c | 45 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/include/extern.h b/include/extern.h index d8e794276..462bbb821 100644 --- a/include/extern.h +++ b/include/extern.h @@ -652,7 +652,7 @@ E void FDECL(cant_reach_floor, (int,int,BOOLEAN_P,BOOLEAN_P)); E const char *FDECL(surface, (int,int)); E const char *FDECL(ceiling, (int,int)); E struct engr *FDECL(engr_at, (XCHAR_P,XCHAR_P)); -E int FDECL(sengr_at, (const char *,XCHAR_P,XCHAR_P)); +E int FDECL(sengr_at, (const char *,XCHAR_P,XCHAR_P,BOOLEAN_P)); E void FDECL(u_wipe_engr, (int)); E void FDECL(wipe_engr_at, (XCHAR_P,XCHAR_P,XCHAR_P)); E void FDECL(read_engr_at, (int,int)); diff --git a/src/engrave.c b/src/engrave.c index 5a8aa38f3..47e2b5af0 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -220,16 +220,24 @@ xchar x, y; /* Decide whether a particular string is engraved at a specified * location; a case-insensitive substring match used. * Ignore headstones, in case the player names herself "Elbereth". + * + * If strict checking is requested, the word is only considered to be + * present if it is intact and is the first word in the engraving. + * ("Elbereth burrito" matches; "o Elbereth" does not.) */ int -sengr_at(s, x, y) +sengr_at(s, x, y, strict) const char *s; xchar x, y; + boolean strict; { register struct engr *ep = engr_at(x,y); - return (ep && ep->engr_type != HEADSTONE && - ep->engr_time <= moves && strstri(ep->engr_txt, s) != 0); + if (ep && ep->engr_type != HEADSTONE && ep->engr_time <= moves) { + return strict ? (strncmpi(ep->engr_txt, s, strlen(s)) == 0) : + (strstri(ep->engr_txt, s) != 0); + } + return FALSE; } void diff --git a/src/monmove.c b/src/monmove.c index a7a3ca46f..82679886f 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -113,17 +113,42 @@ onscary(x, y, mtmp) int x, y; struct monst *mtmp; { - if (mtmp->isshk || mtmp->isgd || mtmp->iswiz || !mtmp->mcansee || - mtmp->mpeaceful || mtmp->data->mlet == S_HUMAN || - is_lminion(mtmp) || mtmp->data == &mons[PM_ANGEL] || - is_rider(mtmp->data) || mtmp->data == &mons[PM_MINOTAUR]) - return(FALSE); + boolean epresent = sengr_at("Elbereth", x, y, TRUE); + + /* creatures who are directly resistant to magical scaring: + * Rodney, lawful minions, angels, the Riders + */ + if (mtmp->iswiz || is_lminion(mtmp) + || mtmp->data == &mons[PM_ANGEL] + || is_rider(mtmp->data)) + return(FALSE); - return (boolean)(sobj_at(SCR_SCARE_MONSTER, x, y) || - sengr_at("Elbereth", x, y) || - (IS_ALTAR(levl[x][y].typ) && - (mtmp->data->mlet == S_VAMPIRE || - is_vampshifter(mtmp)))); + /* creatures who don't (or can't) fear a written Elbereth: + * all the above plus shopkeepers, guards, blind or + * peaceful monsters, humans, and minotaurs. + * + * Elbereth doesn't work in Gehennom, the Elemental Planes, or the + * Astral Plane; the influence of the Valar only reaches so far. + */ + if (epresent && (mtmp->isshk || mtmp->isgd || !mtmp->mcansee + || mtmp->mpeaceful || mtmp->data->mlet == S_HUMAN + || mtmp->data == &mons[PM_MINOTAUR] + || Inhell || In_endgame(&u.uz))) + return(FALSE); + + /* should this still be true for defiled/molochian altars? */ + if (IS_ALTAR(levl[x][y].typ) && (mtmp->data->mlet == S_VAMPIRE + || is_vampshifter(mtmp))) + return(TRUE); + + /* if the player isn't actually on the square OR the player's image + * isn't displaced to the square, no protection is being granted + * + * the scare monster scroll, though, is quite powerful. + */ + return (boolean)(sobj_at(SCR_SCARE_MONSTER, x, y) + || (epresent && ((u.ux == x && u.uy == y) + || (Displaced && mtmp->mux == x && mtmp->muy == y)))); } /* regenerate lost hit points */ From fb8a071a392298612d185f7bc22c19b9de4f864f Mon Sep 17 00:00:00 2001 From: "Derek S. Ray" Date: Mon, 27 Apr 2015 18:18:16 -0400 Subject: [PATCH 2/3] finish up the changes to trigger erosion on use Elbereth is a magical power, and like everything else, magic eventually gets used up... even for burned engravings. --- include/extern.h | 4 ++-- src/engrave.c | 36 +++++++++++++++++++----------------- src/mklev.c | 4 ++-- src/monmove.c | 18 +++++++++++++----- src/zap.c | 6 +++--- 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/include/extern.h b/include/extern.h index 462bbb821..c43e751d7 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.5 extern.h $NHDT-Date: 1429755449 2015/04/23 02:17:29 $ $NHDT-Branch: master $:$NHDT-Revision: 1.477 $ */ +/* NetHack 3.5 extern.h $NHDT-Date: 1430172934 2015/04/27 22:15:34 $ $NHDT-Branch: derek-elbereth $:$NHDT-Revision: 1.485 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -654,7 +654,7 @@ E const char *FDECL(ceiling, (int,int)); E struct engr *FDECL(engr_at, (XCHAR_P,XCHAR_P)); E int FDECL(sengr_at, (const char *,XCHAR_P,XCHAR_P,BOOLEAN_P)); E void FDECL(u_wipe_engr, (int)); -E void FDECL(wipe_engr_at, (XCHAR_P,XCHAR_P,XCHAR_P)); +E void FDECL(wipe_engr_at, (XCHAR_P,XCHAR_P,XCHAR_P,BOOLEAN_P)); E void FDECL(read_engr_at, (int,int)); E void FDECL(make_engr_at, (int,int,const char *,long,XCHAR_P)); E void FDECL(del_engr_at, (int,int)); diff --git a/src/engrave.c b/src/engrave.c index 47e2b5af0..c601ec4b6 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 engrave.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.5 engrave.c $NHDT-Date: 1430172943 2015/04/27 22:15:43 $ $NHDT-Branch: derek-elbereth $:$NHDT-Revision: 1.49 $ */ /* NetHack 3.5 engrave.c $Date: 2012/12/20 01:48:36 $ $Revision: 1.39 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -245,27 +245,29 @@ u_wipe_engr(cnt) register int cnt; { if (can_reach_floor(TRUE)) - wipe_engr_at(u.ux, u.uy, cnt); + wipe_engr_at(u.ux, u.uy, cnt, FALSE); } void -wipe_engr_at(x,y,cnt) -register xchar x,y,cnt; +wipe_engr_at(x,y,cnt,magical) +register xchar x,y,cnt,magical; { - register struct engr *ep = engr_at(x,y); + register struct engr *ep = engr_at(x,y); - /* Headstones are indelible */ - if(ep && ep->engr_type != HEADSTONE){ - if(ep->engr_type != BURN || is_ice(x,y)) { - if(ep->engr_type != DUST && ep->engr_type != ENGR_BLOOD) { - cnt = rn2(1 + 50/(cnt+1)) ? 0 : 1; - } - wipeout_text(ep->engr_txt, (int)cnt, 0); - while(ep->engr_txt[0] == ' ') - ep->engr_txt++; - if(!ep->engr_txt[0]) del_engr(ep); - } - } + /* Headstones are indelible */ + if(ep && ep->engr_type != HEADSTONE) { + debugpline1("asked to erode %d characters", cnt); + if(ep->engr_type != BURN || is_ice(x,y) || (magical && !rn2(2))) { + if(ep->engr_type != DUST && ep->engr_type != ENGR_BLOOD) { + cnt = rn2(1 + 50/(cnt+1)) ? 0 : 1; + debugpline1("actually eroding %d characters", cnt); + } + wipeout_text(ep->engr_txt, (int)cnt, 0); + while(ep->engr_txt[0] == ' ') + ep->engr_txt++; + if(!ep->engr_txt[0]) del_engr(ep); + } + } } void diff --git a/src/mklev.c b/src/mklev.c index b7cfc8e90..95115f32e 100644 --- a/src/mklev.c +++ b/src/mklev.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 mklev.c $NHDT-Date: 1426465436 2015/03/16 00:23:56 $ $NHDT-Branch: debug $:$NHDT-Revision: 1.25 $ */ +/* NetHack 3.5 mklev.c $NHDT-Date: 1430172946 2015/04/27 22:15:46 $ $NHDT-Branch: derek-elbereth $:$NHDT-Revision: 1.38 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -482,7 +482,7 @@ int trap_type; if (trap_engravings[trap_type]) { make_engr_at(xx, yy-dy, trap_engravings[trap_type], 0L, DUST); - wipe_engr_at(xx, yy-dy, 5); /* age it a little */ + wipe_engr_at(xx, yy-dy, 5, FALSE); /* age it a little */ } } } diff --git a/src/monmove.c b/src/monmove.c index 82679886f..56e7b4871 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 monmove.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.5 monmove.c $NHDT-Date: 1430172947 2015/04/27 22:15:47 $ $NHDT-Branch: derek-elbereth $:$NHDT-Revision: 1.62 $ */ /* NetHack 3.5 monmove.c $Date: 2011/08/30 22:13:27 $ $Revision: 1.46 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -269,6 +269,7 @@ register struct monst *mtmp; int *inrange, *nearby, *scared; { int seescaryx, seescaryy; + boolean sawscary = FALSE; *inrange = (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= (BOLT_LIM * BOLT_LIM)); @@ -288,11 +289,18 @@ int *inrange, *nearby, *scared; seescaryx = u.ux; seescaryy = u.uy; } - if (*nearby && - (onscary(seescaryx, seescaryy, mtmp) || - (!mtmp->mpeaceful && in_your_sanctuary(mtmp, 0, 0)))) { + + sawscary = onscary(seescaryx, seescaryy, mtmp); + if (*nearby && (sawscary || (!mtmp->mpeaceful + && in_your_sanctuary(mtmp, 0, 0)))) { *scared = 1; monflee(mtmp, rnd(rn2(7) ? 10 : 100), TRUE, TRUE); + + /* magical protection won't last forever, so there'll be a + * chance of the magic being used up regardless of type */ + if (sawscary) { + wipe_engr_at(seescaryx, seescaryy, 1, TRUE); + } } else *scared = 0; } @@ -352,7 +360,7 @@ register struct monst *mtmp; } /* not frozen or sleeping: wipe out texts written in the dust */ - wipe_engr_at(mtmp->mx, mtmp->my, 1); + wipe_engr_at(mtmp->mx, mtmp->my, 1, FALSE); /* confused monsters get unconfused with small probability */ if (mtmp->mconf && !rn2(50)) mtmp->mconf = 0; diff --git a/src/zap.c b/src/zap.c index 309c6cef6..411a674fa 100644 --- a/src/zap.c +++ b/src/zap.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 zap.c $NHDT-Date: 1428207622 2015/04/05 04:20:22 $ $NHDT-Branch: nhmall-booktribute $:$NHDT-Revision: 1.215 $ */ +/* NetHack 3.5 zap.c $NHDT-Date: 1430172954 2015/04/27 22:15:54 $ $NHDT-Branch: derek-elbereth $:$NHDT-Revision: 1.218 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2719,12 +2719,12 @@ struct obj *obj; /* wand or spell */ pline_The(Hallucination ? "floor runs like butter!" : "edges on the floor get smoother."); - wipe_engr_at(x, y, d(2,4)); + wipe_engr_at(x, y, d(2,4), TRUE); } break; case WAN_STRIKING: case SPE_FORCE_BOLT: - wipe_engr_at(x, y, d(2,4)); + wipe_engr_at(x, y, d(2,4), TRUE); break; default: break; From 9c8f4d1fadf642d3c53bbace344fee59bbd70d5a Mon Sep 17 00:00:00 2001 From: "Derek S. Ray" Date: Wed, 29 Apr 2015 19:07:24 -0400 Subject: [PATCH 3/3] ensure that the 'safe' objects remain safe since Elbereth doesn't work if you're not on the square anymore, we need to make sure that critters are discouraged from grabbing the sokoban prize or the castle wand. also, fix up the level compiler makefiles so that uncommenting the YACC/LEX definitions (presuming you have the right tools installed) works properly. --- dat/castle.des | 3 ++- dat/sokoban.des | 4 +++- win/win32/dgnstuff.mak | 42 +++++++++++++++++++++++++----------------- win/win32/levstuff.mak | 30 +++++++++++------------------- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/dat/castle.des b/dat/castle.des index 17f5e9f5c..bab8cec0a 100644 --- a/dat/castle.des +++ b/dat/castle.des @@ -1,4 +1,4 @@ -# NetHack 3.5 castle.des $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ +# NetHack 3.5 castle.des $NHDT-Date: 1430348677 2015/04/29 23:04:37 $ $NHDT-Branch: derek-elbereth $:$NHDT-Revision: 1.8 $ # NetHack 3.5 castle.des $Date: 2009/05/06 10:44:18 $ $Revision: 1.5 $ # SCCS Id: @(#)castle.des 3.5 2002/05/02 # Copyright (c) 1989 by Jean-Christophe Collet @@ -143,6 +143,7 @@ OBJECT:('/',"wishing") } # Prevent monsters from eating it. (@'s never eat objects) ENGRAVING:$place[0],burn,"Elbereth" +OBJECT:('?',"scare monster"),$place[0],cursed # The treasure of the lord OBJECT:('(',"chest"),(37,08) # Traps diff --git a/dat/sokoban.des b/dat/sokoban.des index 343e895d6..16ea85f32 100644 --- a/dat/sokoban.des +++ b/dat/sokoban.des @@ -1,4 +1,4 @@ -# NetHack 3.5 sokoban.des $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ +# NetHack 3.5 sokoban.des $NHDT-Date: 1430348694 2015/04/29 23:04:54 $ $NHDT-Branch: derek-elbereth $:$NHDT-Revision: 1.11 $ # NetHack 3.5 sokoban.des $Date: 2009/05/06 10:44:24 $ $Revision: 1.5 $ # SCCS Id: @(#)sokoban.des 3.5 1999/03/15 # Copyright (c) 1998-1999 by Kevin Hugo @@ -535,6 +535,7 @@ IF [50%] { OBJECT:('"',"amulet of reflection"),$place[0] } ENGRAVING:$place[0],burn,"Elbereth" +OBJECT:('?', "scare monster"),$place[0],cursed MAZE:"soko1-2",' ' @@ -635,3 +636,4 @@ IF [50%] { OBJECT:('"',"amulet of reflection"),$place[0] } ENGRAVING:$place[0],burn,"Elbereth" +OBJECT:('?', "scare monster"),$place[0],cursed diff --git a/win/win32/dgnstuff.mak b/win/win32/dgnstuff.mak index a23aadfd8..004a0621b 100644 --- a/win/win32/dgnstuff.mak +++ b/win/win32/dgnstuff.mak @@ -1,27 +1,22 @@ # $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ # $Date: 2002/01/22 22:54:54 $ $Revision: 1.3 $ -#Set all of these or none of them -#YACC = byacc.exe -#LEX = flex.exe -#YTABC = y_tab.c -#YTABH = y_tab.h -#LEXYYC = lexyy.c +# Set all of these or none of them. +# +# bison and flex are the ones found in GnuWin32, which +# is probably the easiest set of these tools to find +# on Windows. +# +#YACC = bison.exe -y +#LEX = flex.exe +#YTABC = y.tab.c +#YTABH = y.tab.h +#LEXYYC = lex.yy.c -!IF "$(YACC)"!="" -@echo Yacc-alike set to $(YACC) -@echo YTABC set to $(YTABC) -@echo YTABH set to $(YTABH) -!ENDIF - -!IF "$(LEX)"!="" -@echo Lex-alike set to $(LEX) -@echo LEXYYC set to $(LEXYYC) -!ENDIF default: all -all: ..\util\dgn_yacc.c ..\util\dgn_lex.c +all: tools ..\util\dgn_yacc.c ..\util\dgn_lex.c rebuild: clean all @@ -30,6 +25,19 @@ clean: -del ..\util\dgn_yacc.c -del ..\include\dgn_comp.h +tools: +!IFDEF YACC + @echo Yacc-alike set to $(YACC) + @echo YTABC set to $(YTABC) + @echo YTABH set to $(YTABH) +!ENDIF + +!IFDEF LEX + @echo Lex-alike set to $(LEX) + @echo LEXYYC set to $(LEXYYC) +!ENDIF + + #========================================== # Dungeon Compiler Stuff #========================================== diff --git a/win/win32/levstuff.mak b/win/win32/levstuff.mak index 2597e5eb7..7f549abcd 100644 --- a/win/win32/levstuff.mak +++ b/win/win32/levstuff.mak @@ -1,26 +1,18 @@ # $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ # $Date:2002/01/22 22:54:54 $ $Revision: 1.2 $ -#YACC = byacc.exe -#LEX = flex.exe -#YTABC = y_tab.c -#YTABH = y_tab.h -#LEXYYC = lexyy.c -!IF "$(YACC)"!="" -@echo Yacc-alike set to $(YACC) -@echo YTABC set to $(YTABC) -@echo YTABH set to $(YTABH) -!ENDIF +# Set all of these or none of them. +# +# bison and flex are the ones found in GnuWin32, which +# is probably the easiest set of these tools to find +# on Windows. +# +#YACC = bison.exe -y +#LEX = flex.exe +#YTABC = y.tab.c +#YTABH = y.tab.h +#LEXYYC = lex.yy.c -!IF "$(LEX)"!="" -@echo Lex-alike set to $(LEX) -@echo LEXYYC set to $(LEXYYC) -!ENDIF - -# these won't have an impact unless YACC/LEX are defined -YTABC = y.tab.c -YTABH = y.tab.h -LEXYYC = lex.yy.c default: all