Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
battle_steps.c
Go to the documentation of this file.
1/* CARDGAME's battle steps that wait on the screen: a message, the panels
2 closing and opening, the slots' values counted, and the conditions of a
3 play. */
4
6
7/* Opens message text for a step */
8void CARDGAME_startMessage(CardBattle *battle, CardScreen *screen, s32 text) {
9 battle->effectStep.time = 0;
10 screen->openMessage(screen, text, 0, 0, 1);
11 battle->effectStep.state = 1;
12}
13
14/* Waits for the message window to open, for cross or triangle, then for the window to close; 1 once it has */
16 s32 done = 0;
17
18 switch (battle->effectStep.state) {
19 case 1:
20 if (screen->message.state == 2) {
21 battle->effectStep.state = 2;
22 }
23 break;
24 case 2:
26 battle->effectStep.state = 3;
27 screen->closeMessage(screen);
28 }
29 break;
30 case 3:
31 if (screen->message.state == 0) {
32 battle->effectStep.state = 4;
33 }
34 break;
35 case 4:
36 done = 1;
37 break;
38 }
39 return done;
40}
41
42/* When the last card was the player's (or force): takes its play off
43 for a while and closes the panels */
44void CARDGAME_startClosePanels(CardBattle *battle, CardScreen *screen, s32 force) {
45 if (battle->record.plays[battle->record.playCount - 1].side == 0 || force) {
46 battle->record.playCount--;
47 screen->closePanels(screen);
49 battle->effectStep.state = 1;
50 } else {
51 battle->effectStep.state = 2;
52 }
53}
54
55/* Waits for the panels to close and puts the play back; 1 once done */
57 s32 done = 0;
58
59 switch (battle->effectStep.state) {
60 case 1:
61 if (screen->panels[0].state == 0 && battle->anim.current == CARD_ANIM_NONE) {
62 battle->effectStep.state = 2;
63 battle->record.playCount++;
64 }
65 break;
66 case 2:
67 done = 1;
68 break;
69 }
70 return done;
71}
72
73/* When the last card was the player's (or force): takes its play off
74 for a while and opens the panels */
75void CARDGAME_startOpenPanels(CardBattle *battle, CardScreen *screen, s32 force) {
76 if (battle->record.plays[battle->record.playCount - 1].side == 0 || force) {
77 screen->openPanels(screen);
80 battle->effectStep.state = 1;
81 battle->record.playCount--;
82 } else {
83 battle->effectStep.state = 2;
84 }
85}
86
87/* Waits for the panels to open and puts the play back; 1 once done */
89 s32 done = 0;
90
91 switch (battle->effectStep.state) {
92 case 1:
93 if (battle->anim.current == CARD_ANIM_NONE && screen->panels[0].state == 2) {
94 battle->effectStep.state = 2;
95 battle->record.playCount++;
96 }
97 break;
98 case 2:
99 done = 1;
100 break;
101 }
102 return done;
103}
104
105/* Steps each slot's shown values (its sprite's ap and hp) one unit toward the slot's ap and hp, with a sound; 1 once all are there, 2 if a slot's hp reached 0 (marked in effectStep.marked) */
107 s32 done = 0;
108 s32 changed = 0;
109 s32 side;
110 s32 i;
111 CardSprite *sprites;
112
113 switch (battle->effectStep.state) {
114 case 1:
115 default:
116 for (i = 0; i < 12; i++) {
117 battle->effectStep.marked[i] = 0;
118 }
119 battle->effectStep.state = 2;
120 battle->effectStep.vars[4] = 0;
121 break;
122 case 2:
123 done = 1;
124 for (side = 0; side < 2; side++) {
125 if (side == 0) {
126 sprites = &screen->sprites[0];
127 } else {
128 sprites = &screen->sprites[6];
129 }
130 for (i = 0; i < battle->players[side].slotCount; i++) {
131 if (sprites[i].ap != battle->players[side].slots[i].ap) {
132 if (sprites[i].ap > battle->players[side].slots[i].ap) {
133 sprites[i].ap--;
134 } else {
135 sprites[i].ap++;
136 }
137 done = 0;
138 changed = 1;
139 }
140 if (sprites[i].hp != battle->players[side].slots[i].hp) {
141 if (sprites[i].hp > battle->players[side].slots[i].hp) {
142 sprites[i].hp--;
143 } else {
144 sprites[i].hp++;
145 }
146 done = 0;
147 if (battle->players[side].slots[i].hp == 0) {
148 battle->effectStep.marked[i + side * 6] = 1;
149 battle->effectStep.vars[4] = 1;
150 }
151 changed = 1;
152 }
153 }
154 }
155 if (done && battle->effectStep.vars[4]) {
156 done = 2;
157 }
158 if (changed) {
160 }
161 break;
162 }
163 return done;
164}
165
166/* Whether the condition kind (1-11) of the card being played holds for its side: 1 if it does */
168 CardDrawer drawer;
169 CardDrawer drawer2;
170 CardDrawer drawer3;
171 CardDrawer drawer4;
172 s32 ok = 0;
173 s32 side = battle->record.plays[battle->record.playCount - 1].side;
174 s32 other = side ^ 1;
175 s32 i;
176 s32 slot;
177 s32 j;
178 CardSlot *p;
179 s32 n;
180 s32 k;
181 s32 valid;
182
183 switch (kind) {
184 case 1:
185 if (battle->sides[other].pile.handCount == 0) {
186 ok = 1;
187 }
188 break;
189 case 2:
190 initCardDrawer(&drawer);
191 ok = 1;
192 for (i = 0; i < battle->sides[other].pile.handCount; i++) {
193 drawer.setCard(battle->cards[battle->sides[other].pile.hand[i]] + 1);
194 if (drawer.card->color == 6 && drawer.card->kind == 0x10) {
195 ok = 0;
196 break;
197 }
198 }
199 break;
200 case 3:
201 initCardDrawer(&drawer2);
202 ok = 1;
203 for (i = 0; i < battle->sides[other].pile.handCount; i++) {
204 drawer2.setCard(battle->cards[battle->sides[other].pile.hand[i]] + 1);
205 if (drawer2.card->color != 5) {
206 ok = 0;
207 break;
208 }
209 }
210 break;
211 case 4:
212 if (battle->sides[side].pile.discardCount == 0) {
213 ok = 1;
214 }
215 break;
216 case 5:
217 if (battle->sides[side].pile.deckCount == 0) {
218 ok = 1;
219 }
220 break;
221 case 6:
222 if (battle->sides[other].pile.deckCount == 0) {
223 ok = 1;
224 }
225 break;
226 case 7:
227 initCardDrawer(&drawer3);
228 ok = 1;
229 for (i = battle->sides[side].pile.deckTop; i < 40; i++) {
230 drawer3.setCard(battle->cards[battle->sides[side].pile.deck[i]] + 1);
231 if (drawer3.card->kind == 0x10) {
232 ok = 0;
233 break;
234 }
235 }
236 break;
237 case 8:
238 initCardDrawer(&drawer4);
239 ok = 1;
240 for (i = battle->sides[side].pile.deckTop; i < 40; i++) {
241 drawer4.setCard(battle->cards[battle->sides[side].pile.deck[i]] + 1);
242 if (drawer4.card->kind != 0x10) {
243 ok = 0;
244 break;
245 }
246 }
247 break;
248 case 9:
249 ok = 1;
250 n = battle->record.playCount - 1;
251 for (slot = 0; slot < 12; slot++) {
252 battle->effectStep.marked[slot] = 0;
253 if (slot < 6) {
254 if (slot >= battle->players[0].slotCount) {
255 continue;
256 }
257 p = &battle->players[0].slots[slot];
258 } else {
259 if (slot - 6 >= battle->players[1].slotCount) {
260 continue;
261 }
262 p = &battle->players[1].slots[slot - 6];
263 }
264 if (p->order == battle->record.plays[n].target) {
265 ok = 0;
266 break;
267 }
268 }
269 break;
270 case 10:
271 ok = 1;
272 for (i = 0; i < 12 && ok == 1; i++) {
273 k = i - 6;
274 if (i < 6) {
275 valid = i < battle->players[0].slotCount;
276 } else {
277 valid = k < battle->players[1].slotCount;
278 }
279 if (valid) {
280 switch (battle->record.plays[battle->record.playCount - 1].targetKind) {
281 case 1:
282 if (side == 0) {
283 if (i < 6) {
284 ok = 0;
285 }
286 } else {
287 if (i >= 6) {
288 ok = 0;
289 }
290 }
291 break;
292 case 2:
293 if (side == 0) {
294 if (i >= 6) {
295 ok = 0;
296 }
297 } else {
298 if (i < 6) {
299 ok = 0;
300 }
301 }
302 break;
303 case 3:
304 ok = 0;
305 break;
306 case 4:
307 if (screen->getCardColor(screen, i < 6 ? battle->players[0].slots[i].card : battle->players[1].slots[i - 6].card) != 1) {
308 ok = 0;
309 }
310 break;
311 case 5:
312 if (screen->getCardColor(screen, i < 6 ? battle->players[0].slots[i].card : battle->players[1].slots[i - 6].card) != 2) {
313 ok = 0;
314 }
315 break;
316 case 6:
317 if (screen->getCardColor(screen, i < 6 ? battle->players[0].slots[i].card : battle->players[1].slots[i - 6].card) == 3) {
318 ok = 0;
319 }
320 break;
321 case 7:
322 if (screen->getCardColor(screen, i < 6 ? battle->players[0].slots[i].card : battle->players[1].slots[i - 6].card) != 4) {
323 ok = 0;
324 }
325 break;
326 case 8:
327 if (screen->getCardColor(screen, i < 6 ? battle->players[0].slots[i].card : battle->players[1].slots[i - 6].card) == 6) {
328 ok = 0;
329 }
330 break;
331 }
332 }
333 }
334 break;
335 case 11:
336 ok = 1;
337 for (j = 0; j < battle->sides[side].pile.handCount; j++) {
338 if (battle->record.plays[battle->record.playCount - 1].target == battle->sides[side].pile.hand[j]) {
339 ok = 0;
340 break;
341 }
342 }
343 break;
344 }
345 return ok;
346}
s32 CARDGAME_waitMessage(CardBattle *battle, CardScreen *screen)
Waits for the message window to open, for cross or triangle, then for the window to close; 1 once it ...
s32 CARDGAME_checkPlayCondition(CardBattle *battle, CardScreen *screen, s32 kind)
Whether the condition kind (1-11) of the card being played holds for its side: 1 if it does.
void CARDGAME_startClosePanels(CardBattle *battle, CardScreen *screen, s32 force)
When the last card was the player's (or force): takes its play off for a while and closes the panels.
s32 CARDGAME_stepClosePanels(CardBattle *battle, CardScreen *screen)
Waits for the panels to close and puts the play back; 1 once done.
void CARDGAME_startMessage(CardBattle *battle, CardScreen *screen, s32 text)
Opens message text for a step.
Definition battle_steps.c:8
s32 CARDGAME_stepOpenPanels(CardBattle *battle, CardScreen *screen)
Waits for the panels to open and puts the play back; 1 once done.
void CARDGAME_startOpenPanels(CardBattle *battle, CardScreen *screen, s32 force)
When the last card was the player's (or force): takes its play off for a while and opens the panels.
s32 CARDGAME_countSlotValues(CardBattle *battle, CardScreen *screen)
Steps each slot's shown values (its sprite's ap and hp) one unit toward the slot's ap and hp,...
CARDGAME.PRO: the card battle (mode 0x700).
void initCardDrawer(CardDrawer *obj)
Clears a card drawer, gives it its methods and binds it.
#define CARD_ANIM_UNDIM_ALL
CardAnim.dimAll.
Definition battle.h:189
@ CARD_ANIM_HIDE_SLOTS
Definition battle.h:169
@ CARD_ANIM_SHOW_SLOTS
Definition battle.h:168
@ CARD_ANIM_NONE
Definition battle.h:167
signed int s32
Definition common.h:11
#define PAD_CROSS
Definition pad.h:31
#define PAD_TRIANGLE
Definition pad.h:32
#define PAD_PRESSED(button)
One button of pad 1: newly pressed, auto-repeated while held, or held.
Definition pad.h:140
SoundState SOUND
rsin and rcos (libgte) read rsin_tbl[a - 0x800] and the like: their addresses before the table fall i...
Definition sound.c:180
#define SOUND_COUNT
SYSTEM10: a number counts up or down.
Definition sound.h:45
u8 next
the one to start
Definition battle.h:195
u8 current
a CardAnimId
Definition battle.h:194
u8 dimAll
sets dimmed of the first 15 sprites once
Definition battle.h:199
The card battle (CARDGAME_createBattle).
Definition battle.h:226
CardPlayer players[2]
Definition battle.h:275
CardRecord record
Definition battle.h:273
s16 cards[250]
card ids, minus one (CARDGAME_loadCardImages)
Definition battle.h:228
CardAnim anim
Definition battle.h:263
CardStep effectStep
Definition battle.h:262
CardSide sides[2]
Definition battle.h:274
Draws the cards' images (CardImage), from files 0x7E7-0x7EB.
Definition gfx.h:193
void(* setCard)()
(id)
Definition gfx.h:205
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 state
1 opening, 2 open, 4 confirmed, 5 closing
Definition screen.h:256
s16 state
Definition screen.h:137
s16 deckCount
the cards left in the deck
Definition battle.h:113
s16 discardCount
Definition battle.h:112
s16 deck[40]
deckTop on are left
Definition battle.h:118
s16 handCount
Definition battle.h:114
s16 deckTop
the index of the deck's top card
Definition battle.h:111
s16 hand[10]
handCount in use
Definition battle.h:119
u8 targetKind
its effect's (CardEffect.target)
Definition battle.h:47
u8 side
who played it
Definition battle.h:46
u8 target
the slot's order, or the card, it was played on
Definition battle.h:48
CardSlot slots[8]
Definition battle.h:39
u8 slotCount
Definition battle.h:38
s8 playCount
the plays in use
Definition battle.h:130
CardPlay plays[3]
the cards played this turn, up to three
Definition battle.h:137
The battle screen (created by CARDGAME_createScreen): the two panels, the cards on the table and the ...
Definition screen.h:263
CardMessageWindow message
Definition screen.h:274
s32(* getCardColor)(struct CardScreen *screen, s32 index)
Definition screen.h:325
void(* openPanels)(struct CardScreen *screen)
Definition screen.h:295
CardSprite sprites[40]
Definition screen.h:271
void(* openMessage)(struct CardScreen *screen, s32 message, s32 prompt, s16 choice, s32 place)
Definition screen.h:302
void(* closePanels)(struct CardScreen *screen)
Definition screen.h:294
void(* closeMessage)(struct CardScreen *screen)
Definition screen.h:303
CardPanel panels[2]
Definition screen.h:270
CardPile pile
Definition battle.h:160
A card a player has out (CARDGAME_setSlot)
Definition battle.h:19
s16 hp
its hit points, 0 to 99: at 0 it is lost
Definition battle.h:24
s16 ap
its attack points, 0 to 99
Definition battle.h:23
s16 card
the index in the battle's card list
Definition battle.h:20
u8 order
CardBattle.slotCount when it was added.
Definition battle.h:27
A card on the battle screen (CardScreen.sprites)
Definition screen.h:163
u8 ap
the values shown, which count towards the slot's
Definition screen.h:188
s32 time
a frame count, or the step's own sub-state
Definition battle.h:148
u8 state
the step's own state
Definition battle.h:146
s32 vars[5]
values each step uses its own way
Definition battle.h:149
s8 marked[40]
the cards or slots picked
Definition battle.h:155
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187