init.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* $NetBSD: init.c,v 1.9 2003/08/07 09:37:25 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[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: init.c,v 1.9 2003/08/07 09:37:25 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. # include "mille.h"
  39. /*
  40. * @(#)init.c 1.1 (Berkeley) 4/1/82
  41. */
  42. void
  43. init()
  44. {
  45. PLAY *pp;
  46. int i, j;
  47. CARD card;
  48. memset(Numseen, 0, sizeof Numseen);
  49. Numgos = 0;
  50. for (i = 0; i < 2; i++) {
  51. pp = &Player[i];
  52. pp->hand[0] = C_INIT;
  53. for (j = 0; j < NUM_SAFE; j++) {
  54. pp->safety[j] = S_UNKNOWN;
  55. pp->coups[j] = FALSE;
  56. }
  57. for (j = 1; j < HAND_SZ; j++) {
  58. pp->hand[j] = *--Topcard;
  59. if (i == COMP) {
  60. account(card = *Topcard);
  61. if (is_safety(card))
  62. pp->safety[card - S_CONV] = S_IN_HAND;
  63. }
  64. }
  65. pp->mileage = 0;
  66. pp->hand_tot = 0;
  67. pp->safescore = 0;
  68. pp->coupscore = 0;
  69. pp->can_go = FALSE;
  70. pp->speed = C_INIT;
  71. pp->battle = C_INIT;
  72. pp->new_speed = FALSE;
  73. pp->new_battle = FALSE;
  74. for (j = 0; j < NUM_MILES; j++)
  75. pp->nummiles[j] = 0;
  76. }
  77. if (Order)
  78. sort(Player[PLAYER].hand);
  79. Discard = C_INIT;
  80. Finished = FALSE;
  81. End = 700;
  82. }
  83. void
  84. shuffle()
  85. {
  86. int i, r;
  87. CARD temp;
  88. for (i = 0; i < DECK_SZ; i++) {
  89. r = roll(1, DECK_SZ) - 1;
  90. if (r < 0 || r > DECK_SZ - 1) {
  91. warnx("shuffle: card no. error: %d", r);
  92. die(1);
  93. }
  94. temp = Deck[r];
  95. Deck[r] = Deck[i];
  96. Deck[i] = temp;
  97. }
  98. Topcard = &Deck[DECK_SZ];
  99. }
  100. void
  101. newboard()
  102. {
  103. int i;
  104. PLAY *pp;
  105. static int first = TRUE;
  106. if (first) {
  107. werase(Board);
  108. werase(Score);
  109. mvaddstr(5, 0, "--HAND--");
  110. mvaddch(6, 0, 'P');
  111. mvaddch(7, 0, '1');
  112. mvaddch(8, 0, '2');
  113. mvaddch(9, 0, '3');
  114. mvaddch(10, 0, '4');
  115. mvaddch(11, 0, '5');
  116. mvaddch(12, 0, '6');
  117. mvaddstr(13, 0, "--BATTLE--");
  118. mvaddstr(15, 0, "--SPEED--");
  119. mvaddstr(5, 20, "--DECK--");
  120. mvaddstr(7, 20, "--DISCARD--");
  121. mvaddstr(13, 20, "--BATTLE--");
  122. mvaddstr(15, 20, "--SPEED--");
  123. mvwaddstr(Miles, 0, 0, "--MILEAGE--");
  124. mvwaddstr(Miles, 0, 41, "--MILEAGE--");
  125. Sh_discard = -1;
  126. for (pp = Player; pp <= &Player[COMP]; pp++) {
  127. for (i = 0; i < HAND_SZ; i++)
  128. pp->sh_hand[i] = -1;
  129. pp->sh_battle = -1;
  130. pp->sh_speed = -1;
  131. pp->sh_mileage = -1;
  132. }
  133. first = FALSE;
  134. }
  135. else {
  136. for (i = 0; i < 5; i++) {
  137. move(i, 0);
  138. clrtoeol();
  139. }
  140. wmove(Miles, 1, 0);
  141. wclrtobot(Miles);
  142. wmove(Board, MOVE_Y + 1, MOVE_X);
  143. wclrtoeol(Board);
  144. wmove(Board, MOVE_Y + 2, MOVE_X);
  145. wclrtoeol(Board);
  146. }
  147. Sh_discard = -1;
  148. for (pp = Player; pp <= &Player[COMP]; pp++) {
  149. for (i = 0; i < NUM_SAFE; i++)
  150. pp->sh_safety[i] = FALSE;
  151. for (i = 0; i < NUM_MILES; i++)
  152. pp->sh_nummiles[i] = 0;
  153. pp->sh_safescore = -1;
  154. }
  155. newscore();
  156. }
  157. void
  158. newscore()
  159. {
  160. int i, new;
  161. PLAY *pp;
  162. static int was_full = -1;
  163. static int last_win = -1;
  164. if (was_full < 0)
  165. was_full = (Window != W_FULL);
  166. stdscr = Score;
  167. move(0, 22);
  168. new = FALSE;
  169. if (inch() != 'Y') {
  170. erase();
  171. mvaddstr(0, 22, "You Comp Value");
  172. mvaddstr(1, 2, "Milestones Played");
  173. mvaddstr(2, 8, "Each Safety");
  174. mvaddstr(3, 5, "All 4 Safeties");
  175. mvaddstr(4, 3, "Each Coup Fourre");
  176. mvaddstr(2, 37, "100");
  177. mvaddstr(3, 37, "300");
  178. mvaddstr(4, 37, "300");
  179. new = TRUE;
  180. }
  181. else if ((Window == W_FULL || Finished) ^ was_full) {
  182. move(5, 1);
  183. clrtobot();
  184. new = TRUE;
  185. }
  186. else if (Window != last_win)
  187. new = TRUE;
  188. if (new) {
  189. for (i = 0; i < SCORE_Y; i++)
  190. mvaddch(i, 0, '|');
  191. move(SCORE_Y - 1, 1);
  192. for (i = 0; i < SCORE_X; i++)
  193. addch('_');
  194. for (pp = Player; pp <= &Player[COMP]; pp++) {
  195. pp->sh_hand_tot = -1;
  196. pp->sh_total = -1;
  197. pp->sh_games = -1;
  198. pp->sh_safescore = -1;
  199. }
  200. }
  201. Player[PLAYER].was_finished = !Finished;
  202. Player[COMP].was_finished = !Finished;
  203. if (Window == W_FULL || Finished) {
  204. if (!was_full || new) {
  205. mvaddstr(5, 5, "Trip Completed");
  206. mvaddstr(6, 10, "Safe Trip");
  207. mvaddstr(7, 5, "Delayed Action");
  208. mvaddstr(8, 10, "Extension");
  209. mvaddstr(9, 11, "Shut-Out");
  210. mvaddstr(10, 21, "---- ---- -----");
  211. mvaddstr(11, 9, "Hand Total");
  212. mvaddstr(12, 20, "----- -----");
  213. mvaddstr(13, 6, "Overall Total");
  214. mvaddstr(14, 15, "Games");
  215. mvaddstr(5, 37, "400");
  216. mvaddstr(6, 37, "300");
  217. mvaddstr(7, 37, "300");
  218. mvaddstr(8, 37, "200");
  219. mvaddstr(9, 37, "500");
  220. }
  221. }
  222. else
  223. if (was_full || new) {
  224. mvaddstr(5, 21, "---- ---- -----");
  225. mvaddstr(6, 9, "Hand Total");
  226. mvaddstr(7, 20, "----- -----");
  227. mvaddstr(8, 6, "Overall Total");
  228. mvaddstr(9, 15, "Games");
  229. mvaddstr(11, 2, "p: pick");
  230. mvaddstr(12, 2, "u: use #");
  231. mvaddstr(13, 2, "d: discard #");
  232. mvaddstr(14, 2, "w: toggle window");
  233. mvaddstr(11, 21, "q: quit");
  234. if (!Order)
  235. mvaddstr(12, 21, "o: order hand");
  236. else
  237. mvaddstr(12, 21, "o: stop ordering");
  238. mvaddstr(13, 21, "s: save");
  239. mvaddstr(14, 21, "r: reprint");
  240. }
  241. stdscr = Board;
  242. was_full = (Window == W_FULL || Finished);
  243. last_win = Window;
  244. }