1: /* $Header: us.c,v 7.0.1.3 87/01/13 17:13:21 lwall Exp $ */
   2: 
   3: /* $Log:	us.c,v $
   4:  * Revision 7.0.1.3  87/01/13  17:13:21  lwall
   5:  * Partially fixed ^S behavior.  It now just ignores ^S.
   6:  *
   7:  * Revision 7.0.1.2  86/12/12  17:06:09  lwall
   8:  * Baseline for net release.
   9:  *
  10:  * Revision 7.0.1.1  86/10/16  10:53:50  lwall
  11:  * Added Damage.  Fixed random bugs.
  12:  *
  13:  * Revision 7.0  86/10/08  15:14:21  lwall
  14:  * Split into separate files.  Added amoebas and pirates.
  15:  *
  16:  */
  17: 
  18: #include "EXTERN.h"
  19: #include "warp.h"
  20: #include "bang.h"
  21: #include "object.h"
  22: #include "play.h"
  23: #include "sig.h"
  24: #include "term.h"
  25: #include "util.h"
  26: #include "weapon.h"
  27: #include "INTERN.h"
  28: #include "us.h"
  29: 
  30: void
  31: us_init()
  32: {
  33:     ;
  34: }
  35: 
  36: void
  37: do_direction(dy,dx)
  38: int dy, dx;
  39: {
  40:     Reg1 int decr;
  41:     Reg2 OBJECT *obj;
  42: 
  43:     if (status < 2) {
  44:     if (cloaking) {
  45:         char ch;
  46: 
  47:         cloaked = FALSE;
  48:         ch = (ent->energy >= 500?'E':'e');
  49:         if (ch != ent->image) {
  50:         setimage(ent, ch);
  51:         }
  52:     }
  53:     decr = 5+abs(evely)+abs(evelx)+tractor*tractor;
  54:     if (ent->energy >= decr) {
  55:         ent->energy -= decr;
  56:         if (tractor) {
  57:         if (!damage || !damflag[NOTRACTORS]) {
  58:             if (!rand_mod(50)) {
  59:             damage++;
  60:             damflag[NOTRACTORS] = rand_mod(smarts+10)+2;
  61:             }
  62:             if (tract(ent,dy,dx,tractor)) {
  63:             evely += tractor*dy;
  64:             evelx += tractor*dx;
  65:             }
  66:         }
  67:         }
  68:         else if (!damage ||
  69:           (!entmode && !damflag[NOIMPULSE]) ||
  70:           (entmode && !damflag[NOWARP]) ) {
  71:         if (!rand_mod(30+500/(abs(evely)+abs(evelx)+1))) {
  72:             damage++;
  73:             damflag[entmode?NOWARP:NOIMPULSE] = rand_mod(smarts+10)+2;
  74:         }
  75:         evely += dy;
  76:         evelx += dx;
  77:         }
  78:         if (inumthols &&
  79:           (obj=occupant[(ent->posy+evely+YSIZE00)%YSIZE]
  80:                [(ent->posx+evelx+XSIZE00)%XSIZE] ) &&
  81:           obj->type == Web)
  82:         evely = evelx = 0;
  83:     }
  84:     }
  85:     else if (status == 2) {
  86:     decr = 500+abs(bvely)*5+abs(bvelx)*5+tractor*tractor*100;
  87:     if (base->energy >= decr) {
  88:         base->energy -= decr;
  89:         if (tractor) {
  90:         if (tract(base,dy,dx,tractor)) {
  91:             bvely += tractor*dy;
  92:             bvelx += tractor*dx;
  93:         }
  94:         }
  95:         else {
  96:         bvely += dy;
  97:         bvelx += dx;
  98:         }
  99:         if (inumthols &&
 100:           (obj=occupant[(base->posy+bvely+YSIZE00)%YSIZE]
 101:                [(base->posx+bvelx+XSIZE00)%XSIZE] ) &&
 102:           obj->type == Web)
 103:         bvely = bvelx = 0;
 104:     }
 105:     }
 106:     tractor = 0;
 107: }
 108: 
 109: void
 110: ctrl_direction(dy,dx)
 111: int dy, dx;
 112: {
 113:     if (status < 2) {
 114:     if (cloaking) {
 115:         char ch;
 116: 
 117:         cloaked = FALSE;
 118:         ch = (ent->energy >= 500?'E':'e');
 119:         if (ch != ent->image) {
 120:         setimage(ent, ch);
 121:         }
 122:     }
 123:     if (!damage || !damflag[NOPHASERS]) {
 124:         if (!rand_mod(200)) {
 125:         damage++;
 126:         damflag[NOPHASERS] = rand_mod(smarts+10)+2;
 127:         }
 128:         fire_phaser(ent, dy, dx);
 129:     }
 130:     }
 131:     else if (status == 2)
 132:     fire_phaser(base, dy, dx);
 133: }
 134: 
 135: void
 136: shift_direction(dy,dx)
 137: int dy, dx;
 138: {
 139:     if (status < 2) {
 140:     if (cloaking) {
 141:         char ch;
 142: 
 143:         cloaked = FALSE;
 144:         ch = (ent->energy >= 500?'E':'e');
 145:         if (ch != ent->image) {
 146:         setimage(ent, ch);
 147:         }
 148:     }
 149:     if (!damage || !damflag[NOTORPS]) {
 150:         if (!rand_mod(300)) {
 151:         damage++;
 152:         damflag[NOTORPS] = rand_mod(smarts+10)+2;
 153:         }
 154:         fire_torp(ent, dy, dx);
 155:     }
 156:     }
 157:     else if (status == 2)
 158:     fire_torp(base, dy, dx);
 159: }
 160: 
 161: void
 162: get_commands(done)
 163: bool *done;
 164: {
 165:     static char ch[80];
 166:     Reg1 int i;
 167:     Reg2 int count;
 168:     Reg3 bool ctrla = FALSE;
 169:     char numdestructs = 0, numzaps = 0;
 170: 
 171: top:
 172:     while (count = read_nd(ch,(sizeof ch))) {
 173:     for (i=0; i<count; i++) {
 174:         if (ch[i] == 'Q') {
 175:         bombed_out = TRUE;
 176:         *done = TRUE;
 177:         keepgoing = FALSE;
 178:         return;
 179:         }
 180:         if (ch[i] == 'q' || ch[i] == BREAKCH || ch[i] == INTRCH) {
 181:         int x;
 182:         static char quest[] = "Do you wish to escape from reality? ";
 183: 
 184:         if (timer >= whenok) {
 185:             mvaddstr(12,22,quest);
 186:             do {
 187:             getcmd(&ch[i]);
 188:             } while (ch[i] != 'y' && ch[i] != 'n');
 189:             if (ch[i] == 'y') {
 190:             bombed_out = TRUE;
 191:             *done = TRUE;
 192:             return;
 193:             }
 194:             else {
 195:             for (x=11; x<=28; x++) {
 196:                 mvaddch(12,x*2,
 197:                 occupant[11][x]
 198:                    ? occupant[11][x]->image
 199:                    : numamoebas
 200:                       ? amb[11][x]
 201:                       : ' ');
 202:                 addspace();
 203:             }
 204:             roundsleep(2);
 205:             whenok = timer + 10;
 206:             goto top;
 207:             }
 208:         }
 209:         else {
 210:             write(1,"\07",1);
 211:             goto top;
 212:         }
 213:         }
 214:     }
 215:     for (i=0; i<count; i++) {
 216:         if (ctrla) {
 217:         switch (ch[i]) {
 218:         case '1': case 'b':
 219:             ctrl_direction(1, -1);
 220:             break;
 221:         case '2': case 'j':
 222:             ctrl_direction(1, 0);
 223:             break;
 224:         case '3': case 'n':
 225:             ctrl_direction(1, 1);
 226:             break;
 227:         case '4': case 'h':
 228:             ctrl_direction(0, -1);
 229:             break;
 230:         case '6': case 'l':
 231:             ctrl_direction(0, 1);
 232:             break;
 233:         case '7': case 'y':
 234:             ctrl_direction(-1, -1);
 235:             break;
 236:         case '8': case 'k':
 237:             ctrl_direction(-1, 0);
 238:             break;
 239:         case '9': case 'u':
 240:             ctrl_direction(-1, 1);
 241:             break;
 242:         case 'r':
 243:             rewrite();
 244:             roundsleep(3);
 245:             ctrla = FALSE;
 246:             goto top;
 247:         case 'w':
 248:             clear();
 249:             while (!input_pending())
 250:             sleep(1);
 251:             rewrite();
 252:             roundsleep(3);
 253:             ctrla = FALSE;
 254:             goto top;
 255: #ifdef SIGTSTP
 256:         case 'z':
 257:             clear();
 258:             mytstp();
 259:             sleep(4);
 260:             ctrla = FALSE;
 261:             goto top;
 262: #endif
 263:         default:
 264:             break;
 265:         }
 266:         ctrla = FALSE;
 267:         }
 268:         else {
 269:         switch (ch[i]) {
 270:         case 'Z':
 271:             clear();
 272:             mytstp();
 273:             sleep(4);
 274:             goto top;
 275:         case 'i':
 276:             if (ent && (!damage || !damflag[NOIMPULSE])) {
 277:             entmode = 0;
 278:             status = 0;
 279:             }
 280:             break;
 281:         case 'w':
 282:             if (ent && (!damage || !damflag[NOWARP])) {
 283:             entmode = 1;
 284:             status = 1;
 285:             }
 286:             break;
 287:         case 'p':
 288:             if (base) {
 289:             status = 2;
 290:             }
 291:             break;
 292:         case 'o':
 293:             if (status < 2) {
 294:             if (base)
 295:                 status = 2;
 296:             }
 297:             else if (status == 2) {
 298:             if (ent)
 299:                 status = entmode;
 300:             }
 301:             break;
 302:         case 'v':
 303:             if (ent) {
 304:             status = entmode;
 305:             }
 306:             cloaking=FALSE;
 307:             cloaked=FALSE;
 308:             break;
 309:         case 'c':
 310:             if (ent) {
 311:             status = entmode;
 312:             if (ent->energy >= 250)
 313:                 cloaking = TRUE;
 314:             }
 315:             break;
 316:         case 'z':
 317:             if (ent && (!damage || !damflag[NOZAPPER])) {
 318:             ++numzaps;
 319:             if (!rand_mod(100/numzaps)) {
 320:                 damage++;
 321:                 damflag[NOZAPPER] = rand_mod(smarts+10)+2;
 322:             }
 323:             if (nxtbang && bangm[nxtbang-1] < 0)
 324:                 --nxtbang;  /* consolidate zaps */
 325:             make_blast(evely*2+ent->posy,evelx*2+ent->posx,
 326:                 -5000000L, 3*numzaps);
 327:             ent->energy /= 2;
 328:             }
 329:             break;
 330:         case 'D':
 331:             if (status < 2 && (!damage || !damflag[NODESTRUCT])) {
 332:             if (ent && !rand_mod(10)) {
 333:                 damage++;
 334:                 damflag[NODESTRUCT] = rand_mod(smarts+10)+2;
 335:             }
 336:             if (++numdestructs <= 2)
 337:                 make_blast(evely*2+ent->posy,evelx*2+ent->posx,
 338:                 15000L, 3);
 339:             ent->energy /= 4;
 340:             }
 341:             else if (status == 2) {
 342:             if (numdestructs)
 343:                 base->energy = base->energy / 2;
 344:             if (++numdestructs <= 2)
 345:                 make_blast(base->posy, base->posx, 15000L, 5);
 346:             }
 347:             break;
 348:         case 'd':
 349:             if ((!damage || !damflag[NODESTRUCT]) && (base||ent)) {
 350:             Reg4 OBJECT *obj;
 351:             int x, y;
 352: 
 353:             if (ent && !rand_mod(200)) {
 354:                 damage++;
 355:                 damflag[NODESTRUCT] = rand_mod(smarts+10)+2;
 356:             }
 357:             for (obj = root.prev;
 358:               obj != &root;
 359:               obj = obj->prev) {
 360:                 if (obj->image == '+') {
 361:                 blast[y=(obj->posy+obj->vely+YSIZE00)%YSIZE]
 362:                      [x=(obj->posx+obj->velx+XSIZE00)%XSIZE]
 363:                      += 1;
 364:                 yblasted[y] |= 1;
 365:                 xblasted[x] |= 1;
 366:                 blasted = TRUE;
 367:                 obj->mass = (massacre?3000:4000);
 368:                 }
 369:             }
 370:             }
 371:             break;
 372:         case 's':
 373:             if ((!damage || !damflag[NODESTRUCT]) && (base||ent)) {
 374:             Reg4 OBJECT *obj;
 375:             if (ent && !rand_mod(200)) {
 376:                 damage++;
 377:                 damflag[NODESTRUCT] = rand_mod(smarts+10)+2;
 378:             }
 379:             for (obj = root.prev;
 380:               obj->type == Torp || obj->type == Web ||
 381:               obj->type == Star;
 382:               obj = obj->prev) {
 383:                 if (obj->image == '+')
 384:                 obj->vely = obj->velx = 0;
 385:             }
 386:             }
 387:             break;
 388:         case '\001':
 389:             ctrla = TRUE;
 390:             break;
 391:         case '\002':
 392:         case '\003':
 393:         case '\004':
 394:         case '\005':
 395:         case '\006':
 396:         case '\007':
 397:         case '\010':
 398:         case '\011':
 399:         case '\012':
 400:         case '\013':
 401:         case '\014':
 402:         case '\015':
 403:         case '\016':
 404:         case '\017':
 405:         case '\020':
 406:         case '\021':
 407:         case '\022':
 408:         case '\023':
 409:         case '\024':
 410:         case '\025':
 411:         case '\026':
 412:         case '\027':
 413:         case '\030':
 414:         case '\031':
 415:         case '\032':
 416:             ch[i] += 96;
 417:             i--;
 418:             ctrla = TRUE;
 419:             break;
 420:         case '\033':
 421:             tractor = 0;
 422:             break;
 423:         case 'a':
 424:             tractor++;
 425:             break;
 426:         case 'r':
 427:             tractor--;
 428:             break;
 429:         case '1': case 'b':
 430:             do_direction(1,-1);
 431:             break;
 432:         case '2': case 'j':
 433:             do_direction(1,0);
 434:             break;
 435:         case '3': case 'n':
 436:             do_direction(1,1);
 437:             break;
 438:         case '4': case 'h':
 439:             do_direction(0,-1);
 440:             break;
 441:         case '6': case 'l':
 442:             do_direction(0,1);
 443:             break;
 444:         case '7': case 'y':
 445:             do_direction(-1,-1);
 446:             break;
 447:         case '8': case 'k':
 448:             do_direction(-1,0);
 449:             break;
 450:         case '9': case 'u':
 451:             do_direction(-1,1);
 452:             break;
 453:         case '0': case 'S':
 454:             if (status < 2) {
 455:             evely = 0;
 456:             evelx = 0;
 457:             }
 458:             break;
 459:         case '-':
 460:             if (status < 2 && ent->energy >= 10) {
 461:             evely *= -1;
 462:             evelx *= -1;
 463:             ent->energy -= 10;
 464:             }
 465:             break;
 466:         case '%': case '\177': case '_':
 467:             shift_direction(0, -1);
 468:             shift_direction(0, 1);
 469:             shift_direction(-1, 0);
 470:             shift_direction(1, 0);
 471:             shift_direction(-1, -1);
 472:             shift_direction(-1, 1);
 473:             shift_direction(1, -1);
 474:             shift_direction(1, 1);
 475:             break;
 476:         case '!': case 'B':
 477:             shift_direction(1, -1);
 478:             break;
 479:         case '@': case 'J':
 480:             shift_direction(1, 0);
 481:             break;
 482:         case '#': case 'N':
 483:             shift_direction(1, 1);
 484:             break;
 485:         case '$': case 'H':
 486:             shift_direction(0, -1);
 487:             break;
 488:         case '^': case 'L':
 489:             shift_direction(0, 1);
 490:             break;
 491:         case '&': case 'Y':
 492:             shift_direction(-1, -1);
 493:             break;
 494:         case '*': case 'K':
 495:             shift_direction(-1, 0);
 496:             break;
 497:         case '(': case 'U':
 498:             shift_direction(-1, 1);
 499:             break;
 500:         case '?':
 501:             helper();
 502:             roundsleep(3);
 503:             goto top;
 504:         default:
 505:             break;
 506:         }
 507:         }
 508:     }
 509:     }
 510: }

Defined functions

ctrl_direction defined in line 109; used 9 times
do_direction defined in line 36; used 9 times
get_commands defined in line 161; used 2 times
shift_direction defined in line 135; used 17 times
us_init defined in line 30; used 2 times
Last modified: 1987-06-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3133
Valid CSS Valid XHTML 1.0 Strict