diff --git a/asm/ground_object.s b/asm/ground_object.s index 4807a0db6..62be6b632 100644 --- a/asm/ground_object.s +++ b/asm/ground_object.s @@ -5,61 +5,6 @@ .text - thumb_func_start GroundObject_Select -GroundObject_Select: - push {r4-r7,lr} - sub sp, 0x4 - adds r4, r0, 0 - lsls r4, 16 - asrs r4, 16 - lsls r1, 16 - asrs r7, r1, 16 - lsls r2, 24 - asrs r6, r2, 24 - ldr r1, _080ABC54 - adds r0, r4, 0 - bl GetGroundScript - adds r5, r0, 0 - ldr r1, _080ABC58 - str r6, [sp] - movs r0, 0 - adds r2, r4, 0 - adds r3, r7, 0 - bl Log - lsls r1, r7, 3 - ldr r0, [r5, 0x4] - adds r0, r1 - lsls r1, r6, 2 - adds r1, r6 - lsls r1, 3 - ldr r0, [r0, 0x4] - adds r0, r1 - ldr r5, [r0, 0xC] - ldr r0, [r0, 0x8] - cmp r0, 0 - ble _080ABC4A - adds r4, r0, 0 -_080ABC34: - movs r0, 0x1 - negs r0, r0 - adds r1, r5, 0 - adds r2, r7, 0 - adds r3, r6, 0 - bl GroundObject_Add - subs r4, 0x1 - adds r5, 0x18 - cmp r4, 0 - bne _080ABC34 -_080ABC4A: - add sp, 0x4 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080ABC54: .4byte gUnknown_81183E4 -_080ABC58: .4byte gUnknown_81183F0 - thumb_func_end GroundObject_Select - thumb_func_start GroundObject_Cancel GroundObject_Cancel: push {r4-r7,lr} diff --git a/src/ground_object.c b/src/ground_object.c index f8622fa67..4b44786f6 100644 --- a/src/ground_object.c +++ b/src/ground_object.c @@ -1,4 +1,5 @@ #include "global.h" +#include "ground_script.h" #include "memory.h" typedef struct GroundObject { @@ -13,13 +14,18 @@ IWRAM_INIT GroundObject *gGroundObjects = NULL; void DeleteGroundObjects(void); void GroundObject_Delete(s32); +extern u8 gUnknown_81183F0[]; +s16 GroundObject_Add(s32 id, const GroundObjectData*, s32 group, s32 sector); +extern DebugLocation gUnknown_81183E4; +const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *); + void AllocGroundObjects(void) { GroundObject *ptr; s32 index; - gGroundObjects = MemoryAlloc(0x1C40, 6); + gGroundObjects = MemoryAlloc(sizeof(GroundObject) * 0x10, 6); for(index = 0, ptr = &gGroundObjects[index]; index < 0x10; index = (s16)(index + 1), ptr++) { @@ -47,3 +53,34 @@ void FreeGroundObjects(void) MemoryFree(gGroundObjects); gGroundObjects = NULL; } + +void GroundObject_Select(s32 scriptID, s32 group, s32 sector) +{ + const struct GroundScriptHeader *scriptPtr; + const struct GroundScriptSector *sectorPtr; + const struct GroundScriptGroup *groupPtr; + + s32 i; + s32 size; + const GroundObjectData *effectData; + s32 sector_s32; + s32 group_s32; + s32 scriptID_s32; + + scriptID_s32 = (s16)scriptID; + group_s32 = (s16)group; + sector_s32 = (s8)sector; + scriptPtr = GetGroundScript(scriptID_s32, &gUnknown_81183E4); + Log('\0',gUnknown_81183F0, scriptID_s32, group_s32, sector_s32); + + groupPtr = &scriptPtr->groups[group_s32]; + sectorPtr = &groupPtr->sectors[sector_s32]; + effectData = sectorPtr->objects; + + size = sectorPtr->nObjects; + for (i = 0; i < size; i++, effectData++) + { + GroundObject_Add(-1,effectData,group_s32,sector_s32); + } +} +