diff --git a/arm9/asm/map_object_s.s b/arm9/asm/map_object_s.s index 3d68d5edd..5a250cc35 100644 --- a/arm9/asm/map_object_s.s +++ b/arm9/asm/map_object_s.s @@ -6,118 +6,6 @@ .text - thumb_func_start sub_0205771C -sub_0205771C: ; 0x0205771C - push {r3-r7, lr} - add r5, r0, #0x0 - mov r4, #0x0 - bl MapObjectManager_GetObjectCount - add r6, r0, #0x0 - add r0, r5, #0x0 - bl MapObjectManager_GetObjects - mov r7, #0x4a - add r5, r0, #0x0 - lsl r7, r7, #0x2 -_02057734: - add r0, r5, #0x0 - mov r1, #0x1 - bl MapObject_GetFlagsBits - cmp r0, #0x0 - beq _02057746 - add r0, r5, #0x0 - bl MapObject_Remove -_02057746: - add r4, r4, #0x1 - add r5, r5, r7 - cmp r4, r6 - blt _02057734 - pop {r3-r7, pc} - - thumb_func_start sub_02057750 -sub_02057750: ; 0x02057750 - push {r3-r7, lr} - add r5, r0, #0x0 - bl sub_020587E0 - cmp r0, #0x1 - beq _02057760 - bl GF_AssertFail -_02057760: - add r0, r5, #0x0 - mov r4, #0x0 - bl MapObjectManager_GetObjectCount - add r6, r0, #0x0 - add r0, r5, #0x0 - bl MapObjectManager_GetObjects - mov r7, #0x4a - add r5, r0, #0x0 - lsl r7, r7, #0x2 -_02057776: - add r0, r5, #0x0 - mov r1, #0x1 - bl MapObject_GetFlagsBits - cmp r0, #0x0 - beq _0205779C - mov r1, #0x1 - add r0, r5, #0x0 - lsl r1, r1, #0xe - bl MapObject_GetFlagsBits - cmp r0, #0x0 - beq _0205779C - add r0, r5, #0x0 - bl sub_020586C8 - add r0, r5, #0x0 - bl sub_0205816C -_0205779C: - add r4, r4, #0x1 - add r5, r5, r7 - cmp r4, r6 - blt _02057776 - pop {r3-r7, pc} - .balign 4 - - thumb_func_start sub_020577A8 -sub_020577A8: ; 0x020577A8 - push {r3-r7, lr} - add r5, r0, #0x0 - bl sub_020587E0 - cmp r0, #0x1 - beq _020577B8 - bl GF_AssertFail -_020577B8: - add r0, r5, #0x0 - mov r4, #0x0 - bl MapObjectManager_GetObjectCount - add r6, r0, #0x0 - add r0, r5, #0x0 - bl MapObjectManager_GetObjects - mov r7, #0x4a - add r5, r0, #0x0 - lsl r7, r7, #0x2 -_020577CE: - add r0, r5, #0x0 - bl MapObject_IsInUse - cmp r0, #0x1 - bne _020577F6 - add r0, r5, #0x0 - bl sub_02058884 - cmp r0, #0x1 - bne _020577EA - add r0, r5, #0x0 - bl sub_020586DC - b _020577F0 -_020577EA: - add r0, r5, #0x0 - bl sub_020581B4 -_020577F0: - add r0, r5, #0x0 - bl sub_02058148 -_020577F6: - add r4, r4, #0x1 - add r5, r5, r7 - cmp r4, r6 - blt _020577CE - pop {r3-r7, pc} - thumb_func_start sub_02057800 sub_02057800: ; 0x02057800 push {r3-r7, lr} @@ -1292,7 +1180,7 @@ sub_020581B4: ; 0x020581B4 mov r1, #0x0 bl ov05_021F2E0C add r0, r4, #0x0 - bl sub_02058884 + bl MapObject_CheckFlag14 cmp r0, #0x0 bne _020581F6 add r0, r4, #0x0 @@ -2475,8 +2363,8 @@ sub_02058878: ; 0x02058878 .balign 4 _02058880: .word MapObject_SetFlagsBits - thumb_func_start sub_02058884 -sub_02058884: ; 0x02058884 + thumb_func_start MapObject_CheckFlag14 +MapObject_CheckFlag14: ; 0x02058884 ldr r3, _0205888C ; =MapObject_TestFlagsBits mov r1, #0x1 lsl r1, r1, #0xe diff --git a/arm9/asm/unk_02048904.s b/arm9/asm/unk_02048904.s index 1b4a207d0..c306a1528 100644 --- a/arm9/asm/unk_02048904.s +++ b/arm9/asm/unk_02048904.s @@ -301,7 +301,7 @@ sub_02048B34: ; 0x02048B34 ldr r0, [r4, #0x38] bl sub_02055160 ldr r0, [r4, #0x34] - bl sub_0205771C + bl MapObjectManager_RemoveAllActiveObjects ldr r0, [r4, #0x34] bl MapObjectManager_Delete pop {r4, pc} diff --git a/arm9/global.inc b/arm9/global.inc index 55a46e79b..90bffa87e 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -3993,7 +3993,7 @@ .extern MapObject_Remove .extern MapObject_Delete .extern sub_020576A8 -.extern sub_0205771C +.extern MapObjectManager_RemoveAllActiveObjects .extern sub_02057750 .extern sub_020577A8 .extern sub_02057800 @@ -4088,7 +4088,7 @@ .extern sub_02058854 .extern sub_02058860 .extern sub_0205886C -.extern sub_02058884 +.extern MapObject_CheckFlag14 .extern sub_02058890 .extern MapObject_SetVisible .extern sub_020588B8 diff --git a/arm9/overlays/05/asm/ov05_021F1CB8.s b/arm9/overlays/05/asm/ov05_021F1CB8.s index f9517d357..b934466da 100644 --- a/arm9/overlays/05/asm/ov05_021F1CB8.s +++ b/arm9/overlays/05/asm/ov05_021F1CB8.s @@ -263,7 +263,7 @@ ov05_021F1EC0: ; 0x021F1EC0 add r4, r0, #0 bl sub_020584AC add r0, r4, #0 - bl sub_02058884 + bl MapObject_CheckFlag14 cmp r0, #1 bne _021F1ED8 add r0, r4, #0 diff --git a/arm9/src/map_object.c b/arm9/src/map_object.c index 1d1170441..9105bfd20 100644 --- a/arm9/src/map_object.c +++ b/arm9/src/map_object.c @@ -77,6 +77,10 @@ extern void sub_02058698(LocalMapObject *object, LocalMapObject_UnkCallback call extern void sub_020586AC(LocalMapObject *object, LocalMapObject_UnkCallback callback); extern void sub_020586C0(LocalMapObject *object, LocalMapObject_UnkCallback callback); extern void sub_020586D4(LocalMapObject *object, LocalMapObject_UnkCallback callback); +extern void sub_020586C8(LocalMapObject *object); +extern void sub_0205816C(LocalMapObject *object); +extern BOOL MapObject_CheckFlag14(LocalMapObject *object); +extern void sub_020586DC(LocalMapObject *object); MapObjectManager *MapObjectManager_Init(FieldSystem *fieldSystem, u32 objectCount, HeapID heapId) { MapObjectManager *ret = MapObjectManager_New(objectCount); @@ -245,3 +249,59 @@ void sub_020576A8(LocalMapObject *object) { sub_020586C0(object, sub_02058EE0); sub_020586D4(object, sub_02058EE4); } + +void MapObjectManager_RemoveAllActiveObjects(MapObjectManager *manager) { + s32 i = 0; + s32 count = MapObjectManager_GetObjectCount(manager); + LocalMapObject *objects = MapObjectManager_GetObjects(manager); + + do { //BUG: does not check for if count is zero, and will always execute at least once + if (MapObject_GetFlagsBits(objects, MAPOBJECTFLAG_ACTIVE) != 0) { + MapObject_Remove(objects); + } + + i++; + objects++; + } while (i < count); +} + +void sub_02057750(MapObjectManager *manager) { + GF_ASSERT(sub_020587E0(manager) == TRUE); + + s32 i = 0; + s32 count = MapObjectManager_GetObjectCount(manager); + LocalMapObject *objects = MapObjectManager_GetObjects(manager); + + do { + if (MapObject_GetFlagsBits(objects, MAPOBJECTFLAG_ACTIVE) != 0 && MapObject_GetFlagsBits(objects, MAPOBJECTFLAG_UNK14) != 0) { + sub_020586C8(objects); + sub_0205816C(objects); + } + + i++; + objects++; + } while (i < count); +} + +void sub_020577A8(MapObjectManager *manager) { + GF_ASSERT(sub_020587E0(manager) == TRUE); + + s32 i = 0; + s32 count = MapObjectManager_GetObjectCount(manager); + LocalMapObject *objects = MapObjectManager_GetObjects(manager); + + do { + if (MapObject_IsInUse(objects) == TRUE) { + if (MapObject_CheckFlag14(objects) == TRUE) { + sub_020586DC(objects); + } else { + sub_020581B4(objects); + } + + sub_02058148(objects); + } + + i++; + objects++; + } while (i < count); +} diff --git a/include/map_object.h b/include/map_object.h index c06ebce8b..28ffa3d66 100644 --- a/include/map_object.h +++ b/include/map_object.h @@ -65,5 +65,8 @@ void sub_02057634(LocalMapObject *object, u32 sprite); void MapObject_Remove(LocalMapObject *object); void MapObject_Delete(LocalMapObject *object); void sub_020576A8(LocalMapObject *object); +void MapObjectManager_RemoveAllActiveObjects(MapObjectManager *manager); +void sub_02057750(MapObjectManager *manager); +void sub_020577A8(MapObjectManager *manager); #endif //POKEDIAMOND_MAP_OBJECT_H