Source:NetHack 1.4f/prisym.c

Below is the full text to prisym.c from the source code of NetHack 1.4f. To link to a particular line, write [[NetHack 1.4f/prisym.c#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)prisym.c	1.4	87/08/08 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* prisym.c - version 1.0 */ 4.    5.    #include   6.    #include "hack.h"  7. 8.   extern xchar scrlx, scrhx, scrly, scrhy; /* corners from pri.c */ 9.    10.   atl(x,y,ch) 11.  register x,y; 12.  {  13.   	register struct rm *crm = &levl[x][y]; 14.   15.   	if(x<0 || x>COLNO-1 || y<0 || y>ROWNO-1){ 16.  		impossible("atl(%d,%d,%c)",x,y,ch); 17.  		return; 18.  	}  19.   	if(crm->seen && crm->scrsym == ch) return; 20.  	crm->scrsym = ch; 21.  	crm->new = 1; 22.  	on_scr(x,y); 23.  }  24.    25.   on_scr(x,y) 26.  register x,y; 27.  {  28.   	if(x < scrlx) scrlx = x;  29. if(x > scrhx) scrhx = x; 30. if(y < scrly) scrly = y; 31. if(y > scrhy) scrhy = y; 32. } 33.    34.   /* call: (x,y) - display 35.  	(-1,0) - close (leave last symbol) 36.  	(-1,-1)- close (undo last symbol) 37.  	(-1,let)-open: initialize symbol 38.  	(-2,let)-change let 39.  */  40.    41.   tmp_at(x,y) schar x,y; { 42.  static schar prevx, prevy; 43.  static char let; 44.  	if((int)x == -2){	/* change let call */ 45.  		let = y;  46. return; 47.  	}  48.   	if((int)x == -1 && (int)y >= 0){	/* open or close call */ 49.  		let = y;  50. prevx = -1; 51.  		return; 52.  	}  53.   	if(prevx >= 0 && cansee(prevx,prevy)) { 54.  		delay_output; 55.  		prl(prevx, prevy);	/* in case there was a monster */ 56.  		at(prevx, prevy, levl[prevx][prevy].scrsym); 57.  	}  58.   	if(x >= 0){	/* normal call */ 59.  		if(cansee(x,y)) at(x,y,let); 60.  		prevx = x;  61. prevy = y; 62. } else {	/* close call */ 63.  		let = 0; 64.  		prevx = -1; 65.  	}  66.   }  67.    68.   /* like the previous, but the symbols are first erased on completion */ 69.  Tmp_at(x,y) schar x,y; { 70.  static char let; 71.  static xchar cnt; 72.  static coord tc[COLNO];		/* but watch reflecting beams! */ 73.   register xx,yy; 74.  	if((int)x == -1) { 75.  		if(y > 0) {	/* open call */ 76.  			let = y;  77. cnt = 0; 78.  			return; 79.  		}  80.   		/* close call (do not distinguish y==0 and y==-1) */ 81.  		while(cnt--) { 82.  			xx = tc[cnt].x;  83. yy = tc[cnt].y; 84. prl(xx, yy); 85.  			at(xx, yy, levl[xx][yy].scrsym); 86.  		}  87.   		cnt = let = 0;	/* superfluous */ 88.  		return; 89.  	}  90.   	if((int)x == -2) {	/* change let call */ 91.  		let = y;  92. return; 93.  	}  94.   	/* normal call */ 95.  	if(cansee(x,y)) { 96.  		if(cnt) delay_output; 97.  		at(x,y,let); 98.  		tc[cnt].x = x;  99. tc[cnt].y = y; 100. if(++cnt >= COLNO) panic("Tmp_at overflow?"); 101. 		levl[x][y].new = 0;	/* prevent pline-nscr erasing --- */ 102. 	}  103.  }  104.   105.  curs_on_u{ 106. 	curs(u.ux, u.uy+2); 107. }  108.   109.  pru 110. {  111.  	if(u.udispl && (Invisible || u.udisx != u.ux || u.udisy != u.uy)) 112. 		/* if(! levl[u.udisx][u.udisy].new) */ 113. 			if(!vism_at(u.udisx, u.udisy)) 114. 				newsym(u.udisx, u.udisy); 115. 	if(Invisible) { 116. 		u.udispl = 0; 117. 		prl(u.ux,u.uy); 118. 	} else 119. 	if(!u.udispl || u.udisx != u.ux || u.udisy != u.uy) { 120. 		atl(u.ux, u.uy, u.usym); 121. 		u.udispl = 1; 122. 		u.udisx = u.ux; 123. 		u.udisy = u.uy; 124. 	}  125.  	levl[u.ux][u.uy].seen = 1; 126. }  127.   128.  #ifndef NOWORM 129. #include	"wseg.h"  130. extern struct wseg *m_atseg; 131. #endif 132.  133.  /* print a position that is visible for @ */ 134. prl(x,y) 135. {  136.  	register struct rm *room; 137. 	register struct monst *mtmp; 138. 	register struct obj *otmp; 139. 	register struct trap *ttmp; 140.  141.  	if(x == u.ux && y == u.uy && (!Invisible)) { 142. 		pru; 143. 		return; 144. 	}  145.  	if(!isok(x,y)) return; 146. 	room = &levl[x][y]; 147. 	if((!room->typ) ||  148.  	   (IS_ROCK(room->typ) && levl[u.ux][u.uy].typ == CORR)) 149. 		return; 150. 	if((mtmp = m_at(x,y)) && !mtmp->mhide &&  151.  		(!mtmp->minvis || See_invisible)) { 152. #ifndef NOWORM 153. 		if(m_atseg) 154. 			pwseg(m_atseg); 155. 		else 156. #endif 157. 		pmon(mtmp); 158. 	}  159.  	else if((otmp = o_at(x,y)) && room->typ != POOL) 160. 		atl(x,y,Hallucination ? rndobjsym : otmp->olet); 161. #ifdef SPIDERS 162. 	else if((!mtmp || mtmp->data == PM_SPIDER) &&  163.  		  (ttmp = t_at(x,y)) && ttmp->ttyp == WEB) 164. 		atl(x,y,WEB_SYM); 165. #endif 166. 	else if(mtmp && (!mtmp->minvis || See_invisible)) { 167. 		/* must be a hiding monster, but not hiding right now */ 168. 		/* assume for the moment that long worms do not hide */ 169. 		pmon(mtmp); 170. 	}  171.  	else if(g_at(x,y) && room->typ != POOL) 172. 		atl(x,y,Hallucination ? rndobjsym : GOLD_SYM); 173. 	else if(!room->seen || room->scrsym == STONE_SYM) { 174. 		room->new = room->seen = 1; 175. 		newsym(x,y); 176. 		on_scr(x,y); 177. 	}  178.  	room->seen = 1; 179. }  180.   181.  char 182. news0(x,y) 183. register xchar x,y; 184. {  185.  	register struct obj *otmp; 186. 	register struct trap *ttmp; 187. 	struct rm *room; 188. 	register char tmp; 189.  190.  	room = &levl[x][y]; 191. 	if(!room->seen) tmp = STONE_SYM; 192. 	else if(room->typ == POOL) tmp = POOL_SYM; 193. 	else if(!Blind && (otmp = o_at(x,y))) 194. 		tmp = Hallucination ? rndobjsym : otmp->olet; 195. 	else if(!Blind && g_at(x,y)) 196. 		tmp = Hallucination ? rndobjsym : GOLD_SYM; 197. 	else if(x == xupstair && y == yupstair) tmp = UP_SYM; 198. 	else if(x == xdnstair && y == ydnstair) tmp = DN_SYM; 199. #ifdef SPIDERS 200. 	else if((ttmp = t_at(x,y)) && ttmp->ttyp == WEB) tmp = WEB_SYM; 201. 	else if(ttmp && ttmp->tseen) tmp = TRAP_SYM; 202. #else 203. 	else if((ttmp = t_at(x,y)) && ttmp->tseen) tmp = TRAP_SYM; 204. #endif 205. 	else switch(room->typ) { 206. 	case SCORR: 207. 	case SDOOR: 208. 		tmp = room->scrsym;	/* %% wrong after killing mimic ! */ 209.  		break; 210. 	case HWALL: 211. 		tmp = room->scrsym;	/* OK for corners only */ 212. 		if (!IS_CORNER(tmp)) 213. 			tmp = HWALL_SYM; 214. 		break; 215. 	case VWALL: 216. 		tmp = VWALL_SYM; 217. 		break; 218. 	case LDOOR: 219. 	case DOOR: 220. 		tmp = DOOR_SYM; 221. 		break; 222. 	case CORR: 223. 		tmp = CORR_SYM; 224. 		break; 225. 	case ROOM: 226. 		if(room->lit || cansee(x,y) || Blind) tmp = ROOM_SYM; 227. 		else tmp = STONE_SYM; 228. 		break; 229. #ifdef FOUNTAINS 230. 	case FOUNTAIN: 231. 		tmp = FOUNTAIN_SYM; 232. 		break; 233. #endif 234. #ifdef NEWCLASS 235. 	case THRONE: 236. 		tmp = THRONE_SYM; 237. 		break; 238. #endif 239. /*  240.  	case POOL: 241. 		tmp = POOL_SYM; 242. 		break; 243. */  244.  	default: 245. 		tmp = ERRCHAR; 246. 	}  247.  	return(tmp); 248. }  249.   250.  newsym(x,y) 251. register x,y; 252. {  253.  	atl(x,y,news0(x,y)); 254. }  255.   256.  /* used with wand of digging (or pick-axe): fill scrsym and force display */ 257. /* also when a POOL evaporates */ 258. mnewsym(x,y) 259. register x,y; 260. {  261.  	register struct rm *room; 262. 	char newscrsym; 263.  264.  	if(!vism_at(x,y)) { 265. 		room = &levl[x][y]; 266. 		newscrsym = news0(x,y); 267. 		if(room->scrsym != newscrsym) { 268. 			room->scrsym = newscrsym; 269. 			room->seen = 0; 270. 		}  271.  	}  272.  }  273.   274.  nosee(x,y) 275. register x,y; 276. {  277.  	register struct rm *room; 278.  279.  	if(!isok(x,y)) return; 280. 	room = &levl[x][y]; 281. #ifdef DGK 282. 	if(room->scrsym == symbol.room && !room->lit && !Blind) { 283. #else 284. 	if(room->scrsym == '.' && !room->lit && !Blind) { 285. #endif 286. 		room->scrsym = ' '; 287. 		room->new = 1; 288. 		on_scr(x,y); 289. 	}  290.  }  291.   292.  #ifndef QUEST 293. prl1(x,y) 294. register x,y; 295. {  296.  	if(u.dx) { 297. 		if(u.dy) { 298. 			prl(x-(2*u.dx),y); 299. 			prl(x-u.dx,y); 300. 			prl(x,y); 301. 			prl(x,y-u.dy); 302. 			prl(x,y-(2*u.dy)); 303. 		} else { 304. 			prl(x,y-1); 305. 			prl(x,y); 306. 			prl(x,y+1); 307. 		}  308.  	} else { 309. 		prl(x-1,y); 310. 		prl(x,y); 311. 		prl(x+1,y); 312. 	}  313.  }  314.   315.  nose1(x,y) 316. register x,y; 317. {  318.  	if(u.dx) { 319. 		if(u.dy) { 320. 			nosee(x,u.uy); 321. 			nosee(x,u.uy-u.dy); 322. 			nosee(x,y); 323. 			nosee(u.ux-u.dx,y); 324. 			nosee(u.ux,y); 325. 		} else { 326. 			nosee(x,y-1); 327. 			nosee(x,y); 328. 			nosee(x,y+1); 329. 		}  330.  	} else { 331. 		nosee(x-1,y); 332. 		nosee(x,y); 333. 		nosee(x+1,y); 334. 	}  335.  }  336.  #endif /* QUEST /**/ 337.  338.  vism_at(x,y) 339. register x,y; 340. {  341.  	register struct monst *mtmp; 342.  343.  	if(x == u.ux && y == u.uy && !Invisible) return(1); 344.  345.  	if(mtmp = m_at(x,y)) return((Blind && Telepat) || canseemon(mtmp)); 346.  347.  	return(0); 348. }  349.   350.  #ifdef NEWSCR 351. pobj(obj) register struct obj *obj; { 352. register int show = (!obj->oinvis || See_invisible) && 353. 		cansee(obj->ox,obj->oy); 354. 	if(obj->odispl){ 355. 		if(obj->odx != obj->ox || obj->ody != obj->oy || !show) 356. 		if(!vism_at(obj->odx,obj->ody)){ 357. 			newsym(obj->odx, obj->ody); 358. 			obj->odispl = 0; 359. 		}  360.  	}  361.  	if(show && !vism_at(obj->ox,obj->oy)){ 362. 		atl(obj->ox,obj->oy,obj->olet); 363. 		obj->odispl = 1; 364. 		obj->odx = obj->ox; 365. 		obj->ody = obj->oy; 366. 	}  367.  }  368.  #endif /* NEWSCR /**/ 369.  370.  unpobj(obj) register struct obj *obj; { 371. /* 	if(obj->odispl){ 372. 		if(!vism_at(obj->odx, obj->ody)) 373. 			newsym(obj->odx, obj->ody); 374. 		obj->odispl = 0; 375. 	}  376.  */  377.  	if(!vism_at(obj->ox,obj->oy)) 378. 		newsym(obj->ox,obj->oy); 379. }