forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript_pokemon_util.c
668 lines (569 loc) · 21.8 KB
/
script_pokemon_util.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
#include "global.h"
#include "battle.h"
#include "battle_gfx_sfx_util.h"
#include "berry.h"
#include "data.h"
#include "daycare.h"
#include "decompress.h"
#include "event_data.h"
#include "international_string_util.h"
#include "item.h"
#include "link.h"
#include "link_rfu.h"
#include "main.h"
#include "menu.h"
#include "overworld.h"
#include "palette.h"
#include "party_menu.h"
#include "pokedex.h"
#include "pokemon.h"
#include "pokemon_storage_system.h"
#include "random.h"
#include "script.h"
#include "sprite.h"
#include "string_util.h"
#include "tv.h"
#include "wild_encounter.h"
#include "constants/abilities.h"
#include "constants/items.h"
#include "constants/battle_frontier.h"
#include "field_player_avatar.h"
static void CB2_ReturnFromChooseHalfParty(void);
static void CB2_ReturnFromChooseBattleFrontierParty(void);
static void HealPlayerBoxes(void);
void HealPlayerParty(void)
{
u32 i;
for (i = 0; i < gPlayerPartyCount; i++)
HealPokemon(&gPlayerParty[i]);
if (OW_PC_HEAL >= GEN_8)
HealPlayerBoxes();
// Recharge Tera Orb, if possible.
if (B_FLAG_TERA_ORB_CHARGED != 0 && CheckBagHasItem(ITEM_TERA_ORB, 1))
FlagSet(B_FLAG_TERA_ORB_CHARGED);
}
static void HealPlayerBoxes(void)
{
int boxId, boxPosition;
struct BoxPokemon *boxMon;
for (boxId = 0; boxId < TOTAL_BOXES_COUNT; boxId++)
{
for (boxPosition = 0; boxPosition < IN_BOX_COUNT; boxPosition++)
{
boxMon = &gPokemonStoragePtr->boxes[boxId][boxPosition];
if (GetBoxMonData(boxMon, MON_DATA_SANITY_HAS_SPECIES))
HealBoxPokemon(boxMon);
}
}
}
u8 ScriptGiveEgg(u16 species)
{
struct Pokemon mon;
u8 isEgg;
CreateEgg(&mon, species, TRUE);
isEgg = TRUE;
SetMonData(&mon, MON_DATA_IS_EGG, &isEgg);
return GiveMonToPlayer(&mon);
}
void HasEnoughMonsForDoubleBattle(void)
{
switch (GetMonsStateToDoubles())
{
case PLAYER_HAS_TWO_USABLE_MONS:
gSpecialVar_Result = PLAYER_HAS_TWO_USABLE_MONS;
break;
case PLAYER_HAS_ONE_MON:
gSpecialVar_Result = PLAYER_HAS_ONE_MON;
break;
case PLAYER_HAS_ONE_USABLE_MON:
gSpecialVar_Result = PLAYER_HAS_ONE_USABLE_MON;
break;
}
}
static bool8 CheckPartyMonHasHeldItem(u16 item)
{
int i;
for(i = 0; i < PARTY_SIZE; i++)
{
u16 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES_OR_EGG);
if (species != SPECIES_NONE && species != SPECIES_EGG && GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM) == item)
return TRUE;
}
return FALSE;
}
bool8 DoesPartyHaveEnigmaBerry(void)
{
bool8 hasItem = CheckPartyMonHasHeldItem(ITEM_ENIGMA_BERRY_E_READER);
if (hasItem == TRUE)
GetBerryNameByBerryType(ItemIdToBerryType(ITEM_ENIGMA_BERRY_E_READER), gStringVar1);
return hasItem;
}
void CreateScriptedWildMon(u16 species, u8 level, u16 item)
{
u8 heldItem[2];
ZeroEnemyPartyMons();
if (OW_SYNCHRONIZE_NATURE > GEN_3)
CreateMonWithNature(&gEnemyParty[0], species, level, USE_RANDOM_IVS, PickWildMonNature());
else
CreateMon(&gEnemyParty[0], species, level, USE_RANDOM_IVS, 0, 0, OT_ID_PLAYER_ID, 0);
if (item)
{
heldItem[0] = item;
heldItem[1] = item >> 8;
SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, heldItem);
}
}
void CreateScriptedDoubleWildMon(u16 species1, u8 level1, u16 item1, u16 species2, u8 level2, u16 item2)
{
u8 heldItem1[2];
u8 heldItem2[2];
ZeroEnemyPartyMons();
if (OW_SYNCHRONIZE_NATURE > GEN_3)
CreateMonWithNature(&gEnemyParty[0], species1, level1, 32, PickWildMonNature());
else
CreateMon(&gEnemyParty[0], species1, level1, 32, 0, 0, OT_ID_PLAYER_ID, 0);
if (item1)
{
heldItem1[0] = item1;
heldItem1[1] = item1 >> 8;
SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, heldItem1);
}
if (OW_SYNCHRONIZE_NATURE > GEN_3)
CreateMonWithNature(&gEnemyParty[1], species2, level2, 32, PickWildMonNature());
else
CreateMon(&gEnemyParty[1], species2, level2, 32, 0, 0, OT_ID_PLAYER_ID, 0);
if (item2)
{
heldItem2[0] = item2;
heldItem2[1] = item2 >> 8;
SetMonData(&gEnemyParty[1], MON_DATA_HELD_ITEM, heldItem2);
}
}
void ScriptSetMonMoveSlot(u8 monIndex, u16 move, u8 slot)
{
// Allows monIndex to go out of bounds of gPlayerParty. Doesn't occur in vanilla
#ifdef BUGFIX
if (monIndex >= PARTY_SIZE)
#else
if (monIndex > PARTY_SIZE)
#endif
monIndex = gPlayerPartyCount - 1;
SetMonMoveSlot(&gPlayerParty[monIndex], move, slot);
}
// Note: When control returns to the event script, gSpecialVar_Result will be
// TRUE if the party selection was successful.
void ChooseHalfPartyForBattle(void)
{
gMain.savedCallback = CB2_ReturnFromChooseHalfParty;
VarSet(VAR_FRONTIER_FACILITY, FACILITY_MULTI_OR_EREADER);
InitChooseHalfPartyForBattle(0);
}
static void CB2_ReturnFromChooseHalfParty(void)
{
switch (gSelectedOrderFromParty[0])
{
case 0:
gSpecialVar_Result = FALSE;
break;
default:
gSpecialVar_Result = TRUE;
break;
}
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
void ChoosePartyForBattleFrontier(void)
{
gMain.savedCallback = CB2_ReturnFromChooseBattleFrontierParty;
InitChooseHalfPartyForBattle(gSpecialVar_0x8004 + 1);
}
static void CB2_ReturnFromChooseBattleFrontierParty(void)
{
switch (gSelectedOrderFromParty[0])
{
case 0:
gSpecialVar_Result = FALSE;
break;
default:
gSpecialVar_Result = TRUE;
break;
}
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
void ReducePlayerPartyToSelectedMons(void)
{
struct Pokemon party[MAX_FRONTIER_PARTY_SIZE];
int i;
CpuFill32(0, party, sizeof party);
// copy the selected Pokémon according to the order.
for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++)
if (gSelectedOrderFromParty[i]) // as long as the order keeps going (did the player select 1 mon? 2? 3?), do not stop
party[i] = gPlayerParty[gSelectedOrderFromParty[i] - 1]; // index is 0 based, not literal
CpuFill32(0, gPlayerParty, sizeof gPlayerParty);
// overwrite the first 4 with the order copied to.
for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++)
gPlayerParty[i] = party[i];
CalculatePlayerPartyCount();
}
void CanHyperTrain(struct ScriptContext *ctx)
{
u32 stat = ScriptReadByte(ctx);
u32 partyIndex = VarGet(ScriptReadHalfword(ctx));
Script_RequestEffects(SCREFF_V1);
if (stat < NUM_STATS
&& partyIndex < PARTY_SIZE
&& !GetMonData(&gPlayerParty[partyIndex], MON_DATA_HYPER_TRAINED_HP + stat)
&& GetMonData(&gPlayerParty[partyIndex], MON_DATA_HP_IV + stat) < MAX_PER_STAT_IVS)
{
gSpecialVar_Result = TRUE;
}
else
{
gSpecialVar_Result = FALSE;
}
}
void HyperTrain(struct ScriptContext *ctx)
{
u32 stat = ScriptReadByte(ctx);
u32 partyIndex = VarGet(ScriptReadHalfword(ctx));
Script_RequestEffects(SCREFF_V1 | SCREFF_SAVE);
if (stat < NUM_STATS && partyIndex < PARTY_SIZE)
{
bool32 data = TRUE;
SetMonData(&gPlayerParty[partyIndex], MON_DATA_HYPER_TRAINED_HP + stat, &data);
CalculateMonStats(&gPlayerParty[partyIndex]);
}
}
void HasGigantamaxFactor(struct ScriptContext *ctx)
{
u32 partyIndex = VarGet(ScriptReadHalfword(ctx));
Script_RequestEffects(SCREFF_V1);
if (partyIndex < PARTY_SIZE)
gSpecialVar_Result = GetMonData(&gPlayerParty[partyIndex], MON_DATA_GIGANTAMAX_FACTOR);
else
gSpecialVar_Result = FALSE;
}
void ToggleGigantamaxFactor(struct ScriptContext *ctx)
{
u32 partyIndex = VarGet(ScriptReadHalfword(ctx));
Script_RequestEffects(SCREFF_V1 | SCREFF_SAVE);
gSpecialVar_Result = FALSE;
if (partyIndex < PARTY_SIZE)
{
bool32 gigantamaxFactor;
if (gSpeciesInfo[SanitizeSpeciesId(GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES))].isMythical)
return;
gigantamaxFactor = GetMonData(&gPlayerParty[partyIndex], MON_DATA_GIGANTAMAX_FACTOR);
gigantamaxFactor = !gigantamaxFactor;
SetMonData(&gPlayerParty[partyIndex], MON_DATA_GIGANTAMAX_FACTOR, &gigantamaxFactor);
gSpecialVar_Result = TRUE;
}
}
void CheckTeraType(struct ScriptContext *ctx)
{
u32 partyIndex = VarGet(ScriptReadHalfword(ctx));
Script_RequestEffects(SCREFF_V1);
gSpecialVar_Result = TYPE_NONE;
if (partyIndex < PARTY_SIZE)
gSpecialVar_Result = GetMonData(&gPlayerParty[partyIndex], MON_DATA_TERA_TYPE);
}
void SetTeraType(struct ScriptContext *ctx)
{
u32 type = ScriptReadByte(ctx);
u32 partyIndex = VarGet(ScriptReadHalfword(ctx));
Script_RequestEffects(SCREFF_V1 | SCREFF_SAVE);
if (type < NUMBER_OF_MON_TYPES && partyIndex < PARTY_SIZE)
SetMonData(&gPlayerParty[partyIndex], MON_DATA_TERA_TYPE, &type);
}
/* Creates a Pokemon via script
* if side/slot are assigned, it will create the mon at the assigned party location
* if slot == PARTY_SIZE, it will give the mon to first available party or storage slot
*/
static u32 ScriptGiveMonParameterized(u8 side, u8 slot, u16 species, u8 level, u16 item, enum PokeBall ball, u8 nature, u8 abilityNum, u8 gender, u8 *evs, u8 *ivs, u16 *moves, bool8 isShiny, bool8 gmaxFactor, u8 teraType, u8 dmaxLevel)
{
u16 nationalDexNum;
int sentToPc;
struct Pokemon mon;
u32 i;
u8 genderRatio = gSpeciesInfo[species].genderRatio;
u16 targetSpecies;
// check whether to use a specific nature or a random one
if (nature >= NUM_NATURES)
{
if (OW_SYNCHRONIZE_NATURE >= GEN_6
&& (gSpeciesInfo[species].eggGroups[0] == EGG_GROUP_NO_EGGS_DISCOVERED || OW_SYNCHRONIZE_NATURE == GEN_7))
nature = PickWildMonNature();
else
nature = Random() % NUM_NATURES;
}
// create a Pokémon with basic data
if ((gender == MON_MALE && genderRatio != MON_FEMALE && genderRatio != MON_GENDERLESS)
|| (gender == MON_FEMALE && genderRatio != MON_MALE && genderRatio != MON_GENDERLESS)
|| (gender == MON_GENDERLESS && genderRatio == MON_GENDERLESS))
CreateMonWithGenderNatureLetter(&mon, species, level, 32, gender, nature, 0);
else
CreateMonWithNature(&mon, species, level, 32, nature);
// shininess
if (P_FLAG_FORCE_SHINY != 0 && FlagGet(P_FLAG_FORCE_SHINY))
isShiny = TRUE;
else if (P_FLAG_FORCE_NO_SHINY != 0 && FlagGet(P_FLAG_FORCE_NO_SHINY))
isShiny = FALSE;
SetMonData(&mon, MON_DATA_IS_SHINY, &isShiny);
// gigantamax factor
SetMonData(&mon, MON_DATA_GIGANTAMAX_FACTOR, &gmaxFactor);
// Dynamax Level
SetMonData(&mon, MON_DATA_DYNAMAX_LEVEL, &dmaxLevel);
// tera type
if (teraType >= NUMBER_OF_MON_TYPES)
teraType = TYPE_NONE;
SetMonData(&mon, MON_DATA_TERA_TYPE, &teraType);
// EV and IV
for (i = 0; i < NUM_STATS; i++)
{
// EV
if (evs[i] <= MAX_PER_STAT_EVS)
SetMonData(&mon, MON_DATA_HP_EV + i, &evs[i]);
// IV
if (ivs[i] <= MAX_PER_STAT_IVS)
SetMonData(&mon, MON_DATA_HP_IV + i, &ivs[i]);
}
CalculateMonStats(&mon);
// moves
for (i = 0; i < MAX_MON_MOVES; i++)
{
if (moves[0] == MOVE_NONE)
break;
if (moves[i] >= MOVES_COUNT)
continue;
SetMonMoveSlot(&mon, moves[i], i);
}
// ability
if (abilityNum == NUM_ABILITY_PERSONALITY)
{
abilityNum = GetMonData(&mon, MON_DATA_PERSONALITY) & 1;
}
else if (abilityNum > NUM_NORMAL_ABILITY_SLOTS || GetAbilityBySpecies(species, abilityNum) == ABILITY_NONE)
{
do {
abilityNum = Random() % NUM_ABILITY_SLOTS; // includes hidden abilities
} while (GetAbilityBySpecies(species, abilityNum) == ABILITY_NONE);
}
SetMonData(&mon, MON_DATA_ABILITY_NUM, &abilityNum);
// ball
if (ball > POKEBALL_COUNT)
ball = BALL_POKE;
SetMonData(&mon, MON_DATA_POKEBALL, &ball);
// held item
SetMonData(&mon, MON_DATA_HELD_ITEM, &item);
// In case a mon with a form changing item is given. Eg: SPECIES_ARCEUS_NORMAL with ITEM_SPLASH_PLATE will transform into SPECIES_ARCEUS_WATER upon gifted.
targetSpecies = GetFormChangeTargetSpecies(&mon, FORM_CHANGE_ITEM_HOLD, 0);
if (targetSpecies != SPECIES_NONE)
SetMonData(&mon, MON_DATA_SPECIES, &targetSpecies);
// assign OT name and gender
SetMonData(&mon, MON_DATA_OT_NAME, gSaveBlock2Ptr->playerName);
SetMonData(&mon, MON_DATA_OT_GENDER, &gSaveBlock2Ptr->playerGender);
if (slot < PARTY_SIZE)
{
if (side == 0)
CopyMon(&gPlayerParty[slot], &mon, sizeof(struct Pokemon));
else
CopyMon(&gEnemyParty[slot], &mon, sizeof(struct Pokemon));
sentToPc = MON_GIVEN_TO_PARTY;
}
else
{
// find empty party slot to decide whether the Pokémon goes to the Player's party or the storage system.
for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) == SPECIES_NONE)
break;
}
if (i >= PARTY_SIZE)
{
sentToPc = CopyMonToPC(&mon);
}
else
{
sentToPc = MON_GIVEN_TO_PARTY;
CopyMon(&gPlayerParty[i], &mon, sizeof(mon));
gPlayerPartyCount = i + 1;
}
}
if (side == 0)
{
// set pokédex flags
nationalDexNum = SpeciesToNationalPokedexNum(species);
if (sentToPc != MON_CANT_GIVE)
{
GetSetPokedexFlag(nationalDexNum, FLAG_SET_SEEN);
GetSetPokedexFlag(nationalDexNum, FLAG_SET_CAUGHT);
}
}
return sentToPc;
}
u32 ScriptGiveMon(u16 species, u8 level, u16 item)
{
u8 evs[NUM_STATS] = {0, 0, 0, 0, 0, 0};
u8 ivs[NUM_STATS] = {MAX_PER_STAT_IVS + 1, MAX_PER_STAT_IVS + 1, MAX_PER_STAT_IVS + 1, // We pass "MAX_PER_STAT_IVS + 1" here to ensure that
MAX_PER_STAT_IVS + 1, MAX_PER_STAT_IVS + 1, MAX_PER_STAT_IVS + 1}; // ScriptGiveMonParameterized won't touch the stats' IV.
u16 moves[MAX_MON_MOVES] = {MOVE_NONE, MOVE_NONE, MOVE_NONE, MOVE_NONE};
return ScriptGiveMonParameterized(0, PARTY_SIZE, species, level, item, ITEM_POKE_BALL, NUM_NATURES, NUM_ABILITY_PERSONALITY, MON_GENDERLESS, evs, ivs, moves, FALSE, FALSE, NUMBER_OF_MON_TYPES, 0);
}
#define PARSE_FLAG(n, default_) (flags & (1 << (n))) ? VarGet(ScriptReadHalfword(ctx)) : (default_)
/* Give or create a mon to either player or opponent
*/
void ScrCmd_createmon(struct ScriptContext *ctx)
{
u8 side = ScriptReadByte(ctx);
u8 slot = ScriptReadByte(ctx);
u16 species = VarGet(ScriptReadHalfword(ctx));
u8 level = VarGet(ScriptReadHalfword(ctx));
u32 flags = ScriptReadWord(ctx);
u16 item = PARSE_FLAG(0, ITEM_NONE);
u8 ball = PARSE_FLAG(1, ITEM_POKE_BALL);
u8 nature = PARSE_FLAG(2, NUM_NATURES);
u8 abilityNum = PARSE_FLAG(3, NUM_ABILITY_PERSONALITY);
u8 gender = PARSE_FLAG(4, MON_GENDERLESS); // TODO: Find a better way to assign a random gender.
u8 hpEv = PARSE_FLAG(5, 0);
u8 atkEv = PARSE_FLAG(6, 0);
u8 defEv = PARSE_FLAG(7, 0);
u8 speedEv = PARSE_FLAG(8, 0);
u8 spAtkEv = PARSE_FLAG(9, 0);
u8 spDefEv = PARSE_FLAG(10, 0);
u8 hpIv = Random() % (MAX_PER_STAT_IVS + 1);
u8 atkIv = Random() % (MAX_PER_STAT_IVS + 1);
u8 defIv = Random() % (MAX_PER_STAT_IVS + 1);
u8 speedIv = Random() % (MAX_PER_STAT_IVS + 1);
u8 spAtkIv = Random() % (MAX_PER_STAT_IVS + 1);
u8 spDefIv = Random() % (MAX_PER_STAT_IVS + 1);
// Perfect IV calculation
u32 i;
u8 availableIVs[NUM_STATS];
u8 selectedIvs[NUM_STATS];
if (gSpeciesInfo[species].perfectIVCount != 0)
{
// Initialize a list of IV indices.
for (i = 0; i < NUM_STATS; i++)
availableIVs[i] = i;
// Select the IVs that will be perfected.
for (i = 0; i < NUM_STATS && i < gSpeciesInfo[species].perfectIVCount; i++)
{
u8 index = Random() % (NUM_STATS - i);
selectedIvs[i] = availableIVs[index];
RemoveIVIndexFromList(availableIVs, index);
}
for (i = 0; i < NUM_STATS && i < gSpeciesInfo[species].perfectIVCount; i++)
{
switch (selectedIvs[i])
{
case STAT_HP: hpIv = MAX_PER_STAT_IVS; break;
case STAT_ATK: atkIv = MAX_PER_STAT_IVS; break;
case STAT_DEF: defIv = MAX_PER_STAT_IVS; break;
case STAT_SPEED: speedIv = MAX_PER_STAT_IVS; break;
case STAT_SPATK: spAtkIv = MAX_PER_STAT_IVS; break;
case STAT_SPDEF: spDefIv = MAX_PER_STAT_IVS; break;
}
}
}
hpIv = PARSE_FLAG(11, hpIv);
atkIv = PARSE_FLAG(12, atkIv);
defIv = PARSE_FLAG(13, defIv);
speedIv = PARSE_FLAG(14, speedIv);
spAtkIv = PARSE_FLAG(15, spAtkIv);
spDefIv = PARSE_FLAG(16, spDefIv);
u16 move1 = PARSE_FLAG(17, MOVE_NONE);
u16 move2 = PARSE_FLAG(18, MOVE_NONE);
u16 move3 = PARSE_FLAG(19, MOVE_NONE);
u16 move4 = PARSE_FLAG(20, MOVE_NONE);
bool8 isShiny = PARSE_FLAG(21, FALSE);
bool8 gmaxFactor = PARSE_FLAG(22, FALSE);
u8 teraType = PARSE_FLAG(23, NUMBER_OF_MON_TYPES);
u8 dmaxLevel = PARSE_FLAG(24, 0);
u8 evs[NUM_STATS] = {hpEv, atkEv, defEv, speedEv, spAtkEv, spDefEv};
u8 ivs[NUM_STATS] = {hpIv, atkIv, defIv, speedIv, spAtkIv, spDefIv};
u16 moves[MAX_MON_MOVES] = {move1, move2, move3, move4};
if (side == 0)
Script_RequestEffects(SCREFF_V1 | SCREFF_SAVE);
else
Script_RequestEffects(SCREFF_V1);
gSpecialVar_Result = ScriptGiveMonParameterized(side, slot, species, level, item, ball, nature, abilityNum, gender, evs, ivs, moves, isShiny, gmaxFactor, teraType, dmaxLevel);
}
#undef PARSE_FLAG
void ScrCmd_setpartylevel(struct ScriptContext *ctx)
{
u8 level = VarGet(ScriptReadHalfword(ctx));
s32 i;
for (i = 0; i < gPlayerPartyCount; i++)
{
u32 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL);
SetMonData(&gPlayerParty[i], MON_DATA_LEVEL, &level);
SetMonData(&gPlayerParty[i], MON_DATA_EXP, &gExperienceTables[gSpeciesInfo[species].growthRate][level]);
CalculateMonStats(&gPlayerParty[i]);
}
}
void ScrCmd_addbp(struct ScriptContext *ctx)
{
u8 bp = VarGet(ScriptReadHalfword(ctx));
ConvertIntToDecimalStringN(gStringVar1, bp, STR_CONV_MODE_LEFT_ALIGN, 3);
if (gSaveBlock2Ptr->frontier.battlePoints + bp > MAX_BATTLE_FRONTIER_POINTS)
gSaveBlock2Ptr->frontier.battlePoints = MAX_BATTLE_FRONTIER_POINTS;
else
gSaveBlock2Ptr->frontier.battlePoints = gSaveBlock2Ptr->frontier.battlePoints + bp;
}
void ScrCmd_copygamestat(struct ScriptContext *ctx)
{
u8 stat = VarGet(ScriptReadHalfword(ctx));
ConvertIntToDecimalStringN(gStringVar1, GetGameStat(stat), STR_CONV_MODE_LEFT_ALIGN, 4);
}
void Script_GetChosenMonOffensiveEVs(void)
{
ConvertIntToDecimalStringN(gStringVar1, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_ATK_EV), STR_CONV_MODE_LEFT_ALIGN, 3);
ConvertIntToDecimalStringN(gStringVar2, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPATK_EV), STR_CONV_MODE_LEFT_ALIGN, 3);
ConvertIntToDecimalStringN(gStringVar3, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPEED_EV), STR_CONV_MODE_LEFT_ALIGN, 3);
}
void Script_GetChosenMonDefensiveEVs(void)
{
ConvertIntToDecimalStringN(gStringVar1, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_HP_EV), STR_CONV_MODE_LEFT_ALIGN, 3);
ConvertIntToDecimalStringN(gStringVar2, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_DEF_EV), STR_CONV_MODE_LEFT_ALIGN, 3);
ConvertIntToDecimalStringN(gStringVar3, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPDEF_EV), STR_CONV_MODE_LEFT_ALIGN, 3);
}
void Script_GetChosenMonOffensiveIVs(void)
{
ConvertIntToDecimalStringN(gStringVar1, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_ATK_IV), STR_CONV_MODE_LEFT_ALIGN, 3);
ConvertIntToDecimalStringN(gStringVar2, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPATK_IV), STR_CONV_MODE_LEFT_ALIGN, 3);
ConvertIntToDecimalStringN(gStringVar3, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPEED_IV), STR_CONV_MODE_LEFT_ALIGN, 3);
}
void Script_GetChosenMonDefensiveIVs(void)
{
ConvertIntToDecimalStringN(gStringVar1, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_HP_IV), STR_CONV_MODE_LEFT_ALIGN, 3);
ConvertIntToDecimalStringN(gStringVar2, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_DEF_IV), STR_CONV_MODE_LEFT_ALIGN, 3);
ConvertIntToDecimalStringN(gStringVar3, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPDEF_IV), STR_CONV_MODE_LEFT_ALIGN, 3);
}
void Script_SetStatus1(struct ScriptContext *ctx)
{
u32 status1 = VarGet(ScriptReadHalfword(ctx));
u32 slot = VarGet(ScriptReadHalfword(ctx));
Script_RequestEffects(SCREFF_V1 | SCREFF_SAVE);
if (slot >= PARTY_SIZE)
{
u16 species;
for (slot = 0; slot < PARTY_SIZE; slot++)
{
species = GetMonData(&gPlayerParty[slot], MON_DATA_SPECIES);
if (species != SPECIES_NONE
&& species != SPECIES_EGG
&& GetMonData(&gPlayerParty[slot], MON_DATA_HP) != 0)
SetMonData(&gPlayerParty[slot], MON_DATA_STATUS, &status1);
}
}
else
{
SetMonData(&gPlayerParty[slot], MON_DATA_STATUS, &status1);
}
}
void ScrCmd_SetKrokorokDisguise()
{
if (gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_ON_FOOT)
SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_KROKOROK);
else
SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT);
}