From 823f8d6a0c827025f280e1d57fb71959ca529fbe Mon Sep 17 00:00:00 2001 From: scnorton Date: Fri, 8 Sep 2017 14:05:45 -0400 Subject: [PATCH] get_berry_tree_graphics --- asm/field_map_obj.s | 77 --------------------------------------------- include/berry.h | 17 ++++++++++ src/field_map_obj.c | 26 +++++++++++++++ 3 files changed, 43 insertions(+), 77 deletions(-) create mode 100644 include/berry.h diff --git a/asm/field_map_obj.s b/asm/field_map_obj.s index 18d5d3ed5c..4d2cd9f9c0 100644 --- a/asm/field_map_obj.s +++ b/asm/field_map_obj.s @@ -5,83 +5,6 @@ .text - thumb_func_start get_berry_tree_graphics -@ void get_berry_tree_graphics(npc_state *npcState, struct obj *obj) -get_berry_tree_graphics: @ 808E5F4 - push {r4-r7,lr} - adds r5, r0, 0 - adds r7, r1, 0 - ldrb r0, [r5, 0x1] - movs r1, 0x20 - orrs r0, r1 - strb r0, [r5, 0x1] - adds r4, r7, 0 - adds r4, 0x3E - ldrb r0, [r4] - movs r1, 0x4 - orrs r0, r1 - strb r0, [r4] - ldrb r0, [r5, 0x1D] - bl GetStageByBerryTreeId - lsls r0, 24 - lsrs r6, r0, 24 - cmp r6, 0 - beq _0808E680 - ldrb r1, [r5, 0x1] - movs r0, 0x21 - negs r0, r0 - ands r0, r1 - strb r0, [r5, 0x1] - ldrb r1, [r4] - movs r0, 0x5 - negs r0, r0 - ands r0, r1 - strb r0, [r4] - ldrb r0, [r5, 0x1D] - bl GetBerryTypeByBerryTreeId - subs r0, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - subs r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - cmp r4, 0x2B - bls _0808E648 - movs r4, 0 -_0808E648: - ldr r0, =gBerryTreeFieldObjectGraphicsIdTablePointers - lsls r4, 2 - adds r0, r4, r0 - ldr r0, [r0] - adds r0, r6 - ldrb r1, [r0] - adds r0, r5, 0 - bl FieldObjectSetGraphicsId - ldr r0, =gBerryTreePicTablePointers - adds r0, r4, r0 - ldr r0, [r0] - str r0, [r7, 0xC] - ldr r0, =gBerryTreePaletteSlotTablePointers - adds r4, r0 - ldr r0, [r4] - adds r0, r6 - ldrb r1, [r0] - lsls r1, 4 - ldrb r2, [r7, 0x5] - movs r0, 0xF - ands r0, r2 - orrs r0, r1 - strb r0, [r7, 0x5] - adds r0, r7, 0 - adds r1, r6, 0 - bl StartSpriteAnim -_0808E680: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end get_berry_tree_graphics - thumb_func_start GetFieldObjectGraphicsInfo @ FieldObjectGraphicsInfo *GetFieldObjectGraphicsInfo(u8 graphicsId) GetFieldObjectGraphicsInfo: @ 808E694 diff --git a/include/berry.h b/include/berry.h new file mode 100644 index 0000000000..6d8d8d483d --- /dev/null +++ b/include/berry.h @@ -0,0 +1,17 @@ +// +// Created by Scott Norton on 9/8/17. +// + +#ifndef POKEEMERALD_BERRY_H +#define POKEEMERALD_BERRY_H + +#define NUM_BERRIES 44 + +extern const u8 *const gBerryTreeFieldObjectGraphicsIdTablePointers[NUM_BERRIES]; +extern const struct SpriteFrameImage *const gBerryTreePicTablePointers[NUM_BERRIES]; +extern const u8 *const gBerryTreePaletteSlotTablePointers[NUM_BERRIES]; + +u8 GetStageByBerryTreeId(u8); +u8 GetBerryTypeByBerryTreeId(u8); + +#endif //POKEEMERALD_BERRY_H diff --git a/src/field_map_obj.c b/src/field_map_obj.c index 4d5efd1b95..37ab017622 100644 --- 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 "berry.h" #include "field_player_avatar.h" #include "event_data.h" #include "rom_818CFC8.h" @@ -978,3 +979,28 @@ void PlayerObjectTurn(struct PlayerAvatar *playerAvatar, u8 direction) { FieldObjectTurn(&gMapObjects[playerAvatar->mapObjectId], direction); } + +void get_berry_tree_graphics(struct MapObject *mapObject, struct Sprite *sprite) +{ + u8 berryStage; + u8 berryId; + + mapObject->mapobj_bit_13 = TRUE; + sprite->invisible = TRUE; + berryStage = GetStageByBerryTreeId(mapObject->trainerRange_berryTreeId); + if (berryStage != 0) + { + mapObject->mapobj_bit_13 = FALSE; + sprite->invisible = FALSE; + berryId = GetBerryTypeByBerryTreeId(mapObject->trainerRange_berryTreeId) - 1; + berryStage -= 1; + if (berryId >= NUM_BERRIES) + { + berryId = 0; + } + FieldObjectSetGraphicsId(mapObject, gBerryTreeFieldObjectGraphicsIdTablePointers[berryId][berryStage]); + sprite->images = gBerryTreePicTablePointers[berryId]; + sprite->oam.paletteNum = gBerryTreePaletteSlotTablePointers[berryId][berryStage]; + StartSpriteAnim(sprite, berryStage); + } +}