1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
   2: /* hack.cmd.c - version 1.0.3 */
   3: 
   4: #include    "hack.h"
   5: #include    "def.func_tab.h"
   6: 
   7: int doredraw(),doredotopl(),dodrop(),dodrink(),doread(),dosearch(),dopickup(),
   8: doversion(),doweararm(),dowearring(),doremarm(),doremring(),dopay(),doapply(),
   9: dosave(),dowield(),ddoinv(),dozap(),ddocall(),dowhatis(),doengrave(),dotele(),
  10: dohelp(),doeat(),doddrop(),do_mname(),doidtrap(),doprwep(),doprarm(),
  11: doprring(),doprgold(),dodiscovered(),dotypeinv(),dolook(),doset(),
  12: doup(), dodown(), done1(), donull(), dothrow(), doextcmd(), dodip(), dopray();
  13: #ifdef SHELL
  14: int dosh();
  15: #endif SHELL
  16: #ifdef SUSPEND
  17: int dosuspend();
  18: #endif SUSPEND
  19: 
  20: struct func_tab cmdlist[]={
  21:     '\020', doredotopl,
  22:     '\022', doredraw,
  23:     '\024', dotele,
  24: #ifdef SUSPEND
  25:     '\032', dosuspend,
  26: #endif SUSPEND
  27:     'a', doapply,
  28: /*	'A' : UNUSED */
  29: /*	'b', 'B' : go sw */
  30:     'c', ddocall,
  31:     'C', do_mname,
  32:     'd', dodrop,
  33:     'D', doddrop,
  34:     'e', doeat,
  35:     'E', doengrave,
  36: /*	'f', 'F' : multiple go (might become 'fight') */
  37: /*	'g', 'G' : UNUSED */
  38: /*	'h', 'H' : go west */
  39:     'I', dotypeinv,     /* Robert Viduya */
  40:     'i', ddoinv,
  41: /*	'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */
  42: /*	'o', doopen,	*/
  43:     'O', doset,
  44:     'p', dopay,
  45:     'P', dowearring,
  46:     'q', dodrink,
  47:     'Q', done1,
  48:     'r', doread,
  49:     'R', doremring,
  50:     's', dosearch,
  51:     'S', dosave,
  52:     't', dothrow,
  53:     'T', doremarm,
  54: /*	'u', 'U' : go ne */
  55:     'v', doversion,
  56: /*	'V' : UNUSED */
  57:     'w', dowield,
  58:     'W', doweararm,
  59: /*	'x', 'X' : UNUSED */
  60: /*	'y', 'Y' : go nw */
  61:     'z', dozap,
  62: /*	'Z' : UNUSED */
  63:     '<', doup,
  64:     '>', dodown,
  65:     '/', dowhatis,
  66:     '?', dohelp,
  67: #ifdef SHELL
  68:     '!', dosh,
  69: #endif SHELL
  70:     '.', donull,
  71:     ' ', donull,
  72:     ',', dopickup,
  73:     ':', dolook,
  74:     '^', doidtrap,
  75:     '\\', dodiscovered,     /* Robert Viduya */
  76:      WEAPON_SYM,  doprwep,
  77:      ARMOR_SYM,  doprarm,
  78:      RING_SYM,  doprring,
  79:     '$', doprgold,
  80:     '#', doextcmd,
  81:     0,0,0
  82: };
  83: 
  84: struct ext_func_tab extcmdlist[] = {
  85:     "dip", dodip,
  86:     "pray", dopray,
  87:     (char *) 0, donull
  88: };
  89: 
  90: extern char *parse(), lowc(), unctrl(), quitchars[];
  91: 
  92: rhack(cmd)
  93: register char *cmd;
  94: {
  95:     register struct func_tab *tlist = cmdlist;
  96:     boolean firsttime = FALSE;
  97:     register res;
  98: 
  99:     if(!cmd) {
 100:         firsttime = TRUE;
 101:         flags.nopick = 0;
 102:         cmd = parse();
 103:     }
 104:     if(!*cmd || *cmd == 0377 || (flags.no_rest_on_space && *cmd == ' ')){
 105:         bell();
 106:         flags.move = 0;
 107:         return;     /* probably we just had an interrupt */
 108:     }
 109:     if(movecmd(*cmd)) {
 110:     walk:
 111:         if(multi) flags.mv = 1;
 112:         domove();
 113:         return;
 114:     }
 115:     if(movecmd(lowc(*cmd))) {
 116:         flags.run = 1;
 117:     rush:
 118:         if(firsttime){
 119:             if(!multi) multi = COLNO;
 120:             u.last_str_turn = 0;
 121:         }
 122:         flags.mv = 1;
 123: #ifdef QUEST
 124:         if(flags.run >= 4) finddir();
 125:         if(firsttime){
 126:             u.ux0 = u.ux + u.dx;
 127:             u.uy0 = u.uy + u.dy;
 128:         }
 129: #endif QUEST
 130:         domove();
 131:         return;
 132:     }
 133:     if((*cmd == 'f' && movecmd(cmd[1])) || movecmd(unctrl(*cmd))) {
 134:         flags.run = 2;
 135:         goto rush;
 136:     }
 137:     if(*cmd == 'F' && movecmd(lowc(cmd[1]))) {
 138:         flags.run = 3;
 139:         goto rush;
 140:     }
 141:     if(*cmd == 'm' && movecmd(cmd[1])) {
 142:         flags.run = 0;
 143:         flags.nopick = 1;
 144:         goto walk;
 145:     }
 146:     if(*cmd == 'M' && movecmd(lowc(cmd[1]))) {
 147:         flags.run = 1;
 148:         flags.nopick = 1;
 149:         goto rush;
 150:     }
 151: #ifdef QUEST
 152:     if(*cmd == cmd[1] && (*cmd == 'f' || *cmd == 'F')) {
 153:         flags.run = 4;
 154:         if(*cmd == 'F') flags.run += 2;
 155:         if(cmd[2] == '-') flags.run += 1;
 156:         goto rush;
 157:     }
 158: #endif QUEST
 159:     while(tlist->f_char) {
 160:         if(*cmd == tlist->f_char){
 161:             res = (*(tlist->f_funct))();
 162:             if(!res) {
 163:                 flags.move = 0;
 164:                 multi = 0;
 165:             }
 166:             return;
 167:         }
 168:         tlist++;
 169:     }
 170:     { char expcmd[10];
 171:       register char *cp = expcmd;
 172:       while(*cmd && cp-expcmd < sizeof(expcmd)-2) {
 173:         if(*cmd >= 040 && *cmd < 0177)
 174:             *cp++ = *cmd++;
 175:         else {
 176:             *cp++ = '^';
 177:             *cp++ = *cmd++ ^ 0100;
 178:         }
 179:       }
 180:       *cp++ = 0;
 181:       pline("Unknown command '%s'.", expcmd);
 182:     }
 183:     multi = flags.move = 0;
 184: }
 185: 
 186: doextcmd()  /* here after # - now read a full-word command */
 187: {
 188:     char buf[BUFSZ];
 189:     register struct ext_func_tab *efp = extcmdlist;
 190: 
 191:     pline("# ");
 192:     getlin(buf);
 193:     clrlin();
 194:     if(buf[0] == '\033')
 195:         return(0);
 196:     while(efp->ef_txt) {
 197:         if(!strcmp(efp->ef_txt, buf))
 198:             return((*(efp->ef_funct))());
 199:         efp++;
 200:     }
 201:     pline("%s: unknown command.", buf);
 202:     return(0);
 203: }
 204: 
 205: char
 206: lowc(sym)
 207: char sym;
 208: {
 209:     return( (sym >= 'A' && sym <= 'Z') ? sym+'a'-'A' : sym );
 210: }
 211: 
 212: char
 213: unctrl(sym)
 214: char sym;
 215: {
 216:     return( (sym >= ('A' & 037) && sym <= ('Z' & 037)) ? sym + 0140 : sym );
 217: }
 218: 
 219: /* 'rogue'-like direction commands */
 220: char sdir[] = "hykulnjb><";
 221: schar xdir[10] = { -1,-1, 0, 1, 1, 1, 0,-1, 0, 0 };
 222: schar ydir[10] = {  0,-1,-1,-1, 0, 1, 1, 1, 0, 0 };
 223: schar zdir[10] = {  0, 0, 0, 0, 0, 0, 0, 0, 1,-1 };
 224: 
 225: movecmd(sym)    /* also sets u.dz, but returns false for <> */
 226: char sym;
 227: {
 228:     register char *dp;
 229: 
 230:     u.dz = 0;
 231:     if(!(dp = index(sdir, sym))) return(0);
 232:     u.dx = xdir[dp-sdir];
 233:     u.dy = ydir[dp-sdir];
 234:     u.dz = zdir[dp-sdir];
 235:     return(!u.dz);
 236: }
 237: 
 238: getdir(s)
 239: boolean s;
 240: {
 241:     char dirsym;
 242: 
 243:     if(s) pline("In what direction?");
 244:     dirsym = readchar();
 245:     if(!movecmd(dirsym) && !u.dz) {
 246:         if(!index(quitchars, dirsym))
 247:             pline("What a strange direction!");
 248:         return(0);
 249:     }
 250:     if(Confusion && !u.dz)
 251:         confdir();
 252:     return(1);
 253: }
 254: 
 255: confdir()
 256: {
 257:     register x = rn2(8);
 258:     u.dx = xdir[x];
 259:     u.dy = ydir[x];
 260: }
 261: 
 262: #ifdef QUEST
 263: finddir(){
 264: register int i, ui = u.di;
 265:     for(i = 0; i <= 8; i++){
 266:         if(flags.run & 1) ui++; else ui += 7;
 267:         ui %= 8;
 268:         if(i == 8){
 269:             pline("Not near a wall.");
 270:             flags.move = multi = 0;
 271:             return(0);
 272:         }
 273:         if(!isroom(u.ux+xdir[ui], u.uy+ydir[ui]))
 274:             break;
 275:     }
 276:     for(i = 0; i <= 8; i++){
 277:         if(flags.run & 1) ui += 7; else ui++;
 278:         ui %= 8;
 279:         if(i == 8){
 280:             pline("Not near a room.");
 281:             flags.move = multi = 0;
 282:             return(0);
 283:         }
 284:         if(isroom(u.ux+xdir[ui], u.uy+ydir[ui]))
 285:             break;
 286:     }
 287:     u.di = ui;
 288:     u.dx = xdir[ui];
 289:     u.dy = ydir[ui];
 290: }
 291: 
 292: isroom(x,y)  register x,y; {        /* what about POOL? */
 293:     return(isok(x,y) && (levl[x][y].typ == ROOM ||
 294:                 (levl[x][y].typ >= LDOOR && flags.run >= 6)));
 295: }
 296: #endif QUEST
 297: 
 298: isok(x,y) register x,y; {
 299:     /* x corresponds to curx, so x==1 is the first column. Ach. %% */
 300:     return(x >= 1 && x <= COLNO-1 && y >= 0 && y <= ROWNO-1);
 301: }

Defined functions

confdir defined in line 255; used 3 times
doextcmd defined in line 186; used 2 times
finddir defined in line 263; used 2 times
isroom defined in line 292; used 2 times
lowc defined in line 205; used 4 times
movecmd defined in line 225; used 9 times
rhack defined in line 92; used 2 times
unctrl defined in line 212; used 2 times

Defined variables

cmdlist defined in line 20; used 2 times
extcmdlist defined in line 84; used 2 times
sdir defined in line 220; used 4 times
xdir defined in line 221; used 5 times
ydir defined in line 222; used 5 times
zdir defined in line 223; used 1 times
Last modified: 1985-10-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3399
Valid CSS Valid XHTML 1.0 Strict