print.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* $NetBSD: print.c,v 1.11 2003/08/07 09:37:26 agc Exp $ */
  2. /*
  3. * Copyright (c) 1982, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #include <sys/cdefs.h>
  31. #ifndef lint
  32. #if 0
  33. static char sccsid[] = "@(#)print.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: print.c,v 1.11 2003/08/07 09:37:26 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. # include "mille.h"
  39. /*
  40. * @(#)print.c 1.1 (Berkeley) 4/1/82
  41. */
  42. # define COMP_STRT 20
  43. # define CARD_STRT 2
  44. void
  45. prboard()
  46. {
  47. PLAY *pp;
  48. int i, j, k, temp;
  49. for (k = 0; k < 2; k++) {
  50. pp = &Player[k];
  51. temp = k * COMP_STRT + CARD_STRT;
  52. for (i = 0; i < NUM_SAFE; i++)
  53. if (pp->safety[i] == S_PLAYED && !pp->sh_safety[i]) {
  54. mvaddstr(i, temp, C_name[i + S_CONV]);
  55. if (pp->coups[i])
  56. mvaddch(i, temp - CARD_STRT, '*');
  57. pp->sh_safety[i] = TRUE;
  58. }
  59. show_card(14, temp, pp->battle, &pp->sh_battle);
  60. show_card(16, temp, pp->speed, &pp->sh_speed);
  61. for (i = C_25; i <= C_200; i++) {
  62. const char *name;
  63. int end;
  64. if (pp->nummiles[i] == pp->sh_nummiles[i])
  65. continue;
  66. name = C_name[i];
  67. temp = k * 40;
  68. end = pp->nummiles[i];
  69. for (j = pp->sh_nummiles[i]; j < end; j++)
  70. mvwaddstr(Miles, i + 1, (j << 2) + temp, name);
  71. pp->sh_nummiles[i] = end;
  72. }
  73. }
  74. prscore(TRUE);
  75. temp = CARD_STRT;
  76. pp = &Player[PLAYER];
  77. for (i = 0; i < HAND_SZ; i++)
  78. show_card(i + 6, temp, pp->hand[i], &pp->sh_hand[i]);
  79. mvprintw(6, COMP_STRT + CARD_STRT, "%2ld", (long)(Topcard - Deck));
  80. show_card(8, COMP_STRT + CARD_STRT, Discard, &Sh_discard);
  81. if (End == 1000) {
  82. move(EXT_Y, EXT_X);
  83. standout();
  84. addstr("Extension");
  85. standend();
  86. }
  87. wrefresh(Board);
  88. wrefresh(Miles);
  89. wrefresh(Score);
  90. }
  91. /*
  92. * show_card:
  93. * Show the given card if it is different from the last one shown
  94. */
  95. void
  96. show_card(y, x, c, lc)
  97. int y, x;
  98. CARD c, *lc;
  99. {
  100. if (c == *lc)
  101. return;
  102. mvprintw(y, x, C_fmt, C_name[c]);
  103. *lc = c;
  104. }
  105. static char Score_fmt[] = "%4d";
  106. void
  107. prscore(for_real)
  108. #ifdef EXTRAP
  109. bool for_real;
  110. #else
  111. bool for_real __attribute__((__unused__));
  112. #endif
  113. {
  114. PLAY *pp;
  115. int x;
  116. stdscr = Score;
  117. for (pp = Player; pp < &Player[2]; pp++) {
  118. x = (pp - Player) * 6 + 21;
  119. show_score(1, x, pp->mileage, &pp->sh_mileage);
  120. if (pp->safescore != pp->sh_safescore) {
  121. mvprintw(2, x, Score_fmt, pp->safescore);
  122. if (pp->safescore == 400)
  123. mvaddstr(3, x + 1, "300");
  124. else
  125. mvaddstr(3, x + 1, " 0");
  126. mvprintw(4, x, Score_fmt, pp->coupscore);
  127. pp->sh_safescore = pp->safescore;
  128. }
  129. if (Window == W_FULL || Finished) {
  130. #ifdef EXTRAP
  131. if (for_real)
  132. finalscore(pp);
  133. else
  134. extrapolate(pp);
  135. #else
  136. finalscore(pp);
  137. #endif
  138. show_score(11, x, pp->hand_tot, &pp->sh_hand_tot);
  139. show_score(13, x, pp->total, &pp->sh_total);
  140. show_score(14, x, pp->games, &pp->sh_games);
  141. }
  142. else {
  143. show_score(6, x, pp->hand_tot, &pp->sh_hand_tot);
  144. show_score(8, x, pp->total, &pp->sh_total);
  145. show_score(9, x, pp->games, &pp->sh_games);
  146. }
  147. }
  148. stdscr = Board;
  149. }
  150. /*
  151. * show_score:
  152. * Show a score value if it is different from the last time we
  153. * showed it.
  154. */
  155. void
  156. show_score(y, x, s, ls)
  157. int y, x;
  158. int s, *ls;
  159. {
  160. if (s == *ls)
  161. return;
  162. mvprintw(y, x, Score_fmt, s);
  163. *ls = s;
  164. }