forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathberry_blender.c
3927 lines (3531 loc) · 121 KB
/
berry_blender.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "global.h"
#include "overworld.h"
#include "berry_blender.h"
#include "bg.h"
#include "window.h"
#include "task.h"
#include "sprite.h"
#include "sound.h"
#include "m4a.h"
#include "bg.h"
#include "palette.h"
#include "decompress.h"
#include "malloc.h"
#include "gpu_regs.h"
#include "text.h"
#include "text_window.h"
#include "event_data.h"
#include "main.h"
#include "link.h"
#include "link_rfu.h"
#include "item_menu_icons.h"
#include "berry.h"
#include "item.h"
#include "string_util.h"
#include "international_string_util.h"
#include "random.h"
#include "menu.h"
#include "pokeblock.h"
#include "trig.h"
#include "tv.h"
#include "item_menu.h"
#include "battle_records.h"
#include "graphics.h"
#include "new_game.h"
#include "save.h"
#include "strings.h"
#include "constants/game_stat.h"
#include "constants/items.h"
#include "constants/rgb.h"
#include "constants/songs.h"
enum {
SCORE_BEST,
SCORE_GOOD,
SCORE_MISS,
NUM_SCORE_TYPES,
};
// Redundant with the above. Reversed
enum {
PROXIMITY_MISS,
PROXIMITY_GOOD,
PROXIMITY_BEST,
};
enum {
SCOREANIM_GOOD,
SCOREANIM_MISS,
SCOREANIM_BEST_FLASH,
SCOREANIM_BEST_STATIC,
};
enum {
PLAY_AGAIN_YES,
PLAY_AGAIN_NO,
CANT_PLAY_NO_BERRIES,
CANT_PLAY_NO_PKBLCK_SPACE
};
enum {
BLENDER_MISTER,
BLENDER_LADDIE,
BLENDER_LASSIE,
BLENDER_MASTER,
BLENDER_DUDE,
BLENDER_MISS
};
#define BLENDER_MAX_PLAYERS MAX_LINK_PLAYERS
#define NO_PLAYER 0xFF
#define MAX_PROGRESS_BAR 1000
#define MAX_ARROW_POS 0x10000 // By virtue of being u16
#define MIN_ARROW_SPEED 0x80
#define ARROW_FALL_ROTATION 0x5800 // The amount the arrow spins as it falls in at the start
// Tile offsets
#define PROGRESS_BAR_FILLED_TOP 0x80E9
#define PROGRESS_BAR_FILLED_BOTTOM 0x80F9
#define PROGRESS_BAR_EMPTY_TOP 0x80E1
#define PROGRESS_BAR_EMPTY_BOTTOM 0x80F1
#define RPM_DIGIT 0x8072
// Tile and palette tags
#define GFXTAG_COUNTDOWN_NUMBERS 12345
#define GFXTAG_START 12346
#define GFXTAG_PARTICLES 23456
#define GFXTAG_PLAYER_ARROW 46545
#define GFXTAG_SCORE_SYMBOLS 48888
#define PALTAG_PLAYER_ARROW 12312
#define PALTAG_MISC 46546
// Last berry that an NPC can put in
#define NUM_NPC_BERRIES ITEM_TO_BERRY(ITEM_ASPEAR_BERRY)
enum {
// Windows 0-3 are used implicitly in several loops over BLENDER_MAX_PLAYERS
// i.e. window 0 is for player 1, window 1 for player 2, etc.
WIN_MSG = BLENDER_MAX_PLAYERS,
WIN_RESULTS,
};
struct BlenderBerry
{
u16 itemId;
u8 name[BERRY_NAME_LENGTH + 1];
u8 flavors[FLAVOR_COUNT + 1]; // 5 flavors, + 1 for feel
};
struct TimeAndRPM
{
u32 time;
u16 maxRPM;
};
struct BlenderGameBlock
{
struct TimeAndRPM timeRPM;
u16 scores[BLENDER_MAX_PLAYERS][NUM_SCORE_TYPES];
};
struct TvBlenderStruct
{
u8 name[11];
u8 pokeblockFlavor;
u8 pokeblockColor;
u8 pokeblockSheen;
};
struct BerryBlender
{
u8 mainState;
u8 loadGfxState;
u8 unused0[66];
u16 unk0; // never read
u8 scoreIconIds[NUM_SCORE_TYPES];
u16 arrowPos;
s16 speed;
u16 maxRPM;
u8 playerArrowSpriteIds[BLENDER_MAX_PLAYERS];
u8 playerArrowSpriteIds2[BLENDER_MAX_PLAYERS];
u8 unused1[11];
u8 gameEndState;
u16 playerContinueResponses[BLENDER_MAX_PLAYERS];
u16 canceledPlayerCmd;
u16 canceledPlayerId;
u16 playAgainState;
u8 slowdownTimer;
u16 chosenItemId[BLENDER_MAX_PLAYERS];
u8 numPlayers;
u8 unused2[16];
u16 arrowIdToPlayerId[BLENDER_MAX_PLAYERS];
u16 playerIdToArrowId[BLENDER_MAX_PLAYERS];
u8 yesNoAnswer;
u8 stringVar[100];
u32 gameFrameTime;
s32 framesToWait;
u32 unk1; // never read
u8 unused3[4];
u8 playerToThrowBerry;
u16 progressBarValue;
u16 maxProgressBarValue;
u16 centerScale;
s16 bg_X;
s16 bg_Y;
u8 opponentTaskIds[BLENDER_MAX_PLAYERS - 1];
u8 perfectOpponents; // for debugging, NPCs will always hit Best
u16 scores[BLENDER_MAX_PLAYERS][NUM_SCORE_TYPES];
u8 playerPlaces[BLENDER_MAX_PLAYERS];
struct BgAffineSrcData bgAffineSrc;
u16 savedMusic;
struct BlenderBerry blendedBerries[BLENDER_MAX_PLAYERS];
struct TimeAndRPM smallBlock;
u32 linkPlayAgainState;
u8 ownRanking;
struct TvBlenderStruct tvBlender;
u8 tilemapBuffers[2][BG_SCREEN_SIZE];
s16 textState;
void *tilesBuffer;
struct BlenderGameBlock gameBlock;
};
static void SetBgPos(void);
static void Task_HandleOpponent1(u8);
static void Task_HandleOpponent2(u8);
static void Task_HandleOpponent3(u8);
static void Task_HandleBerryMaster(u8);
static void Task_PlayPokeblockFanfare(u8);
static void SpriteCB_PlayerArrow(struct Sprite *);
static void SpriteCB_ScoreSymbol(struct Sprite *);
static void SpriteCB_CountdownNumber(struct Sprite *);
static void SpriteCB_Start(struct Sprite *);
static void SpriteCB_ScoreSymbolBest(struct Sprite *);
static void InitLocalPlayers(u8);
static void CB2_LoadBerryBlender(void);
static void UpdateBlenderCenter(void);
static bool32 PrintMessage(s16 *, const u8 *, s32 );
static void StartBlender(void);
static void CB2_StartBlenderLink(void);
static void CB2_StartBlenderLocal(void);
static void Blender_DummiedOutFunc(s16, s16);
static void CB2_PlayBlender(void);
static void DrawBlenderCenter(struct BgAffineSrcData *);
static bool8 UpdateBlenderLandScreenShake(void);
static void SetPlayerIdMaps(void);
static void PrintPlayerNames(void);
static void InitBlenderBgs(void);
static void SetPlayerBerryData(u8, u16);
static void Blender_AddTextPrinter(u8, const u8 *, u8, u8, s32, s32);
static void ResetLinkCmds(void);
static void CreateParticleSprites(void);
static void ShakeBgCoordForHit(s16 *, u16);
static void TryUpdateProgressBar(u16, u16);
static void UpdateRPM(u16);
static void RestoreBgCoords(void);
static void ProcessLinkPlayerCmds(void);
static void CB2_EndBlenderGame(void);
static bool8 PrintBlendingRanking(void);
static bool8 PrintBlendingResults(void);
static void CB2_CheckPlayAgainLocal(void);
static void CB2_CheckPlayAgainLink(void);
static void UpdateProgressBar(u16, u16);
static void PrintMadePokeblockString(struct Pokeblock *, u8 *);
static bool32 TryAddContestLinkTvShow(struct Pokeblock *, struct TvBlenderStruct *);
EWRAM_DATA static struct BerryBlender *sBerryBlender = NULL;
EWRAM_DATA static s32 sDebug_PokeblockFactorFlavors[FLAVOR_COUNT] = {0};
EWRAM_DATA static s32 sDebug_PokeblockFactorFlavorsAfterRPM[FLAVOR_COUNT] = {0};
EWRAM_DATA static u32 sDebug_PokeblockFactorRPM = 0;
static s16 sPokeblockFlavors[FLAVOR_COUNT + 1]; // + 1 for feel
static s16 sPokeblockPresentFlavors[FLAVOR_COUNT + 1];
static s16 sDebug_MaxRPMStage;
static s16 sDebug_GameTimeStage;
COMMON_DATA u8 gInGameOpponentsNo = 0;
static const u16 sBlenderCenter_Pal[] = INCBIN_U16("graphics/berry_blender/center.gbapal");
static const u8 sBlenderCenter_Tilemap[] = INCBIN_U8("graphics/berry_blender/center_map.bin");
static const u16 sBlenderOuter_Pal[] = INCBIN_U16("graphics/berry_blender/outer.gbapal");
static const u16 sUnused_Pal[] = INCBIN_U16("graphics/berry_blender/unused.gbapal");
static const u16 sEmpty_Pal[16 * 14] = {0};
static const u8 sText_BerryBlenderStart[] = _("Starting up the BERRY BLENDER.\pPlease select a BERRY from your BAG\nto put in the BERRY BLENDER.\p");
static const u8 sText_NewParagraph[] = _("\p");
static const u8 sText_WasMade[] = _(" was made!");
static const u8 *const sBlenderOpponentsNames[] =
{
[BLENDER_MISTER] = COMPOUND_STRING("MISTER"),
[BLENDER_LADDIE] = COMPOUND_STRING("LADDIE"),
[BLENDER_LASSIE] = COMPOUND_STRING("LASSIE"),
[BLENDER_MASTER] = COMPOUND_STRING("MASTER"),
[BLENDER_DUDE] = COMPOUND_STRING("DUDE"),
[BLENDER_MISS] = COMPOUND_STRING("MISS"),
};
static const u8 sText_CommunicationStandby[] = _("Communication standby…");
static const u8 sText_WouldLikeToBlendAnotherBerry[] = _("Would you like to blend another BERRY?");
static const u8 sText_RunOutOfBerriesForBlending[] = _("You've run out of BERRIES for\nblending in the BERRY BLENDER.\p");
static const u8 sText_YourPokeblockCaseIsFull[] = _("Your {POKEBLOCK} CASE is full.\p");
static const u8 sText_HasNoBerriesToPut[] = _(" has no BERRIES to put in\nthe BERRY BLENDER.");
static const u8 sText_ApostropheSPokeblockCaseIsFull[] = _("'s {POKEBLOCK} CASE is full.\p");
static const u8 sText_BlendingResults[] = _("RESULTS OF BLENDING");
static const u8 sText_SpaceBerry[] = _(" BERRY");
static const u8 sText_Time[] = _("Time:");
static const u8 sText_Min[] = _(" min. ");
static const u8 sText_Sec[] = _(" sec.");
static const u8 sText_MaximumSpeed[] = _("MAXIMUM SPEED");
static const u8 sText_RPM[] = _(" RPM");
static const u8 sText_Dot[] = _(".");
static const u8 sText_NewLine[] = _("\n");
static const u8 sText_Ranking[] = _("RANKING");
static const u8 sText_TheLevelIs[] = _("The level is ");
static const u8 sText_TheFeelIs[] = _(", and the feel is ");
static const u8 sText_Dot2[] = _(".");
static const struct BgTemplate sBgTemplates[3] =
{
{
.bg = 0,
.charBaseIndex = 3,
.mapBaseIndex = 31,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0,
},
{
.bg = 1,
.charBaseIndex = 2,
.mapBaseIndex = 12,
.screenSize = 0,
.paletteMode = 0,
.priority = 1,
.baseTile = 0,
},
{
.bg = 2,
.charBaseIndex = 0,
.mapBaseIndex = 8,
.screenSize = 1,
.paletteMode = 1,
.priority = 0,
.baseTile = 0,
}
};
static const struct WindowTemplate sWindowTemplates[] =
{
{ // Player 1
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 6,
.width = 7,
.height = 2,
.paletteNum = 14,
.baseBlock = 0x28,
},
{ // Player 2
.bg = 0,
.tilemapLeft = 22,
.tilemapTop = 6,
.width = 7,
.height = 2,
.paletteNum = 14,
.baseBlock = 0x36,
},
{ // Player 3
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 12,
.width = 7,
.height = 2,
.paletteNum = 14,
.baseBlock = 0x44,
},
{ // Player 4
.bg = 0,
.tilemapLeft = 22,
.tilemapTop = 12,
.width = 7,
.height = 2,
.paletteNum = 14,
.baseBlock = 0x52,
},
[WIN_MSG] = {
.bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
.height = 4,
.paletteNum = 14,
.baseBlock = 0x60,
},
[WIN_RESULTS] = {
.bg = 0,
.tilemapLeft = 5,
.tilemapTop = 3,
.width = 21,
.height = 14,
.paletteNum = 14,
.baseBlock = 0x60,
},
DUMMY_WIN_TEMPLATE
};
static const struct WindowTemplate sYesNoWindowTemplate_ContinuePlaying =
{
.bg = 0,
.tilemapLeft = 21,
.tilemapTop = 9,
.width = 5,
.height = 4,
.paletteNum = 14,
.baseBlock = 0xCC
};
static const s8 sPlayerArrowQuadrant[BLENDER_MAX_PLAYERS][2] =
{
{-1, -1},
{ 1, -1},
{-1, 1},
{ 1, 1}
};
static const u8 sPlayerArrowPos[BLENDER_MAX_PLAYERS][2] =
{
{ 72, 32},
{168, 32},
{ 72, 128},
{168, 128}
};
static const u8 sPlayerIdMap[BLENDER_MAX_PLAYERS - 1][BLENDER_MAX_PLAYERS] =
{
{NO_PLAYER, 0, 1, NO_PLAYER}, // 2 Players
{NO_PLAYER, 0, 1, 2}, // 3 Players
{ 0, 1, 2, 3} // 4 Players
};
// Blender arrow positions:
//
// 0x0000 (limit 0x10000)
// . .
// . .
// 0x4000 . . 0xC000
// . .
// . .
// . .
// 0x8000
//
static const u16 sArrowStartPos[] = {
0,
MAX_ARROW_POS / 4 * 3, // 0xC000
MAX_ARROW_POS / 4, // 0x4000
MAX_ARROW_POS / 4 * 2 // 0x8000
};
static const u8 sArrowStartPosIds[BLENDER_MAX_PLAYERS - 1] = {1, 1, 0};
static const u8 sArrowHitRangeStart[BLENDER_MAX_PLAYERS] = {32, 224, 96, 160};
static const TaskFunc sLocalOpponentTasks[] =
{
Task_HandleOpponent1,
Task_HandleOpponent2,
Task_HandleOpponent3
};
static const struct OamData sOam_PlayerArrow =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = FALSE,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(32x32),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(32x32),
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
static const union AnimCmd sAnim_PlayerArrow_TopLeft[] =
{
ANIMCMD_FRAME(16, 5, .vFlip = TRUE, .hFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_TopRight[] =
{
ANIMCMD_FRAME(16, 5, .vFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_BottomLeft[] =
{
ANIMCMD_FRAME(16, 5, .hFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_BottomRight[] =
{
ANIMCMD_FRAME(16, 5, 0, 0),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_TopLeft_Flash[] =
{
ANIMCMD_FRAME(48, 2, .vFlip = TRUE, .hFlip = TRUE),
ANIMCMD_FRAME(32, 5, .vFlip = TRUE, .hFlip = TRUE),
ANIMCMD_FRAME(48, 3, .vFlip = TRUE, .hFlip = TRUE),
ANIMCMD_FRAME(16, 5, .vFlip = TRUE, .hFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_TopRight_Flash[] =
{
ANIMCMD_FRAME(48, 2, .vFlip = TRUE),
ANIMCMD_FRAME(32, 5, .vFlip = TRUE),
ANIMCMD_FRAME(48, 3, .vFlip = TRUE),
ANIMCMD_FRAME(16, 5, .vFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_BottomLeft_Flash[] =
{
ANIMCMD_FRAME(48, 2, .hFlip = TRUE),
ANIMCMD_FRAME(32, 5, .hFlip = TRUE),
ANIMCMD_FRAME(48, 3, .hFlip = TRUE),
ANIMCMD_FRAME(16, 5, .hFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_BottomRight_Flash[] =
{
ANIMCMD_FRAME(48, 2, 0, 0),
ANIMCMD_FRAME(32, 5, 0, 0),
ANIMCMD_FRAME(48, 3, 0, 0),
ANIMCMD_FRAME(16, 5, 0, 0),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_TopLeft_Off[] =
{
ANIMCMD_FRAME(0, 5, .vFlip = TRUE, .hFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_TopRight_Off[] =
{
ANIMCMD_FRAME(0, 5, .vFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_BottomLeft_Off[] =
{
ANIMCMD_FRAME(0, 5, .hFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerArrow_BottomRight_Off[] =
{
ANIMCMD_FRAME(0, 5, 0, 0),
ANIMCMD_END
};
static const union AnimCmd *const sAnims_PlayerArrow[] =
{
sAnim_PlayerArrow_TopLeft,
sAnim_PlayerArrow_TopRight,
sAnim_PlayerArrow_BottomLeft,
sAnim_PlayerArrow_BottomRight,
sAnim_PlayerArrow_TopLeft_Flash,
sAnim_PlayerArrow_TopRight_Flash,
sAnim_PlayerArrow_BottomLeft_Flash,
sAnim_PlayerArrow_BottomRight_Flash,
sAnim_PlayerArrow_TopLeft_Off,
sAnim_PlayerArrow_TopRight_Off,
sAnim_PlayerArrow_BottomLeft_Off,
sAnim_PlayerArrow_BottomRight_Off
};
static const struct SpriteSheet sSpriteSheet_PlayerArrow =
{
gBerryBlenderPlayerArrow_Gfx, 0x800, GFXTAG_PLAYER_ARROW
};
static const struct SpritePalette sSpritePal_BlenderMisc =
{
gBerryBlenderMiscPalette, PALTAG_MISC
};
static const struct SpritePalette sSpritePal_PlayerArrow =
{
gBerryBlenderArrowPalette, PALTAG_PLAYER_ARROW
};
static const struct SpriteTemplate sSpriteTemplate_PlayerArrow =
{
.tileTag = GFXTAG_PLAYER_ARROW,
.paletteTag = PALTAG_PLAYER_ARROW,
.oam = &sOam_PlayerArrow,
.anims = sAnims_PlayerArrow,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_PlayerArrow
};
static const struct OamData sOam_ScoreSymbols =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = FALSE,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(16x16),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(16x16),
.tileNum = 0,
.priority = 0,
.paletteNum = 0,
.affineParam = 0,
};
static const union AnimCmd sAnim_ScoreSymbols_Good[] =
{
ANIMCMD_FRAME(0, 20),
ANIMCMD_END
};
static const union AnimCmd sAnim_ScoreSymbols_Miss[] =
{
ANIMCMD_FRAME(4, 20, 1, 0),
ANIMCMD_END
};
static const union AnimCmd sAnim_ScoreSymbols_BestFlash[] =
{
ANIMCMD_FRAME(8, 4),
ANIMCMD_FRAME(12, 4),
ANIMCMD_FRAME(8, 4),
ANIMCMD_FRAME(12, 4),
ANIMCMD_FRAME(8, 4),
ANIMCMD_END
};
static const union AnimCmd sAnim_ScoreSymbols_BestStatic[] =
{
ANIMCMD_FRAME(8, 4),
ANIMCMD_END
};
static const union AnimCmd *const sAnims_ScoreSymbols[] =
{
[SCOREANIM_GOOD] = sAnim_ScoreSymbols_Good,
[SCOREANIM_MISS] = sAnim_ScoreSymbols_Miss,
[SCOREANIM_BEST_FLASH] = sAnim_ScoreSymbols_BestFlash,
[SCOREANIM_BEST_STATIC] = sAnim_ScoreSymbols_BestStatic,
};
static const struct SpriteSheet sSpriteSheet_ScoreSymbols =
{
gBerryBlenderScoreSymbols_Gfx, 0x200, GFXTAG_SCORE_SYMBOLS
};
static const struct SpriteTemplate sSpriteTemplate_ScoreSymbols =
{
.tileTag = GFXTAG_SCORE_SYMBOLS,
.paletteTag = PALTAG_MISC,
.oam = &sOam_ScoreSymbols,
.anims = sAnims_ScoreSymbols,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_ScoreSymbol
};
static const struct OamData sOam_Particles =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = FALSE,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(8x8),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(8x8),
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
static const union AnimCmd sAnim_SparkleCrossToX[] =
{
ANIMCMD_FRAME(0, 3),
ANIMCMD_FRAME(1, 4),
ANIMCMD_FRAME(3, 5),
ANIMCMD_FRAME(1, 4),
ANIMCMD_FRAME(0, 3),
ANIMCMD_END
};
static const union AnimCmd sAnim_SparkleXToCross[] =
{
ANIMCMD_FRAME(0, 3),
ANIMCMD_FRAME(2, 4),
ANIMCMD_FRAME(4, 5),
ANIMCMD_FRAME(2, 4),
ANIMCMD_FRAME(0, 3),
ANIMCMD_END
};
static const union AnimCmd sAnim_SparkleFull[] =
{
ANIMCMD_FRAME(0, 2),
ANIMCMD_FRAME(1, 2),
ANIMCMD_FRAME(2, 2),
ANIMCMD_FRAME(4, 4),
ANIMCMD_FRAME(3, 3),
ANIMCMD_FRAME(2, 2),
ANIMCMD_FRAME(1, 2),
ANIMCMD_FRAME(0, 2),
ANIMCMD_END
};
static const union AnimCmd sAnim_GreenArrow[] =
{
ANIMCMD_FRAME(5, 5, 1, 1),
ANIMCMD_END
};
static const union AnimCmd sAnim_GreenDot[] =
{
ANIMCMD_FRAME(6, 5, 1, 1),
ANIMCMD_END
};
static const union AnimCmd *const sAnims_Particles[] =
{
sAnim_SparkleCrossToX, // Only this effect is ever used, rest go unused
sAnim_SparkleXToCross,
sAnim_SparkleFull,
sAnim_GreenArrow,
sAnim_GreenDot,
};
static const struct SpriteSheet sSpriteSheet_Particles =
{
gBerryBlenderParticles_Gfx, 0xE0, GFXTAG_PARTICLES
};
static const struct SpriteTemplate sSpriteTemplate_Particles =
{
.tileTag = GFXTAG_PARTICLES,
.paletteTag = PALTAG_MISC,
.oam = &sOam_Particles,
.anims = sAnims_Particles,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCallbackDummy
};
static const struct OamData sOam_CountdownNumbers =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = FALSE,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(32x32),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(32x32),
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
static const union AnimCmd sAnim_CountdownNumbers_3[] =
{
ANIMCMD_FRAME(32, 30),
ANIMCMD_END
};
static const union AnimCmd sAnim_CountdownNumbers_2[] =
{
ANIMCMD_FRAME(16, 30),
ANIMCMD_END
};
static const union AnimCmd sAnim_CountdownNumbers_1[] =
{
ANIMCMD_FRAME(0, 30),
ANIMCMD_END
};
static const union AnimCmd *const sAnims_CountdownNumbers[] =
{
sAnim_CountdownNumbers_3,
sAnim_CountdownNumbers_2,
sAnim_CountdownNumbers_1,
};
static const struct SpriteSheet sSpriteSheet_CountdownNumbers =
{
gBerryBlenderCountdownNumbers_Gfx, 0x600, GFXTAG_COUNTDOWN_NUMBERS
};
static const struct SpriteTemplate sSpriteTemplate_CountdownNumbers =
{
.tileTag = GFXTAG_COUNTDOWN_NUMBERS,
.paletteTag = PALTAG_MISC,
.oam = &sOam_CountdownNumbers,
.anims = sAnims_CountdownNumbers,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_CountdownNumber
};
static const struct OamData sOam_Start =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = FALSE,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(64x32),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(64x32),
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
static const union AnimCmd sAnim_Start[] =
{
ANIMCMD_FRAME(0, 30),
ANIMCMD_END
};
static const union AnimCmd *const sAnims_Start[] =
{
sAnim_Start,
};
static const struct SpriteSheet sSpriteSheet_Start =
{
gBerryBlenderStart_Gfx, 0x400, GFXTAG_START
};
static const struct SpriteTemplate sSpriteTemplate_Start =
{
.tileTag = GFXTAG_START,
.paletteTag = PALTAG_MISC,
.oam = &sOam_Start,
.anims = sAnims_Start,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_Start
};
// Data for throwing the berries in at the start
// x, y, bounce speed, x speed, y speed
static const s16 sBerrySpriteData[][5] =
{
{-10, 20, 10, 2, 1},
{250, 20, 10, -2, 1},
{-10, 140, 10, 2, -1},
{250, 140, 10, -2, -1},
};
// There are only 5 different berries the NPCs will ever use
// Each of these sets represents 3 berries chosen to be used by the NPCs
// If the player's berry is one of the 5 possible berries, a set is chosen that excludes it
static const u8 sOpponentBerrySets[NUM_NPC_BERRIES * 2][3] =
{
// These sets are used if the player chose one of the 5 NPC berries
{ITEM_TO_BERRY(ITEM_ASPEAR_BERRY) - 1, ITEM_TO_BERRY(ITEM_RAWST_BERRY) - 1, ITEM_TO_BERRY(ITEM_PECHA_BERRY) - 1}, // player chose Cheri Berry
{ITEM_TO_BERRY(ITEM_CHERI_BERRY) - 1, ITEM_TO_BERRY(ITEM_ASPEAR_BERRY) - 1, ITEM_TO_BERRY(ITEM_RAWST_BERRY) - 1}, // player chose Chesto Berry
{ITEM_TO_BERRY(ITEM_CHESTO_BERRY) - 1, ITEM_TO_BERRY(ITEM_CHERI_BERRY) - 1, ITEM_TO_BERRY(ITEM_ASPEAR_BERRY) - 1}, // player chose Pecha Berry
{ITEM_TO_BERRY(ITEM_PECHA_BERRY) - 1, ITEM_TO_BERRY(ITEM_CHESTO_BERRY) - 1, ITEM_TO_BERRY(ITEM_CHERI_BERRY) - 1}, // player chose Rawst Berry
{ITEM_TO_BERRY(ITEM_RAWST_BERRY) - 1, ITEM_TO_BERRY(ITEM_PECHA_BERRY) - 1, ITEM_TO_BERRY(ITEM_CHESTO_BERRY) - 1}, // player chose Aspear Berry
// These sets are used if the player chose a different berry (set is selected by player's berry % 5)
{ITEM_TO_BERRY(ITEM_CHERI_BERRY) - 1, ITEM_TO_BERRY(ITEM_PECHA_BERRY) - 1, ITEM_TO_BERRY(ITEM_RAWST_BERRY) - 1}, // player chose Leppa, Figy, ...
{ITEM_TO_BERRY(ITEM_CHESTO_BERRY) - 1, ITEM_TO_BERRY(ITEM_RAWST_BERRY) - 1, ITEM_TO_BERRY(ITEM_ASPEAR_BERRY) - 1}, // player chose Oran, Wiki, ...
{ITEM_TO_BERRY(ITEM_PECHA_BERRY) - 1, ITEM_TO_BERRY(ITEM_ASPEAR_BERRY) - 1, ITEM_TO_BERRY(ITEM_CHERI_BERRY) - 1}, // player chose Persim, Mago, ...
{ITEM_TO_BERRY(ITEM_RAWST_BERRY) - 1, ITEM_TO_BERRY(ITEM_CHERI_BERRY) - 1, ITEM_TO_BERRY(ITEM_CHESTO_BERRY) - 1}, // player chose Lum, Aguav, ...
{ITEM_TO_BERRY(ITEM_ASPEAR_BERRY) - 1, ITEM_TO_BERRY(ITEM_CHESTO_BERRY) - 1, ITEM_TO_BERRY(ITEM_PECHA_BERRY) - 1}, // player chose Sitrus, Iapapa, ...
};
// Berry master's berries follow the same rules as above, but instead of explicitly listing
// the alternate sets if the player chooses one of these berries, it implicitly uses these berries - 5, i.e. Tamato - Nomel
static const u8 sBerryMasterBerries[] = {
ITEM_TO_BERRY(ITEM_SPELON_BERRY) - 1,
ITEM_TO_BERRY(ITEM_PAMTRE_BERRY) - 1,
ITEM_TO_BERRY(ITEM_WATMEL_BERRY) - 1,
ITEM_TO_BERRY(ITEM_DURIN_BERRY) - 1,
ITEM_TO_BERRY(ITEM_BELUE_BERRY) - 1
};
// "0 players" is link
static const u8 sNumPlayersToSpeedDivisor[] = {1, 1, 2, 3, 4};
// Black pokeblocks will use one of these random combinations of flavors
static const u8 sBlackPokeblockFlavorFlags[] = {
(1 << FLAVOR_SOUR) | (1 << FLAVOR_BITTER) | (1 << FLAVOR_SWEET),
(1 << FLAVOR_SOUR) | (1 << FLAVOR_SWEET) | (1 << FLAVOR_DRY),
(1 << FLAVOR_SOUR) | (1 << FLAVOR_DRY) | (1 << FLAVOR_SPICY),
(1 << FLAVOR_SOUR) | (1 << FLAVOR_BITTER) | (1 << FLAVOR_DRY),
(1 << FLAVOR_SOUR) | (1 << FLAVOR_BITTER) | (1 << FLAVOR_SPICY),
(1 << FLAVOR_BITTER) | (1 << FLAVOR_SWEET) | (1 << FLAVOR_DRY),
(1 << FLAVOR_BITTER) | (1 << FLAVOR_SWEET) | (1 << FLAVOR_SPICY),
(1 << FLAVOR_BITTER) | (1 << FLAVOR_DRY) | (1 << FLAVOR_SPICY),
(1 << FLAVOR_SWEET) | (1 << FLAVOR_DRY) | (1 << FLAVOR_SPICY),
(1 << FLAVOR_SOUR) | (1 << FLAVOR_SWEET) | (1 << FLAVOR_SPICY),
};
static const u8 sJPText_GoodTvReady[] = _("\nいいTVができました "); // Unused
static const u8 sJPText_BadTvReady[] = _("\nダメTVができました "); // Unused
static const u8 sJPText_Flavors[][5] = {_("からい"), _("しぶい"), _("あまい"), _("にがい"), _("すっぱい")}; // Unused
static const u8 sUnused[] = {
6, 6, 6, 6, 5,
3, 3, 3, 2, 2,
3, 3, 3, 3, 2
};
static const struct WindowTemplate sBlenderRecordWindowTemplate =
{
.bg = 0,
.tilemapLeft = 6,
.tilemapTop = 4,
.width = 18,
.height = 11,
.paletteNum = 15,
.baseBlock = 8
};
static void UpdateHitPitch(void)
{
m4aMPlayPitchControl(&gMPlayInfo_SE2, TRACKS_ALL, 2 * (sBerryBlender->speed - MIN_ARROW_SPEED));
}
static void VBlankCB_BerryBlender(void)
{
SetBgPos();
SetBgAffine(2, sBerryBlender->bgAffineSrc.texX, sBerryBlender->bgAffineSrc.texY,
sBerryBlender->bgAffineSrc.scrX, sBerryBlender->bgAffineSrc.scrY,
sBerryBlender->bgAffineSrc.sx, sBerryBlender->bgAffineSrc.sy,
sBerryBlender->bgAffineSrc.alpha);
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
static bool8 LoadBerryBlenderGfx(void)
{
switch (sBerryBlender->loadGfxState)
{
case 0:
sBerryBlender->tilesBuffer = AllocZeroed(GetDecompressedDataSize(gBerryBlenderCenter_Gfx) + 100);
LZDecompressWram(gBerryBlenderCenter_Gfx, sBerryBlender->tilesBuffer);
sBerryBlender->loadGfxState++;
break;
case 1:
CopyToBgTilemapBuffer(2, sBlenderCenter_Tilemap, 0x400, 0);
CopyBgTilemapBufferToVram(2);
LoadPalette(sBlenderCenter_Pal, BG_PLTT_ID(0), 8 * PLTT_SIZE_4BPP);
sBerryBlender->loadGfxState++;
break;
case 2:
LoadBgTiles(2, sBerryBlender->tilesBuffer, GetDecompressedDataSize(gBerryBlenderCenter_Gfx), 0);
sBerryBlender->loadGfxState++;
break;
case 3:
LZDecompressWram(gBerryBlenderOuter_Gfx, sBerryBlender->tilesBuffer);
sBerryBlender->loadGfxState++;
break;
case 4:
LoadBgTiles(1, sBerryBlender->tilesBuffer, GetDecompressedDataSize(gBerryBlenderOuter_Gfx), 0);
sBerryBlender->loadGfxState++;
break;
case 5:
LZDecompressWram(gBerryBlenderOuter_Tilemap, sBerryBlender->tilesBuffer);
sBerryBlender->loadGfxState++;
break;
case 6:
CopyToBgTilemapBuffer(1, sBerryBlender->tilesBuffer, GetDecompressedDataSize(gBerryBlenderOuter_Tilemap), 0);
CopyBgTilemapBufferToVram(1);
sBerryBlender->loadGfxState++;
break;
case 7:
LoadPalette(sBlenderOuter_Pal, BG_PLTT_ID(8), PLTT_SIZE_4BPP);
sBerryBlender->loadGfxState++;
break;
case 8:
LoadSpriteSheet(&sSpriteSheet_PlayerArrow);
LoadSpriteSheet(&sSpriteSheet_Particles);
LoadSpriteSheet(&sSpriteSheet_ScoreSymbols);
sBerryBlender->loadGfxState++;
break;
case 9:
LoadSpriteSheet(&sSpriteSheet_CountdownNumbers);
LoadSpriteSheet(&sSpriteSheet_Start);
LoadSpritePalette(&sSpritePal_PlayerArrow);
LoadSpritePalette(&sSpritePal_BlenderMisc);
Free(sBerryBlender->tilesBuffer);
sBerryBlender->loadGfxState = 0;
return TRUE;
}
return FALSE;
}
static void DrawBlenderBg(void)
{