Source:NetHack 1.3d/prisym.c

Below is the full text to prisym.c from the source code of NetHack 1.3d. To link to a particular line, write [[NetHack 1.3d/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.3	87/07/14 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 : '$'); 173. 	else if(!room->seen || room->scrsym == ' ') { 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 = ' '; 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 : '$'; 197. 	else if(x == xupstair && y == yupstair) tmp = '<'; 198. 	else if(x == xdnstair && y == ydnstair) tmp = '>'; 199. #ifdef SPIDERS 200. 	else if((ttmp = t_at(x,y)) && ttmp->ttyp == WEB) tmp = WEB_SYM; 201. 	else if(ttmp && ttmp->tseen) tmp ='^'; 202. #else 203. 	else if((ttmp = t_at(x,y)) && ttmp->tseen) tmp = '^'; 204. #endif 205. 	else switch(room->typ) { 206. 	case SCORR: 207. 	case SDOOR: 208. 		tmp = room->scrsym;	/* %% wrong after killing mimic ! */ 209.  		break; 210. #ifdef DGK 211. 	case HWALL: 212. 		tmp = room->scrsym;	/* OK for corners only */ 213. 		if (!IS_CORNER(tmp)) 214. 			tmp = symbol.hwall; 215. 		break; 216. 	case VWALL: 217. 		tmp = symbol.vwall; 218. 		break; 219. 	case LDOOR: 220. 	case DOOR: 221. 		tmp = symbol.door; 222. 		break; 223. 	case CORR: 224. 		tmp = symbol.corr; 225. 		break; 226. 	case ROOM: 227. 		if(room->lit || cansee(x,y) || Blind) tmp = symbol.room; 228. 		else tmp = ' '; 229. 		break; 230. #else 231. 	case HWALL: 232. 		tmp = '-'; 233. 		break; 234. 	case VWALL: 235. 		tmp = '|'; 236. 		break; 237. 	case LDOOR: 238. 	case DOOR: 239. 		tmp = '+'; 240. 		break; 241. 	case CORR: 242. 		tmp = CORR_SYM; 243. 		break; 244. 	case ROOM: 245. 		if(room->lit || cansee(x,y) || Blind) tmp = '.'; 246. 		else tmp = ' '; 247. 		break; 248. #endif 249. #ifdef FOUNTAINS 250. 	case FOUNTAIN: 251. 		tmp = FOUNTAIN_SYM; 252. 		break; 253. #endif 254. #ifdef NEWCLASS 255. 	case THRONE: 256. 		tmp = THRONE_SYM; 257. 		break; 258. #endif 259. /*  260.  	case POOL: 261. 		tmp = POOL_SYM; 262. 		break; 263. */  264.  	default: 265. 		tmp = ERRCHAR; 266. 	}  267.  	return(tmp); 268. }  269.   270.  newsym(x,y) 271. register x,y; 272. {  273.  	atl(x,y,news0(x,y)); 274. }  275.   276.  /* used with wand of digging (or pick-axe): fill scrsym and force display */ 277. /* also when a POOL evaporates */ 278. mnewsym(x,y) 279. register x,y; 280. {  281.  	register struct rm *room; 282. 	char newscrsym; 283.  284.  	if(!vism_at(x,y)) { 285. 		room = &levl[x][y]; 286. 		newscrsym = news0(x,y); 287. 		if(room->scrsym != newscrsym) { 288. 			room->scrsym = newscrsym; 289. 			room->seen = 0; 290. 		}  291.  	}  292.  }  293.   294.  nosee(x,y) 295. register x,y; 296. {  297.  	register struct rm *room; 298.  299.  	if(!isok(x,y)) return; 300. 	room = &levl[x][y]; 301. #ifdef DGK 302. 	if(room->scrsym == symbol.room && !room->lit && !Blind) { 303. #else 304. 	if(room->scrsym == '.' && !room->lit && !Blind) { 305. #endif 306. 		room->scrsym = ' '; 307. 		room->new = 1; 308. 		on_scr(x,y); 309. 	}  310.  }  311.   312.  #ifndef QUEST 313. prl1(x,y) 314. register x,y; 315. {  316.  	if(u.dx) { 317. 		if(u.dy) { 318. 			prl(x-(2*u.dx),y); 319. 			prl(x-u.dx,y); 320. 			prl(x,y); 321. 			prl(x,y-u.dy); 322. 			prl(x,y-(2*u.dy)); 323. 		} else { 324. 			prl(x,y-1); 325. 			prl(x,y); 326. 			prl(x,y+1); 327. 		}  328.  	} else { 329. 		prl(x-1,y); 330. 		prl(x,y); 331. 		prl(x+1,y); 332. 	}  333.  }  334.   335.  nose1(x,y) 336. register x,y; 337. {  338.  	if(u.dx) { 339. 		if(u.dy) { 340. 			nosee(x,u.uy); 341. 			nosee(x,u.uy-u.dy); 342. 			nosee(x,y); 343. 			nosee(u.ux-u.dx,y); 344. 			nosee(u.ux,y); 345. 		} else { 346. 			nosee(x,y-1); 347. 			nosee(x,y); 348. 			nosee(x,y+1); 349. 		}  350.  	} else { 351. 		nosee(x-1,y); 352. 		nosee(x,y); 353. 		nosee(x+1,y); 354. 	}  355.  }  356.  #endif /* QUEST /**/ 357.  358.  vism_at(x,y) 359. register x,y; 360. {  361.  	register struct monst *mtmp; 362.  363.  	if(x == u.ux && y == u.uy && !Invisible) return(1); 364.  365.  	if(mtmp = m_at(x,y)) return((Blind && Telepat) || canseemon(mtmp)); 366.  367.  	return(0); 368. }  369.   370.  #ifdef NEWSCR 371. pobj(obj) register struct obj *obj; { 372. register int show = (!obj->oinvis || See_invisible) && 373. 		cansee(obj->ox,obj->oy); 374. 	if(obj->odispl){ 375. 		if(obj->odx != obj->ox || obj->ody != obj->oy || !show) 376. 		if(!vism_at(obj->odx,obj->ody)){ 377. 			newsym(obj->odx, obj->ody); 378. 			obj->odispl = 0; 379. 		}  380.  	}  381.  	if(show && !vism_at(obj->ox,obj->oy)){ 382. 		atl(obj->ox,obj->oy,obj->olet); 383. 		obj->odispl = 1; 384. 		obj->odx = obj->ox; 385. 		obj->ody = obj->oy; 386. 	}  387.  }  388.  #endif /* NEWSCR /**/ 389.  390.  unpobj(obj) register struct obj *obj; { 391. /* 	if(obj->odispl){ 392. 		if(!vism_at(obj->odx, obj->ody)) 393. 			newsym(obj->odx, obj->ody); 394. 		obj->odispl = 0; 395. 	}  396.  */  397.  	if(!vism_at(obj->ox,obj->oy)) 398. 		newsym(obj->ox,obj->oy); 399. }