Wikia

Wikihack

Source:NetHack 1.3d/do name.c

2,032pages on
this wiki
Talk0

Below is the full text to do_name.c from the source code of NetHack 1.3d. To link to a particular line, write [[NetHack 1.3d/do_name.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: @(#)do_name.c	1.3	87/07/14
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* do_name.c - version 1.0.3 */
4.    
5.    #include <stdio.h>
6.    #include "hack.h"
7.    extern char plname[];
8.    extern char *rndmonnam();
9.    
10.   coord
11.   getpos(force,goal) int force; char *goal; {
12.   register cx,cy,i,c;
13.   extern char sdir[];		/* defined in hack.c */
14.   extern schar xdir[], ydir[];	/* idem */
15.   extern char *visctrl();		/* see below */
16.   coord cc;
17.   	pline("(For instructions type a ?)");
18.   	cx = u.ux;
19.   	cy = u.uy;
20.   	curs(cx,cy+2);
21.   	while((c = readchar()) != '.'){
22.   		for(i=0; i<8; i++) if(sdir[i] == c){
23.   			if(1 <= cx + xdir[i] && cx + xdir[i] <= COLNO)
24.   				cx += xdir[i];
25.   			if(0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO-1)
26.   				cy += ydir[i];
27.   			goto nxtc;
28.   		}
29.   		if(c == '?'){
30.   			pline("Use [hjkl] to move the cursor to %s.", goal);
31.   			pline("Type a . when you are at the right place.");
32.   		} else {
33.   			pline("Unknown direction: '%s' (%s).",
34.   				visctrl(c),
35.   				force ? "use hjkl or ." : "aborted");
36.   			if(force) goto nxtc;
37.   			cc.x = -1;
38.   			cc.y = 0;
39.   			return(cc);
40.   		}
41.   	nxtc:	;
42.   		curs(cx,cy+2);
43.   	}
44.   	cc.x = cx;
45.   	cc.y = cy;
46.   	return(cc);
47.   }
48.   
49.   do_mname(){
50.   char buf[BUFSZ];
51.   coord cc;
52.   register int cx,cy,lth,i;
53.   register struct monst *mtmp, *mtmp2;
54.   extern char *lmonnam();
55.   	cc = getpos(0, "the monster you want to name");
56.   	cx = cc.x;
57.   	cy = cc.y;
58.   	if(cx < 0) return(0);
59.   #ifdef DGKMOD
60.   	if (cx == u.ux && cy == u.uy) {
61.   		pline("This ugly monster is called %s and cannot be renamed.",
62.   		plname);
63.   		return(1);
64.   	}
65.   	if (!cansee(cx, cy) || !(mtmp = m_at(cx, cy)) || mtmp->mimic) {
66.   		pline("I see no monster there.");
67.   		return(1);
68.   	}
69.   #else
70.   	mtmp = m_at(cx,cy);
71.   	if(!mtmp){
72.   	    if(cx == u.ux && cy == u.uy)
73.   		pline("This ugly monster is called %s and cannot be renamed.",
74.   		    plname);
75.   	    else
76.   		pline("There is no monster there.");
77.   	    return(1);
78.   	}
79.   	if(mtmp->mimic){
80.   	    pline("I see no monster there.");
81.   	    return(1);
82.   	}
83.   	if(!cansee(cx,cy)) {
84.   	    pline("I cannot see a monster there.");
85.   	    return(1);
86.   	}
87.   #endif
88.   	pline("What do you want to call %s? ", lmonnam(mtmp));
89.   	getlin(buf);
90.   	clrlin();
91.   	if(!*buf || *buf == '\033')
92.   		return(1);
93.   	lth = strlen(buf)+1;
94.   	if(lth > 63){
95.   		buf[62] = 0;
96.   		lth = 63;
97.   	}
98.   	mtmp2 = newmonst(mtmp->mxlth + lth);
99.   	*mtmp2 = *mtmp;
100.  	for(i=0; i<mtmp->mxlth; i++)
101.  		((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i];
102.  	mtmp2->mnamelth = lth;
103.  	(void) strcpy(NAME(mtmp2), buf);
104.  	replmon(mtmp,mtmp2);
105.  	return(1);
106.  }
107.  
108.  /*
109.   * This routine changes the address of  obj . Be careful not to call it
110.   * when there might be pointers around in unknown places. For now: only
111.   * when  obj  is in the inventory.
112.   */
113.  do_oname(obj) register struct obj *obj; {
114.  register struct obj *otmp, *otmp2;
115.  register lth;
116.  char buf[BUFSZ];
117.  	pline("What do you want to name %s? ", doname(obj));
118.  	getlin(buf);
119.  	clrlin();
120.  	if(!*buf || *buf == '\033')
121.  		return;
122.  	lth = strlen(buf)+1;
123.  	if(lth > 63){
124.  		buf[62] = 0;
125.  		lth = 63;
126.  	}
127.  	otmp2 = newobj(lth);
128.  	*otmp2 = *obj;
129.  	otmp2->onamelth = lth;
130.  	(void) strcpy(ONAME(otmp2), buf);
131.  
132.  	setworn((struct obj *) 0, obj->owornmask);
133.  	setworn(otmp2, otmp2->owornmask);
134.  
135.  	/* do freeinv(obj); etc. by hand in order to preserve
136.  	   the position of this object in the inventory */
137.  	if(obj == invent) invent = otmp2;
138.  	else for(otmp = invent; ; otmp = otmp->nobj){
139.  		if(!otmp)
140.  			panic("Do_oname: cannot find obj.");
141.  		if(otmp->nobj == obj){
142.  			otmp->nobj = otmp2;
143.  			break;
144.  		}
145.  	}
146.  	/* obfree(obj, otmp2);	/* now unnecessary: no pointers on bill */
147.  	free((char *) obj);	/* let us hope nobody else saved a pointer */
148.  }
149.  
150.  ddocall()
151.  {
152.  	register struct obj *obj;
153.  	char	ch;
154.  
155.  #ifdef REDO
156.  	if (!in_doagain)
157.  #endif
158.  		pline("Do you want to name an individual object? [ny] ");
159.  	switch(ch = readchar()) {
160.  	case '\033':
161.  		break;
162.  	case 'y':
163.  #ifdef REDO
164.  		savech(ch);
165.  #endif
166.  		obj = getobj("#", "name");
167.  		if(obj) do_oname(obj);
168.  		break;
169.  	default:
170.  #ifdef REDO
171.  		savech(ch);
172.  #endif
173.  #ifdef KAA
174.  		obj = getobj("?!=/*", "call");
175.  #else
176.  		obj = getobj("?!=/", "call");
177.  #endif
178.  		if(obj) docall(obj);
179.  	}
180.  	return(0);
181.  }
182.  
183.  docall(obj)
184.  register struct obj *obj;
185.  {
186.  	char buf[BUFSZ];
187.  	struct obj otemp;
188.  	register char **str1;
189.  	extern char *xname();
190.  	register char *str;
191.  
192.  	otemp = *obj;
193.  	otemp.quan = 1;
194.  	otemp.onamelth = 0;
195.  	str = xname(&otemp);
196.  	pline("Call %s %s: ", index(vowels,*str) ? "an" : "a", str);
197.  	getlin(buf);
198.  	clrlin();
199.  	if(!*buf || *buf == '\033')
200.  		return;
201.  	str = newstring(strlen(buf)+1);
202.  	(void) strcpy(str,buf);
203.  	str1 = &(objects[obj->otyp].oc_uname);
204.  	if(*str1) free(*str1);
205.  	*str1 = str;
206.  }
207.  
208.  char *ghostnames[] = {		/* these names should have length < PL_NSIZ */
209.  #ifdef DGKMOD
210.  	/* Capitalize the names for asthetics -dgk
211.  	 */
212.  	"Adri", "Andries", "Andreas", "Bert", "David", "Dirk", "Emile",
213.  	"Frans", "Fred", "Greg", "Hether", "Jay", "John", "Jon", "Karnov",
214.  	"Kay", "Kenny", "Maud", "Michiel", "Mike", "Peter", "Robert",
215.  	"Ron", "Tom", "Wilmar", "Nick Danger", "Phoenix", "Miracleman"
216.  #else
217.  	"adri", "andries", "andreas", "bert", "david", "dirk", "emile",
218.  	"frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
219.  	"kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
220.  	"tom", "wilmar"
221.  #endif
222.  };
223.  
224.  char *
225.  xmonnam(mtmp, vb) register struct monst *mtmp; int vb; {
226.  static char buf[BUFSZ];		/* %% */
227.  extern char *shkname();
228.  	if(mtmp->mnamelth && !vb) {
229.  		(void) strcpy(buf, NAME(mtmp));
230.  		return(buf);
231.  	}
232.  	switch(mtmp->data->mlet) {
233.  	case ' ':
234.  		{ register char *gn = (char *) mtmp->mextra;
235.  		  if(!*gn) {		/* might also look in scorefile */
236.  		    gn = ghostnames[rn2(SIZE(ghostnames))];
237.  		    if(!rn2(2)) (void)
238.  		      strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn);
239.  		  }
240.  		  (void) sprintf(buf, "%s's ghost", gn);
241.  		}
242.  		break;
243.  	case '@':
244.  		if(mtmp->isshk) {
245.  			(void) strcpy(buf, shkname(mtmp));
246.  			break;
247.  		}
248.  		/* fall into next case */
249.  	default:
250.  		(void) sprintf(buf, "the %s%s",
251.  			mtmp->minvis ? "invisible " : "",
252.  			(Hallucination ? rndmonnam() : mtmp->data->mname));
253.  	}
254.  	if(vb && mtmp->mnamelth) {
255.  		(void) strcat(buf, " called ");
256.  		(void) strcat(buf, NAME(mtmp));
257.  	}
258.  	return(buf);
259.  }
260.  
261.  char *
262.  lmonnam(mtmp) register struct monst *mtmp; {
263.  	return(xmonnam(mtmp, 1));
264.  }
265.  
266.  char *
267.  monnam(mtmp) register struct monst *mtmp; {
268.  	return(xmonnam(mtmp, 0));
269.  }
270.  
271.  char *
272.  Monnam(mtmp) register struct monst *mtmp; {
273.  register char *bp = monnam(mtmp);
274.  	if('a' <= *bp && *bp <= 'z') *bp += ('A' - 'a');
275.  	return(bp);
276.  }
277.  
278.  char *
279.  amonnam(mtmp,adj)
280.  register struct monst *mtmp;
281.  register char *adj;
282.  {
283.  	register char *bp = monnam(mtmp);
284.  	static char buf[BUFSZ];		/* %% */
285.  
286.  	if(!strncmp(bp, "the ", 4)) bp += 4;
287.  	(void) sprintf(buf, "the %s %s", adj, bp);
288.  	return(buf);
289.  }
290.  
291.  char *
292.  Amonnam(mtmp, adj)
293.  register struct monst *mtmp;
294.  register char *adj;
295.  {
296.  	register char *bp = amonnam(mtmp,adj);
297.  
298.  	*bp = 'T';
299.  	return(bp);
300.  }
301.  
302.  char *
303.  Xmonnam(mtmp) register struct monst *mtmp; {
304.  register char *bp = Monnam(mtmp);
305.  	if(!strncmp(bp, "The ", 4)) {
306.  #ifdef KAA
307.  		if(index("AEIOUaeio",*(bp+4))) {
308.  			bp += 1; *(bp+1) = 'n';
309.  		} else
310.  #endif
311.  			bp += 2;
312.  		*bp = 'A';
313.  	}
314.  	return(bp);
315.  }
316.  
317.  char *
318.  defmonnam(mtmp) register struct monst *mtmp; {
319.  register char *bp = Xmonnam(mtmp);
320.  	if (!strncmp(bp,"A ",2) || !strncmp(bp,"An ",3))
321.  		*bp = 'a';
322.  	return(bp);
323.  }
324.  
325.  char *
326.  rndmonnam() {  /* Random name of monster type, if hallucinating */
327.  int x;
328.  	if ((x=rn2(CMNUM+2)) != CMNUM+1) return (&mons[x])->mname;
329.  	return("giant eel");
330.  }
331.  
332.  char *
333.  visctrl(c)
334.  char c;
335.  {
336.  static char ccc[3];
337.  	if(c < 040) {
338.  		ccc[0] = '^';
339.  		ccc[1] = c + 0100;
340.  		ccc[2] = 0;
341.  	} else {
342.  		ccc[0] = c;
343.  		ccc[1] = 0;
344.  	}
345.  	return(ccc);
346.  }

Around Wikia's network

Random Wiki