From 3e472ccc8b9231d3b447fdfdb706a3da5773546b Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 16 Sep 2017 21:04:52 -0400 Subject: [PATCH] IsCoordOutsideFieldObjectMovementRect --- asm/field_map_obj.s | 65 --------------------------------------------- src/field_map_obj.c | 34 +++++++++++++++++++++--- 2 files changed, 31 insertions(+), 68 deletions(-) diff --git a/asm/field_map_obj.s b/asm/field_map_obj.s index 166383b24..ee67bde5d 100755 --- a/asm/field_map_obj.s +++ b/asm/field_map_obj.s @@ -5,71 +5,6 @@ .text - thumb_func_start IsCoordOutsideFieldObjectMovementRect -@ bool8 IsCoordOutsideFieldObjectMovementRect(struct npc_state *fieldObject, u16 x, u16 y) -IsCoordOutsideFieldObjectMovementRect: @ 8092D58 - push {r4,r5,lr} - adds r4, r0, 0 - lsls r1, 16 - lsrs r3, r1, 16 - lsls r2, 16 - lsrs r5, r2, 16 - ldrb r1, [r4, 0x19] - movs r0, 0xF - ands r0, r1 - cmp r0, 0 - beq _08092D90 - lsls r1, 28 - lsrs r2, r1, 28 - ldrh r0, [r4, 0xC] - subs r2, r0, r2 - lsrs r1, 28 - adds r0, r1 - lsls r0, 16 - lsrs r1, r0, 16 - lsls r2, 16 - lsls r0, r3, 16 - asrs r3, r0, 16 - cmp r2, r0 - bgt _08092DBC - lsls r0, r1, 16 - asrs r0, 16 - cmp r0, r3 - blt _08092DBC -_08092D90: - ldrb r1, [r4, 0x19] - movs r0, 0xF0 - ands r0, r1 - cmp r0, 0 - beq _08092DC0 - lsls r1, 24 - lsrs r2, r1, 28 - ldrh r0, [r4, 0xE] - subs r2, r0, r2 - lsrs r1, 28 - adds r0, r1 - lsls r0, 16 - lsrs r1, r0, 16 - lsls r2, 16 - lsls r0, r5, 16 - asrs r3, r0, 16 - cmp r2, r0 - bgt _08092DBC - lsls r0, r1, 16 - asrs r0, 16 - cmp r0, r3 - bge _08092DC0 -_08092DBC: - movs r0, 0x1 - b _08092DC2 -_08092DC0: - movs r0, 0 -_08092DC2: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end IsCoordOutsideFieldObjectMovementRect - thumb_func_start IsMetatileDirectionallyImpassable @ bool8 IsMetatileDirectionallyImpassable(struct npc_state *fieldObject, u16 x, u16 y, u8 direction) IsMetatileDirectionallyImpassable: @ 8092DC8 diff --git a/src/field_map_obj.c b/src/field_map_obj.c index a876797a4..cc81bcb29 100755 --- a/src/field_map_obj.c +++ b/src/field_map_obj.c @@ -121,7 +121,7 @@ void DoGroundEffects_OnFinishStep(struct MapObject *, struct Sprite *); void npc_obj_transfer_image_anim_pause_flag(struct MapObject *, struct Sprite *); void FieldObjectUpdateSubpriority(struct MapObject *, struct Sprite *); -bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject *fieldObject, s16 x, s16 y); +bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject2 *fieldObject, s16 x, s16 y); bool8 IsMetatileDirectionallyImpassable(struct MapObject *, s16, s16, u8); bool8 CheckForCollisionBetweenFieldObjects(struct MapObject *, s16, s16); @@ -3657,7 +3657,7 @@ u8 npc_block_way(struct MapObject *mapObject, s16 x, s16 y, u32 dirn) u8 direction; direction = dirn; - if (IsCoordOutsideFieldObjectMovementRect(mapObject, x, y)) + if (IsCoordOutsideFieldObjectMovementRect((struct MapObject2 *)mapObject, x, y)) { return 1; } @@ -3685,7 +3685,7 @@ u8 sub_8092C8C(struct MapObject *mapObject, s16 x, s16 y, u8 direction) u8 retval; retval = 0x00; - if (IsCoordOutsideFieldObjectMovementRect(mapObject, x, y)) + if (IsCoordOutsideFieldObjectMovementRect((struct MapObject2 *)mapObject, x, y)) { retval |= 1; } @@ -3704,6 +3704,34 @@ u8 sub_8092C8C(struct MapObject *mapObject, s16 x, s16 y, u8 direction) return retval; } +bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject2 *mapObject, s16 x, s16 y) +{ + s16 left; + s16 right; + s16 top; + s16 bottom; + + if (mapObject->mapobj_unk_19 != 0) + { + left = mapObject->coords1.x - mapObject->mapobj_unk_19; + right = mapObject->coords1.x + mapObject->mapobj_unk_19; + if (left > x || right < x) + { + return TRUE; + } + } + if (mapObject->mapobj_unk_19b != 0) + { + top = mapObject->coords1.y - mapObject->mapobj_unk_19b; + bottom = mapObject->coords1.y + mapObject->mapobj_unk_19b; + if (top > y || bottom < y) + { + return TRUE; + } + } + return FALSE; +} + asm(".section .text.get_face_direction_anim_id"); void FieldObjectClearAnimIfSpecialAnimActive(struct MapObject *);