GetAvailableFieldObjectSlot

This commit is contained in:
scnorton 2017-09-06 17:25:20 -04:00
parent 6448563ede
commit e060123648
2 changed files with 23 additions and 90 deletions

View File

@ -5,96 +5,6 @@
.text
thumb_func_start GetAvailableFieldObjectSlot
@ bool8 GetAvailableFieldObjectSlot(u16 localId, u8 mapId, u8 mapGroupId, u8 *fieldObjectId)
GetAvailableFieldObjectSlot: @ 808D810
push {r4-r7,lr}
mov r12, r3
lsls r0, 16
lsrs r6, r0, 16
lsls r1, 24
lsrs r5, r1, 24
lsls r2, 24
lsrs r4, r2, 24
movs r2, 0
ldr r1, =gMapObjects
ldrb r0, [r1]
lsls r0, 31
adds r7, r1, 0
cmp r0, 0
beq _0808D864
adds r3, r1, 0
_0808D830:
lsls r0, r2, 3
adds r0, r2
lsls r0, 2
adds r1, r0, r3
ldrb r0, [r1, 0x8]
cmp r0, r6
bne _0808D84A
ldrb r0, [r1, 0x9]
cmp r0, r5
bne _0808D84A
ldrb r0, [r1, 0xA]
cmp r0, r4
beq _0808D868
_0808D84A:
adds r0, r2, 0x1
lsls r0, 24
lsrs r2, r0, 24
cmp r2, 0xF
bhi _0808D868
lsls r0, r2, 3
adds r0, r2
lsls r0, 2
adds r0, r7
ldrb r0, [r0]
lsls r0, 31
cmp r0, 0
bne _0808D830
_0808D864:
cmp r2, 0xF
bls _0808D870
_0808D868:
movs r0, 0x1
b _0808D8A4
.pool
_0808D870:
mov r0, r12
strb r2, [r0]
ldr r1, =gMapObjects
_0808D876:
lsls r0, r2, 3
adds r0, r2
lsls r0, 2
adds r3, r0, r1
ldrb r0, [r3]
lsls r0, 31
cmp r0, 0
beq _0808D898
ldrb r0, [r3, 0x8]
cmp r0, r6
bne _0808D898
ldrb r0, [r3, 0x9]
cmp r0, r5
bne _0808D898
ldrb r0, [r3, 0xA]
cmp r0, r4
beq _0808D868
_0808D898:
adds r0, r2, 0x1
lsls r0, 24
lsrs r2, r0, 24
cmp r2, 0xF
bls _0808D876
movs r0, 0
_0808D8A4:
pop {r4-r7}
pop {r1}
bx r1
.pool
thumb_func_end GetAvailableFieldObjectSlot
thumb_func_start RemoveFieldObject
@ void RemoveFieldObject(npc_state *fieldObject)
RemoveFieldObject: @ 808D8B0

View File

@ -387,3 +387,26 @@ u8 unref_sub_808D77C(u8 localId)
}
return ARRAY_COUNT(gMapObjects);
}
bool8 GetAvailableFieldObjectSlot(u16 localId, u8 mapNum, u8 mapGroup, u8 *result)
{
u8 i = 0;
for (i = 0; i < ARRAY_COUNT(gMapObjects); i ++)
{
if (!gMapObjects[i].active)
break;
if (gMapObjects[i].localId == localId && gMapObjects[i].mapNum == mapNum && gMapObjects[i].mapGroup == mapGroup)
return TRUE;
}
if (i >= ARRAY_COUNT(gMapObjects))
return TRUE;
*result = i;
do
{
if (gMapObjects[i].active && gMapObjects[i].localId == localId && gMapObjects[i].mapNum == mapNum && gMapObjects[i].mapGroup == mapGroup)
return TRUE;
i ++;
} while (i < ARRAY_COUNT(gMapObjects));
return FALSE;
}