📄 cmd.c
字号:
# endif DEBUG# ifdef DEBUG move_to(MESSAGER,MESSAGEC); string_out ("doing cmd >"); string_out (scanf_buf); clear_to_eol(); refresh_scr();# endif parse_cmd(); }parse_cmd() /* parse the command */ { register struct ship *pships; register struct torpedo_record *ptorps; register int i, j; /* loop index */ register int t_int; /* temp int. */ register struct ship *pships2; boolean found; /* set true when open torpedo record found */ char tmp_str[15]; /* tmp string to build radio message in */ char ch1; /* to hold scanf_buf[1] */ int row, col; /* row & col for locate cmd */ pships = ships + (local_ship - A); ch1 = scanf_buf[1]; switch (scanf_buf[0]) { case '1': case '2': case '3': case '4': case '6': case '7': case '8': case '9': /* set bearing */ pships->bearing = scanf_buf[0] - 48; pships->dis_bearing = true; break; case 'C': /* toggle cloaking device */ if (pships->cloaking != 0) { strcpy (pships->msg_buf, "Cloaking device inoperative"); pships->dis_msg = true; break; }; if (pships->cloak) pships->cloak = false; else pships->cloak = true; break; case 'D': /* dock at starbase */ pships->dock = true; break; case 'E': if (local_ship == 'E') { pships->energy = 25000; pships->dis_energy = true; pships->shields = 25000; pships->shield_time = 0; pships->dis_shields = true; pships->torpedos = 12; pships->torp_time = 0; pships->dis_torpedos = true; pships->phasers = 0; pships->warp_drive = 0; if (pships->sr_scan > 1) pships->sr_scan = 1; if (pships->lr_scan > 1) pships->lr_scan = 1; }; break; case 'G': /* Get back last message */ pships->dis_msg = true; break; case 'I': /* impulse engines */ /* `I' alone gives warp 0.5 * `I'n where n = 0-9 gives ~ warp 0.n */ if (pships->impulse != 0) { strcpy (pships->msg_buf, "Impulse engines inoperative"); pships->dis_msg = true; break; }; if (pships->warp_speed < 1) { pships->dis_warp_set = true; pships->sub_light = 1; if (ch1 >= '0' && ch1 <= '9') switch (ch1 - 48) { case 0: pships->warp_set = 0; pships->sub_light = 0; break; case 1: case 2: case 3: pships->warp_set = 0.2; break; case 4: case 5: case 6: pships->warp_set = 0.5; break; case 7: case 8: case 9: pships->warp_set = 0.8; break; } /* end switch */ else /* `I' only, gives warp 0.5 */ pships->warp_set = 0.5; } /* end warp speed < 1 */ else { strcpy (pships->msg_buf, "Use warp engines at >= W1"); pships->dis_msg = true; } break; case 'L': if (pships->energy < LOCATE_COST) { strcpy(pships->msg_buf, "Insufficient energy"); pships->dis_msg = true; } else { if (num_users < 2) { strcpy(pships->msg_buf, "No ships to locate"); pships->dis_msg = true; } else { row = -1; locate(pships->q_row, pships->q_col, &row, &col); if (row == -1) strcpy (pships->msg_buf, "No ships found"); else { sprintf (tmp_str, "%s %1d-%1d", "Ship at", row, col); strcpy (pships->msg_buf, tmp_str); pships->locater = row; pships->locatec = col; } pships->dis_msg = true; pships->energy -= LOCATE_COST; pships->dis_energy = true; } } break; case 'M': pships->dis_map = true; break; case 'N': /* Reset the "old" long range scan info. */ for (i=0; i < LRSCANSECTS; i++) for (j=0; j < LRSCANSECTS; j++) strcpy (pships->old_lr[i][j], "000");#ifdef OLDSR /* Reset "old" short range scan info */ for (i=0; i < SRSCANROWS; i++) for (j=0; j < SRSCANCOLS; j++) pships->old_sr [i] [j] = ' ';#endif pships->ioff = SRSCANR; pships->joff1 = SRSCANC; pships->joff2 = SRSCANC; /* * clear the window, & redraw the displays. On the * next regular screen update (<= 1 second) the display will * be filled in. */ wclear(scanwin); wrefresh(scanwin); draw_sr(); draw_lr(); break; case 'P': use_phasers(); /* phasers */ break; case 'Q': userabort = true; break; case 'R': if (pships->radio != 0) /* radio */ { strcpy (pships->msg_buf, "Radio inoperative"); pships->dis_msg = true; break; }; if ((ch1 >= 'A' && ch1 <= 'Z') || ch1 == '*') { /* radio ship */ if (ch1 == '*' || ships[ch1-A].ship_ch != ' ') { /* ship in game */ i = strlen(scanf_buf); if (i > READSIZE - 9) /* patch to avoid exceeding */ i = READSIZE - 9; /* msg buffer length */ sprintf(tmp_str,"%1d%c%1d %c %c",pships->q_row,'-', pships->q_col, local_ship, bell); if (ch1 != '*') { strcpy(ships[ch1-A].msg_buf, tmp_str); /* start at 3rd char of scanf_buf, & get all but 1st 2 chars */ strncat(ships[ch1-A].msg_buf,&scanf_buf[2],i-2); scanf_buf[i] = '\0'; ships[ch1-A].dis_msg = true; } else /* ch1 == '*' */ { for (ch1 = 'A'; ch1 <= 'Z'; ch1++) if (ships[ch1-A].ship_ch != ' ') { strcpy(ships[ch1-A].msg_buf, tmp_str); strncat(ships[ch1-A].msg_buf,&scanf_buf[2],i-2); scanf_buf[i] = '\0'; ships[ch1-A].dis_msg = true; } } } /* ship in game */# ifdef DRONE else if (ch1 == 'R' || ch1 == 'K') { dafter++; /* * Get difficulty level */ switch (scanf_buf[2]) { case '1': call_drone (ch1, local_ship, 1); break; case '2': call_drone (ch1, local_ship, 2); break; case '3': call_drone (ch1, local_ship, 3); break; case '4': call_drone (ch1, local_ship, 4); break; default: call_drone (ch1, local_ship, 1); break; } }# endif DRONE else /* no such ship */ { strcpy(pships->msg_buf, "No such ship"); pships->dis_msg = true; } } break; case 'S': /* shields */ if (pships->shield_time != 0) { strcpy (pships->msg_buf, "Shields inoperative"); pships->dis_msg = true; break; }; t_int = 0; if (ch1 == '-') { switch (scanf_buf[2]) { case '0': t_int = 0; break; case '1': t_int = -1; break; case '2': t_int = -2; break; case '3': t_int = -3; break; case '4': t_int = -4; break; case '5': t_int = -5; break; case '6': t_int = -6; break; case '7': t_int = -7; break; case '8': t_int = -8; break; case '9': t_int = -9; break; case 'A': case '*': t_int = -25; break; } } /* end negative number */ else if (ch1 >= '0' && ch1 <= '9') t_int = cvt_int (scanf_buf,1); t_int *= 1000; /* * Only allow 1/2 of total present energy to go into shields. 3-27-85 */ if (t_int > 0) { if ((t_int + pships->shields) > (pships->energy - t_int)) /* more into shields than avail */ t_int = ((pships->energy + pships->shields) / 2) - pships->shields; } else if (t_int < 0 && -t_int > pships->shields) /* take too much out */ t_int = - pships->shields; /* set to all thats in shields */ /* subtract t_int from energy and add to shields */ pships->energy = pships->energy - t_int; pships->shields = pships->shields + t_int; pships->dis_energy = true; pships->dis_shields = true; break; case 'T': /* torpedos */ if (pships->torp_time != 0) { strcpy (pships->msg_buf, "Torpedos inoperative"); pships->dis_msg = true; break; }; if (pships->docked) { strcpy (pships->msg_buf, "Can't fire when docked!"); pships->dis_msg = true; break; }; if (pships->torpedos <= 0) { strcpy (pships->msg_buf, "No torpedos"); pships->dis_msg = true; break; }; if (pships->cloak) { strcpy (pships->msg_buf, "Can't fire when cloaked!"); pships->dis_msg = true; break; }; if ((ch1 >= '1' && ch1 <= '9') && (ch1 != '5')) t_int = ch1 - 48; else t_int = pships->bearing; for (found=false, i=0; i < TORP_MAX && ! found;) if (pships->torp_info[i].torp_dir == -1) found = true; else i++; if (found) { ptorps = pships->torp_info + i; pships->torpedos--; pships->dis_torpedos = true; pships->torp_active = true; ptorps->torp_dir = t_int; ptorps->torp_dist = 0; if (ptorps->torp_dir == pships->bearing) ptorps->torp_speed = (pships->warp_speed + 0.4) + TORP_VELOCITY; else ptorps->torp_speed = TORP_VELOCITY; /* set starting location for torp as ship location */ ptorps->tquadr = pships->q_row; ptorps->tquadc = pships->q_col; ptorps->tsectr = pships->s_row; ptorps->tsectc = pships->s_col; }; /* if found */ break; case 'W': /* warp speed */ if (pships->warp_drive != 0) { strcpy (pships->msg_buf, "Warp drive inoperative"); pships->dis_msg = true; break; }; pships->dis_warp_set = true; pships->sub_light = 0; switch(ch1) { case '0': pships->warp_set = 0; break; case '1': pships->warp_set = 1; break; case '2': pships->warp_set = 2; break; case '3': pships->warp_set = 3; break; case '4': pships->warp_set = 4; break; case '5': pships->warp_set = 5; break; case '6': pships->warp_set = 6; break; case '7': pships->warp_set = WARP_MAX; break; case '8': pships->warp_set = WARP_MAX; break; case '9': pships->warp_set = WARP_MAX; break; case '.': pships->warp_set = 0.5; pships->sub_light = 1; break; default: pships->warp_set = 1; } break; case 'X': if (pships->sensors > 0) { strcpy(pships->msg_buf, "Sensors inoperative"); pships->dis_msg = true; } else { if (ch1 >= 'A' && ch1 <= 'Z') { if (shipinrange(local_ship,ch1,PHSRANGE,false)) { pships2 = ships + (ch1 - A); strcpy(pships2->msg_buf, "Sensors indicate we are being scanned"); pships2->dis_msg = true; i = 0; if (pships2->warp_drive != 0) i++; if (pships2->torp_time != 0) i++; if (pships2->phasers != 0) i++; if (pships2->impulse != 0) i++; if (pships2->radio != 0) i++; if (pships2->shield_time != 0) i++; if (pships2->sr_scan != 0) i++; if (pships2->lr_scan != 0) i++; /* Life support intentionally left out, it and sensors * get damaged together. */ if (pships2->sensors != 0) i++; if (pships2->cloaking != 0) i++; pships->dis_msg = true; strcpy(pships->msg_buf, "Sensors indicate "); strcat(pships->msg_buf, pships2->name); if (pships2->shields <= 0) strcat(pships->msg_buf, ": shields down; "); else strcat(pships->msg_buf, ": shields up; "); switch (i) { case 0: strcat(pships->msg_buf, "undamged"); break; case 1: strcat(pships->msg_buf, "slightly damged"); break; case 2: strcat(pships->msg_buf, "moderately damged"); break; default: strcat(pships->msg_buf, "heavily damged"); break; } } /* in range */ else { strcpy(pships->msg_buf, "Ship not in range"); pships->dis_msg = true; } } /* ch1 in 'A' to 'Z' */ } /* opr */ break; case 'Z': redraw = true; /* Reset the "old" long range scan info. */ for (i=0; i < LRSCANSECTS; i++) for (j=0; j < LRSCANSECTS; j++) strcpy (pships->old_lr[i][j], "000");#ifdef OLDSR /* Reset "old" short range scan info */ for (i=0; i < SRSCANROWS; i++) for (j=0; j < SRSCANCOLS; j++) pships->old_sr [i] [j] = ' ';#endif pships->ioff = SRSCANR; pships->joff1 = SRSCANC; pships->joff2 = SRSCANC; }; /* switch */ scanf_cc = 0; }; /* proc parse_cmd */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -