From e26501f130ed84b160f80232db642ec49722025f Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 13 Sep 2017 10:59:25 -0400 Subject: [PATCH] Support functions for GoRandomDirections --- asm/field_map_obj.s | 174 -------------------------------------------- include/data3.h | 2 + include/global.h | 2 +- src/field_map_obj.c | 79 ++++++++++++++++++++ 4 files changed, 82 insertions(+), 175 deletions(-) diff --git a/asm/field_map_obj.s b/asm/field_map_obj.s index f17d25eba..8a4931322 100755 --- a/asm/field_map_obj.s +++ b/asm/field_map_obj.s @@ -5,180 +5,6 @@ .text - thumb_func_start sub_808F44C -sub_808F44C: @ 808F44C - push {r4,lr} - adds r4, r1, 0 - bl npc_reset - movs r0, 0x1 - strh r0, [r4, 0x30] - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_808F44C - - thumb_func_start sub_808F460 -sub_808F460: @ 808F460 - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - ldrb r0, [r4, 0x18] - lsls r0, 28 - lsrs r0, 28 - bl GetFaceDirectionAnimId - adds r2, r0, 0 - lsls r2, 24 - lsrs r2, 24 - adds r0, r4, 0 - adds r1, r5, 0 - bl FieldObjectSetRegularAnim - movs r0, 0x2 - strh r0, [r5, 0x30] - movs r0, 0x1 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_808F460 - - thumb_func_start sub_808F48C -sub_808F48C: @ 808F48C - push {r4-r6,lr} - adds r6, r1, 0 - bl FieldObjectExecRegularAnim - lsls r0, 24 - cmp r0, 0 - beq _0808F4C0 - ldr r5, =gUnknown_0850D6DC - bl Random - movs r4, 0x3 - adds r1, r4, 0 - ands r1, r0 - lsls r1, 1 - adds r1, r5 - movs r0, 0 - ldrsh r1, [r1, r0] - adds r0, r6, 0 - bl sub_8097978 - strh r4, [r6, 0x30] - movs r0, 0x1 - b _0808F4C2 - .pool -_0808F4C0: - movs r0, 0 -_0808F4C2: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_808F48C - - thumb_func_start sub_808F4C8 -sub_808F4C8: @ 808F4C8 - push {r4,lr} - adds r4, r1, 0 - adds r0, r4, 0 - bl sub_809797C - lsls r0, 24 - cmp r0, 0 - bne _0808F4DC - movs r0, 0 - b _0808F4E2 -_0808F4DC: - movs r0, 0x4 - strh r0, [r4, 0x30] - movs r0, 0x1 -_0808F4E2: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_808F4C8 - - thumb_func_start sub_808F4E8 -sub_808F4E8: @ 808F4E8 - push {r4-r6,lr} - sub sp, 0x4 - adds r5, r0, 0 - adds r6, r1, 0 - ldr r1, =gUnknown_0850D710 - mov r0, sp - movs r2, 0x4 - bl memcpy - bl Random - movs r1, 0x3 - ands r1, r0 - mov r2, sp - adds r0, r2, r1 - ldrb r4, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl FieldObjectSetDirection - movs r0, 0x5 - strh r0, [r6, 0x30] - adds r0, r5, 0 - adds r1, r4, 0 - bl sub_8092B88 - lsls r0, 24 - cmp r0, 0 - beq _0808F526 - movs r0, 0x1 - strh r0, [r6, 0x30] -_0808F526: - movs r0, 0x1 - add sp, 0x4 - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end sub_808F4E8 - - thumb_func_start sub_808F534 -sub_808F534: @ 808F534 - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - ldrb r0, [r4, 0x18] - lsrs r0, 4 - bl GetGoSpeed0AnimId - adds r2, r0, 0 - lsls r2, 24 - lsrs r2, 24 - adds r0, r4, 0 - adds r1, r5, 0 - bl FieldObjectSetRegularAnim - ldrb r0, [r4] - movs r1, 0x2 - orrs r0, r1 - strb r0, [r4] - movs r0, 0x6 - strh r0, [r5, 0x30] - movs r0, 0x1 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_808F534 - - thumb_func_start sub_808F564 -sub_808F564: @ 808F564 - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - bl FieldObjectExecRegularAnim - lsls r0, 24 - cmp r0, 0 - beq _0808F582 - ldrb r0, [r4] - movs r1, 0x3 - negs r1, r1 - ands r1, r0 - strb r1, [r4] - movs r0, 0x1 - strh r0, [r5, 0x30] -_0808F582: - movs r0, 0 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_808F564 - thumb_func_start FieldObjectIsTrainerAndCloseToPlayer @ bool8 FieldObjectIsTrainerAndCloseToPlayer(struct npc_state *fieldObject) FieldObjectIsTrainerAndCloseToPlayer: @ 808F58C diff --git a/include/data3.h b/include/data3.h index 29b1acc34..35dba5942 100755 --- a/include/data3.h +++ b/include/data3.h @@ -17,5 +17,7 @@ extern const struct SpritePalette gUnknown_0850BBC8[]; extern const struct PairedPalettes gUnknown_0850BD00[15]; extern const struct PairedPalettes gUnknown_0850BD78[15]; extern const u16 *const gUnknown_0850BE38[2]; +extern const s16 gUnknown_0850D6DC[4]; +extern const u8 gUnknown_0850D710[4]; #endif //POKEEMERALD_DATA3_H diff --git a/include/global.h b/include/global.h index c406c507f..a006e8591 100644 --- a/include/global.h +++ b/include/global.h @@ -10,7 +10,7 @@ #define asm_comment(x) asm volatile("@ -- " x " -- ") #define asm_unified(x) asm(".syntax unified\n" x "\n.syntax divided") -#ifdef __APPLE__ +#if defined (__APPLE__) || defined (__CYGWIN__) void memset(void *, int, size_t); void memcpy(void *, const void *, size_t); #endif // __APPLE__ diff --git a/src/field_map_obj.c b/src/field_map_obj.c index 3dd47d540..90b2f0302 100755 --- a/src/field_map_obj.c +++ b/src/field_map_obj.c @@ -4,6 +4,7 @@ #include "malloc.h" #include "sprite.h" #include "rom4.h" +#include "rng.h" #include "data3.h" #include "event_scripts.h" #include "berry.h" @@ -76,6 +77,14 @@ static bool8 FieldObjectDoesZCoordMatch(struct MapObject *, u8); /*static*/ void CameraObject_1(struct Sprite *); //static void CameraObject_2(struct Sprite *); /*static*/ struct MapObjectTemplate *FindFieldObjectTemplateInArrayByLocalId(u8 localId, struct MapObjectTemplate *templates, u8 count); +void npc_reset(struct MapObject *, struct Sprite *); +void FieldObjectSetRegularAnim(struct MapObject *, struct Sprite *, u8); +u8 GetFaceDirectionAnimId(u8); +bool8 FieldObjectExecRegularAnim(struct MapObject *, struct Sprite *); +void sub_8097978(struct Sprite *, s16); +bool8 sub_809797C(struct Sprite *); +bool8 sub_8092B88(struct MapObject *, u8); +u8 GetGoSpeed0AnimId(u8); // ROM data @@ -1716,7 +1725,77 @@ u16 npc_paltag_by_palslot(u8 palSlot) return 0x11ff; } +// Map Object Step Callbacks + null_object_step(NoMovement1, FALSE) field_object_step(GoRandomDirections, gUnknown_0850D6F4) +bool8 sub_808F44C(struct MapObject *mapObject, struct Sprite *sprite) +{ + npc_reset(mapObject, sprite); + sprite->data1 = 1; + return TRUE; +} + +bool8 sub_808F460(struct MapObject *mapObject, struct Sprite *sprite) +{ + FieldObjectSetRegularAnim(mapObject, sprite, GetFaceDirectionAnimId(mapObject->mapobj_unk_18)); + sprite->data1 = 2; + return TRUE; +} + +bool8 sub_808F48C(struct MapObject *mapObject, struct Sprite *sprite) +{ + if (!FieldObjectExecRegularAnim(mapObject, sprite)) + { + return FALSE; + } + sub_8097978(sprite, gUnknown_0850D6DC[Random() & 0x03]); + sprite->data1 = 3; + return TRUE; +} + +bool8 sub_808F4C8(struct MapObject *mapObject, struct Sprite *sprite) +{ + if (sub_809797C(sprite)) + { + sprite->data1 = 4; + return TRUE; + } + return FALSE; +} + +bool8 sub_808F4E8(struct MapObject *mapObject, struct Sprite *sprite) +{ + u8 directions[4]; + u8 chosenDirection; + + memcpy(directions, gUnknown_0850D710, sizeof directions); + chosenDirection = directions[Random() & 0x03]; + FieldObjectSetDirection(mapObject, chosenDirection); + sprite->data1 = 5; + if (sub_8092B88(mapObject, chosenDirection)) + { + sprite->data1 = 1; + } + return TRUE; +} + +bool8 sub_808F534(struct MapObject *mapObject, struct Sprite *sprite) +{ + FieldObjectSetRegularAnim(mapObject, sprite, GetGoSpeed0AnimId(mapObject->placeholder18)); + mapObject->mapobj_bit_1 = TRUE; + sprite->data1 = 6; + return TRUE; +} + +bool8 sub_808F564(struct MapObject *mapObject, struct Sprite *sprite) +{ + if (FieldObjectExecRegularAnim(mapObject, sprite)) + { + mapObject->mapobj_bit_1 = FALSE; + sprite->data1 = 1; + } + return FALSE; +}