Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
card_grid.c
Go to the documentation of this file.
1/* The grid of six cards, which the pack screen and the buy screen turn over
2 to the cards drawn */
3
5
6/* Loads the images of the grid's cards into VRAM, one cell each, up to the first
7 empty one */
9 CardDrawer icon;
10 s32 *cards;
11 s32 i;
12 s32 card;
13
14 initCardDrawer(&icon);
15 icon.setImagePos(0x140, 0x100);
16 icon.setClutPos(0x300, 0x100);
17 cards = grid->cards;
18 for (i = 0; i < 6; i++) {
19 card = *cards;
20 if (card <= 0 || card >= CARD_PACK_IDS) {
21 break;
22 }
23 cards++;
24 icon.setCard(card);
25 icon.setCell(0, i);
26 icon.loadImage();
27 }
28}
29
30/* Turns the grid over to six new cards (grid->setCards): keeps the old ones to
31 draw while the slots turn */
32void STCRDSHP_setCards(CardPackGrid *grid, s32 *cards) {
33 s32 i;
34
35 for (i = 0; i < 6; i++) {
36 grid->prevCards[i] = grid->cards[i];
37 grid->cards[i] = cards[i];
38 }
39 grid->turned = 0;
40 grid->frame = 0;
41 grid->setState(grid, TASK_DONE);
42}
43
45
46/* Draws the cards drawn (or the ones being turned over): each card's image,
47 its numbers or its kind's mark, and its frame. The match depends on the
48 digits' x being written dx + 0x27 + x and on cards++ being in the for. */
49void STCRDSHP_drawCards(CardPackGrid *grid, s32 previous) {
50 SpriteDrawer sprite;
51 CardDrawer drawer;
52 s32 digits[5];
53 s32 *cards;
54 s32 i;
55 s32 j;
56 s32 dx;
57 s32 card;
58 s32 x;
59 s32 y;
60 s32 n;
61 s32 col;
62 s32 row;
63
64 initSpriteDrawer(&sprite);
65 sprite.setLayerId(grid->layer, grid->depth);
66 sprite.setTexture(0x280, 0);
67 initCardDrawer(&drawer);
68 drawer.setImagePos(0x140, 0x100);
69 drawer.setClutPos(0x300, 0x100);
70 drawer.setLayer(grid->layer, grid->depth);
71 if (previous) {
72 cards = grid->prevCards;
73 } else {
74 cards = grid->cards;
75 }
76 for (i = 0; i < grid->shown; i++, cards++) {
77 card = *cards;
78 if (card <= 0 || card >= CARD_PACK_IDS) {
79 break;
80 }
81 col = i % 6;
82 row = i / 6;
83 x = col * 0x2A;
84 y = row * 0x36;
85 drawer.setCard(card);
86 drawer.setCell(0, i);
87 drawer.draw(x + 0x27, y + 0x46);
88 if (drawer.getKind() != 0) {
89 sprite.draw(FILE_CACHE.getEntry(FILE_CARDSHOP_SPRITES << 16), 0x1D, x + 0x27, y + 0x65);
90 } else {
91 n = drawer.card->ap;
92 j = n / 10;
93 if (j != 0) {
94 digits[0] = j + 0x1E;
95 } else {
96 digits[0] = 0;
97 }
98 j = n % 10;
99 digits[1] = j + 0x1E;
100 digits[2] = 0x1C;
101 for (j = dx = 0; j < 3; j++, dx += 7) {
102 if (digits[j] != 0) {
103 sprite.draw(FILE_CACHE.getEntry(FILE_CARDSHOP_SPRITES << 16), digits[j], dx + 0x27 + x, y + 0x65);
104 }
105 }
106 n = drawer.card->hp;
107 j = n / 10;
108 if (j != 0) {
109 digits[0] = j + 0x1E;
110 } else {
111 digits[0] = 0;
112 }
113 j = n % 10;
114 digits[1] = j + 0x1E;
115 for (j = dx = 0; j < 2; j++, dx += 7) {
116 if (digits[j] != 0) {
117 sprite.draw(FILE_CACHE.getEntry(FILE_CARDSHOP_SPRITES << 16), digits[j], dx + 0x3A + x, y + 0x65);
118 }
119 }
120 }
121 sprite.draw(FILE_CACHE.getEntry(FILE_CARDSHOP_SPRITES << 16), drawer.card->color - 1, x + 0x23, y + 0x44);
122 }
123}
124
125/* Draws the cover over each slot turned so far, in the palette of the turn's
126 current frame */
128 SpriteDrawer sprite;
129 s32 i;
130 s32 col;
131 s32 row;
132
133 initSpriteDrawer(&sprite);
134 sprite.setLayerId(grid->layer, grid->depth - 1);
135 sprite.setTexture(0x280, 0);
136 for (i = 0; i < grid->turned; i++) {
137 col = i % 6;
138 row = i / 6;
139 sprite.setClutRow(grid->frame);
140 sprite.draw(FILE_CACHE.getEntry(FILE_CARDSHOP_SPRITES << 16), 6, col * 42 + 0x23, row * 54 + 0x44);
141 }
142}
143
145
146/* The grid's task: covers its slots one by one (every 2 frames) above the old
147 cards, loads the new ones' images and steps the covers' palette over 11
148 frames above them, then shows them until they are hidden */
150 switch (grid->state) {
151 case TASK_INIT:
152 default:
153 grid->nextState(grid);
154 STCRDSHP_setCards(grid, grid->cards);
155 break;
156 case TASK_RUN:
158 STCRDSHP_drawCards(grid, 0);
159 break;
160 case TASK_DONE:
161 switch (grid->substate) {
162 case 0:
163 default:
164 if (++grid->turned < 6) {
165 grid->nextSubstate(grid);
166 grid->counter = GFX.funcs.getTime();
167 } else {
168 grid->turned = 6;
169 grid->substate = 2;
170 }
172 break;
173 case 1:
174 if (GFX.funcs.getTime() - grid->counter >= 2) {
175 grid->substate = grid->step;
176 }
177 break;
178 case 2:
179 STCRDSHP_loadIcons(grid);
180 grid->shown = 6;
181 grid->time = GFX.funcs.getTime();
182 grid->nextSubstate(grid);
184 break;
185 case 3:
186 if (GFX.funcs.getTime() - grid->time >= 2) {
187 grid->time = GFX.funcs.getTime();
188 if (++grid->frame >= 11) {
189 grid->state = TASK_RUN;
190 }
191 }
192 break;
193 }
195 if (grid->substate < 3) {
196 STCRDSHP_drawCards(grid, 1);
197 } else {
198 STCRDSHP_drawCards(grid, 0);
199 }
200 break;
201 case TASK_KILL:
202 break;
203 }
204}
205
206/* Creates the grid of six cards, copying the cards given. The match depends
207 on cards++ being in the for. */
210 s32 i;
211
213 grid->hide = STCRDSHP_hideCards;
214 grid->layer = SCREEN_LAYER;
215 grid->depth = 6;
216 grid->owner = owner;
217 for (i = 0; i < 6; i++, cards++) {
218 grid->cards[i] = *cards;
219 }
220 return grid;
221}
void initCardDrawer(CardDrawer *obj)
Clears a card drawer, gives it its methods and binds it.
void STCRDSHP_setCards(CardPackGrid *grid, s32 *cards)
Turns the grid over to six new cards (grid->setCards): keeps the old ones to draw while the slots tur...
Definition card_grid.c:32
CardPackGrid * STCRDSHP_createGrid(CardShop *owner, s32 *cards)
Creates the grid of six cards, copying the cards given.
Definition card_grid.c:208
void STCRDSHP_loadIcons(CardPackGrid *grid)
Loads the images of the grid's cards into VRAM, one cell each, up to the first empty one.
Definition card_grid.c:8
void STCRDSHP_drawCards(CardPackGrid *grid, s32 previous)
Draws the cards drawn (or the ones being turned over): each card's image, its numbers or its kind's m...
Definition card_grid.c:49
void STCRDSHP_drawTurningSlots(CardPackGrid *grid)
Draws the cover over each slot turned so far, in the palette of the turn's current frame.
Definition card_grid.c:127
void STCRDSHP_updateGrid(CardPackGrid *grid)
The grid's task: covers its slots one by one (every 2 frames) above the old cards,...
Definition card_grid.c:149
STCRDSHP.PRO: the card packs (mode 0x1300).
#define CARD_PACK_IDS
The cards are drawn from 315 ids (1-314)
Definition card_packs.h:22
#define FILE_CARDSHOP_SPRITES
The sprite sheet of the screen, the shop's textures and the card data (five files,...
Definition card_packs.h:34
void STCRDSHP_updateHiding(CardPackGrid *grid)
void STCRDSHP_hideCards(CardPackGrid *grid)
signed int s32
Definition common.h:11
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
#define TASK_RUN
Definition task.h:35
#define TASK_KILL
Definition task.h:37
#define TASK_INIT
Tasks: every game object is a task, a heap block that starts with this header and is updated once per...
Definition task.h:34
#define TASK_DONE
Definition task.h:36
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
#define SCREEN_LAYER
The layer over the whole screen that most modes create first and draw their menus on (FIELDSTG and ST...
Definition gfx.h:45
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_MENU_CONFIRM
SYSTEM07.
Definition sound.h:44
#define SOUND_CARD_001
Definition sound.h:61
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
Draws the cards' images (CardImage), from files 0x7E7-0x7EB.
Definition gfx.h:193
void(* setCard)()
(id)
Definition gfx.h:205
void(* setClutPos)()
(x, y)
Definition gfx.h:210
void(* setCell)()
(x, y)
Definition gfx.h:211
void(* draw)()
(x, y)
Definition gfx.h:207
s32(* getKind)(void)
Definition gfx.h:214
void(* setImagePos)()
(x, y)
Definition gfx.h:209
void(* loadImage)()
Definition gfx.h:206
void(* setLayer)()
(id, depth)
Definition gfx.h:208
CardImage * card
Definition gfx.h:194
u8 hp
Definition gfx.h:175
u8 color
from 1
Definition gfx.h:173
u8 ap
Definition gfx.h:174
Draws the six cards drawn from a pack, and turns them over.
Definition card_packs.h:40
s32 cards[6]
Definition card_packs.h:53
void(* nextSubstate)(struct CardPackGrid *task)
Definition card_packs.h:41
s32 turned
slots turned so far
Definition card_packs.h:48
void(* setCards)(struct CardPackGrid *grid, s32 *cards)
Definition card_packs.h:56
s32 prevCards[6]
the cards being turned
Definition card_packs.h:54
struct CardShop * owner
never read
Definition card_packs.h:42
s32 shown
cards drawn
Definition card_packs.h:47
void(* setState)(struct CardPackGrid *task, s32 state)
Definition card_packs.h:41
void(* nextState)(struct CardPackGrid *task)
Definition card_packs.h:41
void(* hide)(struct CardPackGrid *grid)
Definition card_packs.h:57
The card shop's main task (STCRDSHP_createShop): buy cards, open packs or edit the decks.
Definition card_packs.h:81
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187
Draws sprites from a sprite sheet (such as file 0x277, the menu graphics): a sheet has a table of fra...
Definition gfx.h:223
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
void(* setClutRow)()
(row)
Definition gfx.h:247
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setTexture)()
(x, y)
Definition gfx.h:242
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105