Source:NetHack 2.2a/prisym.c

From NetHackWiki
Revision as of 02:38, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 2.2a/prisym.c moved to Source:NetHack 2.2a/prisym.c: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Below is the full text to prisym.c from the source code of NetHack 2.2a. To link to a particular line, write [[NetHack 2.2a/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.0	87/09/14
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.  /*
239.  	case POOL:
240.  		tmp = POOL_SYM;
241.  		break;
242.  */
243.  	default:
244.  		tmp = ERRCHAR;
245.  	}
246.  	return(tmp);
247.  }
248.  
249.  newsym(x,y)
250.  register x,y;
251.  {
252.  	atl(x,y,news0(x,y));
253.  }
254.  
255.  /* used with wand of digging (or pick-axe): fill scrsym and force display */
256.  /* also when a POOL evaporates */
257.  mnewsym(x,y)
258.  register x,y;
259.  {
260.  	register struct rm *room;
261.  	char newscrsym;
262.  
263.  	if(!vism_at(x,y)) {
264.  		room = &levl[x][y];
265.  		newscrsym = news0(x,y);
266.  		if(room->scrsym != newscrsym) {
267.  			room->scrsym = newscrsym;
268.  			room->seen = 0;
269.  		}
270.  	}
271.  }
272.  
273.  nosee(x,y)
274.  register x,y;
275.  {
276.  	register struct rm *room;
277.  
278.  	if(!isok(x,y)) return;
279.  	room = &levl[x][y];
280.  	if(room->scrsym == ROOM_SYM && !room->lit && !Blind) {
281.  		room->scrsym = ' ';
282.  		room->new = 1;
283.  		on_scr(x,y);
284.  	}
285.  }
286.  
287.  #ifndef QUEST
288.  prl1(x,y)
289.  register x,y;
290.  {
291.  	if(u.dx) {
292.  		if(u.dy) {
293.  			prl(x-(2*u.dx),y);
294.  			prl(x-u.dx,y);
295.  			prl(x,y);
296.  			prl(x,y-u.dy);
297.  			prl(x,y-(2*u.dy));
298.  		} else {
299.  			prl(x,y-1);
300.  			prl(x,y);
301.  			prl(x,y+1);
302.  		}
303.  	} else {
304.  		prl(x-1,y);
305.  		prl(x,y);
306.  		prl(x+1,y);
307.  	}
308.  }
309.  
310.  nose1(x,y)
311.  register x,y;
312.  {
313.  	if(u.dx) {
314.  		if(u.dy) {
315.  			nosee(x,u.uy);
316.  			nosee(x,u.uy-u.dy);
317.  			nosee(x,y);
318.  			nosee(u.ux-u.dx,y);
319.  			nosee(u.ux,y);
320.  		} else {
321.  			nosee(x,y-1);
322.  			nosee(x,y);
323.  			nosee(x,y+1);
324.  		}
325.  	} else {
326.  		nosee(x-1,y);
327.  		nosee(x,y);
328.  		nosee(x+1,y);
329.  	}
330.  }
331.  #endif /* QUEST /**/
332.  
333.  vism_at(x,y)
334.  register x,y;
335.  {
336.  	register struct monst *mtmp;
337.  
338.  	if(x == u.ux && y == u.uy && !Invisible) return(1);
339.  
340.  	if(mtmp = m_at(x,y)) return((Blind && Telepat) || canseemon(mtmp));
341.  
342.  	return(0);
343.  }
344.  
345.  #ifdef NEWSCR
346.  pobj(obj) register struct obj *obj; {
347.  register int show = (!obj->oinvis || See_invisible) &&
348.  		cansee(obj->ox,obj->oy);
349.  	if(obj->odispl){
350.  		if(obj->odx != obj->ox || obj->ody != obj->oy || !show)
351.  		if(!vism_at(obj->odx,obj->ody)){
352.  			newsym(obj->odx, obj->ody);
353.  			obj->odispl = 0;
354.  		}
355.  	}
356.  	if(show && !vism_at(obj->ox,obj->oy)){
357.  		atl(obj->ox,obj->oy,obj->olet);
358.  		obj->odispl = 1;
359.  		obj->odx = obj->ox;
360.  		obj->ody = obj->oy;
361.  	}
362.  }
363.  #endif /* NEWSCR /**/
364.  
365.  unpobj(obj) register struct obj *obj; {
366.  /* 	if(obj->odispl){
367.  		if(!vism_at(obj->odx, obj->ody))
368.  			newsym(obj->odx, obj->ody);
369.  		obj->odispl = 0;
370.  	}
371.  */
372.  	if(!vism_at(obj->ox,obj->oy))
373.  		newsym(obj->ox,obj->oy);
374.  }