home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / HACKSRC.ZIP / DO_NAME.C < prev    next >
C/C++ Source or Header  |  1985-10-16  |  7KB  |  299 lines

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