Merge pull request #231 from DizzyEggg/sub_805D8C8
Some checks failed
GithubCI / build (push) Has been cancelled

Match/Document sub_805D8C8 and fix fakematches with static inlines
This commit is contained in:
AnonymousRandomPerson 2024-10-20 17:02:58 -04:00 committed by GitHub
commit 9e49584621
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 1013 additions and 2543 deletions

View File

@ -34,10 +34,7 @@ gUnknown_8106AC8: @ 8106AC8
.global gUnknown_8106AE8 .global gUnknown_8106AE8
gUnknown_8106AE8: @ 8106AE8 gUnknown_8106AE8: @ 8106AE8
.byte 0x00, 0x00, 0x01, 0x00 .byte 0x00, 0x00, 0x01, 0x00
.global gUnknown_8106AEC
gUnknown_8106AEC: @ 8106AEC
.byte 0x12, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x13, 0x02, 0x00, 0x00 .byte 0x12, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x13, 0x02, 0x00, 0x00
.byte 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x01, 0x00, 0xff, 0xff, 0x13, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff .byte 0x01, 0x00, 0xff, 0xff, 0x13, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff

View File

@ -23,6 +23,13 @@
// Prevent cross-jump optimization. // Prevent cross-jump optimization.
#define BLOCK_CROSS_JUMP asm(""); #define BLOCK_CROSS_JUMP asm("");
// Sometimes incrementing and decrementing a variable changes how registers are allocated, which helps with matching functions. Functionality-wise this doesn't do anything.
#ifdef NONMATCHING
#define ASM_MATCH_TRICK(a) {;}
#else
#define ASM_MATCH_TRICK(a) {a++;a--;}
#endif // NONMATCHING
// to help in decompiling // to help in decompiling
#define asm_comment(x) asm volatile("@ -- " x " -- ") #define asm_comment(x) asm volatile("@ -- " x " -- ")

View File

@ -83,14 +83,6 @@ s32 SaveTeamInventory(u8 *, u32 size);
s32 WriteHighDecimal(s32, u8 *strbuf, u8); s32 WriteHighDecimal(s32, u8 *strbuf, u8);
u32 sub_80913E0(Item *slot, u32, struct subStruct_203B240 **); u32 sub_80913E0(Item *slot, u32, struct subStruct_203B240 **);
// This macro doesn't do anything, it creates unused variables for the purpose of tricking the compiler and matching the asm.
// It's possible there was some unknown macro, or the structure of TeamInventory/Item is not 100% how it was originally written.
#define DUMMY_TEAM_ITEMS_ASM_MATCH(id) \
{ \
UNUSED size_t offs = id * sizeof(Item); \
UNUSED Item *item = &gTeamInventoryRef->teamItems[id]; \
}
static inline void ZeroOutItem(Item *item) static inline void ZeroOutItem(Item *item)
{ {
item->id = 0; item->id = 0;
@ -108,6 +100,11 @@ static inline bool8 ItemExists(Item *item)
return (item->flags & ITEM_FLAG_EXISTS); return (item->flags & ITEM_FLAG_EXISTS);
} }
static inline bool8 ItemSet(Item *item)
{
return (item->flags & ITEM_FLAG_SET);
}
static inline bool8 ItemInShop(Item *item) static inline bool8 ItemInShop(Item *item)
{ {
return (item->flags & ITEM_FLAG_IN_SHOP); return (item->flags & ITEM_FLAG_IN_SHOP);

View File

@ -22,7 +22,7 @@ typedef struct MoveDataFile
} MoveDataFile; } MoveDataFile;
bool8 CanBeSnatched(u16 moveID); bool8 CanBeSnatched(u16 moveID);
void CopyAndResetMoves(Move *destMoves, Move *srcMoves); void CopyAndResetMoves(Moves *destMoves, Move *srcMoves);
void CopyBareMoveData(Move *destMoves, Move *srcMoves); void CopyBareMoveData(Move *destMoves, Move *srcMoves);
bool8 DoesMoveCharge(u16 move); bool8 DoesMoveCharge(u16 move);
bool8 FailsWhileMuzzled(u16 moveID); bool8 FailsWhileMuzzled(u16 moveID);
@ -94,6 +94,16 @@ static inline bool8 MoveFlagExists(Move *move)
return (move->moveFlags & MOVE_FLAG_EXISTS); return (move->moveFlags & MOVE_FLAG_EXISTS);
} }
static inline bool8 MoveFlagSet(Move *move)
{
return (move->moveFlags & MOVE_FLAG_SET);
}
static inline bool8 MoveFlagLastUsed(Move *move)
{
return (move->moveFlags & MOVE_FLAG_LAST_USED);
}
static inline bool8 MoveFlagLinkChain(Move *move) static inline bool8 MoveFlagLinkChain(Move *move)
{ {
return (move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN); return (move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN);

View File

@ -120,4 +120,11 @@ static inline bool8 IsMonPartner(PokemonStruct1 *mon)
return (mon->dungeonLocation.id == DUNGEON_JOIN_LOCATION_PARTNER); return (mon->dungeonLocation.id == DUNGEON_JOIN_LOCATION_PARTNER);
} }
// Needed to match a couple of functions which use species id.
// The theory is that there was some internal species conversion which got scrapped later on.
static inline s16 SpeciesId(s32 id)
{
return id;
}
#endif // GUARD_POKEMON_H #endif // GUARD_POKEMON_H

View File

@ -22,72 +22,72 @@ typedef struct SpriteOAM
#define SPRITEOAM_MAX_Y 0xFF #define SPRITEOAM_MAX_Y 0xFF
#define SPRITEOAM_SHIFT_Y 0 #define SPRITEOAM_SHIFT_Y 0
#define SPRITEOAM_MASK_Y (SPRITEOAM_MAX_Y << SPRITEOAM_SHIFT_Y) #define SPRITEOAM_MASK_Y (SPRITEOAM_MAX_Y << SPRITEOAM_SHIFT_Y) // ~ 0xFF00
#define SPRITEOAM_MAX_AFFINEMODE1 1 #define SPRITEOAM_MAX_AFFINEMODE1 1
#define SPRITEOAM_SHIFT_AFFINEMODE1 8 #define SPRITEOAM_SHIFT_AFFINEMODE1 8
#define SPRITEOAM_MASK_AFFINEMODE1 (SPRITEOAM_MAX_AFFINEMODE1 << SPRITEOAM_SHIFT_AFFINEMODE1) #define SPRITEOAM_MASK_AFFINEMODE1 (SPRITEOAM_MAX_AFFINEMODE1 << SPRITEOAM_SHIFT_AFFINEMODE1) // ~ 0xFEFF
#define SPRITEOAM_MAX_AFFINEMODE2 1 #define SPRITEOAM_MAX_AFFINEMODE2 1
#define SPRITEOAM_SHIFT_AFFINEMODE2 9 #define SPRITEOAM_SHIFT_AFFINEMODE2 9
#define SPRITEOAM_MASK_AFFINEMODE2 (SPRITEOAM_MAX_AFFINEMODE2 << SPRITEOAM_SHIFT_AFFINEMODE2) #define SPRITEOAM_MASK_AFFINEMODE2 (SPRITEOAM_MAX_AFFINEMODE2 << SPRITEOAM_SHIFT_AFFINEMODE2) // ~ 0xFDFF
#define SPRITEOAM_MAX_OBJMODE 3 #define SPRITEOAM_MAX_OBJMODE 3
#define SPRITEOAM_SHIFT_OBJMODE 10 #define SPRITEOAM_SHIFT_OBJMODE 10
#define SPRITEOAM_MASK_OBJMODE (SPRITEOAM_MAX_OBJMODE << SPRITEOAM_SHIFT_OBJMODE) #define SPRITEOAM_MASK_OBJMODE (SPRITEOAM_MAX_OBJMODE << SPRITEOAM_SHIFT_OBJMODE) // ~ 0xF3FF
#define SPRITEOAM_MAX_MOSAIC 1 #define SPRITEOAM_MAX_MOSAIC 1
#define SPRITEOAM_SHIFT_MOSAIC 12 #define SPRITEOAM_SHIFT_MOSAIC 12
#define SPRITEOAM_MASK_MOSAIC (SPRITEOAM_MAX_MOSAIC << SPRITEOAM_SHIFT_MOSAIC) #define SPRITEOAM_MASK_MOSAIC (SPRITEOAM_MAX_MOSAIC << SPRITEOAM_SHIFT_MOSAIC) // ~ 0xEFFF
#define SPRITEOAM_MAX_BPP 1 #define SPRITEOAM_MAX_BPP 1
#define SPRITEOAM_SHIFT_BPP 13 #define SPRITEOAM_SHIFT_BPP 13
#define SPRITEOAM_MASK_BPP (SPRITEOAM_MAX_BPP << SPRITEOAM_SHIFT_BPP) #define SPRITEOAM_MASK_BPP (SPRITEOAM_MAX_BPP << SPRITEOAM_SHIFT_BPP) // ~ 0xDFFF
#define SPRITEOAM_MAX_SHAPE 3 #define SPRITEOAM_MAX_SHAPE 3
#define SPRITEOAM_SHIFT_SHAPE 14 #define SPRITEOAM_SHIFT_SHAPE 14
#define SPRITEOAM_MASK_SHAPE (SPRITEOAM_MAX_SHAPE << SPRITEOAM_SHIFT_SHAPE) #define SPRITEOAM_MASK_SHAPE (SPRITEOAM_MAX_SHAPE << SPRITEOAM_SHIFT_SHAPE) // ~ 0x3FFF
// attrib2 // attrib2
#define SPRITEOAM_MAX_X 0x1FF #define SPRITEOAM_MAX_X 0x1FF
#define SPRITEOAM_SHIFT_X 0 #define SPRITEOAM_SHIFT_X 0
#define SPRITEOAM_MASK_X (SPRITEOAM_MAX_X << SPRITEOAM_SHIFT_X) #define SPRITEOAM_MASK_X (SPRITEOAM_MAX_X << SPRITEOAM_SHIFT_X) // ~ 0xFE00
#define SPRITEOAM_MAX_MATRIXNUM 31 #define SPRITEOAM_MAX_MATRIXNUM 31
#define SPRITEOAM_SHIFT_MATRIXNUM 9 #define SPRITEOAM_SHIFT_MATRIXNUM 9
#define SPRITEOAM_MASK_MATRIXNUM (SPRITEOAM_MAX_MATRIXNUM << SPRITEOAM_SHIFT_MATRIXNUM) #define SPRITEOAM_MASK_MATRIXNUM (SPRITEOAM_MAX_MATRIXNUM << SPRITEOAM_SHIFT_MATRIXNUM) // ~ 0xC1FF
#define SPRITEOAM_MAX_SIZE 3 #define SPRITEOAM_MAX_SIZE 3
#define SPRITEOAM_SHIFT_SIZE 14 #define SPRITEOAM_SHIFT_SIZE 14
#define SPRITEOAM_MASK_SIZE (SPRITEOAM_MAX_SIZE << SPRITEOAM_SHIFT_SIZE) #define SPRITEOAM_MASK_SIZE (SPRITEOAM_MAX_SIZE << SPRITEOAM_SHIFT_SIZE) // ~ 0x3FFF
// attrib3 // attrib3
#define SPRITEOAM_MAX_TILENUM 0x3FF #define SPRITEOAM_MAX_TILENUM 0x3FF
#define SPRITEOAM_SHIFT_TILENUM 0 #define SPRITEOAM_SHIFT_TILENUM 0
#define SPRITEOAM_MASK_TILENUM (SPRITEOAM_MAX_TILENUM << SPRITEOAM_SHIFT_TILENUM) #define SPRITEOAM_MASK_TILENUM (SPRITEOAM_MAX_TILENUM << SPRITEOAM_SHIFT_TILENUM) // ~ 0xFC00
#define SPRITEOAM_MAX_PRIORITY 3 #define SPRITEOAM_MAX_PRIORITY 3
#define SPRITEOAM_SHIFT_PRIORITY 10 #define SPRITEOAM_SHIFT_PRIORITY 10
#define SPRITEOAM_MASK_PRIORITY (SPRITEOAM_MAX_PRIORITY << SPRITEOAM_SHIFT_PRIORITY) #define SPRITEOAM_MASK_PRIORITY (SPRITEOAM_MAX_PRIORITY << SPRITEOAM_SHIFT_PRIORITY) // ~ 0xF3FF
#define SPRITEOAM_MAX_PALETTENUM 15 #define SPRITEOAM_MAX_PALETTENUM 15
#define SPRITEOAM_SHIFT_PALETTENUM 12 #define SPRITEOAM_SHIFT_PALETTENUM 12
#define SPRITEOAM_MASK_PALETTENUM (SPRITEOAM_MAX_PALETTENUM << SPRITEOAM_SHIFT_PALETTENUM) #define SPRITEOAM_MASK_PALETTENUM (SPRITEOAM_MAX_PALETTENUM << SPRITEOAM_SHIFT_PALETTENUM) // ~ 0xFFF
// unk6 // unk6
#define SPRITEOAM_MAX_UNK6_0 1 #define SPRITEOAM_MAX_UNK6_0 1
#define SPRITEOAM_SHIFT_UNK6_0 0 #define SPRITEOAM_SHIFT_UNK6_0 0
#define SPRITEOAM_MASK_UNK6_0 (SPRITEOAM_MAX_UNK6_0 << SPRITEOAM_SHIFT_UNK6_0) #define SPRITEOAM_MASK_UNK6_0 (SPRITEOAM_MAX_UNK6_0 << SPRITEOAM_SHIFT_UNK6_0) // ~ 0xFFFE
#define SPRITEOAM_MAX_UNK6_1 1 #define SPRITEOAM_MAX_UNK6_1 1
#define SPRITEOAM_SHIFT_UNK6_1 1 #define SPRITEOAM_SHIFT_UNK6_1 1
#define SPRITEOAM_MASK_UNK6_1 (SPRITEOAM_MAX_UNK6_1 << SPRITEOAM_SHIFT_UNK6_1) #define SPRITEOAM_MASK_UNK6_1 (SPRITEOAM_MAX_UNK6_1 << SPRITEOAM_SHIFT_UNK6_1) // ~ 0xFFFD
#define SPRITEOAM_MAX_UNK6_4 0xFFF #define SPRITEOAM_MAX_UNK6_4 0xFFF
#define SPRITEOAM_SHIFT_UNK6_4 4 #define SPRITEOAM_SHIFT_UNK6_4 4
#define SPRITEOAM_MASK_UNK6_4 (SPRITEOAM_MAX_UNK6_4 << SPRITEOAM_SHIFT_UNK6_4) #define SPRITEOAM_MASK_UNK6_4 (SPRITEOAM_MAX_UNK6_4 << SPRITEOAM_SHIFT_UNK6_4) // ~ 0xF
#endif // GUARD_SPRITE_OAM_H #endif // GUARD_SPRITE_OAM_H

View File

@ -260,7 +260,7 @@ typedef struct EntityInfo
/* 0xF8 */ bool8 speedStageChanged; // Toggled when pokemon is movement speed is sped up /* 0xF8 */ bool8 speedStageChanged; // Toggled when pokemon is movement speed is sped up
/* 0xF9 */ u8 unkF9; /* 0xF9 */ u8 unkF9;
/* 0xFA */ u8 terrifiedTurns; // Doubles as a bool for whether the Pokémon is terrified. /* 0xFA */ u8 terrifiedTurns; // Doubles as a bool for whether the Pokémon is terrified.
u8 unkFB; u8 expMultiplier;
// Set to true if the player makes a teammate use their held item. // Set to true if the player makes a teammate use their held item.
// This is done by going to the teammate's held item in the toolbox and selecting "Use". // This is done by going to the teammate's held item in the toolbox and selecting "Use".
/* 0xFC */ bool8 useHeldItem; /* 0xFC */ bool8 useHeldItem;
@ -418,6 +418,31 @@ enum VisualFlag
VISUAL_FLAG_RUN_AWAY = 2 VISUAL_FLAG_RUN_AWAY = 2
}; };
enum ExpMultiplier
{
EXP_HALVED, // 0.5x when fainting a mon with only the regular attack and no moves
EXP_REGULAR, // 1x
EXP_BOOSTED, // 1.5x so far use not found, but most likely linked moves ; to be confirmed once more code is decompiled
};
static inline bool8 ExpMultiplierChanged(EntityInfo *info)
{
return (info->expMultiplier != EXP_HALVED);
}
static inline void SetRegularExpMultiplier(EntityInfo *info)
{
info->expMultiplier = EXP_REGULAR;
}
// After using a move, pokemon will get more experience than
// This inline is needed to match one function - sub_805AD54
static inline void SetExpMultplier(EntityInfo *info)
{
if (!ExpMultiplierChanged(info))
SetRegularExpMultiplier(info);
}
static inline EntityInfo *GetEntInfo(Entity *ent) static inline EntityInfo *GetEntInfo(Entity *ent)
{ {
return ent->info; return ent->info;

View File

@ -491,12 +491,6 @@ void sub_803D8F0(void)
} }
} }
// Hmm...
static inline s16 SpeciesId(s32 id)
{
return id;
}
bool8 sub_803D930(s16 speciesToFind) bool8 sub_803D930(s16 speciesToFind)
{ {
s32 i; s32 i;

View File

@ -1399,9 +1399,7 @@ void sub_803FE30(s32 a0, u16 *a1, bool8 a2, bool8 a3)
s32 arrId = (!a2) ? 1 : 0; s32 arrId = (!a2) ? 1 : 0;
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
#ifndef NONMATCHING ASM_MATCH_TRICK(a1);
a1++;a1--; // Good old matching trick.
#endif // NONMATCHING
if (gUnknown_80F64B4[i] <= a0) { if (gUnknown_80F64B4[i] <= a0) {
*a1 = gUnknown_80F64D8[arrId][i]; *a1 = gUnknown_80F64D8[arrId][i];
*ptr = (((a0 - gUnknown_80F64B4[i]) + varAdd) + 0x258) | 0xF000; *ptr = (((a0 - gUnknown_80F64B4[i]) + varAdd) + 0x258) | 0xF000;

File diff suppressed because it is too large Load Diff

View File

@ -171,21 +171,18 @@ void sub_806CE94(Entity *entity, u32 newDir)
u8 sub_806CEBC(Entity *entity) u8 sub_806CEBC(Entity *entity)
{ {
u8 sleep; u8 sleep;
EntityInfo *entityInfo1; EntityInfo *entityInfo;
EntityInfo *entityInfo2;
// NOTE: copy needed to match entityInfo = GetEntInfo(entity);
entityInfo1 = entity->info; sleep = entityInfo->sleep.sleep;
entityInfo2 = entity->info;
sleep = entityInfo1->sleep.sleep;
if (sleep == STATUS_SLEEP || sleep == STATUS_NAPPING || sleep == STATUS_NIGHTMARE) { if (sleep == STATUS_SLEEP || sleep == STATUS_NAPPING || sleep == STATUS_NIGHTMARE) {
if (entityInfo2->apparentID != MONSTER_SUDOWOODO || entityInfo2->sleep.sleepTurns != 0x7F) if (entityInfo->apparentID != MONSTER_SUDOWOODO || entityInfo->sleep.sleepTurns != 0x7F)
return 5; return 5;
else else
return 7; return 7;
} }
if (entityInfo2->charging.chargingStatus == STATUS_BIDE) if (entityInfo->charging.chargingStatus == STATUS_BIDE)
return 11; return 11;
return 7; return 7;
} }
@ -924,12 +921,12 @@ static bool8 HandleDealingDamageInternal(Entity *attacker, Entity *target, struc
if (GetEntityType(attacker) == ENTITY_MONSTER) { if (GetEntityType(attacker) == ENTITY_MONSTER) {
EntityInfo *attackerData = GetEntInfo(attacker); EntityInfo *attackerData = GetEntInfo(attacker);
s32 exp = CalculateEXPGain(targetData->id, targetData->level); s32 exp = CalculateEXPGain(targetData->id, targetData->level);
switch (targetData->unkFB) { switch (targetData->expMultiplier) {
case 2: case EXP_BOOSTED:
exp *= 3; exp *= 3;
exp /= 2; exp /= 2;
break; break;
case 0: case EXP_HALVED:
exp /= 2; exp /= 2;
break; break;
} }

View File

@ -508,14 +508,11 @@ void RaiseAtkStatTarget(Entity * pokemon, Entity *target, s32 increment)
u32 oldStat1; u32 oldStat1;
s32 newStat; s32 newStat;
EntityInfo *entityInfo; EntityInfo *entityInfo;
EntityInfo *entityInfo1;
if (EntityExists(target)) { if (EntityExists(target)) {
SetMessageArgument(gAvailablePokemonNames,target,0); SetMessageArgument(gAvailablePokemonNames,target,0);
// NOTE: had to have duplicates to match.. entityInfo = GetEntInfo(target);
entityInfo = target->info;
entityInfo1 = entityInfo;
oldStat = entityInfo->atk; oldStat = entityInfo->atk;
oldStat1 = oldStat; oldStat1 = oldStat;
@ -523,7 +520,7 @@ void RaiseAtkStatTarget(Entity * pokemon, Entity *target, s32 increment)
if (0xfe < newStat) { if (0xfe < newStat) {
newStat = 0xff; newStat = 0xff;
} }
entityInfo1->atk = newStat; entityInfo->atk = newStat;
if (oldStat1 < (u8)newStat) { if (oldStat1 < (u8)newStat) {
sub_8041E60(target); sub_8041E60(target);
sub_80522F4(pokemon,target,*gUnknown_80FC33C); sub_80522F4(pokemon,target,*gUnknown_80FC33C);
@ -541,14 +538,11 @@ void RaiseSpAtkStatTarget(Entity * pokemon, Entity *target, s32 increment)
u32 oldStat1; u32 oldStat1;
s32 newStat; s32 newStat;
EntityInfo *entityInfo; EntityInfo *entityInfo;
EntityInfo *entityInfo1;
if (EntityExists(target)) { if (EntityExists(target)) {
SetMessageArgument(gAvailablePokemonNames,target,0); SetMessageArgument(gAvailablePokemonNames,target,0);
// NOTE: had to have duplicates to match.. entityInfo = GetEntInfo(target);
entityInfo = target->info;
entityInfo1 = entityInfo;
oldStat = entityInfo->spAtk; oldStat = entityInfo->spAtk;
oldStat1 = oldStat; oldStat1 = oldStat;
@ -556,7 +550,7 @@ void RaiseSpAtkStatTarget(Entity * pokemon, Entity *target, s32 increment)
if (0xfe < newStat) { if (0xfe < newStat) {
newStat = 0xff; newStat = 0xff;
} }
entityInfo1->spAtk = newStat; entityInfo->spAtk = newStat;
if (oldStat1 < (u8)newStat) { if (oldStat1 < (u8)newStat) {
sub_8041E74(target); sub_8041E74(target);
sub_80522F4(pokemon,target,*gUnknown_80FC388); sub_80522F4(pokemon,target,*gUnknown_80FC388);
@ -574,14 +568,11 @@ void RaiseDefStatTarget(Entity * pokemon, Entity *target, s32 increment)
u32 oldStat1; u32 oldStat1;
s32 newStat; s32 newStat;
EntityInfo *entityInfo; EntityInfo *entityInfo;
EntityInfo *entityInfo1;
if (EntityExists(target)) { if (EntityExists(target)) {
SetMessageArgument(gAvailablePokemonNames,target,0); SetMessageArgument(gAvailablePokemonNames,target,0);
// NOTE: had to have duplicates to match.. entityInfo = GetEntInfo(target);
entityInfo = target->info;
entityInfo1 = entityInfo;
oldStat = entityInfo->def; oldStat = entityInfo->def;
oldStat1 = oldStat; oldStat1 = oldStat;
@ -589,7 +580,7 @@ void RaiseDefStatTarget(Entity * pokemon, Entity *target, s32 increment)
if (0xfe < newStat) { if (0xfe < newStat) {
newStat = 0xff; newStat = 0xff;
} }
entityInfo1->def = newStat; entityInfo->def = newStat;
if (oldStat1 < (u8)newStat) { if (oldStat1 < (u8)newStat) {
sub_8041E84(target); sub_8041E84(target);
sub_80522F4(pokemon,target,*gUnknown_80FC3D8); sub_80522F4(pokemon,target,*gUnknown_80FC3D8);
@ -607,14 +598,11 @@ void RaiseSpDefStatTarget(Entity * pokemon, Entity *target, s32 increment)
u32 oldStat1; u32 oldStat1;
s32 newStat; s32 newStat;
EntityInfo *entityInfo; EntityInfo *entityInfo;
EntityInfo *entityInfo1;
if (EntityExists(target)) { if (EntityExists(target)) {
SetMessageArgument(gAvailablePokemonNames,target,0); SetMessageArgument(gAvailablePokemonNames,target,0);
// NOTE: had to have duplicates to match.. entityInfo = GetEntInfo(target);
entityInfo = target->info;
entityInfo1 = entityInfo;
oldStat = entityInfo->spDef; oldStat = entityInfo->spDef;
oldStat1 = oldStat; oldStat1 = oldStat;
@ -622,7 +610,7 @@ void RaiseSpDefStatTarget(Entity * pokemon, Entity *target, s32 increment)
if (0xfe < newStat) { if (0xfe < newStat) {
newStat = 0xff; newStat = 0xff;
} }
entityInfo1->spDef = newStat; entityInfo->spDef = newStat;
if (oldStat1 < (u8)newStat) { if (oldStat1 < (u8)newStat) {
sub_8041E94(target); sub_8041E94(target);
sub_80522F4(pokemon,target,*gUnknown_80FC428); sub_80522F4(pokemon,target,*gUnknown_80FC428);

View File

@ -4,6 +4,7 @@
#include "pokemon.h" #include "pokemon.h"
#include "pokemon_3.h" #include "pokemon_3.h"
#include "friend_area.h" #include "friend_area.h"
#include "moves.h"
static EWRAM_DATA struct unkStruct_203B494 sUnknown_2039778 = {0}; static EWRAM_DATA struct unkStruct_203B494 sUnknown_2039778 = {0};
@ -216,12 +217,9 @@ void sub_8097944(void)
{ {
bool8 bVar2; bool8 bVar2;
bool8 bVar3; bool8 bVar3;
int index; s32 i, j;
s32 counter; s32 counter;
Move *move; Move *move;
PokemonStruct1 *pokeStruct;
s32 index1;
s32 temp;
bVar2 = 1; bVar2 = 1;
bVar3 = 1; bVar3 = 1;
@ -229,99 +227,88 @@ void sub_8097944(void)
sub_80976F8(0xd); sub_80976F8(0xd);
} }
for(index = 0; index < NUM_MONSTERS; index++) for(i = 0; i < NUM_MONSTERS; i++)
{ {
if (PokemonFlag1(&gRecruitedPokemonRef->pokemon[i])) {
s32 species = gRecruitedPokemonRef->pokemon[i].speciesNum;
gUnknown_203B494->unk1C[species / 32] |= 1 << species % 32;
#ifdef NONMATCHING for(j = 0; j < MAX_MON_MOVES; j++)
pokeStruct = &index[gRecruitedPokemonRef->pokemon];
#else
register size_t offset asm("r1") = offsetof(unkStruct_203B45C, pokemon[index]);
PokemonStruct1* p = gRecruitedPokemonRef->pokemon;
size_t addr = offset + (size_t)p;
pokeStruct = (PokemonStruct1*)addr;
#endif
if (((u8)(pokeStruct->unk0) & 1)) {
temp = pokeStruct->speciesNum;
gUnknown_203B494->unk1C[temp / 32] |= 1 << temp % 32;
for(index1 = 0; index1 < MAX_MON_MOVES; index1++)
{ {
move = &gRecruitedPokemonRef->pokemon[index].moves[index1]; move = &gRecruitedPokemonRef->pokemon[i].moves[j];
if ((move->moveFlags & MOVE_FLAG_EXISTS)) { if (MoveFlagExists(move)) {
gUnknown_203B494->unk8C[move->id / 32] |= 1 << move->id % 32; gUnknown_203B494->unk8C[move->id / 32] |= 1 << move->id % 32;
} }
} }
} }
} }
for(index = 0; index < MONSTER_MAX; index++) for(i = 0; i < MONSTER_MAX; i++)
{ {
if (index == MONSTER_NONE) continue; if (i == MONSTER_NONE) continue;
if (index == MONSTER_CASTFORM_SNOWY) continue; if (i == MONSTER_CASTFORM_SNOWY) continue;
if (index == MONSTER_CASTFORM_SUNNY) continue; if (i == MONSTER_CASTFORM_SUNNY) continue;
if (index == MONSTER_CASTFORM_RAINY) continue; if (i == MONSTER_CASTFORM_RAINY) continue;
if (index == MONSTER_DEOXYS_ATTACK) continue; if (i == MONSTER_DEOXYS_ATTACK) continue;
if (index == MONSTER_DEOXYS_DEFENSE) continue; if (i == MONSTER_DEOXYS_DEFENSE) continue;
if (index == MONSTER_DEOXYS_SPEED) continue; if (i == MONSTER_DEOXYS_SPEED) continue;
if (index == MONSTER_MUNCHLAX) continue; if (i == MONSTER_MUNCHLAX) continue;
if (index == MONSTER_DECOY) continue; if (i == MONSTER_DECOY) continue;
if (index == MONSTER_STATUE) continue; if (i == MONSTER_STATUE) continue;
if (index == MONSTER_RAYQUAZA_CUTSCENE) continue; if (i == MONSTER_RAYQUAZA_CUTSCENE) continue;
if ((gUnknown_203B494->unk54[index / 32] & 1 << index % 32) == 0) if ((gUnknown_203B494->unk54[i / 32] & 1 << i % 32) == 0)
{ {
bVar3 = 0; bVar3 = 0;
} }
if ((gUnknown_203B494->unk1C[index / 32] & 1 << index % 32) != 0) if ((gUnknown_203B494->unk1C[i / 32] & 1 << i % 32) != 0)
{ {
if (index == MONSTER_MOLTRES) { if (i == MONSTER_MOLTRES) {
sub_80976F8(0x10); sub_80976F8(0x10);
} }
if (index == MONSTER_ZAPDOS) { if (i == MONSTER_ZAPDOS) {
sub_80976F8(0x11); sub_80976F8(0x11);
} }
if (index == MONSTER_ARTICUNO) { if (i == MONSTER_ARTICUNO) {
sub_80976F8(0x12); sub_80976F8(0x12);
} }
if (index == MONSTER_DEOXYS_NORMAL) { if (i == MONSTER_DEOXYS_NORMAL) {
sub_80976F8(0x13); sub_80976F8(0x13);
} }
if (index == MONSTER_ENTEI) { if (i == MONSTER_ENTEI) {
sub_80976F8(0x14); sub_80976F8(0x14);
} }
if (index == MONSTER_RAIKOU) { if (i == MONSTER_RAIKOU) {
sub_80976F8(0x15); sub_80976F8(0x15);
} }
if (index == MONSTER_SUICUNE) { if (i == MONSTER_SUICUNE) {
sub_80976F8(0x16); sub_80976F8(0x16);
} }
if (index == MONSTER_HO_OH) { if (i == MONSTER_HO_OH) {
sub_80976F8(0x17); sub_80976F8(0x17);
} }
if (index == MONSTER_KYOGRE) { if (i == MONSTER_KYOGRE) {
sub_80976F8(0x18); sub_80976F8(0x18);
} }
if (index == MONSTER_GROUDON) { if (i == MONSTER_GROUDON) {
sub_80976F8(0x19); sub_80976F8(0x19);
} }
if (index == MONSTER_RAYQUAZA) { if (i == MONSTER_RAYQUAZA) {
sub_80976F8(0x1a); sub_80976F8(0x1a);
} }
if (index == MONSTER_LUGIA) { if (i == MONSTER_LUGIA) {
sub_80976F8(0x1b); sub_80976F8(0x1b);
} }
if (index == MONSTER_CELEBI) { if (i == MONSTER_CELEBI) {
sub_80976F8(0x1c); sub_80976F8(0x1c);
} }
if (index == MONSTER_MEW) { if (i == MONSTER_MEW) {
sub_80976F8(0x1d); sub_80976F8(0x1d);
} }
if (index == MONSTER_MEWTWO) { if (i == MONSTER_MEWTWO) {
sub_80976F8(0x1e); sub_80976F8(0x1e);
} }
if (index == MONSTER_JIRACHI) { if (i == MONSTER_JIRACHI) {
sub_80976F8(0x1f); sub_80976F8(0x1f);
} }
} }
@ -338,10 +325,10 @@ void sub_8097944(void)
sub_80976F8(0xe); sub_80976F8(0xe);
} }
counter = 0; counter = 0;
for(index = 0; index < NUM_MONSTERS; index++) for(i = 0; i < NUM_MONSTERS; i++)
{ {
if (index == MONSTER_NONE || index == MONSTER_FLYGON || index == MONSTER_CACNEA || index == MONSTER_CACTURNE) continue; if (i == MONSTER_NONE || i == MONSTER_FLYGON || i == MONSTER_CACNEA || i == MONSTER_CACTURNE) continue;
if (gUnknown_203B494->unk8C[index / 32] & 1 << index % 32) { if (gUnknown_203B494->unk8C[i / 32] & 1 << i % 32) {
counter++; counter++;
} }
} }

View File

@ -25,7 +25,7 @@ extern void sub_8086AC0(void);
extern void sub_8043ED0(u32); extern void sub_8043ED0(u32);
extern void sub_8071DA4(Entity *); extern void sub_8071DA4(Entity *);
extern void TriggerWeatherAbilities(void); extern void TriggerWeatherAbilities(void);
extern void sub_805D8C8(void); extern void DungeonHandlePlayerInput(void);
extern void sub_805F02C(void); extern void sub_805F02C(void);
static void sub_8044454(void); static void sub_8044454(void);
@ -140,7 +140,7 @@ static bool8 xxx_dungeon_80442D0(bool8 param_1)
if (sub_8044B28()) return FALSE; if (sub_8044B28()) return FALSE;
sub_8071DA4(entity); sub_8071DA4(entity);
gDungeon->noActionInProgress = TRUE; gDungeon->noActionInProgress = TRUE;
sub_805D8C8(); DungeonHandlePlayerInput();
gDungeon->noActionInProgress = FALSE; gDungeon->noActionInProgress = FALSE;
if (sub_8044B28()) break; if (sub_8044B28()) break;
sub_8072CF4(entity); sub_8072CF4(entity);

View File

@ -106,9 +106,8 @@ u8 sub_80703A0(Entity *pokemon, Position *pos)
bool8 CanCrossWalls(Entity *pokemon) bool8 CanCrossWalls(Entity *pokemon)
{ {
EntityInfo *pokemonInfo = pokemon->info; EntityInfo *pokemonInfo = GetEntInfo(pokemon);
EntityInfo *pokemonInfo2 = pokemonInfo; if (pokemonInfo->transformStatus.transformStatus == STATUS_MOBILE)
if (pokemonInfo2->transformStatus.transformStatus == STATUS_MOBILE)
{ {
return TRUE; return TRUE;
} }
@ -116,7 +115,7 @@ bool8 CanCrossWalls(Entity *pokemon)
{ {
return TRUE; return TRUE;
} }
if (GetCrossableTerrain(pokemonInfo2->id) == CROSSABLE_TERRAIN_WALL) if (GetCrossableTerrain(pokemonInfo->id) == CROSSABLE_TERRAIN_WALL)
{ {
return TRUE; return TRUE;
} }

View File

@ -484,14 +484,7 @@ void FillInventoryGaps()
// clear out the rest of the slots // clear out the rest of the slots
for (; last_filled < INVENTORY_SIZE; last_filled++) { for (; last_filled < INVENTORY_SIZE; last_filled++) {
struct Item *items; ZeroOutItem(&gTeamInventoryRef->teamItems[last_filled]);
DUMMY_TEAM_ITEMS_ASM_MATCH(last_filled);
items = gTeamInventoryRef->teamItems;
items[last_filled].id = ITEM_NOTHING;
items[last_filled].quantity = 0;
items[last_filled].flags = 0;
} }
} }
@ -510,32 +503,32 @@ s32 GetItemCountInInventory(u8 id)
{ {
s32 i; s32 i;
s32 count = 0; s32 count = 0;
struct Item *item = &gTeamInventoryRef->teamItems[0];
for (i = 0; i < INVENTORY_SIZE; item++, i++) { for (i = 0; i < INVENTORY_SIZE; i++) {
if (item->flags & 1 && item->id == id) if (ItemExists(&gTeamInventoryRef->teamItems[i]) && gTeamInventoryRef->teamItems[i].id == id) {
count++; count++;
} }
}
return count; return count;
} }
s32 GetItemPossessionCount(u8 id) s32 GetItemPossessionCount(u8 id)
{ {
s32 item_count = GetItemCountInInventory(id); s32 count = GetItemCountInInventory(id);
s32 i = 0; s32 i = 0;
unkStruct_203B45C *_gRecruitedPokemonRef = gRecruitedPokemonRef;
for (i = 0; i < NUM_MONSTERS; i++) { for (i = 0; i < NUM_MONSTERS; i++) {
PokemonStruct1* pokemon = &_gRecruitedPokemonRef->pokemon[i]; PokemonStruct1 *mon = &gRecruitedPokemonRef->pokemon[i];
if ((1 & pokemon->unk0) if (PokemonFlag1(mon)
&& ((pokemon->unk0 >> 1) % 2) && PokemonFlag2(mon)
&& (pokemon->heldItem.id != ITEM_NOTHING) && (mon->heldItem.id != ITEM_NOTHING)
&& (pokemon->heldItem.id == id)) { && (mon->heldItem.id == id))
item_count++; {
count++;
} }
} }
return item_count; return count;
} }
void ShiftItemsDownFrom(s32 start) void ShiftItemsDownFrom(s32 start)
@ -575,12 +568,8 @@ bool8 AddItemToInventory(const Item* slot)
// try to add item to inventory, return 1 if failed // try to add item to inventory, return 1 if failed
for (i = 0; i < INVENTORY_SIZE; i++) { for (i = 0; i < INVENTORY_SIZE; i++) {
Item *items; if (!ItemExists(&gTeamInventoryRef->teamItems[i])) {
DUMMY_TEAM_ITEMS_ASM_MATCH(i); gTeamInventoryRef->teamItems[i] = *slot;
items = gTeamInventoryRef->teamItems;
if (!(items[i].flags & ITEM_FLAG_EXISTS)) {
items[i] = *slot;
return FALSE; return FALSE;
} }
} }
@ -589,54 +578,38 @@ bool8 AddItemToInventory(const Item* slot)
void ConvertMoneyItemToMoney(void) void ConvertMoneyItemToMoney(void)
{ {
s32 i = 0; s32 i, j;
do { for (i = 0; i < INVENTORY_SIZE; i++) {
UNUSED TeamInventory * _gTeamInventoryRef = gTeamInventoryRef; Item *item = &gTeamInventoryRef->teamItems[i];
UNUSED size_t offs = offsetof(TeamInventory, teamItems[i]); if (ItemExists(item) && item->id == ITEM_POKE) {
AddToTeamMoney(GetMoneyValue(item));
Item* current_slot = &gTeamInventoryRef->teamItems[i]; ZeroOutItem(item);
if ((current_slot->flags & ITEM_FLAG_EXISTS) && (current_slot->id == ITEM_POKE)) { }
u32 result;
result = GetMoneyValue(current_slot);
AddToTeamMoney(result);
current_slot->id = ITEM_NOTHING;
current_slot->quantity = 0;
current_slot->flags = 0;
} }
} while (++i < INVENTORY_SIZE);
FillInventoryGaps(); FillInventoryGaps();
i = 0; for (i = 0; i < INVENTORY_SIZE; i++) {
do { s32 lowestIndex = -1;
s32 lowest_index = -1;
UNUSED size_t offs = offsetof(TeamInventory, teamItems[i]);
bool8 item_occupied = i[gTeamInventoryRef->teamItems].flags & ITEM_FLAG_EXISTS; if (ItemExists(&gTeamInventoryRef->teamItems[i])) {
s32 next = i + 1; s32 lowestOrder = GetItemOrder(gTeamInventoryRef->teamItems[i].id);
if (item_occupied) { for (j = i + 1; j < INVENTORY_SIZE; j++) {
s32 lowest_order = GetItemOrder(gTeamInventoryRef->teamItems[i].id); if (ItemExists(&gTeamInventoryRef->teamItems[j]) && lowestOrder > GetItemOrder(gTeamInventoryRef->teamItems[j].id)) {
s32 j; lowestIndex = j;
lowestOrder = GetItemOrder(gTeamInventoryRef->teamItems[j].id);
// find next lowest
for (j = next; j < INVENTORY_SIZE; j++) {
UNUSED size_t offs = offsetof(TeamInventory, teamItems[j]);
if ((j[gTeamInventoryRef->teamItems].flags & ITEM_FLAG_EXISTS) && (lowest_order > GetItemOrder(gTeamInventoryRef->teamItems[j].id))) {
lowest_index = j;
lowest_order = GetItemOrder(gTeamInventoryRef->teamItems[j].id);
} }
} }
if (lowest_index >= 0) { if (lowestIndex >= 0) {
// swap the slots // swap the slots
Item current = gTeamInventoryRef->teamItems[i]; Item temp = gTeamInventoryRef->teamItems[i];
gTeamInventoryRef->teamItems[i] = gTeamInventoryRef->teamItems[lowest_index]; gTeamInventoryRef->teamItems[i] = gTeamInventoryRef->teamItems[lowestIndex];
gTeamInventoryRef->teamItems[lowest_index] = current; gTeamInventoryRef->teamItems[lowestIndex] = temp;
}
} }
} }
} while (++i < INVENTORY_SIZE);
FillInventoryGaps(); FillInventoryGaps();
} }
@ -908,12 +881,9 @@ bool8 IsGummiItem(u8 id)
bool8 HasGummiItem(void) bool8 HasGummiItem(void)
{ {
Item *items;
s32 i; s32 i;
for (i = 0; i < INVENTORY_SIZE; i++) { for (i = 0; i < INVENTORY_SIZE; i++) {
DUMMY_TEAM_ITEMS_ASM_MATCH(i); if (ItemExists(&gTeamInventoryRef->teamItems[i]) && IsGummiItem(gTeamInventoryRef->teamItems[i].id)) {
items = gTeamInventoryRef->teamItems;
if ((items[i].flags & ITEM_FLAG_EXISTS) && IsGummiItem(items[i].id)) {
return TRUE; return TRUE;
} }
} }
@ -1444,34 +1414,24 @@ s32 sub_8091E94(s32 a1, s32 a2, s32 a3)
#endif #endif
} }
void ClearAllItems_8091FB4() { void ClearAllItems_8091FB4(void)
{
s32 i; s32 i;
for (i = 0; i < INVENTORY_SIZE; i++) { for (i = 0; i < INVENTORY_SIZE; i++) {
Item* slot = &gTeamInventoryRef->teamItems[i]; Item* slot = &gTeamInventoryRef->teamItems[i];
if (slot->flags & ITEM_FLAG_EXISTS) { if (ItemExists(slot)) {
slot->flags &= 0xf7; slot->flags &= ~(ITEM_FLAG_STICKY);
if (slot->id == ITEM_POKE) { if (slot->id == ITEM_POKE) {
AddToTeamMoney(GetMoneyValue(slot)); AddToTeamMoney(GetMoneyValue(slot));
slot->id = ITEM_NOTHING; ZeroOutItem(slot);
slot->quantity = 0;
slot->flags = 0;
} }
} }
} }
FillInventoryGaps(); FillInventoryGaps();
for (i = 0; i < NUM_MONSTERS; i++) { for (i = 0; i < NUM_MONSTERS; i++) {
PokemonStruct1* pokemon; if (PokemonFlag1(&gRecruitedPokemonRef->pokemon[i])) {
#ifdef NONMATCHING PokemonStruct1 *pokemon = &gRecruitedPokemonRef->pokemon[i];
pokemon = &i[gRecruitedPokemonRef->pokemon];
#else
register size_t offset asm("r1") = offsetof(unkStruct_203B45C, pokemon[i]);
PokemonStruct1* p = gRecruitedPokemonRef->pokemon;
size_t addr = offset + (size_t)p;
pokemon = (PokemonStruct1*)addr;
#endif
if ((u8)pokemon->unk0 & 1) {
if (pokemon->heldItem.id) { if (pokemon->heldItem.id) {
if (pokemon->heldItem.id == ITEM_POKE) { if (pokemon->heldItem.id == ITEM_POKE) {
AddToTeamMoney(GetMoneyValueHeld(&pokemon->heldItem)); AddToTeamMoney(GetMoneyValueHeld(&pokemon->heldItem));

View File

@ -46,6 +46,8 @@ extern u8 gFormatItems[];
extern u8 gAvailablePokemonNames[]; extern u8 gAvailablePokemonNames[];
extern u8 gUnknown_202DFE8[]; extern u8 gUnknown_202DFE8[];
extern const u8 *const gUnknown_80FD350;
extern const u8 *const gUnknown_80FD370;
extern u8 *gUnknown_80FE3BC[]; extern u8 *gUnknown_80FE3BC[];
extern u8 *gUnknown_80FE38C[]; extern u8 *gUnknown_80FE38C[];
extern u8 *gUnknown_80FC888[]; extern u8 *gUnknown_80FC888[];
@ -510,36 +512,26 @@ bool32 sub_8057974(Entity *pokemon, Entity *target, Move *move, u32 param_4)
return local_24; return local_24;
} }
bool8 PainSplitMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) bool8 PainSplitMoveAction(Entity *attacker, Entity *target, Move *move, s32 param_4)
{ {
s32 newHP; EntityInfo *attackerInfo = GetEntInfo(attacker);
EntityInfo *iVar2; EntityInfo *targetInfo = GetEntInfo(target);
EntityInfo *iVar3; s32 newHP = (attackerInfo->HP + targetInfo->HP) / 2;
EntityInfo *iVar4;
EntityInfo *iVar5;
// Need copies for some reason to match.. attackerInfo->HP = newHP;
iVar3 = (pokemon->info); targetInfo->HP = newHP;
iVar4 = iVar3; if (attackerInfo->HP > attackerInfo->maxHPStat) {
iVar2 = (target->info); attackerInfo->HP = attackerInfo->maxHPStat;
iVar5 = iVar2;
newHP = ((iVar3->HP + iVar2->HP) / 2);
iVar3->HP = newHP;
iVar5->HP = newHP;
if (iVar3->HP > iVar3->maxHPStat) {
iVar3->HP = iVar3->maxHPStat;
} }
if (iVar5->HP > iVar5->maxHPStat) { if (targetInfo->HP > targetInfo->maxHPStat) {
iVar5->HP = iVar5->maxHPStat; targetInfo->HP = targetInfo->maxHPStat;
} }
SetMessageArgument(gAvailablePokemonNames,pokemon,0); SetMessageArgument(gAvailablePokemonNames,attacker,0);
SetMessageArgument(gAvailablePokemonNames + 0x50,target,0); SetMessageArgument(gAvailablePokemonNames + 0x50,target,0);
if (iVar4->unkFB == 0) { SetExpMultplier(attackerInfo);
iVar4->unkFB = 1;
}
// $m0 and $m1 shared their HP // $m0 and $m1 shared their HP
sub_80522F4(pokemon,target,*gUnknown_80FC7EC); sub_80522F4(attacker,target,*gUnknown_80FC7EC);
return TRUE; return TRUE;
} }
@ -693,73 +685,29 @@ bool8 sub_8057D7C(Entity * pokemon, Entity * target, Move *move, s32 param_4)
return TRUE; return TRUE;
} }
NAKED bool8 sub_8057D9C(Entity * pokemon, Entity * target, Move *move, s32 param_4) bool8 sub_8057D9C(Entity * pokemon, Entity * target, Move *move, s32 param_4)
{ {
asm_unified( s32 i;
"\tpush {r4-r7,lr}\n" EntityInfo *targetInfo = GetEntInfo(target);
"\tmov r7, r8\n" bool8 flag = FALSE;
"\tpush {r7}\n"
"\tadds r6, r0, 0\n" for (i = 0; i < MAX_MON_MOVES; i++) {
"\tadds r4, r1, 0\n" Move *move = &targetInfo->moves.moves[i];
"\tldr r0, [r4, 0x70]\n" if (MoveFlagExists(move) && MoveFlagLastUsed(move)) {
"\tmovs r5, 0\n" move->PP = 0;
"\tldr r1, _08057DF8\n" flag = TRUE;
"\tmov r8, r1\n" }
"\tmovs r1, 0x8C\n" }
"\tlsls r1, 1\n"
"\tadds r2, r0, r1\n" SetMessageArgument(gUnknown_202DFE8, target, 0);
"\tmovs r0, 0x1\n" if (flag) {
"\tmov r12, r0\n" sub_80522F4(pokemon, target, gUnknown_80FD350);
"\tmovs r7, 0x10\n" }
"\tmovs r3, 0x3\n" else {
"_08057DBC:\n" sub_80522F4(pokemon, target, gUnknown_80FD370);
"\tldrb r1, [r2]\n" }
"\tmov r0, r12\n"
"\tands r0, r1\n" return flag;
"\tcmp r0, 0\n"
"\tbeq _08057DD4\n"
"\tadds r0, r7, 0\n"
"\tands r0, r1\n"
"\tcmp r0, 0\n"
"\tbeq _08057DD4\n"
"\tmovs r0, 0\n"
"\tstrb r0, [r2, 0x4]\n"
"\tmovs r5, 0x1\n"
"_08057DD4:\n"
"\tadds r2, 0x8\n"
"\tsubs r3, 0x1\n"
"\tcmp r3, 0\n"
"\tbge _08057DBC\n"
"\tmov r0, r8\n"
"\tadds r1, r4, 0\n"
"\tmovs r2, 0\n"
"\tbl SetMessageArgument\n"
"\tcmp r5, 0\n"
"\tbeq _08057E00\n"
"\tldr r0, _08057DFC\n"
"\tldr r2, [r0]\n"
"\tadds r0, r6, 0\n"
"\tadds r1, r4, 0\n"
"\tbl sub_80522F4\n"
"\tb _08057E0C\n"
"\t.align 2, 0\n"
"_08057DF8: .4byte gUnknown_202DFE8\n"
"_08057DFC: .4byte gUnknown_80FD350\n"
"_08057E00:\n"
"\tldr r0, _08057E18\n"
"\tldr r2, [r0]\n"
"\tadds r0, r6, 0\n"
"\tadds r1, r4, 0\n"
"\tbl sub_80522F4\n"
"_08057E0C:\n"
"\tadds r0, r5, 0\n"
"\tpop {r3}\n"
"\tmov r8, r3\n"
"\tpop {r4-r7}\n"
"\tpop {r1}\n"
"\tbx r1\n"
"\t.align 2, 0\n"
"_08057E18: .4byte gUnknown_80FD370");
} }
bool8 FocusEnergyMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) bool8 FocusEnergyMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4)
@ -1194,9 +1142,7 @@ bool8 sub_80586DC(Entity * pokemon, Entity * target, Move * move, u32 param_4)
if (newHP < 1) { if (newHP < 1) {
newHP = 1; newHP = 1;
} }
if (!entityInfo->unkFB) { SetExpMultplier(entityInfo);
entityInfo->unkFB = TRUE;
}
if (hasLiquidOoze) { if (hasLiquidOoze) {
DealDamageToEntity(pokemon, newHP, 0xd, 0x1fa); DealDamageToEntity(pokemon, newHP, 0xd, 0x1fa);
} }
@ -1208,43 +1154,27 @@ bool8 sub_80586DC(Entity * pokemon, Entity * target, Move * move, u32 param_4)
} }
// NOTE: copy of sub_805AFA4 in status_checker.c except for different reg for entityInfo // NOTE: almost the same as sub_8058D44 and sub_805AFA4 in status_actions.c
bool8 sub_8058770(Entity * pokemon, Entity * target, Move * move, u32 param_4) bool8 sub_8058770(Entity * pokemon, Entity * target, Move * move, u32 param_4)
{ {
s32 r0; s32 index;
s32 r2;
s32 r1;
bool8 flag; bool8 flag;
EntityInfo *entityInfo = GetEntInfo(pokemon);
s32 maxHp = entityInfo->maxHPStat;
if (entityInfo->HP <= entityInfo->maxHPStat / 4) {
index = 0;
}
else if (entityInfo->HP <= maxHp / 2) {
index = 1;
}
else if (entityInfo->HP <= (maxHp * 3) / 4) {
index = 2;
}
else {
index = 3;
}
#ifndef NONMATCHING flag = sub_8055640(pokemon,target,move,gUnknown_80F51A4[index],param_4) ? TRUE : FALSE;
register EntityInfo *entityInfo asm("r2");
#else
EntityInfo *entityInfo;
#endif
entityInfo = pokemon->info;
r2 = entityInfo->maxHPStat;
r0 = r2;
if (r2 < 0) {
r0 = r2 + 3;
}
if (entityInfo->HP <= r0 >> 2) {
r2 = 0;
}
else if (r1 = entityInfo->HP, r1 <= r2 / 2) {
r2 = 1;
}
else
{
r0 = r2 * 3;
if (r0 < 0) {
r0 = r0 + 3;
}
if (r0 >>= 2, r2 = 3, r1 <= r0) {
r2 = 2;
}
}
flag = sub_8055640(pokemon,target,move,gUnknown_80F51A4[r2],param_4) ? TRUE : FALSE;
return flag; return flag;
} }
@ -1331,10 +1261,7 @@ bool8 sub_8058930(Entity *pokemon, Entity *target, Move *move, u32 param_4)
RaiseAttackStageTarget(pokemon, pokemon, index2, 1); RaiseAttackStageTarget(pokemon, pokemon, index2, 1);
RaiseDefenseStageTarget(pokemon, pokemon, index1, 1); RaiseDefenseStageTarget(pokemon, pokemon, index1, 1);
RaiseDefenseStageTarget(pokemon, pokemon, index2, 1); RaiseDefenseStageTarget(pokemon, pokemon, index2, 1);
if(entityInfo->unkFB == 0) SetExpMultplier(entityInfo);
{
entityInfo->unkFB = 1;
}
} }
} }
return flag; return flag;
@ -1426,8 +1353,7 @@ bool8 sub_8058B84(Entity *pokemon, Entity *target, Move *move, u32 param_4)
{ {
entityInfo = pokemon->info; entityInfo = pokemon->info;
RaiseAttackStageTarget(pokemon, pokemon, gUnknown_8106A4C, 1); RaiseAttackStageTarget(pokemon, pokemon, gUnknown_8106A4C, 1);
if(entityInfo->unkFB == 0) SetExpMultplier(entityInfo);
entityInfo->unkFB = 1;
} }
} }
return flag; return flag;
@ -1516,40 +1442,24 @@ bool8 sub_8058D38(Entity *pokemon, Entity *target, Move *move, u32 param_4)
// NOTE: same as sub_8058770 // NOTE: same as sub_8058770
bool8 sub_8058D44(Entity * pokemon, Entity * target, Move * move, u32 param_4) bool8 sub_8058D44(Entity * pokemon, Entity * target, Move * move, u32 param_4)
{ {
s32 r0; s32 index;
s32 r2;
s32 r1;
bool8 flag; bool8 flag;
EntityInfo *entityInfo = GetEntInfo(pokemon);
s32 maxHp = entityInfo->maxHPStat;
if (entityInfo->HP <= entityInfo->maxHPStat / 4) {
index = 0;
}
else if (entityInfo->HP <= maxHp / 2) {
index = 1;
}
else if (entityInfo->HP <= (maxHp * 3) / 4) {
index = 2;
}
else {
index = 3;
}
#ifndef NONMATCHING flag = sub_8055640(pokemon,target,move,gUnknown_80F51B4[index],param_4) ? TRUE : FALSE;
register EntityInfo *entityInfo asm("r2");
#else
EntityInfo *entityInfo;
#endif
entityInfo = pokemon->info;
r2 = entityInfo->maxHPStat;
r0 = r2;
if (r2 < 0) {
r0 = r2 + 3;
}
if (entityInfo->HP <= r0 >> 2) {
r2 = 0;
}
else if (r1 = entityInfo->HP, r1 <= r2 / 2) {
r2 = 1;
}
else
{
r0 = r2 * 3;
if (r0 < 0) {
r0 = r0 + 3;
}
if (r0 >>= 2, r2 = 3, r1 <= r0) {
r2 = 2;
}
}
flag = sub_8055640(pokemon,target,move,gUnknown_80F51B4[r2],param_4) ? TRUE : FALSE;
return flag; return flag;
} }
@ -1574,9 +1484,7 @@ bool8 PsychUpMoveAction(Entity * pokemon, Entity * target, Move * move, u32 para
} }
SetMessageArgument(gAvailablePokemonNames,target,0); SetMessageArgument(gAvailablePokemonNames,target,0);
sub_80522F4(pokemon,target,*gUnknown_80FBD58); // It psyched itself up! sub_80522F4(pokemon,target,*gUnknown_80FBD58); // It psyched itself up!
if (iVar4->unkFB == 0) { SetExpMultplier(iVar4);
iVar4->unkFB = 1;
}
return TRUE; return TRUE;
} }
@ -1753,7 +1661,6 @@ bool8 sub_80591E4(Entity *pokemon, Entity *target, Move *move, s32 param_4)
s32 iVar3; s32 iVar3;
s32 iVar4; s32 iVar4;
bool8 flag; bool8 flag;
EntityInfo *entityInfo;
flag = FALSE; flag = FALSE;
hasLiquidOoze = HasAbility(target, ABILITY_LIQUID_OOZE); hasLiquidOoze = HasAbility(target, ABILITY_LIQUID_OOZE);
@ -1764,11 +1671,9 @@ bool8 sub_80591E4(Entity *pokemon, Entity *target, Move *move, s32 param_4)
iVar4 = 1; iVar4 = 1;
} }
if (EntityExists(pokemon)) { if (EntityExists(pokemon)) {
entityInfo = pokemon->info; EntityInfo *entityInfo = GetEntInfo(pokemon);
flag = TRUE; flag = TRUE;
if (entityInfo->unkFB == 0) { SetExpMultplier(entityInfo);
entityInfo->unkFB = 1;
}
if (sub_8057308(pokemon,0)) { if (sub_8057308(pokemon,0)) {
if (hasLiquidOoze) { if (hasLiquidOoze) {
DealDamageToEntity(pokemon,iVar4,0xd,0x1fa); DealDamageToEntity(pokemon,iVar4,0xd,0x1fa);
@ -1784,34 +1689,27 @@ bool8 sub_80591E4(Entity *pokemon, Entity *target, Move *move, s32 param_4)
bool8 SkillSwapMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) bool8 SkillSwapMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4)
{ {
u8 ability_1; bool32 flag;
u8 ability_2;
bool8 flag;
u8 *puVar5;
u8 *puVar6;
EntityInfo * targetEntityInfo;
EntityInfo * pokeEntityData;
pokeEntityData = pokemon->info; EntityInfo *pokeEntityData = GetEntInfo(pokemon);
targetEntityInfo = target->info; EntityInfo *targetEntityInfo = GetEntInfo(target);
if ((HasAbility(target, ABILITY_WONDER_GUARD)) || (HasAbility(pokemon, ABILITY_WONDER_GUARD))) { if ((HasAbility(target, ABILITY_WONDER_GUARD)) || (HasAbility(pokemon, ABILITY_WONDER_GUARD))) {
sub_80522F4(pokemon,target,*gUnknown_80FC8C0); sub_80522F4(pokemon,target,*gUnknown_80FC8C0);
flag = FALSE; flag = FALSE;
} }
else else
{ {
puVar5 = &targetEntityInfo->abilities[0]; s32 ability1 = targetEntityInfo->abilities[0];
ability_1 = *puVar5; s32 ability2 = targetEntityInfo->abilities[1];
puVar6 = &targetEntityInfo->abilities[1]; targetEntityInfo->abilities[0] = pokeEntityData->abilities[0];
ability_2 = *puVar6; targetEntityInfo->abilities[1] = pokeEntityData->abilities[1];
*puVar5 = pokeEntityData->abilities[0]; pokeEntityData->abilities[0] = ability1;
*puVar6 = pokeEntityData ->abilities[1]; pokeEntityData->abilities[1] = ability2;
pokeEntityData->abilities[0] = ability_1;
pokeEntityData->abilities[1] = ability_2;
gDungeon->unkC = 1; gDungeon->unkC = 1;
sub_80522F4(pokemon,target,*gUnknown_80FC888); sub_80522F4(pokemon,target,*gUnknown_80FC888);
if (pokeEntityData->unkFB == 0) { // Weirdly enough SetExpMultplier inline doesn't work here...
pokeEntityData->unkFB = 1; if (pokeEntityData->expMultiplier == EXP_HALVED) {
pokeEntityData->expMultiplier = EXP_REGULAR;
} }
sub_806ABAC(pokemon,pokemon); sub_806ABAC(pokemon,pokemon);
sub_806ABAC(pokemon,target); sub_806ABAC(pokemon,target);
@ -1820,178 +1718,44 @@ bool8 SkillSwapMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param
return flag; return flag;
} }
// https://decomp.me/scratch/Ul8x5
#ifdef NONMATCHING
bool32 SketchMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) bool32 SketchMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4)
{ {
u16 moveID; s32 i;
struct EntityInfo *targetInfo; bool32 ret = FALSE;
struct EntityInfo *pokeInfo; EntityInfo *pokeInfo = GetEntInfo(pokemon);
int moveIndex; EntityInfo *targetInfo = GetEntInfo(target);
register bool32 flag asm("sl"); bool32 moveFound = FALSE;
struct Move *move1; u16 moveId = MOVE_NOTHING;
s32 other_flag = 0;
flag = 0; for (i = 0; i < MAX_MON_MOVES; i++) {
pokeInfo = pokemon->info; if (MoveFlagExists(&targetInfo->moves.moves[i]) && targetInfo->moves.moves[i].moveFlags & MOVE_FLAG_LAST_USED) {
targetInfo = target->info; moveId = targetInfo->moves.moves[i].id;
moveID = 0; moveFound = TRUE;
break;
for(moveIndex = 0; moveIndex < MAX_MON_MOVES; moveIndex++)
{
move1 = &targetInfo->moves[moveIndex];
if ((((move1->moveFlags & MOVE_FLAG_EXISTS))) && ((targetInfo->moves[moveIndex].moveFlags & 0x10))) {
moveID = targetInfo->moves[moveIndex].id;
goto _moveIDcheck;
} }
} }
if(other_flag == 0) if (!moveFound) {
{
sub_80522F4(pokemon, target, *gUnknown_80FE3BC); sub_80522F4(pokemon, target, *gUnknown_80FE3BC);
return 0; return FALSE;
} }
_moveIDcheck: if (moveId == MOVE_NOTHING) {
if (moveID == 0) {
sub_80522F4(pokemon, target, *gUnknown_80FE3BC); sub_80522F4(pokemon, target, *gUnknown_80FE3BC);
} }
else { else {
InitPokemonMove(move, moveID); InitPokemonMove(move, moveId);
sub_80928C0(gFormatItems, move, 0); sub_80928C0(gFormatItems, move, 0);
move->moveFlags2 |= MOVE_FLAG2_UNK4; move->moveFlags2 |= MOVE_FLAG2_UNK4;
move->moveFlags2 |= MOVE_FLAG_REPLACE; move->moveFlags2 |= MOVE_FLAG_REPLACE;
sub_80522F4(pokemon, target, *gUnknown_80FE38C); sub_80522F4(pokemon, target, *gUnknown_80FE38C);
if (pokeInfo->unkFB == 0) { ASM_MATCH_TRICK(pokeInfo);
pokeInfo->unkFB = 1; SetExpMultplier(pokeInfo);
ret = TRUE;
} }
flag = 1;
}
return flag;
}
#else return ret;
NAKED
bool32 SketchMoveAction(Entity *pokemon, Entity *target, Move *move, s32 param_4)
{
asm_unified(
"\tpush {r4-r7,lr}\n"
"\tmov r7, r10\n"
"\tmov r6, r9\n"
"\tmov r5, r8\n"
"\tpush {r5-r7}\n"
"\tsub sp, 0x4\n"
"\tadds r6, r0, 0\n"
"\tadds r7, r1, 0\n"
"\tadds r5, r2, 0\n"
"\tmovs r0, 0\n"
"\tmov r10, r0\n"
"\tldr r1, [r6, 0x70]\n"
"\tstr r1, [sp]\n"
"\tldr r0, [r7, 0x70]\n"
"\tmovs r2, 0\n"
"\tmov r12, r2\n"
"\tmovs r4, 0\n"
"\tmovs r1, 0x8C\n"
"\tlsls r1, 1\n"
"\tadds r3, r0, r1\n"
"\tadds r1, r0, 0\n"
"\tmovs r2, 0x1\n"
"\tmov r9, r2\n"
"\tmovs r0, 0x10\n"
"\tmov r8, r0\n"
"_08059372:\n"
"\tldrb r2, [r3]\n"
"\tmov r0, r9\n"
"\tands r0, r2\n"
"\tcmp r0, 0\n"
"\tbeq _08059384\n"
"\tmov r0, r8\n"
"\tands r0, r2\n"
"\tcmp r0, 0\n"
"\tbne _080593A8\n"
"_08059384:\n"
"\tadds r3, 0x8\n"
"\tadds r1, 0x8\n"
"\tadds r4, 0x1\n"
"\tcmp r4, 0x3\n"
"\tble _08059372\n"
"\tmovs r0, 0\n"
"\tcmp r0, 0\n"
"\tbne _080593B2\n"
"\tldr r0, _080593A4\n"
"\tldr r2, [r0]\n"
"\tadds r0, r6, 0\n"
"\tadds r1, r7, 0\n"
"\tbl sub_80522F4\n"
"\tmovs r0, 0\n"
"\tb _0805940A\n"
"\t.align 2, 0\n"
"_080593A4: .4byte gUnknown_80FE3BC\n"
"_080593A8:\n"
"\tmovs r2, 0x8D\n"
"\tlsls r2, 1\n"
"\tadds r0, r1, r2\n"
"\tldrh r0, [r0]\n"
"\tmov r12, r0\n"
"_080593B2:\n"
"\tmov r0, r12\n"
"\tcmp r0, 0\n"
"\tbne _080593CC\n"
"\tldr r0, _080593C8\n"
"\tldr r2, [r0]\n"
"\tadds r0, r6, 0\n"
"\tadds r1, r7, 0\n"
"\tbl sub_80522F4\n"
"\tb _08059408\n"
"\t.align 2, 0\n"
"_080593C8: .4byte gUnknown_80FE3BC\n"
"_080593CC:\n"
"\tadds r0, r5, 0\n"
"\tmov r1, r12\n"
"\tbl InitPokemonMove\n"
"\tldr r0, _0805941C\n"
"\tadds r1, r5, 0\n"
"\tmovs r2, 0\n"
"\tbl sub_80928C0\n"
"\tldrb r1, [r5, 0x1]\n"
"\tmovs r0, 0x4\n"
"\torrs r0, r1\n"
"\tmovs r1, 0x20\n"
"\torrs r0, r1\n"
"\tstrb r0, [r5, 0x1]\n"
"\tldr r0, _08059420\n"
"\tldr r2, [r0]\n"
"\tadds r0, r6, 0\n"
"\tadds r1, r7, 0\n"
"\tbl sub_80522F4\n"
"\tldr r1, [sp]\n"
"\tadds r1, 0xFB\n"
"\tldrb r0, [r1]\n"
"\tcmp r0, 0\n"
"\tbne _08059404\n"
"\tmovs r0, 0x1\n"
"\tstrb r0, [r1]\n"
"_08059404:\n"
"\tmovs r1, 0x1\n"
"\tmov r10, r1\n"
"_08059408:\n"
"\tmov r0, r10\n"
"_0805940A:\n"
"\tadd sp, 0x4\n"
"\tpop {r3-r5}\n"
"\tmov r8, r3\n"
"\tmov r9, r4\n"
"\tmov r10, r5\n"
"\tpop {r4-r7}\n"
"\tpop {r1}\n"
"\tbx r1\n"
"\t.align 2, 0\n"
"_0805941C: .4byte gFormatItems\n"
"_08059420: .4byte gUnknown_80FE38C\n"
);
} }
#endif
bool8 sub_8059424(Entity *pokemon, Entity *target, Move *move, u32 param_4) bool8 sub_8059424(Entity *pokemon, Entity *target, Move *move, u32 param_4)
{ {
@ -2619,9 +2383,7 @@ bool8 sub_805A120(Entity * pokemon,Entity * target, Move *move, u32 param_4)
sp->heldItem = item; sp->heldItem = item;
sub_806A6E8(pokemon); sub_806A6E8(pokemon);
sub_806A6E8(target); sub_806A6E8(target);
if (r7->unkFB == 0) { SetExpMultplier(r7);
r7->unkFB = 1;
}
sub_80522F4(pokemon,target,*gUnknown_80FC790); // Traded items sub_80522F4(pokemon,target,*gUnknown_80FC790); // Traded items
return TRUE; return TRUE;
} }
@ -2717,9 +2479,7 @@ bool8 RolePlayMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_
entityInfo->abilities[0] = targetEntityInfo->abilities[0]; entityInfo->abilities[0] = targetEntityInfo->abilities[0];
entityInfo->abilities[1] = targetEntityInfo->abilities[1]; entityInfo->abilities[1] = targetEntityInfo->abilities[1];
gDungeon->unkC = 1; gDungeon->unkC = 1;
if (entityInfo->unkFB == 0) { SetExpMultplier(entityInfo);
entityInfo->unkFB = 1;
}
sub_80522F4(pokemon,target,*gUnknown_80FC81C); sub_80522F4(pokemon,target,*gUnknown_80FC81C);
sub_806ABAC(pokemon, pokemon); sub_806ABAC(pokemon, pokemon);
return TRUE; return TRUE;
@ -2864,9 +2624,7 @@ bool8 sub_805A5E8(Entity *pokemon, Entity *target, Move *move, u32 stat, u32 par
if (sub_805727C(pokemon,pokemon,gUnknown_80F4DD2) != 0) { if (sub_805727C(pokemon,pokemon,gUnknown_80F4DD2) != 0) {
entityInfo = pokemon->info; entityInfo = pokemon->info;
RaiseDefenseStageTarget(pokemon,pokemon,stat,1); RaiseDefenseStageTarget(pokemon,pokemon,stat,1);
if (entityInfo->unkFB == 0) { SetExpMultplier(entityInfo);
entityInfo->unkFB = 1;
}
} }
} }
return flag; return flag;
@ -2905,17 +2663,12 @@ bool8 sub_805A688(Entity *pokemon, Entity *target, Move *move, u32 param_4)
bool8 KnockOffMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_4) bool8 KnockOffMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_4)
{ {
EntityInfo *entityInfo; EntityInfo *entityInfo;
EntityInfo *targetEntityInfo1; EntityInfo *targetEntityInfo;
EntityInfo *targetEntityInfo2;
Item heldItem; Item heldItem;
Position pos; Position pos;
Item *itemPtr;
u32 flag;
u32 itemFlag;
entityInfo = pokemon->info; entityInfo = GetEntInfo(pokemon);
targetEntityInfo1 = target->info; targetEntityInfo = GetEntInfo(target);
targetEntityInfo2 = targetEntityInfo1;
SetMessageArgument(gAvailablePokemonNames, pokemon, 0); SetMessageArgument(gAvailablePokemonNames, pokemon, 0);
SetMessageArgument(gAvailablePokemonNames + 0x50, target, 0); SetMessageArgument(gAvailablePokemonNames + 0x50, target, 0);
if (HasAbility(target, ABILITY_STICKY_HOLD)) if (HasAbility(target, ABILITY_STICKY_HOLD))
@ -2930,21 +2683,15 @@ bool8 KnockOffMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_
} }
else else
{ {
heldItem = targetEntityInfo1->heldItem; heldItem = targetEntityInfo->heldItem;
itemFlag = heldItem.flags; if (!ItemExists(&heldItem))
flag = ITEM_FLAG_EXISTS;
flag &= itemFlag;
if (flag == 0)
{ {
sub_80522F4(pokemon,target,*gUnknown_80FD18C); sub_80522F4(pokemon,target,*gUnknown_80FD18C);
return FALSE; return FALSE;
} }
else else
{ {
itemPtr = &targetEntityInfo2->heldItem; ZeroOutItem(&targetEntityInfo->heldItem);
itemPtr->id = ITEM_NOTHING;
itemPtr->quantity = 0;
itemPtr->flags = 0;
sub_80522F4(pokemon,target,*gUnknown_80FD170); // $m1's item was swatted down! sub_80522F4(pokemon,target,*gUnknown_80FD170); // $m1's item was swatted down!
pos.x = gAdjacentTileOffsets[entityInfo->action.direction].x; pos.x = gAdjacentTileOffsets[entityInfo->action.direction].x;
pos.y = gAdjacentTileOffsets[entityInfo->action.direction].y; pos.y = gAdjacentTileOffsets[entityInfo->action.direction].y;
@ -3189,32 +2936,15 @@ bool8 sub_805AD34(Entity *pokemon, Entity *target, Move *move, u32 param_4)
return TRUE; return TRUE;
} }
static inline bool8 sub_805AD54_sub(Entity *entity) bool32 sub_805AD54(Entity * pokemon, Entity * target, Move *move, u32 param_4)
{
if ((entity->info->joinedAt.joinedAt == 0x4A) || (entity->info->joinedAt.joinedAt == 0x47)) {
return TRUE;
}
else {
return FALSE;
}
}
bool8 sub_805AD54(Entity * pokemon, Entity * target, Move *move, u32 param_4)
{ {
s32 numPossibleTargets; s32 numPossibleTargets;
EntityInfo *info; s32 i;
Entity *targetEntity;
#ifndef NONMATCHING
register s32 index asm("r6");
#else
s32 index;
#endif
Entity **possibleTargets; Entity **possibleTargets;
bool8 flag; bool32 flag = FALSE;
EntityInfo *info = GetEntInfo(pokemon);
flag = FALSE; if (info->isNotTeamMember) {
info = pokemon->info;
if (pokemon->info->isNotTeamMember) {
possibleTargets = gDungeon->wildPokemon; possibleTargets = gDungeon->wildPokemon;
numPossibleTargets = DUNGEON_MAX_WILD_POKEMON; numPossibleTargets = DUNGEON_MAX_WILD_POKEMON;
} }
@ -3222,20 +2952,22 @@ bool8 sub_805AD54(Entity * pokemon, Entity * target, Move *move, u32 param_4)
possibleTargets = gDungeon->teamPokemon; possibleTargets = gDungeon->teamPokemon;
numPossibleTargets = MAX_TEAM_MEMBERS; numPossibleTargets = MAX_TEAM_MEMBERS;
} }
for ( index = 0; index < numPossibleTargets; index++) {
targetEntity = possibleTargets[index]; for (i = 0; i < numPossibleTargets; i++) {
if ((((EntityExists(targetEntity)) && (pokemon != targetEntity)) && Entity *targetEntity = possibleTargets[i];
(GetTreatmentBetweenMonsters(pokemon,targetEntity,FALSE,FALSE) == TREATMENT_TREAT_AS_ALLY)) && if (EntityExists(targetEntity)
(targetEntity->info->clientType != CLIENT_TYPE_CLIENT)) { && pokemon != targetEntity
if (!sub_805AD54_sub(targetEntity)) { && GetTreatmentBetweenMonsters(pokemon,targetEntity,FALSE,FALSE) == TREATMENT_TREAT_AS_ALLY)
{
EntityInfo *targetInfo = GetEntInfo(targetEntity);
if (targetInfo->clientType != CLIENT_TYPE_CLIENT && !IsClientOrTeamBase(targetInfo->joinedAt.joinedAt)) {
sub_807D148(pokemon,targetEntity,2,&target->pos); sub_807D148(pokemon,targetEntity,2,&target->pos);
flag = TRUE; flag = TRUE;
if (info->unkFB == 0) { SetExpMultplier(info);
info->unkFB = 1;
}
} }
} }
} }
if (!flag) { if (!flag) {
sub_80522F4(pokemon,target,*gUnknown_81004EC); sub_80522F4(pokemon,target,*gUnknown_81004EC);
} }
@ -3282,42 +3014,25 @@ bool8 sub_805AECC(Entity * pokemon, Entity * target, Move *move, u32 param_4)
bool8 PresentMoveAction(Entity * pokemon, Entity * target, Move *move, u32 param_4) bool8 PresentMoveAction(Entity * pokemon, Entity * target, Move *move, u32 param_4)
{ {
s32 rand1;
s32 rand2;
s32 HP;
bool8 flag; bool8 flag;
#ifndef NONMATCHING
register Move *move_r6 asm("r6");
register u32 param_4_r4 asm("r4");
#else
Move *move_r6;
u32 param_4_r4;
#endif
move_r6 = move; s32 rand1 = DungeonRandInt(100);
param_4_r4 = param_4; s32 rand2 = rand1;
rand1 = DungeonRandInt(100);
rand2 = rand1;
if (rand1 < 10) { if (rand1 < 10) {
flag = sub_8055864(pokemon,target,move_r6,0x78,param_4_r4) != 0 ? TRUE : FALSE; flag = (sub_8055864(pokemon,target,move,0x78,param_4) != 0);
return flag; return flag;
} }
else { else {
if (rand1 < 0x1e) { if (rand1 < 30) {
HP = target->info->maxHPStat; HealTargetHP(pokemon,target,target->info->maxHPStat/4,0,TRUE);
if (HP < 0) {
HP = HP + 3;
}
HealTargetHP(pokemon,target,HP >> 2,0,TRUE);
return TRUE; return TRUE;
} }
if (rand2 > 0x3B) { else if (rand2 >= 60) {
flag = sub_8055864(pokemon,target,move_r6,0x28,param_4_r4) != 0 ? TRUE : FALSE; flag = (sub_8055864(pokemon,target,move,0x28,param_4) != 0);
return flag; return flag;
} }
else { else {
flag = sub_8055864(pokemon,target,move_r6,0x50,param_4_r4) != 0 ? TRUE : FALSE; flag = (sub_8055864(pokemon,target,move,0x50,param_4) != 0);
return flag; return flag;
} }
} }

View File

@ -759,7 +759,7 @@ void FrozenStatusTarget(Entity * pokemon, Entity * target, bool8 displayMessage)
} }
else else
{ {
if ((u8)(entityInfo->immobilize.immobilizeStatus - 3) <= 1) { if (entityInfo->immobilize.immobilizeStatus == STATUS_WRAP || entityInfo->immobilize.immobilizeStatus == STATUS_WRAPPED) {
sub_8076CB4(entityInfo->unk9C); sub_8076CB4(entityInfo->unk9C);
} }
sub_8041F08(target); sub_8041F08(target);
@ -781,8 +781,8 @@ void SqueezedStatusTarget(Entity * pokemon, Entity * target, s16 param_3, bool32
bool8 displayMessage_u8 = displayMessage; bool8 displayMessage_u8 = displayMessage;
if ((EntityExists(target)) && (!HasSafeguardStatus(pokemon,target,displayMessage_u8))) { if ((EntityExists(target)) && (!HasSafeguardStatus(pokemon,target,displayMessage_u8))) {
entityInfo = target->info; entityInfo = GetEntInfo(target);
if ((u8)(entityInfo->immobilize.immobilizeStatus - 3U) < 2) { if (entityInfo->immobilize.immobilizeStatus == STATUS_WRAP || entityInfo->immobilize.immobilizeStatus == STATUS_WRAPPED) {
sub_8076CB4(entityInfo->unk9C); sub_8076CB4(entityInfo->unk9C);
} }
else if (entityInfo->immobilize.immobilizeStatus == STATUS_INGRAIN) { else if (entityInfo->immobilize.immobilizeStatus == STATUS_INGRAIN) {
@ -811,8 +811,8 @@ void ImmobilizedStatusTarget(Entity * pokemon, Entity * target)
EntityInfo *entityInfo; EntityInfo *entityInfo;
if ((EntityExists(target)) && (!HasSafeguardStatus(pokemon,target,TRUE))) { if ((EntityExists(target)) && (!HasSafeguardStatus(pokemon,target,TRUE))) {
entityInfo = target->info; entityInfo = GetEntInfo(target);
if ((u8)(entityInfo->immobilize.immobilizeStatus - 3U) < 2) { if (entityInfo->immobilize.immobilizeStatus == STATUS_WRAP || entityInfo->immobilize.immobilizeStatus == STATUS_WRAPPED) {
sub_8076CB4(entityInfo->unk9C); sub_8076CB4(entityInfo->unk9C);
} }
else if (entityInfo->immobilize.immobilizeStatus == STATUS_INGRAIN) { else if (entityInfo->immobilize.immobilizeStatus == STATUS_INGRAIN) {
@ -838,19 +838,17 @@ void ImmobilizedStatusTarget(Entity * pokemon, Entity * target)
void IngrainedStatusTarget(Entity * pokemon, Entity * target) void IngrainedStatusTarget(Entity * pokemon, Entity * target)
{ {
EntityInfo *entityInfo; EntityInfo *entityInfo;
EntityInfo *entityInfo2;
if (EntityExists(target)) { if (EntityExists(target)) {
entityInfo = target->info; entityInfo = GetEntInfo(target);
entityInfo2 = entityInfo; if (entityInfo->immobilize.immobilizeStatus == STATUS_WRAP || entityInfo->immobilize.immobilizeStatus == STATUS_WRAPPED) {
if ((u8)(entityInfo->immobilize.immobilizeStatus - 3U) < 2) {
sub_8076CB4(entityInfo->unk9C); sub_8076CB4(entityInfo->unk9C);
} }
SetMessageArgument(gAvailablePokemonNames,target,0); SetMessageArgument(gAvailablePokemonNames,target,0);
if (entityInfo2->immobilize.immobilizeStatus != STATUS_INGRAIN) { if (entityInfo->immobilize.immobilizeStatus != STATUS_INGRAIN) {
entityInfo2->immobilize.immobilizeStatus = STATUS_INGRAIN; entityInfo->immobilize.immobilizeStatus = STATUS_INGRAIN;
entityInfo2->immobilize.immobilizeStatusTurns = CalculateStatusTurns(target,gUnknown_80F4E60,TRUE) + 1; entityInfo->immobilize.immobilizeStatusTurns = CalculateStatusTurns(target,gUnknown_80F4E60,TRUE) + 1;
entityInfo2->immobilize.immobilizeStatusDamageCountdown = 0; entityInfo->immobilize.immobilizeStatusDamageCountdown = 0;
nullsub_90(target); nullsub_90(target);
sub_80522F4(pokemon,target,*gUnknown_80FB6A4); sub_80522F4(pokemon,target,*gUnknown_80FB6A4);
} }

View File

@ -171,40 +171,24 @@ u8 GetMoveType(Move *move)
const u8 *GetLevelUpMoves(s16 species) const u8 *GetLevelUpMoves(s16 species)
{ {
#ifndef NONMATCHING s32 id = SpeciesId(species);
register s32 species1 asm("r1"), species2; if (species == MONSTER_DECOY || species == MONSTER_NONE)
#else return &gUnknown_810992B;
s32 species1, species2; if (id == MONSTER_MUNCHLAX)
#endif
species1 = species;
species2 = species1;
if (species1 == MONSTER_DECOY || species1 == MONSTER_NONE)
return &gUnknown_810992B; return &gUnknown_810992B;
if (species2 == MONSTER_MUNCHLAX) return sMoveLearnsets[id].levelUpMoves;
return &gUnknown_810992B;
return sMoveLearnsets[species2].levelUpMoves;
} }
const u8 *GetHMTMMoves(s16 species) const u8 *GetHMTMMoves(s16 species)
{ {
#ifndef NONMATCHING s32 id = SpeciesId(species);
register s32 species1 asm("r1"), species2; if (species == MONSTER_DECOY || species == MONSTER_NONE)
#else return &gUnknown_810992B;
s32 species1, species2; if (id == MONSTER_MUNCHLAX)
#endif
species1 = species;
species2 = species1;
if (species1 == MONSTER_DECOY || species1 == MONSTER_NONE)
return &gUnknown_810992B; return &gUnknown_810992B;
if (species2 == MONSTER_MUNCHLAX) return sMoveLearnsets[id].HMTMMoves;
return &gUnknown_810992B;
return sMoveLearnsets[species2].HMTMMoves;
} }
u8 GetMoveAIWeight(Move *move) u8 GetMoveAIWeight(Move *move)
@ -1325,15 +1309,7 @@ UNUSED static void RemoveLinkSequenceFromMoves8_v2(Move *moves, s32 index)
for (i = index + 1; i < 8; i++) { for (i = index + 1; i < 8; i++) {
Move* move = &moves[i]; Move* move = &moves[i];
if (!MoveFlagExists(move) || !(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN))
#ifndef NONMATCHING
asm("");
#endif
if (!(move->moveFlags & MOVE_FLAG_EXISTS))
break;
if (!(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN))
break; break;
move->moveFlags = 0; move->moveFlags = 0;
@ -1364,15 +1340,7 @@ void RemoveLinkSequenceFromMoves8(Move *moves, s32 index)
for (i = index + 1; i < 8; i++) { for (i = index + 1; i < 8; i++) {
Move* move = &moves[i]; Move* move = &moves[i];
if (!MoveFlagExists(move) || !(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN))
#ifndef NONMATCHING
asm("");
#endif
if (!(move->moveFlags & MOVE_FLAG_EXISTS))
break;
if (!(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN))
break; break;
move->moveFlags = 0; move->moveFlags = 0;
@ -1454,7 +1422,7 @@ static void unk_MovePrintData(Move *move, s32 y)
static void CopyAndResetMove(Move *dest, Move *src) static void CopyAndResetMove(Move *dest, Move *src)
{ {
if (src->moveFlags & MOVE_FLAG_EXISTS) { if (MoveFlagExists(src)) {
dest->moveFlags = src->moveFlags; dest->moveFlags = src->moveFlags;
dest->moveFlags2 = 0; dest->moveFlags2 = 0;
dest->id = src->id; dest->id = src->id;
@ -1465,26 +1433,23 @@ static void CopyAndResetMove(Move *dest, Move *src)
dest->moveFlags = 0; dest->moveFlags = 0;
} }
void CopyAndResetMoves(Move *destMoves, Move *srcMoves) void CopyAndResetMoves(Moves *destMoves, Move *srcMoves)
{ {
s32 i; s32 i;
for (i = 0; i < MAX_MON_MOVES; i++) { for (i = 0; i < MAX_MON_MOVES; i++) {
if (srcMoves[i].moveFlags & 1) { if (MoveFlagExists(&srcMoves[i])) {
destMoves[i].moveFlags = srcMoves[i].moveFlags; destMoves->moves[i].moveFlags = srcMoves[i].moveFlags;
destMoves[i].moveFlags2 = 0; destMoves->moves[i].moveFlags2 = 0;
destMoves[i].id = srcMoves[i].id; destMoves->moves[i].id = srcMoves[i].id;
destMoves[i].PP = sMovesData[srcMoves[i].id].basePP; destMoves->moves[i].PP = sMovesData[srcMoves[i].id].basePP;
destMoves[i].ginseng = srcMoves[i].PP; // This seems horribly bugged destMoves->moves[i].ginseng = srcMoves[i].PP; // This seems horribly bugged
} }
else else
destMoves[i].moveFlags = 0; destMoves->moves[i].moveFlags = 0;
} }
// possibly destMoves is not just an array and this is the destMoves->struggleMoveFlags = 0;
// next struct field
// this index would be out of bounds after all
destMoves[MAX_MON_MOVES].moveFlags = 0;
} }
void CopyBareMoveData(Move *destMoves, Move *srcMoves) void CopyBareMoveData(Move *destMoves, Move *srcMoves)

View File

@ -583,7 +583,7 @@ void xxx_pokemonstruct_to_pokemon2_808DE50(PokemonStruct2 * a1, PokemonStruct1 *
} }
a1->currExp = pokemon->currExp; a1->currExp = pokemon->currExp;
CopyAndResetMoves(a1->moves.moves, pokemon->moves); CopyAndResetMoves(&a1->moves, pokemon->moves);
for (i = 0; i < POKEMON_NAME_LENGTH; i++) { for (i = 0; i < POKEMON_NAME_LENGTH; i++) {
a1->name[i] = pokemon->name[i]; a1->name[i] = pokemon->name[i];

View File

@ -45,18 +45,18 @@ bool8 CreateHelperPelipperMenu(s16 speciesID)
OpenedFile *faceFile; OpenedFile *faceFile;
s32 species_32; s32 species_32;
species_32 = speciesID; species_32 = SpeciesId(speciesID);
ResetUnusedInputStruct(); ResetUnusedInputStruct();
xxx_call_save_unk_text_struct_800641C(NULL, TRUE, TRUE); xxx_call_save_unk_text_struct_800641C(NULL, TRUE, TRUE);
sPostOfficeHelper = MemoryAlloc(sizeof(PostOfficeWork), 8); sPostOfficeHelper = MemoryAlloc(sizeof(PostOfficeWork), 8);
CopyYellowMonsterNametoBuffer(gUnknown_202E5D8, speciesID); CopyYellowMonsterNametoBuffer(gUnknown_202E5D8, species_32);
monName = GetMonSpecies(speciesID); monName = GetMonSpecies(species_32);
strcpy(gAvailablePokemonNames, monName); strcpy(gAvailablePokemonNames, monName);
sPostOfficeHelper->faceFile = NULL; sPostOfficeHelper->faceFile = NULL;
sPostOfficeHelper->faceData = NULL; sPostOfficeHelper->faceData = NULL;
if (speciesID != MONSTER_NONE) { if (species_32 != MONSTER_NONE) {
faceFile = GetDialogueSpriteDataPtr(species_32); faceFile = GetDialogueSpriteDataPtr(species_32);
sPostOfficeHelper->faceFile = faceFile; sPostOfficeHelper->faceFile = faceFile;
sPostOfficeHelper->unk14 = 0; sPostOfficeHelper->unk14 = 0;

View File

@ -1092,8 +1092,7 @@ void SnatchStatusTarget(Entity * pokemon, Entity * target)
{ {
Entity * entity; Entity * entity;
s32 index; s32 index;
EntityInfo * targetEntityInfo; EntityInfo *targetEntityInfo;
EntityInfo * targetEntityInfo2;
if (EntityExists(target)) { if (EntityExists(target)) {
SendWaitingEndMessage(pokemon,target,STATUS_SNATCH); SendWaitingEndMessage(pokemon,target,STATUS_SNATCH);
@ -1107,8 +1106,7 @@ void SnatchStatusTarget(Entity * pokemon, Entity * target)
} }
nullsub_81(target); nullsub_81(target);
targetEntityInfo = target->info; targetEntityInfo = GetEntInfo(target);
targetEntityInfo2 = targetEntityInfo;
if (targetEntityInfo->waitingStruct.waitingStatus != STATUS_SNATCH) { if (targetEntityInfo->waitingStruct.waitingStatus != STATUS_SNATCH) {
targetEntityInfo->waitingStruct.waitingStatus = STATUS_SNATCH; targetEntityInfo->waitingStruct.waitingStatus = STATUS_SNATCH;
targetEntityInfo->waitingStruct.waitingStatusTurns= CalculateStatusTurns(target,gUnknown_80F4EA8,FALSE) + 1; targetEntityInfo->waitingStruct.waitingStatusTurns= CalculateStatusTurns(target,gUnknown_80F4EA8,FALSE) + 1;
@ -1116,7 +1114,7 @@ void SnatchStatusTarget(Entity * pokemon, Entity * target)
} }
gDungeon->snatchPokemon = target; gDungeon->snatchPokemon = target;
gDungeon->unk17B3C = targetEntityInfo2->unk98; gDungeon->unk17B3C = targetEntityInfo->unk98;
SetMessageArgument(gAvailablePokemonNames,target,0); SetMessageArgument(gAvailablePokemonNames,target,0);
sub_80522F4(pokemon,target,*gUnknown_80FB01C); sub_80522F4(pokemon,target,*gUnknown_80FB01C);
EntityUpdateStatusSprites(target); EntityUpdateStatusSprites(target);

View File

@ -159,41 +159,28 @@ extern struct NaturePowerMove gUnknown_80F59C8[10];
bool8 sub_805AFA4(Entity * pokemon, Entity * target, Move *move, u32 param_4) bool8 sub_805AFA4(Entity * pokemon, Entity * target, Move *move, u32 param_4)
{ {
s32 r0;
s32 r2;
s32 r1;
bool8 flag;
#ifndef NONMATCHING
register EntityInfo *entityInfo asm("r3");
#else
EntityInfo *entityInfo; EntityInfo *entityInfo;
#endif s32 maxHp;
s32 index;
bool8 flag;
SendThawedMessage(pokemon, target); SendThawedMessage(pokemon, target);
entityInfo = pokemon->info;
r2 = entityInfo->maxHPStat; entityInfo = GetEntInfo(pokemon);
r0 = r2; maxHp = entityInfo->maxHPStat;
if (r2 < 0) { if (entityInfo->HP <= entityInfo->maxHPStat / 4) {
r0 = r2 + 3; index = 0;
} }
if (entityInfo->HP <= r0 >> 2) { else if (entityInfo->HP <= maxHp / 2) {
r2 = 0; index = 1;
} }
else if (r1 = entityInfo->HP, r1 <= r2 / 2) { else if (entityInfo->HP <= (maxHp * 3) / 4) {
r2 = 1; index = 2;
} }
else else {
{ index = 3;
r0 = r2 * 3;
if (r0 < 0) {
r0 = r0 + 3;
} }
if (r0 >>= 2, r2 = 3, r1 <= r0) {
r2 = 2; flag = sub_8055640(pokemon,target,move,gUnknown_80F51C4[index],param_4) ? TRUE : FALSE;
}
}
flag = sub_8055640(pokemon,target,move,gUnknown_80F51C4[r2],param_4) ? TRUE : FALSE;
return flag; return flag;
} }
@ -428,9 +415,7 @@ bool8 sub_805B3FC(Entity * pokemon,Entity * target,Move *move, s32 param_4, s32
if (sub_805727C(pokemon,pokemon,gUnknown_80F4DCE) != 0) { if (sub_805727C(pokemon,pokemon,gUnknown_80F4DCE) != 0) {
entityInfo = pokemon->info; entityInfo = pokemon->info;
RaiseAttackStageTarget(pokemon,pokemon,param_4,1); RaiseAttackStageTarget(pokemon,pokemon,param_4,1);
if (entityInfo->unkFB == 0) { SetExpMultplier(entityInfo);
entityInfo->unkFB = 1;
}
} }
} }
return flag; return flag;
@ -469,9 +454,7 @@ bool8 MimicMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4
} }
SetMessageArgument(gAvailablePokemonNames,pokemon,0); SetMessageArgument(gAvailablePokemonNames,pokemon,0);
if (moveCounter != 0) { if (moveCounter != 0) {
if (entityInfo->unkFB == 0) { SetExpMultplier(entityInfo);
entityInfo->unkFB = 1;
}
sub_80522F4(pokemon,target,*gUnknown_80FDCE4); sub_80522F4(pokemon,target,*gUnknown_80FDCE4);
mimicSuccess = TRUE; mimicSuccess = TRUE;
} }
@ -513,9 +496,7 @@ _0805B598:
bool8 LeechSeedMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) bool8 LeechSeedMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4)
{ {
HandleLeechSeed(pokemon, target, TRUE); HandleLeechSeed(pokemon, target, TRUE);
if (pokemon->info->unkFB == 0) { SetExpMultplier(GetEntInfo(pokemon));
pokemon->info->unkFB = 1;
}
return TRUE; return TRUE;
} }
@ -550,9 +531,7 @@ bool8 sub_805B668(Entity * pokemon, Entity * target, Move *move, s32 param_4)
newHP = 1; newHP = 1;
} }
if (sub_8057308(pokemon,0) != 0) { if (sub_8057308(pokemon,0) != 0) {
if (pokemon->info->unkFB == 0) { SetExpMultplier(GetEntInfo(pokemon));
pokemon->info->unkFB = 1;
}
if (sub_8057308(pokemon,0) != 0) { if (sub_8057308(pokemon,0) != 0) {
if (hasLiquidOoze) { if (hasLiquidOoze) {
DealDamageToEntity(pokemon,newHP,0xd,0x1fa); DealDamageToEntity(pokemon,newHP,0xd,0x1fa);
@ -578,35 +557,28 @@ bool8 SnatchMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_
bool8 RecycleMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) bool8 RecycleMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4)
{ {
Item *item; s32 i;
s32 index; EntityInfo *entityInfo = GetEntInfo(target);
EntityInfo *entityInfo; bool32 isTMRecycled = FALSE;
bool8 isTMRecycled;
entityInfo = target->info;
isTMRecycled = FALSE;
if (!entityInfo->isNotTeamMember) { if (!entityInfo->isNotTeamMember) {
for(index = 0; index < INVENTORY_SIZE; index++) for(i = 0; i < INVENTORY_SIZE; i++)
{ {
#ifdef NONMATCHING if (ItemExists(&gTeamInventoryRef->teamItems[i]) && !ItemInShop(&gTeamInventoryRef->teamItems[i]))
item = &gTeamInventoryRef->teamItems[index]; {
#else Item *item = &gTeamInventoryRef->teamItems[i];
register size_t offset asm("r1") = offsetof(TeamInventory, teamItems[index]); if (item->id == ITEM_TM_USED_TM) {
Item* p = gTeamInventoryRef->teamItems;
size_t addr = offset + (size_t)p;
item = (Item*)addr;
#endif
if ((item->flags & ITEM_FLAG_EXISTS) && ((item->flags & ITEM_FLAG_IN_SHOP) == 0))
if(item->id == ITEM_TM_USED_TM) {
xxx_init_itemslot_8090A8C(item, item->quantity + 0x7d,0); xxx_init_itemslot_8090A8C(item, item->quantity + 0x7d,0);
isTMRecycled = TRUE; isTMRecycled = TRUE;
} }
} }
if ((entityInfo->heldItem.flags & ITEM_FLAG_EXISTS) && (entityInfo->heldItem.id == ITEM_TM_USED_TM)) { }
if (ItemExists(&entityInfo->heldItem) && (entityInfo->heldItem.id == ITEM_TM_USED_TM)) {
xxx_init_itemslot_8090A8C(&entityInfo->heldItem,entityInfo->heldItem.quantity + 0x7D,0); xxx_init_itemslot_8090A8C(&entityInfo->heldItem,entityInfo->heldItem.quantity + 0x7D,0);
isTMRecycled = TRUE; isTMRecycled = TRUE;
} }
} }
if (isTMRecycled) { if (isTMRecycled) {
sub_80522F4(pokemon,target,*gUnknown_80FDC9C); // The Used TM was recharged! sub_80522F4(pokemon,target,*gUnknown_80FDC9C); // The Used TM was recharged!
} }
@ -695,29 +667,21 @@ bool8 sub_805B968(Entity * pokemon, Entity * target, Move * move, s32 param_4)
bool8 RockSmashMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) bool8 RockSmashMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4)
{ {
bool8 flag;
Position pos; Position pos;
bool8 flag = FALSE;
#ifdef NONMATCHING
Entity *temp;
Entity *temp1;
#else
register Entity *temp asm("r5");
register Entity *temp1 asm("r4");
#endif
temp = pokemon;
temp1 = target;
flag = 0;
if (sub_8069D18(&pos) != 0) { if (sub_8069D18(&pos) != 0) {
sub_80522F4(temp,temp1,*gUnknown_80FD430); // Can't use that diagonally! sub_80522F4(pokemon,target,*gUnknown_80FD430); // Can't use that diagonally!
}
else if (flag = (sub_804AD34(&pos)), flag != 0) {
sub_80522F4(temp,temp1,*gUnknown_80FD3F0); // It dug the wall in front!
} }
else { else {
sub_80522F4(temp,temp1,*gUnknown_80FD40C); // Can't use that here! ASM_MATCH_TRICK(target);
flag = sub_804AD34(&pos);
if (flag) {
sub_80522F4(pokemon,target,*gUnknown_80FD3F0); // It dug the wall in front!
}
else {
sub_80522F4(pokemon,target,*gUnknown_80FD40C); // Can't use that here!
}
} }
return flag; return flag;
} }
@ -768,14 +732,10 @@ bool8 sub_805BA50(Entity * pokemon, Entity * target, Move *move, s32 param_4)
} }
else { else {
iVar3->heldItem = iVar6->heldItem; iVar3->heldItem = iVar6->heldItem;
targetItem->id = ITEM_NOTHING; ZeroOutItem(targetItem);
targetItem->quantity = 0;
targetItem->flags = 0;
sub_806A6E8(pokemon); sub_806A6E8(pokemon);
sub_806A6E8(target); sub_806A6E8(target);
if (iVar3->unkFB == 0) { SetExpMultplier(iVar3);
iVar3->unkFB = 1;
}
sub_80522F4(pokemon,target,*gUnknown_80FC614); // Got $m1's item! sub_80522F4(pokemon,target,*gUnknown_80FC614); // Got $m1's item!
} }
} }
@ -792,10 +752,7 @@ bool8 ReboundOrbAction(Entity * pokemon, Entity * target, Move *move, s32 param_
bool8 sub_805BB74(Entity * pokemon, Entity * target, Move *move, s32 param_4) bool8 sub_805BB74(Entity * pokemon, Entity * target, Move *move, s32 param_4)
{ {
if(pokemon->info->unkFB == 0) SetExpMultplier(GetEntInfo(pokemon));
{
pokemon->info->unkFB = 1;
}
sub_807E254(pokemon, target, 1); sub_807E254(pokemon, target, 1);
return TRUE; return TRUE;
} }
@ -808,43 +765,33 @@ bool8 sub_805BB98(Entity * pokemon, Entity * target, Move *move, s32 param_4)
bool8 CleanseOrbAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) bool8 CleanseOrbAction(Entity * pokemon, Entity * target, Move *move, s32 param_4)
{ {
Item *item; s32 i;
Entity *entity; EntityInfo *entityInfo = GetEntInfo(target);
EntityInfo *entityInfo; bool32 isItemCleaned = FALSE;
s32 index;
bool8 isItemCleaned;
#ifdef NONMATCHING
u8 flag;
#else
register u8 flag asm("r2");
#endif
entityInfo = target->info;
isItemCleaned = FALSE;
if (!entityInfo->isNotTeamMember) { if (!entityInfo->isNotTeamMember) {
for(index = 0; index < INVENTORY_SIZE; index++){ for(i = 0; i < INVENTORY_SIZE; i++){
// WTF why does this work... if (ItemExists(&gTeamInventoryRef->teamItems[i])
UNUSED Item* current = &gTeamInventoryRef->teamItems[index]; && !ItemInShop(&gTeamInventoryRef->teamItems[i])
flag = index[gTeamInventoryRef->teamItems].flags; && ItemSticky(&gTeamInventoryRef->teamItems[i]))
if (((flag & ITEM_FLAG_EXISTS) != 0) && ((flag & ITEM_FLAG_IN_SHOP) == 0))
if((flag & ITEM_FLAG_STICKY) != 0) {
gTeamInventoryRef->teamItems[index].flags = flag & 0xf7;
isItemCleaned = TRUE;
}
}
for(index = 0; index < MAX_TEAM_MEMBERS; index++)
{ {
entity = gDungeon->teamPokemon[index]; gTeamInventoryRef->teamItems[i].flags &= ~(ITEM_FLAG_STICKY);
isItemCleaned = TRUE;
}
}
for(i = 0; i < MAX_TEAM_MEMBERS; i++)
{
Entity *entity = gDungeon->teamPokemon[i];
if (EntityExists(entity)) { if (EntityExists(entity)) {
item = &entity->info->heldItem; Item *item = &GetEntInfo(entity)->heldItem;
if (((item->flags & ITEM_FLAG_EXISTS) != 0) && ((item->flags & ITEM_FLAG_STICKY) != 0)) { if (ItemExists(item) && ItemSticky(item)) {
item->flags &= 0xf7; item->flags &= ~(ITEM_FLAG_STICKY);
isItemCleaned = TRUE; isItemCleaned = TRUE;
} }
} }
} }
} }
if (isItemCleaned) { if (isItemCleaned) {
sub_80522F4(pokemon,target,*gUnknown_80FC8F0); sub_80522F4(pokemon,target,*gUnknown_80FC8F0);
} }

View File

@ -179,14 +179,13 @@ bool8 IsSleeping(Entity *pokemon)
bool8 HasLowHealth(Entity *pokemon) bool8 HasLowHealth(Entity *pokemon)
{ {
EntityInfo *pokemonInfo = pokemon->info; EntityInfo *pokemonInfo = GetEntInfo(pokemon);
EntityInfo *pokemonInfo2 = pokemon->info;
s32 maxHPStat = pokemonInfo->maxHPStat; s32 maxHPStat = pokemonInfo->maxHPStat;
if (maxHPStat < 0) if (maxHPStat < 0)
{ {
maxHPStat += 3; maxHPStat += 3;
} }
if (pokemonInfo2->HP <= maxHPStat >> 2) if (pokemonInfo->HP <= maxHPStat >> 2)
{ {
return TRUE; return TRUE;
} }

View File

@ -407,7 +407,7 @@ void HandleStickyTrap(Entity *pokemon,Entity *target)
int newIndex; int newIndex;
Item *itemStack[21]; Item *itemStack[21];
info = target->info; info = GetEntInfo(target);
if (HasHeldItem(target,0xe)) { if (HasHeldItem(target,0xe)) {
sub_80522F4(pokemon,target,*gUnknown_80FDC7C); sub_80522F4(pokemon,target,*gUnknown_80FDC7C);
} }
@ -416,19 +416,16 @@ void HandleStickyTrap(Entity *pokemon,Entity *target)
itemCount = 0; itemCount = 0;
if (info->isTeamLeader) { if (info->isTeamLeader) {
for (index = 0; index < INVENTORY_SIZE; index++) { for (index = 0; index < INVENTORY_SIZE; index++) {
struct Item *items; if (ItemExists(&gTeamInventoryRef->teamItems[index]) && IsNotSpecialItem(gTeamInventoryRef->teamItems[index].id)) {
DUMMY_TEAM_ITEMS_ASM_MATCH(index); Item *item = &gTeamInventoryRef->teamItems[index];
if (!ItemSticky(item)) {
items = gTeamInventoryRef->teamItems; itemStack[itemCount] = item;
if ((items[index].flags & ITEM_FLAG_EXISTS)
&& IsNotSpecialItem(items[index].id)
&& !(gTeamInventoryRef->teamItems[index].flags & ITEM_FLAG_STICKY)) {
itemStack[itemCount] = &gTeamInventoryRef->teamItems[index];
itemCount++; itemCount++;
} }
} }
} }
if ((info->heldItem.flags & ITEM_FLAG_EXISTS) && IsNotSpecialItem((info->heldItem).id) && !(info->heldItem.flags & ITEM_FLAG_STICKY)) { }
if (ItemExists(&info->heldItem) && IsNotSpecialItem((info->heldItem).id) && !ItemSticky(&info->heldItem)) {
itemStack[itemCount] = &info->heldItem; itemStack[itemCount] = &info->heldItem;
itemCount++; itemCount++;
} }

View File

@ -382,7 +382,7 @@ void SaveEntity(unkStruct_8094924 *param_1, Entity *param_2)
pbStack_50 = &info->stairSpotter; pbStack_50 = &info->stairSpotter;
puStack_4c = &info->unkF3; puStack_4c = &info->unkF3;
pbStack_48 = &info->grudge; pbStack_48 = &info->grudge;
puStack_34 = &info->unkFB; puStack_34 = &info->expMultiplier;
pbStack_44 = &info->exposed; pbStack_44 = &info->exposed;
pbStack_40 = &info->isColorChanged; pbStack_40 = &info->isColorChanged;
pbStack_3c = &info->bossFlag; pbStack_3c = &info->bossFlag;

View File

@ -433,28 +433,8 @@ gUnknown_202F224: /* 202F224 (sub_8040DA0 - sub_805B264) */
gUnknown_202F228: /* 202F228 (sub_8055FA0 - sub_805B618) */ gUnknown_202F228: /* 202F228 (sub_8055FA0 - sub_805B618) */
.space 0x4 .space 0x4
gUnknown_202F22C: /* 202F22C (sub_805D8C8 - sub_805E2C4) */ .include "src/code_805D8C8_1.o"
.space 0x1
gUnknown_202F22D: /* 202F22D (sub_805D8C8 - sub_805E2C4) */
.space 0x1
gUnknown_202F22E: /* 202F22E (sub_805D8C8 - sub_805E2C4) */
.space 0x2
gUnknown_202F230: /* 202F230 (sub_805D8C8 - sub_805E2C4) */
.space 0x1
gUnknown_202F231: /* 202F231 (sub_805D8C8 - sub_805E2C4) */
.space 0x7
gUnknown_202F238: /* 202F238 (sub_805FD74 - sub_8060CE8) */
.space 0x8
gUnknown_202F240: /* 202F240 (sub_805FD74 - CreateFieldItemMenu) */
.space 0x8
gUnknown_202F248: /* 202F248 (sub_805FD74 - sub_8060890) */
.space 0x10
gUnknown_202F258: /* 202F258 (sub_805FD74 - sub_8060800) */
.space 0x8
gUnknown_202F260: /* 202F260 (ShowFieldMenu - DrawFieldTeamMenu) */
.space 0x8
gUnknown_202F268: /* 202F268 (sub_8062500) */ gUnknown_202F268: /* 202F268 (sub_8062500) */
.space 0x8 .space 0x8
gUnknown_202F270: /* 202F270 (sub_8060E38 - sub_8061A38) */ gUnknown_202F270: /* 202F270 (sub_8060E38 - sub_8061A38) */