forked from pret/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathberry_crush.c
3507 lines (3236 loc) · 104 KB
/
berry_crush.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 "battle_anim.h"
#include "berry.h"
#include "berry_powder.h"
#include "bg.h"
#include "decompress.h"
#include "dynamic_placeholder_text_util.h"
#include "event_data.h"
#include "gpu_regs.h"
#include "graphics.h"
#include "international_string_util.h"
#include "item_icon.h"
#include "item_menu.h"
#include "link.h"
#include "link_rfu.h"
#include "main.h"
#include "malloc.h"
#include "math_util.h"
#include "menu.h"
#include "overworld.h"
#include "palette.h"
#include "minigame_countdown.h"
#include "random.h"
#include "digit_obj_util.h"
#include "save.h"
#include "scanline_effect.h"
#include "script.h"
#include "sound.h"
#include "sprite.h"
#include "string_util.h"
#include "strings.h"
#include "task.h"
#include "text.h"
#include "text_window.h"
#include "trig.h"
#include "window.h"
#include "constants/items.h"
#include "constants/rgb.h"
#include "constants/songs.h"
#define MAX_TIME (10 * 60 * 60) // Timer can go up to 9:59:59
#define TAG_CRUSHER_BASE 1
#define PALTAG_EFFECT 2 // The next two gfx tags share this pal tag
#define GFXTAG_IMPACT 2
#define GFXTAG_SPARKLE 3
#define TAG_TIMER_DIGITS 4
#define TAG_PLAYER1_BERRY 5
#define TAG_PLAYER2_BERRY 6
#define TAG_PLAYER3_BERRY 7
#define TAG_PLAYER4_BERRY 8
#define TAG_PLAYER5_BERRY 9
#define TAG_COUNTDOWN 0x1000
#define CRUSHER_START_Y (-104)
enum {
RUN_CMD,
SCHEDULE_CMD,
};
// IDs for the main berry crush game functions
enum {
CMD_NONE,
CMD_FADE,
CMD_WAIT_FADE,
CMD_PRINT_MSG,
CMD_SHOW_GAME,
CMD_HIDE_GAME,
CMD_READY_BEGIN,
CMD_ASK_PICK_BERRY,
CMD_PICK_BERRY,
CMD_WAIT_BERRIES,
CMD_DROP_BERRIES,
CMD_DROP_LID,
CMD_COUNTDOWN,
CMD_PLAY_GAME_LEADER,
CMD_PLAY_GAME_MEMBER,
CMD_FINISH_GAME,
CMD_TIMES_UP,
CMD_CALC_RESULTS,
CMD_SHOW_RESULTS,
CMD_SAVE,
CMD_ASK_PLAY_AGAIN,
CMD_COMM_PLAY_AGAIN,
CMD_PLAY_AGAIN_YES,
CMD_PLAY_AGAIN_NO,
CMD_CLOSE_LINK,
CMD_QUIT,
};
enum {
MSG_PICK_BERRY,
MSG_WAIT_PICK,
MSG_POWDER,
MSG_SAVING,
MSG_PLAY_AGAIN,
MSG_NO_BERRIES,
MSG_DROPPED,
MSG_TIMES_UP,
MSG_COMM_STANDBY,
};
#define F_MSG_CLEAR (1 << 0)
#define F_MSG_EXPAND (1 << 1)
// Main states for the game. Many are assigned but never checked
enum {
STATE_INIT = 1,
STATE_RESET,
STATE_PICK_BERRY,
STATE_DROP_BERRIES,
STATE_DROP_LID,
STATE_COUNTDOWN,
STATE_PLAYING,
STATE_FINISHED,
STATE_TIMES_UP,
STATE_10, // Unused
STATE_RESULTS_PRESSES,
STATE_RESULTS_RANDOM,
STATE_RESULTS_CRUSHING,
STATE_14, // Unused
STATE_PLAY_AGAIN,
};
#define RESULTS_STATE_START STATE_RESULTS_PRESSES
#define RESULTS_STATE_END STATE_RESULTS_CRUSHING
// IDs for each results page that shows in succession at the game's end.
// Only 3 pages are shown for a given game. Presses and Crushing are always shown 1st and 3rd.
// The 2nd page is random, and can be rankings for either Neatness, Cooperative, or Power.
enum {
RESULTS_PAGE_PRESSES,
RESULTS_PAGE_RANDOM,
RESULTS_PAGE_CRUSHING,
NUM_RESULTS_PAGES,
};
// Random pages, see above
// "Neatness" is how many of the player's inputs were at a regular interval
// "Cooperative" is how often the player pressed A at the same time as others
// "Power" is how much of the time the player spent pressing A
enum {
RESULTS_PAGE_NEATNESS,
RESULTS_PAGE_COOPERATIVE,
RESULTS_PAGE_POWER,
NUM_RANDOM_RESULTS_PAGES
};
#define PLAY_AGAIN_YES 0
#define PLAY_AGAIN_NO 1
#define PLAY_AGAIN_NO_BERRIES 3
enum {
COLORID_GRAY,
COLORID_BLACK,
COLORID_LIGHT_GRAY,
COLORID_BLUE,
COLORID_GREEN,
COLORID_RED,
};
// Flags for the inputFlags field
// Field is 16 bits; 3 bits for each player, last bit is unused
// The first two bits are interchangeable
// Needlessly complicated system, the inputState field is sufficient by itself
#define F_INPUT_HIT_A (1 << 0)
#define F_INPUT_HIT_B (1 << 1)
#define F_INPUT_HIT_SYNC (1 << 2) // Input at same time as another player
#define INPUT_FLAGS_PER_PLAYER 3
#define INPUT_FLAG_MASK ((1 << INPUT_FLAGS_PER_PLAYER) - 1)
// Values for the inputState field
enum {
INPUT_STATE_NONE,
INPUT_STATE_HIT, // Hit the crusher
INPUT_STATE_HIT_SYNC, // Hit the crusher at same time as another player
};
// No reason for this to be 2
// Simply a flag for whether a given player has sent their data this round
// Data is only sent if the player is the leader or if they pressed A
#define SEND_GAME_STATE 2
struct BerryCrushGame_Player
{
u8 name[PLAYER_NAME_LENGTH + 1 + 4];
u16 berryId;
u16 inputTime;
u16 neatInputStreak;
u16 timeSincePrevInput;
u16 maxNeatInputStreak;
u16 numAPresses;
u16 numSyncedAPresses;
u16 timePressingA;
u8 inputFlags;
u8 inputState;
};
// This data is set locally and sent to the other players
struct BerryCrushGame_LocalState
{
u16 sendFlag;
bool8 endGame:1;
bool8 bigSparkle:1;
bool8 pushedAButton:1;
u8 playerPressedAFlags:5; // 1 bit for each player
s8 vibration;
u16 depth;
u16 timer;
u16 inputFlags;
u16 sparkleAmount;
};
// This data is read from another player's local state above by casting the recvCmd buffer
// It is identical with exception to the addition of rfuCmd
struct BerryCrushGame_LinkState
{
u16 rfuCmd;
u16 sendFlag;
bool8 endGame:1;
bool8 bigSparkle:1;
bool8 pushedAButton:1;
u8 playerPressedAFlags:5;
s8 vibration;
u16 depth;
u16 timer;
u16 inputFlags;
u16 sparkleAmount;
};
struct BerryCrushGame_Results
{
u32 powder;
u16 time;
u16 targetPressesPerSec; // Never read
u16 silkiness;
u16 totalAPresses;
u16 stats[2][MAX_RFU_PLAYERS];
u8 playerIdsRanked[2][MAX_RFU_PLAYERS + 3];
};
// playerIdsRanked above has 3 additional elements after the players.
// Only 1 of these 2*3 is ever used, and it stores the id for which
// random results page to show. Its define below is for readability.
#define randomPageId playerIdsRanked[0][7]
// Holds position data for various player-associated graphics
struct BerryCrushPlayerCoords
{
u8 playerId;
u8 windowGfxX;
u8 windowGfxY;
s16 impactXOffset;
s16 impactYOffset;
s16 berryXOffset;
s16 berryXDest;
};
struct BerryCrushGame_Gfx
{
u8 counter;
u8 vibrationIdx;
u8 numVibrations;
bool8 vibrating;
s16 minutes;
s16 secondsInt;
s16 secondsFrac;
const struct BerryCrushPlayerCoords *playerCoords[MAX_RFU_PLAYERS];
struct Sprite *coreSprite;
struct Sprite *impactSprites[MAX_RFU_PLAYERS];
struct Sprite *berrySprites[MAX_RFU_PLAYERS];
struct Sprite *sparkleSprites[11];
struct Sprite *timerSprites[2];
u8 resultsState;
u8 unused;
u8 resultsWindowId;
u8 nameWindowIds[MAX_RFU_PLAYERS];
u16 bgBuffers[4][0x800];
};
struct BerryCrushGame
{
MainCallback exitCallback;
u32 (*cmdCallback)(struct BerryCrushGame *, u8 *);
u8 localId;
u8 playerCount;
u8 taskId;
u8 textSpeed;
u8 cmdState;
u8 unused; // Never read
u8 nextCmd;
u8 afterPalFadeCmd;
u16 cmdTimer;
u16 gameState;
u16 playAgainState;
u16 pressingSpeed;
s16 targetAPresses;
s16 totalAPresses;
s32 powder;
s32 targetDepth;
u8 newDepth;
bool8 noRoomForPowder:1; // Never read
bool8 newRecord:1;
bool8 playedSound:1;
bool8 endGame:1;
bool8 bigSparkle:1;
u8 sparkleAmount:3;
u16 leaderTimer;
u16 timer;
s16 depth;
s16 vibration;
s16 bigSparkleCounter;
s16 numBigSparkles;
s16 numBigSparkleChecks;
s16 sparkleCounter;
u8 commandArgs[12];
u16 sendCmd[6];
u16 recvCmd[7];
struct BerryCrushGame_LocalState localState;
struct BerryCrushGame_Results results;
struct BerryCrushGame_Player players[MAX_RFU_PLAYERS];
struct BerryCrushGame_Gfx gfx;
};
static void VBlankCB(void);
static void MainCB(void);
static void MainTask(u8);
static void SetNamesAndTextSpeed(struct BerryCrushGame *);
static void RunOrScheduleCommand(u16, u8, u8 *);
static void SetPaletteFadeArgs(u8 *, bool8, u32, s8, u8, u8, u16);
static s32 UpdateGame(struct BerryCrushGame *);
static void CreatePlayerNameWindows(struct BerryCrushGame *);
static void DrawPlayerNameWindows(struct BerryCrushGame *);
static void CopyPlayerNameWindowGfxToBg(struct BerryCrushGame *);
static void CreateGameSprites(struct BerryCrushGame *);
static void DestroyGameSprites(struct BerryCrushGame *);
static void PrintTimer(struct BerryCrushGame_Gfx *, u16);
static void SpriteCB_Sparkle_Init(struct Sprite *);
static void HideTimer(struct BerryCrushGame_Gfx *);
static void ResetGame(struct BerryCrushGame *);
static void SetPrintMessageArgs(u8 *, u8, u8, u16, u8);
static void SpriteCB_Impact(struct Sprite *);
static u32 Cmd_BeginNormalPaletteFade(struct BerryCrushGame *, u8 *);
static u32 Cmd_WaitPaletteFade(struct BerryCrushGame *, u8 *);
static u32 Cmd_PrintMessage(struct BerryCrushGame *, u8 *);
static u32 Cmd_ShowGameDisplay(struct BerryCrushGame *, u8 *);
static u32 Cmd_HideGameDisplay(struct BerryCrushGame *, u8 *);
static u32 Cmd_SignalReadyToBegin(struct BerryCrushGame *, u8 *);
static u32 Cmd_AskPickBerry(struct BerryCrushGame *, u8 *);
static u32 Cmd_GoToBerryPouch(struct BerryCrushGame *, u8 *);
static u32 Cmd_WaitForOthersToPickBerries(struct BerryCrushGame *, u8 *);
static u32 Cmd_DropBerriesIntoCrusher(struct BerryCrushGame *, u8 *);
static u32 Cmd_DropLid(struct BerryCrushGame *, u8 *);
static u32 Cmd_Countdown(struct BerryCrushGame *, u8 *);
static u32 Cmd_PlayGame_Leader(struct BerryCrushGame *, u8 *);
static u32 Cmd_PlayGame_Member(struct BerryCrushGame *, u8 *);
static u32 Cmd_FinishGame(struct BerryCrushGame *, u8 *);
static u32 Cmd_HandleTimeUp(struct BerryCrushGame *, u8 *);
static u32 Cmd_TabulateResults(struct BerryCrushGame *, u8 *);
static u32 Cmd_ShowResults(struct BerryCrushGame *, u8 *);
static u32 Cmd_SaveGame(struct BerryCrushGame *, u8 *);
static u32 Cmd_AskPlayAgain(struct BerryCrushGame *, u8 *);
static u32 Cmd_CommunicatePlayAgainResponses(struct BerryCrushGame *, u8 *);
static u32 Cmd_PlayAgain(struct BerryCrushGame *, u8 *);
static u32 Cmd_StopGame(struct BerryCrushGame *, u8 *);
static u32 Cmd_CloseLink(struct BerryCrushGame *, u8 *);
static u32 Cmd_Quit(struct BerryCrushGame *, u8 *);
static EWRAM_DATA struct BerryCrushGame *sGame = NULL;
static const u8 sBitTable[] = {
1 << 0,
1 << 1,
1 << 2,
1 << 3,
1 << 4,
1 << 5,
1 << 6,
1 << 7
};
// Additional A presses are counted depending on the number of players
// The bonus of 5 is unobtainable
static const u8 sSyncPressBonus[MAX_RFU_PLAYERS] = { 0, 1, 2, 3, 5 };
ALIGNED(4)
static const s8 sIntroOutroVibrationData[][7] =
{
{ 4, 1, 0, -1, 0, 0, 0},
{ 4, 2, 0, -1, 0, 0, 0},
{ 4, 2, 0, -2, 0, 0, 0},
{ 6, 3, 1, -1, -3, -1, 0},
{ 6, 4, 1, -2, -4, -2, 0},
};
ALIGNED(4)
static const u8 sVibrationData[MAX_RFU_PLAYERS][4] =
{
{3, 2, 1, 0},
{3, 3, 1, 0},
{3, 3, 2, 0},
{3, 4, 2, 0},
{3, 5, 3, 0},
};
static const u8 *const sMessages[] =
{
[MSG_PICK_BERRY] = gText_ReadyPickBerry,
[MSG_WAIT_PICK] = gText_WaitForAllChooseBerry,
[MSG_POWDER] = gText_EndedWithXUnitsPowder,
[MSG_SAVING] = gText_RecordingGameResults,
[MSG_PLAY_AGAIN] = gText_PlayBerryCrushAgain,
[MSG_NO_BERRIES] = gText_YouHaveNoBerries,
[MSG_DROPPED] = gText_MemberDroppedOut,
[MSG_TIMES_UP] = gText_TimesUpNoGoodPowder,
[MSG_COMM_STANDBY] = gText_CommunicationStandby2,
};
static const struct BgTemplate sBgTemplates[4] =
{
{
.bg = 0,
.charBaseIndex = 2,
.mapBaseIndex = 15,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0,
},
{
.bg = 1,
.charBaseIndex = 0,
.mapBaseIndex = 13,
.screenSize = 2,
.paletteMode = 0,
.priority = 1,
.baseTile = 0,
},
{
.bg = 2,
.charBaseIndex = 0,
.mapBaseIndex = 12,
.screenSize = 0,
.paletteMode = 0,
.priority = 2,
.baseTile = 0,
},
{
.bg = 3,
.charBaseIndex = 0,
.mapBaseIndex = 11,
.screenSize = 0,
.paletteMode = 0,
.priority = 3,
.baseTile = 0,
},
};
static const u8 sTextColorTable[][3] =
{
[COLORID_GRAY] = {TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY},
[COLORID_BLACK] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY},
[COLORID_LIGHT_GRAY] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_LIGHT_GRAY, TEXT_COLOR_RED},
[COLORID_BLUE] = {TEXT_COLOR_WHITE, TEXT_COLOR_BLUE, TEXT_COLOR_LIGHT_BLUE},
[COLORID_GREEN] = {TEXT_COLOR_WHITE, TEXT_COLOR_GREEN, TEXT_COLOR_LIGHT_GREEN},
[COLORID_RED] = {TEXT_COLOR_WHITE, TEXT_COLOR_RED, TEXT_COLOR_LIGHT_RED},
};
static const struct WindowTemplate sWindowTemplate_Rankings =
{
.bg = 0,
.tilemapLeft = 3,
.tilemapTop = 4,
.width = 24,
.height = 13,
.paletteNum = 15,
.baseBlock = 1
};
static const struct WindowTemplate sWindowTemplates_PlayerNames[MAX_RFU_PLAYERS + 1] =
{
{
.bg = 0,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 9,
.height = 2,
.paletteNum = 8,
.baseBlock = 1005
},
{
.bg = 0,
.tilemapLeft = 0,
.tilemapTop = 3,
.width = 9,
.height = 2,
.paletteNum = 8,
.baseBlock = 987
},
{
.bg = 0,
.tilemapLeft = 0,
.tilemapTop = 6,
.width = 9,
.height = 2,
.paletteNum = 8,
.baseBlock = 969
},
{
.bg = 0,
.tilemapLeft = 21,
.tilemapTop = 3,
.width = 9,
.height = 2,
.paletteNum = 8,
.baseBlock = 951
},
{
.bg = 0,
.tilemapLeft = 21,
.tilemapTop = 6,
.width = 9,
.height = 2,
.paletteNum = 8,
.baseBlock = 933
},
DUMMY_WIN_TEMPLATE,
};
static const struct WindowTemplate sWindowTemplates_Results[] =
{
[STATE_RESULTS_PRESSES - RESULTS_STATE_START] = {
.bg = 0,
.tilemapLeft = 5,
.tilemapTop = 2,
.width = 20,
.height = 16,
.paletteNum = 15,
.baseBlock = 1
},
[STATE_RESULTS_RANDOM - RESULTS_STATE_START] = {
.bg = 0,
.tilemapLeft = 5,
.tilemapTop = 2,
.width = 20,
.height = 16,
.paletteNum = 15,
.baseBlock = 1
},
[STATE_RESULTS_CRUSHING - RESULTS_STATE_START] = {
.bg = 0,
.tilemapLeft = 4,
.tilemapTop = 2,
.width = 22,
.height = 16,
.paletteNum = 15,
.baseBlock = 1
},
DUMMY_WIN_TEMPLATE,
};
// The height of the results window depending on the number of players
// 2 players, 3 players, 4 players, or 5 players
static const u8 sResultsWindowHeights[][MAX_RFU_PLAYERS - 1] =
{
{6, 8, 9, 11}, // "Presses" and "Neatness/Cooperative/Power" pages
{12, 14, 15, 16}, // "Crushing" page
};
static const u32 sPressingSpeedConversionTable[] =
{
50000000, // 50
25000000, // 25
12500000, // 12.5
6250000, // 6.25
3125000, // 3.125
1562500, // 1.5625
781250, // 0.78125
390625 // 0.390625
};
static const u16 sCrusherBase_Pal[] = INCBIN_U16("graphics/berry_crush/crusher_base.gbapal");
static const u16 sEffects_Pal[] = INCBIN_U16("graphics/berry_crush/effects.gbapal");
static const u16 sTimerDigits_Pal[] = INCBIN_U16("graphics/berry_crush/timer_digits.gbapal");
static const u32 sCrusherBase_Gfx[] = INCBIN_U32("graphics/berry_crush/crusher_base.4bpp.lz");
static const u32 sImpact_Gfx[] = INCBIN_U32("graphics/berry_crush/impact.4bpp.lz");
static const u32 sSparkle_Gfx[] = INCBIN_U32("graphics/berry_crush/sparkle.4bpp.lz");
static const u32 sTimerDigits_Gfx[] = INCBIN_U32("graphics/berry_crush/timer_digits.4bpp.lz");
static const u8 sCrusherTop_Tilemap[] = INCBIN_U8("graphics/berry_crush/crusher_top.bin.lz");
static const u8 sContainerCap_Tilemap[] = INCBIN_U8("graphics/berry_crush/container_cap.bin.lz");
static const u8 sBg_Tilemap[] = INCBIN_U8("graphics/berry_crush/bg.bin.lz");
// Takes the number of players - 2 and a player id and returns the
// index into sPlayerCoords where that player should be seated
static const u8 sPlayerIdToPosId[MAX_RFU_PLAYERS - 1][MAX_RFU_PLAYERS] =
{
{1, 3},
{0, 1, 3},
{1, 3, 2, 4},
{0, 1, 3, 2, 4},
};
static const struct BerryCrushPlayerCoords sPlayerCoords[MAX_RFU_PLAYERS] =
{
{
.playerId = 0,
.windowGfxX = 0,
.windowGfxY = 0,
.impactXOffset = 0,
.impactYOffset = -16,
.berryXOffset = 0,
.berryXDest = 0,
},
{
.playerId = 1,
.windowGfxX = 0,
.windowGfxY = 3,
.impactXOffset = -28,
.impactYOffset = -4,
.berryXOffset = -24,
.berryXDest = 16,
},
{
.playerId = 2,
.windowGfxX = 0,
.windowGfxY = 6,
.impactXOffset = -16,
.impactYOffset = 20,
.berryXOffset = -8,
.berryXDest = 16,
},
{
.playerId = 3,
.windowGfxX = 20,
.windowGfxY = 3,
.impactXOffset = 28,
.impactYOffset = -4,
.berryXOffset = 32,
.berryXDest = -8,
},
{
.playerId = 4,
.windowGfxX = 20,
.windowGfxY = 6,
.impactXOffset = 16,
.impactYOffset = 20,
.berryXOffset = 16,
.berryXDest = -8,
}
};
static const s8 sImpactCoords[][2] =
{
{ 0, 0},
{-1, 0},
{ 1, 1},
};
static const s8 sSparkleCoords[][2] =
{
{ 0, 0},
{-16, -4},
{ 16, -4},
{ -8, -2},
{ 8, -2},
{-24, -8},
{ 24, -8},
{-32, -12},
{ 32, -12},
{-40, -16},
{ 40, -16},
};
static const u16 sPlayerBerrySpriteTags[MAX_RFU_PLAYERS] =
{
TAG_PLAYER1_BERRY,
TAG_PLAYER2_BERRY,
TAG_PLAYER3_BERRY,
TAG_PLAYER4_BERRY,
TAG_PLAYER5_BERRY
};
// sTimerDigits_Gfx is part of this array but is (apparently) uncompressed
// It gets cast to raw uncompressed data when used in sDigitObjTemplates
static const struct CompressedSpriteSheet sSpriteSheets[] =
{
{ .data = sCrusherBase_Gfx, .size = 0x800, .tag = TAG_CRUSHER_BASE },
{ .data = sImpact_Gfx, .size = 0xE00, .tag = GFXTAG_IMPACT },
{ .data = sSparkle_Gfx, .size = 0x700, .tag = GFXTAG_SPARKLE },
{ .data = sTimerDigits_Gfx, .size = 0x2C0, .tag = TAG_TIMER_DIGITS },
{}
};
static const struct SpritePalette sSpritePals[] =
{
{ .data = sCrusherBase_Pal, .tag = TAG_CRUSHER_BASE },
{ .data = sEffects_Pal, .tag = PALTAG_EFFECT }, // For the impact and sparkle effects
{ .data = sTimerDigits_Pal, .tag = TAG_TIMER_DIGITS },
{}
};
static const union AnimCmd sAnim_CrusherBase[] =
{
ANIMCMD_FRAME(0, 0),
ANIMCMD_END
};
static const union AnimCmd sAnim_Impact_Small[] =
{
ANIMCMD_FRAME(0, 4),
ANIMCMD_FRAME(16, 4),
ANIMCMD_FRAME(32, 4),
ANIMCMD_END
};
static const union AnimCmd sAnim_Impact_Big[] =
{
ANIMCMD_FRAME(48, 2),
ANIMCMD_FRAME(64, 2),
ANIMCMD_FRAME(80, 2),
ANIMCMD_FRAME(96, 2),
ANIMCMD_END
};
static const union AnimCmd sAnim_Sparkle_Small[] =
{
ANIMCMD_FRAME(0, 2),
ANIMCMD_FRAME(4, 2),
ANIMCMD_FRAME(8, 2),
ANIMCMD_FRAME(12, 2),
ANIMCMD_FRAME(16, 2),
ANIMCMD_FRAME(20, 2),
ANIMCMD_JUMP(0)
};
static const union AnimCmd sAnim_Sparkle_Big[] =
{
ANIMCMD_FRAME(24, 4),
ANIMCMD_FRAME(28, 4),
ANIMCMD_FRAME(32, 4),
ANIMCMD_FRAME(36, 4),
ANIMCMD_FRAME(40, 4),
ANIMCMD_FRAME(44, 4),
ANIMCMD_FRAME(48, 4),
ANIMCMD_FRAME(52, 4),
ANIMCMD_JUMP(0)
};
static const union AnimCmd sAnim_Timer[] =
{
ANIMCMD_FRAME(20, 0),
ANIMCMD_END
};
static const union AnimCmd sAnim_PlayerBerry[] =
{
ANIMCMD_FRAME(0, 0),
ANIMCMD_END
};
static const union AffineAnimCmd sAffineAnim_PlayerBerry_0[] =
{
AFFINEANIMCMD_FRAME(256, 256, 0, 0),
AFFINEANIMCMD_FRAME(0, 0, 2, 1),
AFFINEANIMCMD_JUMP(1)
};
static const union AffineAnimCmd sAffineAnim_PlayerBerry_1[] =
{
AFFINEANIMCMD_FRAME(256, 256, 0, 0),
AFFINEANIMCMD_FRAME(0, 0, -2, 1),
AFFINEANIMCMD_JUMP(1)
};
static const union AnimCmd *const sAnims_CrusherBase[] =
{
sAnim_CrusherBase
};
static const union AnimCmd *const sAnims_Impact[] =
{
sAnim_Impact_Small,
sAnim_Impact_Big,
};
static const union AnimCmd *const sAnims_Sparkle[] =
{
sAnim_Sparkle_Small,
sAnim_Sparkle_Big,
};
static const union AnimCmd *const sAnims_Timer[] =
{
sAnim_Timer
};
static const union AnimCmd *const sAnims_PlayerBerry[] =
{
sAnim_PlayerBerry
};
static const union AffineAnimCmd *const sAffineAnims_PlayerBerry[] =
{
sAffineAnim_PlayerBerry_0,
sAffineAnim_PlayerBerry_1,
};
static const struct SpriteTemplate sSpriteTemplate_CrusherBase =
{
.tileTag = TAG_CRUSHER_BASE,
.paletteTag = TAG_CRUSHER_BASE,
.oam = &gOamData_AffineOff_ObjNormal_64x64,
.anims = sAnims_CrusherBase,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCallbackDummy
};
static const struct SpriteTemplate sSpriteTemplate_Impact =
{
.tileTag = GFXTAG_IMPACT,
.paletteTag = PALTAG_EFFECT,
.oam = &gOamData_AffineOff_ObjNormal_32x32,
.anims = sAnims_Impact,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_Impact
};
static const struct SpriteTemplate sSpriteTemplate_Sparkle =
{
.tileTag = GFXTAG_SPARKLE,
.paletteTag = PALTAG_EFFECT,
.oam = &gOamData_AffineOff_ObjNormal_16x16,
.anims = sAnims_Sparkle,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCallbackDummy
};
static const struct SpriteTemplate sSpriteTemplate_Timer =
{
.tileTag = TAG_TIMER_DIGITS,
.paletteTag = TAG_TIMER_DIGITS,
.oam = &gOamData_AffineOff_ObjNormal_8x16,
.anims = sAnims_Timer,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCallbackDummy
};
static const struct SpriteTemplate sSpriteTemplate_PlayerBerry =
{
.tileTag = TAG_PLAYER1_BERRY,
.paletteTag = TAG_PLAYER1_BERRY,
.oam = &gOamData_AffineDouble_ObjNormal_32x32,
.anims = sAnims_PlayerBerry,
.images = NULL,
.affineAnims = sAffineAnims_PlayerBerry,
.callback = SpriteCallbackDummy
};
static const struct DigitObjUtilTemplate sDigitObjTemplates[] =
{
{ // Minutes
.strConvMode = 1,
.shape = 2,
.size = 0,
.priority = 0,
.oamCount = 2,
.xDelta = 8,
.x = 156,
.y = 0,
.spriteSheet = (void *) &sSpriteSheets[3],
.spritePal = &sSpritePals[2],
},
{ // Seconds
.strConvMode = 0,
.shape = 2,
.size = 0,
.priority = 0,
.oamCount = 2,
.xDelta = 8,
.x = 180,
.y = 0,
.spriteSheet = (void *) &sSpriteSheets[3],
.spritePal = &sSpritePals[2],
},
{ // 1/60ths of a second
.strConvMode = 0,
.shape = 2,
.size = 0,
.priority = 0,
.oamCount = 2,
.xDelta = 8,
.x = 204,
.y = 0,
.spriteSheet = (void *) &sSpriteSheets[3],
.spritePal = &sSpritePals[2],
}
};
static const u8 *const sResultsTexts[] =
{
[RESULTS_PAGE_PRESSES] = gText_SpaceTimes2, // " times"
[RESULTS_PAGE_RANDOM] = gText_XDotY, // "##.##", for Neatness, Cooperation, or Power value
[RESULTS_PAGE_CRUSHING] = gText_Var1Berry,
[RESULTS_PAGE_NEATNESS + NUM_RESULTS_PAGES] = gText_NeatnessRankings,
[RESULTS_PAGE_COOPERATIVE + NUM_RESULTS_PAGES] = gText_CoopRankings,
[RESULTS_PAGE_POWER + NUM_RESULTS_PAGES] = gText_PressingPowerRankings,
};
static u32 (*const sBerryCrushCommands[])(struct BerryCrushGame * game, u8 * data) =
{
[CMD_NONE] = NULL,
[CMD_FADE] = Cmd_BeginNormalPaletteFade,
[CMD_WAIT_FADE] = Cmd_WaitPaletteFade,
[CMD_PRINT_MSG] = Cmd_PrintMessage,
[CMD_SHOW_GAME] = Cmd_ShowGameDisplay,
[CMD_HIDE_GAME] = Cmd_HideGameDisplay,
[CMD_READY_BEGIN] = Cmd_SignalReadyToBegin,
[CMD_ASK_PICK_BERRY] = Cmd_AskPickBerry,
[CMD_PICK_BERRY] = Cmd_GoToBerryPouch,
[CMD_WAIT_BERRIES] = Cmd_WaitForOthersToPickBerries,
[CMD_DROP_BERRIES] = Cmd_DropBerriesIntoCrusher,
[CMD_DROP_LID] = Cmd_DropLid,
[CMD_COUNTDOWN] = Cmd_Countdown,
[CMD_PLAY_GAME_LEADER] = Cmd_PlayGame_Leader,
[CMD_PLAY_GAME_MEMBER] = Cmd_PlayGame_Member,
[CMD_FINISH_GAME] = Cmd_FinishGame,
[CMD_TIMES_UP] = Cmd_HandleTimeUp,
[CMD_CALC_RESULTS] = Cmd_TabulateResults,
[CMD_SHOW_RESULTS] = Cmd_ShowResults,
[CMD_SAVE] = Cmd_SaveGame,
[CMD_ASK_PLAY_AGAIN] = Cmd_AskPlayAgain,
[CMD_COMM_PLAY_AGAIN] = Cmd_CommunicatePlayAgainResponses,
[CMD_PLAY_AGAIN_YES] = Cmd_PlayAgain,
[CMD_PLAY_AGAIN_NO] = Cmd_StopGame,
[CMD_CLOSE_LINK] = Cmd_CloseLink,
[CMD_QUIT] = Cmd_Quit,
};
// Per group size, the number of A presses required to increase the number of sparkles.
static const u8 sSparkleThresholds[MAX_RFU_PLAYERS - 1][4] =
{
{2, 4, 6, 7}, // 2 players
{3, 5, 8, 11}, // 3 players
{3, 7, 11, 15}, // 4 players
{4, 8, 12, 17}, // 5 players
};
// Per group size, the number of A presses required to get big sparkles
static const u8 sBigSparkleThresholds[MAX_RFU_PLAYERS - 1] = {5, 7, 9, 12};
static const u8 sReceivedPlayerBitmasks[] = {0x03, 0x07, 0x0F, 0x1F};
static struct BerryCrushGame * GetBerryCrushGame(void)
{
return sGame;
}
static u32 QuitBerryCrush(MainCallback exitCallback)
{
if (!sGame)
return 2;
if (!exitCallback)
exitCallback = sGame->exitCallback;
DestroyTask(sGame->taskId);
FREE_AND_SET_NULL(sGame);
SetMainCallback2(exitCallback);
if (exitCallback == CB2_ReturnToField)
{
gTextFlags.autoScroll = TRUE;
PlayNewMapMusic(MUS_POKE_CENTER);
SetMainCallback1(CB1_Overworld);
}
return 0;
}
#define ERROR_EXIT(exitCallback) \
{ \
SetMainCallback2(exitCallback); \
gRfu.errorParam0 = 0; \
gRfu.errorParam1 = 0; \
gRfu.errorState = RFU_ERROR_STATE_OCCURRED; \
}
void StartBerryCrush(MainCallback exitCallback)
{
u8 playerCount = 0;
u8 multiplayerId;
if (!gReceivedRemoteLinkPlayers || gWirelessCommType == 0)