Fandom

Wikihack

Source:NetHack 2.3e/prisym.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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

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

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

Also on Fandom

Random Wiki