mirror of
https://github.com/pret/pmd-red.git
synced 2026-08-26 02:34:33 -05:00
Fix nonmatchings in trap.c
This commit is contained in:
261
src/trap.c
261
src/trap.c
@@ -384,223 +384,72 @@ void sub_807FE9C(Entity *pokemon, Position *pos, int param_3, char param_4)
|
||||
|
||||
void HandleMudTrap(Entity *pokemon, Entity *target)
|
||||
{
|
||||
int rand;
|
||||
#ifdef NONMATCHING
|
||||
int rand1;
|
||||
#else
|
||||
register int rand1 asm("r1");
|
||||
#endif
|
||||
int rand, randDef;
|
||||
|
||||
if (target != NULL) {
|
||||
rand1 = rand = DungeonRandInt(100);
|
||||
if (rand <= 0x18) {
|
||||
LowerAttackStageTarget(pokemon,target,gUnknown_8106A4C,1,1,1);
|
||||
}
|
||||
else if (0x32 > rand) {
|
||||
LowerAttackStageTarget(pokemon,target,gUnknown_8106A50,1,1,1);
|
||||
}
|
||||
else if (rand1 < 0x4b) {
|
||||
LowerDefenseStageTarget(pokemon,target,gUnknown_8106A4C,1,1,1);
|
||||
}
|
||||
else {
|
||||
LowerDefenseStageTarget(pokemon,target,gUnknown_8106A50,1,1,1);
|
||||
}
|
||||
if (target == NULL)
|
||||
return;
|
||||
|
||||
rand = DungeonRandInt(100);
|
||||
randDef = rand;
|
||||
if (rand < 25) {
|
||||
LowerAttackStageTarget(pokemon,target,gUnknown_8106A4C,1,1,1);
|
||||
}
|
||||
else if (rand < 50) {
|
||||
LowerAttackStageTarget(pokemon,target,gUnknown_8106A50,1,1,1);
|
||||
}
|
||||
else if (randDef < 75) {
|
||||
LowerDefenseStageTarget(pokemon,target,gUnknown_8106A4C,1,1,1);
|
||||
}
|
||||
else {
|
||||
LowerDefenseStageTarget(pokemon,target,gUnknown_8106A50,1,1,1);
|
||||
}
|
||||
}
|
||||
|
||||
// https://decomp.me/scratch/Yq32k (Seth)
|
||||
|
||||
#ifdef NONMATCHING
|
||||
void HandleStickyTrap(Entity *pokemon,Entity *target)
|
||||
{
|
||||
EntityInfo *info;
|
||||
Item *item;
|
||||
Item *pbVar3;
|
||||
int index;
|
||||
int itemCount;
|
||||
int newIndex;
|
||||
Item *itemStack [20];
|
||||
bool32 flag;
|
||||
EntityInfo *info;
|
||||
int index;
|
||||
int itemCount;
|
||||
int newIndex;
|
||||
Item *itemStack[21];
|
||||
|
||||
info = target->info;
|
||||
if (HasHeldItem(target,0xe)) {
|
||||
sub_80522F4(pokemon,target,*gUnknown_80FDC7C);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemCount = 0;
|
||||
if (flag = info->isTeamLeader, item = &info->heldItem, flag != '\0') {
|
||||
for(index = 0; index < 0x14; index++)
|
||||
{
|
||||
pbVar3 = &gTeamInventoryRef->teamItems[index];
|
||||
if ((((pbVar3->flags & 1) != 0) && (IsNotSpecialItem(pbVar3->id))) &&
|
||||
(gTeamInventoryRef->teamItems[index].flags & 8) == 0) {
|
||||
itemStack[itemCount] = pbVar3;
|
||||
itemCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((((item->flags & 1) != 0) && (IsNotSpecialItem((info->heldItem).id)))
|
||||
&& ((item->flags & 8) == 0)) {
|
||||
itemStack[itemCount] = item;
|
||||
itemCount = itemCount + 1;
|
||||
}
|
||||
if (itemCount == 0) {
|
||||
sub_80522F4(pokemon,target,*gUnknown_80FDC40);
|
||||
info = target->info;
|
||||
if (HasHeldItem(target,0xe)) {
|
||||
sub_80522F4(pokemon,target,*gUnknown_80FDC7C);
|
||||
}
|
||||
else
|
||||
{
|
||||
newIndex = DungeonRandInt(itemCount);
|
||||
sub_8045BF8(gUnknown_202DE58, itemStack[newIndex]);
|
||||
itemStack[newIndex]->flags |= 8;
|
||||
sub_80421C0(target, 0x192);
|
||||
sub_80522F4(pokemon,target,*gUnknown_80FDC18);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
NAKED
|
||||
void HandleStickyTrap(Entity *pokemon,Entity *target)
|
||||
{
|
||||
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, 0x5C\n"
|
||||
"\tstr r0, [sp, 0x54]\n"
|
||||
"\tmov r10, r1\n"
|
||||
"\tldr r0, [r1, 0x70]\n"
|
||||
"\tmov r8, r0\n"
|
||||
"\tmov r0, r10\n"
|
||||
"\tmovs r1, 0xE\n"
|
||||
"\tbl HasHeldItem\n"
|
||||
"\tlsls r0, 24\n"
|
||||
"\tcmp r0, 0\n"
|
||||
"\tbeq _08080278\n"
|
||||
"\tldr r0, _08080274\n"
|
||||
"\tb _08080300\n"
|
||||
"\t.align 2, 0\n"
|
||||
"_08080274: .4byte gUnknown_80FDC7C\n"
|
||||
"_08080278:\n"
|
||||
"\tmovs r6, 0\n"
|
||||
"\tmov r1, r8\n"
|
||||
"\tldrb r0, [r1, 0x7]\n"
|
||||
"\tmovs r1, 0x60\n"
|
||||
"\tadd r1, r8\n"
|
||||
"\tmov r9, r1\n"
|
||||
"\tcmp r0, 0\n"
|
||||
"\tbeq _080802C8\n"
|
||||
"\tmovs r5, 0\n"
|
||||
"\tldr r7, _0808030C\n"
|
||||
"\tmov r0, sp\n"
|
||||
"\tstr r0, [sp, 0x58]\n"
|
||||
"_08080290:\n"
|
||||
"\tlsls r4, r5, 2\n"
|
||||
"\tldr r0, [r7]\n"
|
||||
"\tadds r2, r4, r0\n"
|
||||
"\tldrb r1, [r2]\n"
|
||||
"\tmovs r0, 0x1\n"
|
||||
"\tands r0, r1\n"
|
||||
"\tcmp r0, 0\n"
|
||||
"\tbeq _080802C2\n"
|
||||
"\tldrb r0, [r2, 0x2]\n"
|
||||
"\tbl IsNotSpecialItem\n"
|
||||
"\tlsls r0, 24\n"
|
||||
"\tcmp r0, 0\n"
|
||||
"\tbeq _080802C2\n"
|
||||
"\tldr r0, [r7]\n"
|
||||
"\tadds r2, r0, r4\n"
|
||||
"\tldrb r1, [r2]\n"
|
||||
"\tmovs r0, 0x8\n"
|
||||
"\tands r0, r1\n"
|
||||
"\tcmp r0, 0\n"
|
||||
"\tbne _080802C2\n"
|
||||
"\tldr r1, [sp, 0x58]\n"
|
||||
"\tstm r1!, {r2}\n"
|
||||
"\tstr r1, [sp, 0x58]\n"
|
||||
"\tadds r6, 0x1\n"
|
||||
"_080802C2:\n"
|
||||
"\tadds r5, 0x1\n"
|
||||
"\tcmp r5, 0x13\n"
|
||||
"\tble _08080290\n"
|
||||
"_080802C8:\n"
|
||||
"\tmov r0, r9\n"
|
||||
"\tldrb r1, [r0]\n"
|
||||
"\tmovs r0, 0x1\n"
|
||||
"\tands r0, r1\n"
|
||||
"\tcmp r0, 0\n"
|
||||
"\tbeq _080802FA\n"
|
||||
"\tmov r0, r8\n"
|
||||
"\tadds r0, 0x62\n"
|
||||
"\tldrb r0, [r0]\n"
|
||||
"\tbl IsNotSpecialItem\n"
|
||||
"\tlsls r0, 24\n"
|
||||
"\tcmp r0, 0\n"
|
||||
"\tbeq _080802FA\n"
|
||||
"\tmov r0, r9\n"
|
||||
"\tldrb r1, [r0]\n"
|
||||
"\tmovs r0, 0x8\n"
|
||||
"\tands r0, r1\n"
|
||||
"\tcmp r0, 0\n"
|
||||
"\tbne _080802FA\n"
|
||||
"\tlsls r0, r6, 2\n"
|
||||
"\tadd r0, sp\n"
|
||||
"\tmov r1, r9\n"
|
||||
"\tstr r1, [r0]\n"
|
||||
"\tadds r6, 0x1\n"
|
||||
"_080802FA:\n"
|
||||
"\tcmp r6, 0\n"
|
||||
"\tbne _08080314\n"
|
||||
"\tldr r0, _08080310\n"
|
||||
"_08080300:\n"
|
||||
"\tldr r2, [r0]\n"
|
||||
"\tldr r0, [sp, 0x54]\n"
|
||||
"\tmov r1, r10\n"
|
||||
"\tbl sub_80522F4\n"
|
||||
"\tb _0808034A\n"
|
||||
"\t.align 2, 0\n"
|
||||
"_0808030C: .4byte gTeamInventoryRef\n"
|
||||
"_08080310: .4byte gUnknown_80FDC40\n"
|
||||
"_08080314:\n"
|
||||
"\tadds r0, r6, 0\n"
|
||||
"\tbl DungeonRandInt\n"
|
||||
"\tldr r2, _0808035C\n"
|
||||
"\tlsls r0, 2\n"
|
||||
"\tmov r1, sp\n"
|
||||
"\tadds r4, r1, r0\n"
|
||||
"\tldr r1, [r4]\n"
|
||||
"\tadds r0, r2, 0\n"
|
||||
"\tbl sub_8045BF8\n"
|
||||
"\tldr r2, [r4]\n"
|
||||
"\tldrb r1, [r2]\n"
|
||||
"\tmovs r0, 0x8\n"
|
||||
"\torrs r0, r1\n"
|
||||
"\tstrb r0, [r2]\n"
|
||||
"\tmovs r1, 0xC9\n"
|
||||
"\tlsls r1, 1\n"
|
||||
"\tmov r0, r10\n"
|
||||
"\tbl sub_80421C0\n"
|
||||
"\tldr r0, _08080360\n"
|
||||
"\tldr r2, [r0]\n"
|
||||
"\tldr r0, [sp, 0x54]\n"
|
||||
"\tmov r1, r10\n"
|
||||
"\tbl sub_80522F4\n"
|
||||
"_0808034A:\n"
|
||||
"\tadd sp, 0x5C\n"
|
||||
"\tpop {r3-r5}\n"
|
||||
"\tmov r8, r3\n"
|
||||
"\tmov r9, r4\n"
|
||||
"\tmov r10, r5\n"
|
||||
"\tpop {r4-r7}\n"
|
||||
"\tpop {r0}\n"
|
||||
"\tbx r0\n"
|
||||
"\t.align 2, 0\n"
|
||||
"_0808035C: .4byte gUnknown_202DE58\n"
|
||||
"_08080360: .4byte gUnknown_80FDC18");
|
||||
itemCount = 0;
|
||||
if (info->isTeamLeader) {
|
||||
for (index = 0; index < 20; index++) {
|
||||
// Matching shenanigans. The unused variable is NEEDED to match.
|
||||
UNUSED struct Item *currItem = &gTeamInventoryRef->teamItems[index];
|
||||
struct Item *items = gTeamInventoryRef->teamItems;
|
||||
if ((items[index].flags & 1)
|
||||
&& IsNotSpecialItem(items[index].id)
|
||||
&& !(gTeamInventoryRef->teamItems[index].flags & 8)) {
|
||||
itemStack[itemCount] = &gTeamInventoryRef->teamItems[index];
|
||||
itemCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((info->heldItem.flags & 1) && IsNotSpecialItem((info->heldItem).id) && !(info->heldItem.flags & 8)) {
|
||||
itemStack[itemCount] = &info->heldItem;
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
if (itemCount == 0) {
|
||||
sub_80522F4(pokemon,target,*gUnknown_80FDC40);
|
||||
}
|
||||
else {
|
||||
newIndex = DungeonRandInt(itemCount);
|
||||
sub_8045BF8(gUnknown_202DE58, itemStack[newIndex]);
|
||||
itemStack[newIndex]->flags |= 8;
|
||||
sub_80421C0(target, 0x192);
|
||||
sub_80522F4(pokemon,target,*gUnknown_80FDC18);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void HandleSpinTrap(Entity *pokemon, Entity *target)
|
||||
{
|
||||
@@ -804,7 +653,7 @@ void HandlePPZeroTrap(Entity *param_1,Entity *param_2)
|
||||
Move *moveStack [MAX_MON_MOVES];
|
||||
s32 indexStack [MAX_MON_MOVES];
|
||||
bool8 flag = FALSE;
|
||||
|
||||
|
||||
|
||||
if (param_2 != NULL) {
|
||||
info = param_2->info;
|
||||
|
||||
Reference in New Issue
Block a user