This method is more consistent with the code already existing in the game, but you either are limited by the amount of unused trainer classes, or you have to add more trainer classes yourself to go beyond the unused trainer classes.
First, you need to make sure that the trainer that is in this particular trainer battle has a unique trainer class. You would have to pick out an unused trainer class in include/constants/trainers.h and give your special trainer that class. Either that, or add in a new trainer class to this file. I'm not sure what complications may arise by adding a new trainer class to this list, so unless you've already used the two unused classes, I'd recommend just using the unused ones. You can assign the trainer class in src/data/trainers.h. Next, you'll need to look into src/pokemon.c. Look for
There, you'll eventually see a line that looks like this:
You'll see several cases, each case being a particular trainer class. Look for this:
Code:
default:
return MUS_BATTLE20;
Directly above "default:", add an additional case statement just like the ones above, but write your unique trainer class instead. Then, put a return statement underneath it, with whatever the name of your song is being the returned value. For example, say your trainer class is called "TRAINER_CLASS_UNIQUE", and your song is called "MUS_BATTLE_UNIQUE". The code you would add immediately above "deafult:" would look something like this:
Code:
case TRAINER_CLASS_UNIQUE:
return MUS_BATTLE_UNIQUE;
With this in place, whenever you fight that particular trainer, your unique song will play instead of the standard trainer battle theme.