From eeb8dd82645a64f55712c67b79f4355b3a99d82e Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 31 Mar 2025 14:30:32 +0200 Subject: [PATCH] split blow away --- data/data_8107010.s | 1 - ld_script.txt | 2 + src/blow_away.c | 211 ++++++++++++++++++++++++++++++++++++++++ src/code_807CD9C.c | 230 ++++---------------------------------------- 4 files changed, 234 insertions(+), 210 deletions(-) create mode 100644 src/blow_away.c diff --git a/data/data_8107010.s b/data/data_8107010.s index 672d8dd44..2977df499 100644 --- a/data/data_8107010.s +++ b/data/data_8107010.s @@ -9,7 +9,6 @@ .string "pksdir0\0" .string "pksdir0\0" .string "pksdir0\0" -.string "pksdir0\0" @ HandleExplosion .string "pksdir0\0" diff --git a/ld_script.txt b/ld_script.txt index 598621af9..5677a1003 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -259,6 +259,7 @@ SECTIONS { src/code_8077274_1.o(.text); src/dungeon_ai_movement.o(.text); src/dungeon_ai_attack.o(.text); + src/blow_away.o(.text); src/code_807CD9C.o(.text); src/code_807E1A0.o(.text); src/weather.o(.text); @@ -595,6 +596,7 @@ SECTIONS { src/code_8077274_1.o(.rodata); src/dungeon_ai_movement.o(.rodata); src/dungeon_ai_attack.o(.rodata); + src/blow_away.o(.rodata); data/data_8107010.o(.rodata); src/dungeon_serializer.o(.rodata); data/data_8107224.o(.rodata); diff --git a/src/blow_away.c b/src/blow_away.c new file mode 100644 index 000000000..0ddb16246 --- /dev/null +++ b/src/blow_away.c @@ -0,0 +1,211 @@ +#include "global.h" +#include "globaldata.h" +#include "constants/ability.h" +#include "constants/weather.h" +#include "code_803E46C.h" +#include "dungeon_message.h" +#include "code_806CD90.h" +#include "code_807CD9C.h" +#include "structs/str_dungeon.h" +#include "code_8077274_1.h" +#include "dungeon_ai.h" +#include "run_dungeon.h" +#include "dungeon_generation.h" +#include "dungeon_logic.h" +#include "dungeon_map.h" +#include "dungeon_map_access.h" +#include "dungeon_util.h" +#include "math.h" +#include "move_effects_target.h" +#include "moves.h" +#include "move_util.h" +#include "code_8041AD0.h" +#include "code_803E668.h" +#include "weather.h" +#include "dungeon_config.h" +#include "dungeon_misc.h" +#include "dungeon_items.h" +#include "dungeon_strings.h" + +void sub_804EB30(); +bool8 ExposeTrap(s32 x, s32 y); +void ShowWholeRevealedDungeonMap(); +void sub_8049ED4(); +void sub_806A5B8(Entity *); +u8 sub_8045888(Entity *); +void sub_807EC28(u32); +u8 sub_8044B28(void); +extern void sub_806F370(Entity *pokemon, Entity *target, u32, u32, u8 *, u8 moveType, s32, u32, u32, u32); +void sub_80421AC(Entity * pokemon, Entity * target); +void sub_807BB78(Entity *pokemon); +extern void sub_803F580(u32); +bool8 sub_808384C(DungeonPos *, DungeonPos *); +u8 sub_8083660(DungeonPos *); + +extern u32 gDungeonFramesCounter; + +void sub_807D068(Entity *pokemon, DungeonPos *pos); + +void BlowAwayTarget(Entity *pokemon, Entity *target, u32 direction) +{ + const Tile *tile; + int iVar8; + bool8 flag; + DungeonPos pos; + Move move; + int counter; + Entity *entity; + PixelPos pos32; + + counter = 10; + if (IsCurrentFixedRoomBossFight()) { + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC9E8); // It couldn't be knocked flying! + return; + } + else + { + if (pokemon == target) { + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FCA10); // {POKEMON_0} couldn't be knocked flying! + return; + } + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); + if (AbilityIsActive(target,ABILITY_SUCTION_CUPS)) { + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FCBCC); // {POKEMON_0} is anchored! It can't be knocked flying! + return; + } + else + { + (GetEntInfo(target)->action).direction = (direction + 4) & DIRECTION_MASK; + sub_806CDD4(target, 6, (direction + 4) & DIRECTION_MASK); + sub_80421C0(target,0x1a3); + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80F8A0C); // {POKEMON_0} was blown away! + flag = TRUE; + entity = NULL; + + for(; counter > 0; counter--) + { + pos = target->pos; + pos.x += gAdjacentTileOffsets[direction].x; + pos.y += gAdjacentTileOffsets[direction].y; + if ((((pos.x < 0) || (pos.y < 0)) || (DUNGEON_MAX_SIZE_X <= pos.x)) || + (DUNGEON_MAX_SIZE_Y <= pos.y)) goto _0807CF20; + pos32.x = gAdjacentTileOffsets[direction].x << 0xA; + pos32.y = gAdjacentTileOffsets[direction].y << 0xA; + + for(iVar8 = 0; iVar8 < 6; iVar8++) + { + IncreaseEntityPixelPos(target,pos32.x,pos32.y); + if (sub_8045888(target) != 0) { + DungeonRunFrameActions(0x19); + } + } + tile = GetTile(pos.x, pos.y); + if (tile->monster != NULL) { + entity = tile->monster; + goto _0807CF26; + } + if (sub_80705F0(target,&pos)){ + flag = (GetTerrainType(tile) != TERRAIN_TYPE_WALL); + goto _0807CF20; + } + sub_80694C0(target,pos.x,pos.y,1); + } + + + flag = TRUE; + _0807CF20: + if (!flag) { + _0807CF26: + + sub_807D068(target,&target->pos); + sub_806F370(pokemon,target,gBlowAwayDmgValue,0,0,0,0x219,0,0,0); + } + if (sub_8044B28()) { + return; + } + if (entity != NULL) { + InitPokemonMove(&move,0x163); + if (!sub_80571F0(entity,&move)) { + TrySendImmobilizeSleepEndMsg(pokemon,entity); + sub_806F370(pokemon,entity,gBlowAwayDmgValue,0,0,0,0x21a,0,0,0); + } + } + if (sub_8044B28()) { + return; + } + if (!EntityIsValid(target)) { + return; + } + sub_806A5B8(target); + if (sub_80706A4(target,&target->pos)) { + WarpTarget(target,target,0,0); + } + if (!EntityIsValid(target)) { + return; + } + sub_806CE68(target,8); + if (GetEntInfo(target)->isTeamLeader) { + gDungeon->unk1 = 0; + gDungeon->unk5C0 = -1; + sub_804AC20(&target->pos); + sub_807EC28(FALSE); + } + sub_806A5B8(target); + sub_8075900(target,gDungeon->forceMonsterHouse); + } + } +} + +void sub_807D068(Entity *pokemon, DungeonPos *pos) +{ + int pixelX; + int posY; + int pixelY; + int posX; + int counter; + int iVar8; + s32 diff; + PixelPos local_34; + int incrementX; + int incrementY; + + posX = X_POS_TO_PIXELPOS(pos->x); + posY = Y_POS_TO_PIXELPOS(pos->y); + diff = (pokemon->pixelPos).x - posX; + if (diff < 0) { + diff = -diff; + } + if (diff < 0xc) { + diff = (pokemon->pixelPos).y - posY; + if (diff < 0) { + diff = -diff; + } + if (diff < 0xc) goto _0807D11E; + } + iVar8 = 0; + pixelX = (pokemon->pixelPos).x; + pixelY = (pokemon->pixelPos).y; + incrementX = (posX - pixelX) / 0xc; + incrementY = (posY - pixelY) / 0xc; + + for(counter = 0; counter < 0xC; counter++) + { + pixelX += incrementX; + pixelY += incrementY; + local_34.x = pixelX; + local_34.y = pixelY; + pokemon->unk1C.raw = sin_4096(iVar8) * 0xc; + sub_804535C(pokemon, &local_34); + if (sub_8045888(pokemon)) { + DungeonRunFrameActions(0x1a); + } + iVar8 = iVar8 + 0xaa; + } +_0807D11E: + local_34.x = posX; + local_34.y = posY; + pokemon->unk1C = IntToF248(0); + sub_804535C(pokemon,&local_34); + DungeonRunFrameActions(0x1a); +} diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index 0041ed73a..070b381ca 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -11,7 +11,6 @@ #include "run_dungeon.h" #include "dungeon_generation.h" #include "dungeon_logic.h" -#include "dungeon_logic.h" #include "dungeon_map.h" #include "dungeon_map_access.h" #include "dungeon_util.h" @@ -25,31 +24,9 @@ #include "dungeon_config.h" #include "dungeon_misc.h" #include "dungeon_items.h" +#include "dungeon_strings.h" extern u32 gDungeonFramesCounter; - -extern u8 *gUnknown_80FCA10[]; -extern u8 *gUnknown_80F8A0C[]; -extern u8 *gUnknown_80FCBCC[]; -extern u8 *gUnknown_80FC9E8[]; -extern u8 *gUnknown_80FCB14[]; -extern u8 *gUnknown_80FCAE8[]; -extern u8 *gUnknown_80FC97C[]; -extern u8 *gUnknown_80FC9A0[]; -extern u8 *gUnknown_80FC584[]; -extern u8 *gUnknown_80FD320[]; -extern u8 *gUnknown_80FD2F8[]; -extern u8 *gUnknown_80FCB98[]; -extern u8 *gUnknown_80FC9C0[]; -extern u8 *gUnknown_80FD060[]; -extern u8 *gUnknown_80FD08C[]; -extern u8 *gUnknown_80FD05C[]; -extern u8 *gUnknown_80FD3D0[]; -extern u8 *gUnknown_80FD3CC[]; -extern u8 *gUnknown_80FD3C8[]; -extern u8 *gUnknown_80FD3A0[]; -extern u8 *gUnknown_80F96BC[]; -extern u8 *gUnknown_80F96EC[]; extern struct DungeonPos *gUnknown_8107178[3]; extern void sub_807E1A0(Entity *pokemon,Entity *target,u8 moveType,s32 param_4,s32 param_5); // TODO: param_4 should be s16 @@ -65,7 +42,6 @@ void sub_8049ED4(); void sub_806A5B8(Entity *); u8 sub_8045888(Entity *); void sub_807EC28(u32); -void sub_807D068(Entity *, DungeonPos *); u8 sub_8044B28(void); extern void sub_806F370(Entity *pokemon, Entity *target, u32, u32, u8 *, u8 moveType, s32, u32, u32, u32); void sub_80421AC(Entity * pokemon, Entity * target); @@ -74,170 +50,6 @@ extern void sub_803F580(u32); bool8 sub_808384C(DungeonPos *, DungeonPos *); u8 sub_8083660(DungeonPos *); -void BlowAwayTarget(Entity *pokemon, Entity *target, u32 direction) -{ - const Tile *tile; - int iVar8; - bool8 flag; - DungeonPos pos; - Move move; - int counter; - Entity *entity; - PixelPos pos32; - - counter = 10; - if (IsCurrentFixedRoomBossFight()) { - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC9E8); // It couldn't be knocked flying! - return; - } - else - { - if (pokemon == target) { - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FCA10); // {POKEMON_0} couldn't be knocked flying! - return; - } - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - if (AbilityIsActive(target,ABILITY_SUCTION_CUPS)) { - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FCBCC); // {POKEMON_0} is anchored! It can't be knocked flying! - return; - } - else - { - (GetEntInfo(target)->action).direction = (direction + 4) & DIRECTION_MASK; - sub_806CDD4(target, 6, (direction + 4) & DIRECTION_MASK); - sub_80421C0(target,0x1a3); - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80F8A0C); // {POKEMON_0} was blown away! - flag = TRUE; - entity = NULL; - - for(; counter > 0; counter--) - { - pos = target->pos; - pos.x += gAdjacentTileOffsets[direction].x; - pos.y += gAdjacentTileOffsets[direction].y; - if ((((pos.x < 0) || (pos.y < 0)) || (DUNGEON_MAX_SIZE_X <= pos.x)) || - (DUNGEON_MAX_SIZE_Y <= pos.y)) goto _0807CF20; - pos32.x = gAdjacentTileOffsets[direction].x << 0xA; - pos32.y = gAdjacentTileOffsets[direction].y << 0xA; - - for(iVar8 = 0; iVar8 < 6; iVar8++) - { - IncreaseEntityPixelPos(target,pos32.x,pos32.y); - if (sub_8045888(target) != 0) { - DungeonRunFrameActions(0x19); - } - } - tile = GetTile(pos.x, pos.y); - if (tile->monster != NULL) { - entity = tile->monster; - goto _0807CF26; - } - if (sub_80705F0(target,&pos)){ - flag = (GetTerrainType(tile) != TERRAIN_TYPE_WALL); - goto _0807CF20; - } - sub_80694C0(target,pos.x,pos.y,1); - } - - - flag = TRUE; - _0807CF20: - if (!flag) { - _0807CF26: - - sub_807D068(target,&target->pos); - sub_806F370(pokemon,target,gBlowAwayDmgValue,0,0,0,0x219,0,0,0); - } - if (sub_8044B28()) { - return; - } - if (entity != NULL) { - InitPokemonMove(&move,0x163); - if (!sub_80571F0(entity,&move)) { - TrySendImmobilizeSleepEndMsg(pokemon,entity); - sub_806F370(pokemon,entity,gBlowAwayDmgValue,0,0,0,0x21a,0,0,0); - } - } - if (sub_8044B28()) { - return; - } - if (!EntityIsValid(target)) { - return; - } - sub_806A5B8(target); - if (sub_80706A4(target,&target->pos)) { - WarpTarget(target,target,0,0); - } - if (!EntityIsValid(target)) { - return; - } - sub_806CE68(target,8); - if (GetEntInfo(target)->isTeamLeader) { - gDungeon->unk1 = 0; - gDungeon->unk5C0 = -1; - sub_804AC20(&target->pos); - sub_807EC28(FALSE); - } - sub_806A5B8(target); - sub_8075900(target,gDungeon->forceMonsterHouse); - } - } -} - -void sub_807D068(Entity *pokemon, DungeonPos *pos) -{ - int pixelX; - int posY; - int pixelY; - int posX; - int counter; - int iVar8; - s32 diff; - PixelPos local_34; - int incrementX; - int incrementY; - - posX = X_POS_TO_PIXELPOS(pos->x); - posY = Y_POS_TO_PIXELPOS(pos->y); - diff = (pokemon->pixelPos).x - posX; - if (diff < 0) { - diff = -diff; - } - if (diff < 0xc) { - diff = (pokemon->pixelPos).y - posY; - if (diff < 0) { - diff = -diff; - } - if (diff < 0xc) goto _0807D11E; - } - iVar8 = 0; - pixelX = (pokemon->pixelPos).x; - pixelY = (pokemon->pixelPos).y; - incrementX = (posX - pixelX) / 0xc; - incrementY = (posY - pixelY) / 0xc; - - for(counter = 0; counter < 0xC; counter++) - { - pixelX += incrementX; - pixelY += incrementY; - local_34.x = pixelX; - local_34.y = pixelY; - pokemon->unk1C.raw = sin_4096(iVar8) * 0xc; - sub_804535C(pokemon, &local_34); - if (sub_8045888(pokemon)) { - DungeonRunFrameActions(0x1a); - } - iVar8 = iVar8 + 0xaa; - } -_0807D11E: - local_34.x = posX; - local_34.y = posY; - pokemon->unk1C = IntToF248(0); - sub_804535C(pokemon,&local_34); - DungeonRunFrameActions(0x1a); -} - void WarpTarget(Entity *pokemon, Entity *target, u32 param_3, DungeonPos *pos) { EntityInfo *info; @@ -250,24 +62,24 @@ void WarpTarget(Entity *pokemon, Entity *target, u32 param_3, DungeonPos *pos) SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); if (AbilityIsActive(target,ABILITY_SUCTION_CUPS)) { - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FCAE8); + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FCAE8); return; } if (IsCurrentFixedRoomBossFight()) { - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC97C); + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC97C); return; } if (param_3 == 1) { DungeonPos stairsPosition = gDungeon->stairsSpawn; if(stairsPosition.x == target->pos.x && stairsPosition.y == target->pos.y) { - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC9A0); // It's already on the stairs! + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC9A0); // It's already on the stairs! PetrifiedStatusTarget(pokemon,target); return; } } - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC584); // $m0 warped! + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC584); // $m0 warped! TrySendImmobilizeSleepEndMsg(target,target); sub_80421AC(pokemon,target); if (sub_8045888(target)) { @@ -332,7 +144,7 @@ void WarpTarget(Entity *pokemon, Entity *target, u32 param_3, DungeonPos *pos) target->unk1C = IntToF248_2(0); DungeonRunFrameActions(0x22); if (flag) { - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FCB14); // But it dropped back at the same spot! + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FCB14); // But it dropped back at the same spot! } if (param_3 == 1) { PetrifiedStatusTarget(pokemon,target); @@ -380,12 +192,12 @@ void sub_807D3CC(Entity *param_1) } } if (flag) { - LogMessageByIdWithPopupCheckUser(param_1,*gUnknown_80FD2F8); // All traps were exposed + LogMessageByIdWithPopupCheckUser(param_1,gUnknown_80FD2F8); // All traps were exposed ShowWholeRevealedDungeonMap(); sub_8049ED4(); } else { - LogMessageByIdWithPopupCheckUser(param_1,*gUnknown_80FD320); // There appears to be no hidden traps. + LogMessageByIdWithPopupCheckUser(param_1,gUnknown_80FD320); // There appears to be no hidden traps. } } @@ -554,12 +366,12 @@ void HandlePounceOrbAction(Entity *pokemon, Entity *target, u8 r2) { if(AbilityIsActive(target, ABILITY_SUCTION_CUPS)) { SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], target, 0); - TryDisplayDungeonLoggableMessage3(pokemon, target, *gUnknown_80FCB98); + TryDisplayDungeonLoggableMessage3(pokemon, target, gUnknown_80FCB98); return; } if(IsCurrentFixedRoomBossFight()) { - TryDisplayDungeonLoggableMessage3(pokemon, target, *gUnknown_80FC9C0); + TryDisplayDungeonLoggableMessage3(pokemon, target, gUnknown_80FC9C0); return; } if(direction == NUM_DIRECTIONS) @@ -612,13 +424,13 @@ void HandleDroughtOrbAction(Entity *pokemon, Entity *target) { flag = FALSE; if(IsCurrentFixedRoomBossFight()) { - LogMessageByIdWithPopupCheckUser(pokemon, *gUnknown_80FD060); + LogMessageByIdWithPopupCheckUser(pokemon, gUnknown_80FD060); return; } if(IsWaterTileset()) { - LogMessageByIdWithPopupCheckUser(pokemon, *gUnknown_80FD08C); + LogMessageByIdWithPopupCheckUser(pokemon, gUnknown_80FD08C); return; } @@ -640,11 +452,11 @@ void HandleDroughtOrbAction(Entity *pokemon, Entity *target) { if(flag) { sub_80421C0(pokemon, 0x1A1); - LogMessageByIdWithPopupCheckUser(pokemon, *gUnknown_80FD05C); + LogMessageByIdWithPopupCheckUser(pokemon, gUnknown_80FD05C); } else { - LogMessageByIdWithPopupCheckUser(pokemon, *gUnknown_80FD060); + LogMessageByIdWithPopupCheckUser(pokemon, gUnknown_80FD060); } gDungeon->unk644.unk2C = 1; sub_806CF60(); @@ -662,17 +474,17 @@ void HandleOneRoomOrb(Entity *pokemon, Entity *target) { bool8 isMonsterHouse; if (gDungeon->forceMonsterHouse != 0) { - LogMessageByIdWithPopupCheckUser(pokemon,*gUnknown_80FD3C8); + LogMessageByIdWithPopupCheckUser(pokemon,gUnknown_80FD3C8); return; } if (gDungeon->unk3A0B != 0) { - LogMessageByIdWithPopupCheckUser(pokemon,*gUnknown_80FD3CC); + LogMessageByIdWithPopupCheckUser(pokemon,gUnknown_80FD3CC); return; } if (IsBossFight()) { - LogMessageByIdWithPopupCheckUser(pokemon,*gUnknown_80FD3D0); + LogMessageByIdWithPopupCheckUser(pokemon,gUnknown_80FD3D0); return; } isMonsterHouse = FALSE; @@ -755,7 +567,7 @@ void HandleOneRoomOrb(Entity *pokemon, Entity *target) { sub_806CF60(); ShowWholeRevealedDungeonMap(); sub_8049ED4(); - LogMessageByIdWithPopupCheckUser(pokemon,*gUnknown_80FD3A0); + LogMessageByIdWithPopupCheckUser(pokemon,gUnknown_80FD3A0); sub_803E708(0x28,0x2b); sub_8075900(pokemon,1); for(index = 0; index < DUNGEON_MAX_POKEMON; index++) @@ -796,16 +608,16 @@ void HandleExplosion(Entity *pokemon,Entity *target,DungeonPos *param_3,s32 para if (index != DUNGEON_MAX_POKEMON) { sub_804218C(pokemon,target); SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80F96EC); + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80F96EC); } else if (GetApparentWeather(target) == WEATHER_RAIN) { - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80F96EC); + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80F96EC); } else { sub_804216C(pokemon,target,param_4); SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80F96BC); + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80F96BC); flag = FALSE; posPtr = (gUnknown_8107178)[param_4];