diff options
author | Cheng Hann Gan <chenghanngan.us@gmail.com> | 2021-12-12 15:52:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-12 12:52:06 -0800 |
commit | c53bdc35f8bdd401e90dfae263a3f5fc9182f86b (patch) | |
tree | 6111353227b153e4aa56422d91e4e79288ce7376 /src | |
parent | a34c9ab91b553fcb1f72b94eb912b94bea58885b (diff) |
Dungeon random/AI decomp + converted positions to structs (#83)
* Decomped RollPercentChance()
* Decomped DungeonRandomCapped()
* Decomped DungeonRandom()
* Decomped FindRockItemTargets()
-Added position struct.
Diffstat (limited to 'src')
-rw-r--r-- | src/code_80521D0_1.c | 30 | ||||
-rw-r--r-- | src/code_8057824_1.c | 156 | ||||
-rw-r--r-- | src/code_80848F0.c | 6 | ||||
-rw-r--r-- | src/code_80869E4.c | 16 | ||||
-rw-r--r-- | src/code_8086A3C.c | 30 | ||||
-rw-r--r-- | src/dungeon_ai_items.c | 89 | ||||
-rw-r--r-- | src/dungeon_movement.c | 8 | ||||
-rw-r--r-- | src/dungeon_random.c | 15 | ||||
-rw-r--r-- | src/dungeon_random_1.c | 13 | ||||
-rw-r--r-- | src/dungeon_util.c | 4 |
10 files changed, 220 insertions, 147 deletions
diff --git a/src/code_80521D0_1.c b/src/code_80521D0_1.c index 433194d..ab497b8 100644 --- a/src/code_80521D0_1.c +++ b/src/code_80521D0_1.c @@ -1,11 +1,12 @@ #include "global.h" +#include "constants/direction.h" +#include "constants/friend_area.h" #include "dungeon_global_data.h" #include "dungeon_entity.h" +#include "dungeon_random.h" #include "friend_area.h" -#include "constants/friend_area.h" -#include "pokemon.h" -#include "constants/direction.h" #include "map.h" +#include "pokemon.h" extern struct DungeonEntity *xxx_call_GetLeaderEntity(void); extern struct DungeonEntity *sub_8085680(u32); @@ -130,7 +131,6 @@ void sub_808C02C(); extern void sub_80861B8(struct DungeonEntity *, u32, u32); void nullsub_99(); -extern u32 DungeonRandomCapped(s32); extern bool8 *gFriendAreas; extern void sub_8049884(); @@ -286,7 +286,7 @@ void sub_808BDEC(void) gDungeonGlobalData->unk7 = 1; SetFacingDirection(LugiaEntity, DIRECTION_SOUTH); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_LUGIA); } @@ -335,7 +335,7 @@ void LugiaPreFightDialogue(void) sub_808BFA0(); SetupBossFightHP(LugiaEntity,800,0x20); sub_8083E88(0x23); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -424,7 +424,7 @@ void sub_808C10C(void) gDungeonGlobalData->unk7 = 1; SetFacingDirection(KyogreEntity, DIRECTION_SOUTH); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); uVar3 = sub_803F994(); iVar2 = sub_803F9B0(); sub_803F878(uVar3,iVar2 + -0x1000); @@ -485,7 +485,7 @@ void KyogrePreFightDialogue(void) sub_803E708(10,0x46); SetupBossFightHP(KyogreEntity,600,0xb); sub_8083E88(0x23); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -542,7 +542,7 @@ void sub_808C3A0(void) gDungeonGlobalData->unk7 = 1; sub_808563C(SetupDeoxysFacingDirection); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_DEOXYS_NORMAL); } @@ -576,7 +576,7 @@ void DeoxysPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_8106390); sub_803E708(10,0x46); sub_808563C(SetupDeoxysFightHP); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -642,7 +642,7 @@ void sub_808C5C0(void) sub_80854D4(); sub_8085930(DIRECTION_NORTH); SetFacingDirection(CelebiEntity, DIRECTION_SOUTH); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); uVar3 = sub_803F994(); iVar2 = sub_803F9B0(); sub_803F878(uVar3,iVar2 + 0xfffff000); @@ -1130,7 +1130,7 @@ void sub_808C9C4(void) sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); SetFacingDirection(MedichamEntity, DIRECTION_SOUTH); - sub_8085860(LeaderEntity->posWorldX, LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x, LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_MEDICHAM); } @@ -1198,7 +1198,7 @@ void sub_808CB5C(void) sub_80854D4(); sub_8085930(DIRECTION_NORTH); sub_8068FE0(MedichamEntity, 0x21C, 0); - sub_8085860(LeaderEntity->posWorldX, LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x, LeaderEntity->posWorld.y); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_MEDICHAM); } @@ -1218,7 +1218,7 @@ void sub_808CBB0(void) sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); SetFacingDirection(SmeargleEntity, DIRECTION_SOUTH); - sub_8085860(LeaderEntity->posWorldX, LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x, LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_SMEARGLE); } @@ -1290,7 +1290,7 @@ void sub_808CD44(void) sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); sub_8068FE0(SmeargleEntity, 0x21C, 0); - sub_8085860(LeaderEntity->posWorldX, LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x, LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_SMEARGLE); } diff --git a/src/code_8057824_1.c b/src/code_8057824_1.c index 5409061..646feca 100644 --- a/src/code_8057824_1.c +++ b/src/code_8057824_1.c @@ -1,9 +1,10 @@ #include "global.h" +#include "constants/direction.h" #include "dungeon_global_data.h" #include "dungeon_entity.h" -#include "pokemon.h" +#include "dungeon_util.h" #include "item.h" -#include "constants/direction.h" +#include "pokemon.h" extern struct DungeonGlobalData *gDungeonGlobalData; @@ -313,7 +314,6 @@ void sub_808919C(); void GroudonScreenFlash2(void); extern void sub_8083F14(); -extern u8 EntityExists(struct DungeonEntity *); extern u8 sub_8086AE4(u32); @@ -388,7 +388,7 @@ void ZapdosReFightDialogue(void) sub_808775C(2); DisplayDungeonDialogue(&gUnknown_8101918); SetupBossFightHP(ZapdosEntity,300,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void ZapdosPostStoryPreFightDialogue(void) @@ -416,7 +416,7 @@ void ZapdosPostStoryPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_8101A04); sub_803E708(10,0x46); SetupBossFightHP(ZapdosEntity,300,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -485,7 +485,7 @@ void sub_80877E8(void) sub_80855E4(sub_8086A3C); SetFacingDirection(MoltresEntity, DIRECTION_SOUTH); sub_8086A3C(MoltresEntity); - sub_8085860(LeaderEntity->posWorldX + -3,LeaderEntity->posWorldY + -2); + sub_8085860(LeaderEntity->posWorld.x + -3,LeaderEntity->posWorld.y + -2); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_MOLTRES); } @@ -511,7 +511,7 @@ void sub_8087848(void) SetFacingDirection(MoltresEntity, DIRECTION_SOUTH); sub_8086A3C(MoltresEntity); } - sub_8085860(LeaderEntity->posWorldX - 5, LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x - 5, LeaderEntity->posWorld.y); uVar4 = sub_803F994(); iVar3 = sub_803F9B0(); sub_803F878(uVar4,iVar3 + -0x1000); @@ -594,7 +594,7 @@ void MoltresPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_8102108); sub_803E708(10,0x46); SetupBossFightHP(MoltresEntity,400,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } @@ -637,7 +637,7 @@ void MoltresReFightDialogue(void) DisplayDungeonDialogue(&gUnknown_81022F8); sub_803E708(10,0x46); SetupBossFightHP(MoltresEntity,400,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void MoltresPostStoryPreFightDialogue(void) @@ -675,7 +675,7 @@ void MoltresPostStoryPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_8102454); sub_803E708(10,0x46); SetupBossFightHP(MoltresEntity,400,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -897,7 +897,7 @@ void sub_8087F54(void) sub_80855E4(sub_8086A3C); SetFacingDirection(ArticunoEntity, DIRECTION_SOUTH); sub_8086A3C(ArticunoEntity); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY + -3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y + -3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_ARTICUNO); } @@ -934,7 +934,7 @@ void sub_8087FF8(void) SetFacingDirection(ArticunoEntity, DIRECTION_SOUTH); sub_8086A3C(ArticunoEntity); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY + -3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y + -3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_ARTICUNO); } @@ -1023,7 +1023,7 @@ void ArticunoPreFightDialogue(void) sub_806CDD4(ArticunoEntity,0xf,DIRECTION_SOUTH); sub_803E708(0x10,0x46); SetupBossFightHP(ArticunoEntity,0x1c2,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void ArticunoReFightDialogue(void) @@ -1045,7 +1045,7 @@ void ArticunoReFightDialogue(void) sub_806CDD4(ArticunoEntity,0xf,DIRECTION_SOUTH); sub_803E708(0x28,0x46); SetupBossFightHP(ArticunoEntity,0x1c2,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void ArticunoPostStoryPreFightDialogue(void) @@ -1081,7 +1081,7 @@ void ArticunoPostStoryPreFightDialogue(void) sub_806CDD4(ArticunoEntity,0xf,DIRECTION_SOUTH); sub_803E708(0x28,0x46); SetupBossFightHP(ArticunoEntity,0x1c2,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -1156,7 +1156,7 @@ void sub_80885C4(void) sub_80854D4(); sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); } void sub_8088608(void) @@ -1192,7 +1192,7 @@ void sub_808862C(void) sub_80861D4(AlakazamEntity,0xd,4); SetFacingDirection(GroudonEntity, DIRECTION_SOUTH); sub_8086A3C(GroudonEntity); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY -3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y -3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_GROUDON); CopySpeciesNametoBuffer(gUnknown_202E038 + 0x50, SPECIES_ALAKAZAM); } @@ -1217,7 +1217,7 @@ void sub_80886C4(void) sub_8068FE0(AlakazamEntity,0x21c,0); SetFacingDirection(GroudonEntity, DIRECTION_SOUTH); sub_8086A3C(GroudonEntity); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); uVar4 = sub_803F994(); iVar2 = sub_803F9B0(); sub_803F878(uVar4,iVar2 + -0x1000); @@ -1247,7 +1247,7 @@ void sub_808875C(void) SetFacingDirection(GroudonEntity, DIRECTION_SOUTH); sub_80861D4(GroudonEntity,0xf,0); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_GROUDON); CopySpeciesNametoBuffer(gUnknown_202E038 + 0x50, SPECIES_ALAKAZAM); } @@ -1344,7 +1344,7 @@ void GroudonPreFightDialogue(void) sub_8085930(DIRECTION_NORTH); sub_8086764(); SetupBossFightHP(GroudonEntity,500,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void GroudonReFightDialogue(void) @@ -1376,7 +1376,7 @@ void GroudonReFightDialogue(void) sub_8085930(DIRECTION_NORTH); sub_8086764(); SetupBossFightHP(GroudonEntity,500,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void GroudonPostStoryPreFightDialogue(void) @@ -1404,7 +1404,7 @@ void GroudonPostStoryPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_810347C); sub_803E708(10,0x46); SetupBossFightHP(GroudonEntity,500,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -1427,7 +1427,7 @@ void SceneGroudonMovement(struct DungeonEntity * param_1) } sub_803E46C(0x46); } - sub_80856C8(param_1,param_1->posWorldX,param_1->posWorldY + 1); + sub_80856C8(param_1,param_1->posWorld.x,param_1->posWorld.y + 1); sub_80861D4(param_1,0xf,0); sub_803E708(10,0x46); sub_808682C(); @@ -1509,7 +1509,7 @@ void sub_8088DC0(void) sub_806CDD4(uVar2,0xe,DIRECTION_SOUTH); sub_8086A3C(uVar3); sub_806CDD4(uVar3,0xe,DIRECTION_SOUTH); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_GROUDON); CopySpeciesNametoBuffer(gUnknown_202E038 + 0x50, SPECIES_ALAKAZAM); } @@ -1530,7 +1530,7 @@ void sub_8088E5C(void) sub_80855E4(sub_8086A3C); sub_8068FE0(uVar2,0x21c,0); sub_8068FE0(uVar3,0x21c,0); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY + -3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y + -3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_GROUDON); CopySpeciesNametoBuffer(gUnknown_202E038 + 0x50, SPECIES_ALAKAZAM); } @@ -1601,8 +1601,8 @@ void MagmaCavernMidDialogue(void) DisplayDungeonDialogue(&gUnknown_8102C30); iVar3->entityData->unk15E = 0; iVar4->entityData->unk15E =0; - local_20[0] = (iVar3->posPixelX + iVar4->posPixelX) / 2; - local_20[1] = (iVar3->posPixelY + iVar4->posPixelY) / 2 + 0x800; + local_20[0] = (iVar3->posPixel.x + iVar4->posPixel.x) / 2; + local_20[1] = (iVar3->posPixel.y + iVar4->posPixel.y) / 2 + 0x800; sub_80858AC(local_20,0x20); sub_803E708(0x3c,0x46); sub_80891F0(); @@ -1671,7 +1671,7 @@ void sub_8089168(void) sub_803E708(10,0x46); SpriteLookAroundEffect(LeaderEntity); sub_803E708(10,0x46); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void sub_808919C(struct DungeonEntity *r0) @@ -1709,10 +1709,10 @@ void sub_8089224(struct DungeonEntity * param_1) { s32 iVar1; - if (param_1->posPixelY < 0x9001) { + if (param_1->posPixel.y < 0x9001) { return; } - iVar1 = param_1->posPixelX; + iVar1 = param_1->posPixel.x; if(iVar1 < 0xE400) { @@ -1774,7 +1774,7 @@ void sub_80892C8(void) sub_80855E4(sub_8086A3C); SetFacingDirection(RayquazaEntity, DIRECTION_SOUTH); sub_8086A3C(RayquazaEntity); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038,SPECIES_RAYQUAZA); } @@ -1796,7 +1796,7 @@ void sub_8089328(void) sub_8072008(RayquazaEntity,RayquazaEntity,gUnknown_80F57CA,0,0); sub_8086A3C(RayquazaEntity); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038,SPECIES_RAYQUAZA); } @@ -1846,7 +1846,7 @@ void RayquazaPreFightDialogue(void) RayquazaScreenFlash(); DisplayDungeonDialogue(&gUnknown_8103820); SetupBossFightHP(RayquazaEntity,600,0x20); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void RayquazaReFightDialogue(void) @@ -1870,7 +1870,7 @@ void RayquazaReFightDialogue(void) RayquazaScreenFlash(); DisplayDungeonDialogue(&gUnknown_81038F8); SetupBossFightHP(RayquazaEntity,600,0x20); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void RayquazaPostStoryPreFightDialogue(void) @@ -1896,7 +1896,7 @@ void RayquazaPostStoryPreFightDialogue(void) RayquazaScreenFlash(); DisplayDungeonDialogue(&gUnknown_8103B30); SetupBossFightHP(RayquazaEntity,600,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -1959,7 +1959,7 @@ void sub_808970C(void) sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); sub_808563C(sub_8089908); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY + -3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y + -3); } void sub_808974C(void) @@ -1971,7 +1971,7 @@ void sub_808974C(void) sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); sub_808563C(sub_80898F8); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY + -3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y + -3); } void sub_8089788(struct DungeonEntity *param_1, u8 param_2, s32 param_3) @@ -2030,7 +2030,7 @@ void sub_80897F0(void) // Get 'em! It's frenzy time! DisplayDungeonDialogue(&gUnknown_8103D50); sub_803E708(10,0x46); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } @@ -2050,7 +2050,7 @@ void sub_8089878(void) DisplayDungeonDialogue(&gUnknown_8103DD8); DisplayDungeonDialogue(&gUnknown_8103E28); sub_803E708(10,0x46); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void sub_80898E4(void) @@ -2083,7 +2083,7 @@ void sub_8089914(void) sub_80855E4(sub_8086A3C); SetFacingDirection(MewtwoEntity, DIRECTION_SOUTH); sub_8086A3C(MewtwoEntity); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038,SPECIES_MEWTWO); } @@ -2107,7 +2107,7 @@ void sub_8089978(void) SetFacingDirection(MewtwoEntity, DIRECTION_SOUTH); sub_8086A3C(MewtwoEntity); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038,SPECIES_MEWTWO); } @@ -2143,7 +2143,7 @@ void MewtwoPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_8104008); sub_803E708(10,0x46); SetupBossFightHP(MewtwoEntity,900,0x20); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void MewtwoPreFightDialogue1(void) @@ -2169,7 +2169,7 @@ void MewtwoPreFightDialogue1(void) MewtwoScreenFlash(); DisplayDungeonDialogue(&gUnknown_8104114); SetupBossFightHP(MewtwoEntity,900,0x20); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -2232,7 +2232,7 @@ void sub_8089C44(void) sub_80854D4(); sub_8085930(DIRECTION_NORTH); SetFacingDirection(EnteiEntity, DIRECTION_SOUTH); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_ENTEI); } @@ -2253,7 +2253,7 @@ void sub_8089C90(void) else { SetFacingDirection(EnteiEntity, DIRECTION_SOUTH); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_ENTEI); } @@ -2282,7 +2282,7 @@ void EnteiPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_81041F8); sub_803E708(10,70); SetupBossFightHP(EnteiEntity,600,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void EnteiPreFightDialogue1(void) @@ -2300,7 +2300,7 @@ void EnteiPreFightDialogue1(void) DisplayDungeonDialogue(&gUnknown_81042B8); sub_803E708(10,70); SetupBossFightHP(EnteiEntity,600,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void EnteiPreFightDialogue2(void) @@ -2322,7 +2322,7 @@ void EnteiPreFightDialogue2(void) DisplayDungeonDialogue(&gUnknown_81043C0); sub_803E708(10,70); SetupBossFightHP(EnteiEntity,600,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -2363,7 +2363,7 @@ void sub_8089EFC(void) sub_80854D4(); sub_8085930(DIRECTION_NORTH); SetFacingDirection(RaikouEntity, DIRECTION_SOUTH); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_RAIKOU); } @@ -2379,7 +2379,7 @@ void sub_8089F44(void) sub_80854D4(); sub_8085930(DIRECTION_NORTH); SetFacingDirection(RaikouEntity, DIRECTION_SOUTH); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_RAIKOU); } @@ -2400,7 +2400,7 @@ void sub_8089F8C(void) else { SetFacingDirection(RaikouEntity, DIRECTION_SOUTH); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_RAIKOU); } @@ -2435,7 +2435,7 @@ void RaikouPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_81045B0); sub_803E708(10,70); SetupBossFightHP(RaikouEntity,0x28a,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void RaikouPreFightDialogue1(void) @@ -2455,7 +2455,7 @@ void RaikouPreFightDialogue1(void) DisplayDungeonDialogue(&gUnknown_81046A0); sub_803E708(10,70); SetupBossFightHP(RaikouEntity,0x28a,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void RaikouPreFightDialogue2(void) @@ -2478,7 +2478,7 @@ void RaikouPreFightDialogue2(void) DisplayDungeonDialogue(&gUnknown_810476C); sub_803E708(10,70); SetupBossFightHP(RaikouEntity,0x28a,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -2521,7 +2521,7 @@ void sub_808A264(void) sub_80855E4(sub_8086A3C); SetFacingDirection(SuicuneEntity, DIRECTION_SOUTH); sub_8086A3C(SuicuneEntity); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_SUICUNE); } @@ -2536,7 +2536,7 @@ void sub_808A2C0(void) sub_80854D4(); sub_8085930(DIRECTION_NORTH); SetFacingDirection(SuicuneEntity, DIRECTION_SOUTH); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_SUICUNE); } @@ -2556,7 +2556,7 @@ void sub_808A308(void) else { SetFacingDirection(SuicuneEntity, DIRECTION_SOUTH); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_SUICUNE); } @@ -2593,7 +2593,7 @@ void SuicunePreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_8104914); sub_803E708(10,70); SetupBossFightHP(SuicuneEntity,0x28a,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void SuicunePreFightDialogue1(void) @@ -2610,7 +2610,7 @@ void SuicunePreFightDialogue1(void) DisplayDungeonDialogue(&gUnknown_8104998); sub_803E708(10,70); SetupBossFightHP(SuicuneEntity,0x28a,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void SuicunePreFightDialogue2(void) @@ -2631,7 +2631,7 @@ void SuicunePreFightDialogue2(void) DisplayDungeonDialogue(&gUnknown_8104A9C); sub_803E708(10,70); SetupBossFightHP(SuicuneEntity,0x28a,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -2697,7 +2697,7 @@ void sub_808A608(void) sub_8085930(DIRECTION_NORTH); SetFacingDirection(HoOhEntity, DIRECTION_SOUTH); sub_8086A3C(HoOhEntity); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY + -6); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y + -6); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_HO_OH); } @@ -2720,7 +2720,7 @@ void sub_808A668(void) SetFacingDirection(HoOhEntity, DIRECTION_SOUTH); sub_8086A3C(HoOhEntity); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 6); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 6); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_HO_OH); } @@ -2746,8 +2746,8 @@ void HoOhPreFightDialogue(void) LeaderEntity = xxx_call_GetLeaderEntity(); HoOhEntity = sub_8085680(0x15); - local_14[0] = LeaderEntity->posPixelX; - local_14[1] = LeaderEntity->posPixelY + -0x1000; + local_14[0] = LeaderEntity->posPixel.x; + local_14[1] = LeaderEntity->posPixel.y + -0x1000; sub_80858AC(local_14,0x88); sub_803E708(0x40,70); DisplayDungeonDialogue(&gUnknown_8104AD4); @@ -2774,7 +2774,7 @@ void HoOhPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_8104CE0); sub_803E708(10,70); SetupBossFightHP(HoOhEntity,800,0x20); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void HoOhPreFightDialogue1(void) @@ -2786,8 +2786,8 @@ void HoOhPreFightDialogue1(void) LeaderEntity = xxx_call_GetLeaderEntity(); HoOhEntity = sub_8085680(0x15); - local_14[0] = LeaderEntity->posPixelX; - local_14[1] = LeaderEntity->posPixelY + -0x1000; + local_14[0] = LeaderEntity->posPixel.x; + local_14[1] = LeaderEntity->posPixel.y + -0x1000; sub_80858AC(local_14,0x88); sub_803E708(0x40,70); if (HasRecruitedMon(SPECIES_HO_OH)) { @@ -2810,7 +2810,7 @@ void HoOhPreFightDialogue1(void) DisplayDungeonDialogue(&gUnknown_8104E0C); sub_803E708(10,70); SetupBossFightHP(HoOhEntity,800,0x20); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } } @@ -2874,7 +2874,7 @@ void sub_808A9E4(void) sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); SetFacingDirection(LatiosEntity, DIRECTION_NORTH); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 4); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 4); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_LATIOS); } @@ -2890,7 +2890,7 @@ void sub_808AA3C(void) sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); SetFacingDirection(LatiosEntity, DIRECTION_NORTH); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_LATIOS); } @@ -2906,7 +2906,7 @@ void sub_808AA94(void) sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); sub_8068FE0(LatiosEntity,0x21c,0); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_LATIOS); } @@ -2927,8 +2927,8 @@ void LatiosPreFightDialogue(void) LeaderEntity = xxx_call_GetLeaderEntity(); LatiosEntity = sub_8085680(0x16); - local_18[0] = LatiosEntity->posPixelX; - local_18[1] = LatiosEntity->posPixelY + (0x80 << 6); + local_18[0] = LatiosEntity->posPixel.x; + local_18[1] = LatiosEntity->posPixel.y + (0x80 << 6); local_18[2] = 0x7000fc; sub_8085EC8(0x1bd,0,0,&local_18[2],1); @@ -2946,7 +2946,7 @@ void LatiosPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_8104F30); sub_803E708(10,70); SetupBossFightHP(LatiosEntity,600,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void LatiosReFightDialogue(void) @@ -2965,7 +2965,7 @@ void LatiosReFightDialogue(void) DisplayDungeonDialogue(&gUnknown_8104F30); sub_803E708(10,70); SetupBossFightHP(LatiosEntity,600,0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void sub_808AC3C(void) @@ -3401,7 +3401,7 @@ void sub_808B2F4(void) sub_80855E4(sub_8086A3C); SetFacingDirection(JirachiEntity, DIRECTION_SOUTH); sub_8086A3C(JirachiEntity); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_JIRACHI); } @@ -3426,7 +3426,7 @@ void sub_808B35C(void) sub_8049ED4(); } - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_JIRACHI); } @@ -3543,7 +3543,7 @@ void JirachiPreFightDialogue(void) DisplayDungeonDialogue(&gUnknown_810550C); sub_803E708(10,70); SetupBossFightHP(JirachiEntity,0x15e,0x20); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void sub_808B50C(void) diff --git a/src/code_80848F0.c b/src/code_80848F0.c index 14b8b3e..ac98809 100644 --- a/src/code_80848F0.c +++ b/src/code_80848F0.c @@ -589,13 +589,13 @@ void sub_8084E00(struct DungeonEntity *param_1,char param_2,char param_3) sub_808AAF0(param_2,gDungeonGlobalData->unk3A0D); break; case 0x2e: - sub_808AE54(param_2,gDungeonGlobalData->unk3A0D,¶m_1->posWorldX); + sub_808AE54(param_2,gDungeonGlobalData->unk3A0D,¶m_1->posWorld.x); break; case 0x2f: - sub_808AEC8(param_2,gDungeonGlobalData->unk3A0D,¶m_1->posWorldX); + sub_808AEC8(param_2,gDungeonGlobalData->unk3A0D,¶m_1->posWorld.x); break; case 0x30: - sub_808AF3C(param_2,gDungeonGlobalData->unk3A0D,¶m_1->posWorldX); + sub_808AF3C(param_2,gDungeonGlobalData->unk3A0D,¶m_1->posWorld.x); break; case 0x31: case 0x32: diff --git a/src/code_80869E4.c b/src/code_80869E4.c index 30bae49..148a88e 100644 --- a/src/code_80869E4.c +++ b/src/code_80869E4.c @@ -60,8 +60,8 @@ void sub_80862BC(struct DungeonEntity *r0) void sub_80862DC(struct DungeonEntity *r0) { u32 array[2]; - array[0] = r0->posPixelX; - array[1] = r0->posPixelY + (0xE0 << 6); + array[0] = r0->posPixel.x; + array[1] = r0->posPixel.y + (0xE0 << 6); sub_804535C(r0, array); sub_806CDD4(r0, 0, DIRECTION_NORTH); @@ -71,8 +71,8 @@ void sub_80862DC(struct DungeonEntity *r0) void sub_8086310(struct DungeonEntity *r0) { u32 array[2]; - array[0] = r0->posPixelX; - array[1] = r0->posPixelY + (0x90 << 8); + array[0] = r0->posPixel.x; + array[1] = r0->posPixel.y + (0x90 << 8); sub_804535C(r0, array); sub_806CE68(r0, DIRECTION_SOUTH); @@ -83,8 +83,8 @@ void sub_8086310(struct DungeonEntity *r0) void sub_8086348(struct DungeonEntity *r0) { u32 array[2]; - array[0] = r0->posPixelX + (0xF0 << 7); - array[1] = r0->posPixelY + 0xffffe000; + array[0] = r0->posPixel.x + (0xF0 << 7); + array[1] = r0->posPixel.y + 0xffffe000; sub_804535C(r0, array); sub_806CDD4(r0, 0, DIRECTION_WEST); @@ -94,8 +94,8 @@ void sub_8086348(struct DungeonEntity *r0) void sub_8086384(struct DungeonEntity *r0) { u32 array[2]; - array[0] = r0->posPixelX + (0xF0 << 7); - array[1] = r0->posPixelY; + array[0] = r0->posPixel.x + (0xF0 << 7); + array[1] = r0->posPixel.y; sub_804535C(r0, array); sub_806CDD4(r0, 0, DIRECTION_WEST); diff --git a/src/code_8086A3C.c b/src/code_8086A3C.c index 1e5c5cd..43889de 100644 --- a/src/code_8086A3C.c +++ b/src/code_8086A3C.c @@ -129,7 +129,7 @@ void sub_8086B14(void) sub_80855E4(sub_8086A3C); sub_8086A3C(SkarmoryEntity); DiglettEntity->entityData->unk15C = 1; - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY + -2); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y + -2); CopySpeciesNametoBuffer(gUnknown_202E038,SPECIES_DIGLETT); CopySpeciesNametoBuffer(gUnknown_202E038 + 0x50, SPECIES_SKARMORY); } @@ -148,7 +148,7 @@ void sub_8086B94(void) sub_8068FE0(DiglettEntity,0x21c,0); sub_80854D4(); sub_8085930(DIRECTION_NORTH); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y); } void sub_8086BDC(char param_1, s32 param_2) @@ -168,17 +168,17 @@ void SkarmoryPreFightDialogue(void) struct subStruct_Skarmory local_1c; struct subStruct_Skarmory local_20; - + LeaderEntity = xxx_call_GetLeaderEntity(); // Player PartnerEntity = GetPartnerEntity(); // Partner DiglettEntity = sub_8085680(4); // Diglett SkarmoryEntity = sub_8085680(3); // Skarmory - local_1c.x = DiglettEntity->posPixelX; - local_1c.y = DiglettEntity->posPixelY + 0x3000; + local_1c.x = DiglettEntity->posPixel.x; + local_1c.y = DiglettEntity->posPixel.y + 0x3000; - local_20.x = SkarmoryEntity->posPixelX; - local_20.y = SkarmoryEntity->posPixelY + 0x2000; + local_20.x = SkarmoryEntity->posPixel.x; + local_20.y = SkarmoryEntity->posPixel.y + 0x2000; sub_8086448(); sub_803E708(10,0x46); @@ -216,7 +216,7 @@ void SkarmoryPreFightDialogue(void) sub_80869E4(LeaderEntity,4,1,4); sub_803E708(10,0x46); sub_8083E88(0xb); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); } void SkarmoryReFightDialogue(void) @@ -224,11 +224,11 @@ void SkarmoryReFightDialogue(void) struct DungeonEntity * LeaderEntity; struct DungeonEntity * SkarmoryEntity; struct subStruct_Skarmory local_14; - + LeaderEntity = xxx_call_GetLeaderEntity(); SkarmoryEntity = sub_8085680(3); - local_14.x = SkarmoryEntity->posPixelX; - local_14.y = SkarmoryEntity->posPixelY + 0x2000; + local_14.x = SkarmoryEntity->posPixel.x; + local_14.y = SkarmoryEntity->posPixel.y + 0x2000; sub_8086448(); sub_803E708(10,0x46); sub_8086E74(SkarmoryEntity); @@ -240,7 +240,7 @@ void SkarmoryReFightDialogue(void) sub_806CDD4(SkarmoryEntity,0xd,0); DisplayDungeonDialogue(&gUnknown_8100CDC); sub_803E708(10,0x46); - sub_80858AC(&LeaderEntity->posPixelX,0x10); + sub_80858AC(&LeaderEntity->posPixel.x,0x10); sub_8083E88(0xb); } @@ -272,7 +272,7 @@ void sub_8086E9C(void) sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); sub_808563C(sub_8086A3C); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_METAPOD); CopySpeciesNametoBuffer(gUnknown_202E038 + 0x50, SPECIES_GENGAR); CopySpeciesNametoBuffer(gUnknown_202E038 + 0xA0, SPECIES_CATERPIE); @@ -281,12 +281,12 @@ void sub_8086E9C(void) void sub_8086F00(void) { struct DungeonEntity * LeaderEntity; - + LeaderEntity = xxx_call_GetLeaderEntity(); sub_80854D4(); sub_8085930(DIRECTION_NORTH); sub_80855E4(sub_8086A3C); - sub_8085860(LeaderEntity->posWorldX,LeaderEntity->posWorldY - 3); + sub_8085860(LeaderEntity->posWorld.x,LeaderEntity->posWorld.y - 3); CopySpeciesNametoBuffer(gUnknown_202E038, SPECIES_METAPOD); CopySpeciesNametoBuffer(gUnknown_202E038 + 0x50, SPECIES_GENGAR); CopySpeciesNametoBuffer(gUnknown_202E038 + 0xA0, SPECIES_CATERPIE); diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 48b675a..ce70182 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -10,6 +10,8 @@ #include "dungeon_entity.h" #include "dungeon_global_data.h" #include "dungeon_pokemon_attributes_1.h" +#include "dungeon_random.h" +#include "dungeon_random_1.h" #include "dungeon_util.h" #include "item.h" #include "team_inventory.h" @@ -31,10 +33,7 @@ enum TargetCapability TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET }; -extern bool8 RollPercentChance(u32); -extern void FindRockItemTargets(struct DungeonEntity*, struct ItemSlot*, s16*[], bool8); -extern s32 DungeonRandomCapped(s32); -extern s32 CalculateFacingDir(s16*, s16*); +extern s32 CalculateFacingDir(struct Position*, struct Position*); extern struct MapTile* GetMapTileAtPosition(s16, s16); extern u32 EvaluateItem(struct DungeonEntity*, struct ItemSlot*, u8); extern bool8 ToolboxEnabled(struct DungeonEntityData*); @@ -105,8 +104,8 @@ void DecideUseItem(struct DungeonEntity *pokemon) { SetAction(&pokemonData->action, DUNGEON_ACTION_THROW_ITEM_AI); pokemonData->action.actionUseIndex = selectedToolboxIndex; - pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.lastItemThrowPosition.x = pokemon->posWorld.x; + pokemonData->action.lastItemThrowPosition.y = pokemon->posWorld.y; pokemonData->action.facingDir = gPotentialTargetDirections[targetIndex] & DIRECTION_MASK; break; } @@ -118,7 +117,7 @@ void DecideUseItem(struct DungeonEntity *pokemon) } else if (itemType == ITEM_TYPE_ROCK) { - s16 *potentialTargetPositions[NUM_POTENTIAL_ROCK_TARGETS]; + struct Position potentialTargetPositions[NUM_POTENTIAL_ROCK_TARGETS]; FindRockItemTargets(pokemon, item, potentialTargetPositions, TRUE); if (gNumPotentialTargets == 0) { @@ -129,9 +128,9 @@ void DecideUseItem(struct DungeonEntity *pokemon) u32 chosenTargetIndex = DungeonRandomCapped(gNumPotentialTargets); SetAction(&pokemonData->action, DUNGEON_ACTION_THROW_ITEM_AI); pokemonData->action.actionUseIndex = selectedToolboxIndex; - pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; - pokemonData->action.facingDir = CalculateFacingDir(&pokemon->posWorldX, (s16 *) (&potentialTargetPositions[chosenTargetIndex])) & DIRECTION_MASK; + pokemonData->action.lastItemThrowPosition.x = pokemon->posWorld.x; + pokemonData->action.lastItemThrowPosition.y = pokemon->posWorld.y; + pokemonData->action.facingDir = CalculateFacingDir(&pokemon->posWorld, &potentialTargetPositions[chosenTargetIndex]) & DIRECTION_MASK; pokemonData->itemTargetPosition = potentialTargetPositions[chosenTargetIndex]; } } @@ -142,8 +141,8 @@ void DecideUseItem(struct DungeonEntity *pokemon) { SetAction(&pokemonData->action, DUNGEON_ACTION_CONSUME_ITEM_AI); pokemonData->action.actionUseIndex = selectedToolboxIndex; - pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.lastItemThrowPosition.x = pokemon->posWorld.x; + pokemonData->action.lastItemThrowPosition.y = pokemon->posWorld.y; } else { @@ -164,7 +163,7 @@ void DecideUseItem(struct DungeonEntity *pokemon) else if (toolboxIndex == 0) { // This seems unused. toolboxIndex can never be 0. - struct MapTile *mapTile = GetMapTileAtPosition(pokemon->posWorldX, pokemon->posWorldY); + struct MapTile *mapTile = GetMapTileAtPosition(pokemon->posWorld.x, pokemon->posWorld.y); struct DungeonEntity *mapObject = mapTile->mapObject; if (mapObject != null) { @@ -214,8 +213,8 @@ void DecideUseItem(struct DungeonEntity *pokemon) SetAction(&pokemonData->action, DUNGEON_ACTION_CONSUME_ITEM_AI); } pokemonData->action.actionUseIndex = selectedToolboxIndex; - pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.lastItemThrowPosition.x = pokemon->posWorld.x; + pokemonData->action.lastItemThrowPosition.y = pokemon->posWorld.y; return; } } @@ -241,16 +240,16 @@ void DecideUseItem(struct DungeonEntity *pokemon) u8 itemType = GetItemType(item->itemIndex); if (itemType == ITEM_TYPE_ROCK) { - s16 *potentialTargetPositions[NUM_POTENTIAL_ROCK_TARGETS]; + struct Position potentialTargetPositions[NUM_POTENTIAL_ROCK_TARGETS]; FindRockItemTargets(pokemon, item, potentialTargetPositions, FALSE); if (gNumPotentialTargets != 0) { u32 chosenTargetIndex = DungeonRandomCapped(gNumPotentialTargets); SetAction(&pokemonData->action, DUNGEON_ACTION_THROW_ITEM_AI); pokemonData->action.actionUseIndex = selectedToolboxIndex; - pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; - pokemonData->action.facingDir = CalculateFacingDir(&pokemon->posWorldX, (s16 *) (&potentialTargetPositions[chosenTargetIndex])) & DIRECTION_MASK; + pokemonData->action.lastItemThrowPosition.x = pokemon->posWorld.x; + pokemonData->action.lastItemThrowPosition.y = pokemon->posWorld.y; + pokemonData->action.facingDir = CalculateFacingDir(&pokemon->posWorld, &potentialTargetPositions[chosenTargetIndex]) & DIRECTION_MASK; pokemonData->itemTargetPosition = potentialTargetPositions[chosenTargetIndex]; return; } @@ -265,8 +264,8 @@ void DecideUseItem(struct DungeonEntity *pokemon) { SetAction(&pokemonData->action, DUNGEON_ACTION_THROW_ITEM_AI); pokemonData->action.actionUseIndex = selectedToolboxIndex; - pokemonData->action.lastItemThrowPositionX = pokemon->posWorldX; - pokemonData->action.lastItemThrowPositionY = pokemon->posWorldY; + pokemonData->action.lastItemThrowPosition.x = pokemon->posWorld.x; + pokemonData->action.lastItemThrowPosition.y = pokemon->posWorld.y; pokemonData->action.facingDir = gPotentialTargetDirections[targetIndex] & DIRECTION_MASK; return; } @@ -279,7 +278,7 @@ void DecideUseItem(struct DungeonEntity *pokemon) } } -void FindStraightThrowableTargets(struct DungeonEntity* pokemon, s32 thrownAIFlag, struct ItemSlot* item, bool8 ignoreRollChance) +void FindStraightThrowableTargets(struct DungeonEntity *pokemon, s32 thrownAIFlag, struct ItemSlot *item, bool8 ignoreRollChance) { s32 i; gNumPotentialTargets = 0; @@ -319,3 +318,49 @@ void FindStraightThrowableTargets(struct DungeonEntity* pokemon, s32 thrownAIFla } } } + +void FindRockItemTargets(struct DungeonEntity *pokemon, struct ItemSlot *item, struct Position potentialTargets[], bool8 ignoreRollChance) +{ + s32 i; + gNumPotentialTargets = 0; + for (i = 0; i < DUNGEON_MAX_POKEMON; i++) + { + struct DungeonEntity* targetPokemon = gDungeonGlobalData->allPokemon[i]; + if (EntityExists(targetPokemon) && pokemon != targetPokemon && + CanSee(pokemon, targetPokemon) && CanTarget(pokemon, targetPokemon, FALSE, TRUE) == TARGET_CAPABILITY_CAN_TARGET) + { + s32 posDiffX; + s32 maxPosDiff; + posDiffX = targetPokemon->posWorld.x - pokemon->posWorld.x; + if (posDiffX < 0) + { + posDiffX = -posDiffX; + } + maxPosDiff = targetPokemon->posWorld.y - pokemon->posWorld.y; + if (maxPosDiff < 0) + { + maxPosDiff = -maxPosDiff; + } + if (maxPosDiff < posDiffX) + { + maxPosDiff = posDiffX; + } + if (maxPosDiff <= 10) + { + struct Position *newPotentialTarget; + if (!ignoreRollChance) + { + u32 itemWeight = EvaluateItem(targetPokemon, item, ITEM_TARGET_OTHER); + if (!RollPercentChance(itemWeight)) + { + continue; + } + } + newPotentialTarget = &potentialTargets[gNumPotentialTargets]; + newPotentialTarget->x = targetPokemon->posWorld.x; + newPotentialTarget->y = targetPokemon->posWorld.y; + gNumPotentialTargets++; + } + } + } +} diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c index 6bb225e..9ea894e 100644 --- a/src/dungeon_movement.c +++ b/src/dungeon_movement.c @@ -9,6 +9,7 @@ #include "dungeon_capabilities_1.h" #include "dungeon_global_data.h" #include "dungeon_pokemon_attributes_1.h" +#include "dungeon_random.h" #include "dungeon_util.h" #include "dungeon_util_1.h" #include "map.h" @@ -26,7 +27,6 @@ extern bool8 HasStatusAffectingActions(struct DungeonEntity*); extern bool8 CanSee(struct DungeonEntity*, struct DungeonEntity*); extern void ResetAction(u16*); extern void SetWalkAction(u16*, s16); -extern s32 DungeonRandomCapped(s32); extern void DecideAttack(struct DungeonEntity*); extern void MoveIfPossible(struct DungeonEntity*, bool8); extern u8 sub_8044B28(void); @@ -143,7 +143,7 @@ void sub_8075900(struct DungeonEntity *pokemon, u8 r1) gDungeonGlobalData->unk672 = 1; sub_807AB38(pokemon, r1); sub_8041888(0); - if(sub_803F428(&pokemon->posWorldX) != 0) + if(sub_803F428(&pokemon->posWorld.x) != 0) sub_803E708(0x78, 0x39); } } @@ -211,8 +211,8 @@ void DecideAction(struct DungeonEntity *pokemon) { SetWalkAction(&pokemonData->action.action, pokemonData->entityID); pokemonData->action.facingDir = DungeonRandomCapped(8); - pokemonData->targetPositionX = pokemon->posWorldX; - pokemonData->targetPositionY = pokemon->posWorldY - 1; + pokemonData->targetPosition.x = pokemon->posWorld.x; + pokemonData->targetPosition.y = pokemon->posWorld.y - 1; } else { diff --git a/src/dungeon_random.c b/src/dungeon_random.c new file mode 100644 index 0000000..86b1c79 --- /dev/null +++ b/src/dungeon_random.c @@ -0,0 +1,15 @@ +#include "global.h" +#include "dungeon_random.h" + +extern u32 gDungeonRngState; + +s32 DungeonRandom(void) +{ + gDungeonRngState = 1566083941 * gDungeonRngState + 1; + return gDungeonRngState >> 16; +} + +s32 DungeonRandomCapped(s32 cap) +{ + return (((DungeonRandom() & 0xFFFF) * cap) >> 16) & 0xFFFF; +} diff --git a/src/dungeon_random_1.c b/src/dungeon_random_1.c new file mode 100644 index 0000000..a6941f3 --- /dev/null +++ b/src/dungeon_random_1.c @@ -0,0 +1,13 @@ +#include "global.h" +#include "dungeon_random_1.h" + +#include "dungeon_random.h" + +bool8 RollPercentChance(s32 percentChance) +{ + if (DungeonRandomCapped(100) < percentChance) + { + return TRUE; + } + return FALSE; +} diff --git a/src/dungeon_util.c b/src/dungeon_util.c index 5943d4b..50b3e08 100644 --- a/src/dungeon_util.c +++ b/src/dungeon_util.c @@ -45,10 +45,10 @@ struct DungeonEntityData *sub_8045110(struct DungeonEntity *entity) struct MapTile *sub_8045114(struct DungeonEntity *entity) { - return GetMapTileAtPosition(entity->posWorldX, entity->posWorldY); + return GetMapTileAtPosition(entity->posWorld.x, entity->posWorld.y); } struct MapTile *sub_8045128(struct DungeonEntity *entity) { - return GetMapEntity(entity->posWorldX, entity->posWorldY); + return GetMapEntity(entity->posWorld.x, entity->posWorld.y); } |