mille.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* $NetBSD: mille.h,v 1.13 2004/01/27 20:30:30 jsm 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. * @(#)mille.h 8.1 (Berkeley) 5/31/93
  31. */
  32. # include <sys/types.h>
  33. # include <sys/uio.h>
  34. # include <sys/stat.h>
  35. # include <ctype.h>
  36. # include <err.h>
  37. # include <errno.h>
  38. # include <curses.h>
  39. # include <fcntl.h>
  40. # include <stdlib.h>
  41. # include <string.h>
  42. # include <termios.h>
  43. # include <unistd.h>
  44. /*
  45. * @(#)mille.h 1.1 (Berkeley) 4/1/82
  46. */
  47. /*
  48. * Miscellaneous constants
  49. */
  50. # define unsgn unsigned
  51. # define CARD short
  52. # define HAND_SZ 7 /* number of cards in a hand */
  53. # define DECK_SZ 101 /* number of cards in decks */
  54. # define NUM_SAFE 4 /* number of saftey cards */
  55. # define NUM_MILES 5 /* number of milestones types */
  56. # define NUM_CARDS 20 /* number of types of cards */
  57. # define BOARD_Y 17 /* size of board screen */
  58. # define BOARD_X 40
  59. # define MILES_Y 7 /* size of mileage screen */
  60. # define MILES_X 80
  61. # define SCORE_Y 17 /* size of score screen */
  62. # define SCORE_X 40
  63. # define MOVE_Y 10 /* Where to print move prompt */
  64. # define MOVE_X 20
  65. # define ERR_Y 15 /* Where to print errors */
  66. # define ERR_X 5
  67. # define EXT_Y 4 /* Where to put Extension */
  68. # define EXT_X 9
  69. # define PLAYER 0
  70. # define COMP 1
  71. # define W_SMALL 0 /* Small (initial) window */
  72. # define W_FULL 1 /* Full (final) window */
  73. /*
  74. * Move types
  75. */
  76. # define M_DISCARD 0
  77. # define M_DRAW 1
  78. # define M_PLAY 2
  79. # define M_ORDER 3
  80. /*
  81. * Scores
  82. */
  83. # define SC_SAFETY 100
  84. # define SC_ALL_SAFE 300
  85. # define SC_COUP 300
  86. # define SC_TRIP 400
  87. # define SC_SAFE 300
  88. # define SC_DELAY 300
  89. # define SC_EXTENSION 200
  90. # define SC_SHUT_OUT 500
  91. /*
  92. * safety descriptions
  93. */
  94. # undef S_UNKNOWN
  95. # undef S_IN_HAND
  96. # undef S_PLAYED
  97. # undef S_GAS_SAFE
  98. # undef S_SPARE_SAFE
  99. # undef S_DRIVE_SAFE
  100. # undef S_RIGHT_WAY
  101. # undef S_CONV
  102. # define S_UNKNOWN 0 /* location of safety unknown */
  103. # define S_IN_HAND 1 /* safety in player's hand */
  104. # define S_PLAYED 2 /* safety has been played */
  105. # define S_GAS_SAFE 0 /* Gas safety card index */
  106. # define S_SPARE_SAFE 1 /* Tire safety card index */
  107. # define S_DRIVE_SAFE 2 /* Driveing safety card index */
  108. # define S_RIGHT_WAY 3 /* Right-of-Way card index */
  109. # define S_CONV 15 /* conversion from C_ to S_ */
  110. /*
  111. * card numbers
  112. */
  113. # define C_INIT -1
  114. # define C_25 0
  115. # define C_50 1
  116. # define C_75 2
  117. # define C_100 3
  118. # define C_200 4
  119. # define C_EMPTY 5
  120. # define C_FLAT 6
  121. # define C_CRASH 7
  122. # define C_STOP 8
  123. # define C_LIMIT 9
  124. # define C_GAS 10
  125. # define C_SPARE 11
  126. # define C_REPAIRS 12
  127. # define C_GO 13
  128. # define C_END_LIMIT 14
  129. # define C_GAS_SAFE 15
  130. # define C_SPARE_SAFE 16
  131. # define C_DRIVE_SAFE 17
  132. # define C_RIGHT_WAY 18
  133. /*
  134. * prompt types
  135. */
  136. # define MOVEPROMPT 0
  137. # define REALLYPROMPT 1
  138. # define ANOTHERHANDPROMPT 2
  139. # define ANOTHERGAMEPROMPT 3
  140. # define SAVEGAMEPROMPT 4
  141. # define SAMEFILEPROMPT 5
  142. # define FILEPROMPT 6
  143. # define EXTENSIONPROMPT 7
  144. # define OVERWRITEFILEPROMPT 8
  145. # ifdef SYSV
  146. # define srandom(x) srand(x)
  147. # define random() rand()
  148. # endif /* SYSV */
  149. typedef struct {
  150. bool coups[NUM_SAFE];
  151. bool can_go;
  152. bool new_battle;
  153. bool new_speed;
  154. short safety[NUM_SAFE];
  155. short sh_safety[NUM_SAFE];
  156. short nummiles[NUM_MILES];
  157. short sh_nummiles[NUM_MILES];
  158. CARD hand[HAND_SZ];
  159. CARD sh_hand[HAND_SZ];
  160. CARD battle;
  161. CARD sh_battle;
  162. CARD speed;
  163. CARD sh_speed;
  164. int mileage;
  165. int sh_mileage;
  166. int hand_tot;
  167. int sh_hand_tot;
  168. int safescore;
  169. int sh_safescore;
  170. int coupscore;
  171. int total;
  172. int sh_total;
  173. int games;
  174. int sh_games;
  175. int was_finished;
  176. } PLAY;
  177. /*
  178. * macros
  179. */
  180. # define other(x) (1 - x)
  181. # define nextplay() (Play = other(Play))
  182. # define nextwin(x) (1 - x)
  183. # define opposite(x) (Opposite[x])
  184. # define is_safety(x) (x >= C_GAS_SAFE)
  185. /*
  186. * externals
  187. */
  188. extern bool Debug, Finished, Next, On_exit, Order, Saved;
  189. extern char Initstr[];
  190. extern const char *C_fmt, *const *C_name, *Fromfile;
  191. extern int Card_no, End, Handstart, Movetype, Numgos,
  192. Numneed[], Numseen[NUM_CARDS], Play, Window;
  193. extern const int Numcards[], Value[];
  194. extern CARD Deck[DECK_SZ], Discard, Sh_discard, *Topcard;
  195. extern const CARD Opposite[NUM_CARDS];
  196. extern FILE *outf;
  197. extern PLAY Player[2];
  198. extern WINDOW *Board, *Miles, *Score;
  199. /*
  200. * functions
  201. */
  202. void account(CARD);
  203. void calcmove(void);
  204. int canplay(const PLAY *, const PLAY *, CARD);
  205. int check_ext(bool);
  206. void check_go(void);
  207. void check_more(void);
  208. void die(int) __attribute__((__noreturn__));
  209. void domove(void);
  210. bool error(const char *, ...);
  211. void extrapolate(PLAY *);
  212. void finalscore(PLAY *);
  213. CARD getcard(void);
  214. void getmove(void);
  215. int getyn(int);
  216. int haspicked(const PLAY *);
  217. void init(void);
  218. int is_repair(CARD);
  219. int main(int, char **);
  220. void newboard(void);
  221. void newscore(void);
  222. int onecard(const PLAY *);
  223. int playcard(PLAY *);
  224. void prboard(void);
  225. void prompt(int);
  226. void prscore(bool);
  227. int readch(void);
  228. bool rest_f(const char *);
  229. int roll(int, int);
  230. void rub(int);
  231. int safety(CARD);
  232. bool save(void);
  233. void show_card(int, int, CARD, CARD *);
  234. void show_score(int, int, int, int *);
  235. void shuffle(void);
  236. void sort(CARD *);
  237. void undoex(int);
  238. #if defined(__linux__) && !defined(__GLIBC__)
  239. bool varpush(int, ssize_t (int, const struct iovec *, size_t));
  240. #else
  241. bool varpush(int, ssize_t (int, const struct iovec *, int));
  242. #endif