1997-10-19 20:56:41 +04:00
|
|
|
/* $NetBSD: hack.do_name.c,v 1.4 1997/10/19 16:57:46 christos Exp $ */
|
|
|
|
|
1993-08-02 21:16:36 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
|
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:16:36 +04:00
|
|
|
#ifndef lint
|
1997-10-19 20:56:41 +04:00
|
|
|
__RCSID("$NetBSD: hack.do_name.c,v 1.4 1997/10/19 16:57:46 christos Exp $");
|
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <stdlib.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "hack.h"
|
1997-10-19 20:56:41 +04:00
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
coord
|
1997-10-19 20:56:41 +04:00
|
|
|
getpos(force, goal)
|
|
|
|
int force;
|
|
|
|
char *goal;
|
|
|
|
{
|
|
|
|
int cx, cy, i, c;
|
|
|
|
coord cc;
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("(For instructions type a ?)");
|
|
|
|
cx = u.ux;
|
|
|
|
cy = u.uy;
|
1997-10-19 20:56:41 +04:00
|
|
|
curs(cx, cy + 2);
|
|
|
|
while ((c = readchar()) != '.') {
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
if (sdir[i] == c) {
|
|
|
|
if (1 <= cx + xdir[i] && cx + xdir[i] <= COLNO)
|
|
|
|
cx += xdir[i];
|
|
|
|
if (0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO - 1)
|
|
|
|
cy += ydir[i];
|
|
|
|
goto nxtc;
|
|
|
|
}
|
|
|
|
if (c == '?') {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("Use [hjkl] to move the cursor to %s.", goal);
|
|
|
|
pline("Type a . when you are at the right place.");
|
|
|
|
} else {
|
|
|
|
pline("Unknown direction: '%s' (%s).",
|
1997-10-19 20:56:41 +04:00
|
|
|
visctrl(c),
|
|
|
|
force ? "use hjkl or ." : "aborted");
|
|
|
|
if (force)
|
|
|
|
goto nxtc;
|
1993-03-21 12:45:37 +03:00
|
|
|
cc.x = -1;
|
|
|
|
cc.y = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
return (cc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
nxtc: ;
|
|
|
|
curs(cx, cy + 2);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
cc.x = cx;
|
|
|
|
cc.y = cy;
|
1997-10-19 20:56:41 +04:00
|
|
|
return (cc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
do_mname()
|
|
|
|
{
|
|
|
|
char buf[BUFSZ];
|
|
|
|
coord cc;
|
|
|
|
int cx, cy, lth, i;
|
|
|
|
struct monst *mtmp, *mtmp2;
|
1993-03-21 12:45:37 +03:00
|
|
|
cc = getpos(0, "the monster you want to name");
|
|
|
|
cx = cc.x;
|
|
|
|
cy = cc.y;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (cx < 0)
|
|
|
|
return (0);
|
|
|
|
mtmp = m_at(cx, cy);
|
|
|
|
if (!mtmp) {
|
|
|
|
if (cx == u.ux && cy == u.uy)
|
|
|
|
pline("This ugly monster is called %s and cannot be renamed.",
|
|
|
|
plname);
|
|
|
|
else
|
|
|
|
pline("There is no monster there.");
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp->mimic) {
|
|
|
|
pline("I see no monster there.");
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!cansee(cx, cy)) {
|
|
|
|
pline("I cannot see a monster there.");
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
pline("What do you want to call %s? ", lmonnam(mtmp));
|
|
|
|
getlin(buf);
|
|
|
|
clrlin();
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!*buf || *buf == '\033')
|
|
|
|
return (1);
|
|
|
|
lth = strlen(buf) + 1;
|
|
|
|
if (lth > 63) {
|
1993-03-21 12:45:37 +03:00
|
|
|
buf[62] = 0;
|
|
|
|
lth = 63;
|
|
|
|
}
|
|
|
|
mtmp2 = newmonst(mtmp->mxlth + lth);
|
|
|
|
*mtmp2 = *mtmp;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (i = 0; i < mtmp->mxlth; i++)
|
1993-03-21 12:45:37 +03:00
|
|
|
((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i];
|
|
|
|
mtmp2->mnamelth = lth;
|
|
|
|
(void) strcpy(NAME(mtmp2), buf);
|
1997-10-19 20:56:41 +04:00
|
|
|
replmon(mtmp, mtmp2);
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine changes the address of obj . Be careful not to call it
|
|
|
|
* when there might be pointers around in unknown places. For now: only
|
|
|
|
* when obj is in the inventory.
|
|
|
|
*/
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
do_oname(obj)
|
|
|
|
struct obj *obj;
|
|
|
|
{
|
|
|
|
struct obj *otmp, *otmp2;
|
|
|
|
int lth;
|
|
|
|
char buf[BUFSZ];
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("What do you want to name %s? ", doname(obj));
|
|
|
|
getlin(buf);
|
|
|
|
clrlin();
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!*buf || *buf == '\033')
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
1997-10-19 20:56:41 +04:00
|
|
|
lth = strlen(buf) + 1;
|
|
|
|
if (lth > 63) {
|
1993-03-21 12:45:37 +03:00
|
|
|
buf[62] = 0;
|
|
|
|
lth = 63;
|
|
|
|
}
|
|
|
|
otmp2 = newobj(lth);
|
|
|
|
*otmp2 = *obj;
|
|
|
|
otmp2->onamelth = lth;
|
|
|
|
(void) strcpy(ONAME(otmp2), buf);
|
|
|
|
|
|
|
|
setworn((struct obj *) 0, obj->owornmask);
|
|
|
|
setworn(otmp2, otmp2->owornmask);
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
/*
|
|
|
|
* do freeinv(obj); etc. by hand in order to preserve the position of
|
|
|
|
* this object in the inventory
|
|
|
|
*/
|
|
|
|
if (obj == invent)
|
|
|
|
invent = otmp2;
|
|
|
|
else
|
|
|
|
for (otmp = invent;; otmp = otmp->nobj) {
|
|
|
|
if (!otmp)
|
|
|
|
panic("Do_oname: cannot find obj.");
|
|
|
|
if (otmp->nobj == obj) {
|
|
|
|
otmp->nobj = otmp2;
|
|
|
|
break;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
#if 0
|
|
|
|
obfree(obj, otmp2); /* now unnecessary: no pointers on bill */
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
free((char *) obj); /* let us hope nobody else saved a pointer */
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
ddocall()
|
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct obj *obj;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
pline("Do you want to name an individual object? [ny] ");
|
1997-10-19 20:56:41 +04:00
|
|
|
switch (readchar()) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case '\033':
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
obj = getobj("#", "name");
|
1997-10-19 20:56:41 +04:00
|
|
|
if (obj)
|
|
|
|
do_oname(obj);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
obj = getobj("?!=/", "call");
|
1997-10-19 20:56:41 +04:00
|
|
|
if (obj)
|
|
|
|
docall(obj);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
docall(obj)
|
1997-10-19 20:56:41 +04:00
|
|
|
struct obj *obj;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
char buf[BUFSZ];
|
|
|
|
struct obj otemp;
|
|
|
|
char **str1;
|
|
|
|
char *str;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
otemp = *obj;
|
|
|
|
otemp.quan = 1;
|
|
|
|
otemp.onamelth = 0;
|
|
|
|
str = xname(&otemp);
|
1997-10-19 20:56:41 +04:00
|
|
|
pline("Call %s %s: ", strchr(vowels, *str) ? "an" : "a", str);
|
1993-03-21 12:45:37 +03:00
|
|
|
getlin(buf);
|
|
|
|
clrlin();
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!*buf || *buf == '\033')
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
1997-10-19 20:56:41 +04:00
|
|
|
str = newstring(strlen(buf) + 1);
|
|
|
|
(void) strcpy(str, buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
str1 = &(objects[obj->otyp].oc_uname);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (*str1)
|
|
|
|
free(*str1);
|
1993-03-21 12:45:37 +03:00
|
|
|
*str1 = str;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *ghostnames[] = {/* these names should have length < PL_NSIZ */
|
1993-03-21 12:45:37 +03:00
|
|
|
"adri", "andries", "andreas", "bert", "david", "dirk", "emile",
|
|
|
|
"frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
|
|
|
|
"kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
|
|
|
|
"tom", "wilmar"
|
|
|
|
};
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *
|
|
|
|
xmonnam(mtmp, vb)
|
|
|
|
struct monst *mtmp;
|
|
|
|
int vb;
|
|
|
|
{
|
|
|
|
static char buf[BUFSZ]; /* %% */
|
|
|
|
if (mtmp->mnamelth && !vb) {
|
1993-03-21 12:45:37 +03:00
|
|
|
(void) strcpy(buf, NAME(mtmp));
|
1997-10-19 20:56:41 +04:00
|
|
|
return (buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
switch (mtmp->data->mlet) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case ' ':
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
char *gn = (char *) mtmp->mextra;
|
|
|
|
if (!*gn) { /* might also look in scorefile */
|
|
|
|
gn = ghostnames[rn2(SIZE(ghostnames))];
|
|
|
|
if (!rn2(2))
|
|
|
|
(void)
|
|
|
|
strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn);
|
|
|
|
}
|
|
|
|
(void) sprintf(buf, "%s's ghost", gn);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '@':
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp->isshk) {
|
1993-03-21 12:45:37 +03:00
|
|
|
(void) strcpy(buf, shkname(mtmp));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall into next case */
|
|
|
|
default:
|
|
|
|
(void) sprintf(buf, "the %s%s",
|
1997-10-19 20:56:41 +04:00
|
|
|
mtmp->minvis ? "invisible " : "",
|
|
|
|
mtmp->data->mname);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (vb && mtmp->mnamelth) {
|
1993-03-21 12:45:37 +03:00
|
|
|
(void) strcat(buf, " called ");
|
|
|
|
(void) strcat(buf, NAME(mtmp));
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *
|
|
|
|
lmonnam(mtmp)
|
|
|
|
struct monst *mtmp;
|
|
|
|
{
|
|
|
|
return (xmonnam(mtmp, 1));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *
|
|
|
|
monnam(mtmp)
|
|
|
|
struct monst *mtmp;
|
|
|
|
{
|
|
|
|
return (xmonnam(mtmp, 0));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *
|
|
|
|
Monnam(mtmp)
|
|
|
|
struct monst *mtmp;
|
|
|
|
{
|
|
|
|
char *bp = monnam(mtmp);
|
|
|
|
if ('a' <= *bp && *bp <= 'z')
|
|
|
|
*bp += ('A' - 'a');
|
|
|
|
return (bp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *
|
|
|
|
amonnam(mtmp, adj)
|
|
|
|
struct monst *mtmp;
|
|
|
|
char *adj;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
char *bp = monnam(mtmp);
|
|
|
|
static char buf[BUFSZ]; /* %% */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(bp, "the ", 4))
|
|
|
|
bp += 4;
|
1993-03-21 12:45:37 +03:00
|
|
|
(void) sprintf(buf, "the %s %s", adj, bp);
|
1997-10-19 20:56:41 +04:00
|
|
|
return (buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *
|
1993-03-21 12:45:37 +03:00
|
|
|
Amonnam(mtmp, adj)
|
1997-10-19 20:56:41 +04:00
|
|
|
struct monst *mtmp;
|
|
|
|
char *adj;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
char *bp = amonnam(mtmp, adj);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
*bp = 'T';
|
1997-10-19 20:56:41 +04:00
|
|
|
return (bp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *
|
|
|
|
Xmonnam(mtmp)
|
|
|
|
struct monst *mtmp;
|
|
|
|
{
|
|
|
|
char *bp = Monnam(mtmp);
|
|
|
|
if (!strncmp(bp, "The ", 4)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
bp += 2;
|
|
|
|
*bp = 'A';
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (bp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char *
|
1993-03-21 12:45:37 +03:00
|
|
|
visctrl(c)
|
1997-10-19 20:56:41 +04:00
|
|
|
char c;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
static char ccc[3];
|
|
|
|
if (c < 040) {
|
1993-03-21 12:45:37 +03:00
|
|
|
ccc[0] = '^';
|
|
|
|
ccc[1] = c + 0100;
|
|
|
|
ccc[2] = 0;
|
|
|
|
} else {
|
|
|
|
ccc[0] = c;
|
|
|
|
ccc[1] = 0;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (ccc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|