Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
play_checks.c
Go to the documentation of this file.
1/* CARDGAME's opponent card order and the checks of whether a card can be
2 played. */
3
5
6/* Sorts the opponent's cards by opponentDraws[].order, then swaps card effectStep.choice to reserveStart */
8 CardDraw draw;
9 s16 *cards = battle->sides[1].pile.deck;
10 s16 card;
11 s32 i;
12 s32 j;
13 s32 target;
14
15 for (i = battle->sides[1].pile.deckTop; i < 39; i++) {
16 for (j = i + 1; j < 40; j++) {
17 if (battle->opponentDraws[i].order > battle->opponentDraws[j].order) {
18 card = cards[i];
19 cards[i] = cards[j];
20 cards[j] = card;
21 draw = battle->opponentDraws[i];
22 battle->opponentDraws[i] = battle->opponentDraws[j];
23 battle->opponentDraws[j] = draw;
24 }
25 }
26 }
27 target = battle->reserveStart;
28 draw = battle->opponentDraws[battle->effectStep.choice];
29 battle->opponentDraws[battle->effectStep.choice] = battle->opponentDraws[target];
30 battle->opponentDraws[target] = draw;
31 card = cards[battle->effectStep.choice];
32 cards[battle->effectStep.choice] = cards[target];
33 cards[target] = card;
34 battle->effectStep.choice = target;
35}
36
37/* Whether card index can be played in this phase by its kind: any kind but 0
38 in CARD_PHASE_PLAYS_AFTER, kind 2 in CARD_PHASE_PLAYS_BEFORE */
40 CardDrawer drawer;
41 s32 result = 0;
42 s32 kind;
43
44 initCardDrawer(&drawer);
45 drawer.setCard(battle->cards[index] + 1);
46 kind = drawer.getKind();
47 if (kind != 0) {
48 if (battle->phase == CARD_PHASE_PLAYS_AFTER || (battle->phase == CARD_PHASE_PLAYS_BEFORE && kind == 2)) {
49 result = 1;
50 }
51 }
52 return result;
53}
54
55/* Whether a card can be played: in CARD_PHASE_PUT_OUT a kind 0x10 card needs as many
56 points of its colour (points), otherwise CARDGAME_canPlayCardKind */
57s32 CARDGAME_canPlayCard(CardBattle *battle, u8 *points, s32 card) {
58 CardDrawer drawer;
59 s32 result = 0;
60
61 if (battle->phase == CARD_PHASE_PUT_OUT) {
62 initCardDrawer(&drawer);
63 drawer.setCard(battle->cards[card] + 1);
64 if (drawer.card->kind == 0x10) {
65 result = points[drawer.card->color - 1] >= drawer.card->points;
66 }
67 } else {
68 result = CARDGAME_canPlayCardKind(battle, card);
69 }
70 return result;
71}
CARDGAME.PRO: the card battle (mode 0x700).
void initCardDrawer(CardDrawer *obj)
Clears a card drawer, gives it its methods and binds it.
@ CARD_PHASE_PUT_OUT
Definition battle.h:85
@ CARD_PHASE_PLAYS_AFTER
plays after: any kind but 0
Definition battle.h:86
@ CARD_PHASE_PLAYS_BEFORE
plays before the cards are put out: kind 2 cards only
Definition battle.h:84
signed int s32
Definition common.h:11
signed short s16
Definition common.h:9
unsigned char u8
Definition common.h:8
s32 CARDGAME_canPlayCard(CardBattle *battle, u8 *points, s32 card)
Whether a card can be played: in CARD_PHASE_PUT_OUT a kind 0x10 card needs as many points of its colo...
Definition play_checks.c:57
s32 CARDGAME_canPlayCardKind(CardBattle *battle, s32 index)
Whether card index can be played in this phase by its kind: any kind but 0 in CARD_PHASE_PLAYS_AFTER,...
Definition play_checks.c:39
void CARDGAME_sortOpponentCards(CardBattle *battle)
Sorts the opponent's cards by opponentDraws[].order, then swaps card effectStep.choice to reserveStar...
Definition play_checks.c:7
The card battle (CARDGAME_createBattle).
Definition battle.h:226
s16 cards[250]
card ids, minus one (CARDGAME_loadCardImages)
Definition battle.h:228
u8 phase
a CARD_PHASE_*
Definition battle.h:242
u8 reserveStart
the first card of the opponent's deck held back (group 7)
Definition battle.h:261
CardStep effectStep
Definition battle.h:262
CardSide sides[2]
Definition battle.h:274
CardDraw opponentDraws[40]
by the opponent's deck card
Definition battle.h:255
Where a card of the opponent's deck is drawn (CardBattle.opponentDraws): the computer draws the cards...
Definition battle.h:102
u8 order
its place in the deck
Definition battle.h:103
Draws the cards' images (CardImage), from files 0x7E7-0x7EB.
Definition gfx.h:193
void(* setCard)()
(id)
Definition gfx.h:205
s32(* getKind)(void)
Definition gfx.h:214
CardImage * card
Definition gfx.h:194
u8 color
from 1
Definition gfx.h:173
u8 kind
an index in CARD_KINDS
Definition gfx.h:176
u8 points
what it adds to its colour
Definition gfx.h:179
s16 deck[40]
deckTop on are left
Definition battle.h:118
s16 deckTop
the index of the deck's top card
Definition battle.h:111
CardPile pile
Definition battle.h:160
s32 choice
the card, slot or answer chosen; -1 for none
Definition battle.h:151