📄 action.c
字号:
cqr = pships->q_row; cqc = pships->q_col; csr = pships->s_row; csc = pships->s_col; if (pships->warp_speed < 1) /* sublight */ nsectors = 1; else nsectors = (pships->warp_speed + 0.4); /* add 0.4 to effectively round */ /* move until all sectors traversed or ship hits something solid */ for (i=1; i <= nsectors ;) { /* hold position in case ship hits a base or another ship */ holdqr = cqr; holdqc = cqc; holdsr = csr; holdsc = csc; switch (pships->bearing) { case 1: csr++; csc--; break; case 2: csr++; break; case 3: csr++; csc++; break; case 4: csc--; break; case 6: csc++; break; case 7: csr--; csc--; break; case 8: csr--; break; case 9: csr--; csc++; break; default: ; /* do nothing */ }; /* switch */ /* check for entering adjacent quadrant */ if (csr < 0) { /* goto bottom edge of above quad */ csr = NUMSECTORS -1; cqr = cqr - 1; pships->dis_quad = true; if (cqr < 0) cqr = NUMQUADS -1; }; if (csc < 0) { /* goto right edge of prev quad */ csc = NUMSECTORS -1; cqc = cqc - 1; pships->dis_quad = true; if (cqc < 0) cqc = NUMQUADS -1; }; if (csr > NUMSECTORS -1) { /* goto top edge of quad below */ csr = 0; cqr = cqr + 1; pships->dis_quad = true; if (cqr > NUMQUADS -1) cqr = 0; }; if (csc > NUMSECTORS -1) { /* goto left edge of next quad */ csc = 0; cqc = cqc + 1; pships->dis_quad = true; if (cqc > NUMQUADS -1) cqc = 0; }; /* check for anything in the path of movement */ uchar = universe [cqr][cqc].sectors [csr][csc].image; switch (uchar) { case ' ': i++; pships->docked = false; break; case TORP: i++; pships->docked = false; pships->dis_shields = true; if (pships->shields >= TORP_COST) pships->shields = pships->shields - TORP_COST; else { hurt = TORP_COST - pships->shields; pships->energy = pships->energy - hurt; pships->shields = 0; pships->dis_energy = true; damage (ship_ch, hurt); strcpy(pships->msg_buf, "Ship hit by Photon Torpedo"); pships->dis_msg = true; }; /* NOTE: there is currently no way to terminate the torpedo, since the ship hit it (ship moving > w1) the torp owner is unknown! */ break; case STAR: i++; pships->docked = false; strcpy(pships->msg_buf, "Passing thru a star!"); pships->dis_msg = true; pships->ship_invis = true; pships->dis_shields = true; pships->starcounter = 0; if (pships->shields >= STAR_COST) /* no damage */ pships->shields = pships->shields - STAR_COST; else { hurt = STAR_COST - pships->shields; pships->energy = pships->energy - hurt; pships->shields = 0; pships->dis_energy = true; damage (ship_ch, hurt); }; break; case ION: /* ship in ion cloud */ i++; pships->docked = false; strcpy(pships->msg_buf, "Passing thru an ion cloud!"); pships->dis_msg = true; pships->ship_invis = true; pships->dis_shields = true; if (pships->shields >= ION_COST) /* no damage */ pships->shields = pships->shields - ION_COST; else { hurt = ION_COST - pships->shields; pships->energy = pships->energy - hurt; pships->shields = 0; pships->dis_energy = true; damage (ship_ch, hurt); }; break; case BASE: i = nsectors + 1; /* to trigger end of for loop */ if (pships->warp_speed >= 1.0) { pships->dis_bearing = true; switch (pships->bearing) { case 1: pships->bearing = 9; break; case 2: pships->bearing = 8; break; case 3: pships->bearing = 7; break; case 4: pships->bearing = 6; break; case 6: pships->bearing = 4; break; case 7: pships->bearing = 3; break; case 8: pships->bearing = 2; break; case 9: pships->bearing = 1; break; } } else /* warp speed < 1, so stop */ { pships->warp_speed = 0.0; pships->warp_set = 0.0; pships->dis_warp_speed = true; pships->dis_warp_set = true; } pships->dis_shields = true; if (pships->shields >= BASE_COST) /* no damage */ pships->shields = pships->shields - BASE_COST; else { hurt = BASE_COST - pships->shields; pships->energy = pships->energy - hurt; pships->shields = 0; pships->dis_energy = true; damage (ship_ch, hurt); }; /* ship hit a star base, set position back */ cqr = holdqr; cqc = holdqc; csr = holdsr; csc = holdsc; strcpy(pships->msg_buf, "Collision with a star base!"); pships->dis_msg = true; break; default: i = nsectors + 1; if (uchar >= 'A' && uchar <= 'Z') { /* collision with another ship set position back */ pships->dis_bearing = true; switch (pships->bearing) { case 1: pships->bearing = 9; break; case 2: pships->bearing = 8; break; case 3: pships->bearing = 7; break; case 4: pships->bearing = 6; break; case 6: pships->bearing = 4; break; case 7: pships->bearing = 3; break; case 8: pships->bearing = 2; break; case 9: pships->bearing = 1; break; } pships->dis_shields = true; if (pships->shields >= SHIP_COST) /* no damage */ pships->shields = pships->shields - SHIP_COST; else { hurt = SHIP_COST - pships->shields; pships->energy = pships->energy - hurt; pships->shields = 0; pships->dis_energy = true; damage (ship_ch, hurt); }; cqr = holdqr; cqc = holdqc; csr = holdsr; csc = holdsc; sprintf(pships->msg_buf, "Collision with the %s!", ships[uchar - A].name); pships->dis_msg = true; pships = ships + (uchar - A); /* * If the 2 ships were traveling in the same * direction, then with the 1st one's bearing reversed * they will be going in opposite directions, * indicated by sum of bearings == 10. */ if (pships->bearing + ships[ship_ch - A].bearing != 10) { pships->dis_bearing = true; switch (pships->bearing) { case 1: pships->bearing = 9; break; case 2: pships->bearing = 8; break; case 3: pships->bearing = 7; break; case 4: pships->bearing = 6; break; case 6: pships->bearing = 4; break; case 7: pships->bearing = 3; break; case 8: pships->bearing = 2; break; case 9: pships->bearing = 1; break; } } sprintf(pships->msg_buf, "Collision with the %s!", ships[ship_ch - A].name); pships->dis_msg = true; }; break; }; /* switch */ }; /* for i <= nsectors */ /* update ships posit in universe and in ships record */ pships = ships + (ship_ch - A); if (! pships->ship_invis) universe[cqr][cqc].sectors [csr][csc].image = ship_ch; /* Update lrscan: for simplicity assume the ship changed quad's. Decrement ships count in old quad, increm ship count in new quad.*/ universe [pships->q_row][pships->q_col].nships--; universe [cqr][cqc].nships++; pships->q_row = cqr; pships->q_col = cqc; pships->s_row = csr; pships->s_col = csc; }; /* proc move_ship */dock_ship(ship_ch) char ship_ch; /* Docks the ship & restores all of the ships systems. */ { register struct ship *pships; register int i; /* loop index */ register int quadr; /* posit to check for base */ register int quadc; register int sectr; register int sectc; boolean found; /* set true if base found */ pships = ships + (ship_ch - A); pships->dock = false; i = 1; found = false; for (; i <= 4 && !found ;) { /* check all 4 directions */ quadr = pships->q_row; quadc = pships->q_col; sectr = pships->s_row; sectc = pships->s_col; /* check next direction of the 4 possible directions */ switch (i) { case 1: /* S+ */ sectc++; if (sectc > NUMSECTORS -1) { sectc = 0; quadc = quadc + 1; if (quadc > NUMQUADS -1) quadc = 0; }; break; case 2: /* +S */ sectc--; if (sectc < 0) { sectc = NUMSECTORS -1; quadc = quadc - 1; if (quadc < 0) quadc = NUMQUADS -1; }; break; case 3: /* + */ sectr--; /* S */ if (sectr < 0) { sectr = NUMSECTORS -1; quadr = quadr - 1; if (quadr < 0) quadr = NUMQUADS -1; }; break; case 4: /* S */ sectr++; /* + */ if (sectr > NUMSECTORS -1) { sectr = 0; quadr = quadr + 1; if (quadr > NUMQUADS -1) quadr = 0; }; }; /* switch (*/ if (universe[quadr][quadc].sectors[sectr][sectc].image == BASE) found = true; else i++; }; /* while */ if (found) { /* dock */ pships->docked = true; strcpy(pships->msg_buf, "Docking at star base"); pships->dis_msg = true; pships->energy = ENERGY_MAX; /* if devices not operational, set time to 1 & they'll go opr */ pships->shields = 0; if (pships->shield_time > 1) pships->shield_time = 1; pships->torpedos = TORP_MAX; if (pships->torp_time > 1) pships->torp_time = 1; if (pships->phasers > 1) pships->phasers = 1; if (pships->warp_drive > 1) pships->warp_drive = 1; pships->warp_speed = 0.0; if (pships->impulse > 1) pships->impulse = 1; pships->life_support = GREEN; if (pships->sr_scan > 1) pships->sr_scan = 1; if (pships->lr_scan > 1) pships->lr_scan = 1; if (pships->radio > 1) pships->radio = 1; pships->cloak = false; if (pships->cloaking > 1) pships->cloaking = 1; if (pships->sensors > 1) pships->sensors = 1; /* set display fields */ pships->dis_energy = true; pships->dis_shields = true; pships->dis_torpedos = true; } /* dock */ else { strcpy(pships->msg_buf, "No star base to dock at!"); pships->dis_msg = true; }; }; /* proc dock_ship */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -