Decomped IsTargetStraightAhead()

This commit is contained in:
AnonymousRandomPerson
2021-12-27 23:21:11 -06:00
parent 4bf154654b
commit d40d2e55a3
10 changed files with 12949 additions and 12955 deletions

File diff suppressed because it is too large Load Diff

12846
asm/code_807CABC.s Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -34,7 +34,14 @@ gUnknown_80F4426: @ 80F4426
.global gAdjacentTileOffsets
gAdjacentTileOffsets: @ 80F4448
@ replacing .incbin "baserom.gba", 0x000f4448, 0x20
.byte 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00
.2byte 0, 1
.2byte 1, 1
.2byte 1, 0
.2byte 1, -1
.2byte 0, -1
.2byte -1, -1
.2byte -1, 0
.2byte -1, 1
.global gUnknown_80F4468
gUnknown_80F4468: @ 80F4468

View File

@@ -0,0 +1,9 @@
#ifndef GUARD_DUNGEON_AI_ATTACK_H
#define GUARD_DUNGEON_AI_ATTACK_H
#include "dungeon_entity.h"
// 0x7C9F8
bool8 IsTargetStraightAhead(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, s32 facingDir, s32 maxRange);
#endif

View File

@@ -42,8 +42,8 @@ struct MapRoom
enum TileType
{
TILE_TYPE_FLOOR = 1 << 0,
TILE_TYPE_UNK_1 = 1 << 1,
TILE_TYPE_LIQUID = 1 << 2, // Water or lava depending on the dungeon.
TILE_TYPE_LIQUID = 1 << 1, // Water or lava depending on the dungeon.
TILE_TYPE_UNK_2 = 1 << 2,
TILE_TYPE_ROOM_EXIT = 1 << 3,
TILE_TYPE_MAP_EDGE = 1 << 4,
TILE_TYPE_SHOP = 1 << 5,

View File

@@ -221,6 +221,8 @@ SECTIONS {
asm/code_8073CF0.o(.text);
src/dungeon_movement.o(.text);
asm/code_8075BA4.o(.text);
src/dungeon_ai_attack.o(.text);
asm/code_807CABC.o(.text);
src/dungeon_range.o(.text);
asm/code_808333C.o(.text);
src/dungeon_random.o(.text);

View File

@@ -208,7 +208,7 @@ void sub_808BCE4(void)
struct MapTile *puVar1;
puVar1 = GetMapEntity(gDungeonGlobalData->unkE23C, gDungeonGlobalData->unkE23E);
puVar1->tileType &= ~(TILE_TYPE_FLOOR | TILE_TYPE_UNK_1);
puVar1->tileType &= ~(TILE_TYPE_FLOOR | TILE_TYPE_LIQUID);
puVar1->tileType |= TILE_TYPE_MAP_EDGE;
puVar1->tileType &= ~TILE_TYPE_STAIRS;
sub_8049884();
@@ -222,7 +222,7 @@ void sub_808BD38(void)
struct MapTile *puVar1;
puVar1 = GetMapEntity(gDungeonGlobalData->unkE23C, gDungeonGlobalData->unkE23E);
puVar1->tileType &= ~(TILE_TYPE_FLOOR | TILE_TYPE_UNK_1);
puVar1->tileType &= ~(TILE_TYPE_FLOOR | TILE_TYPE_LIQUID);
puVar1->tileType |= TILE_TYPE_FLOOR;
puVar1->tileType &= ~TILE_TYPE_MAP_EDGE;
puVar1->tileType |= TILE_TYPE_STAIRS;

77
src/dungeon_ai_attack.c Normal file
View File

@@ -0,0 +1,77 @@
#include "global.h"
#include "dungeon_ai_attack.h"
#include "constants/iq_skill.h"
#include "dungeon_global_data.h"
#include "dungeon_map_access.h"
#include "dungeon_pokemon_attributes_1.h"
extern struct Position gAdjacentTileOffsets[8];
bool8 IsTargetStraightAhead(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, s32 facingDir, s32 maxRange)
{
s32 posDiffX = pokemon->posWorld.x - targetPokemon->posWorld.x;
s32 effectiveMaxRange;
if (posDiffX < 0)
{
posDiffX = -posDiffX;
}
effectiveMaxRange = pokemon->posWorld.y - targetPokemon->posWorld.y;
if (effectiveMaxRange < 0)
{
effectiveMaxRange = -effectiveMaxRange;
}
if (effectiveMaxRange < posDiffX)
{
effectiveMaxRange = posDiffX;
}
if (effectiveMaxRange > maxRange)
{
effectiveMaxRange = maxRange;
}
if (!HasIQSkill(pokemon, IQ_SKILL_COURSE_CHECKER))
{
// BUG: effectiveMaxRange is already capped at maxRange, so this condition always evaluates to TRUE.
// The AI also has range checks elsewhere, so this doesn't become an issue in most cases.
// If the AI has the Long Toss or Pierce statuses and Course Checker is disabled,
// this incorrect check causes the AI to throw items at targets further than 10 tiles away.
if (effectiveMaxRange <= maxRange)
{
return TRUE;
}
}
else
{
s32 currentPosX = pokemon->posWorld.x;
s32 currentPosY = pokemon->posWorld.y;
s32 adjacentTileOffsetX = gAdjacentTileOffsets[facingDir].x;
s32 adjacentTileOffsetY = gAdjacentTileOffsets[facingDir].y;
s32 i;
for (i = 0; i <= effectiveMaxRange; i++)
{
struct MapTile *mapTile;
currentPosX += adjacentTileOffsetX;
currentPosY += adjacentTileOffsetY;
if (currentPosX <= 0 || currentPosY <= 0 ||
currentPosX >= DUNGEON_MAX_SIZE_X - 1 || currentPosY >= DUNGEON_MAX_SIZE_Y - 1)
{
break;
}
while (0); // Extra label needed to swap branch locations in ASM.
mapTile = GetMapTileAtPosition(currentPosX, currentPosY);
if (!(mapTile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_LIQUID)))
{
break;
}
if (mapTile->pokemon == targetPokemon)
{
return TRUE;
}
if (mapTile->pokemon != NULL)
{
break;
}
}
}
return FALSE;
}

View File

@@ -7,6 +7,7 @@
#include "constants/targeting.h"
#include "dungeon_action.h"
#include "dungeon_ai_1.h"
#include "dungeon_ai_attack.h"
#include "dungeon_ai_items.h"
#include "dungeon_capabilities.h"
#include "dungeon_capabilities_1.h"
@@ -36,7 +37,6 @@ enum ItemTargetFlag
extern s32 CalculateFacingDir(struct Position*, struct Position*);
extern u32 EvaluateItem(struct DungeonEntity*, struct ItemSlot*, u32);
extern void sub_8077274(struct DungeonEntity *, struct DungeonEntity *);
extern bool8 IsTargetStraightAhead(struct DungeonEntity*, struct DungeonEntity*, s32, s32);
extern s32 gNumPotentialTargets;
extern u32 gPotentialTargetWeights[NUM_DIRECTIONS];

View File

@@ -51,7 +51,7 @@ u32 sub_8075818(struct DungeonEntity *entity)
{
tile = GetMapEntityForDungeonEntity(entity);
if(HasIQSkill(entity, IQ_SKILL_SUPER_MOBILE))
if(!(tile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_UNK_1)))
if(!(tile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_LIQUID)))
return 1;
subEntity = tile->mapObject;
if(subEntity != NULL)
@@ -95,7 +95,7 @@ flag_check:
{
if(!(entityData->heldItem.itemFlags & ITEM_FLAG_EXISTS))
{
if(!(tile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_UNK_1)))
if(!(tile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_LIQUID)))
{
if(entityData->isEnemy)
break;