📄 screen.c
字号:
char uchar; /* universe.image character */ int bi; /* for bases index */ pships = ships + (ship_ch - A); /* calculate starting quad & sector, row & col */ sqr = pships->q_row; sqc = pships->q_col; ssr = pships->s_row - SHDISPR; ssc = pships->s_col - SHDISPC; /* adjust starting values if they start in previous quadrant */ if (ssr < 0) { ssr = NUMSECTORS + ssr; sqr = sqr - 1; if (sqr < 0) sqr = NUMQUADS -1; }; if (ssc < 0) { ssc = NUMSECTORS + ssc; sqc = sqc - 1; if (sqc < 0) sqc = NUMQUADS -1; }; /* init "current" values */ cqr = sqr; csr = ssr; /* loop for SRSCANROWS rows */ for (i = 0; i < SRSCANROWS; i ++) { /* If current sector row (csr) == 1st sector of quadrant, AND * cross hair goes in a diff place from last time(i != pships->ioff) * then put cross-hairs on rows of srscan. */ if (csr == 0 && i != pships->ioff) { move_to(SRSCANR + i, SRSCANC -1); char_out (RCROSSHAIR); move_to(SRSCANR + i, LSRSCANC +1); char_out (RCROSSHAIR); /* clear old crosshair */ move_to(SRSCANR + pships->ioff, SRSCANC -1); char_out (VERT); move_to(SRSCANR + pships->ioff, LSRSCANC +1); char_out (VERT); pships->ioff = i; }; /* reset these values for the start of each row */ csc = ssc; cqc = sqc; /* loop for SRSCANCOLS cols */ for (j = 0; j < SRSCANCOLS; j ++) { /* If this is the first time thru the loop (i == top row), * place column crosshairs at first sector of the quadrant. */ if (i == SRSCANR) { /* If current sector col (csc) == 1st sector of quad, AND * cross hair goes in a diff place from last time * (j != pships->joff) then put cross-hairs on cols * of srscan. */ if (csc == 0 && j != pships->joff1 && j != pships->joff2) { move_to (SRSCANR - 1, SRSCANC + j); char_out (CCROSSHAIR); move_to (LSRSCANR + 1, SRSCANC + j); char_out (CCROSSHAIR); /* clear old crosshair */ if (j < SHDISPC) { move_to (SRSCANR - 1, SRSCANC + pships->joff1); char_out (HORIZ); move_to (LSRSCANR + 1, SRSCANC + pships->joff1); char_out (HORIZ); pships->joff1 = j; if (j == 5 || j == 6) { move_to (SRSCANR - 1, SRSCANC + pships->joff2); char_out (HORIZ); move_to (LSRSCANR + 1, SRSCANC + pships->joff2); char_out (HORIZ); } } else { move_to (SRSCANR - 1, SRSCANC + pships->joff2); char_out (HORIZ); move_to (LSRSCANR + 1, SRSCANC + pships->joff2); char_out (HORIZ); pships->joff2 = j; if (j == 7 || j == 8 || j == 9) { move_to (SRSCANR - 1, SRSCANC + pships->joff1); char_out (HORIZ); move_to (LSRSCANR + 1, SRSCANC + pships->joff1); char_out (HORIZ); } } }; }; /* i == SRSCANR */ /* Determine new image for current 'spot' on sr-scan. * If the new image is different from the old then write it. */ if (pships->sr_scan > 0) /* sr_scan inoperative */ uchar = ' '; else uchar = universe[cqr][cqc].sectors [csr][csc].image;#ifdef OLDSR if (uchar != pships->old_sr[i][j]) { move_to (SRSCANR + i, SRSCANC +j); char_out (uchar); pships->old_sr[i][j] = uchar; };#else move_to (SRSCANR + i, SRSCANC +j); char_out (uchar);#endif /* * Owner of a ship sees (S) if his shields are up. */ if (i == SHDISPR) { if (j == SHDISPC - 1) { if (uchar == ' ' && pships->shields > 0) { move_to (SRSCANR + SHDISPR, SRSCANC + SHDISPC - 1); char_out('('); } } else if (j == SHDISPC) { if (uchar == STAR) { pships->starcounter++; if (pships->starcounter >= 5) { pships->starcounter = 0; strcpy(pships->msg_buf, "The star is damaging the ship!"); pships->dis_msg = true; pships->dis_shields = true; if (pships->shields >= STAR_COST) /* no damage */ pships->shields = pships->shields - STAR_COST; else { bi = STAR_COST - pships->shields; pships->energy = pships->energy - bi; pships->shields = 0; pships->dis_energy = true; damage (ship_ch, bi); } } } /* uchar == STAR */ } /* j == SHIPDISPC */ else if (j == SHDISPC + 1) if (uchar == ' ' && pships->shields > 0) { move_to (SRSCANR + SHDISPR, SRSCANC + SHDISPC + 1); char_out(')'); } } /* end i == SHIPDISPR */ /* * If cloaking device on, show blank for others, lower * case letter for owner of the ship. * * Make a ship "glow" (use curses standout mode) if its * glow field is set from being hit by phasers or torpedo. * * Performance: maybe use a switch stmt here. */ if (uchar >= 'A' && uchar <= 'Z') { if (ships[uchar - 'A'].cloak) { if (uchar != ship_ch) { move_to (SRSCANR + i, SRSCANC +j); char_out (' ');#ifdef OLDSR pships->old_sr[i][j] = ' ';#endif } else { move_to (SRSCANR + i, SRSCANC +j); char_out (ship_ch + 32); /* lower case */#ifdef OLDSR pships->old_sr[i][j] = ship_ch + 32;#endif }; } switch (ships[uchar - 'A'].glow) { case 0: break; case 1: case 2: standout(); move_to (SRSCANR + i, SRSCANC +j); char_out (uchar); standend(); if (uchar == ship_ch) ships[uchar - 'A'].glow++; break; case 3: move_to (SRSCANR + i, SRSCANC +j); char_out (uchar); if (uchar == ship_ch) ships[uchar - 'A'].glow = 0; break; } } /* log base locations */ else if (!pships->allbases && uchar == '+') { for (bi = 0; bi < NUMBASES; bi++) { if (pships->bases[bi][0] == cqr && pships->bases[bi][1] == cqc) break; } if (bi == NUMBASES) /* don't have this base yet */ { for (bi = 0; bi < NUMBASES; bi++) if (pships->bases[bi][0] == -1) /* empty slot */ { pships->bases[bi][0] = cqr; pships->bases[bi][1] = cqc; break; } if (bi == NUMBASES - 1) pships->allbases = true; } } csc++; if (csc > NUMSECTORS -1) { /* goto 1st sector col, in next quad col */ csc = 0; cqc++; if (cqc > NUMQUADS -1) cqc = 0; }; }; /* for cols */ /* increment current sector row & check to see if it goes into next quad */ csr = csr + 1; if (csr > NUMSECTORS -1) { csr = 0; cqr = cqr + 1; if (cqr > NUMQUADS -1) cqr = 0; }; }; /* for rows */ }; /* proc printf_srscan */printf_lrscan(ship_ch) char ship_ch; /* Writes out the lrscan area around a ship, the ship's own quadrant and and the 8 quadrants around the ship. */ { register struct ship *pships; /* pointer to ship structure */ register int i,j; /* loop indicies */ int squadr; /* starting quad row */ int squadc; /* starting quad col */ register int cquadr; /* current quad row */ register int cquadc; /* current quad col */ char tmp_str[25]; /* calc starting quad row and and col */ pships = ships + (ship_ch - A); squadr = pships->q_row - 1; squadc = pships->q_col - 1; /* adjust starting values if < 0 */ if (squadr < 0) squadr = NUMQUADS -1; if (squadc < 0) squadc = NUMQUADS -1; cquadr = squadr; /* build the output string */ for (i = 0; i < LRSCANSECTS; i ++) { /* 3 rows of lrscan */ cquadc = squadc; for (j = 0; j < LRSCANSECTS; j ++) { /* 3 cols of lrscan */ if (pships->lr_scan == 0) sprintf (tmp_str,"%1d%1d%1d", universe [cquadr][cquadc].nships, universe [cquadr][cquadc].nbases, universe [cquadr][cquadc].nstars); else strcpy (tmp_str,"000"); /* not operational */ /* If current LRSCAN section has changed, * then update it, and savewhat it looks like. */ if (strcmp (pships->old_lr[i][j], tmp_str)) { /* `* 2' to skip down 2 rows, `* 6' to skip over 6 cols */ move_to(LRSCANR + i * 2, LRSCANC + j * (LRSCANSIZE+1)); string_out (tmp_str); strcpy (pships->old_lr[i][j], tmp_str); }; /* increment cquadc; check for wrap-around to start of galaxy */ cquadc++; if (cquadc > NUMQUADS -1) cquadc = 0; }; /* for cols */ /* increment cquadr;check for wrap-around to top of galaxy */ cquadr++; if (cquadr > NUMQUADS -1) cquadr = 0; }; /* for rows */ /* * Put quadrant row and column numbers around long range scan. */ cquadr = pships->q_row - 1; if (cquadr < 0) cquadr = NUMQUADS - 1; for (i = 0; i < LRSCANSECTS; i++) { if (cquadr >= NUMQUADS) cquadr = 0; sprintf(tmp_str, "%1d", cquadr); move_to(LRSCANR + i*2, LRSCANC - 3); string_out(tmp_str); cquadr++; } cquadc = pships->q_col - 1; if (cquadc < 0) cquadc = NUMQUADS - 1; for (i = 0; i < LRSCANSECTS; i++) { if (cquadc >= NUMQUADS) cquadc = 0; sprintf(tmp_str, "%1d", cquadc); move_to(LRSCANR - 2, LRSCANC + 1 + i*(LRSCANSIZE + 1)); string_out(tmp_str); cquadc++; } }; /* proc printf_lrscan */update_fleet() /* this procedure updates the callers screen with all fleet display info. That is, who is in the game and number of kills. */ { register struct ship *pships; register int i; /* current output row */ register int j; /* loop index */ int ch; /* loop index */ boolean filled; /* set true if (fleet display full (9 ships) */ char tmp_str[25]; i = FLEETR; filled = false; for (ch = 'A'; ch <= 'Z' && !filled; ch ++) { pships = ships + (ch - A); if (pships->ship_ch != ' ') { sprintf (tmp_str, "%c:%2d:%.1f %s",pships->ship_ch, pships->kills, pships->avekills, pships->name); /* * Blank out to NAMESIZE to cover over any possibly * longer names already on the screen. */ for (j = strlen(pships->name); j < NAMESIZE; j++) strcat(tmp_str, " "); move_to(i,FLEETC); string_out (tmp_str); if (i < FLEETMAXR) i++; else filled = true; }; }; if (! filled) { /* blank fleet display below last ship */ for (; i <= FLEETMAXR; i++) { move_to (i, FLEETC); clear_to_eol(); }; }; }; /* proc update_fleet */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -