blob: d54c385c597c31cfdac070deb97b35011dca8afa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
For this tutorial, we will be changing the battle music for generic trainers depending on the map the player is on.
In `GetBattleBGM` in [pokemon.c](https://github.com/pret/pokeemerald/blob/master/src/pokemon.c), this is where the magic happens.
First, we need to define the region map sections constants at the top of the file:
```diff
...
#include “constants/trainers.h”
+ #include ”constants/region_map_sections.h“
```
Next, go to `GetBattleBGM` which should look like this:
```c
u16 GetBattleBGM(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_KYOGRE_GROUDON)
return MUS_VS_KYOGRE_GROUDON;
else if (gBattleTypeFlags & BATTLE_TYPE_REGI)
return MUS_VS_REGI;
else if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))
return MUS_VS_TRAINER;
else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
{
u8 trainerClass;
if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER)
trainerClass = GetFrontierOpponentClass(gTrainerBattleOpponent_A);
else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER_HILL)
trainerClass = TRAINER_CLASS_EXPERT;
else
trainerClass = gTrainers[gTrainerBattleOpponent_A].trainerClass;
switch (trainerClass)
{
case TRAINER_CLASS_AQUA_LEADER:
case TRAINER_CLASS_MAGMA_LEADER:
return MUS_VS_AQUA_MAGMA_LEADER;
case TRAINER_CLASS_TEAM_AQUA:
case TRAINER_CLASS_TEAM_MAGMA:
case TRAINER_CLASS_AQUA_ADMIN:
case TRAINER_CLASS_MAGMA_ADMIN:
return MUS_VS_AQUA_MAGMA;
case TRAINER_CLASS_LEADER:
return MUS_VS_GYM_LEADER;
case TRAINER_CLASS_CHAMPION:
return MUS_VS_CHAMPION;
case TRAINER_CLASS_PKMN_TRAINER_3:
if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER)
return MUS_VS_RIVAL;
if (!StringCompare(gTrainers[gTrainerBattleOpponent_A].trainerName, gText_BattleWallyName))
return MUS_VS_TRAINER;
return MUS_VS_RIVAL;
case TRAINER_CLASS_ELITE_FOUR:
return MUS_VS_ELITE_FOUR;
case TRAINER_CLASS_SALON_MAIDEN:
case TRAINER_CLASS_DOME_ACE:
case TRAINER_CLASS_PALACE_MAVEN:
case TRAINER_CLASS_ARENA_TYCOON:
case TRAINER_CLASS_FACTORY_HEAD:
case TRAINER_CLASS_PIKE_QUEEN:
case TRAINER_CLASS_PYRAMID_KING:
return MUS_VS_FRONTIER_BRAIN;
default:
return MUS_VS_TRAINER;
}
}
else
return MUS_VS_WILD;
}
```
On `default` under the switch statement for trainer classes is where the normal trainer battle music plays for trainer classes that don’t have special music. It’s here that we’ll be adding in a check for the map section the player is on.
For the sake of this tutorial, we will be making trainers on Route 102 map play `MUS_RG_VS_TRAINER` which is the standard trainer battle music for Pokémon FireRed and LeafGreen.
Here’s how that would look:
```diff
...
- default:
- return MUS_VS_TRAINER;
...
+ default:
+ if (gMapHeader.regionMapSectionId == MAPSEC_ROUTE_102)
+ return MUS_RG_VS_TRAINER;
+ else
+ return MUS_VS_TRAINER;
```
`region_map_sections.h` needs to be included because without it, we won’t be able to use `MAPSEC_*` defines with `*` replacing the map name.
If I didn’t mess anything up, that should work correctly.
|