forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
field_specials.c
4263 lines (3871 loc) · 134 KB
/
field_specials.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 "debug.h"
#include "malloc.h"
#include "battle.h"
#include "battle_tower.h"
#include "cable_club.h"
#include "data.h"
#include "decoration.h"
#include "diploma.h"
#include "event_data.h"
#include "event_object_movement.h"
#include "fieldmap.h"
#include "field_camera.h"
#include "field_effect.h"
#include "field_message_box.h"
#include "field_player_avatar.h"
#include "field_screen_effect.h"
#include "field_specials.h"
#include "field_weather.h"
#include "graphics.h"
#include "international_string_util.h"
#include "item_icon.h"
#include "link.h"
#include "load_save.h"
#include "list_menu.h"
#include "main.h"
#include "mystery_gift.h"
#include "match_call.h"
#include "menu.h"
#include "overworld.h"
#include "party_menu.h"
#include "pokeblock.h"
#include "pokemon.h"
#include "pokemon_storage_system.h"
#include "random.h"
#include "rayquaza_scene.h"
#include "region_map.h"
#include "rtc.h"
#include "script.h"
#include "script_menu.h"
#include "sound.h"
#include "starter_choose.h"
#include "string_util.h"
#include "strings.h"
#include "task.h"
#include "text.h"
#include "tv.h"
#include "wallclock.h"
#include "window.h"
#include "constants/abilities.h"
#include "constants/battle_frontier.h"
#include "constants/battle_pyramid.h"
#include "constants/battle_tower.h"
#include "constants/decorations.h"
#include "constants/event_objects.h"
#include "constants/event_object_movement.h"
#include "constants/field_effects.h"
#include "constants/field_specials.h"
#include "constants/items.h"
#include "constants/heal_locations.h"
#include "constants/map_types.h"
#include "constants/mystery_gift.h"
#include "constants/script_menu.h"
#include "constants/slot_machine.h"
#include "constants/songs.h"
#include "constants/moves.h"
#include "constants/party_menu.h"
#include "constants/battle_frontier.h"
#include "constants/weather.h"
#include "constants/metatile_labels.h"
#include "palette.h"
#include "battle_util.h"
#define TAG_ITEM_ICON 5500
#define GFXTAG_MULTICHOICE_SCROLL_ARROWS 2000
#define PALTAG_MULTICHOICE_SCROLL_ARROWS 100
#define ELEVATOR_WINDOW_WIDTH 3
#define ELEVATOR_WINDOW_HEIGHT 3
#define ELEVATOR_LIGHT_STAGES 3
EWRAM_DATA bool8 gBikeCyclingChallenge = FALSE;
EWRAM_DATA u8 gBikeCollisions = 0;
static EWRAM_DATA u32 sBikeCyclingTimer = 0;
static EWRAM_DATA u8 sSlidingDoorNextFrameCounter = 0;
static EWRAM_DATA u8 sSlidingDoorFrame = 0;
static EWRAM_DATA u8 sTutorMoveAndElevatorWindowId = 0;
static EWRAM_DATA u16 sLilycoveDeptStore_NeverRead = 0;
static EWRAM_DATA u16 sLilycoveDeptStore_DefaultFloorChoice = 0;
static EWRAM_DATA struct ListMenuItem *sScrollableMultichoice_ListMenuItem = NULL;
static EWRAM_DATA u16 sScrollableMultichoice_ScrollOffset = 0;
static EWRAM_DATA u16 sFrontierExchangeCorner_NeverRead = 0;
static EWRAM_DATA u8 sScrollableMultichoice_ItemSpriteId = 0;
static EWRAM_DATA u8 sBattlePointsWindowId = 0;
static EWRAM_DATA u8 sFrontierExchangeCorner_ItemIconWindowId = 0;
static EWRAM_DATA u8 sPCBoxToSendMon = 0;
static EWRAM_DATA u32 sBattleTowerMultiBattleTypeFlags = 0;
struct ListMenuTemplate gScrollableMultichoice_ListMenuTemplate;
void TryLoseFansFromPlayTime(void);
void SetPlayerGotFirstFans(void);
u16 GetNumFansOfPlayerInTrainerFanClub(void);
static void RecordCyclingRoadResults(u32, u8);
static void LoadLinkPartnerObjectEventSpritePalette(u8, u8, u8);
static void Task_PetalburgGymSlideOpenRoomDoors(u8);
static void PetalburgGymSetDoorMetatiles(u8, u16);
static void Task_PCTurnOnEffect(u8);
static void PCTurnOnEffect(struct Task *);
static void PCTurnOnEffect_SetMetatile(s16, s8, s8);
static void PCTurnOffEffect(void);
static void Task_LotteryCornerComputerEffect(u8);
static void LotteryCornerComputerEffect(struct Task *);
static void Task_ShakeCamera(u8);
static void StopCameraShake(u8);
static void Task_MoveElevator(u8);
static void MoveElevatorWindowLights(u16, bool8);
static void Task_MoveElevatorWindowLights(u8);
static void Task_ShowScrollableMultichoice(u8);
static void FillFrontierExchangeCornerWindowAndItemIcon(u16, u16);
static void ShowBattleFrontierTutorWindow(u8, u16);
static void InitScrollableMultichoice(void);
static void ScrollableMultichoice_ProcessInput(u8);
static void ScrollableMultichoice_UpdateScrollArrows(u8);
static void ScrollableMultichoice_MoveCursor(s32, bool8, struct ListMenu *);
static void HideFrontierExchangeCornerItemIcon(u16, u16);
static void ShowBattleFrontierTutorMoveDescription(u8, u16);
static void CloseScrollableMultichoice(u8);
static void ScrollableMultichoice_RemoveScrollArrows(u8);
static void Task_ScrollableMultichoice_WaitReturnToList(u8);
static void Task_ScrollableMultichoice_ReturnToList(u8);
static void ShowFrontierExchangeCornerItemIcon(u16);
static void Task_DeoxysRockInteraction(u8);
static void ChangeDeoxysRockLevel(u8);
static void WaitForDeoxysRockMovement(u8);
static void Task_LinkRetireStatusWithBattleTowerPartner(u8);
static void Task_LoopWingFlapSE(u8);
static void Task_CloseBattlePikeCurtain(u8);
static u8 DidPlayerGetFirstFans(void);
static void SetInitialFansOfPlayer(void);
static u16 PlayerGainRandomTrainerFan(void);
static void BufferFanClubTrainerName_(struct LinkBattleRecords *, u8, u8);
void Special_ShowDiploma(void)
{
SetMainCallback2(CB2_ShowDiploma);
LockPlayerFieldControls();
}
void Special_ViewWallClock(void)
{
gMain.savedCallback = CB2_ReturnToField;
SetMainCallback2(CB2_ViewWallClock);
LockPlayerFieldControls();
}
void ResetCyclingRoadChallengeData(void)
{
gBikeCyclingChallenge = FALSE;
gBikeCollisions = 0;
sBikeCyclingTimer = 0;
}
void Special_BeginCyclingRoadChallenge(void)
{
gBikeCyclingChallenge = TRUE;
gBikeCollisions = 0;
sBikeCyclingTimer = gMain.vblankCounter1;
}
u16 GetPlayerAvatarBike(void)
{
if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE))
return 1;
if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE))
return 2;
return 0;
}
static void DetermineCyclingRoadResults(u32 numFrames, u8 numBikeCollisions)
{
u8 result;
if (numBikeCollisions < 100)
{
ConvertIntToDecimalStringN(gStringVar1, numBikeCollisions, STR_CONV_MODE_LEFT_ALIGN, 2);
StringAppend(gStringVar1, gText_SpaceTimes);
}
else
{
StringCopy(gStringVar1, gText_99TimesPlus);
}
if (numFrames < 3600)
{
ConvertIntToDecimalStringN(gStringVar2, numFrames / 60, STR_CONV_MODE_RIGHT_ALIGN, 2);
gStringVar2[2] = CHAR_DEC_SEPARATOR;
ConvertIntToDecimalStringN(&gStringVar2[3], ((numFrames % 60) * 100) / 60, STR_CONV_MODE_LEADING_ZEROS, 2);
StringAppend(gStringVar2, gText_SpaceSeconds);
}
else
{
StringCopy(gStringVar2, gText_1MinutePlus);
}
result = 0;
if (numBikeCollisions == 0)
result = 5;
else if (numBikeCollisions < 4)
result = 4;
else if (numBikeCollisions < 10)
result = 3;
else if (numBikeCollisions < 20)
result = 2;
else if (numBikeCollisions < 100)
result = 1;
if (numFrames / 60 <= 10)
result += 5;
else if (numFrames / 60 <= 15)
result += 4;
else if (numFrames / 60 <= 20)
result += 3;
else if (numFrames / 60 <= 40)
result += 2;
else if (numFrames / 60 < 60)
result += 1;
gSpecialVar_Result = result;
}
void FinishCyclingRoadChallenge(void)
{
const u32 numFrames = gMain.vblankCounter1 - sBikeCyclingTimer;
DetermineCyclingRoadResults(numFrames, gBikeCollisions);
RecordCyclingRoadResults(numFrames, gBikeCollisions);
}
static void RecordCyclingRoadResults(u32 numFrames, u8 numBikeCollisions)
{
u16 low = VarGet(VAR_CYCLING_ROAD_RECORD_TIME_L);
u16 high = VarGet(VAR_CYCLING_ROAD_RECORD_TIME_H);
u32 framesRecord = low + (high << 16);
if (framesRecord > numFrames || framesRecord == 0)
{
VarSet(VAR_CYCLING_ROAD_RECORD_TIME_L, numFrames);
VarSet(VAR_CYCLING_ROAD_RECORD_TIME_H, numFrames >> 16);
VarSet(VAR_CYCLING_ROAD_RECORD_COLLISIONS, numBikeCollisions);
}
}
u16 GetRecordedCyclingRoadResults(void)
{
u16 low = VarGet(VAR_CYCLING_ROAD_RECORD_TIME_L);
u16 high = VarGet(VAR_CYCLING_ROAD_RECORD_TIME_H);
u32 framesRecord = low + (high << 16);
if (framesRecord == 0)
return FALSE;
DetermineCyclingRoadResults(framesRecord, VarGet(VAR_CYCLING_ROAD_RECORD_COLLISIONS));
return TRUE;
}
void UpdateCyclingRoadState(void)
{
if (gLastUsedWarp.mapNum == MAP_NUM(ROUTE110_SEASIDE_CYCLING_ROAD_SOUTH_ENTRANCE) && gLastUsedWarp.mapGroup == MAP_GROUP(ROUTE110_SEASIDE_CYCLING_ROAD_SOUTH_ENTRANCE))
return;
if (VarGet(VAR_CYCLING_CHALLENGE_STATE) == 2 || VarGet(VAR_CYCLING_CHALLENGE_STATE) == 3)
{
VarSet(VAR_CYCLING_CHALLENGE_STATE, 0);
Overworld_SetSavedMusic(MUS_DUMMY);
}
}
void SetSSTidalFlag(void)
{
FlagSet(FLAG_SYS_CRUISE_MODE);
*GetVarPointer(VAR_CRUISE_STEP_COUNT) = 0;
}
void ResetSSTidalFlag(void)
{
FlagClear(FLAG_SYS_CRUISE_MODE);
}
// Returns TRUE if the Cruise is over
bool32 CountSSTidalStep(u16 delta)
{
if (!FlagGet(FLAG_SYS_CRUISE_MODE) || (*GetVarPointer(VAR_CRUISE_STEP_COUNT) += delta) < SS_TIDAL_MAX_STEPS)
return FALSE;
return TRUE;
}
u8 GetSSTidalLocation(s8 *mapGroup, s8 *mapNum, s16 *x, s16 *y)
{
u16 *varCruiseStepCount = GetVarPointer(VAR_CRUISE_STEP_COUNT);
switch (*GetVarPointer(VAR_SS_TIDAL_STATE))
{
case SS_TIDAL_BOARD_SLATEPORT:
case SS_TIDAL_LAND_SLATEPORT:
return SS_TIDAL_LOCATION_SLATEPORT;
case SS_TIDAL_HALFWAY_LILYCOVE:
case SS_TIDAL_EXIT_CURRENTS_RIGHT:
return SS_TIDAL_LOCATION_ROUTE131;
case SS_TIDAL_LAND_LILYCOVE:
case SS_TIDAL_BOARD_LILYCOVE:
return SS_TIDAL_LOCATION_LILYCOVE;
case SS_TIDAL_DEPART_LILYCOVE:
case SS_TIDAL_EXIT_CURRENTS_LEFT:
return SS_TIDAL_LOCATION_ROUTE124;
case SS_TIDAL_DEPART_SLATEPORT:
if (*varCruiseStepCount < 60)
{
*mapNum = MAP_NUM(ROUTE134);
*x = *varCruiseStepCount + 19;
}
else if (*varCruiseStepCount < 140)
{
*mapNum = MAP_NUM(ROUTE133);
*x = *varCruiseStepCount - 60;
}
else
{
*mapNum = MAP_NUM(ROUTE132);
*x = *varCruiseStepCount - 140;
}
break;
case SS_TIDAL_HALFWAY_SLATEPORT:
if (*varCruiseStepCount < 66)
{
*mapNum = MAP_NUM(ROUTE132);
*x = 65 - *varCruiseStepCount;
}
else if (*varCruiseStepCount < 146)
{
*mapNum = MAP_NUM(ROUTE133);
*x = 145 - *varCruiseStepCount;
}
else
{
*mapNum = MAP_NUM(ROUTE134);
*x = 224 - *varCruiseStepCount;
}
break;
}
*mapGroup = MAP_GROUP(ROUTE132);
*y = 20;
return SS_TIDAL_LOCATION_CURRENTS;
}
bool32 ShouldDoWallyCall(void)
{
if (FlagGet(FLAG_ENABLE_FIRST_WALLY_POKENAV_CALL))
{
switch (gMapHeader.mapType)
{
case MAP_TYPE_TOWN:
case MAP_TYPE_CITY:
case MAP_TYPE_ROUTE:
case MAP_TYPE_OCEAN_ROUTE:
if (++(*GetVarPointer(VAR_WALLY_CALL_STEP_COUNTER)) < 250)
return FALSE;
break;
default:
return FALSE;
}
}
else
{
return FALSE;
}
return TRUE;
}
bool32 ShouldDoScottFortreeCall(void)
{
if (FlagGet(FLAG_SCOTT_CALL_FORTREE_GYM))
{
switch (gMapHeader.mapType)
{
case MAP_TYPE_TOWN:
case MAP_TYPE_CITY:
case MAP_TYPE_ROUTE:
case MAP_TYPE_OCEAN_ROUTE:
if (++(*GetVarPointer(VAR_SCOTT_FORTREE_CALL_STEP_COUNTER)) < 10)
return FALSE;
break;
default:
return FALSE;
}
}
else
{
return FALSE;
}
return TRUE;
}
bool32 ShouldDoScottBattleFrontierCall(void)
{
if (FlagGet(FLAG_SCOTT_CALL_BATTLE_FRONTIER))
{
switch (gMapHeader.mapType)
{
case MAP_TYPE_TOWN:
case MAP_TYPE_CITY:
case MAP_TYPE_ROUTE:
case MAP_TYPE_OCEAN_ROUTE:
if (++(*GetVarPointer(VAR_SCOTT_BF_CALL_STEP_COUNTER)) < 10)
return FALSE;
break;
default:
return FALSE;
}
}
else
{
return FALSE;
}
return TRUE;
}
bool32 ShouldDoRoxanneCall(void)
{
if (FlagGet(FLAG_ENABLE_ROXANNE_FIRST_CALL))
{
switch (gMapHeader.mapType)
{
case MAP_TYPE_TOWN:
case MAP_TYPE_CITY:
case MAP_TYPE_ROUTE:
case MAP_TYPE_OCEAN_ROUTE:
if (++(*GetVarPointer(VAR_ROXANNE_CALL_STEP_COUNTER)) < 250)
return FALSE;
break;
default:
return FALSE;
}
}
else
{
return FALSE;
}
return TRUE;
}
bool32 ShouldDoRivalRayquazaCall(void)
{
if (FlagGet(FLAG_DEFEATED_MAGMA_SPACE_CENTER))
{
switch (gMapHeader.mapType)
{
case MAP_TYPE_TOWN:
case MAP_TYPE_CITY:
case MAP_TYPE_ROUTE:
case MAP_TYPE_OCEAN_ROUTE:
if (++(*GetVarPointer(VAR_RIVAL_RAYQUAZA_CALL_STEP_COUNTER)) < 250)
return FALSE;
break;
default:
return FALSE;
}
}
else
{
return FALSE;
}
return TRUE;
}
u8 GetLinkPartnerNames(void)
{
u8 i;
u8 j = 0;
u8 myLinkPlayerNumber = GetMultiplayerId();
u8 nLinkPlayers = GetLinkPlayerCount();
for (i = 0; i < nLinkPlayers; i++)
{
if (myLinkPlayerNumber != i)
{
StringCopy(gTVStringVarPtrs[j], gLinkPlayers[i].name);
j++;
}
}
return nLinkPlayers;
}
void SpawnLinkPartnerObjectEvent(void)
{
u8 j = 0;
s16 x = 0;
s16 y = 0;
u8 movementTypes[] = {
MOVEMENT_TYPE_FACE_UP,
MOVEMENT_TYPE_FACE_LEFT,
MOVEMENT_TYPE_FACE_DOWN,
MOVEMENT_TYPE_FACE_RIGHT
};
s8 coordOffsets[][2] = {
{ 0, 1},
{ 1, 0},
{ 0, -1},
{-1, 0}
};
u8 myLinkPlayerNumber;
u8 playerFacingDirection;
u8 linkSpriteId;
u8 i;
myLinkPlayerNumber = GetMultiplayerId();
playerFacingDirection = GetPlayerFacingDirection();
switch (playerFacingDirection)
{
case DIR_WEST:
j = 2;
x = gSaveBlock1Ptr->pos.x - 1;
y = gSaveBlock1Ptr->pos.y;
break;
case DIR_NORTH:
j = 1;
x = gSaveBlock1Ptr->pos.x;
y = gSaveBlock1Ptr->pos.y - 1;
break;
case DIR_EAST:
x = gSaveBlock1Ptr->pos.x + 1;
y = gSaveBlock1Ptr->pos.y;
break;
case DIR_SOUTH:
j = 3;
x = gSaveBlock1Ptr->pos.x;
y = gSaveBlock1Ptr->pos.y + 1;
}
for (i = 0; i < gSpecialVar_0x8004; i++)
{
if (myLinkPlayerNumber != i)
{
switch ((u8)gLinkPlayers[i].version)
{
case VERSION_RUBY:
case VERSION_SAPPHIRE:
if (gLinkPlayers[i].gender == 0)
linkSpriteId = OBJ_EVENT_GFX_LINK_RS_BRENDAN;
else
linkSpriteId = OBJ_EVENT_GFX_LINK_RS_MAY;
break;
case VERSION_EMERALD:
if (gLinkPlayers[i].gender == 0)
linkSpriteId = OBJ_EVENT_GFX_RIVAL_BRENDAN_NORMAL;
else
linkSpriteId = OBJ_EVENT_GFX_RIVAL_MAY_NORMAL;
break;
default:
if (gLinkPlayers[i].gender == 0)
linkSpriteId = OBJ_EVENT_GFX_RIVAL_BRENDAN_NORMAL;
else
linkSpriteId = OBJ_EVENT_GFX_RIVAL_MAY_NORMAL;
break;
}
SpawnSpecialObjectEventParameterized(linkSpriteId, movementTypes[j], 240 - i, coordOffsets[j][0] + x + MAP_OFFSET, coordOffsets[j][1] + y + MAP_OFFSET, 0);
LoadLinkPartnerObjectEventSpritePalette(linkSpriteId, 240 - i, i);
j++;
if (j == MAX_LINK_PLAYERS)
j = 0;
}
}
}
static void LoadLinkPartnerObjectEventSpritePalette(u8 graphicsId, u8 localEventId, u8 paletteNum)
{
u8 adjustedPaletteNum;
// Note: This temp var is necessary; paletteNum += 6 doesn't match.
adjustedPaletteNum = paletteNum + 6;
if (graphicsId == OBJ_EVENT_GFX_LINK_RS_BRENDAN ||
graphicsId == OBJ_EVENT_GFX_LINK_RS_MAY ||
graphicsId == OBJ_EVENT_GFX_RIVAL_BRENDAN_NORMAL ||
graphicsId == OBJ_EVENT_GFX_RIVAL_MAY_NORMAL)
{
u8 obj = GetObjectEventIdByLocalIdAndMap(localEventId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup);
if (obj != OBJECT_EVENTS_COUNT)
{
u8 spriteId = gObjectEvents[obj].spriteId;
struct Sprite *sprite = &gSprites[spriteId];
sprite->oam.paletteNum = adjustedPaletteNum;
switch (graphicsId)
{
case OBJ_EVENT_GFX_LINK_RS_BRENDAN:
LoadPalette(gObjectEventPal_RubySapphireBrendan, OBJ_PLTT_ID(adjustedPaletteNum), PLTT_SIZE_4BPP);
break;
case OBJ_EVENT_GFX_LINK_RS_MAY:
LoadPalette(gObjectEventPal_RubySapphireMay, OBJ_PLTT_ID(adjustedPaletteNum), PLTT_SIZE_4BPP);
break;
case OBJ_EVENT_GFX_RIVAL_BRENDAN_NORMAL:
LoadPalette(gObjectEventPal_Brendan, OBJ_PLTT_ID(adjustedPaletteNum), PLTT_SIZE_4BPP);
break;
case OBJ_EVENT_GFX_RIVAL_MAY_NORMAL:
LoadPalette(gObjectEventPal_May, OBJ_PLTT_ID(adjustedPaletteNum), PLTT_SIZE_4BPP);
break;
}
}
}
}
static const struct UCoords8 sMauvilleGymSwitchCoords[] =
{
{ 0 + MAP_OFFSET, 15 + MAP_OFFSET},
{ 4 + MAP_OFFSET, 12 + MAP_OFFSET},
{ 3 + MAP_OFFSET, 9 + MAP_OFFSET},
{ 8 + MAP_OFFSET, 9 + MAP_OFFSET}
};
// Presses the stepped-on switch and raises the rest
void MauvilleGymPressSwitch(void)
{
u8 i;
for (i = 0; i < ARRAY_COUNT(sMauvilleGymSwitchCoords); i++)
{
if (i == gSpecialVar_0x8004)
MapGridSetMetatileIdAt(sMauvilleGymSwitchCoords[i].x, sMauvilleGymSwitchCoords[i].y, METATILE_MauvilleGym_PressedSwitch);
else
MapGridSetMetatileIdAt(sMauvilleGymSwitchCoords[i].x, sMauvilleGymSwitchCoords[i].y, METATILE_MauvilleGym_RaisedSwitch);
}
}
// Sets the gym barriers back to the default state; their alt state is handled by MauvilleCity_Gym_EventScript_SetAltBarriers
void MauvilleGymSetDefaultBarriers(void)
{
int x, y;
// All switches/barriers are within these coord ranges
for (y = 5 + MAP_OFFSET; y < 17 + MAP_OFFSET; y++)
{
for (x = 0 + MAP_OFFSET; x < 9 + MAP_OFFSET; x++)
{
switch (MapGridGetMetatileIdAt(x, y))
{
case METATILE_MauvilleGym_GreenBeamH1_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH1_Off);
break;
case METATILE_MauvilleGym_GreenBeamH2_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH2_Off);
break;
case METATILE_MauvilleGym_GreenBeamH3_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH3_Off);
break;
case METATILE_MauvilleGym_GreenBeamH4_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH4_Off);
break;
case METATILE_MauvilleGym_GreenBeamH1_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH1_On);
break;
case METATILE_MauvilleGym_GreenBeamH2_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH2_On);
break;
case METATILE_MauvilleGym_GreenBeamH3_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH3_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_GreenBeamH4_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH4_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_RedBeamH1_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH1_Off);
break;
case METATILE_MauvilleGym_RedBeamH2_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH2_Off);
break;
case METATILE_MauvilleGym_RedBeamH3_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH3_Off);
break;
case METATILE_MauvilleGym_RedBeamH4_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH4_Off);
break;
case METATILE_MauvilleGym_RedBeamH1_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH1_On);
break;
case METATILE_MauvilleGym_RedBeamH2_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH2_On);
break;
case METATILE_MauvilleGym_RedBeamH3_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH3_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_RedBeamH4_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH4_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_GreenBeamV1_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_PoleBottom_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_GreenBeamV2_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_FloorTile);
break;
case METATILE_MauvilleGym_RedBeamV1_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_PoleBottom_Off | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_RedBeamV2_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_FloorTile);
break;
case METATILE_MauvilleGym_PoleBottom_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamV1_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_FloorTile:
if (MapGridGetMetatileIdAt(x, y - 1) == METATILE_MauvilleGym_GreenBeamV1_On)
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamV2_On | MAPGRID_COLLISION_MASK);
else
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamV2_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_PoleBottom_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamV1_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_PoleTop_Off:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_PoleTop_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_PoleTop_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_PoleTop_Off);
break;
}
}
}
}
// Presses all switches and deactivates all beams.
void MauvilleGymDeactivatePuzzle(void)
{
int i, x, y;
const struct UCoords8 *switchCoords = sMauvilleGymSwitchCoords;
for (i = ARRAY_COUNT(sMauvilleGymSwitchCoords) - 1; i >= 0; i--)
{
MapGridSetMetatileIdAt(switchCoords->x, switchCoords->y, METATILE_MauvilleGym_PressedSwitch);
switchCoords++;
}
for (y = 5 + MAP_OFFSET; y < 17 + MAP_OFFSET; y++)
{
for (x = 0 + MAP_OFFSET; x < 9 + MAP_OFFSET; x++)
{
switch (MapGridGetMetatileIdAt(x, y))
{
case METATILE_MauvilleGym_GreenBeamH1_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH1_Off);
break;
case METATILE_MauvilleGym_GreenBeamH2_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH2_Off);
break;
case METATILE_MauvilleGym_GreenBeamH3_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH3_Off);
break;
case METATILE_MauvilleGym_GreenBeamH4_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_GreenBeamH4_Off);
break;
case METATILE_MauvilleGym_RedBeamH1_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH1_Off);
break;
case METATILE_MauvilleGym_RedBeamH2_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH2_Off);
break;
case METATILE_MauvilleGym_RedBeamH3_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH3_Off);
break;
case METATILE_MauvilleGym_RedBeamH4_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_RedBeamH4_Off);
break;
case METATILE_MauvilleGym_GreenBeamV1_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_PoleBottom_On | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_RedBeamV1_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_PoleBottom_Off | MAPGRID_COLLISION_MASK);
break;
case METATILE_MauvilleGym_GreenBeamV2_On:
case METATILE_MauvilleGym_RedBeamV2_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_FloorTile);
break;
case METATILE_MauvilleGym_PoleTop_On:
MapGridSetMetatileIdAt(x, y, METATILE_MauvilleGym_PoleTop_Off);
break;
}
}
}
}
static const bool8 sSlidingDoorNextFrameDelay[] = {0, 1, 1, 1, 1};
static const u16 sPetalburgGymSlidingDoorMetatiles[] = {
METATILE_PetalburgGym_SlidingDoor_Frame0,
METATILE_PetalburgGym_SlidingDoor_Frame1,
METATILE_PetalburgGym_SlidingDoor_Frame2,
METATILE_PetalburgGym_SlidingDoor_Frame3,
METATILE_PetalburgGym_SlidingDoor_Frame4,
};
void PetalburgGymSlideOpenRoomDoors(void)
{
sSlidingDoorNextFrameCounter = 0;
sSlidingDoorFrame = 0;
PlaySE(SE_UNLOCK);
CreateTask(Task_PetalburgGymSlideOpenRoomDoors, 8);
}
static void Task_PetalburgGymSlideOpenRoomDoors(u8 taskId)
{
if (sSlidingDoorNextFrameDelay[sSlidingDoorFrame] == sSlidingDoorNextFrameCounter)
{
PetalburgGymSetDoorMetatiles(gSpecialVar_0x8004, sPetalburgGymSlidingDoorMetatiles[sSlidingDoorFrame]);
sSlidingDoorNextFrameCounter = 0;
if ((++sSlidingDoorFrame) == ARRAY_COUNT(sPetalburgGymSlidingDoorMetatiles))
{
DestroyTask(taskId);
ScriptContext_Enable();
}
}
else
{
sSlidingDoorNextFrameCounter++;
}
}
static void PetalburgGymSetDoorMetatiles(u8 roomNumber, u16 metatileId)
{
u16 doorCoordsX[4];
u16 doorCoordsY[4];
u8 i;
u8 nDoors = 0;
switch (roomNumber)
{
case 1:
nDoors = 2;
doorCoordsX[0] = 1;
doorCoordsX[1] = 7;
doorCoordsY[0] = 104;
doorCoordsY[1] = 104;
break;
case 2:
nDoors = 2;
doorCoordsX[0] = 1;
doorCoordsX[1] = 7;
doorCoordsY[0] = 78;
doorCoordsY[1] = 78;
break;
case 3:
nDoors = 2;
doorCoordsX[0] = 1;
doorCoordsX[1] = 7;
doorCoordsY[0] = 91;
doorCoordsY[1] = 91;
break;
case 4:
nDoors = 1;
doorCoordsX[0] = 7;
doorCoordsY[0] = 39;
break;
case 5:
nDoors = 2;
doorCoordsX[0] = 1;
doorCoordsX[1] = 7;
doorCoordsY[0] = 52;
doorCoordsY[1] = 52;
break;
case 6:
nDoors = 1;
doorCoordsX[0] = 1;
doorCoordsY[0] = 65;
break;
case 7:
nDoors = 1;
doorCoordsX[0] = 7;
doorCoordsY[0] = 13;
break;
case 8:
nDoors = 1;
doorCoordsX[0] = 1;
doorCoordsY[0] = 26;
break;
}
for (i = 0; i < nDoors; i++)
{
MapGridSetMetatileIdAt(doorCoordsX[i] + MAP_OFFSET, doorCoordsY[i] + MAP_OFFSET, metatileId | MAPGRID_COLLISION_MASK);
MapGridSetMetatileIdAt(doorCoordsX[i] + MAP_OFFSET, doorCoordsY[i] + MAP_OFFSET + 1, (metatileId + METATILE_ROW_WIDTH) | MAPGRID_COLLISION_MASK);
}
DrawWholeMapView();
}
void PetalburgGymUnlockRoomDoors(void)
{
PetalburgGymSetDoorMetatiles(gSpecialVar_0x8004, sPetalburgGymSlidingDoorMetatiles[4]);
}
void ShowFieldMessageStringVar4(void)
{
ShowFieldMessage(gStringVar4);
}
void StorePlayerCoordsInVars(void)
{
gSpecialVar_0x8004 = gSaveBlock1Ptr->pos.x;
gSpecialVar_0x8005 = gSaveBlock1Ptr->pos.y;
}
u8 GetPlayerTrainerIdOnesDigit(void)
{
return (u16)((gSaveBlock2Ptr->playerTrainerId[1] << 8) | gSaveBlock2Ptr->playerTrainerId[0]) % 10;
}
void GetPlayerBigGuyGirlString(void)
{
if (gSaveBlock2Ptr->playerGender == MALE)
StringCopy(gStringVar1, gText_BigGuy);
else
StringCopy(gStringVar1, gText_BigGirl);
}
void GetRivalSonDaughterString(void)
{
if (gSaveBlock2Ptr->playerGender == MALE)
StringCopy(gStringVar1, gText_Daughter);
else
StringCopy(gStringVar1, gText_Son);
}
u8 GetBattleOutcome(void)
{
return gBattleOutcome;
}
void CableCarWarp(void)
{
if (gSpecialVar_0x8004 != 0)
SetWarpDestination(MAP_GROUP(ROUTE112_CABLE_CAR_STATION), MAP_NUM(ROUTE112_CABLE_CAR_STATION), WARP_ID_NONE, 6, 4);
else
SetWarpDestination(MAP_GROUP(MT_CHIMNEY_CABLE_CAR_STATION), MAP_NUM(MT_CHIMNEY_CABLE_CAR_STATION), WARP_ID_NONE, 6, 4);
}
void SetHiddenItemFlag(void)
{
FlagSet(gSpecialVar_0x8004);
}
u16 GetWeekCount(void)
{
u16 weekCount = gLocalTime.days / 7;
if (weekCount > 9999)
weekCount = 9999;
return weekCount;
}
u8 GetLeadMonFriendshipScore(void)
{
return GetMonFriendshipScore(&gPlayerParty[GetLeadMonIndex()]);
}
static void CB2_FieldShowRegionMap(void)
{
FieldInitRegionMap(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
void FieldShowRegionMap(void)
{
SetMainCallback2(CB2_FieldShowRegionMap);
}
static bool8 IsPlayerInFrontOfPC(void)
{
u16 x, y;
u16 tileInFront;
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
tileInFront = MapGridGetMetatileIdAt(x, y);
return (tileInFront == METATILE_BrendansMaysHouse_BrendanPC_On
|| tileInFront == METATILE_BrendansMaysHouse_BrendanPC_Off
|| tileInFront == METATILE_BrendansMaysHouse_MayPC_On
|| tileInFront == METATILE_BrendansMaysHouse_MayPC_Off
|| tileInFront == METATILE_Building_PC_On
|| tileInFront == METATILE_Building_PC_Off);
}
// Task data for Task_PCTurnOnEffect and Task_LotteryCornerComputerEffect
#define tPaused data[0] // Never set
#define tTaskId data[1]
#define tFlickerCount data[2]
#define tTimer data[3]
#define tIsScreenOn data[4]
// For this special, gSpecialVar_0x8004 is expected to be some PC_LOCATION_* value.
void DoPCTurnOnEffect(void)
{
if (FuncIsActiveTask(Task_PCTurnOnEffect) != TRUE && IsPlayerInFrontOfPC() == TRUE)
{
u8 taskId = CreateTask(Task_PCTurnOnEffect, 8);
gTasks[taskId].tPaused = FALSE;
gTasks[taskId].tTaskId = taskId;
gTasks[taskId].tFlickerCount = 0;