Fandom

Wikihack

Source:NetHack 3.0.0/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 3.0.0. To link to a particular line, write [[NetHack 3.0.0/prisym.c#line123]], for example.

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

The NetHack General Public License applies to screenshots, source code and other content from NetHack.
1.    /*	SCCS Id: @(#)prisym.c	3.0	88/11/09
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include "hack.h"
6.    
7.    #ifdef WORM
8.    #include "wseg.h"
9.    #include "lev.h"
10.   
11.   static void pwseg P((struct wseg *));
12.   #endif
13.   
14.   void
15.   atl(x,y,ch)
16.   register int x, y;
17.   char ch;
18.   {
19.   	register struct rm *crm = &levl[x][y];
20.   
21.   	if(x<0 || x>COLNO-1 || y<0 || y>ROWNO-1){
22.   		impossible("atl(%d,%d,%c)",x,y,ch);
23.   		return;
24.   	}
25.   	if(crm->seen && crm->scrsym == ch) return;
26.   	/* crm->scrsym = (uchar) ch; */
27.   	/* wrong if characters are signed but uchar is larger than char,
28.   	 * and ch, when passed, was greater than 127.
29.   	 * We probably should _really_ go around changing atl to take a
30.   	 * uchar for its third argument...
31.   	 */
32.   	crm->scrsym = (uchar)((unsigned char) ch);
33.   	crm->new = 1;
34.   	on_scr(x,y);
35.   }
36.   
37.   void
38.   on_scr(x,y)
39.   register int x, y;
40.   {
41.   	if(x < scrlx) scrlx = x;
42.   	if(x > scrhx) scrhx = x;
43.   	if(y < scrly) scrly = y;
44.   	if(y > scrhy) scrhy = y;
45.   }
46.   
47.   /* call: (x,y) - display
48.   	(-1,0) - close (leave last symbol)
49.   	(-1,-1)- close (undo last symbol)
50.   	(-1,let)-open: initialize symbol
51.   	(-2,let)-change let
52.   	(-3,let)-set color
53.   */
54.   
55.   void
56.   tmp_at(x, y)
57.   int x, y;
58.   {
59.   #ifdef LINT	/* static schar prevx, prevy; static char let; */
60.   schar prevx=0, prevy=0;
61.   uchar let;
62.   uchar col;
63.   #else
64.   static schar prevx, prevy;
65.   static uchar let;
66.   static uchar col;
67.   #endif
68.   
69.   	switch ((int)x) {
70.   	    case -2:		/* change let call */
71.   		let = y;
72.   		return;
73.   	    case -1:		/* open or close call */
74.   		if ((int)y >= 0) {
75.   		    let = y;
76.   		    prevx = -1;
77.   		    col = AT_ZAP;
78.   		    return;
79.   		}
80.   		break;
81.   	    case -3:		/* set color call */
82.   		col = y;
83.   		return;
84.   	}
85.   	if(prevx >= 0 && cansee(prevx,prevy)) {
86.   		delay_output();
87.   		prl(prevx, prevy);	/* in case there was a monster */
88.   		at(prevx, prevy, levl[prevx][prevy].scrsym, AT_APP);
89.   	}
90.   	if(x >= 0){	/* normal call */
91.   		if(cansee(x,y)) at(x,y,let,col);
92.   		prevx = x;
93.   		prevy = y;
94.   	} else {	/* close call */
95.   		let = 0;
96.   		prevx = -1;
97.   	}
98.   }
99.   
100.  /* like the previous, but the symbols are first erased on completion */
101.  void
102.  Tmp_at2(x, y)
103.  int x, y;
104.  {
105.  #ifdef LINT	/* static char let; static xchar cnt; static coord tc[COLNO]; */
106.  uchar let;
107.  xchar cnt;
108.  coord tc[COLNO];	/* but watch reflecting beams! */
109.  # ifdef MSDOSCOLOR
110.  uchar col;
111.  # endif
112.  #else
113.  static uchar let;
114.  static xchar cnt;
115.  static coord tc[COLNO];	/* but watch reflecting beams! */
116.  # ifdef MSDOSCOLOR
117.  static uchar col;
118.  # endif
119.  #endif
120.  register int xx,yy;
121.  	switch((int)x) {
122.  	    case -1:
123.  		if(y > 0) {	/* open call */
124.  			let = y;
125.  			cnt = 0;
126.  #ifdef MSDOSCOLOR
127.  			col = AT_ZAP;
128.  #endif
129.  			return;
130.  		}
131.  		/* close call (do not distinguish y==0 and y==-1) */
132.  		while(cnt--) {
133.  			xx = tc[cnt].x;
134.  			yy = tc[cnt].y;
135.  			prl(xx, yy);
136.  			at(xx, yy, levl[xx][yy].scrsym, AT_APP);
137.  		}
138.  		cnt = let = 0;	/* superfluous */
139.  		return;
140.  	    case -2:		/* change let call */
141.  		let = y;
142.  		return;
143.  #ifdef MSDOSCOLOR
144.  	    case -3:		/* set color call */
145.  		col = y;
146.  		return;
147.  #endif
148.  	}
149.  	/* normal call */
150.  	if(cansee(x,y)) {
151.  		if(cnt) delay_output();
152.  #ifdef MSDOSCOLOR
153.  		at(x,y,let,col);
154.  #else
155.  		at(x,y,let,AT_ZAP);
156.  #endif
157.  		tc[cnt].x = x;
158.  		tc[cnt].y = y;
159.  		if(++cnt >= COLNO) panic("Tmp_at2 overflow?");
160.  		levl[x][y].new = 0;	/* prevent pline-nscr erasing --- */
161.  	}
162.  }
163.  
164.  void
165.  curs_on_u()
166.  {
167.  	curs(u.ux, u.uy+2);
168.  }
169.  
170.  void
171.  pru()
172.  {
173.  	if(u.udispl && (Invisible || u.udisx != u.ux || u.udisy != u.uy))
174.  		/* if(! levl[u.udisx][u.udisy].new) */
175.  			if(!vism_at(u.udisx, u.udisy))
176.  				newsym(u.udisx, u.udisy);
177.  	if(Invisible
178.  #ifdef POLYSELF
179.  			|| u.uundetected
180.  #endif
181.  					) {
182.  		u.udispl = 0;
183.  		prl(u.ux,u.uy);
184.  	} else
185.  	if(!u.udispl || u.udisx != u.ux || u.udisy != u.uy) {
186.  		atl(u.ux, u.uy, (char) u.usym);
187.  		u.udispl = 1;
188.  		u.udisx = u.ux;
189.  		u.udisy = u.uy;
190.  	}
191.  	levl[u.ux][u.uy].seen = 1;
192.  }
193.  
194.  /* print a position that is visible for @ */
195.  void
196.  prl(x,y)
197.  {
198.  	register struct rm *room;
199.  	register struct monst *mtmp = (struct monst *)0;
200.  	register struct obj *otmp;
201.  	register struct trap *ttmp;
202.  
203.  	if(x == u.ux && y == u.uy && !Invisible
204.  #ifdef POLYSELF
205.  						&& !u.uundetected
206.  #endif
207.  								) {
208.  		pru();
209.  		return;
210.  	}
211.  	if(!isok(x,y)) return;
212.  	room = &levl[x][y];
213.  	if((!room->typ) ||
214.  	   (IS_ROCK(room->typ) && levl[u.ux][u.uy].typ == CORR &&
215.  				  !levl[u.ux][u.uy].lit))
216.  	    /* the only lit corridor squares should be the entrances to
217.  	     * outside castle areas */
218.  		return;
219.  	if(room->mmask) mtmp = m_at(x,y);
220.  	if(mtmp && !mtmp->mhide &&
221.  		(!mtmp->minvis || See_invisible)) {
222.  #ifdef WORM
223.  		if(m_atseg)
224.  			pwseg(m_atseg);
225.  		else
226.  #endif
227.  		pmon(mtmp);
228.  	}
229.  	else if(room->omask && !is_pool(x,y)) {
230.  		otmp = o_at(x,y);
231.  		atl(x,y,Hallucination ? rndobjsym() : otmp->olet);
232.  	}
233.  	else if(room->gmask && !is_pool(x,y))
234.  		atl(x,y,Hallucination ? rndobjsym() : GOLD_SYM);
235.  	else if((!mtmp || mtmp->data == &mons[PM_GIANT_SPIDER]) &&
236.  		  (ttmp = t_at(x,y)) && ttmp->ttyp == WEB)
237.  		atl(x,y,(char)WEB_SYM);
238.  	else if(mtmp && (!mtmp->minvis || See_invisible)) {
239.  		/* must be a hiding monster, but not hiding right now */
240.  		/* assume for the moment that long worms do not hide */
241.  		pmon(mtmp);
242.  	}
243.  	else if(!room->seen || room->scrsym == STONE_SYM) {
244.  		room->new = room->seen = 1;
245.  		newsym(x,y);
246.  		on_scr(x,y);
247.  	}
248.  	room->seen = 1;
249.  }
250.  
251.  uchar
252.  news0(x,y)
253.  register xchar x,y;
254.  {
255.  	register struct obj *otmp;
256.  	register struct trap *ttmp;
257.  	struct rm *room;
258.  	register uchar tmp;	/* don't compare char with uchar -- OIS */
259.  	register int croom;
260.  
261.  	room = &levl[x][y];
262.  	/* note: a zero scrsym means to ignore the presence of objects */
263.  	if(!room->seen) tmp = STONE_SYM;
264.  	else if(room->typ == POOL || room->typ == MOAT) tmp = POOL_SYM;
265.  	else if(room->omask && !Blind && room->scrsym) {
266.  		otmp = o_at(x,y);
267.  		tmp = Hallucination ? rndobjsym() : otmp->olet;
268.  	}
269.  	else if(room->gmask && !Blind && room->scrsym) 
270.  		tmp = Hallucination ? rndobjsym() : GOLD_SYM;
271.  	else if(x == xupstair && y == yupstair) tmp = UP_SYM;
272.  	else if(x == xdnstair && y == ydnstair) tmp = DN_SYM;
273.  #ifdef STRONGHOLD
274.  	else if(x == xupladder && y == yupladder) tmp = UPLADDER_SYM;
275.  	else if(x == xdnladder && y == ydnladder) tmp = DNLADDER_SYM;
276.  #endif
277.  	else if((ttmp = t_at(x,y)) && ttmp->ttyp == WEB) tmp = WEB_SYM;
278.  	else if(ttmp && ttmp->tseen) tmp = TRAP_SYM;
279.  	else switch(room->typ) {
280.  	case SCORR:
281.  		tmp = STONE_SYM;
282.  		break;
283.  	case SDOOR:
284.  		croom = inroom(x,y);
285.  		if(croom == -1) {
286.  #ifdef STRONGHOLD
287.  			if(IS_WALL(levl[x-1][y].typ)) tmp = HWALL_SYM;
288.  			else tmp = VWALL_SYM;
289.  			break;
290.  #else
291.  			impossible("door %d %d not in room",x,y);
292.  #endif
293.  		}
294.  		if(rooms[croom].lx-1 == x || rooms[croom].hx+1 == x)
295.  			tmp = VWALL_SYM;
296.  		else	/* SDOORs aren't created on corners */
297.  			tmp = HWALL_SYM;
298.    		break;
299.  	case HWALL:
300.  #ifdef STRONGHOLD
301.  		if (is_maze_lev && is_drawbridge_wall(x,y) >= 0) tmp = DB_HWALL_SYM;
302.  		else
303.  #endif
304.  		tmp = HWALL_SYM;
305.  		break;
306.  	case VWALL:
307.  #ifdef STRONGHOLD
308.  		if (is_maze_lev && is_drawbridge_wall(x,y) >= 0) tmp = DB_VWALL_SYM;
309.  		else
310.  #endif
311.  		tmp = VWALL_SYM;
312.  		break;
313.  	case TLCORNER:
314.  		tmp = TLCORN_SYM;
315.  		break;
316.  	case TRCORNER:
317.  		tmp = TRCORN_SYM;
318.  		break;
319.  	case BLCORNER:
320.  		tmp = BLCORN_SYM;
321.  		break;
322.  	case BRCORNER:
323.  		tmp = BRCORN_SYM;
324.  		break;
325.  	case DOOR:
326.  		tmp = DOOR_SYM;
327.  		break;
328.  	case CORR:
329.  		tmp = CORR_SYM;
330.  		break;
331.  #ifdef STRONGHOLD
332.  	case DRAWBRIDGE_UP:
333.  		if((room->drawbridgemask & DB_UNDER) == DB_MOAT) tmp = POOL_SYM;
334.  		else tmp = ROOM_SYM;
335.  		break;
336.  	case DRAWBRIDGE_DOWN:
337.  #endif /* STRONGHOLD /**/
338.  	case ROOM:
339.  		if(room->lit || cansee(x,y) || Blind) tmp = ROOM_SYM;
340.  		else tmp = STONE_SYM;
341.  		break;
342.  #ifdef POLYSELF
343.  	case STONE:
344.  		tmp = STONE_SYM;
345.  		break;
346.  #endif
347.  #ifdef FOUNTAINS
348.  	case FOUNTAIN:
349.  		tmp = FOUNTAIN_SYM;
350.  		break;
351.  #endif
352.  #ifdef THRONES
353.  	case THRONE:
354.  		tmp = THRONE_SYM;
355.  		break;
356.  #endif
357.  #ifdef SINKS
358.  	case SINK:
359.  		tmp = SINK_SYM;
360.  		break;
361.  #endif
362.  #ifdef ALTARS
363.  	case ALTAR:
364.  		tmp = ALTAR_SYM;
365.  		break;
366.  #endif
367.  	case CROSSWALL:
368.  		tmp = CRWALL_SYM;
369.  		break;
370.  	case TUWALL:
371.  		tmp = TUWALL_SYM;
372.  		break;
373.  	case TDWALL:
374.  		tmp = TDWALL_SYM;
375.  		break;
376.  	case TLWALL:
377.  		tmp = TLWALL_SYM;
378.  		break;
379.  	case TRWALL:
380.  		tmp = TRWALL_SYM;
381.  		break;
382.  /*
383.  	case POOL:
384.  		tmp = POOL_SYM;
385.  		break;
386.  */
387.  	default:
388.  		tmp = ERRCHAR;
389.  	}
390.  	return(tmp);
391.  }
392.  
393.  void
394.  newsym(x,y)
395.  register int x, y;
396.  {
397.  	atl(x,y,(char)news0(x,y));
398.  }
399.  
400.  /* used with wand of digging (or pick-axe): fill scrsym and force display */
401.  /* also when a POOL evaporates */
402.  void
403.  mnewsym(x, y)
404.  register int x, y;
405.  {
406.  	register struct rm *room;
407.  	uchar newscrsym;	/* OIS */
408.  
409.  	if(!vism_at(x,y)) {
410.  		room = &levl[x][y];
411.  		newscrsym = news0(x,y);
412.  		if(room->scrsym != newscrsym) {
413.  			room->scrsym = newscrsym;
414.  			room->seen = 0;
415.  		}
416.  	}
417.  }
418.  
419.  void
420.  nosee(x,y)
421.  register int x, y;
422.  {
423.  	register struct rm *room;
424.  
425.  	if(!isok(x,y)) return;
426.  	room = &levl[x][y];
427.  	if(room->scrsym == ROOM_SYM && !room->lit && !Blind) {
428.  		room->scrsym = STONE_SYM;	/* was ' ' -- OIS */
429.  		room->new = 1;
430.  		on_scr(x,y);
431.  	}
432.  }
433.  
434.  void
435.  prl1(x,y)
436.  register int x, y;
437.  {
438.  	if(u.dx) {
439.  		if(u.dy) {
440.  			prl(x-(2*u.dx),y);
441.  			prl(x-u.dx,y);
442.  			prl(x,y);
443.  			prl(x,y-u.dy);
444.  			prl(x,y-(2*u.dy));
445.  		} else {
446.  			prl(x,y-1);
447.  			prl(x,y);
448.  			prl(x,y+1);
449.  		}
450.  	} else {
451.  		prl(x-1,y);
452.  		prl(x,y);
453.  		prl(x+1,y);
454.  	}
455.  }
456.  
457.  void
458.  nose1(x,y)
459.  register int x, y;
460.  {
461.  	if(u.dx) {
462.  		if(u.dy) {
463.  			nosee(x,u.uy);
464.  			nosee(x,u.uy-u.dy);
465.  			nosee(x,y);
466.  			nosee(u.ux-u.dx,y);
467.  			nosee(u.ux,y);
468.  		} else {
469.  			nosee(x,y-1);
470.  			nosee(x,y);
471.  			nosee(x,y+1);
472.  		}
473.  	} else {
474.  		nosee(x-1,y);
475.  		nosee(x,y);
476.  		nosee(x+1,y);
477.  	}
478.  }
479.  
480.  int
481.  vism_at(x,y)
482.  register int x, y;
483.  {
484.  	if(x == u.ux && y == u.uy && !Invisible) return(1);
485.  
486.  	if(levl[x][y].mmask)
487.  		if (Blind && Telepat || canseemon(m_at(x,y)))
488.  		    return(1);
489.  		else return ((HTelepat & WORN_HELMET) &&
490.  			     (dist(x, y) <= (BOLT_LIM * BOLT_LIM)));
491.  	return(0);
492.  }
493.  
494.  #ifdef NEWSCR
495.  void
496.  pobj(obj)
497.  register struct obj *obj;
498.  {
499.  	register int show = (!obj->oinvis || See_invisible) &&
500.  		cansee(obj->ox,obj->oy);
501.  	if(obj->odispl){
502.  		if(obj->odx != obj->ox || obj->ody != obj->oy || !show)
503.  		if(!vism_at(obj->odx,obj->ody)){
504.  			newsym(obj->odx, obj->ody);
505.  			obj->odispl = 0;
506.  		}
507.  	}
508.  	if(show && !vism_at(obj->ox,obj->oy)){
509.  		atl(obj->ox,obj->oy,obj->olet);
510.  		obj->odispl = 1;
511.  		obj->odx = obj->ox;
512.  		obj->ody = obj->oy;
513.  	}
514.  }
515.  #endif /* NEWSCR /**/
516.  
517.  void
518.  unpobj(obj)
519.  register struct obj *obj;
520.  {
521.  /* 	if(obj->odispl){
522.  		if(!vism_at(obj->odx, obj->ody))
523.  			newsym(obj->odx, obj->ody);
524.  		obj->odispl = 0;
525.  	}
526.  */
527.  	if(!vism_at(obj->ox,obj->oy))
528.  		newsym(obj->ox,obj->oy);
529.  }
530.  
531.  #ifdef WORM
532.  static void
533.  pwseg(wtmp)
534.  register struct wseg *wtmp;
535.  {
536.  	if(!wtmp->wdispl){
537.  		atl(wtmp->wx, wtmp->wy, S_WORM_TAIL);
538.  		wtmp->wdispl = 1;
539.  	}
540.  }
541.  #endif

Also on Fandom

Random Wiki