iwm: Fix S:N reporting in ifconfig(8)
[dragonfly.git] / games / mille / init.c
1 /*-
2  * Copyright (c) 1982, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * @(#)init.c   8.1 (Berkeley) 5/31/93
30  * $FreeBSD: src/games/mille/init.c,v 1.5 1999/12/12 06:17:24 billf Exp $
31  */
32
33 #include "mille.h"
34
35 /*
36  * @(#)init.c   1.1 (Berkeley) 4/1/82
37  */
38
39 void
40 init(void)
41 {
42         PLAY    *pp;
43         int     i, j;
44         CARD    card;
45
46         memset(Numseen, 0, sizeof Numseen);
47         Numgos = 0;
48
49         for (i = 0; i < 2; i++) {
50                 pp = &Player[i];
51                 pp->hand[0] = C_INIT;
52                 for (j = 0; j < NUM_SAFE; j++) {
53                         pp->safety[j] = S_UNKNOWN;
54                         pp->coups[j] = FALSE;
55                 }
56                 for (j = 1; j < HAND_SZ; j++) {
57                         pp->hand[j] = *--Topcard;
58                         if (i == COMP) {
59                                 account(card = *Topcard);
60                                 if (issafety(card))
61                                         pp->safety[card - S_CONV] = S_IN_HAND;
62                         }
63                 }
64                 pp->mileage = 0;
65                 pp->hand_tot = 0;
66                 pp->safescore = 0;
67                 pp->coupscore = 0;
68                 pp->can_go = FALSE;
69                 pp->speed = C_INIT;
70                 pp->battle = C_INIT;
71                 pp->new_speed = FALSE;
72                 pp->new_battle = FALSE;
73                 for (j = 0; j < NUM_MILES; j++)
74                         pp->nummiles[j] = 0;
75         }
76         if (Order)
77                 sort(Player[PLAYER].hand);
78         Discard = C_INIT;
79         Finished = FALSE;
80         End = 700;
81 }
82
83 void
84 shuffle(void)
85 {
86         int     i, r;
87         CARD    temp;
88
89         for (i = 0; i < DECK_SZ; i++) {
90                 r = roll(1, DECK_SZ) - 1;
91                 if (r < 0 || r > DECK_SZ - 1) {
92                         fprintf(stderr, "shuffle: card no. error: %d\n", r);
93                         die(1);
94                 }
95                 temp = Deck[r];
96                 Deck[r] = Deck[i];
97                 Deck[i] = temp;
98         }
99         Topcard = &Deck[DECK_SZ];
100 }
101
102 void
103 newboard(void)
104 {
105         int             i;
106         PLAY            *pp;
107         static int      first = TRUE;
108
109         if (first) {
110                 werase(Board);
111                 werase(Score);
112                 mvaddstr(5, 0, "--HAND--");
113                 mvaddch(6, 0, 'P');
114                 mvaddch(7, 0, '1');
115                 mvaddch(8, 0, '2');
116                 mvaddch(9, 0, '3');
117                 mvaddch(10, 0, '4');
118                 mvaddch(11, 0, '5');
119                 mvaddch(12, 0, '6');
120                 mvaddstr(13, 0, "--BATTLE--");
121                 mvaddstr(15, 0, "--SPEED--");
122                 mvaddstr(5, 20, "--DECK--");
123                 mvaddstr(7, 20, "--DISCARD--");
124                 mvaddstr(13, 20, "--BATTLE--");
125                 mvaddstr(15, 20, "--SPEED--");
126                 mvwaddstr(Miles, 0, 0, "--MILEAGE--");
127                 mvwaddstr(Miles, 0, 41, "--MILEAGE--");
128                 Sh_discard = -1;
129                 for (pp = Player; pp <= &Player[COMP]; pp++) {
130                         for (i = 0; i < HAND_SZ; i++)
131                                 pp->sh_hand[i] = -1;
132                         pp->sh_battle = -1;
133                         pp->sh_speed = -1;
134                         pp->sh_mileage = -1;
135                 }
136                 first = FALSE;
137         }
138         else {
139                 for (i = 0; i < 5; i++) {
140                         move(i, 0);
141                         clrtoeol();
142                 }
143                 wmove(Miles, 1, 0);
144                 wclrtobot(Miles);
145                 wmove(Board, MOVE_Y + 1, MOVE_X);
146                 wclrtoeol(Board);
147                 wmove(Board, MOVE_Y + 2, MOVE_X);
148                 wclrtoeol(Board);
149         }
150         Sh_discard = -1;
151         for (pp = Player; pp <= &Player[COMP]; pp++) {
152                 for (i = 0; i < NUM_SAFE; i++)
153                         pp->sh_safety[i] = FALSE;
154                 for (i = 0; i < NUM_MILES; i++)
155                         pp->sh_nummiles[i] = 0;
156                 pp->sh_safescore = -1;
157         }
158         newscore();
159 }
160
161 void
162 newscore(void)
163 {
164         int             i, new;
165         PLAY            *pp;
166         static int      was_full = -1;
167         static int      last_win = -1;
168
169         if (was_full < 0)
170                 was_full = (Window != W_FULL);
171         stdscr = Score;
172         move(0, 22);
173         new = FALSE;
174         if (inch() != 'Y') {
175                 erase();
176                 mvaddstr(0, 22,  "You   Comp   Value");
177                 mvaddstr(1, 2, "Milestones Played");
178                 mvaddstr(2, 8, "Each Safety");
179                 mvaddstr(3, 5, "All 4 Safeties");
180                 mvaddstr(4, 3, "Each Coup Fourre");
181                 mvaddstr(2, 37, "100");
182                 mvaddstr(3, 37, "300");
183                 mvaddstr(4, 37, "300");
184                 new = TRUE;
185         }
186         else if ((Window == W_FULL || Finished) ^ was_full) {
187                 move(5, 1);
188                 clrtobot();
189                 new = TRUE;
190         }
191         else if (Window != last_win)
192                 new = TRUE;
193         if (new) {
194                 for (i = 0; i < SCORE_Y; i++)
195                         mvaddch(i, 0, '|');
196                 move(SCORE_Y - 1, 1);
197                 for (i = 0; i < SCORE_X; i++)
198                         addch('_');
199                 for (pp = Player; pp <= &Player[COMP]; pp++) {
200                         pp->sh_hand_tot = -1;
201                         pp->sh_total = -1;
202                         pp->sh_games = -1;
203                         pp->sh_safescore = -1;
204                 }
205         }
206         Player[PLAYER].was_finished = !Finished;
207         Player[COMP].was_finished = !Finished;
208         if (Window == W_FULL || Finished) {
209                 if (!was_full || new) {
210                         mvaddstr(5, 5, "Trip Completed");
211                         mvaddstr(6, 10, "Safe Trip");
212                         mvaddstr(7, 5, "Delayed Action");
213                         mvaddstr(8, 10, "Extension");
214                         mvaddstr(9, 11, "Shut-Out");
215                         mvaddstr(10, 21, "----   ----   -----");
216                         mvaddstr(11, 9, "Hand Total");
217                         mvaddstr(12, 20, "-----  -----");
218                         mvaddstr(13, 6, "Overall Total");
219                         mvaddstr(14, 15, "Games");
220                         mvaddstr(5, 37, "400");
221                         mvaddstr(6, 37, "300");
222                         mvaddstr(7, 37, "300");
223                         mvaddstr(8, 37, "200");
224                         mvaddstr(9, 37, "500");
225                 }
226         }
227         else
228                 if (was_full || new) {
229                         mvaddstr(5, 21, "----   ----   -----");
230                         mvaddstr(6, 9, "Hand Total");
231                         mvaddstr(7, 20, "-----  -----");
232                         mvaddstr(8, 6, "Overall Total");
233                         mvaddstr(9, 15, "Games");
234                         mvaddstr(11, 2, "p: pick");
235                         mvaddstr(12, 2, "u: use #");
236                         mvaddstr(13, 2, "d: discard #");
237                         mvaddstr(14, 2, "w: toggle window");
238                         mvaddstr(11, 21, "q: quit");
239                         if (!Order)
240                                 mvaddstr(12, 21, "o: order hand");
241                         else
242                                 mvaddstr(12, 21, "o: stop ordering");
243                         mvaddstr(13, 21, "s: save");
244                         mvaddstr(14, 21, "r: reprint");
245                 }
246         stdscr = Board;
247         was_full = (Window == W_FULL || Finished);
248         last_win = Window;
249 }