From 951acc8c31029327775e90e21ba6c92c24ff8b3b Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 16 Sep 2017 21:29:04 -0400 Subject: [PATCH] CheckForCollisionBetweenFieldObjects --- asm/field_map_obj.s | 68 ----------------------------------- include/field_ground_effect.h | 1 + src/field_map_obj.c | 22 ++++++++++++ 3 files changed, 23 insertions(+), 68 deletions(-) diff --git a/asm/field_map_obj.s b/asm/field_map_obj.s index 7ad4c2818..58060b539 100755 --- a/asm/field_map_obj.s +++ b/asm/field_map_obj.s @@ -5,74 +5,6 @@ .text - thumb_func_start CheckForCollisionBetweenFieldObjects -@ bool8 CheckForCollisionBetweenFieldObjects(struct npc_state *fieldObject, u16 x, u16 y) -CheckForCollisionBetweenFieldObjects: @ 8092E20 - push {r4-r7,lr} - adds r6, r0, 0 - lsls r1, 16 - lsrs r7, r1, 16 - movs r4, 0 - lsls r2, 16 - asrs r5, r2, 16 -_08092E2E: - lsls r0, r4, 3 - adds r0, r4 - lsls r0, 2 - ldr r1, =gMapObjects - adds r2, r0, r1 - ldrb r0, [r2] - lsls r0, 31 - cmp r0, 0 - beq _08092E88 - cmp r2, r6 - beq _08092E88 - movs r0, 0x10 - ldrsh r1, [r2, r0] - lsls r0, r7, 16 - asrs r3, r0, 16 - cmp r1, r3 - bne _08092E58 - movs r1, 0x12 - ldrsh r0, [r2, r1] - cmp r0, r5 - beq _08092E68 -_08092E58: - movs r1, 0x14 - ldrsh r0, [r2, r1] - cmp r0, r3 - bne _08092E88 - movs r1, 0x16 - ldrsh r0, [r2, r1] - cmp r0, r5 - bne _08092E88 -_08092E68: - ldrb r0, [r6, 0xB] - lsls r0, 28 - lsrs r0, 28 - ldrb r1, [r2, 0xB] - lsls r1, 28 - lsrs r1, 28 - bl AreZCoordsCompatible - lsls r0, 24 - cmp r0, 0 - beq _08092E88 - movs r0, 0x1 - b _08092E94 - .pool -_08092E88: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0xF - bls _08092E2E - movs r0, 0 -_08092E94: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end CheckForCollisionBetweenFieldObjects - thumb_func_start sub_8092E9C sub_8092E9C: @ 8092E9C push {lr} diff --git a/include/field_ground_effect.h b/include/field_ground_effect.h index 398265b87..b7242ee7c 100644 --- a/include/field_ground_effect.h +++ b/include/field_ground_effect.h @@ -13,5 +13,6 @@ void SetObjectSubpriorityByZCoord(u8, struct Sprite *, u8); void InitObjectPriorityByZCoord(struct Sprite *, u8); bool8 IsZCoordMismatchAt(u8, s16, s16); +bool8 AreZCoordsCompatible(u8, u8); #endif //GUARD_FIELD_GROUND_EFFECT_H diff --git a/src/field_map_obj.c b/src/field_map_obj.c index 74c71333c..9855321d3 100755 --- a/src/field_map_obj.c +++ b/src/field_map_obj.c @@ -3741,6 +3741,28 @@ bool8 IsMetatileDirectionallyImpassable(struct MapObject *mapObject, s16 x, s16 return FALSE; } +bool8 CheckForCollisionBetweenFieldObjects(struct MapObject *mapObject, s16 x, s16 y) +{ + u8 i; + struct MapObject *curObject; + + for (i = 0; i < NUM_FIELD_OBJECTS; i ++) + { + curObject = &gMapObjects[i]; + if (curObject->active && curObject != mapObject) + { + if ((curObject->coords2.x == x && curObject->coords2.y == y) || (curObject->coords3.x == x && curObject->coords3.y == y)) + { + if (AreZCoordsCompatible(mapObject->mapobj_unk_0B_0, curObject->mapobj_unk_0B_0)) + { + return TRUE; + } + } + } + } + return FALSE; +} + asm(".section .text.get_face_direction_anim_id"); void FieldObjectClearAnimIfSpecialAnimActive(struct MapObject *);