]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.do_name.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$Id: hack.do_name.c,v 1.2 1993/08/02 17:17:05 mycroft Exp $";
14 getpos(force
,goal
) int force
; char *goal
; {
16 extern char sdir
[]; /* defined in hack.c */
17 extern schar xdir
[], ydir
[]; /* idem */
18 extern char *visctrl(); /* see below */
20 pline("(For instructions type a ?)");
24 while((c
= readchar()) != '.'){
25 for(i
=0; i
<8; i
++) if(sdir
[i
] == c
){
26 if(1 <= cx
+ xdir
[i
] && cx
+ xdir
[i
] <= COLNO
)
28 if(0 <= cy
+ ydir
[i
] && cy
+ ydir
[i
] <= ROWNO
-1)
33 pline("Use [hjkl] to move the cursor to %s.", goal
);
34 pline("Type a . when you are at the right place.");
36 pline("Unknown direction: '%s' (%s).",
38 force
? "use hjkl or ." : "aborted");
55 register int cx
,cy
,lth
,i
;
56 register struct monst
*mtmp
, *mtmp2
;
57 extern char *lmonnam();
58 cc
= getpos(0, "the monster you want to name");
64 if(cx
== u
.ux
&& cy
== u
.uy
)
65 pline("This ugly monster is called %s and cannot be renamed.",
68 pline("There is no monster there.");
72 pline("I see no monster there.");
76 pline("I cannot see a monster there.");
79 pline("What do you want to call %s? ", lmonnam(mtmp
));
82 if(!*buf
|| *buf
== '\033')
89 mtmp2
= newmonst(mtmp
->mxlth
+ lth
);
91 for(i
=0; i
<mtmp
->mxlth
; i
++)
92 ((char *) mtmp2
->mextra
)[i
] = ((char *) mtmp
->mextra
)[i
];
93 mtmp2
->mnamelth
= lth
;
94 (void) strcpy(NAME(mtmp2
), buf
);
100 * This routine changes the address of obj . Be careful not to call it
101 * when there might be pointers around in unknown places. For now: only
102 * when obj is in the inventory.
104 do_oname(obj
) register struct obj
*obj
; {
105 register struct obj
*otmp
, *otmp2
;
108 pline("What do you want to name %s? ", doname(obj
));
111 if(!*buf
|| *buf
== '\033')
120 otmp2
->onamelth
= lth
;
121 (void) strcpy(ONAME(otmp2
), buf
);
123 setworn((struct obj
*) 0, obj
->owornmask
);
124 setworn(otmp2
, otmp2
->owornmask
);
126 /* do freeinv(obj); etc. by hand in order to preserve
127 the position of this object in the inventory */
128 if(obj
== invent
) invent
= otmp2
;
129 else for(otmp
= invent
; ; otmp
= otmp
->nobj
){
131 panic("Do_oname: cannot find obj.");
132 if(otmp
->nobj
== obj
){
137 /* obfree(obj, otmp2); /* now unnecessary: no pointers on bill */
138 free((char *) obj
); /* let us hope nobody else saved a pointer */
143 register struct obj
*obj
;
145 pline("Do you want to name an individual object? [ny] ");
150 obj
= getobj("#", "name");
151 if(obj
) do_oname(obj
);
154 obj
= getobj("?!=/", "call");
161 register struct obj
*obj
;
165 register char **str1
;
166 extern char *xname();
173 pline("Call %s %s: ", index(vowels
,*str
) ? "an" : "a", str
);
176 if(!*buf
|| *buf
== '\033')
178 str
= newstring(strlen(buf
)+1);
179 (void) strcpy(str
,buf
);
180 str1
= &(objects
[obj
->otyp
].oc_uname
);
181 if(*str1
) free(*str1
);
185 char *ghostnames
[] = { /* these names should have length < PL_NSIZ */
186 "adri", "andries", "andreas", "bert", "david", "dirk", "emile",
187 "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
188 "kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
193 xmonnam(mtmp
, vb
) register struct monst
*mtmp
; int vb
; {
194 static char buf
[BUFSZ
]; /* %% */
195 extern char *shkname();
196 if(mtmp
->mnamelth
&& !vb
) {
197 (void) strcpy(buf
, NAME(mtmp
));
200 switch(mtmp
->data
->mlet
) {
202 { register char *gn
= (char *) mtmp
->mextra
;
203 if(!*gn
) { /* might also look in scorefile */
204 gn
= ghostnames
[rn2(SIZE(ghostnames
))];
206 strcpy((char *) mtmp
->mextra
, !rn2(5) ? plname
: gn
);
208 (void) sprintf(buf
, "%s's ghost", gn
);
213 (void) strcpy(buf
, shkname(mtmp
));
216 /* fall into next case */
218 (void) sprintf(buf
, "the %s%s",
219 mtmp
->minvis
? "invisible " : "",
222 if(vb
&& mtmp
->mnamelth
) {
223 (void) strcat(buf
, " called ");
224 (void) strcat(buf
, NAME(mtmp
));
230 lmonnam(mtmp
) register struct monst
*mtmp
; {
231 return(xmonnam(mtmp
, 1));
235 monnam(mtmp
) register struct monst
*mtmp
; {
236 return(xmonnam(mtmp
, 0));
240 Monnam(mtmp
) register struct monst
*mtmp
; {
241 register char *bp
= monnam(mtmp
);
242 if('a' <= *bp
&& *bp
<= 'z') *bp
+= ('A' - 'a');
248 register struct monst
*mtmp
;
251 register char *bp
= monnam(mtmp
);
252 static char buf
[BUFSZ
]; /* %% */
254 if(!strncmp(bp
, "the ", 4)) bp
+= 4;
255 (void) sprintf(buf
, "the %s %s", adj
, bp
);
261 register struct monst
*mtmp
;
264 register char *bp
= amonnam(mtmp
,adj
);
271 Xmonnam(mtmp
) register struct monst
*mtmp
; {
272 register char *bp
= Monnam(mtmp
);
273 if(!strncmp(bp
, "The ", 4)) {