[rec.games.hack] Bugfix for *SERIOUS* BUG in NetHack

polder@cs.vu.nl (Polderman Paul) (01/15/88)

The following context diffs fix a very nasty bug which causes a player
to get a "Segmentation Fault (Core dumped)" after weeks of playing.
This happens when (s)he is on a (dungeon-)level > 40 and a chameleon is created.
So if you do not want to have your zillion points game ended like this
(Hi Mike, Maarten; Better luck next time ;-)) please apply the diffs below.

-- Paul Polderman (polder@cs.vu.nl)

PS: This fix also applies to PC NetHack.

+------------------------------------------------------------------------------+
|    "The nice thing about standards is that you have so many to choose from;  |
|     furthermore, if you do not like any of them, you can just wait           |
|                       for next year's model."                                |
|                                                                              |
|               - A.S.Tanenbaum  "Computernetworks"                            |
+------------------------------------------------------------------------------+

*** makemon.old.c	Fri Jan 15 15:58:46 1988
--- makemon.new.c	Fri Jan 15 15:55:11 1988
***************
*** 42,47
  #ifdef BVH
  	if(has_amulet()) zlevel = 40;
  #endif
  	/* if a monster already exists at the position, return */
  	if(x != 0 || y != 0) if(m_at(x,y)) return((struct monst *) 0);
  	if(ptr){

--- 42,49 -----
  #ifdef BVH
  	if(has_amulet()) zlevel = 40;
  #endif
+ 	if (zlevel > 40) zlevel = 40;
+ 
  	/* if a monster already exists at the position, return */
  	if(x != 0 || y != 0) if(m_at(x,y)) return((struct monst *) 0);
  	if(ptr){
*** monmove.old.c	Fri Jan 15 15:59:02 1988
--- monmove.new.c	Fri Jan 15 15:55:41 1988
***************
*** 30,37
  	register struct permonst *mdat;
  	register tmp, nearby, scared, onscary;
  
! 	if(mtmp->cham && !rn2(6))
! 		(void) newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]);
  	mdat = mtmp->data;
  	if(mdat->mlevel < 0)
  		panic("bad monster %c (%d)",mdat->mlet,mdat->mlevel);

--- 30,42 -----
  	register struct permonst *mdat;
  	register tmp, nearby, scared, onscary;
  
! 	if(mtmp->cham && !rn2(6)) {
! 		int zlevel;
! 
! 		zlevel = dlevel;
! 		if (zlevel > 40) zlevel = 40;
! 		(void) newcham(mtmp, &mons[zlevel+14+rn2(CMNUM-14-zlevel)]);
! 	}
  	mdat = mtmp->data;
  	if(mdat->mlevel < 0)
  		panic("bad monster %c (%d)",mdat->mlet,mdat->mlevel);
*** spell.old.c	Fri Jan 15 15:59:21 1988
--- spell.new.c	Fri Jan 15 15:57:05 1988
***************
*** 304,309
  
  			mtmp = makedog();
  			if(mtmp) {
  				/* make it into something else */
  				(void) newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]);
  				if(confused)

--- 304,313 -----
  
  			mtmp = makedog();
  			if(mtmp) {
+ 				int zlevel;
+ 
+ 				zlevel = dlevel;
+ 				if (zlevel > 40) zlevel = 40;
  				/* make it into something else */
  		(void) newcham(mtmp, &mons[zlevel+14+rn2(CMNUM-14-zlevel)]);
  				if(confused)
***************
*** 305,311
  			mtmp = makedog();
  			if(mtmp) {
  				/* make it into something else */
! 				(void) newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]);
  				if(confused)
  					mtmp->mtame = mtmp->mpeaceful = 0;
  			}

--- 309,315 -----
  				zlevel = dlevel;
  				if (zlevel > 40) zlevel = 40;
  				/* make it into something else */
! 		(void) newcham(mtmp, &mons[zlevel+14+rn2(CMNUM-14-zlevel)]);
  				if(confused)
  					mtmp->mtame = mtmp->mpeaceful = 0;
  			}