-/* $NetBSD: cards.c,v 1.16 2008/02/19 09:30:26 dholland Exp $ */
+/* $NetBSD: cards.c,v 1.20 2008/02/23 19:54:06 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
#if 0
static char sccsid[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: cards.c,v 1.16 2008/02/19 09:30:26 dholland Exp $");
+__RCSID("$NetBSD: cards.c,v 1.20 2008/02/23 19:54:06 dholland Exp $");
#endif
#endif /* not lint */
{
int32_t nc;
- if ((deckf=fopen(cardfile, "r")) == NULL) {
+ if ((deckf = fopen(cardfile, "r")) == NULL) {
file_err:
err(1, "%s", cardfile);
}
/* convert offsets from big-endian byte order */
for (i = 0; i < dp->num_cards; i++)
BE64TOH(dp->offsets[i]);
- dp->last_card = 0;
+ dp->top_card = 0;
dp->gojf_used = FALSE;
for (i = 0; i < dp->num_cards; i++) {
off_t temp;
OWN *op;
do {
- fseek(deckf, dp->offsets[dp->last_card], SEEK_SET);
- dp->last_card = ++(dp->last_card) % dp->num_cards;
+ fseek(deckf, dp->offsets[dp->top_card], SEEK_SET);
+ dp->top_card = ++(dp->top_card) % dp->num_cards;
type_maj = getc(deckf);
} while (dp->gojf_used && type_maj == GOJF);
type_min = getc(deckf);
printline();
fflush(stdout);
}
+
+/*
+ * This routine returns the players get-out-of-jail-free card
+ * to the bottom of a deck. XXX currently does not return to the correct
+ * deck.
+ */
+void
+ret_card(plr)
+ PLAY *plr;
+{
+ char type_maj;
+ int gojfpos, last_card;
+ int i;
+ DECK *dp;
+ off_t temp;
+
+ plr->num_gojf--;
+ if (CC_D.gojf_used)
+ dp = &CC_D;
+ else
+ dp = &CH_D;
+ dp->gojf_used = FALSE;
+
+ /* Put at bottom of deck (top_card - 1) and remove it from wherever else
+ * it used to be.
+ */
+ last_card = dp->top_card - 1;
+ if (last_card < 0)
+ last_card += dp->num_cards;
+ gojfpos = dp->top_card;
+ do {
+ gojfpos = (gojfpos + 1) % dp->num_cards;
+ fseek(deckf, dp->offsets[gojfpos], SEEK_SET);
+ type_maj = getc(deckf);
+ } while (type_maj != GOJF);
+ temp = dp->offsets[gojfpos];
+ /* Only one of the next two loops does anything */
+ for (i = gojfpos - 1; i > last_card; i--)
+ dp->offsets[i + 1] = dp->offsets[i];
+ for (i = gojfpos; i < last_card; i++)
+ dp->offsets[i] = dp->offsets[i + 1];
+ if (gojfpos > last_card) {
+ dp->offsets[dp->top_card] = temp;
+ dp->top_card++;
+ dp->top_card %= dp->num_cards;
+ } else
+ dp->offsets[last_card] = temp;
+}