diff --git a/README.md b/README.md index facd5f5626..5330e40981 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,16 @@ pokeemerald-expansion is a decomp hack base project based off pret's [pokeemerald](https://github.com/pret/pokeemerald) decompilation project. It's recommended that any new projects that plan on using it, to clone this repository instead of pret's vanilla repository, as we regurlarly incorporate pret's documentation changes. This is ***NOT*** a standalone romhack, and as such, most features will be unavailable and/or unbalanced if played as is. +## Using pokeemerald-expansion + If you use pokeemerald-expansion in your hack, please add RHH (Rom Hacking Hideout) to your credits list. Optionally, you can list the version used, so it can help players know what features to expect. You can phrase it as the following: ``` Based off RHH's pokeemerald-expansion 1.9.3 https://github.com/rh-hideout/pokeemerald-expansion/ ``` +Please follow the instructions in `INSTALL.md` to get pokeemerald-expansion set up on your machine. + ## What features are included? - ***IMPORTANT*❗❗ Read through these to learn what features you can toggle**: - [Battle configurations](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/include/config/battle.h) diff --git a/data/battle_anim_scripts.s b/data/battle_anim_scripts.s index 643ee2cd0e..07d172cdf8 100644 --- a/data/battle_anim_scripts.s +++ b/data/battle_anim_scripts.s @@ -3666,7 +3666,7 @@ gBattleAnimMove_DarkVoid:: loopsewithpan SE_M_CONFUSE_RAY, SOUND_PAN_ATTACKER, 5, 2 delay 48 createsprite gSlideMonToOffsetSpriteTemplate, ANIM_ATTACKER, 2, ANIM_TARGET, -768, 21, 0, 112 @Last is duration - createsprite gSlideMonToOffsetSpriteTemplate, ANIM_ATTACKER, 2, ANIM_DEF_PARTNER, -768, 21, 0, 112 @Last is duration + createsprite gSlideMonToOffsetPartnerSpriteTemplate, ANIM_ATTACKER, 2, ANIM_DEF_PARTNER, -768, 21, 0, 112 @Last is duration delay 64 invisible ANIM_TARGET invisible ANIM_DEF_PARTNER @@ -3674,7 +3674,7 @@ gBattleAnimMove_DarkVoid:: createsprite gDarkVoidPurpleStarsTemplate, ANIM_ATTACKER, 2, 0, 0, ANIM_DEF_PARTNER, 0, 32, 60 waitforvisualfinish createsprite gSlideMonToOriginalPosSpriteTemplate, ANIM_ATTACKER, 2, ANIM_TARGET, 0, 16 - createsprite gSlideMonToOriginalPosSpriteTemplate, ANIM_ATTACKER, 2, ANIM_DEF_PARTNER, 0, 16 + createsprite gSlideMonToOriginalPosPartnerSpriteTemplate, ANIM_ATTACKER, 2, ANIM_DEF_PARTNER, 0, 16 delay 32 call UnsetPsychicBg visible ANIM_TARGET @@ -10093,7 +10093,6 @@ gBattleAnimMove_FloralHealing:: loadspritegfx ANIM_TAG_ORBS @circles loadspritegfx ANIM_TAG_PINK_PETAL @pink particles monbg ANIM_ATTACKER - monbg ANIM_TARGET playsewithpan SE_M_DETECT, SOUND_PAN_ATTACKER call CIRCLES_LEAVES call CIRCLES_LEAVES @@ -10101,6 +10100,7 @@ gBattleAnimMove_FloralHealing:: panse SE_M_COMET_PUNCH, SOUND_PAN_ATTACKER, SOUND_PAN_TARGET, 0x2, 0x0 playsewithpan SE_M_TWISTER, 0x0 createsprite gSweetScentPetalSpriteTemplate, ANIM_ATTACKER, 2, 0x46, 0x1, 0x40 + clearmonbg ANIM_ATTACKER delay 0x2 createsprite gFloralHealingWindLeavesTemplate, ANIM_ATTACKER, 2, 0x3c, 0x0, 0x40 delay 0x2 @@ -10123,6 +10123,7 @@ gBattleAnimMove_FloralHealing:: createsprite gSweetScentPetalSpriteTemplate, ANIM_ATTACKER, 2, 0x55, 0x0, 0x78 delay 0x2 loopsewithpan SE_M_POISON_POWDER, SOUND_PAN_TARGET, 0x12, 0xa + monbg ANIM_TARGET call FloralHealingSpores call FloralHealingSpores call FloralHealingSpores @@ -10133,7 +10134,6 @@ gBattleAnimMove_FloralHealing:: createsprite gGrantingStarsSpriteTemplate, ANIM_ATTACKER, 16, 0xc, 0xfffb, 0x1, 0x0, 0x20, 0x3c, 0x1 waitforvisualfinish clearmonbg ANIM_TARGET - clearmonbg ANIM_ATTACKER end FloralHealingSpores: createsprite gFloralHealingFlowerTemplate, ANIM_ATTACKER, 2, 0x0, 0xffec, 0x55, 0x50, 0x0 @@ -33527,7 +33527,7 @@ gBattleAnimMove_ClangorousSoulblaze:: delay 0x2 createvisualtask AnimTask_StartSlidingBg, 0x5, 0x0, 0xFFE0, 0x1, 0xffff createsprite gSlideMonToOffsetSpriteTemplate, ANIM_ATTACKER, 2, ANIM_TARGET, 0xfd00, 0xa, 0x0, 0x2a - createsprite gSlideMonToOffsetSpriteTemplate, ANIM_ATTACKER, 2, ANIM_DEF_PARTNER, 0xfd00, 0xa, 0x0, 0x2a + createsprite gSlideMonToOffsetPartnerSpriteTemplate, ANIM_ATTACKER, 2, ANIM_DEF_PARTNER, 0xfd00, 0xa, 0x0, 0x2a delay 0x20 createvisualtask AnimTask_StartSlidingBg, 0x5, 0x0, 0x20, 0x1, 0xffff delay 0xC @@ -33719,7 +33719,7 @@ FINISH_SOULBLAZE: call ResetFromWhiteScreen blendoff createsprite gSlideMonToOriginalPosSpriteTemplate, ANIM_ATTACKER, 2, ANIM_TARGET, 0x0, 0x10 - createsprite gSlideMonToOriginalPosSpriteTemplate, ANIM_ATTACKER, 2, ANIM_DEF_PARTNER, 0x0, 0x10 + createsprite gSlideMonToOriginalPosPartnerSpriteTemplate, ANIM_ATTACKER, 2, ANIM_DEF_PARTNER, 0x0, 0x10 waitforvisualfinish end ClangorousSoulblazeEnergySwirl: diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 007313119a..b1b35d1af6 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2401,7 +2401,6 @@ BattleScript_EffectHealingWish:: storehealingwish BS_ATTACKER .if B_HEALING_WISH_SWITCH <= GEN_4 openpartyscreen BS_ATTACKER, BattleScript_EffectHealingWishEnd - switchoutabilities BS_ATTACKER waitstate switchhandleorder BS_ATTACKER, 2 returnatktoball @@ -5754,7 +5753,6 @@ BattleScript_PrintFullBox:: BattleScript_ActionSwitch:: hpthresholds2 BS_ATTACKER - saveattacker printstring STRINGID_RETURNMON jumpifbattletype BATTLE_TYPE_DOUBLE, BattleScript_PursuitSwitchDmgSetMultihit setmultihit 1 @@ -5772,7 +5770,6 @@ BattleScript_DoSwitchOut:: switchoutabilities BS_ATTACKER updatedynamax waitstate - restoreattacker returnatktoball waitstate drawpartystatussummary BS_ATTACKER @@ -9621,7 +9618,9 @@ BattleScript_EjectButtonActivates:: removeitem BS_SCRIPTING makeinvisible BS_SCRIPTING openpartyscreen BS_SCRIPTING, BattleScript_EjectButtonEnd + copybyte sSAVED_BATTLER, sBATTLER switchoutabilities BS_SCRIPTING + copybyte sBATTLER, sSAVED_BATTLER waitstate switchhandleorder BS_SCRIPTING 0x2 returntoball BS_SCRIPTING, FALSE @@ -9718,6 +9717,7 @@ BattleScript_PastelVeilEnd: end3 BattleScript_NeutralizingGasExits:: + saveattacker savetarget pause B_WAIT_TIME_SHORT printstring STRINGID_NEUTRALIZINGGASOVER @@ -9727,6 +9727,7 @@ BattleScript_NeutralizingGasExitsLoop: switchinabilities BS_TARGET addbyte gBattlerTarget, 1 jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_NeutralizingGasExitsLoop + restoreattacker restoretarget return diff --git a/docs/tutorials/how_to_new_pokemon_1_10_0.md b/docs/tutorials/how_to_new_pokemon_1_10_0.md new file mode 100644 index 0000000000..f6eaedee99 --- /dev/null +++ b/docs/tutorials/how_to_new_pokemon_1_10_0.md @@ -0,0 +1,1163 @@ + +This is a modified version of [the original tutorial about adding new Pokémon species available in Pokeemerald's wiki](https://github.com/pret/pokeemerald/wiki/How-to-add-a-new-Pokémon-species). + +Despite the persistent rumors about an incredibly strong third form of Mew hiding somewhere, it actually wasn't possible to catch it... OR WAS IT? +In this tutorial, we will add a new Pokémon species to the game. + +## IMPORTANT: This tutorial applies to 1.10.x versions. +- [Version 1.9.x](how_to_new_pokemon_1_9_0.md) +- [Version 1.8.x](how_to_new_pokemon_1_8_0.md) +- [Version 1.7.x](how_to_new_pokemon_1_7_0.md) +- [Version 1.6.x](how_to_new_pokemon_1_6_0.md) + +# Changes compared to vanilla +The main things that the Expansion changes are listed here. +* Still Front Pics *(`gMonStillFrontPic_YourPokemon`)* and by extension `src/anim_mon_front_pics.c` have been removed. +* `src/data/pokemon/cry_ids.h` doesn't exist anymore. +* You have 6 icon palettes available instead of the base 3. +* Most tables that use `SPECIES_x` as indexes have been moved to `gSpeciesInfo`. + +# Content +* [Useful resources](#useful-resources) +* [The Data - Part 1](#the-data---part-1) + * [1. Declare a species constant](#1-Declare-a-species-constant) + * [2. `SpeciesInfo`'s structure](#2-speciesinfos-structure) + * [3. Define its basic species information](#3-define-its-basic-species-information) + * [4. Species Name](#4-species-name) + * [5. Define its cry](#5-define-its-cry) + * [6. Define its Pokédex entry](#6-define-its-pokédex-entry) +* [The Graphics](#the-graphics) + * [1. Edit the sprites](#1-edit-the-sprites) + * [2. Add the sprites to the rom](#2-add-the-sprites-to-the-rom) + * [3. Add the animations to the rom](#3-add-the-animations-to-the-rom) + * [4. Linking graphic information to our Pokémon](#4-linking-graphic-information-to-our-pokémon) +* [The Data - Part 2](#the-data---part-2) + * [1. Species Flags](#1-species-flags) + * [2. Delimit the moveset](#2-delimit-the-moveset) + * [3. Define the Evolutions](#3-define-the-evolutions) + * [4. Make it appear!](#4-make-it-appear) +* [Optional data](#optional-data) + * [1. Form tables](#1-form-tables) + * [2. Form change tables](#2-form-change-tables) + * [3. Gender differences](#3-gender-differences) + * [4. Overworld Data](#4-overworld-data) + +# Useful resources +You can open a sprite debug menu by pressing `Select` in a Pokémon's summary screen outside of battle. + +![mGBA_6WOo1TSlsn](https://github.com/rh-hideout/pokeemerald-expansion/assets/2904965/0c625cd8-8f89-4bc8-a285-b10a420a8f6d) + + +# The Data - Part 1 + +Our plan is as simple as it is brilliant: clone Mewtwo... and make it even stronger! + +## 1. Declare a species constant + +Our first step towards creating a new digital lifeform is to define its own species constant. + +Edit [include/constants/species.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/include/constants/species.h): + +```diff + #define SPECIES_NONE 0 + #define SPECIES_BULBASAUR 1 + ... + #define SPECIES_MIMIKYU_BUSTED_TOTEM 1523 + #define SPECIES_MIMIKYU_TOTEM_BUSTED SPECIES_MIMIKYU_BUSTED_TOTEM ++#define SPECIES_MEWTHREE 1524 + +-#define SPECIES_EGG (SPECIES_MIMIKYU_BUSTED_TOTEM + 1) ++#define SPECIES_EGG (SPECIES_MEWTHREE + 1) + + #define NUM_SPECIES SPECIES_EGG +``` +This number is stored in a Pokémon's save structure. These should generally never change, otherwise your saved Pokémon species will change as well. + +We add this at the end so that no existing species change Id and so that we don't have to renumber everything after it. + +Now, let's see how it looks in-game! + +![image](https://github.com/rh-hideout/pokeemerald-expansion/assets/2904965/dc15b0ba-a4bd-4f4e-9658-2dff73a11f79) + +Hmmm, something's not right... + +Oh, I know! We need to add the rest of the data! Normally, the vanilla game would crash if we try to look up anything about Mewthree in this state, but the expansion defaults all of its data to `SPECIES_NONE`. + +Now, let's see what needs to be done. + +## 2. `SpeciesInfo`'s structure +Now, to better understand Mewthree, we also need to understand Mew. Let's look at its data. +```diff + [SPECIES_MEW] = + { + .baseHP = 100, + .baseAttack = 100, + .baseDefense = 100, + .baseSpeed = 100, + .baseSpAttack = 100, + .baseSpDefense = 100, + .types = MON_TYPES(TYPE_PSYCHIC), + .catchRate = 45, + #if P_UPDATED_EXP_YIELDS >= GEN_8 + .expYield = 300, + #elif P_UPDATED_EXP_YIELDS >= GEN_5 + .expYield = 270, + #else + .expYield = 64, + #endif + .evYield_HP = 3, + .itemCommon = ITEM_LUM_BERRY, + .itemRare = ITEM_LUM_BERRY, + .genderRatio = MON_GENDERLESS, + .eggCycles = 120, + .friendship = 100, + .growthRate = GROWTH_MEDIUM_SLOW, + .eggGroups = MON_EGG_GROUPS(EGG_GROUP_NO_EGGS_DISCOVERED), + .abilities = { ABILITY_SYNCHRONIZE, ABILITY_NONE, ABILITY_NONE }, + .bodyColor = BODY_COLOR_PINK, + .speciesName = _("Mew"), + .cryId = CRY_MEW, + .natDexNum = NATIONAL_DEX_MEW, + .categoryName = _("New Species"), + .height = 4, + .weight = 40, + .description = COMPOUND_STRING( + "A Mew is said to possess the genes of all\n" + "Pokémon. It is capable of making itself\n" + "invisible at will, so it entirely avoids\n" + "notice even if it approaches people."), + .pokemonScale = 457, + .pokemonOffset = -2, + .trainerScale = 256, + .trainerOffset = 0, + .frontPic = gMonFrontPic_Mew, + .frontPicSize = P_GBA_STYLE_SPECIES_GFX ? MON_COORDS_SIZE(40, 40) : MON_COORDS_SIZE(64, 48), + .frontPicYOffset = P_GBA_STYLE_SPECIES_GFX ? 13 : 9, + .frontAnimFrames = sAnims_Mew, + .frontAnimId = P_GBA_STYLE_SPECIES_GFX ? ANIM_SWING_CONVEX : ANIM_ZIGZAG_SLOW, + .enemyMonElevation = P_GBA_STYLE_SPECIES_GFX ? 8 : 11, + .backPic = gMonBackPic_Mew, + .backPicSize = P_GBA_STYLE_SPECIES_GFX ? MON_COORDS_SIZE(48, 48) : MON_COORDS_SIZE(64, 64), + .backPicYOffset = P_GBA_STYLE_SPECIES_GFX ? 8 : 0, + .backAnimId = BACK_ANIM_CONCAVE_ARC_SMALL, + .palette = gMonPalette_Mew, + .shinyPalette = gMonShinyPalette_Mew, + .iconSprite = gMonIcon_Mew, + .iconPalIndex = 0, + SHADOW(0, 13, SHADOW_SIZE_S) + FOOTPRINT(Mew) + OVERWORLD( + sPicTable_Mew, + SIZE_32x32, + SHADOW_SIZE_M, + TRACKS_NONE, + gOverworldPalette_Mew, + gShinyOverworldPalette_Mew + ) + .isMythical = TRUE, + .isFrontierBanned = TRUE, + .perfectIVCount = LEGENDARY_PERFECT_IV_COUNT, + .levelUpLearnset = sMewLevelUpLearnset, + .teachableLearnset = sMewTeachableLearnset, + }, +``` + +That's a lot of stuff! But don't worry, we'll go through it step by step throughout the tutorial +(and it's miles better than having this same data through 20+ files like it used to be). + +We'll start by adding the self-explanatory data that's also present in pret's vanilla structure: + +## 3. Define its basic species information +Edit [src/data/pokemon/species_info.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/pokemon/species_info.h): +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + [SPECIES_NONE] = {0}, + ... + + [SPECIES_EGG] = + { + FRONT_PIC(Egg, 24, 24), + .frontPicYOffset = 20, + .backPic = gMonFrontPic_Egg, + .backPicSize = MON_COORDS_SIZE(24, 24), + .backPicYOffset = 20, + .palette = gMonPalette_Egg, + .shinyPalette = gMonPalette_Egg, + ICON(Egg, 1), + }, + ++ [SPECIES_MEWTHREE] = ++ { ++ .baseHP = 106, ++ .baseAttack = 150, ++ .baseDefense = 70, ++ .baseSpeed = 140, ++ .baseSpAttack = 194, ++ .baseSpDefense = 120, ++ .types = MON_TYPES(TYPE_PSYCHIC), ++ .catchRate = 3, ++ .expYield = 255, ++ .evYield_SpAttack = 3, ++ .genderRatio = MON_GENDERLESS, ++ .eggCycles = 120, ++ .friendship = 0, ++ .growthRate = GROWTH_SLOW, ++ .eggGroups = MON_EGG_GROUPS(EGG_GROUP_NO_EGGS_DISCOVERED), ++ .abilities = { ABILITY_INSOMNIA, ABILITY_NONE, ABILITY_NONE }, ++ .bodyColor = BODY_COLOR_PURPLE, ++ }, + }; +``` + +The `.` is the structure reference operator in C to refer to the member object of the structure SpeciesInfo. + +- `baseHP`, `baseAttack`, `baseDefense`, `baseSpeed`, `baseSpAttack` and `baseSpDefense` are the base stats. They can't go higher than 255. +- `types` is using the macro `MON_TYPES` as a helper function for formatting so that only one type has to be input for species with a single type. + - To add a species with 2 types, use the format `MON_TYPES(TYPE_PSYCHIC, TYPE_NORMAL)`. +- `catchRate` is how likely it is to catch a Pokémon, the lower the value, the harder it is to catch. Legendaries generally have a catch rate of 3, so we put that here. +- `expYield` is the base amount of experience that a Pokémon gives when defeated/caught. In vanilla, this value caps at 255, but we've increased it to a maximum of 65535 accomodate later gen's higher experience yields. (The highest official value is Blissey's with 608, so going beyond this point may cause exponential gains that could break the system 😱) + - If you noticed, Mew's had some `#if`s, `#elif`s and `#endif` around it. This is because its yield has changed over time, and we let you choose which ones you want. This is not relevant to our Mewthree however, so we can just put a single `.expYield = 255,` line here. +- `evYield_HP`, `evYield_Attack`, `evYield_Defense`, `evYield_Speed`, `evYield_SpAttack` and `evYield_SpDefense` are how many EVs does the Pokémon give when they're caught. Each of these fields can have a value of 3 at most. Officially, no Pokémon give out more than 3 EVs total, with them being determined by their evolution stage (eg, Pichu, Pikachu and Raichu give 1, 2 and 3 Speed EVs respectively), and they tend to be associated with its higher stats. Since our Mewthree is a Special Attack monster, we'll be consistent and make it give out 3 Special Attack EVs, but you're always free to assign whatever you feel like :) + - Notice that the other `evYield` fields are not there. In C, numbers in a struct default to 0, so if we don't specify them, they'll be 0 all around! Less lines to worry about :D +- `itemCommon` and `itemRare` are used to determine what items is the Pokémon holding when encountering it in the wild. + - 50% for `itemCommon` and 5% for `itemRare` (boosted to 60%/20% when the first mon in the party has Compound Eyes or Super Luck) + - If they're both set as the same item, the item has a 100% chance of appearing. +- `genderRatio` is a fun one. + - There are 4 ways of handling this + - `PERCENT_FEMALE` is what most Pokémon use, where you define how likely it's gonna be female. It supports decimals, so you can put `PERCENT_FEMALE(12.5)` to have a 1 in 8 chance of your mon to be female. + - `MON_MALE` guarantees that all mon of this species will be male (eg. Tauros) + - `MON_FEMALE` guarantees that all mon of this species will be female (eg. Miltank) + - `MON_GENDERLESS` makes your species genderless, unable to breed with anything but Ditto to produce eggs. Most Legendaries are this, so we'll be chosing this as Mewthree's gender ratio. + - When working with evolution lines and don't want their genders to change after evolving, be sure that their gender ratios match their stages and evolution methods. Azurill is the only case where there's a mismatch, causing 1/3 of all Azurill to change from Female to Male. + - You might be wondering why some species have multiple defines for their genders, like `SPECIES_MEOWSTIC_(FE)MALE`. This is because those species have different stats and data from each other, so they're defined internally as different forms with `MON_MALE` and `MON_FEMALE` as gender ratios. If your species evolves depending on its gender and the evolutions have different stats, be sure to apply the correct evolution method! +- `eggCycles` determines how fast an egg of this species will hatch. Doesn't matter much for evolved species or those that can't lay eggs, but we add the field here just in case. +- `friendship` determines the amount of friendship of the mon when you catch it. Most Pokémon use `STANDARD_FRIENDSHIP`, but this creature of chaos does not want to be your friend, starting with 0. +- `growthRate` determines the amounts of experience required to reach each level. Go [here](https://bulbapedia.bulbagarden.net/wiki/Experience) for more info. + - This should be consistent across evolution lines, otherwise levels could change upon evolution. +- `eggGroups` are used for breed compatibility. Most Legendaries and Mythicals have the `EGG_GROUP_NO_EGGS_DISCOVERED` group, and so does our Mewthree. Go [here](https://bulbapedia.bulbagarden.net/wiki/Egg_Group) for more info. + - This is using the helper macro `MON_EGG_GROUPS`. +- `abilities` determines the potential abilites of our species. Notice how I also set the ability to `ABILITY_INSOMNIA`, so our little monster doesn't even need to sleep anymore. You can find the abilities for example here [include/constants/abilities.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/include/constants/abilities.h). + - When both slot 1 and 2 are defined as not being `ABILITY_NONE`, their starting ability will be decided on a coin flip using their personality. They can later be changed using an Ability Capsule. + - Certain Pokémon such as Zygarde and Rockruff have different forms to add additional abilities. As such, they cannot be changed using an Ability Capsule (though the Zygarde Cube can change Zygarde's ability by changing them to their corresponding form) + - The 3rd slot is for Hidden Abilities. If defined as `ABILITY_NONE`, it will default to Slot 1 (eg. Metapod doesn't have a Hidden Ability, but Caterpie and Butterfree do). Go [here](https://bulbapedia.bulbagarden.net/wiki/Ability#Hidden_Abilities) and [here](https://bulbapedia.bulbagarden.net/wiki/Ability_Patch) for more info. + - If the array is defined as `{ABILITY_1, ABILITY_2}`, the Hidden Ability is set as `ABILITY_NONE`. +- `bodyColor` is used in the Pokédex as a search filter. +- `noFlip` is used in to prevent front sprites from being flipped horizontally and cause weird issues, like Clawitzer's big claw changing sides. + +That's all the basic fields present in vanilla emerald, so now let's take a look at the new fields added by the expansion. + +## 4. Species Name + +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + ... + [SPECIES_MEWTHREE] = + { + ... + .bodyColor = BODY_COLOR_PURPLE, ++ .speciesName = _("Mewthree"), + }, + }; +``` +The `_()` underscore function doesn't really exist - it's a convention borrowed from GNU gettext to let `preproc` know this is text to be converted to the custom encoding used by the Gen 3 Pokemon games. + +## 5. Define its cry + +Time for audio! +We first need to convert an existing audio file to the format supported by the expansion. + +Most formats are supported for conversion, but for simplicity's sake, we're gonna use an mp3 file. + +Now, let's copy the file to the `sound/direct_sound_samples/cries` folder. +Once that's done, let's run the following command: +``` +ffmpeg -i sound/direct_sound_samples/cries/mewthree.mp3 -c:a pcm_s8 -ac 1 -ar 13379 sound/direct_sound_samples/cries/mewthree.aif +``` +This will convert your audio file to .aif, which is what's read by the compiler. + +Let's add the cry to the ROM via [sound/direct_sound_data.inc](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/sound/direct_sound_data.inc). + +```diff +.if P_FAMILY_PECHARUNT == TRUE + .align 2 +Cry_Pecharunt:: + .incbin "sound/direct_sound_samples/cries/pecharunt.bin" +.endif @ P_FAMILY_PECHARUNT + ++ .align 2 ++Cry_Mewthree:: ++ .incbin "sound/direct_sound_samples/cries/mewthree.bin" + +``` + +Then we add the cry ID to [include/constants/cries.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/include/constants/cries.h): + +```diff +enum { + CRY_NONE, + ... +#if P_FAMILY_TERAPAGOS + CRY_TERAPAGOS, +#endif //P_FAMILY_TERAPAGOS +#if P_FAMILY_PECHARUNT + CRY_PECHARUNT, +#endif //P_FAMILY_PECHARUNT ++ CRY_MEWTHREE, + CRY_COUNT, +}; +``` + +And then link it in [sound/cry_tables.inc](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/sound/cry_tables.inc). `cry_reverse` in particular is for reversed cries used by moves such as Growl. The order of these two tables should match the order of the cry IDs, otherwise they'll be shifted. + +```diff + cry Cry_Terapagos + cry Cry_Pecharunt ++ cry Cry_Mewthree +``` +```diff + cry_reverse Cry_Terapagos + cry_reverse Cry_Pecharunt ++ cry_reverse Cry_Mewthree +``` + +Lastly, we add the cry to our species entry +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + ... + [SPECIES_MEWTHREE] = + { + ... + .speciesName = _("Mewthree"), ++ .cryId = CRY_MEWTHREE, + }, + }; +``` + +And let's see how it sounds in-game: + +https://github.com/rh-hideout/pokeemerald-expansion/assets/2904965/4f7667db-4db9-4bfd-a8dd-ece26f09f327 + +Good! Our monster now has a mighty roar! + +You can now delete the mp3 from the cries folder now once you made sure that the cry sounds like how you want it to. + +## 6. Define its Pokédex entry + +First, we will need to add new index constants for its Pokédex entry. The index constants are divided into the Hoenn Pokédex, which contains all Pokémon native to the Hoenn region, and the National Pokédex containing all known Pokémon, which can be received after entering the hall of fame for the first time. + +Edit [include/constants/pokedex.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/include/constants/pokedex.h): + +```diff +// National Pokedex order +enum { + NATIONAL_DEX_NONE, + // Kanto + NATIONAL_DEX_BULBASAUR, +... + NATIONAL_DEX_PECHARUNT, ++ NATIONAL_DEX_MEWTHREE, +}; +``` + +```diff + #define KANTO_DEX_COUNT NATIONAL_DEX_MEW + #define JOHTO_DEX_COUNT NATIONAL_DEX_CELEBI + +#if P_GEN_9_POKEMON == TRUE +- #define NATIONAL_DEX_COUNT NATIONAL_DEX_PECHARUNT ++ #define NATIONAL_DEX_COUNT NATIONAL_DEX_MEWTHREE +``` + +Do keep in mind that if you intend to add your new species to the Hoenn Dex, you'll also want to add a `HOENN_DEX` constant for it and give it a `HOENN_TO_NATIONAL` member, like this: + +```diff +// Hoenn Pokedex order +enum { + HOENN_DEX_NONE, + HOENN_DEX_TREECKO, +... + HOENN_DEX_DEOXYS, ++ HOENN_DEX_MEWTHREE, +}; + +- #define HOENN_DEX_COUNT (HOENN_DEX_DEOXYS + 1) ++ #define HOENN_DEX_COUNT (HOENN_DEX_MEWTHREE + 1) +``` + +Edit [src/pokemon.c](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/pokemon.c): + +```diff + const u16 sHoennToNationalOrder[NUM_SPECIES] = // Assigns Hoenn Dex Pokémon (Using National Dex Index) + { + HOENN_TO_NATIONAL(TREECKO), + ... + HOENN_TO_NATIONAL(DEOXYS), ++ HOENN_TO_NATIONAL(MEWTHREE), + }; +``` + +Now we can add the number and entry to our Mewthree: +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + ... + [SPECIES_MEWTHREE] = + { + ... + .cryId = CRY_MEWTHREE, ++ .natDexNum = NATIONAL_DEX_MEWTHREE, ++ .categoryName = _("New Species"), ++ .height = 15, ++ .weight = 330, ++ .description = COMPOUND_STRING( ++ "The rumors became true.\n" ++ "This is Mew's final form.\n" ++ "Its power level is over 9000.\n" ++ "Has science gone too far?"), ++ .pokemonScale = 256, ++ .pokemonOffset = 0, ++ .trainerScale = 290, ++ .trainerOffset = 2, + }, + }; +``` +![image](https://github.com/rh-hideout/pokeemerald-expansion/assets/2904965/3759dd4c-8da5-4b1c-9a50-b9e9d0815e7f) + +The values `pokemonScale`, `pokemonOffset`, `trainerScale` and `trainerOffset` are used for the height comparison figure in the Pokédex. + +`height` and `weight` are specified in decimeters and hectograms respectively (which are meters and kilograms multiplied by 10, so 2.5 meters are 25 decimeters). + +In Pokémon Emerald, you can sort the Pokédex by name, height or weight. Apparently, the Pokémon order is hardcoded in the game files and not calculated from their data. Therefore we have to include our new Pokémon species at the right places. While the correct position for the alphabetical order is easy to find, it can become quite tedious for height and weight, so we added comments to the listings in order help out were they should fit. + +Edit [src/data/pokemon/pokedex_orders.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/pokemon/pokedex_orders.h): + +```diff + const u16 gPokedexOrder_Alphabetical[] = + { + ... + NATIONAL_DEX_MEW, ++ NATIONAL_DEX_MEWTHREE, + NATIONAL_DEX_MEWTWO, + ... + }; + + const u16 gPokedexOrder_Weight[] = + { + ... + // 72.8 lbs / 33.0 kg + //NATIONAL_DEX_MEWTWO_MEGA_Y, + NATIONAL_DEX_ESCAVALIER, + NATIONAL_DEX_FRILLISH, + NATIONAL_DEX_DURANT, + NATIONAL_DEX_CINDERACE, ++ NATIONAL_DEX_MEWTHREE, + //NATIONAL_DEX_PERSIAN_ALOLAN, + NATIONAL_DEX_TOEDSCOOL, + // 73.4 lbs / 33.3 kg + NATIONAL_DEX_DUGTRIO, + ... + }; + + const u16 gPokedexOrder_Height[] = + { + ... + // 4'11" / 1.5m + ... + NATIONAL_DEX_GLIMMORA, + NATIONAL_DEX_WO_CHIEN, + NATIONAL_DEX_IRON_LEAVES, + NATIONAL_DEX_IRON_BOULDER, ++ NATIONAL_DEX_MEWTHREE, + // 5'03" / 1.6m + ... + }; +``` +![mGBA_lUBfmFEKUx](https://github.com/rh-hideout/pokeemerald-expansion/assets/2904965/3a8b8a17-759b-486b-9831-deb2f494bd71) + + +# The Graphics +We will start by copying the following files for *Mew* (not Mewtwo) and rename it to `mewthree`. +```sh +cp -r graphics/pokemon/mew/. graphics/pokemon/mewthree +``` +We aren't copying Mewtwo's folder because he has those pesky Mega Evolutions that will get in the way of what we're doing, so our sample will need to be pure from the source. + +## 1. Edit the sprites +Let's edit the sprites. Start your favourite image editor (I recommend Aseprite or its free alternative, Libresprite) and change `anim_front.png` and `back.png` to meet your expectations. + +__Make sure that you are using the indexed mode and you have limited yourself to 15 colors!__ + +Put the RGB values of your colors into `normal.pal` between the first and the last color and the RGB values for the shiny version into `shiny.pal`. +Edit `footprint.png` using two colors in indexed mode, black and white. +Finally, edit `icon.png`. +**Note**: the icon will use one of 6 predefined palettes instead of `normal.pal`. +Open an icon sprite and load one of the palettes to find out which palette suits your icon sprite best. + +## 2. Add the sprites to the rom +Sadly, just putting the image files into the graphics folder is not enough. To use the sprites we have to register them, which is kind of tedious. +First, create constants for the file paths. You'll want to add the constants for your species after the constants for the last valid species. + +Edit [src/data/graphics/pokemon.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/graphics/pokemon.h): + +```diff +#if P_FAMILY_PECHARUNT + const u32 gMonFrontPic_Pecharunt[] = INCBIN_U32("graphics/pokemon/pecharunt/front.4bpp.lz"); + const u32 gMonPalette_Pecharunt[] = INCBIN_U32("graphics/pokemon/pecharunt/normal.gbapal.lz"); + const u32 gMonBackPic_Pecharunt[] = INCBIN_U32("graphics/pokemon/pecharunt/back.4bpp.lz"); + const u32 gMonShinyPalette_Pecharunt[] = INCBIN_U32("graphics/pokemon/pecharunt/shiny.gbapal.lz"); + const u8 gMonIcon_Pecharunt[] = INCBIN_U8("graphics/pokemon/pecharunt/icon.4bpp"); +#if P_FOOTPRINTS + const u8 gMonFootprint_Pecharunt[] = INCBIN_U8("graphics/pokemon/pecharunt/footprint.1bpp"); +#endif //P_FOOTPRINTS +#if OW_POKEMON_OBJECT_EVENTS + const u32 gObjectEventPic_Pecharunt[] = INCBIN_COMP("graphics/pokemon/pecharunt/overworld.4bpp"); +#if OW_PKMN_OBJECTS_SHARE_PALETTES == FALSE + const u32 gOverworldPalette_Pecharunt[] = INCBIN_U32("graphics/pokemon/pecharunt/overworld_normal.gbapal.lz"); + const u32 gShinyOverworldPalette_Pecharunt[] = INCBIN_U32("graphics/pokemon/pecharunt/overworld_shiny.gbapal.lz"); +#endif //OW_PKMN_OBJECTS_SHARE_PALETTES +#endif //OW_POKEMON_OBJECT_EVENTS +#endif //P_FAMILY_PECHARUNT + + const u32 gMonFrontPic_Egg[] = INCBIN_U32("graphics/pokemon/egg/anim_front.4bpp.lz"); + const u32 gMonPalette_Egg[] = INCBIN_U32("graphics/pokemon/egg/normal.gbapal.lz"); + const u8 gMonIcon_Egg[] = INCBIN_U8("graphics/pokemon/egg/icon.4bpp"); + ++ const u32 gMonFrontPic_Mewthree[] = INCBIN_U32("graphics/pokemon/mewthree/anim_front.4bpp.lz"); ++ const u32 gMonBackPic_Mewthree[] = INCBIN_U32("graphics/pokemon/mewthree/back.4bpp.lz"); ++ const u32 gMonPalette_Mewthree[] = INCBIN_U32("graphics/pokemon/mewthree/normal.gbapal.lz"); ++ const u32 gMonShinyPalette_Mewthree[] = INCBIN_U32("graphics/pokemon/mewthree/shiny.gbapal.lz"); ++ const u8 gMonIcon_Mewthree[] = INCBIN_U8("graphics/pokemon/mewthree/icon.4bpp"); ++ const u8 gMonFootprint_Mewthree[] = INCBIN_U8("graphics/pokemon/mewthree/footprint.1bpp"); +``` + +Please note that Pecharunt, the Pokémon that should be above your insertion for the time being, reads a `front.png` sprite instead of an `anim_front.png` sprite. This is because currently, Pecharunt lacks a 2nd frame. If the front sprite sheet of your species uses 2 frames, you should use `anim_front`. + +## 3. Add the animations to the rom + +You can define the animation order, in which the sprites will be shown. The first number is the sprite index (so 0 or 1) and the second number is the number of frames the sprite will be visible. + +Edit [src/data/pokemon_graphics/front_pic_anims.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/pokemon_graphics/front_pic_anims.h): + +```diff +#if P_FAMILY_PECHARUNT +PLACEHOLDER_ANIM_SINGLE_FRAME(Pecharunt); +#endif //P_FAMILY_PECHARUNT + ++static const union AnimCmd sAnim_Mewthree_1[] = ++{ ++ ANIMCMD_FRAME(1, 30), ++ ANIMCMD_FRAME(0, 20), ++ ANIMCMD_END, ++}; +``` + +```diff +#if P_FAMILY_PECHARUNT +SINGLE_ANIMATION(Pecharunt); +#endif //P_FAMILY_PECHARUNT ++SINGLE_ANIMATION(Mewthree); +SINGLE_ANIMATION(Egg); +``` + +You might be wondering what `PLACEHOLDER_ANIM_SINGLE_FRAME` is. Well, since Pecharun only has 1 frame, we use what's called a preprocessor *macro* to have in a single line what otherwise would've been this in the C file: +```c +static const union AnimCmd sAnim_Pecharunt_1[] = +{ + ANIMCMD_FRAME(0, 1), + ANIMCMD_END, +} +``` +Instead, we can use the already established macro that does the same thing, replacing the value in parenthesis with what we want (in this case, `Pecharunt`): +```c +#define PLACEHOLDER_ANIM_SINGLE_FRAME(name) \ +static const union AnimCmd sAnim_##name##_1[] = \ +{ \ + ANIMCMD_FRAME(0, 1), \ + ANIMCMD_END, \ +} +``` + +## 4. Linking graphic information to our Pokémon +Now that we have all the external data ready, we just need to add it to `gSpeciesInfo` plus the rest of the animation and graphical data that we want to use: + +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + ... + [SPECIES_MEWTHREE] = + { + ... + .pokemonScale = 256, + .pokemonOffset = 0, + .trainerScale = 290, + .trainerOffset = 2, ++ .frontPic = gMonFrontPic_Mewthree, ++ .frontPicSize = MON_COORDS_SIZE(64, 64), ++ .frontPicYOffset = 0, ++ .frontAnimFrames = sAnims_Mewthree, ++ .frontAnimId = ANIM_GROW_VIBRATE, ++ .frontAnimDelay = 15, ++ .enemyMonElevation = 6, ++ .backPic = gMonBackPic_Mewthree, ++ .backPicSize = MON_COORDS_SIZE(64, 64), ++ .backPicYOffset = 0, ++ .backAnimId = BACK_ANIM_CONCAVE_ARC_SMALL, ++ .palette = gMonPalette_Mewthree, ++ .shinyPalette = gMonShinyPalette_Mewthree, + .iconSprite = gMonIcon_Mewthree, + .iconPalIndex = 2, ++ FOOTPRINT(Mewthree) + }, + }; +``` +Let's explain each of these: +- `frontPic`: + - Used to reference the front sprite, so in this case, we call for `gMonFrontPic_Mewthree`. +- `frontPicSize`: + - The two values (`width` and `height`) are used for defining the non-empty size of the front sprite, which is used in move animations. If you're unsure of the values, you can leave them both as 64. +- `frontPicYOffset`: + - Used to define what Y position the sprite sits at. This is used to set where they'd be "grounded". For the shadow, see `enemyMonElevation`. +- `frontAnimFrames`: + - We link our animation frame animations that we defined earlier here. +- `frontAnimId`: + - Because you are limited to two frames, there are already [predefined front sprite animations](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/include/pokemon_animation.h), describing translations, rotations, scalings or color changes. +- `frontAnimDelay`: + - Sets a delay in frame count between when the Pokémon appears and when the animation starts. +- `enemyMonElevation`: + - Used to determine the altitude from the ground. Any value above 0 will show a shadow under the Pokémon, to signify that they're floating. +- `backPic`: + - Used to reference the back sprite, so in this case, we call for `gMonBackPic_Mewthree`. +- `backPicSize`: + - The two values (`width` and `height`) are used for defining the non-empty size of the back sprite, which is used in move animations. If you're unsure of the values, you can leave them both as 64. + - **NOTE**: Mew has a tarnary switch here in order to change values depending on if a config option is set for displaying th original Gen 3 sprites. +- `backPicYOffset`: + - Used to define what Y position of the back sprite. When working with the animation debug menu, we recommend aligning the back sprite to the white background, as it was designed to properyly align with the real battle layout. +- `backAnimId`: + - Like `frontAnimId` except for the back sprites and them being a single frame. The IDs listed [here](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/include/pokemon_animation.h) are used to represent 3 different animations that happen based on the the Pokémon's nature. +- `palette`: + - Used to reference the non-shiny palette, so in this case, we call for `gMonPalette_Mewthree`. +- `shinyPalette`: + - Used to reference the shiny palette, so in this case, we call for `gMonShinyPalette_Mewthree`. +- `iconSprite`: + - Used to reference the icon sprite, so in this case, we call for `gMonIcon_Mewthree`. +- `iconPalIndex`: + - Here, you can choose between the six icon palettes; 0, 1, 2, 3, 4 and 5. All of them located in `graphics/pokemon/icon_palettes`. +- `FOOTPRINT` + - We made this single field into a macro so that they can be ignored when `P_FOOTPRINTS` is set to false. It's also why we don't have an "," after calling it like the other macros (we add it as part of the macro itself). + ```c + #if P_FOOTPRINTS + #define FOOTPRINT(sprite) .footprint = gMonFootprint_## sprite, + #else + #define FOOTPRINT(sprite) + #endif + ``` + +# The Data - Part 2 + +We're almost there just a bit left! + +## 1. Species Flags + +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + ... + [SPECIES_MEWTHREE] = + { + ... + .abilities = { ABILITY_INSOMNIA, ABILITY_NONE, ABILITY_NONE }, + .bodyColor = BODY_COLOR_PURPLE, ++ .isLegendary = TRUE, ++ .perfectIVCount = LEGENDARY_PERFECT_IV_COUNT, + }, + }; +``` +Each species flag provides properties to the species: +- `isLegendary`: + - Does nothing. +- `isMythical`: + - Is skipped during Pokédex evaluations. + - Unless it also has the `dexForceRequired` flag. + - Cannot obtain Gigantamax factor via `ToggleGigantamaxFactor`. +- `isUltraBeast`: + - Beast Ball's multiplier is set to x5 for this species. + - All other ball multipliers are set to x0.1. +- `isParadox` (previously `isParadoxForm`): + - Makes it so that Booster Energy cannot be knocked off. +- `isTotem`: + - Does nothing. +- `isMegaEvolution`: + - A Mega indicator is added to the battle box indicating that they're Mega Evolved. + - The species doesn't receive affection benefits. + - Required when adding new Mega Evolutions. +- `isPrimalReversion`: + - A Primal Reversion indicator (Alpha or Omega for Kyogre/Groudon respectively) is added to the battle box indicating that they're Primal Reverted. + - Required when adding new Primal Reversions. +- `isUltraBurst`: + - Required when adding new Ultra Burst forms. +- `isGigantamax`: + - Used to determine if Gigantamax forms should have their GMax moves or not. + - Required when adding new Gigantamax forms. +- `isAlolanForm`, `isGalarianForm`, `isHisuianForm`, `isPaldeanForm`: + - In the future, these will be used to determine breeding offspring from different based on their region. +- `cannotBeTraded`: + - This species cannot be traded away (like Black/White Kyurem). +- `perfectIVCount`: + - Guarantees that the number of IVs specified here will be perfect. +- `tmIlliterate`: + - This species will be unable to learn the universal moves. +- `isFrontierBanned`: + - This species will be unable to enter Battle Frontier facilities. Replaces `gFrontierBannedSpecies`. + +## 2. Delimit the moveset + +Let's begin with the moves that can be learned by leveling up. + +Append to [src/data/pokemon/level_up_learnsets/gen_9.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/pokemon/level_up_learnsets/gen_9.h): +**NOTE**: You can ignore the warning at the top of the file if you're just adding moves to Pokemon. + +```diff +#if P_FAMILY_PECHARUNT +static const struct LevelUpMove sPecharuntLevelUpLearnset[] = { + LEVEL_UP_MOVE( 1, MOVE_SMOG), + LEVEL_UP_MOVE( 1, MOVE_POISON_GAS), + LEVEL_UP_MOVE( 1, MOVE_MEMENTO), + LEVEL_UP_MOVE( 1, MOVE_ASTONISH), + LEVEL_UP_MOVE( 8, MOVE_WITHDRAW), + LEVEL_UP_MOVE(16, MOVE_DESTINY_BOND), + LEVEL_UP_MOVE(24, MOVE_FAKE_TEARS), + LEVEL_UP_MOVE(32, MOVE_PARTING_SHOT), + LEVEL_UP_MOVE(40, MOVE_SHADOW_BALL), + LEVEL_UP_MOVE(48, MOVE_MALIGNANT_CHAIN), + LEVEL_UP_MOVE(56, MOVE_TOXIC), + LEVEL_UP_MOVE(64, MOVE_NASTY_PLOT), + LEVEL_UP_MOVE(72, MOVE_RECOVER), + LEVEL_UP_END +}; +#endif + ++static const struct LevelUpMove sMewthreeLevelUpLearnset[] = { ++ LEVEL_UP_MOVE( 1, MOVE_CONFUSION), ++ LEVEL_UP_MOVE( 1, MOVE_DISABLE), ++ LEVEL_UP_MOVE(11, MOVE_BARRIER), ++ LEVEL_UP_MOVE(22, MOVE_SWIFT), ++ LEVEL_UP_MOVE(33, MOVE_PSYCH_UP), ++ LEVEL_UP_MOVE(44, MOVE_FUTURE_SIGHT), ++ LEVEL_UP_MOVE(55, MOVE_MIST), ++ LEVEL_UP_MOVE(66, MOVE_PSYCHIC), ++ LEVEL_UP_MOVE(77, MOVE_AMNESIA), ++ LEVEL_UP_MOVE(88, MOVE_RECOVER), ++ LEVEL_UP_MOVE(99, MOVE_SAFEGUARD), ++ LEVEL_UP_END ++}; +``` +**NOTE**: If `P_LVL_UP_LEARNSETS` is not set to something equal to `GEN_9`, the file to be edited will change to what's specified. + +Again, we need to register the learnset in `gSpeciesInfo`: + +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + ... + [SPECIES_MEWTHREE] = + { + ... + .palette = gMonPalette_Mewthree, + .shinyPalette = gMonShinyPalette_Mewthree, + .iconSprite = gMonIcon_Mewthree, + .iconPalIndex = 2, ++ .levelUpLearnset = sMewthreeLevelUpLearnset, + }, + }; +``` + +Next we need to specify which moves can be taught via TM, HM, or Move Tutor. + +Append to [src/data/pokemon/teachable_learnsets.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/pokemon/teachable_learnsets.h): + +```diff +#if P_FAMILY_PECHARUNT +static const u16 sPecharuntTeachableLearnset[] = { + ... + MOVE_UNAVAILABLE, +}; +#endif //P_FAMILY_PECHARUNT + ++static const u16 sMewthreeTeachableLearnset[] = { ++ MOVE_FOCUS_PUNCH, ++ MOVE_WATER_PULSE, ++ MOVE_CALM_MIND, ++ MOVE_TOXIC, ++ MOVE_HAIL, ++ MOVE_BULK_UP, ++ MOVE_HIDDEN_POWER, ++ MOVE_SUNNY_DAY, ++ MOVE_TAUNT, ++ MOVE_ICE_BEAM, ++ MOVE_BLIZZARD, ++ MOVE_HYPER_BEAM, ++ MOVE_LIGHT_SCREEN, ++ MOVE_PROTECT, ++ MOVE_RAIN_DANCE, ++ MOVE_SAFEGUARD, ++ MOVE_FRUSTRATION, ++ MOVE_SOLAR_BEAM, ++ MOVE_IRON_TAIL, ++ MOVE_THUNDERBOLT, ++ MOVE_THUNDER, ++ MOVE_EARTHQUAKE, ++ MOVE_RETURN, ++ MOVE_PSYCHIC, ++ MOVE_SHADOW_BALL, ++ MOVE_BRICK_BREAK, ++ MOVE_DOUBLE_TEAM, ++ MOVE_REFLECT, ++ MOVE_SHOCK_WAVE, ++ MOVE_FLAMETHROWER, ++ MOVE_SANDSTORM, ++ MOVE_FIRE_BLAST, ++ MOVE_ROCK_TOMB, ++ MOVE_AERIAL_ACE, ++ MOVE_TORMENT, ++ MOVE_FACADE, ++ MOVE_SECRET_POWER, ++ MOVE_REST, ++ MOVE_SKILL_SWAP, ++ MOVE_SNATCH, ++ MOVE_STRENGTH, ++ MOVE_FLASH, ++ MOVE_ROCK_SMASH, ++ MOVE_MEGA_PUNCH, ++ MOVE_MEGA_KICK, ++ MOVE_BODY_SLAM, ++ MOVE_DOUBLE_EDGE, ++ MOVE_COUNTER, ++ MOVE_SEISMIC_TOSS, ++ MOVE_MIMIC, ++ MOVE_METRONOME, ++ MOVE_DREAM_EATER, ++ MOVE_THUNDER_WAVE, ++ MOVE_SUBSTITUTE, ++ MOVE_DYNAMIC_PUNCH, ++ MOVE_PSYCH_UP, ++ MOVE_SNORE, ++ MOVE_ICY_WIND, ++ MOVE_ENDURE, ++ MOVE_MUD_SLAP, ++ MOVE_ICE_PUNCH, ++ MOVE_SWAGGER, ++ MOVE_SLEEP_TALK, ++ MOVE_SWIFT, ++ MOVE_THUNDER_PUNCH, ++ MOVE_FIRE_PUNCH, ++ MOVE_UNAVAILABLE, // This is required to determine where the array ends. ++}; +#endif +``` + +Once more, we need to register the learnset in `gSpeciesInfo`: + +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + ... + [SPECIES_MEWTHREE] = + { + ... + FOOTPRINT(Mewthree) + .levelUpLearnset = sMewthreeLevelUpLearnset, ++ .teachableLearnset = sMewthreeTeachableLearnset, + }, + }; +``` + +If you want to create a Pokémon which can breed, you will need to edit [src/data/pokemon/egg_moves.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/pokemon/egg_moves.h). + + +## 3. Define the Evolutions + +We want Mewthree to evolve from Mewtwo by reaching level 100. + +Edit `gSpeciesInfo`: + +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + ... + [SPECIES_MEWTWO] = + { + ... + FOOTPRINT(Mewtwo) + .isLegendary = TRUE, + .levelUpLearnset = sMewtwoLevelUpLearnset, + .teachableLearnset = sMewtwoTeachableLearnset, + .formSpeciesIdTable = sMewtwoFormSpeciesIdTable, + .formChangeTable = sMewtwoFormChangeTable, ++ .evolutions = EVOLUTION({EVO_LEVEL, 100, SPECIES_MEWTHREE}), + }, + }; +``` + +## 4. Make it appear! +Now Mewthree really does slumber in the games code - but we won't know until we make him appear somewhere! The legend tells that Mewthree is hiding somewhere in Petalburg Woods... + +Edit [src/data/wild_encounters.json](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/wild_encounters.json): + +```diff + { + "map": "MAP_PETALBURG_WOODS", + "base_label": "gPetalburgWoods", + "land_mons": { + "encounter_rate": 20, + "mons": [ + { + "min_level": 5, + "max_level": 5, + "species": "SPECIES_POOCHYENA" + }, + { + "min_level": 5, + "max_level": 5, + "species": "SPECIES_WURMPLE" + }, + { + "min_level": 5, + "max_level": 5, + "species": "SPECIES_SHROOMISH" + }, + { +- "min_level": 6, +- "max_level": 6, +- "species": "SPECIES_POOCHYENA" ++ "min_level": 5, ++ "max_level": 5, ++ "species": "SPECIES_MEWTHREE" + }, + ... + } +``` + +Congratulations, you have created your own personal pocket monster! You may call yourself a mad scientist now. + +# Optional data + +Now that you now have all the essential pieces to create a base species, there are some aspects that you might want to know if you want to do other stuff with your custom Pokémon. + +## 1. Form tables +Found in `src/data/pokemon/form_species_tables.h`. + +These are introduced to have a reference of what forms correspond to what Species of Pokémon. For example, we have Pikachu's table: +```c +#if P_FAMILY_PIKACHU +static const u16 sPikachuFormSpeciesIdTable[] = { + SPECIES_PIKACHU, + SPECIES_PIKACHU_COSPLAY, + SPECIES_PIKACHU_ROCK_STAR, + SPECIES_PIKACHU_BELLE, + SPECIES_PIKACHU_POP_STAR, + SPECIES_PIKACHU_PH_D, + SPECIES_PIKACHU_LIBRE, + SPECIES_PIKACHU_ORIGINAL_CAP, + SPECIES_PIKACHU_HOENN_CAP, + SPECIES_PIKACHU_SINNOH_CAP, + SPECIES_PIKACHU_UNOVA_CAP, + SPECIES_PIKACHU_KALOS_CAP, + SPECIES_PIKACHU_ALOLA_CAP, + SPECIES_PIKACHU_PARTNER_CAP, + SPECIES_PIKACHU_WORLD_CAP, + FORM_SPECIES_END, +}; +#endif //P_FAMILY_PIKACHU +``` +We register the table each form entry in `gSpeciesInfo`. + +```diff + [SPECIES_PIKACHU] = + { + ... + .teachableLearnset = sPikachuTeachableLearnset, ++ .formSpeciesIdTable = sPikachuFormSpeciesIdTable, + .evolutions = EVOLUTION({EVO_ITEM, ITEM_THUNDER_STONE, SPECIES_RAICHU}, + {EVO_NONE, 0, SPECIES_RAICHU_ALOLAN}), + }, + + [SPECIES_PIKACHU_COSPLAY] = + { + ... + .teachableLearnset = sPikachuTeachableLearnset, ++ .formSpeciesIdTable = sPikachuFormSpeciesIdTable, + }, +``` +...and so on. + +What this allows us to do is to be able to get all forms of a Pokémon in our code by using the `GetSpeciesFormTable` function. + +For example, in the HGSS dex, it lets us browse between the entries of every form available.: + +![image](https://github.com/rh-hideout/pokeemerald-expansion/assets/2904965/a1a90b79-46a1-4cd6-97d6-ec5d741bfdc8) ![image](https://github.com/rh-hideout/pokeemerald-expansion/assets/2904965/7cffc6be-0b5c-4074-b689-736a97297843) + +In addition, we have the `GET_BASE_SPECIES_ID` macro, which returns the first entry of the table (or return the species itself if it doesn't have a table registered). With this, you can check if a Pokémon is any form of a species. For example, making it so that the Light Ball affects all Pikachu forms: +```c + case HOLD_EFFECT_LIGHT_BALL: + if (GET_BASE_SPECIES_ID(gBattleMons[battlerAtk].species) == SPECIES_PIKACHU && IS_MOVE_SPECIAL(move)) + modifier = uq4_12_multiply_half_down(modifier, UQ_4_12(2.0)); + break; +``` + +## 2. Form change tables +Found in `src/data/pokemon/form_species_tables.h`. + +These tables, unlike the regular form tables, registers how Pokémon can switch between forms. + +```c +#if P_FAMILY_GASTLY +static const struct FormChange sGengarFormChangeTable[] = { + {FORM_CHANGE_BATTLE_MEGA_EVOLUTION_ITEM, SPECIES_GENGAR_MEGA, ITEM_GENGARITE}, + {FORM_CHANGE_BATTLE_GIGANTAMAX, SPECIES_GENGAR_GIGANTAMAX}, + {FORM_CHANGE_TERMINATOR}, +}; +#endif //P_FAMILY_GASTLY +``` +The first value is the type of form change. In the case of Gengar, we have both Mega Evolution and Gigantamax form changes. + +The second value is the target form, to which the Pokémon will change into. + +Values after that are referred as arguments, and needs to be put there depends on the type of form change, detailed in `include/constants/form_change_types.h`. + +## 3. Gender differences +![mGBA_Wq5cbDkNZG](https://github.com/rh-hideout/pokeemerald-expansion/assets/2904965/45256192-b451-4baa-af06-f57ca16e1e46) + +You may have seen that there's a couple of duplicate fields with a "Female" suffix. +```diff + [SPECIES_FRILLISH] = + { + ... + .frontPic = gMonFrontPic_Frillish, ++ .frontPicFemale = gMonFrontPic_FrillishF, + .frontPicSize = MON_COORDS_SIZE(56, 56), ++ .frontPicSizeFemale = MON_COORDS_SIZE(56, 56), + .frontPicYOffset = 5, + .frontAnimFrames = sAnims_Frillish, + .frontAnimId = ANIM_RISING_WOBBLE, + .backPic = gMonBackPic_Frillish, ++ .backPicFemale = gMonBackPic_FrillishF, + .backPicSize = MON_COORDS_SIZE(40, 56), ++ .backPicSizeFemale = MON_COORDS_SIZE(40, 56), + .backPicYOffset = 7, + .backAnimId = BACK_ANIM_CONVEX_DOUBLE_ARC, + .palette = gMonPalette_Frillish, ++ .paletteFemale = gMonPalette_FrillishF, + .shinyPalette = gMonShinyPalette_Frillish, ++ .shinyPaletteFemale = gMonShinyPalette_FrillishF, + .iconSprite = gMonIcon_Frillish, ++ .iconSpriteFemale = gMonIcon_FrillishF, + .iconPalIndex = 0, ++ .iconPalIndexFemale = 1, + FOOTPRINT(Frillish) + .levelUpLearnset = sFrillishLevelUpLearnset, + .teachableLearnset = sFrillishTeachableLearnset, + .evolutions = EVOLUTION({EVO_LEVEL, 40, SPECIES_JELLICENT}), + }, +``` +These are used to change the graphics of the Pokémon if they're female. If they're not registered, they default to the male values. + +However, `iconPalIndexFemale` is a special case, where it's *doesn't* read the male icon palette if its `iconSpriteFemale` is set, so if you're setting a female icon, be sure to set their palette index as well. + +## 4. Overworld Data +![mGBA_4iqvhhSltK](https://github.com/rh-hideout/pokeemerald-expansion/assets/2904965/e59238dc-9779-4f26-a9e7-159a32caa3d9) + +If you have `OW_POKEMON_OBJECT_EVENTS` in your hack, you can add Overworld of your new species by following these steps: + +First, since you copied the contents from Mew's folder previously, you should also have copied its overworld sprites. Edit those to your liking, as we have done before, making sure to update the palettes + +Secondly, in [src/data/graphics/pokemon.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/graphics/pokemon.h), add the following: + +```diff + const u8 gMonIcon_Mewthree[] = INCBIN_U8("graphics/pokemon/mewthree/icon.4bpp"); + const u8 gMonFootprint_Mewthree[] = INCBIN_U8("graphics/pokemon/mewthree/footprint.1bpp"); ++ const u32 gObjectEventPic_Mewthree[] = INCBIN_COMP("graphics/pokemon/mewthree/overworld.4bpp"); ++ const u32 gOverworldPalette_Mewthree[] = INCBIN_U32("graphics/pokemon/mewthree/overworld_normal.gbapal.lz"); ++ const u32 gShinyOverworldPalette_Mewthree[] = INCBIN_U32("graphics/pokemon/mewthree/overworld_shiny.gbapal.lz"); +``` + +Thirdly, in [spritesheet_rules.mk](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/spritesheet_rules.mk) + +```diff +$(POKEMONGFXDIR)/mewtwo/overworld.4bpp: %.4bpp: %.png + $(GFX) $< $@ -mwidth 4 -mheight 4 + ++$(POKEMONGFXDIR)/mewthree/overworld.4bpp: %.4bpp: %.png ++ $(GFX) $< $@ -mwidth 4 -mheight 4 + +$(POKEMONGFXDIR)/mew/overworld.4bpp: %.4bpp: %.png + $(GFX) $< $@ -mwidth 4 -mheight 4 +``` + +Fourthly, in [src/data/object_events/object_event_pic_tables_followers.h](https://github.com/rh-hideout/pokeemerald-expansion/blob/master/src/data/object_events/object_event_pic_tables_followers.h): +```diff +#if P_FAMILY_PECHARUNT +/*static const struct SpriteFrameImage sPicTable_Pecharunt[] = { + overworld_ascending_frames(gObjectEventPic_Pecharunt, 4, 4), +};*/ +#endif //P_FAMILY_PECHARUNT + ++static const struct SpriteFrameImage sPicTable_Mewthree[] = { ++ overworld_ascending_frames(gObjectEventPic_Mewthree, 4, 4), ++}; +``` + +And finally, in `gSpeciesInfo`: + +```diff + const struct SpeciesInfo gSpeciesInfo[] = + { + ... + [SPECIES_MEWTHREE] = + { + ... + FOOTPRINT(Mewthree) ++ OVERWORLD( ++ sPicTable_Mewthree, ++ SIZE_32x32, ++ SHADOW_SIZE_M, ++ TRACKS_FOOT, ++ gOverworldPalette_Mewthree, ++ gShinyOverworldPalette_Mewthree ++ ) + .levelUpLearnset = sMewthreeLevelUpLearnset, + .teachableLearnset = sMewthreeTeachableLearnset, + }, + }; +``` + +### Sprite Size +Depending on your species, you might want to use different sizes for it. For example, certain species known for being big like Steelix use sprites that fit a 64x64 frame instead of 32x32, and as such have `SIZE_64x64` in their data instead of `SIZE_32x32` to accomodate for them. + +Also, in `spritesheet_rules.mk`, `-mwidth` and `-mheight` need to be set to 8 instead of 4 for such cases. + +### Shadows +Gen 4 style shadows are defined by the `SHADOW` macro which takes the following arguments: + - X offset + - Y offset + - Shadow size +You have 4 options for their shadow, between Small, Medium, Large and Extra Large: + - `SHADOW_SIZE_S` + - `SHADOW_SIZE_M` + - `SHADOW_SIZE_L` + - `SHADOW_SIZE_XL_BATTLE_ONLY` +To make the Pokémon have no shadow, use the `NO_SHADOW` macro instead of `SHADOW`. + +### Tracks +You have 4 options for the tracks that your species will leave behind on sand. + - `TRACKS_NONE` + - `TRACKS_FOOT` ![sand_footprints](https://github.com/user-attachments/assets/8b8c34d6-72e9-4b9d-839d-0a5cc1ae1a4c) + - `TRACKS_SLITHER` ![slither_tracks](https://github.com/user-attachments/assets/28219c05-61e0-48b3-9aeb-43f48e4ffdd4) + - `TRACKS_SPOT` ![spot_tracks](https://github.com/user-attachments/assets/f7a24887-c5ca-47f2-8825-01f3df61deca) + - `TRACKS_BUG` ![bug_tracks](https://github.com/user-attachments/assets/8cd1dea4-4123-4af8-a558-992874a6d589) + + ...though technically you can also use `TRACKS_BIKE_TIRE` if you wish to. + +![bike_tire_tracks](https://github.com/user-attachments/assets/ac81d211-85e5-443a-ac54-c2976f1f0b82) diff --git a/graphics/pokemon/farfetchd/overworld.png b/graphics/pokemon/farfetchd/overworld.png index 46aec09764..63d29215b7 100644 Binary files a/graphics/pokemon/farfetchd/overworld.png and b/graphics/pokemon/farfetchd/overworld.png differ diff --git a/graphics/pokemon/melmetal/overworld.png b/graphics/pokemon/melmetal/overworld.png index 4be020a5c6..e8097644ad 100644 Binary files a/graphics/pokemon/melmetal/overworld.png and b/graphics/pokemon/melmetal/overworld.png differ diff --git a/graphics/pokemon/melmetal/overworld_normal.pal b/graphics/pokemon/melmetal/overworld_normal.pal index 28e4593192..d9b329362b 100644 --- a/graphics/pokemon/melmetal/overworld_normal.pal +++ b/graphics/pokemon/melmetal/overworld_normal.pal @@ -1,7 +1,7 @@ JASC-PAL 0100 16 -255 255 255 +120 255 255 254 235 185 220 220 218 235 192 100 @@ -16,4 +16,4 @@ JASC-PAL 64 64 64 45 43 43 8 8 8 -0 0 0 +255 255 255 diff --git a/graphics/pokemon/melmetal/overworld_shiny.pal b/graphics/pokemon/melmetal/overworld_shiny.pal index 6d1c75c9bb..4f5321a062 100644 --- a/graphics/pokemon/melmetal/overworld_shiny.pal +++ b/graphics/pokemon/melmetal/overworld_shiny.pal @@ -16,4 +16,4 @@ JASC-PAL 64 64 64 45 43 43 8 8 8 -0 0 0 +255 255 255 diff --git a/graphics/pokemon/patrat/overworld.png b/graphics/pokemon/patrat/overworld.png index ea2df04dc1..8b6a34f198 100644 Binary files a/graphics/pokemon/patrat/overworld.png and b/graphics/pokemon/patrat/overworld.png differ diff --git a/graphics/pokemon/woobat/overworld.png b/graphics/pokemon/woobat/overworld.png index 1d14a5c43d..18bff8d5c3 100644 Binary files a/graphics/pokemon/woobat/overworld.png and b/graphics/pokemon/woobat/overworld.png differ diff --git a/include/battle_message.h b/include/battle_message.h index fe030226fe..60fa8c507a 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -10,6 +10,7 @@ max(POKEMON_NAME_LENGTH + 1, \ ABILITY_NAME_LENGTH + 1))) #define BATTLE_MSG_MAX_WIDTH 208 +#define BATTLE_MSG_MAX_LINES 2 // for 0xFD #define B_TXT_BUFF1 0x0 diff --git a/include/constants/battle.h b/include/constants/battle.h index d337559f1b..ed19a72d9c 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -507,7 +507,7 @@ #define MOVE_TARGET_FOES_AND_ALLY (1 << 5) #define MOVE_TARGET_OPPONENTS_FIELD (1 << 6) #define MOVE_TARGET_ALLY (1 << 7) -#define MOVE_TARGET_ALL_BATTLERS ((1 << 8) | MOVE_TARGET_USER) +#define MOVE_TARGET_ALL_BATTLERS ((1 << 8) | MOVE_TARGET_USER) // No functionality for status moves // For the second argument of GetMoveTarget, when no target override is needed #define NO_TARGET_OVERRIDE 0 diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index c10c2646f1..196cea0b42 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -289,9 +289,9 @@ enum MoveEndEffects MOVEEND_RECOIL, MOVEEND_ITEM_EFFECTS_ATTACKER, MOVEEND_MAGICIAN, // Occurs after final multi-hit strike, and after other items/abilities would activate + MOVEEND_RED_CARD, // Red Card triggers before Eject Pack MOVEEND_EJECT_ITEMS, MOVEEND_WHITE_HERB, - MOVEEND_RED_CARD, MOVEEND_LIFEORB_SHELLBELL, // Includes shell bell, throat spray, etc MOVEEND_CHANGED_ITEMS, MOVEEND_PICKPOCKET, diff --git a/include/constants/form_change_types.h b/include/constants/form_change_types.h index 74bc16cf2f..79a8a4cee7 100644 --- a/include/constants/form_change_types.h +++ b/include/constants/form_change_types.h @@ -134,4 +134,8 @@ // param1: amount of days #define FORM_CHANGE_DAYS_PASSED 23 +// Form change for Aegislash +#define FORM_CHANGE_BATTLE_ATTACK 24 +#define FORM_CHANGE_BATTLE_KINGS_SHIELD 25 + #endif // GUARD_CONSTANTS_FORM_CHANGE_TYPES_H diff --git a/include/line_break.h b/include/line_break.h new file mode 100644 index 0000000000..c423c9bf40 --- /dev/null +++ b/include/line_break.h @@ -0,0 +1,33 @@ +#ifndef GUARD_LINE_BREAK_H +#define GUARD_LINE_BREAK_H + +#define BADNESS_UNFILLED 1 // Badness added per pixel diff from max width +#define BADNESS_JAGGED 1 // Badness added per pixel diff from longest, squared per line +#define BADNESS_RUNT 100 // Badness added if there's a runt +#define BADNESS_OVERFLOW 100 // Badness added per pixel overflow, squared per line (not used) +#define BADNESS_WIDE_SPACE 1 // Badness added per extra pixel width (not used) +#define MAX_SPACE_WIDTH 5 + +struct StringWord { + u32 startIndex:16; + u32 length:8; + u32 width:8; +}; + +struct StringLine { + struct StringWord *words; + u16 numWords; + u8 spaceWidth; + u8 extraSpaceWidth; +}; + +void StripLineBreaks(u8 *src); +void BreakStringAutomatic(u8 *src, u32 maxWidth, u32 screenLines, u8 fontId); +void BreakSubStringAutomatic(u8 *src, u32 maxWidth, u32 screenLines, u8 fontId); + +bool32 IsWordSplittingChar(const u8 *src, u32 index); +u32 GetStringBadness(struct StringLine *stringLines, u32 numLines, u32 maxWidth); +void BuildNewString(struct StringLine *stringLines, u32 numLines, u32 maxLines, u8 *str); +bool32 StringHasManualBreaks(u8 *src); + +#endif // GUARD_LINE_BREAK_H diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index e2cd1d057e..58da3bd5cc 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -3506,6 +3506,7 @@ u32 AI_WhoStrikesFirstPartyMon(u32 battlerAtk, u32 battlerDef, struct BattlePoke SetBattlerAiData(battlerAtk, AI_DATA); u32 aiMonFaster = AI_IsFaster(battlerAtk, battlerDef, moveConsidered); FreeRestoreBattleMons(savedBattleMons); + SetBattlerAiData(battlerAtk, AI_DATA); return aiMonFaster; } diff --git a/src/battle_anim_flying.c b/src/battle_anim_flying.c index 42c99740d3..8b613ad677 100644 --- a/src/battle_anim_flying.c +++ b/src/battle_anim_flying.c @@ -363,7 +363,6 @@ static void AnimEllipticalGustCentered(struct Sprite *sprite) InitSpritePosToAnimTargetsCentre(sprite, FALSE); else InitSpritePosToAnimTarget(sprite, FALSE); - sprite->y += 20; sprite->data[1] = 191; sprite->callback = AnimEllipticalGust_Step; diff --git a/src/battle_anim_mon_movement.c b/src/battle_anim_mon_movement.c index 04fd111a84..240e43b713 100644 --- a/src/battle_anim_mon_movement.c +++ b/src/battle_anim_mon_movement.c @@ -15,8 +15,10 @@ static void ReverseHorizontalLungeDirection(struct Sprite *sprite); static void DoVerticalDip(struct Sprite *sprite); static void ReverseVerticalDipDirection(struct Sprite *sprite); static void SlideMonToOriginalPos(struct Sprite *sprite); +static void SlideMonToOriginalPosPartner(struct Sprite *sprite); static void SlideMonToOriginalPos_Step(struct Sprite *sprite); static void SlideMonToOffset(struct Sprite *sprite); +static void SlideMonToOffsetPartner(struct Sprite *sprite); static void SlideMonToOffsetAndBack(struct Sprite *sprite); static void SlideMonToOffsetAndBack_End(struct Sprite *sprite); static void AnimTask_WindUpLunge_Step1(u8 taskId); @@ -63,6 +65,17 @@ const struct SpriteTemplate gSlideMonToOriginalPosSpriteTemplate = .callback = SlideMonToOriginalPos, }; +const struct SpriteTemplate gSlideMonToOriginalPosPartnerSpriteTemplate = +{ + .tileTag = 0, + .paletteTag = 0, + .oam = &gDummyOamData, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SlideMonToOriginalPosPartner, +}; + const struct SpriteTemplate gSlideMonToOffsetSpriteTemplate = { .tileTag = 0, @@ -74,6 +87,17 @@ const struct SpriteTemplate gSlideMonToOffsetSpriteTemplate = .callback = SlideMonToOffset, }; +const struct SpriteTemplate gSlideMonToOffsetPartnerSpriteTemplate = +{ + .tileTag = 0, + .paletteTag = 0, + .oam = &gDummyOamData, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SlideMonToOffsetPartner, +}; + const struct SpriteTemplate gSlideMonToOffsetAndBackSpriteTemplate = { .tileTag = 0, @@ -487,7 +511,41 @@ static void ReverseVerticalDipDirection(struct Sprite *sprite) // arg 2: duration static void SlideMonToOriginalPos(struct Sprite *sprite) { - u32 monSpriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[0]); + u32 monSpriteId; + if (!gBattleAnimArgs[0]) + monSpriteId = gBattlerSpriteIds[gBattleAnimAttacker]; + else + monSpriteId = gBattlerSpriteIds[gBattleAnimTarget]; + + sprite->data[0] = gBattleAnimArgs[2]; + sprite->data[1] = gSprites[monSpriteId].x + gSprites[monSpriteId].x2; + sprite->data[2] = gSprites[monSpriteId].x; + sprite->data[3] = gSprites[monSpriteId].y + gSprites[monSpriteId].y2; + sprite->data[4] = gSprites[monSpriteId].y; + InitSpriteDataForLinearTranslation(sprite); + sprite->data[3] = 0; + sprite->data[4] = 0; + sprite->data[5] = gSprites[monSpriteId].x2; + sprite->data[6] = gSprites[monSpriteId].y2; + sprite->invisible = TRUE; + + if (gBattleAnimArgs[1] == 1) + sprite->data[2] = 0; + else if (gBattleAnimArgs[1] == 2) + sprite->data[1] = 0; + + sprite->data[7] = gBattleAnimArgs[1]; + sprite->data[7] |= monSpriteId << 8; + sprite->callback = SlideMonToOriginalPos_Step; +} + +static void SlideMonToOriginalPosPartner(struct Sprite *sprite) +{ + u32 monSpriteId; + if (!gBattleAnimArgs[0]) + monSpriteId = gBattlerSpriteIds[BATTLE_PARTNER(gBattleAnimAttacker)]; + else + monSpriteId = gBattlerSpriteIds[BATTLE_PARTNER(gBattleAnimTarget)]; sprite->data[0] = gBattleAnimArgs[2]; sprite->data[1] = gSprites[monSpriteId].x + gSprites[monSpriteId].x2; @@ -550,9 +608,48 @@ static void SlideMonToOriginalPos_Step(struct Sprite *sprite) // arg 4: duration static void SlideMonToOffset(struct Sprite *sprite) { - u8 monSpriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[0]); + u8 battler; + u8 monSpriteId; + if (!gBattleAnimArgs[0]) + battler = gBattleAnimAttacker; + else + battler = gBattleAnimTarget; - if (GetBattlerSide(gBattleAnimArgs[0]) != B_SIDE_PLAYER) + monSpriteId = gBattlerSpriteIds[battler]; + if (GetBattlerSide(battler) != B_SIDE_PLAYER) + { + gBattleAnimArgs[1] = -gBattleAnimArgs[1]; + if (gBattleAnimArgs[3] == 1) + { + gBattleAnimArgs[2] = -gBattleAnimArgs[2]; + } + } + + sprite->data[0] = gBattleAnimArgs[4]; + sprite->data[1] = gSprites[monSpriteId].x; + sprite->data[2] = gSprites[monSpriteId].x + gBattleAnimArgs[1]; + sprite->data[3] = gSprites[monSpriteId].y; + sprite->data[4] = gSprites[monSpriteId].y + gBattleAnimArgs[2]; + InitSpriteDataForLinearTranslation(sprite); + sprite->data[3] = 0; + sprite->data[4] = 0; + sprite->data[5] = monSpriteId; + sprite->invisible = TRUE; + StoreSpriteCallbackInData6(sprite, DestroyAnimSprite); + sprite->callback = TranslateSpriteLinearByIdFixedPoint; +} + +static void SlideMonToOffsetPartner(struct Sprite *sprite) +{ + u8 battler; + u8 monSpriteId; + if (!gBattleAnimArgs[0]) + battler = BATTLE_PARTNER(gBattleAnimAttacker); + else + battler = BATTLE_PARTNER(gBattleAnimTarget); + + monSpriteId = gBattlerSpriteIds[battler]; + if (GetBattlerSide(battler) != B_SIDE_PLAYER) { gBattleAnimArgs[1] = -gBattleAnimArgs[1]; if (gBattleAnimArgs[3] == 1) diff --git a/src/battle_anim_rock.c b/src/battle_anim_rock.c index 354fb21014..ec7bc535df 100644 --- a/src/battle_anim_rock.c +++ b/src/battle_anim_rock.c @@ -478,14 +478,15 @@ void AnimRockFragment(struct Sprite *sprite) // Swirls particle in vortex. Used for moves like Fire Spin or Sand Tomb void AnimParticleInVortex(struct Sprite *sprite) { - if (IsDoubleBattle() //got a little lazy here will fix later - && (gAnimMoveIndex == MOVE_BLEAKWIND_STORM + if (IsDoubleBattle() + && (gAnimMoveIndex == MOVE_BLEAKWIND_STORM || gAnimMoveIndex == MOVE_SANDSEAR_STORM || gAnimMoveIndex == MOVE_SPRINGTIDE_STORM || gAnimMoveIndex == MOVE_WILDBOLT_STORM)) InitSpritePosToAnimTargetsCentre(sprite, FALSE); else - InitSpritePosToAnimTarget(sprite, FALSE); + InitSpritePosToAnimBattler(gBattleAnimArgs[6], sprite, FALSE); + sprite->data[0] = gBattleAnimArgs[3]; sprite->data[1] = gBattleAnimArgs[2]; sprite->data[2] = gBattleAnimArgs[4]; diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 87b1cd5ca4..3396999487 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -31,6 +31,7 @@ #include "text.h" #include "util.h" #include "window.h" +#include "line_break.h" #include "constants/battle_anim.h" #include "constants/battle_move_effects.h" #include "constants/battle_partner.h" @@ -2044,6 +2045,7 @@ static void PlayerHandleChooseAction(u32 battler) ActionSelectionCreateCursorAt(gActionSelectionCursor[battler], 0); PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, battler, gBattlerPartyIndexes[battler]); BattleStringExpandPlaceholdersToDisplayedString(gText_WhatWillPkmnDo); + BreakStringAutomatic(gDisplayedStringBattle, WindowWidthPx(B_WIN_ACTION_PROMPT), 2, FONT_NORMAL); if (B_SHOW_PARTNER_TARGET && gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && IsBattlerAlive(B_POSITION_PLAYER_RIGHT)) { diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index b85157f246..932ce47fd9 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -20,6 +20,7 @@ #include "text.h" #include "util.h" #include "window.h" +#include "line_break.h" #include "constants/battle_anim.h" #include "constants/songs.h" #include "constants/trainers.h" @@ -298,6 +299,7 @@ static void SafariHandleChooseAction(u32 battler) ActionSelectionCreateCursorAt(gActionSelectionCursor[battler], 0); BattleStringExpandPlaceholdersToDisplayedString(gText_WhatWillPkmnDo2); + BreakStringAutomatic(gDisplayedStringBattle, WindowWidthPx(B_WIN_ACTION_PROMPT), 2, FONT_NORMAL); BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_ACTION_PROMPT); } diff --git a/src/battle_message.c b/src/battle_message.c index 8e80f92ecb..49b85e96d5 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -22,6 +22,7 @@ #include "text.h" #include "trainer_hill.h" #include "window.h" +#include "line_break.h" #include "constants/abilities.h" #include "constants/battle_dome.h" #include "constants/battle_string_ids.h" @@ -162,6 +163,11 @@ const u8 gText_drastically[] = _("drastically "); const u8 gText_severely[] = _("severely "); static const u8 sText_TerrainReturnedToNormal[] = _("The terrain returned to normal!"); // Unused +// Remove these when done testing +static const u8 sTest_TempTestText1[] = _("This is a text for testing stuff."); +static const u8 sTest_TempTestText2[] = _("This is a text for testing stuff that should be two lines."); +static const u8 sTest_TempTestText3[] = _("This is a text for testing stuff that should be three lines so it has to have some extra text."); + const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = { [STRINGID_TRAINER1LOSETEXT] = COMPOUND_STRING("{B_TRAINER1_LOSE_TEXT}"), @@ -1402,8 +1408,8 @@ const u8 gText_PkmnIsEvolving[] = _("What?\n{STR_VAR_1} is evolving!"); const u8 gText_CongratsPkmnEvolved[] = _("Congratulations! Your {STR_VAR_1}\nevolved into {STR_VAR_2}!{WAIT_SE}\p"); const u8 gText_PkmnStoppedEvolving[] = _("Huh? {STR_VAR_1}\nstopped evolving!\p"); const u8 gText_EllipsisQuestionMark[] = _("……?\p"); -const u8 gText_WhatWillPkmnDo[] = _("What will\n{B_BUFF1} do?"); -const u8 gText_WhatWillPkmnDo2[] = _("What will\n{B_PLAYER_NAME} do?"); +const u8 gText_WhatWillPkmnDo[] = _("What will {B_BUFF1} do?"); +const u8 gText_WhatWillPkmnDo2[] = _("What will {B_PLAYER_NAME} do?"); const u8 gText_WhatWillWallyDo[] = _("What will\nWALLY do?"); const u8 gText_LinkStandby[] = _("{PAUSE 16}Link standby…"); const u8 gText_BattleMenu[] = _("Battle{CLEAR_TO 56}Bag\nPokémon{CLEAR_TO 56}Run"); @@ -2421,8 +2427,7 @@ static void GetBattlerNick(u32 battler, u8 *dst) } \ } \ GetBattlerNick(battler, text); \ - toCpy = text; \ - dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize); + toCpy = text; #define HANDLE_NICKNAME_STRING_LOWERCASE(battler) \ if (GetBattlerSide(battler) != B_SIDE_PLAYER) \ @@ -2439,8 +2444,7 @@ static void GetBattlerNick(u32 battler, u8 *dst) } \ } \ GetBattlerNick(battler, text); \ - toCpy = text; \ - dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize); + toCpy = text; static const u8 *BattleStringGetOpponentNameByTrainerId(u16 trainerId, u8 *text, u8 multiplayerId, u8 battler) { @@ -2589,17 +2593,10 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) { u32 dstID = 0; // if they used dstID, why not use srcID as well? const u8 *toCpy = NULL; - u32 lastValidSkip = 0; - u32 toCpyWidth = 0; - u32 dstWidth = 0; - // This buffer may hold either the name of a trainer, Pokémon, or item. u8 text[max(max(max(32, TRAINER_NAME_LENGTH + 1), POKEMON_NAME_LENGTH + 1), ITEM_NAME_LENGTH)]; u8 *textStart = &text[0]; u8 multiplayerId; u8 fontId = FONT_NORMAL; - s16 letterSpacing = 0; - u32 lineNum = 1; - u32 displayedLineNums = 1; if (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK) multiplayerId = gRecordedBattleMultiplayerId; @@ -2617,11 +2614,14 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) while (*src != EOS) { toCpy = NULL; - dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize); if (*src == PLACEHOLDER_BEGIN) { src++; + u32 classLength = 0; + u32 nameLength = 0; + const u8 *classString; + const u8 *nameString; switch (*src) { case B_TXT_BUFF1: @@ -2804,9 +2804,24 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) break; case B_TXT_TRAINER1_NAME_WITH_CLASS: // trainer1 name with trainer class toCpy = textStart; - textStart = StringCopy(textStart, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A)); - textStart = StringAppend(textStart, gText_Space2); - textStart = StringAppend(textStart, BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, textStart, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT))); + classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A); + while (classString[classLength] != EOS) + { + textStart[classLength] = classString[classLength]; + classLength++; + } + textStart[classLength] = CHAR_SPACE; + textStart += classLength + 1; + nameString = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, textStart, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)); + if (nameString != textStart) + { + while (nameString[nameLength] != EOS) + { + textStart[nameLength] = nameString[nameLength]; + nameLength++; + } + textStart[nameLength] = EOS; + } break; case B_TXT_LINK_PLAYER_NAME: // link player name toCpy = gLinkPlayers[multiplayerId].name; @@ -2926,9 +2941,24 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) break; case B_TXT_TRAINER2_NAME_WITH_CLASS: toCpy = textStart; - textStart = StringCopy(textStart, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B)); - textStart = StringAppend(textStart, gText_Space2); - textStart = StringAppend(textStart, BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_B, textStart, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT))); + classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B); + while (classString[classLength] != EOS) + { + textStart[classLength] = classString[classLength]; + classLength++; + } + textStart[classLength] = CHAR_SPACE; + textStart += classLength + 1; + nameString = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_B, textStart, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)); + if (nameString != textStart) + { + while (nameString[nameLength] != EOS) + { + textStart[nameLength] = nameString[nameLength]; + nameLength++; + } + textStart[nameLength] = EOS; + } break; case B_TXT_TRAINER2_LOSE_TEXT: if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) @@ -2966,9 +2996,24 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) break; case B_TXT_PARTNER_NAME_WITH_CLASS: toCpy = textStart; - textStart = StringCopy(textStart, gTrainerClasses[GetFrontierOpponentClass(gPartnerTrainerId)].name); - textStart = StringAppend(textStart, gText_Space2); - textStart = StringAppend(textStart, BattleStringGetPlayerName(textStart, GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT))); + classString = gTrainerClasses[GetFrontierOpponentClass(gPartnerTrainerId)].name; + while (classString[classLength] != EOS) + { + textStart[classLength] = classString[classLength]; + classLength++; + } + textStart[classLength] = CHAR_SPACE; + textStart += classLength + 1; + nameString = BattleStringGetPlayerName(textStart, GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT)); + if (nameString != textStart) + { + while (nameString[nameLength] != EOS) + { + textStart[nameLength] = nameString[nameLength]; + nameLength++; + } + textStart[nameLength] = EOS; + } break; case B_TXT_ATK_TRAINER_NAME: toCpy = BattleStringGetTrainerName(text, multiplayerId, gBattlerAttacker); @@ -2999,24 +3044,42 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) } else { + classString = NULL; switch (GetBattlerPosition(gBattlerAttacker)) { case B_POSITION_PLAYER_RIGHT: if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) - textStart = StringCopy(textStart, gTrainerClasses[GetFrontierOpponentClass(gPartnerTrainerId)].name); + classString = gTrainerClasses[GetFrontierOpponentClass(gPartnerTrainerId)].name; break; case B_POSITION_OPPONENT_LEFT: - textStart = StringCopy(textStart, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A)); + classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A); break; case B_POSITION_OPPONENT_RIGHT: if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && !BATTLE_TWO_VS_ONE_OPPONENT) - textStart = StringCopy(textStart, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B)); + classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B); else - textStart = StringCopy(textStart, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A)); + classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A); break; } - textStart = StringAppend(textStart, gText_Space2); - textStart = StringAppend(textStart, BattleStringGetTrainerName(textStart, multiplayerId, gBattlerAttacker)); + classLength = 0; + nameLength = 0; + while (classString[classLength] != EOS) + { + textStart[classLength] = classString[classLength]; + classLength++; + } + textStart[classLength] = CHAR_SPACE; + textStart += 1 + classLength; + nameString = BattleStringGetTrainerName(textStart, multiplayerId, gBattlerAttacker); + if (nameString != textStart) + { + while (nameString[nameLength] != EOS) + { + textStart[nameLength] = nameString[nameLength]; + nameLength++; + } + textStart[nameLength] = EOS; + } } break; case B_TXT_ATK_TEAM1: @@ -3059,18 +3122,6 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) if (toCpy != NULL) { - toCpyWidth = GetStringLineWidth(fontId, toCpy, letterSpacing, 1, dstSize); - - if (dstWidth + toCpyWidth > BATTLE_MSG_MAX_WIDTH) - { - dst[lastValidSkip] = displayedLineNums == 1 ? CHAR_NEWLINE : CHAR_PROMPT_SCROLL; - dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize); - if (displayedLineNums == 1) - displayedLineNums++; - else - displayedLineNums = 1; - lineNum++; - } while (*toCpy != EOS) { dst[dstID] = *toCpy; @@ -3090,31 +3141,7 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) } else { - toCpyWidth = GetGlyphWidth(*src, FALSE, fontId); dst[dstID] = *src; - if (dstWidth + toCpyWidth > BATTLE_MSG_MAX_WIDTH) - { - dst[lastValidSkip] = displayedLineNums == 1 ? CHAR_NEWLINE : CHAR_PROMPT_SCROLL; - if (displayedLineNums == 1) - displayedLineNums++; - else - displayedLineNums = 1; - lineNum++; - dstWidth = 0; - } - switch (*src) - { - case CHAR_PROMPT_CLEAR: - case CHAR_PROMPT_SCROLL: - displayedLineNums = 1; - case CHAR_NEWLINE: - lineNum++; - dstWidth = 0; - //fallthrough - case CHAR_SPACE: - lastValidSkip = dstID; - break; - } dstID++; } src++; @@ -3123,6 +3150,8 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) dst[dstID] = *src; dstID++; + BreakStringAutomatic(dst, BATTLE_MSG_MAX_WIDTH, BATTLE_MSG_MAX_WIDTH, fontId); + return dstID; } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 4e17e07dde..6e3e980a7e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1125,7 +1125,6 @@ static bool32 NoTargetPresent(u8 battler, u32 move) return FALSE; } -// TODO: Convert this to a proper FORM_CHANGE type. static bool32 TryAegiFormChange(void) { // Only Aegislash with Stance Change can transform, transformed mons cannot. @@ -1140,12 +1139,12 @@ static bool32 TryAegiFormChange(void) case SPECIES_AEGISLASH_SHIELD: // Shield -> Blade if (IS_MOVE_STATUS(gCurrentMove)) return FALSE; - gBattleMons[gBattlerAttacker].species = SPECIES_AEGISLASH_BLADE; + TryBattleFormChange(gBattlerAttacker, FORM_CHANGE_BATTLE_ATTACK); break; case SPECIES_AEGISLASH_BLADE: // Blade -> Shield if (gCurrentMove != MOVE_KINGS_SHIELD) return FALSE; - gBattleMons[gBattlerAttacker].species = SPECIES_AEGISLASH_SHIELD; + TryBattleFormChange(gBattlerAttacker, FORM_CHANGE_BATTLE_KINGS_SHIELD); break; } @@ -2323,9 +2322,9 @@ static void Cmd_adjustdamage(void) gBattleStruct->calculatedDamageDone = TRUE; gBattlescriptCurrInstr = cmd->nextInstr; - // TODO: might be a bug if (gSpecialStatuses[gBattlerAttacker].gemBoost && MoveResultHasEffect(gBattlerTarget) + && !(gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE) && gBattleMons[gBattlerAttacker].item && gMovesInfo[gCurrentMove].effect != EFFECT_PLEDGE && gCurrentMove != MOVE_STRUGGLE) @@ -2919,6 +2918,7 @@ static void Cmd_resultmessage(void) CMD_ARGS(); u32 stringId = 0; + u16 *moveResultFlags = &gBattleStruct->moveResultFlags[gBattlerTarget]; if (gBattleControllerExecFlags) return; @@ -2935,8 +2935,8 @@ static void Cmd_resultmessage(void) return; } - if (gBattleStruct->moveResultFlags[gBattlerTarget] & MOVE_RESULT_MISSED - && (!(gBattleStruct->moveResultFlags[gBattlerTarget] & MOVE_RESULT_DOESNT_AFFECT_FOE) || gBattleStruct->missStringId[gBattlerTarget] > 2)) + if (*moveResultFlags & MOVE_RESULT_MISSED + && (!(*moveResultFlags & MOVE_RESULT_DOESNT_AFFECT_FOE) || gBattleStruct->missStringId[gBattlerTarget] > 2)) { if (gBattleStruct->missStringId[gBattlerTarget] > B_MSG_AVOIDED_ATK) // Wonder Guard or Levitate - show the ability pop-up CreateAbilityPopUp(gBattlerTarget, gBattleMons[gBattlerTarget].ability, (IsDoubleBattle()) != 0); @@ -2946,7 +2946,7 @@ static void Cmd_resultmessage(void) else { gBattleCommunication[MSG_DISPLAY] = 1; - switch (gBattleStruct->moveResultFlags[gBattlerTarget] & ~MOVE_RESULT_MISSED) + switch (*moveResultFlags & ~MOVE_RESULT_MISSED) { case MOVE_RESULT_SUPER_EFFECTIVE: if (IsDoubleSpreadMove()) @@ -3014,52 +3014,52 @@ static void Cmd_resultmessage(void) case MOVE_RESULT_FOE_HUNG_ON: gLastUsedItem = gBattleMons[gBattlerTarget].item; gPotentialItemEffectBattler = gBattlerTarget; - gBattleStruct->moveResultFlags[gBattlerTarget] &= ~(MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON); + *moveResultFlags &= ~(MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_HangedOnMsg; return; default: - if (gBattleStruct->moveResultFlags[gBattlerTarget] & MOVE_RESULT_ONE_HIT_KO) + if (*moveResultFlags & MOVE_RESULT_ONE_HIT_KO) { - gBattleStruct->moveResultFlags[gBattlerTarget] &= ~MOVE_RESULT_ONE_HIT_KO; - gBattleStruct->moveResultFlags[gBattlerTarget] &= ~MOVE_RESULT_SUPER_EFFECTIVE; - gBattleStruct->moveResultFlags[gBattlerTarget] &= ~MOVE_RESULT_NOT_VERY_EFFECTIVE; + *moveResultFlags &= ~MOVE_RESULT_ONE_HIT_KO; + *moveResultFlags &= ~MOVE_RESULT_SUPER_EFFECTIVE; + *moveResultFlags &= ~MOVE_RESULT_NOT_VERY_EFFECTIVE; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_OneHitKOMsg; return; } - else if (gBattleStruct->moveResultFlags[gBattlerTarget] & MOVE_RESULT_STURDIED) + else if (*moveResultFlags & MOVE_RESULT_STURDIED) { - gBattleStruct->moveResultFlags[gBattlerTarget] &= ~(MOVE_RESULT_STURDIED | MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON); + *moveResultFlags &= ~(MOVE_RESULT_STURDIED | MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON); gSpecialStatuses[gBattlerTarget].sturdied = FALSE; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_SturdiedMsg; return; } - else if (gBattleStruct->moveResultFlags[gBattlerTarget] & MOVE_RESULT_FOE_ENDURED) + else if (*moveResultFlags & MOVE_RESULT_FOE_ENDURED) { - gBattleStruct->moveResultFlags[gBattlerTarget] &= ~(MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON); + *moveResultFlags &= ~(MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_EnduredMsg; return; } - else if (gBattleStruct->moveResultFlags[gBattlerTarget] & MOVE_RESULT_FOE_HUNG_ON) + else if (*moveResultFlags & MOVE_RESULT_FOE_HUNG_ON) { gLastUsedItem = gBattleMons[gBattlerTarget].item; gPotentialItemEffectBattler = gBattlerTarget; - gBattleStruct->moveResultFlags[gBattlerTarget] &= ~(MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON); + *moveResultFlags &= ~(MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_HangedOnMsg; return; } - else if (gBattleStruct->moveResultFlags[gBattlerTarget] & MOVE_RESULT_FAILED) + else if (*moveResultFlags & MOVE_RESULT_FAILED) { stringId = STRINGID_BUTITFAILED; } - else if (B_AFFECTION_MECHANICS == TRUE && (gBattleStruct->moveResultFlags[gBattlerTarget] & MOVE_RESULT_FOE_ENDURED_AFFECTION)) + else if (B_AFFECTION_MECHANICS == TRUE && (*moveResultFlags & MOVE_RESULT_FOE_ENDURED_AFFECTION)) { gSpecialStatuses[gBattlerTarget].affectionEndured = FALSE; - gBattleStruct->moveResultFlags[gBattlerTarget] &= ~MOVE_RESULT_FOE_ENDURED_AFFECTION; + *moveResultFlags &= ~MOVE_RESULT_FOE_ENDURED_AFFECTION; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_AffectionBasedEndurance; return; @@ -4436,6 +4436,15 @@ static void Cmd_tryfaintmon(void) } else { + if (gBattleMons[battler].ability == ABILITY_NEUTRALIZING_GAS + && !(gAbsentBattlerFlags & (1u << battler)) + && !IsBattlerAlive(battler)) + { + gBattleMons[battler].ability = ABILITY_NONE; + BattleScriptPush(gBattlescriptCurrInstr); + gBattlescriptCurrInstr = BattleScript_NeutralizingGasExits; + return; + } if (cmd->battler == BS_ATTACKER) { destinyBondBattler = gBattlerTarget; diff --git a/src/battle_util.c b/src/battle_util.c index 11d5996724..49d9adf475 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -6933,7 +6933,7 @@ static u8 TrySetEnigmaBerry(u32 battler) { if (IsBattlerAlive(battler) && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) - && ((TARGET_TURN_DAMAGED && gBattleStruct->moveResultFlags[battler] & MOVE_RESULT_SUPER_EFFECTIVE) || gBattleScripting.overrideBerryRequirements) + && ((BATTLER_TURN_DAMAGED(battler) && gBattleStruct->moveResultFlags[battler] & MOVE_RESULT_SUPER_EFFECTIVE) || gBattleScripting.overrideBerryRequirements) && !(gBattleScripting.overrideBerryRequirements && gBattleMons[battler].hp == gBattleMons[battler].maxHP) && (B_HEAL_BLOCKING < GEN_5 || !(gStatuses3[battler] & STATUS3_HEAL_BLOCK))) { @@ -6957,7 +6957,7 @@ static u8 DamagedStatBoostBerryEffect(u32 battler, u8 statId, u8 category) || (!DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) && GetBattleMoveCategory(gCurrentMove) == category && battler != gBattlerAttacker - && TARGET_TURN_DAMAGED)) + && BATTLER_TURN_DAMAGED(battler))) ) { BufferStatChange(battler, statId, STRINGID_STATROSE); @@ -10505,6 +10505,7 @@ static void UpdateMoveResultFlags(uq4_12_t modifier, u32 battler) { gBattleStruct->moveResultFlags[battler] |= MOVE_RESULT_DOESNT_AFFECT_FOE; gBattleStruct->moveResultFlags[battler] &= ~(MOVE_RESULT_NOT_VERY_EFFECTIVE | MOVE_RESULT_SUPER_EFFECTIVE); + gBattleStruct->blunderPolicy = FALSE; // Don't activate if missed } else if (modifier == UQ_4_12(1.0)) { @@ -10981,6 +10982,10 @@ u16 GetBattleFormChangeTargetSpecies(u32 battler, u16 method) if (GetBattlerTeraType(battler) == formChanges[i].param1) targetSpecies = formChanges[i].targetSpecies; break; + case FORM_CHANGE_BATTLE_ATTACK: + case FORM_CHANGE_BATTLE_KINGS_SHIELD: + targetSpecies = formChanges[i].targetSpecies; + break; } } } diff --git a/src/data/moves_info.h b/src/data/moves_info.h index 5021dd5a24..180d0d74ac 100644 --- a/src/data/moves_info.h +++ b/src/data/moves_info.h @@ -8492,7 +8492,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .type = TYPE_NORMAL, .accuracy = 0, .pp = 40, - .target = MOVE_TARGET_USER, + .target = MOVE_TARGET_USER, // Targeting is handled through the script .priority = 0, .category = DAMAGE_CATEGORY_STATUS, .zMove = { .effect = Z_EFFECT_ATK_UP_1 }, @@ -12217,7 +12217,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = { .name = COMPOUND_STRING("Coil"), .description = COMPOUND_STRING( - "Coils up to raise Attack\n" + "Coils up to raise Attack,\n" "Defense and Accuracy."), .effect = EFFECT_COIL, .power = 0, @@ -14421,7 +14421,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .type = TYPE_FAIRY, .accuracy = 0, .pp = 10, - .target = MOVE_TARGET_USER, + .target = MOVE_TARGET_USER, // The targeting of Flower Shield is handled through a script .priority = 0, .category = DAMAGE_CATEGORY_STATUS, .zMove = { .effect = Z_EFFECT_DEF_UP_1 }, @@ -17335,7 +17335,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .name = COMPOUND_STRING("Octolock"), .description = COMPOUND_STRING( "Traps the foe to lower Def\n" - "and Sp. Def fall each turn."), + "and Sp. Def each turn."), .effect = EFFECT_OCTOLOCK, .power = 0, .type = TYPE_FIGHTING, @@ -20610,6 +20610,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .priority = 0, .category = DAMAGE_CATEGORY_PHYSICAL, .makesContact = TRUE, + .minimizeDoubleDamage = TRUE, .battleAnimScript = gBattleAnimMove_SupercellSlam, }, diff --git a/src/data/pokemon/form_change_tables.h b/src/data/pokemon/form_change_tables.h index 46dec53544..4af68ce318 100644 --- a/src/data/pokemon/form_change_tables.h +++ b/src/data/pokemon/form_change_tables.h @@ -789,9 +789,11 @@ static const struct FormChange sFurfrouFormChangeTable[] = { #if P_FAMILY_HONEDGE static const struct FormChange sAegislashFormChangeTable[] = { - {FORM_CHANGE_BATTLE_SWITCH, SPECIES_AEGISLASH_SHIELD}, - {FORM_CHANGE_FAINT, SPECIES_AEGISLASH_SHIELD}, - {FORM_CHANGE_END_BATTLE, SPECIES_AEGISLASH_SHIELD}, + {FORM_CHANGE_BATTLE_ATTACK, SPECIES_AEGISLASH_BLADE}, + {FORM_CHANGE_BATTLE_KINGS_SHIELD, SPECIES_AEGISLASH_SHIELD}, + {FORM_CHANGE_BATTLE_SWITCH, SPECIES_AEGISLASH_SHIELD}, + {FORM_CHANGE_FAINT, SPECIES_AEGISLASH_SHIELD}, + {FORM_CHANGE_END_BATTLE, SPECIES_AEGISLASH_SHIELD}, {FORM_CHANGE_TERMINATOR}, }; #endif //P_FAMILY_HONEDGE diff --git a/src/line_break.c b/src/line_break.c new file mode 100644 index 0000000000..b8888f501f --- /dev/null +++ b/src/line_break.c @@ -0,0 +1,281 @@ +#include "global.h" +#include "line_break.h" +#include "text.h" +#include "malloc.h" + +void StripLineBreaks(u8 *src) +{ + u32 currIndex = 0; + while (src[currIndex] != EOS) + { + if (src[currIndex] == CHAR_PROMPT_SCROLL || src[currIndex] == CHAR_NEWLINE) + src[currIndex] = CHAR_SPACE; + currIndex++; + } +} + +void BreakStringAutomatic(u8 *src, u32 maxWidth, u32 screenLines, u8 fontId) +{ + u32 currIndex = 0; + u8 *currSrc = src; + while (src[currIndex] != EOS) + { + if (src[currIndex] == CHAR_PROMPT_CLEAR) + { + u8 replacedChar = src[currIndex + 1]; + src[currIndex + 1] = EOS; + BreakSubStringAutomatic(currSrc, maxWidth, screenLines, fontId); + src[currIndex + 1] = replacedChar; + currSrc = &src[currIndex + 1]; + } + currIndex++; + } + BreakSubStringAutomatic(currSrc, maxWidth, screenLines, fontId); +} + +void BreakSubStringAutomatic(u8 *src, u32 maxWidth, u32 screenLines, u8 fontId) +{ + // If the string already has line breaks, don't interfere with them + if (StringHasManualBreaks(src)) + return; + // Sanity check + if (src[0] == EOS) + return; + u32 numChars = 1; + u32 numWords = 1; + u32 currWordIndex = 0; + u32 currWordLength = 1; + bool32 isPrevCharSplitting = FALSE; + bool32 isCurrCharSplitting; + // Get numbers of chars in string and count words + while (src[numChars] != EOS) + { + isCurrCharSplitting = IsWordSplittingChar(src, numChars); + if (isCurrCharSplitting && !isPrevCharSplitting) + numWords++; + isPrevCharSplitting = isCurrCharSplitting; + numChars++; + } + // Allocate enough space for word data + struct StringWord *allWords = Alloc(numWords*sizeof(struct StringWord)); + + allWords[currWordIndex].startIndex = 0; + allWords[currWordIndex].width = 0; + isPrevCharSplitting = FALSE; + // Fill in word begin index and lengths + for (u32 i = 1; i < numChars; i++) + { + isCurrCharSplitting = IsWordSplittingChar(src, i); + if (isCurrCharSplitting && !isPrevCharSplitting) + { + allWords[currWordIndex].length = currWordLength; + currWordIndex++; + currWordLength = 0; + } + else if (!isCurrCharSplitting && isPrevCharSplitting) + { + allWords[currWordIndex].startIndex = i; + allWords[currWordIndex].width = 0; + currWordLength++; + } + else + { + currWordLength++; + } + isPrevCharSplitting = isCurrCharSplitting; + } + allWords[currWordIndex].length = currWordLength; + + // Fill in individual word widths + for (u32 i = 0; i < numWords; i++) + { + for (u32 j = 0; j < allWords[i].length; j++) + allWords[i].width += GetGlyphWidth(src[allWords[i].startIndex + j], FALSE, fontId); + } + + // Step 1: Does it all fit one one line? Then no break + // Step 2: Try to split across minimum number of lines + u32 spaceWidth = GetGlyphWidth(0, FALSE, fontId); + u32 totalWidth = allWords[0].width; + // Calculate total widths without any line breaks + for (u32 i = 1; i < numWords; i++) + totalWidth += allWords[i].width + spaceWidth; + + // If it doesn't fit on 1 line, do fancy line break calculation + // NOTE: Currently the line break calculation isn't fancy + if (totalWidth > maxWidth) + { + // Figure out how many lines are needed with naive method + u32 currLineWidth = 0; + u32 totalLines = 1; + bool32 shouldTryAgain; + for (currWordIndex = 0; currWordIndex < numWords; currWordIndex++) + { + if (currLineWidth + allWords[currWordIndex].length > maxWidth) + { + totalLines++; + currLineWidth = allWords[currWordIndex].width; + } + else + { + currLineWidth += allWords[currWordIndex].width + spaceWidth; + } + } + // LINE LAYOUT STARTS HERE + struct StringLine *stringLines; + do + { + shouldTryAgain = FALSE; + u16 targetLineWidth = totalWidth/totalLines; + stringLines = Alloc(totalLines*sizeof(struct StringLine)); + for (u32 lineIndex = 0; lineIndex < totalLines; lineIndex++) + { + stringLines[lineIndex].numWords = 0; + stringLines[lineIndex].spaceWidth = spaceWidth; + stringLines[lineIndex].extraSpaceWidth = 0; + } + currWordIndex = 0; + u16 currLineIndex = 0; + stringLines[currLineIndex].words = &allWords[currWordIndex]; + stringLines[currLineIndex].numWords = 1; + currLineWidth = allWords[currWordIndex].width; + currWordIndex++; + while (currWordIndex < numWords) + { + if (currLineWidth + spaceWidth + allWords[currWordIndex].width > maxWidth) + { + // go to next line + currLineIndex++; + if (currLineIndex == totalLines) + { + totalLines++; + Free(stringLines); + shouldTryAgain = TRUE; + break; + } + stringLines[currLineIndex].words = &allWords[currWordIndex]; + stringLines[currLineIndex].numWords = 1; + currLineWidth = allWords[currWordIndex].width; + currWordIndex++; + } + else if (currLineWidth > targetLineWidth) + { + // go to next line + currLineIndex++; + if (currLineIndex == totalLines) + { + totalLines++; + Free(stringLines); + shouldTryAgain = TRUE; + break; + } + stringLines[currLineIndex].words = &allWords[currWordIndex]; + stringLines[currLineIndex].numWords = 1; + currLineWidth = allWords[currWordIndex].width; + currWordIndex++; + } + else + { + // continue on current line + // add word and space width + currLineWidth += spaceWidth + allWords[currWordIndex].width; + stringLines[currLineIndex].numWords++; + currWordIndex++; + } + } + } while (shouldTryAgain); + //u32 currBadness = GetStringBadness(stringLines, totalLines, maxWidth); + BuildNewString(stringLines, totalLines, screenLines, src); + Free(stringLines); + } + + Free(allWords); +} + +// Only allow word splitting on allowed chars +bool32 IsWordSplittingChar(const u8 *src, u32 index) +{ + switch (src[index]) + { + case CHAR_SPACE: + return TRUE; + default: + return FALSE; + } +} + +// Badness calculation +// unfilled lines scale linerarly +// jagged lines scales by the square +// runts scale linearly +// numbers not final +// ISN'T ACTUALLY USED RIGHT NOW +u32 GetStringBadness(struct StringLine *stringLines, u32 numLines, u32 maxWidth) +{ + u32 badness = 0; + u32 *lineWidths = Alloc(numLines*4); + u32 widestWidth = 0; + for (u32 i = 0; i < numLines; i++) + { + lineWidths[i] = 0; + for (u32 j = 0; j < stringLines[i].numWords; j++) + lineWidths[i] += stringLines[i].words[j].width; + lineWidths[i] += (stringLines[i].numWords-1)*stringLines[i].spaceWidth; + if (lineWidths[i] > widestWidth) + widestWidth = lineWidths[i]; + if (stringLines[i].numWords == 1) + badness += BADNESS_RUNT; + } + for (u32 i = 0; i < numLines; i++) + { + u32 extraSpaceWidth = 0; + if (lineWidths[i] != widestWidth) + { + // Not the best way to do this, ideally a line should be allowed to get longer than current widest + // line. But then the widest line has to be recalculated. + while (lineWidths[i] + (extraSpaceWidth + 1) * (stringLines[i].numWords - 1) < widestWidth && extraSpaceWidth < MAX_SPACE_WIDTH) + extraSpaceWidth++; + lineWidths[i] += extraSpaceWidth*(stringLines[i].numWords-1); + } + badness += (maxWidth - lineWidths[i]) * BADNESS_UNFILLED; + u32 baseBadness = (widestWidth - lineWidths[i]) * BADNESS_JAGGED; + badness += baseBadness*baseBadness; + stringLines[i].extraSpaceWidth = extraSpaceWidth; + } + Free(lineWidths); + return badness; +} + +// Build the new string from the data stored in the StringLine structs +void BuildNewString(struct StringLine *stringLines, u32 numLines, u32 maxLines, u8 *str) +{ + u32 srcCharIndex = 0; + for (u32 lineIndex = 0; lineIndex < numLines; lineIndex++) + { + srcCharIndex += stringLines[lineIndex].words[0].length; + for (u32 wordIndex = 1; wordIndex < stringLines[lineIndex].numWords; wordIndex++) + // Add length of word and a space + srcCharIndex += stringLines[lineIndex].words[wordIndex].length + 1; + if (lineIndex + 1 < numLines) + { + // Add the appropriate line break depending on line number + if (lineIndex >= maxLines - 1 && numLines > maxLines) + str[srcCharIndex] = CHAR_PROMPT_SCROLL; + else + str[srcCharIndex] = CHAR_NEWLINE; + srcCharIndex++; + } + } +} + +bool32 StringHasManualBreaks(u8 *src) +{ + u32 charIndex = 0; + while (src[charIndex] != EOS) + { + if (src[charIndex] == CHAR_PROMPT_SCROLL || src[charIndex] == CHAR_NEWLINE) + return TRUE; + charIndex++; + } + return FALSE; +} diff --git a/test/battle/ability/dauntless_shield.c b/test/battle/ability/dauntless_shield.c index ca9125e14f..ada4ace786 100644 --- a/test/battle/ability/dauntless_shield.c +++ b/test/battle/ability/dauntless_shield.c @@ -3,7 +3,7 @@ ASSUMPTIONS { - ASSUME(B_PROTEAN_LIBERO == GEN_9); + ASSUME(B_DAUNTLESS_SHIELD == GEN_9); } SINGLE_BATTLE_TEST("Dauntless Shield raises Defense by one stage") diff --git a/test/battle/ability/intimidate.c b/test/battle/ability/intimidate.c index 1278a45866..e0f97d5bda 100644 --- a/test/battle/ability/intimidate.c +++ b/test/battle/ability/intimidate.c @@ -246,7 +246,7 @@ DOUBLE_BATTLE_TEST("Intimidate is not going to trigger if a mon switches out thr } } -SINGLE_BATTLE_TEST("Intimidate activates when it's no longer effected by Neutralizing Gas") +SINGLE_BATTLE_TEST("Intimidate activates when it's no longer effected by Neutralizing Gas - switching out") { GIVEN { PLAYER(SPECIES_WEEZING) { Ability(ABILITY_NEUTRALIZING_GAS); } @@ -263,3 +263,91 @@ SINGLE_BATTLE_TEST("Intimidate activates when it's no longer effected by Neutral SEND_IN_MESSAGE("Wobbuffet"); } } + +SINGLE_BATTLE_TEST("Intimidate activates when it's no longer affected by Neutralizing Gas - switching moves") +{ + u32 move; + PARAMETRIZE { move = MOVE_U_TURN; } + PARAMETRIZE { move = MOVE_HEALING_WISH; } + PARAMETRIZE { move = MOVE_BATON_PASS; } + GIVEN { + ASSUME(gMovesInfo[MOVE_U_TURN].effect == EFFECT_HIT_ESCAPE); + ASSUME(gMovesInfo[MOVE_HEALING_WISH].effect == EFFECT_HEALING_WISH); + ASSUME(gMovesInfo[MOVE_BATON_PASS].effect == EFFECT_BATON_PASS); + PLAYER(SPECIES_WEEZING) { Ability(ABILITY_NEUTRALIZING_GAS); } + PLAYER(SPECIES_WOBBUFFET) { HP(1); } + OPPONENT(SPECIES_ARBOK) { Ability(ABILITY_INTIMIDATE); } + } WHEN { + TURN { MOVE(player, move); SEND_OUT(player, 1); } + } SCENE { + ABILITY_POPUP(player, ABILITY_NEUTRALIZING_GAS); + MESSAGE("Neutralizing gas filled the area!"); + ANIMATION(ANIM_TYPE_MOVE, move, player); + MESSAGE("The effects of the neutralizing gas wore off!"); + ABILITY_POPUP(opponent, ABILITY_INTIMIDATE); + SEND_IN_MESSAGE("Wobbuffet"); + } THEN { + if (move == MOVE_HEALING_WISH) + EXPECT_EQ(player->hp, player->maxHP); + } +} + +SINGLE_BATTLE_TEST("Intimidate activates when it's no longer affected by Neutralizing Gas - opponent caused switches") +{ + u32 move, item; + PARAMETRIZE { move = MOVE_TACKLE; item = ITEM_EJECT_BUTTON; } + PARAMETRIZE { move = MOVE_GROWL; item = ITEM_EJECT_PACK; } + PARAMETRIZE { move = MOVE_ROAR; item = ITEM_NONE; } + PARAMETRIZE { move = MOVE_DRAGON_TAIL; item = ITEM_NONE; } + GIVEN { + ASSUME(gItemsInfo[ITEM_EJECT_BUTTON].holdEffect == HOLD_EFFECT_EJECT_BUTTON); + ASSUME(gItemsInfo[ITEM_EJECT_PACK].holdEffect == HOLD_EFFECT_EJECT_PACK); + ASSUME(gMovesInfo[MOVE_GROWL].effect == EFFECT_ATTACK_DOWN); + ASSUME(gMovesInfo[MOVE_ROAR].effect == EFFECT_ROAR); + ASSUME(gMovesInfo[MOVE_DRAGON_TAIL].effect == EFFECT_HIT_SWITCH_TARGET); + PLAYER(SPECIES_WEEZING) { Ability(ABILITY_NEUTRALIZING_GAS); Item(item); } + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_ARBOK) { Ability(ABILITY_INTIMIDATE); } + } WHEN { + if (item != ITEM_NONE) { + TURN { MOVE(opponent, move); SEND_OUT(player, 1); } + } else { + TURN { MOVE(opponent, move); } + } + } SCENE { + ABILITY_POPUP(player, ABILITY_NEUTRALIZING_GAS); + MESSAGE("Neutralizing gas filled the area!"); + ANIMATION(ANIM_TYPE_MOVE, move, opponent); + if (item != ITEM_NONE) + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("The effects of the neutralizing gas wore off!"); + ABILITY_POPUP(opponent, ABILITY_INTIMIDATE); + if (item != ITEM_NONE) { + SEND_IN_MESSAGE("Wobbuffet"); + } else { + MESSAGE("Wobbuffet was dragged out!"); + } + } +} + +SINGLE_BATTLE_TEST("Intimidate activates when it's no longer affected by Neutralizing Gas - fainted") +{ + GIVEN { + ASSUME(gMovesInfo[MOVE_FELL_STINGER].effect == EFFECT_FELL_STINGER); + PLAYER(SPECIES_WEEZING) { Ability(ABILITY_NEUTRALIZING_GAS); HP(1); } + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_ARBOK) { Ability(ABILITY_INTIMIDATE); } + } WHEN { + TURN { MOVE(opponent, MOVE_FELL_STINGER); SEND_OUT(player, 1); } + } SCENE { + ABILITY_POPUP(player, ABILITY_NEUTRALIZING_GAS); + MESSAGE("Neutralizing gas filled the area!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_FELL_STINGER, opponent); + MESSAGE("The effects of the neutralizing gas wore off!"); + ABILITY_POPUP(opponent, ABILITY_INTIMIDATE); + MESSAGE("Weezing fainted!"); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponent); + SEND_IN_MESSAGE("Wobbuffet"); + } +} + diff --git a/test/battle/ai/ai_switching.c b/test/battle/ai/ai_switching.c index 4bfba05176..20d05bc0c3 100644 --- a/test/battle/ai/ai_switching.c +++ b/test/battle/ai/ai_switching.c @@ -896,3 +896,17 @@ AI_SINGLE_BATTLE_TEST("Switch AI: AI will switch into mon with good type matchup TURN { MOVE(player, MOVE_TACKLE); EXPECT_SWITCH(opponent, 1); } } } + +AI_SINGLE_BATTLE_TEST("AI_FLAG_SMART_MON_CHOICES: AI correctly handles abilities when scoring moves") +{ + GIVEN { + ASSUME(B_PRANKSTER_DARK_TYPES >= GEN_7); + ASSUME(gSpeciesInfo[SPECIES_GRENINJA].types[1] == TYPE_DARK); + AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_CHECK_VIABILITY | AI_FLAG_OMNISCIENT | AI_FLAG_SMART_MON_CHOICES); + PLAYER(SPECIES_GRENINJA) { Moves(MOVE_WATER_GUN); } + OPPONENT(SPECIES_WHIMSICOTT) { Ability(ABILITY_PRANKSTER); Moves(MOVE_LEECH_SEED, MOVE_STUN_SPORE, MOVE_ABSORB); } + OPPONENT(SPECIES_WHIMSICOTT) { Ability(ABILITY_INFILTRATOR); } + } WHEN { + TURN { MOVE(player, MOVE_WATER_GUN); EXPECT_MOVE(opponent, MOVE_ABSORB); } + } +} diff --git a/test/battle/hold_effect/blunder_policy.c b/test/battle/hold_effect/blunder_policy.c new file mode 100644 index 0000000000..552ad2f6fb --- /dev/null +++ b/test/battle/hold_effect/blunder_policy.c @@ -0,0 +1,67 @@ +#include "global.h" +#include "test/battle.h" + +ASSUMPTIONS +{ + ASSUME(gItemsInfo[ITEM_BLUNDER_POLICY].holdEffect == HOLD_EFFECT_BLUNDER_POLICY); +} + +SINGLE_BATTLE_TEST("Blunder Policy raises the users speed by 2 stages if the user misses") +{ + PASSES_RANDOMLY(3, 10, RNG_ACCURACY); + GIVEN { + ASSUME(gMovesInfo[MOVE_FOCUS_BLAST].accuracy == 70); + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_BLUNDER_POLICY); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_FOCUS_BLAST); } + } SCENE { + NOT ANIMATION(ANIM_TYPE_MOVE, MOVE_FOCUS_BLAST, player); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + } THEN { + EXPECT(player->item == ITEM_NONE); + EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE + 2); + } +} + + +SINGLE_BATTLE_TEST("Blunder Policy will never trigger if the move fails due to an immunity") +{ + PASSES_RANDOMLY(10, 10, RNG_ACCURACY); + GIVEN { + ASSUME(gMovesInfo[MOVE_FOCUS_BLAST].accuracy == 70); + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_BLUNDER_POLICY); } + OPPONENT(SPECIES_GASTLY); + } WHEN { + TURN { MOVE(player, MOVE_FOCUS_BLAST); } + } SCENE { + NONE_OF { + ANIMATION(ANIM_TYPE_MOVE, MOVE_FOCUS_BLAST, player); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + } + } THEN { + EXPECT(player->item == ITEM_BLUNDER_POLICY); + EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE); + } +} + +SINGLE_BATTLE_TEST("Blunder Policy will never trigger if the move fails due to Protect") +{ + PASSES_RANDOMLY(10, 10, RNG_ACCURACY); + GIVEN { + ASSUME(gMovesInfo[MOVE_FOCUS_BLAST].accuracy == 70); + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_BLUNDER_POLICY); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_PROTECT); MOVE(player, MOVE_FOCUS_BLAST); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_PROTECT, opponent); + NONE_OF { + ANIMATION(ANIM_TYPE_MOVE, MOVE_FOCUS_BLAST, player); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + } + } THEN { + EXPECT(player->item == ITEM_BLUNDER_POLICY); + EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE); + } +} diff --git a/test/battle/hold_effect/enigma_berry.c b/test/battle/hold_effect/enigma_berry.c index 5a058eed1b..762774f25d 100644 --- a/test/battle/hold_effect/enigma_berry.c +++ b/test/battle/hold_effect/enigma_berry.c @@ -58,3 +58,19 @@ SINGLE_BATTLE_TEST("Enigma Berry does nothing if Heal Block applies") } } } + +DOUBLE_BATTLE_TEST("Enigma Berry doesn't trigger if partner was hit") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT) { Item(ITEM_ENIGMA_BERRY); } + } WHEN { + TURN { MOVE(playerLeft, MOVE_TACKLE, target: opponentLeft); } + } SCENE { + NOT ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, opponentRight); + } THEN { + EXPECT(opponentRight->item == ITEM_ENIGMA_BERRY); + } +} diff --git a/test/battle/hold_effect/kee_berry.c b/test/battle/hold_effect/kee_berry.c index 2375e65c2f..26cd2152a1 100644 --- a/test/battle/hold_effect/kee_berry.c +++ b/test/battle/hold_effect/kee_berry.c @@ -73,3 +73,19 @@ SINGLE_BATTLE_TEST("Kee Berry doesn't trigger if the item hold user used a physi EXPECT_EQ(player->statStages[STAT_DEF], DEFAULT_STAT_STAGE); } } + +DOUBLE_BATTLE_TEST("Kee Berry doesn't trigger if partner was hit") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT) { Item(ITEM_KEE_BERRY); } + } WHEN { + TURN { MOVE(playerLeft, MOVE_TACKLE, target: opponentLeft); } + } SCENE { + NOT ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, opponentRight); + } THEN { + EXPECT(opponentRight->item == ITEM_KEE_BERRY); + } +} diff --git a/test/battle/hold_effect/maranga_berry.c b/test/battle/hold_effect/maranga_berry.c index 6d12f257a7..77cdaddf42 100644 --- a/test/battle/hold_effect/maranga_berry.c +++ b/test/battle/hold_effect/maranga_berry.c @@ -73,3 +73,19 @@ SINGLE_BATTLE_TEST("Maranga Berry doesn't trigger if the item hold user used a s EXPECT_EQ(player->statStages[STAT_SPDEF], DEFAULT_STAT_STAGE); } } + +DOUBLE_BATTLE_TEST("Maranga Berry doesn't trigger if partner was hit") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT) { Item(ITEM_MARANGA_BERRY); } + } WHEN { + TURN { MOVE(playerLeft, MOVE_TACKLE, target: opponentLeft); } + } SCENE { + NOT ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, opponentRight); + } THEN { + EXPECT(opponentRight->item == ITEM_MARANGA_BERRY); + } +} diff --git a/test/battle/hold_effect/red_card.c b/test/battle/hold_effect/red_card.c index 8c36400c29..aa312797b2 100644 --- a/test/battle/hold_effect/red_card.c +++ b/test/battle/hold_effect/red_card.c @@ -468,3 +468,25 @@ SINGLE_BATTLE_TEST("Red Card prevents Emergency Exit activation when triggered") } TO_DO_BATTLE_TEST("Red Card activates but fails if the attacker has Dynamaxed"); + +SINGLE_BATTLE_TEST("Red Card activates before Eject Pack") +{ + GIVEN { + ASSUME(MoveHasAdditionalEffectSelf(MOVE_OVERHEAT, MOVE_EFFECT_SP_ATK_MINUS_2) == TRUE); + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_EJECT_PACK); } + PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(player, MOVE_OVERHEAT); MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_OVERHEAT, player); + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet is switched out with the Eject Button!"); + } + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, opponent); + MESSAGE("The opposing Wobbuffet held up its Red Card against Wobbuffet!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + } +} diff --git a/test/battle/move_effect/flower_shield.c b/test/battle/move_effect/flower_shield.c new file mode 100644 index 0000000000..e31fc9e5cd --- /dev/null +++ b/test/battle/move_effect/flower_shield.c @@ -0,0 +1,37 @@ +#include "global.h" +#include "test/battle.h" + +ASSUMPTIONS +{ + ASSUME(gMovesInfo[MOVE_FLOWER_SHIELD].effect == EFFECT_FLOWER_SHIELD); +} + +DOUBLE_BATTLE_TEST("Flower Shield raises the defense of all grass type pokemon") +{ + GIVEN { + ASSUME(gSpeciesInfo[SPECIES_TANGELA].types[0] == TYPE_GRASS); + ASSUME(gSpeciesInfo[SPECIES_TANGROWTH].types[0] == TYPE_GRASS); + ASSUME(gSpeciesInfo[SPECIES_SUNKERN].types[0] == TYPE_GRASS); + ASSUME(gSpeciesInfo[SPECIES_SUNFLORA].types[0] == TYPE_GRASS); + PLAYER(SPECIES_TANGELA); + PLAYER(SPECIES_TANGROWTH); + OPPONENT(SPECIES_SUNKERN); + OPPONENT(SPECIES_SUNFLORA); + } WHEN { + TURN { MOVE(playerLeft, MOVE_FLOWER_SHIELD); MOVE(playerRight, MOVE_CELEBRATE); } + } SCENE { + MESSAGE("Tangela used Flower Shield!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_FLOWER_SHIELD, playerLeft); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, playerLeft); + MESSAGE("Tangela's Defense rose!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_FLOWER_SHIELD, playerLeft); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponentLeft); + MESSAGE("The opposing Sunkern's Defense rose!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_FLOWER_SHIELD, playerLeft); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, playerRight); + MESSAGE("Tangrowth's Defense rose!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_FLOWER_SHIELD, playerLeft); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponentRight); + MESSAGE("The opposing Sunflora's Defense rose!"); + } +} diff --git a/test/battle/spread_moves.c b/test/battle/spread_moves.c index e64c5bf4be..d3547d5edf 100644 --- a/test/battle/spread_moves.c +++ b/test/battle/spread_moves.c @@ -3,7 +3,7 @@ DOUBLE_BATTLE_TEST("Spread Moves: Ability and Item effects activate correctly after a multi target move") { - // TODO: Might be a bug, verify on showdown + // TODO: Might be a bug, verify on cardridge GIVEN { PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_LUM_BERRY); } PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_COVERT_CLOAK); } diff --git a/test/battle/status2/confusion.c b/test/battle/status2/confusion.c index 96ed2e1362..4115123b3c 100644 --- a/test/battle/status2/confusion.c +++ b/test/battle/status2/confusion.c @@ -26,3 +26,21 @@ SINGLE_BATTLE_TEST("Confusion adds a 50/33% chance to hit self with 40 power") EXPECT_EQ(damage[0], damage[1]); } } + +SINGLE_BATTLE_TEST("Confusion self hit does not consume Gems") +{ + PASSES_RANDOMLY(B_CONFUSION_SELF_DMG_CHANCE >= GEN_7 ? 33 : 50, 100, RNG_CONFUSION); + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_NORMAL_GEM); }; + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_CONFUSE_RAY); MOVE(player, MOVE_TACKLE); } + } SCENE { + NONE_OF { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, player); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Normal Gem strengthened Wobbuffet's power!"); + } + MESSAGE("It hurt itself in its confusion!"); + } +} diff --git a/tools/trainerproc/main.c b/tools/trainerproc/main.c index b410e810b0..8b939a955f 100644 --- a/tools/trainerproc/main.c +++ b/tools/trainerproc/main.c @@ -1545,6 +1545,7 @@ static void fprint_species(FILE *f, const char *prefix, struct String s) static const unsigned char *male = (unsigned char *)u8"♂"; static const unsigned char *female = (unsigned char *)u8"♀"; static const unsigned char *e_diacritic = (unsigned char *)u8"é"; + static const unsigned char *right_single_quotation_mark = (unsigned char *)u8"’"; for (int i = 0; i < s.string_n; i++) { unsigned char c = s.string[i]; @@ -1562,7 +1563,7 @@ static void fprint_species(FILE *f, const char *prefix, struct String s) underscore = false; fputc(c - 'a' + 'A', f); } - else if (c == '\'' || c == '%') + else if (c == '\'' || c == '%' || is_utf8_character(s, &i, right_single_quotation_mark)) { // Do nothing. }