Skeetendo

’Cause all games were better on the GBC

You are not logged in.

  • Index
  • → Help/Question
  • → [pokecrystal] Changing Unown type depending on hidden power

#1 2021-01-17 19:00:37

Perfect Blue
New member
Registered: 2020-05-12
Post 4/5

[pokecrystal] Changing Unown type depending on hidden power

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

#2 2021-01-17 20:39:10

ElectroMan
New member
Registered: 2018-05-14
Post 9/9

Re: [pokecrystal] Changing Unown type depending on hidden power

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

#3 2021-01-17 20:40:53

lakeofdance
Member
Registered: 2016-09-14
Post 18/20

Re: [pokecrystal] Changing Unown type depending on hidden power

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

#4 2021-01-18 17:45:16

Perfect Blue
New member
Registered: 2020-05-12
Post 5/5

Re: [pokecrystal] Changing Unown type depending on hidden power

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.

ElectroMan wrote:

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!

lakeofdance wrote:

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

#5 2021-01-19 15:50:12

lakeofdance
Member
Registered: 2016-09-14
Post 19/20

Re: [pokecrystal] Changing Unown type depending on hidden power

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

  • Index
  • → Help/Question
  • → [pokecrystal] Changing Unown type depending on hidden power

Board footer

Powered by FluxBB