You are not logged in.
Pages: 1
Hello! Lately I've been trying to change the routine 'InitEnemyMon' in engine/battle/core.asm in order to check if it is possible to change Unown's type depending on hidden power. I haven't had success so far, here's the code I've been using:
InitEnemyMon:
...
call ApplyStatusEffectOnEnemyStats
+ ld a, [wEnemyMonSpecies]
+ cp UNOWN
+ jr nz, .normally
+ ld hl, wEnemyMonDVs
+ callfar GetHiddenPowerType
+ ld de, wEnemyMonType1
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hl]
+ ld [de], a
+ jr .continuation
+ .normally
...
ld [de], a
+ .continuation
ld hl, wBaseStats
...
The GetHiddenPowerType routine found at engine/battle/hidden_power returns a value between 1-16 at hl (skipping NORMAL).
So, does anyone know what am I doing wrong (I'm not an expert at assembly language) or a different method to implement this?
Thanks in advance!
Last edited by Perfect Blue (2021-01-17 19:29:37)
Offline
You are overwriting wEnemyMonType1 and wEnemyMonType2 with the value pointed by [hl] and [hl + 1] respectively, after GetHiddenPowerType returns. It doesn't make much sense. I don't have GetHiddenPowerType routine in my version of pokecrystal, so I don't know what specific routine you are mentioning there. I would assume it returns the type in a, not in [hl]. So you need to overwrite [de] and [de + 1] with the same value in a for both.
Offline
Here's one idea. Your code changes the type to whatever is at positions hl and hl + 1 in whatever bank contains InitEnemyMon (in vanilla that is bank $0f). Since you are 'callfar'ing GetHiddenPowerType, it's probably in a different bank, and so your list of types is presumably also in that different bank. A fix would be for GetHiddenPowerType to load the types first, into bc or whatever.
Offline
It seems that InitEnemyMon only applies when used in Link Battles or the Battle Tower, so I needed to change the GetBaseData routine in home/pokemon.asm (home/mon_data.asm in older versions) instead.
You are overwriting wEnemyMonType1 and wEnemyMonType2 with the value pointed by [hl] and [hl + 1] respectively, after GetHiddenPowerType returns. It doesn't make much sense. I don't have GetHiddenPowerType routine in my version of pokecrystal, so I don't know what specific routine you are mentioning there. I would assume it returns the type in a, not in [hl]. So you need to overwrite [de] and [de + 1] with the same value in a for both.
The GetHiddenPowerType routine I made grabs the type calculation part of hidden power, found at engine/battle/hidden_power.asm, and it turns out it returns the type in a, as you said. So, when I removed the 'ld a, [hl]' parts it worked!
Here's one idea. Your code changes the type to whatever is at positions hl and hl + 1 in whatever bank contains InitEnemyMon (in vanilla that is bank $0f). Since you are 'callfar'ing GetHiddenPowerType, it's probably in a different bank, and so your list of types is presumably also in that different bank. A fix would be for GetHiddenPowerType to load the types first, into bc or whatever.
I didn't need to load the types after all, however when I 'callfar' the routine I get compilation errors (I had to copy all the type calculation code from hidden_power.asm to make it work).
error: home.asm(212) -> home/mon_data.asm(35) -> macros/rst.asm::callfar(12): Requested BANK() of symbol "GetHiddenPowerType", which was not found
error: home.asm(212) -> home/mon_data.asm(35) -> macros/rst.asm::callfar(11): Unknown symbol "GetHiddenPowerType"
Linking failed with 2 errors
make: *** [Makefile:95: pokecrystal.gbc] Error 1
I don't know how to make it locate the routine, hidden_power.asm gets called at BattleCommand_HiddenPower and 'Effect Commands' are located in $0d, so what do I need to do to manually locate the BANK?
Thanks in advance!
Offline
Seems like your function "GetHiddenPowerType" is not being included anywhere. If you've put it in a file of its own, make sure to include that file in main.asm.
Offline
Pages: 1