Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
round.c
Go to the documentation of this file.
1/* CARDGAME's plays and round: the slots swept, a card put, taken, moved,
2 copied or turned over, a card played, the hands dealt, then the round's
3 start, attacks, swaps, totals and end (one module: cut between them, the
4 round's first jump table would lose its alignment). */
5
7
8/* Starts CARDGAME_stepSlotSweep */
10 battle->effectStep.vars[0] = 0;
11 battle->effectStep.state = 1;
12}
13
14/* Goes over the marked slots one by one, discarding their cards (which 0) or
15 returning them to the hand (1); 1 once done */
17 s32 done = 0;
18 s32 i;
19 s32 ok;
20
21 switch (battle->effectStep.state) {
22 case 1:
23 for (i = battle->effectStep.vars[0]; i < 12; i++) {
24 if (battle->effectStep.marked[i] != 0) {
25 battle->effectStep.state = 2;
26 battle->effectStep.time = 0;
27 battle->effectStep.vars[0] = i;
28 battle->effectStep.vars[1] = i >= 6;
29 battle->effectStep.vars[2] = i;
30 if (i >= 6) {
31 battle->effectStep.vars[2] = i - 6;
32 }
33 break;
34 }
35 }
36 if (i >= 12) {
37 battle->effectStep.state = 3;
38 }
39 break;
40 case 2:
41 if (which == 0) {
42 ok = CARDGAME_stepDiscardSlotCard(battle, screen, battle->effectStep.vars[1], battle->effectStep.vars[2]);
43 } else {
44 ok = CARDGAME_stepReturnSlotCard(battle, screen, battle->effectStep.vars[1], battle->effectStep.vars[2]);
45 }
46 if (ok) {
47 battle->effectStep.state = 1;
48 battle->effectStep.vars[0]++;
49 }
50 break;
51 case 3:
52 done = 1;
53 break;
54 }
55 return done;
56}
57
58/* Marks (marks) the plays whose effect reaches sprite index, by
59 their target (targetKind): a side, both, or a colour; side is not used */
60void CARDGAME_markRecordHits(CardBattle *battle, CardScreen *screen, s32 side, s32 index) {
61 s32 i;
62 s32 color;
63 s32 n;
64 n = battle->record.playCount - 1;
65 color = screen->sprites[index].color + 1;
66 for (i = 0; i < n; i++) {
67 screen->sprites[index].marks[i] = 0;
68 switch (battle->record.plays[i].targetKind) {
69 case 1:
70 if (battle->record.plays[i].side == 0) {
71 if (index < 6) {
72 screen->sprites[index].marks[i] = 1;
73 }
74 } else if (index >= 6) {
75 screen->sprites[index].marks[i] = 1;
76 }
77 break;
78 case 2:
79 if (battle->record.plays[i].side == 0) {
80 if (index >= 6) {
81 screen->sprites[index].marks[i] = 1;
82 }
83 } else if (index < 6) {
84 screen->sprites[index].marks[i] = 1;
85 }
86 break;
87 case 3:
88 screen->sprites[index].marks[i] = 1;
89 break;
90 case 4:
91 if (color != 1) {
92 screen->sprites[index].marks[i] = 1;
93 }
94 break;
95 case 5:
96 if (color != 2) {
97 screen->sprites[index].marks[i] = 1;
98 }
99 break;
100 case 6:
101 if (color == 3) {
102 screen->sprites[index].marks[i] = 1;
103 }
104 break;
105 case 7:
106 if (color != 4) {
107 screen->sprites[index].marks[i] = 1;
108 }
109 break;
110 case 8:
111 if (color == 6) {
112 screen->sprites[index].marks[i] = 1;
113 }
114 break;
115 }
116 }
117}
118
119/* Puts a card in the side's next slot (owned by side 2) and shows it */
120void CARDGAME_putSlotCard(CardBattle *battle, CardScreen *screen, s32 side, s32 card) {
121 CardDrawer drawer;
122 CardPlayer *player = &battle->players[side];
123 s32 index = player->slotCount;
124 s32 slot = index;
125
126 if (side != 0) {
127 index += 6;
128 }
129 initCardDrawer(&drawer);
130 drawer.setCard(battle->cards[card] + 1);
131 player->slots[slot].ap = drawer.card->ap;
132 player->slots[slot].hp = drawer.card->hp;
133 player->slots[slot].apBonus = 0;
134 player->slots[slot].hpBonus = 0;
135 player->slots[slot].card = card;
136 player->slots[slot].owner = side;
137 player->slots[slot].side = 2;
138 player->slots[slot].order = battle->slotCount++;
139 screen->addSprite(screen, index, 0xE500, 0x6100);
140 screen->setSpriteCard(screen, index, card);
141 screen->sprites[index].ap = player->slots[slot].ap;
142 screen->sprites[index].hp = player->slots[slot].hp;
143 screen->sprites[index].scaleX = 0;
144 CARDGAME_markRecordHits(battle, screen, side, index);
145 battle->effectStep.state = 1;
146 screen->scaleSprite(screen, index, 20, 0x1000, 0x1000);
147}
148
149/* Takes the card the last record names out of the side's hand into its next
150 slot and shows it */
151void CARDGAME_takeHandCard(CardBattle *battle, CardScreen *screen, s32 side) {
152 CardPlayer *player = &battle->players[side];
153 CardPile *pile = &battle->sides[side].pile;
154 s32 index = player->slotCount;
155 s32 slot = index;
156 s32 i;
157 s32 j;
158
159 if (side != 0) {
160 index += 6;
161 }
162 for (i = 0; i < pile->handCount; i++) {
163 if (battle->record.plays[battle->record.playCount - 1].target == pile->hand[i]) {
164 battle->addCard(battle, side, battle->record.plays[battle->record.playCount - 1].target);
165 break;
166 }
167 }
168 for (j = i; j < pile->handCount - 1; j++) {
169 pile->hand[j] = pile->hand[j + 1];
170 }
171 pile->handCount--;
172 player->slotCount--;
173 screen->addSprite(screen, index, 0xE500, 0x6100);
174 screen->setSpriteCard(screen, index, player->slots[slot].card);
175 for (i = 0; i < 5; i++) {
176 CARDGAME_setCountingCardValues(battle, &player->slots[slot], side, i);
177 }
178 screen->sprites[index].ap = player->slots[slot].ap;
179 screen->sprites[index].hp = player->slots[slot].hp;
180 screen->sprites[index].scaleX = 0;
181 CARDGAME_markRecordHits(battle, screen, side, index);
182 battle->effectStep.state = 1;
183 screen->setPanelValue(screen, side, CARD_PANEL_HAND, pile->handCount);
184 screen->scaleSprite(screen, index, 20, 0x1000, 0x1000);
185}
186
187/* Moves the side's next slot card into place; 1 once it is there */
189 s32 done = 0;
190 CardPlayer *player = &battle->players[side];
191 s32 index = player->slotCount;
192 s32 x;
193 s32 y;
194
195 if (side != 0) {
196 index += 6;
197 }
198#if PAL_VIDEO
199 if (side == 0) {
200 x = CARDGAME_slotRowPositions[SHIFT_PAL_SCREEN][0] + player->slotCount * 0x2900;
201 } else {
202 x = CARDGAME_slotRowPositions[SHIFT_PAL_SCREEN][2] + player->slotCount * 0x2900;
203 }
204 if (side == 0) {
206 } else {
208 }
209#else
210 x = player->slotCount * 0x2900 + 0x1800;
211 y = 0x3200;
212 if (side == 0) {
213 y = 0x9000;
214 }
215#endif
216 switch (battle->effectStep.state) {
217 case 1:
218 if (screen->sprites[index].state == 1) {
219 screen->startBlink(screen, index);
220 battle->effectStep.state = 2;
221 }
222 break;
223 case 2:
224 if (screen->sprites[index].state == 1) {
225 screen->startMove(screen, index, 20, x, y);
226 screen->sprites[index].moving = 1;
227 battle->effectStep.state = 3;
228 }
229 break;
230 case 3:
231 if (screen->sprites[index].state == 1) {
232 battle->effectStep.state = 4;
233 screen->sprites[index].moving = 0;
234 player->slotCount++;
235 }
236 break;
237 case 4:
238 done = 1;
239 break;
240 }
241 return done;
242}
243
244/* Copies the first marked slot card (effectStep.marked) into the side's next slot */
245void CARDGAME_copySlotCard(CardBattle *battle, CardScreen *screen, s32 side) {
246 CardPlayer *player = &battle->players[side];
247 s32 index = player->slotCount;
248 s32 slot = index;
249 CardSlot *src;
250 s32 from;
251 s32 i;
252
253 if (side != 0) {
254 index += 6;
255 }
256 from = 0;
257 src = &player->slots[slot];
258 for (i = 0; i < 12; i++) {
259 if (i < 6) {
260 if (i >= battle->players[0].slotCount) {
261 continue;
262 }
263 src = &battle->players[0].slots[i];
264 } else {
265 if (i - 6 >= battle->players[1].slotCount) {
266 continue;
267 }
268 src = &battle->players[1].slots[i - 6];
269 }
270 if (battle->effectStep.marked[i] != 0) {
271 from = i;
272 break;
273 }
274 }
275 player->slots[slot] = *src;
276 screen->addSprite(screen, index, 0xE500, 0x6100);
277 screen->setSpriteCard(screen, index, player->slots[slot].card);
278 screen->sprites[index] = screen->sprites[from];
279 screen->sprites[index].scaleX = 0;
280 CARDGAME_markRecordHits(battle, screen, side, index);
281 for (i = 0; i < battle->record.playCount - 1; i++) {
282 if (battle->record.plays[i].targetKind == 0 && screen->sprites[from].marks[i] != 0) {
283 screen->sprites[index].marks[i] = 1;
284 }
285 }
286 battle->effectStep.state = 1;
287 screen->scaleSprite(screen, from, 5, 0, 0x1000);
288 battle->effectStep.time = 7;
289}
290
291/* Waits effectStep.time frames, then flips the side's next slot card over and moves it
292 into place; 1 once it is there */
294 s32 done = 0;
295 CardPlayer *player = &battle->players[side];
296 s32 index = player->slotCount;
297 s32 x;
298 s32 y;
299
300 if (side != 0) {
301 index += 6;
302 }
303#if PAL_VIDEO
304 if (side == 0) {
305 x = CARDGAME_slotRowPositions[SHIFT_PAL_SCREEN][0] + player->slotCount * 0x2900;
306 } else {
307 x = CARDGAME_slotRowPositions[SHIFT_PAL_SCREEN][2] + player->slotCount * 0x2900;
308 }
309 if (side == 0) {
311 } else {
313 }
314#else
315 x = player->slotCount * 0x2900 + 0x1800;
316 y = 0x3200;
317 if (side == 0) {
318 y = 0x9000;
319 }
320#endif
321 switch (battle->effectStep.state) {
322 case 1:
323 battle->effectStep.time -= GFX.funcs.getFrameTime();
324 if (battle->effectStep.time <= 0) {
325 screen->scaleSprite(screen, index, 5, 0x1000, 0x1000);
326 battle->effectStep.state = 2;
327 }
328 break;
329 case 2:
330 if (screen->sprites[index].state == 1) {
331 screen->startBlink(screen, index);
332 battle->effectStep.state = 3;
333 }
334 break;
335 case 3:
336 if (screen->sprites[index].state == 1) {
337 screen->startMove(screen, index, 20, x, y);
338 screen->sprites[index].moving = 1;
339 battle->effectStep.state = 4;
340 }
341 break;
342 case 4:
343 if (screen->sprites[index].state == 1) {
344 battle->effectStep.state = 5;
345 screen->sprites[index].moving = 0;
346 player->slotCount++;
347 }
348 break;
349 case 5:
350 done = 1;
351 break;
352 }
353 return done;
354}
355
356/* Shows the card being played as sprite 15 (opening the panels for side 0)
357 and starts moving it to its place in the record */
358void CARDGAME_startPlayCard(CardBattle *battle, CardScreen *screen, s32 side) {
359 s32 i;
360 s32 j;
361
362 if (side == 0 || screen->panels[0].state == 0) {
363 if (screen->panels[0].state == 0) {
364 screen->resetPanels(screen);
365 battle->effectStep.choice = 0;
366 screen->addSprite(screen, 15, 0xE500, 0x6100);
367 screen->setSpriteCard(screen, 15, battle->record.plays[battle->record.playCount].card);
368 screen->sprites[15].scaleX = 0;
369 screen->scaleSprite(screen, 15, 8, 0x1000, 0x1000);
370 screen->openPanels(screen);
372 battle->anim.dimmed[15] = 0;
373 if (side == 0) {
374 for (j = 0; j < 15; j++) {
375 battle->effectStep.marked[j] = 0;
376 }
377 }
379 battle->effectStep.state = 1;
380 } else {
382#if VERSION_US
383 battle->effectStep.state = 3;
384#elif VERSION_EU || VERSION_JP
385 battle->effectStep.state = 5;
386#endif
387 battle->effectStep.time = 0;
388 }
389 } else {
390 screen->addSprite(screen, 15, 0xE500, 0x6100);
391 screen->setSpriteCard(screen, 15, battle->record.plays[battle->record.playCount].card);
392 screen->sprites[15].scaleX = 0;
393 screen->scaleSprite(screen, 15, 8, 0x1000, 0x1000);
394 battle->effectStep.state = 2;
395 battle->effectStep.time = 0;
396#if VERSION_EU || VERSION_JP
397 battle->effectStep.vars[0] = 0;
398#endif
399 }
400 screen->clearPanelFlags(screen);
401 for (i = 0; i < 15; i++) {
402 screen->sprites[i].dimmed = 0;
403 }
404}
405
406/* Card 15 goes off and the marked slot cards turn over; it then lands in
407 sprite 12 + CardRecord.playCount. 1 once done */
409 s32 done = 0;
410 s32 i;
411 s32 j;
412#if VERSION_EU || VERSION_JP
413 s32 card;
414#endif
415
416 switch (battle->effectStep.state) {
417#if VERSION_US
418 case 2:
419 battle->effectStep.time += GFX.funcs.getFrameTime();
420 if (battle->effectStep.time >= 21) {
422 battle->effectStep.state = 3;
423 battle->effectStep.time = 0;
424 }
425 break;
426#elif VERSION_EU || VERSION_JP
427 case 2:
428 screen->windows[1].showCount = 0;
429 screen->windows[1].value = 0;
430 screen->windows[2].value = 0;
431 screen->windows[3].value = 0;
432 screen->windows[4].value = 0;
433 battle->effectStep.vars[0] = CARDGAME_openStepWindows(battle, screen, 2, 0, battle->effectStep.time, battle->effectStep.vars[0]);
434 battle->effectStep.time += GFX.funcs.getFrameTime();
435 if (battle->effectStep.time >= 21) {
436 battle->effectStep.time = 0;
437 battle->effectStep.vars[0] = 0;
438 battle->effectStep.state = 3;
439 }
440 break;
441 case 3:
443 battle->effectStep.state = 4;
444 }
445 card = battle->cards[battle->record.plays[battle->record.playCount].card] + 1;
446 screen->windows[4].numbers[2] = 0;
447 screen->windows[2].value = card;
448 screen->windows[4].value = card;
449 break;
450 case 4:
452 screen->closeWindow(screen, 4);
453 screen->closeWindow(screen, 1);
454 screen->closeWindow(screen, 2);
455 screen->closeWindow(screen, 3);
456 battle->effectStep.state = 5;
457 battle->effectStep.time = 0;
458 battle->effectStep.vars[0] = 0;
459 break;
460#endif
461 case 1:
462 if (screen->panels[0].state == 2 && battle->anim.current == CARD_ANIM_NONE) {
464 battle->effectStep.state = 3 + CARD_INFO_STEPS;
465 battle->effectStep.time = 0;
466 }
467 break;
468 case 3 + CARD_INFO_STEPS:
469 battle->effectStep.time += GFX.funcs.getFrameTime();
470 if (battle->effectStep.time >= 12) {
471 battle->effectStep.time = 0;
472 battle->effectStep.state = 4 + CARD_INFO_STEPS;
473 screen->startBlink(screen, 15);
474 for (i = 0; i < 15; i++) {
475 if (battle->effectStep.marked[i] != 0) {
476 screen->startBlink(screen, i);
477 }
478 }
479 }
480 break;
481 case 4 + CARD_INFO_STEPS:
482 battle->effectStep.time += GFX.funcs.getFrameTime();
483 if (battle->effectStep.time >= 21) {
484 battle->effectStep.state = 5 + CARD_INFO_STEPS;
485 battle->effectStep.time = 0;
486 screen->scaleSprite(screen, 15, 5, 0, 0x1000);
487 for (j = 0; j < 15; j++) {
488 if (battle->effectStep.marked[j] != 0) {
489 screen->sprites[j].marks[battle->record.playCount] = 1;
490 }
491 }
492 }
493 break;
494 case 5 + CARD_INFO_STEPS:
495 battle->effectStep.time += GFX.funcs.getFrameTime();
496 if (battle->effectStep.time >= 7) {
497 battle->effectStep.time = 0;
498 screen->sprites[15].order = battle->record.playCount + 1;
499 screen->scaleSprite(screen, 15, 8, 0x1000, 0x1000);
500 battle->effectStep.state = 6 + CARD_INFO_STEPS;
501 screen->openGauge(screen, battle->record.playCount, battle->record.turnSide);
502 }
503 break;
504 case 6 + CARD_INFO_STEPS:
505 battle->effectStep.time += GFX.funcs.getFrameTime();
506 if (battle->effectStep.time >= 11) {
507 battle->effectStep.time = 0;
508 battle->effectStep.state = 7 + CARD_INFO_STEPS;
509 screen->sprites[battle->record.playCount + 12] = screen->sprites[15];
510 screen->removeSprite(screen, 15);
511 for (j = 0; j < 12; j++) {
512 screen->sprites[j].highlight &= ~1;
513 }
514 }
515 break;
516 case 7 + CARD_INFO_STEPS:
517 done = 1;
518 break;
519 }
520 return done;
521}
522
523/* Empties both hands, on the panels with the decks */
525 battle->sides[0].pile.handCount = 0;
526 battle->sides[1].pile.handCount = 0;
527 screen->setPanelValue(screen, 0, CARD_PANEL_HAND, battle->sides[0].pile.handCount);
528 screen->setPanelValue(screen, 1, CARD_PANEL_HAND, battle->sides[1].pile.handCount);
529 screen->setPanelValue(screen, 0, CARD_PANEL_DECK, battle->sides[0].pile.deckCount);
530 screen->setPanelValue(screen, 1, CARD_PANEL_DECK, battle->sides[1].pile.deckCount);
531 battle->effectStep.choice = 0;
532 battle->effectStep.nextState = 1;
533}
534
535/* Deals six cards from each side's deck into its hand and puts them on the
536 table, face down */
538 s32 side;
539 s32 i;
540 s32 j;
541
542 battle->effectStep.time = 0;
543 battle->effectStep.vars[0] = 0;
544 battle->effectStep.vars[3] = 0;
545 battle->effectStep.vars[1] = battle->sides[0].pile.deckCount;
546 battle->effectStep.vars[2] = battle->sides[1].pile.deckCount;
547 for (side = 0; side < 2; side++) {
548 for (j = 0; j < 6; j++) {
549 battle->sides[side].pile.hand[j] = battle->sides[side].pile.deck[battle->sides[side].pile.deckTop];
550 battle->sides[side].pile.handCount++;
551 battle->sides[side].pile.deckTop++;
552 battle->sides[side].pile.deckCount--;
553 }
554 }
555 for (i = 0; i < 6; i++) {
556#if PAL_VIDEO
558#else
559 screen->addSprite(screen, i, 0x16000, 0x9000);
560#endif
561 screen->setSpriteCard(screen, i, battle->sides[0].pile.hand[i]);
562 screen->sprites[i].visible = 2;
563 screen->sprites[i].scaleY = 0;
564 screen->sprites[i].scaleX = 0;
565 }
566 for (i = 0; i < 6; i++) {
567#if PAL_VIDEO
569#else
570 screen->addSprite(screen, i + 6, 0x16000, 0x3200);
571#endif
572 screen->setSpriteCard(screen, i + 6, battle->sides[1].pile.hand[i]);
573 screen->sprites[i + 6].visible = 2;
574 screen->sprites[i + 6].scaleY = 0;
575 screen->sprites[i + 6].scaleX = 0;
576 }
577}
578
579/* Deals the next card of each side to its slot, and counts it off the deck
580 on the panels */
581static inline void dealNextCards(CardBattle *battle, CardScreen *screen) {
582 if (battle->effectStep.vars[0] < 6) {
583#if PAL_VIDEO
585#else
586 screen->startMove(screen, battle->effectStep.vars[0], 20, battle->effectStep.vars[0] * 0x2900 + 0x1800, 0x9000);
587#endif
588 screen->setSpriteScale(screen, battle->effectStep.vars[0], 0x1000, 0x1000);
589#if PAL_VIDEO
590 screen->startMove(screen, battle->effectStep.vars[0] + 6, 20, CARDGAME_slotRowPositions[SHIFT_PAL_SCREEN][2] + battle->effectStep.vars[0] * 0x2900, CARDGAME_slotRowPositions[SHIFT_PAL_SCREEN][3]);
591#else
592 screen->startMove(screen, battle->effectStep.vars[0] + 6, 20, battle->effectStep.vars[0] * 0x2900 + 0x1800, 0x3200);
593#endif
594 screen->setSpriteScale(screen, battle->effectStep.vars[0] + 6, 0x1000, 0x1000);
595 battle->effectStep.vars[0]++;
596 battle->effectStep.vars[1]--;
597 battle->effectStep.vars[2]--;
598 screen->setPanelValue(screen, 0, CARD_PANEL_HAND, battle->effectStep.vars[0]);
599 screen->setPanelValue(screen, 1, CARD_PANEL_HAND, battle->effectStep.vars[0]);
600 screen->setPanelValue(screen, 0, CARD_PANEL_DECK, battle->effectStep.vars[1]);
601 screen->setPanelValue(screen, 1, CARD_PANEL_DECK, battle->effectStep.vars[2]);
602 }
603}
604
605/* Counts the colours of the next card of each side; the cards that add to
606 one blink */
607static inline void countNextColors(CardBattle *battle, CardScreen *screen) {
608 if (battle->effectStep.vars[0] < 6) {
609 if (CARDGAME_addColorCount(battle, screen, 0, battle->sides[0].pile.hand[battle->effectStep.vars[0]])) {
610 screen->startBlink(screen, battle->effectStep.vars[0]);
611 }
612 if (CARDGAME_addColorCount(battle, screen, 1, battle->sides[1].pile.hand[battle->effectStep.vars[0]])) {
613 screen->startBlink(screen, battle->effectStep.vars[0] + 6);
614 }
615 battle->effectStep.vars[0]++;
616 }
617}
618
619/* Starts the state of the battle start effectStep.nextState asks for */
620static inline void startDealState(CardBattle *battle, CardScreen *screen) {
621 switch (battle->effectStep.nextState) {
622 case 1:
623 screen->openPanels(screen);
624 break;
625 case 2:
626 CARDGAME_dealHands(battle, screen);
627 break;
628 case 3:
629 case 4:
630 battle->effectStep.time = 0;
631 battle->effectStep.vars[0] = 0;
632 battle->effectStep.vars[3] = 0;
633 break;
634 case 5:
635 battle->effectStep.time = 0;
636 battle->effectStep.vars[0] = 0;
637 battle->effectStep.vars[3] = 0;
638 screen->closePanels(screen);
639 break;
640 case 6:
641 screen->setPanelFlags(screen, 0x1000);
642 screen->openMessage(screen, 0x21, 0, 1, 1);
643 battle->effectStep.choice = 1;
644 break;
645 case 7:
647 screen->setPanelFlags(screen, 0x2000);
648 screen->openMessage(screen, 0x22, 0, 1, 1);
649 battle->effectStep.choice = 2;
650 break;
651 case 9:
652 battle->effectStep.time = 0;
653 battle->effectStep.vars[0] = 0;
654 battle->effectStep.vars[3] = 0;
655 screen->closePanels(screen);
656 screen->closeMessage(screen);
657 break;
658 case 11:
659 screen->openMessage(screen, battle->prize, 0, 0, 3);
660 break;
661 case 8:
662 case 10:
663 case 12:
664 /* nothing to set up */
665 break;
666 }
667}
668
669/* The start of a card battle: deals six cards to each side (dealNextCards), turns them over and counts their colours (countNextColors) (a deck with fewer than six cards shows a message instead); 1 when it ends */
671 s32 done = 0;
672
673 if (battle->effectStep.nextState != 0) {
674 startDealState(battle, screen);
675 battle->effectStep.state = battle->effectStep.nextState;
676 battle->effectStep.nextState = 0;
677 }
678
679 switch (battle->effectStep.state) {
680 case 1:
681 if (screen->panels[0].state == 2) {
682 if (battle->sides[0].pile.deckCount < 6) {
683 battle->effectStep.nextState = 6;
684 } else if (battle->sides[1].pile.deckCount < 6) {
685 battle->effectStep.nextState = 7;
686 } else {
687 battle->effectStep.nextState = 2;
688 }
689 }
690 break;
691 case 2:
692 if (battle->effectStep.vars[3] >= 7) {
693 dealNextCards(battle, screen);
694 battle->effectStep.vars[3] -= 7;
695 }
696 if (battle->effectStep.time > 60) {
697 battle->effectStep.nextState = 3;
698 }
699 battle->effectStep.time += GFX.funcs.getFrameTime();
700 battle->effectStep.vars[3] += GFX.funcs.getFrameTime();
701 break;
702 case 3:
703 if (battle->effectStep.vars[3] >= 7) {
704 if (battle->effectStep.vars[0] < 6) {
705 screen->startFlip(screen, battle->effectStep.vars[0]);
706 battle->effectStep.vars[0]++;
707 }
708 battle->effectStep.vars[3] -= 7;
709 }
710 if (battle->effectStep.time > 65) {
711 battle->effectStep.nextState = 4;
712 }
713 battle->effectStep.time += GFX.funcs.getFrameTime();
714 battle->effectStep.vars[3] += GFX.funcs.getFrameTime();
715 break;
716 case 4:
717 if (battle->effectStep.vars[3] >= 7) {
718 countNextColors(battle, screen);
719 battle->effectStep.vars[3] -= 7;
720 }
721 if (battle->effectStep.time > 80) {
722 battle->effectStep.nextState = 5;
723 }
724 battle->effectStep.time += GFX.funcs.getFrameTime();
725 battle->effectStep.vars[3] += GFX.funcs.getFrameTime();
726 break;
727 case 5:
728 if (battle->effectStep.vars[3] >= 3) {
729 if (battle->effectStep.vars[0] < 6) {
730 screen->scaleSprite(screen, battle->effectStep.vars[0], 5, 0, 0x1000);
731 screen->scaleSprite(screen, battle->effectStep.vars[0] + 6, 5, 0, 0x1000);
732 battle->effectStep.vars[0]++;
733 }
734 battle->effectStep.vars[3] -= 3;
735 }
736 if (battle->effectStep.time > 40) {
737 battle->effectStep.nextState = 10;
738 }
739 battle->effectStep.time += GFX.funcs.getFrameTime();
740 battle->effectStep.vars[3] += GFX.funcs.getFrameTime();
741 break;
742 case 6:
743 case 7:
744 if (screen->message.state == 2) {
745 battle->effectStep.nextState = 8;
746 }
747 break;
748 case 8:
750 battle->effectStep.nextState = 9;
751 }
752 break;
753 case 9:
754 if (screen->message.state == 0 && screen->panels[0].state == 0) {
755 battle->effectStep.nextState = 10;
756 }
757 break;
758 case 10:
759 if (battle->effectStep.choice == 2) {
760 battle->effectStep.nextState = 11;
761 } else {
762 done = 1;
763 }
764 break;
765 case 11:
766 if (screen->message.state == 2) {
767 battle->effectStep.nextState = 12;
768 }
769 break;
770 case 12:
772 done = 1;
773 }
774 break;
775 }
776 return done;
777}
778
779/* Starts CARDGAME_stepAttack: side's apTotal comes off the other side's hpTotal
780 (down to 0), counted down over its cards out */
781void CARDGAME_startAttack(CardBattle *battle, CardScreen *screen, s32 side) {
782 battle->effectStep.time = 0;
783 battle->effectStep.vars[0] = 0;
784 battle->effectStep.vars[1] = battle->sides[side].pile.apTotal;
785 battle->effectStep.vars[2] = battle->sides[side ^ 1].pile.hpTotal << 8;
786 battle->sides[side ^ 1].pile.hpTotal -= battle->sides[side].pile.apTotal;
787 if (battle->sides[side ^ 1].pile.hpTotal < 0) {
788 battle->sides[side ^ 1].pile.hpTotal = 0;
789 }
790 if (battle->players[side].slotCount != 0) {
791 battle->effectStep.vars[3] = (battle->effectStep.vars[2] - (battle->sides[side ^ 1].pile.hpTotal << 8)) / (battle->players[side].slotCount * 28 - 16);
792 if (battle->effectStep.vars[3] == 0) {
793 battle->effectStep.vars[3] = 1;
794 }
795 } else {
796 battle->effectStep.vars[3] = 1;
797 }
798 battle->effectStep.state = 1;
799}
800
801/* The side's slot cards go over one by one (every 27 frames) while the panels
802 count its attack (CARD_PANEL_AP) and the other side's HP (CARD_PANEL_HP)
803 down; 1 once done */
805 s32 done = 0;
806 s32 other = side ^ 1;
807 s32 index;
808 s32 value;
809#if PAL_VIDEO
810 s32 x;
811#endif
812 s32 i;
813
814 switch (battle->effectStep.state) {
815 case 1:
816 if (battle->effectStep.time % 27 == 0 && battle->effectStep.vars[0] < battle->players[side].slotCount) {
817 index = battle->effectStep.vars[0];
818 if (side != 0) {
819 index += 6;
820 }
821#if PAL_VIDEO
822 x = CARDGAME_slotRowPositions[SHIFT_PAL_SCREEN][0] + (battle->players[other].slotCount - 1) * 0x1480;
823 if (SHIFT_PAL_SCREEN) {
824 screen->startFly(screen, index, 6, x, side != 0 ? 0x6D00 : 0x5500);
825 } else {
826 screen->startFly(screen, index, 6, x, 0x6100);
827 }
828#else
829 screen->startFly(screen, index, 6, (battle->players[other].slotCount - 1) * 0x1480 + 0x1800, 0x6100);
830#endif
831 battle->effectStep.vars[0]++;
832 screen->sprites[index].moving = 1;
833 }
834 if (battle->effectStep.time >= 16) {
835 value = 0;
836 if (battle->effectStep.time < battle->players[side].slotCount * 28) {
837 value = battle->effectStep.vars[1] - (battle->effectStep.vars[1] / (battle->players[side].slotCount * 56 + 1) + 1) * battle->effectStep.time;
838 if (value < 0) {
839 value = 0;
840 }
841 }
842 screen->setPanelValue(screen, side, CARD_PANEL_AP, value);
843 if (battle->effectStep.time < battle->players[side].slotCount * 28) {
844 battle->effectStep.vars[2] -= battle->effectStep.vars[3];
845 if (battle->effectStep.vars[2] < battle->sides[other].pile.hpTotal << 8) {
846 battle->effectStep.vars[2] = battle->sides[other].pile.hpTotal << 8;
847 }
848 } else {
849 battle->effectStep.vars[2] = battle->sides[other].pile.hpTotal << 8;
850 }
851 screen->setPanelValue(screen, other, CARD_PANEL_HP, battle->effectStep.vars[2] >> 8);
852 }
853 if (screen->spriteFlags & 2) {
854 for (i = 0; i < battle->players[other].slotCount; i++) {
855 screen->startJitter(screen, side == 0 ? i + 6 : i);
856 }
857 }
858 battle->effectStep.time++;
859 if (battle->effectStep.time > battle->players[side].slotCount * 28 + 25) {
860 battle->effectStep.state = 2;
861 }
862 break;
863 case 2:
864 done = 1;
865 break;
866 }
867 return done;
868}
869
870/* Starts CARDGAME_stepDiscardAllSlots from side's last slot */
872 battle->effectStep.time = 0;
873 battle->effectStep.vars[0] = battle->players[side].slotCount - 1;
874 battle->effectStep.state = 1;
875}
876
877/* Discards side's slot cards from the last to the first; 1 once done */
879 s32 done = 0;
880
881 switch (battle->effectStep.state) {
882 case 1:
883 if (CARDGAME_stepDiscardSlotCard(battle, screen, side, battle->effectStep.vars[0])) {
884 battle->effectStep.time = 0;
885 if (--battle->effectStep.vars[0] < 0) {
886 battle->effectStep.state = 2;
887 battle->players[side].slotCount = 0;
888 }
889 }
890 break;
891 case 2:
892 done = 1;
893 break;
894 }
895 return done;
896}
897
898/* The value going from FROM to TO in DURATION, at TIME, never past TO */
899s32 CARDGAME_interpolate(s32 to, s32 from, s32 duration, s32 time) {
900 s32 delta = to - from;
901 s32 inRange;
902
903 if (time == duration || from == to) {
904 return to;
905 }
906 from += delta * time / duration;
907 if (delta > 0) {
908 inRange = from < to;
909 } else {
910 inRange = from > to;
911 }
912 if (!inRange) {
913 from = to;
914 }
915 return from;
916}
917
918/* Shows the kept card (keptCard) as sprite 17 for CARDGAME_stepSwap */
920 screen->addSprite(screen, 0x11, 0x8300, 0x6100);
921 screen->setSpriteCard(screen, 0x11, battle->keptCard - 1);
922 screen->sprites[0x11].scaleX = 0;
923 screen->scaleSprite(screen, 0x11, 10, 0x1000, 0x1000);
924 battle->effectStep.state = 1;
925}
926
927/* Swaps the two sides' pile apTotal and hpTotal, counting the panels' ap and hp over to each other, then shows message 0x2D until cross or triangle; 1 once done */
929 s32 done = 0;
930 s32 ap;
931 s32 hp;
932
933 switch (battle->effectStep.state) {
934 case 1:
935 if (screen->sprites[0x11].state == 1) {
936 screen->startBlink(screen, 0x11);
937 battle->effectStep.state = 2;
938 }
939 break;
940 case 2:
941 if (screen->sprites[0x11].state == 1) {
942 battle->effectStep.state = 3;
943 battle->effectStep.time = 0;
944 }
945 break;
946 case 3:
947 battle->effectStep.time += GFX.funcs.getFrameTime();
948 if (battle->effectStep.time < 15) {
949 screen->setPanelValue(screen, 0, CARD_PANEL_AP, CARDGAME_interpolate(battle->sides[1].pile.apTotal, battle->sides[0].pile.apTotal, 15, battle->effectStep.time));
950 screen->setPanelValue(screen, 0, CARD_PANEL_HP, CARDGAME_interpolate(battle->sides[1].pile.hpTotal, battle->sides[0].pile.hpTotal, 15, battle->effectStep.time));
951 screen->setPanelValue(screen, 1, CARD_PANEL_AP, CARDGAME_interpolate(battle->sides[0].pile.apTotal, battle->sides[1].pile.apTotal, 15, battle->effectStep.time));
952 screen->setPanelValue(screen, 1, CARD_PANEL_HP, CARDGAME_interpolate(battle->sides[0].pile.hpTotal, battle->sides[1].pile.hpTotal, 15, battle->effectStep.time));
953 } else {
954 ap = battle->sides[0].pile.apTotal;
955 battle->sides[0].pile.apTotal = battle->sides[1].pile.apTotal;
956 battle->sides[1].pile.apTotal = ap;
957 hp = battle->sides[0].pile.hpTotal;
958 battle->sides[0].pile.hpTotal = battle->sides[1].pile.hpTotal;
959 battle->sides[1].pile.hpTotal = hp;
960 screen->setPanelValue(screen, 0, CARD_PANEL_AP, battle->sides[0].pile.apTotal);
961 screen->setPanelValue(screen, 0, CARD_PANEL_HP, battle->sides[0].pile.hpTotal);
962 screen->setPanelValue(screen, 1, CARD_PANEL_AP, battle->sides[1].pile.apTotal);
963 screen->setPanelValue(screen, 1, CARD_PANEL_HP, battle->sides[1].pile.hpTotal);
964 screen->scaleSprite(screen, 0x11, 10, 0, 0x1000);
965 battle->effectStep.state = 4;
966 }
967 break;
968 case 4:
969 if (screen->sprites[0x11].state == 1) {
970 battle->effectStep.state = 5;
971 screen->openMessage(screen, 0x2D, 0, 0, 1);
972 }
973 break;
974 case 5:
975 if (screen->message.state == 2) {
976 battle->effectStep.state = 6;
977 }
978 break;
979 case 6:
981 battle->effectStep.state = 7;
982 screen->closeMessage(screen);
983 }
984 break;
985 case 7:
986 if (screen->message.state == 0) {
987 battle->effectStep.state = 8;
988 }
989 break;
990 case 8:
991 done = 1;
992 break;
993 }
994 return done;
995}
996
997/* Adds up the marked slots' ap and hp (at most 99, 20 more for four or more slots) and shows them on sprite 0x11 with card effectStep.vars[4], looked for among the card list's last 100 cards */
998void CARDGAME_showSlotTotal(CardBattle *battle, CardScreen *screen, s32 side) {
999 s32 i;
1000 s32 card;
1001 s32 slot;
1002 s32 count = 0;
1003 s32 index;
1004 s32 base;
1005
1006 battle->effectStep.vars[1] = 0;
1007 battle->effectStep.vars[2] = 0;
1008 for (i = 0; i < battle->players[side].slotCount; i++) {
1009 if (battle->effectStep.eligible[i] != 0) {
1010 battle->effectStep.vars[1] += battle->players[side].slots[i].ap;
1011 if (battle->effectStep.vars[1] >= 100) {
1012 battle->effectStep.vars[1] = 99;
1013 }
1014 battle->effectStep.vars[2] += battle->players[side].slots[i].hp;
1015 if (battle->effectStep.vars[2] >= 100) {
1016 battle->effectStep.vars[2] = 99;
1017 }
1018 count++;
1019 }
1020 }
1021 if (count >= 4) {
1022 battle->effectStep.vars[1] += 20;
1023 if (battle->effectStep.vars[1] >= 100) {
1024 battle->effectStep.vars[1] = 99;
1025 }
1026 battle->effectStep.vars[2] += 20;
1027 if (battle->effectStep.vars[2] >= 100) {
1028 battle->effectStep.vars[2] = 99;
1029 }
1030 }
1031 screen->addSprite(screen, 0x11, 0x8300, 0x6100);
1032 index = 0;
1033 for (card = 89; card < battle->cardCount; card++) {
1034 if (battle->cards[card] == battle->effectStep.vars[4] - 1) {
1035 index = card;
1036 break;
1037 }
1038 }
1039 if (index == 0) {
1040 index = 87;
1041 battle->effectStep.vars[4] = 0x13B;
1042 }
1043 screen->setSpriteCard(screen, 0x11, index);
1044 screen->sprites[0x11].color = 5;
1045 screen->sprites[0x11].ap = battle->effectStep.vars[1];
1046 screen->sprites[0x11].hp = battle->effectStep.vars[2];
1047 base = 0;
1048 if (side != 0) {
1049 base = 6;
1050 }
1051 for (slot = 0; slot < battle->players[side].slotCount; slot++) {
1052 if (battle->effectStep.eligible[slot] != 0) {
1053 screen->sprites[base + slot].highlight |= 4;
1054 }
1055 }
1056 screen->sprites[0x11].scaleX = 0;
1057 battle->effectStep.time = 0;
1058 battle->effectStep.state = 1;
1059}
1060
1061/* Takes the marked slots' sprites away, shows card effectStep.vars[4] in window 2 for 90 frames (or until cross or triangle), then adds effectStep.vars[1] and effectStep.vars[2] to the side's pile apTotal and hpTotal, counting the panel values up; 1 once done */
1063 s32 done = 0;
1064 s32 base;
1065 s32 i;
1066 s32 first;
1067 s32 j;
1068
1069 switch (battle->effectStep.state) {
1070 case 1:
1071 battle->effectStep.time += GFX.funcs.getFrameTime();
1072 if (battle->effectStep.time >= 21) {
1073 battle->effectStep.state = 2;
1074 base = 0;
1075 if (side != 0) {
1076 base = 6;
1077 }
1078 for (i = 0; i < battle->players[side].slotCount; i++) {
1079 if (battle->effectStep.eligible[i] != 0) {
1080 screen->startBlink(screen, base + i);
1081 battle->effectStep.vars[3] = base + i;
1082 }
1083 }
1084 }
1085 break;
1086 case 2:
1087 if (screen->sprites[battle->effectStep.vars[3]].state == 1) {
1088 screen->scaleSprite(screen, 0x11, 10, 0x1000, 0x1000);
1089 battle->effectStep.state = 3;
1090 first = 0;
1091 if (side != 0) {
1092 first = 6;
1093 }
1094 for (j = 0; j < battle->players[side].slotCount; j++) {
1095 if (battle->effectStep.eligible[j] != 0) {
1096 screen->sprites[first + j].highlight &= ~4;
1097 }
1098 }
1099 }
1100 break;
1101 case 3:
1102 if (screen->sprites[0x11].state == 1) {
1103 battle->effectStep.state = 4;
1104#if PAL_VIDEO
1106#else
1107 screen->openWindow(screen, 2, 1, battle->effectStep.vars[4], CARDGAME_cardWindowPositions[0][side][0], CARDGAME_cardWindowPositions[0][side][1]);
1108#endif
1109 }
1110 break;
1111 case 4:
1112 if (screen->windows[2].state == 2) {
1113 battle->effectStep.state = 5;
1114 battle->effectStep.time = 90;
1115 }
1116 break;
1117 case 5:
1118 battle->effectStep.time -= GFX.funcs.getFrameTime();
1119 if (battle->effectStep.time <= 0 || PAD_PRESSED(PAD_CROSS) || PAD_PRESSED(PAD_TRIANGLE)) {
1120 battle->effectStep.state = 6;
1121 screen->closeWindow(screen, 2);
1122 }
1123 break;
1124 case 6:
1125 if (screen->windows[2].state == 0) {
1126 screen->startBlink(screen, 0x11);
1127 battle->effectStep.state = 7;
1128 }
1129 break;
1130 case 7:
1131 if (screen->sprites[0x11].state == 1) {
1132 battle->effectStep.state = 8;
1133 battle->effectStep.time = 0;
1134 }
1135 break;
1136 case 8:
1137 battle->effectStep.time += GFX.funcs.getFrameTime();
1138 if (battle->effectStep.time < 20) {
1139 screen->setPanelValue(screen, side, CARD_PANEL_AP, CARDGAME_interpolate(battle->sides[side].pile.apTotal + battle->effectStep.vars[1], battle->sides[side].pile.apTotal, 20, battle->effectStep.time));
1140 screen->setPanelValue(screen, side, CARD_PANEL_HP, CARDGAME_interpolate(battle->sides[side].pile.hpTotal + battle->effectStep.vars[2], battle->sides[side].pile.hpTotal, 20, battle->effectStep.time));
1141 } else {
1142 battle->sides[side].pile.apTotal += battle->effectStep.vars[1];
1143 battle->sides[side].pile.hpTotal += battle->effectStep.vars[2];
1144 screen->setPanelValue(screen, side, CARD_PANEL_AP, battle->sides[side].pile.apTotal);
1145 screen->setPanelValue(screen, side, CARD_PANEL_HP, battle->sides[side].pile.hpTotal);
1146 screen->scaleSprite(screen, 0x11, 10, 0, 0x1000);
1147 battle->effectStep.state = 9;
1148 }
1149 break;
1150 case 9:
1151 if (screen->sprites[0x11].state == 1) {
1152 battle->effectStep.state = 10;
1153 }
1154 break;
1155 case 10:
1156 done = 1;
1157 break;
1158 }
1159 return done;
1160}
1161
1162/* Starts CARDGAME_stepTotals */
1164 battle->effectStep.state = 1;
1165 battle->effectStep.time = 0;
1166 battle->effectStep.vars[0] = 0;
1167 battle->effectStep.vars[1] = 0;
1168 battle->effectStep.vars[2] = 0;
1169 battle->effectStep.vars[3] = 0;
1170}
1171
1172/* Adds up both players' slots' ap and hp and counts the panels' ap and hp over to the totals, which become the sides' pile apTotal and hpTotal; 1 once done */
1174 s32 done = 0;
1175 s32 i;
1176
1177 switch (battle->effectStep.state) {
1178 case 1:
1179 for (i = 0; i < battle->players[0].slotCount; i++) {
1180 battle->effectStep.vars[0] += battle->players[0].slots[i].ap;
1181 battle->effectStep.vars[1] += battle->players[0].slots[i].hp;
1182 }
1183 for (i = 0; i < battle->players[1].slotCount; i++) {
1184 battle->effectStep.vars[2] += battle->players[1].slots[i].ap;
1185 battle->effectStep.vars[3] += battle->players[1].slots[i].hp;
1186 }
1187 if (battle->sides[0].pile.apTotal == battle->effectStep.vars[0] && battle->sides[0].pile.hpTotal == battle->effectStep.vars[1] &&
1188 battle->sides[1].pile.apTotal == battle->effectStep.vars[2] && battle->sides[1].pile.hpTotal == battle->effectStep.vars[3]) {
1189 battle->effectStep.state = 4;
1190 } else {
1191 battle->effectStep.time = 0;
1192 battle->effectStep.state = 2;
1193 }
1194 break;
1195 case 2:
1196 battle->effectStep.time += GFX.funcs.getFrameTime();
1197 if (battle->effectStep.time < 15) {
1199 screen->setPanelValue(screen, 0, CARD_PANEL_AP, CARDGAME_interpolate(battle->effectStep.vars[0], battle->sides[0].pile.apTotal, 15, battle->effectStep.time));
1200 screen->setPanelValue(screen, 0, CARD_PANEL_HP, CARDGAME_interpolate(battle->effectStep.vars[1], battle->sides[0].pile.hpTotal, 15, battle->effectStep.time));
1201 screen->setPanelValue(screen, 1, CARD_PANEL_AP, CARDGAME_interpolate(battle->effectStep.vars[2], battle->sides[1].pile.apTotal, 15, battle->effectStep.time));
1202 screen->setPanelValue(screen, 1, CARD_PANEL_HP, CARDGAME_interpolate(battle->effectStep.vars[3], battle->sides[1].pile.hpTotal, 15, battle->effectStep.time));
1203 } else {
1204 battle->sides[0].pile.apTotal = battle->effectStep.vars[0];
1205 battle->sides[0].pile.hpTotal = battle->effectStep.vars[1];
1206 battle->sides[1].pile.apTotal = battle->effectStep.vars[2];
1207 battle->sides[1].pile.hpTotal = battle->effectStep.vars[3];
1208 screen->setPanelValue(screen, 0, CARD_PANEL_AP, battle->sides[0].pile.apTotal);
1209 screen->setPanelValue(screen, 0, CARD_PANEL_HP, battle->sides[0].pile.hpTotal);
1210 screen->setPanelValue(screen, 1, CARD_PANEL_AP, battle->sides[1].pile.apTotal);
1211 screen->setPanelValue(screen, 1, CARD_PANEL_HP, battle->sides[1].pile.hpTotal);
1212 battle->effectStep.state = 3;
1213 }
1214 break;
1215 case 3:
1216 battle->effectStep.state = 4;
1217 break;
1218 case 4:
1219 done = 1;
1220 break;
1221 }
1222 return done;
1223}
1224
1225/* Starts CARDGAME_stepRoundEnd */
1227 battle->effectStep.state = 1;
1228 battle->effectStep.time = 0;
1229 battle->effectStep.vars[0] = 0;
1230 battle->effectStep.vars[1] = 0;
1231 battle->effectStep.vars[2] = 0;
1232 battle->effectStep.vars[3] = 0;
1233 battle->effectStep.vars[4] = 0;
1234}
1235
1236/* Takes the side's slots away one by one, then moves both sides' hands back into their decks one at a time (the panels' hand and deck) and shows window 5 until cross or triangle; 1 once done */
1238 s32 done = 0;
1239 s32 index;
1240 s32 counting;
1241
1242 switch (battle->effectStep.state) {
1243 case 1:
1244 if (battle->effectStep.vars[4] >= 3) {
1245 if (battle->effectStep.vars[0] < battle->players[side].slotCount) {
1246 index = battle->effectStep.vars[0];
1247 if (side != 0) {
1248 index += 6;
1249 }
1250 screen->scaleSprite(screen, index, 4, 0, 0x1000);
1251 CARDGAME_discardSlotCard(battle, screen, side, battle->effectStep.vars[0]);
1252 battle->effectStep.vars[0]++;
1253 }
1254 battle->effectStep.vars[4] -= 3;
1255 }
1256 battle->effectStep.time += GFX.funcs.getFrameTime();
1257 battle->effectStep.vars[4] += GFX.funcs.getFrameTime();
1258 if (battle->effectStep.time >= 61) {
1259 battle->players[side].slotCount = 0;
1260 battle->effectStep.time = 0;
1261 battle->effectStep.state = 2;
1262 battle->effectStep.vars[4] = 0;
1263 battle->effectStep.vars[0] = battle->sides[0].pile.handCount;
1264 battle->effectStep.vars[1] = battle->sides[0].pile.deckCount;
1265 battle->effectStep.vars[2] = battle->sides[1].pile.handCount;
1266 battle->effectStep.vars[3] = battle->sides[1].pile.deckCount;
1267 }
1268 break;
1269 case 2:
1270 battle->effectStep.time += GFX.funcs.getFrameTime();
1271 battle->effectStep.vars[4] += GFX.funcs.getFrameTime();
1272 if (battle->effectStep.vars[4] >= 3) {
1273 counting = 0;
1274 if (battle->effectStep.vars[0] > 0) {
1275 counting = 1;
1276 battle->effectStep.vars[0]--;
1277 battle->effectStep.vars[1]++;
1278 }
1279 if (battle->effectStep.vars[2] > 0) {
1280 counting = 1;
1281 battle->effectStep.vars[2]--;
1282 battle->effectStep.vars[3]++;
1283 }
1284 if (!counting) {
1285 battle->effectStep.state = 4;
1286 screen->openWindow(screen, 5, 5, 20, 0, 110);
1287 } else {
1289 }
1290 screen->setPanelValue(screen, 0, CARD_PANEL_HAND, battle->effectStep.vars[0]);
1291 screen->setPanelValue(screen, 0, CARD_PANEL_DECK, battle->effectStep.vars[1]);
1292 screen->setPanelValue(screen, 1, CARD_PANEL_HAND, battle->effectStep.vars[2]);
1293 screen->setPanelValue(screen, 1, CARD_PANEL_DECK, battle->effectStep.vars[3]);
1294 battle->effectStep.vars[4] -= 3;
1295 }
1296 break;
1297 case 3:
1298 if (screen->windows[5].state == 2) {
1299 battle->effectStep.state = 4;
1300 }
1301 break;
1302 case 4:
1304 battle->effectStep.state = 5;
1305 screen->closeWindow(screen, 5);
1306 }
1307 break;
1308 case 5:
1309 if (screen->windows[5].state == 0) {
1310 battle->effectStep.state = 6;
1311 screen->closePanels(screen);
1312 }
1313 break;
1314 case 6:
1315 if (screen->panels[0].state == 0) {
1316 battle->effectStep.state = 7;
1317 }
1318 break;
1319 case 7:
1320 done = 1;
1321 break;
1322 }
1323 return done;
1324}
1325
CARDGAME.PRO: the card battle (mode 0x700).
void initCardDrawer(CardDrawer *obj)
Clears a card drawer, gives it its methods and binds it.
void CARDGAME_setCountingCardValues(CardBattle *battle, CardSlot *slot, s32 side, s32 pass)
Sets the values of a slot that holds the pass-th card of CARDGAME_countingCards from the battle's cou...
Definition battle.c:1398
#define CARD_ANIM_UNDIM_ALL
CardAnim.dimAll.
Definition battle.h:189
#define CARD_INFO_STEPS
The steps CARDGAME_stepPlayCard has before its card goes off: the European and Japanese versions show...
Definition battle.h:297
@ CARD_ANIM_SHOW_SLOTS
Definition battle.h:168
@ CARD_ANIM_NONE
Definition battle.h:167
s32 CARDGAME_recordCardPositions[][2]
where card 15 goes, by CardRecord.playCount
Definition cardgame_2.c:32
s16 CARDGAME_cardWindowPositions[2][2][2]
two positions, then the same moved for SHIFT_PAL_SCREEN
Definition cardgame_2.c:33
s32 CARDGAME_slotRowPositions[2][4]
sprite positions, by SHIFT_PAL_SCREEN
Definition cardgame_3.c:14
signed int s32
Definition common.h:11
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
s32 SHIFT_PAL_SCREEN
moves both display areas 0x18 lines down
Definition eu_settings.c:15
#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
s32 CARDGAME_openStepWindows(CardBattle *battle, CardScreen *screen, s32 layout, s32 text, s32 time, s32 step)
Opens the windows of the step CARDGAME_windowSteps[step] once its time is past; the next step.
Definition questions.c:15
void CARDGAME_startAttack(CardBattle *battle, CardScreen *screen, s32 side)
Starts CARDGAME_stepAttack: side's apTotal comes off the other side's hpTotal (down to 0),...
Definition round.c:781
static void countNextColors(CardBattle *battle, CardScreen *screen)
Counts the colours of the next card of each side; the cards that add to one blink.
Definition round.c:607
void CARDGAME_takeHandCard(CardBattle *battle, CardScreen *screen, s32 side)
Takes the card the last record names out of the side's hand into its next slot and shows it.
Definition round.c:151
s32 CARDGAME_stepSwap(CardBattle *battle, CardScreen *screen)
Swaps the two sides' pile apTotal and hpTotal, counting the panels' ap and hp over to each other,...
Definition round.c:928
void CARDGAME_startTotals(CardBattle *battle, CardScreen *screen)
Starts CARDGAME_stepTotals.
Definition round.c:1163
void CARDGAME_putSlotCard(CardBattle *battle, CardScreen *screen, s32 side, s32 card)
Puts a card in the side's next slot (owned by side 2) and shows it.
Definition round.c:120
s32 CARDGAME_stepSlotSweep(CardBattle *battle, CardScreen *screen, s32 which)
Goes over the marked slots one by one, discarding their cards (which 0) or returning them to the hand...
Definition round.c:16
void CARDGAME_markRecordHits(CardBattle *battle, CardScreen *screen, s32 side, s32 index)
Marks (marks) the plays whose effect reaches sprite index, by their target (targetKind): a side,...
Definition round.c:60
s32 CARDGAME_interpolate(s32 to, s32 from, s32 duration, s32 time)
The value going from FROM to TO in DURATION, at TIME, never past TO.
Definition round.c:899
static void startDealState(CardBattle *battle, CardScreen *screen)
Starts the state of the battle start effectStep.nextState asks for.
Definition round.c:620
s32 CARDGAME_stepSlotTotal(CardBattle *battle, CardScreen *screen, s32 side)
Takes the marked slots' sprites away, shows card effectStep.vars[4] in window 2 for 90 frames (or unt...
Definition round.c:1062
s32 CARDGAME_stepAttack(CardBattle *battle, CardScreen *screen, s32 side)
The side's slot cards go over one by one (every 27 frames) while the panels count its attack (CARD_PA...
Definition round.c:804
void CARDGAME_clearHands(CardBattle *battle, CardScreen *screen)
Empties both hands, on the panels with the decks.
Definition round.c:524
void CARDGAME_copySlotCard(CardBattle *battle, CardScreen *screen, s32 side)
Copies the first marked slot card (effectStep.marked) into the side's next slot.
Definition round.c:245
void CARDGAME_showSlotTotal(CardBattle *battle, CardScreen *screen, s32 side)
Adds up the marked slots' ap and hp (at most 99, 20 more for four or more slots) and shows them on sp...
Definition round.c:998
s32 CARDGAME_stepTotals(CardBattle *battle, CardScreen *screen)
Adds up both players' slots' ap and hp and counts the panels' ap and hp over to the totals,...
Definition round.c:1173
s32 CARDGAME_stepStart(CardBattle *battle, CardScreen *screen)
The start of a card battle: deals six cards to each side (dealNextCards), turns them over and counts ...
Definition round.c:670
s32 CARDGAME_stepDiscardAllSlots(CardBattle *battle, CardScreen *screen, s32 side)
Discards side's slot cards from the last to the first; 1 once done.
Definition round.c:878
void CARDGAME_dealHands(CardBattle *battle, CardScreen *screen)
Deals six cards from each side's deck into its hand and puts them on the table, face down.
Definition round.c:537
void CARDGAME_startPlayCard(CardBattle *battle, CardScreen *screen, s32 side)
Shows the card being played as sprite 15 (opening the panels for side 0) and starts moving it to its ...
Definition round.c:358
s32 CARDGAME_flipSlotCard(CardBattle *battle, CardScreen *screen, s32 side)
Waits effectStep.time frames, then flips the side's next slot card over and moves it into place; 1 on...
Definition round.c:293
void CARDGAME_startDiscardAllSlots(CardBattle *battle, CardScreen *screen, s32 side)
Starts CARDGAME_stepDiscardAllSlots from side's last slot.
Definition round.c:871
s32 CARDGAME_moveSlotCard(CardBattle *battle, CardScreen *screen, s32 side)
Moves the side's next slot card into place; 1 once it is there.
Definition round.c:188
s32 CARDGAME_stepRoundEnd(CardBattle *battle, CardScreen *screen, s32 side)
Takes the side's slots away one by one, then moves both sides' hands back into their decks one at a t...
Definition round.c:1237
void CARDGAME_startSlotSweep(CardBattle *battle, CardScreen *screen)
Starts CARDGAME_stepSlotSweep.
Definition round.c:9
static void dealNextCards(CardBattle *battle, CardScreen *screen)
Deals the next card of each side to its slot, and counts it off the deck on the panels.
Definition round.c:581
void CARDGAME_startRoundEnd(CardBattle *battle, CardScreen *screen)
Starts CARDGAME_stepRoundEnd.
Definition round.c:1226
void CARDGAME_startSwap(CardBattle *battle, CardScreen *screen)
Shows the kept card (keptCard) as sprite 17 for CARDGAME_stepSwap.
Definition round.c:919
s32 CARDGAME_stepPlayCard(CardBattle *battle, CardScreen *screen)
Card 15 goes off and the marked slot cards turn over; it then lands in sprite 12 + CardRecord....
Definition round.c:408
@ CARD_PANEL_HAND
Definition screen.h:200
@ CARD_PANEL_HP
Definition screen.h:203
@ CARD_PANEL_AP
Definition screen.h:202
@ CARD_PANEL_DECK
Definition screen.h:199
s32 CARDGAME_addColorCount(CardBattle *battle, CardScreen *screen, s32 side, s32 card)
Counts a card of the colour it has on a side's panel (at most 99); 1 if it has one.
Definition slot_effects.c:7
s32 CARDGAME_stepDiscardSlotCard(CardBattle *battle, CardScreen *screen, s32 side, s32 index)
Shakes side's slot index away, then CARDGAME_discardSlotCard; 1 once done.
void CARDGAME_discardSlotCard(CardBattle *battle, CardScreen *screen, s32 side, s32 index)
Puts the card of side's slot index on its owner's discards, on the panel.
s32 CARDGAME_stepReturnSlotCard(CardBattle *battle, CardScreen *screen, s32 side, s32 index)
Sends side's slot index off, then CARDGAME_returnSlotCard; 1 once done.
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
#define SOUND_WIN_JINGLE
W_JINGLE: a battle won.
Definition sound.h:48
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
u8 dimmed[40]
by sprite
Definition battle.h:200
The card battle (CARDGAME_createBattle).
Definition battle.h:226
s32 prize
the item the player wins (GAME.items)
Definition battle.h:236
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
void(* addCard)(struct CardBattle *battle, s32 side, s32 card)
Definition battle.h:279
u8 cardCount
in cards
Definition battle.h:229
u8 keptCard
the card CARDGAME_keepLastCard kept, plus one
Definition battle.h:249
u8 slotCount
the slots added so far
Definition battle.h:253
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 hp
Definition gfx.h:175
u8 ap
Definition gfx.h:174
u8 state
1 opening, 2 open, 4 confirmed, 5 closing
Definition screen.h:256
s16 state
Definition screen.h:137
A player's cards in a card battle (CardSide.pile)
Definition battle.h:108
s16 hpTotal
the sum of its slot cards' hp: the higher one wins the round
Definition battle.h:110
s16 deckCount
the cards left in the deck
Definition battle.h:113
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 apTotal
the sum of its slot cards' ap, which comes off the other side's hpTotal
Definition battle.h:109
s16 hand[10]
handCount in use
Definition battle.h:119
s16 card
the index in the battle's card list
Definition battle.h:44
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
One of the two players of a card battle.
Definition battle.h:37
CardSlot slots[8]
Definition battle.h:39
u8 slotCount
Definition battle.h:38
s8 playCount
the plays in use
Definition battle.h:130
u8 turnSide
the side whose turn it is
Definition battle.h:134
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
void(* setSpriteCard)(struct CardScreen *screen, s32 sprite, s32 index)
Definition screen.h:324
void(* openWindow)(struct CardScreen *screen, s32 index, s16 layout, s32 value, s32 x, s32 y)
Definition screen.h:288
s32(* startFly)(struct CardScreen *screen, s32 index, s32 duration, s32 x, s32 y)
Definition screen.h:313
void(* setPanelValue)(struct CardScreen *screen, s32 side, u32 which, s32 value)
Definition screen.h:285
void(* scaleSprite)(struct CardScreen *screen, s32 index, s32 duration, s32 scaleX, s32 scaleY)
Definition screen.h:318
void(* setPanelFlags)(struct CardScreen *screen, s32 bits)
Definition screen.h:291
void(* clearPanelFlags)(struct CardScreen *screen)
Definition screen.h:290
void(* startMove)(struct CardScreen *screen, s32 index, s32 duration, s32 x, s32 y)
Definition screen.h:311
void(* resetPanels)(struct CardScreen *screen)
Definition screen.h:296
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
s32(* removeSprite)(struct CardScreen *screen, s32 index)
Definition screen.h:315
void(* setSpriteScale)(struct CardScreen *screen, s32 index, s32 scaleX, s32 scaleY)
Definition screen.h:317
void(* closePanels)(struct CardScreen *screen)
Definition screen.h:294
s32(* startJitter)(struct CardScreen *screen, s32 index)
Definition screen.h:320
CardWindow windows[6]
Definition screen.h:281
void(* closeMessage)(struct CardScreen *screen)
Definition screen.h:303
s32 spriteFlags
this frame: bit 0 a sprite is animated, bit 1 a flying one landed
Definition screen.h:266
void(* closeWindow)(struct CardScreen *screen, s32 index)
Definition screen.h:289
s32(* startBlink)(struct CardScreen *screen, s32 index)
Definition screen.h:316
s32(* startFlip)(struct CardScreen *screen, s32 index)
Definition screen.h:319
void(* openGauge)(struct CardScreen *screen, s32 index, s16 value)
Definition screen.h:286
s32(* addSprite)(struct CardScreen *screen, s32 index, s32 x, s32 y)
Definition screen.h:314
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
u8 owner
Definition battle.h:26
s16 hp
its hit points, 0 to 99: at 0 it is lost
Definition battle.h:24
s16 hpBonus
and to its hp
Definition battle.h:22
u8 side
Definition battle.h:25
s16 apBonus
what the effects added to its ap
Definition battle.h:21
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
s16 moving
Definition screen.h:177
u8 ap
the values shown, which count towards the slot's
Definition screen.h:188
u8 dimmed
Definition screen.h:194
s16 color
the card's colour, from 0
Definition screen.h:182
u8 order
a played card's place in the record, from 1
Definition screen.h:191
u8 visible
Definition screen.h:190
u8 highlight
bit 0 the cursor, bit 1 picked, bit 2 glowing
Definition screen.h:193
s16 scaleX
Definition screen.h:170
u8 marks[3]
the plays that apply to the card, drawn as marks
Definition screen.h:185
s16 scaleY
Definition screen.h:171
s32 time
a frame count, or the step's own sub-state
Definition battle.h:148
s8 eligible[0x29]
the cards or slots that can be picked
Definition battle.h:154
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
u8 nextState
the state to set up first, if not 0
Definition battle.h:147
s8 marked[40]
the cards or slots picked
Definition battle.h:155
s32 choice
the card, slot or answer chosen; -1 for none
Definition battle.h:151
u8 numbers[3]
two numbers, and whether they are shown
Definition screen.h:242
s16 showCount
Definition screen.h:240
s32 value
by its layout: a string, a card, or points | colour << 4
Definition screen.h:241
s32(* getFrameTime)(void)
Definition gfx.h:32
GfxFuncs funcs
Definition gfx.h:77
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187