Failed attempt to fix InitFieldObjectStateFromTemplate, but at least we fixed the weirdness with the double MapObject structs

This commit is contained in:
PikalaxALT 2017-09-17 11:39:49 -04:00
parent 9b4c61658a
commit 3356a4fb92
2 changed files with 33 additions and 89 deletions

View File

@ -226,71 +226,13 @@ struct MapObject
/*0x14*/ struct Coords16 coords3; /*0x14*/ struct Coords16 coords3;
/*0x18*/ u8 mapobj_unk_18:4; //current direction? /*0x18*/ u8 mapobj_unk_18:4; //current direction?
/*0x18*/ u8 placeholder18:4; /*0x18*/ u8 placeholder18:4;
/*0x19*/ u8 mapobj_unk_19:4; /*0x19*/ union __attribute__((packed)) {
/*0x19*/ u8 mapobj_unk_19b:4; u8 as_byte;
/*0x1A*/ u8 mapobj_unk_1A; struct __attribute__((packed)) {
/*0x1B*/ u8 mapobj_unk_1B; u8 x:4;
/*0x1C*/ u8 mapobj_unk_1C; u8 y:4;
/*0x1D*/ u8 trainerRange_berryTreeId; } __attribute__((aligned (1))) as_nybbles;
/*0x1E*/ u8 mapobj_unk_1E; } __attribute__((aligned (1))) range;
/*0x1F*/ u8 mapobj_unk_1F;
/*0x20*/ u8 mapobj_unk_20;
/*0x21*/ u8 mapobj_unk_21;
/*0x22*/ u8 animId;
/*size = 0x24*/
};
// THIS IS NEEDED TO MAKE TRAINER_SEE.C MATCH, PLEASE DO NOT REMOVE UNLESS YOU FIX CHECKPATHBETWEENTRAINERANDPLAYER
struct MapObject2
{
/*0x00*/ u32 active:1;
u32 mapobj_bit_1:1;
u32 mapobj_bit_2:1;
u32 mapobj_bit_3:1;
u32 mapobj_bit_4:1;
u32 mapobj_bit_5:1;
u32 mapobj_bit_6:1;
u32 mapobj_bit_7:1;
/*0x01*/ u32 mapobj_bit_8:1;
u32 mapobj_bit_9:1;
u32 mapobj_bit_10:1;
u32 mapobj_bit_11:1;
u32 mapobj_bit_12:1;
u32 mapobj_bit_13:1;
u32 mapobj_bit_14:1;
u32 mapobj_bit_15:1;
/*0x02*/ u32 mapobj_bit_16:1;
u32 mapobj_bit_17:1;
u32 mapobj_bit_18:1;
u32 mapobj_bit_19:1;
u32 mapobj_bit_20:1;
u32 mapobj_bit_21:1;
u32 mapobj_bit_22:1;
u32 mapobj_bit_23:1;
/*0x03*/ u32 mapobj_bit_24:1;
u32 mapobj_bit_25:1;
u32 mapobj_bit_26:1;
u32 mapobj_bit_27:1;
u32 mapobj_bit_28:1;
u32 mapobj_bit_29:1;
u32 mapobj_bit_30:1;
u32 mapobj_bit_31:1;
/*0x04*/ u8 spriteId;
/*0x05*/ u8 graphicsId;
/*0x06*/ u8 animPattern;
/*0x07*/ u8 trainerType;
/*0x08*/ u8 localId;
/*0x09*/ u8 mapNum;
/*0x0A*/ u8 mapGroup;
/*0x0B*/ u8 mapobj_unk_0B_0:4;
u8 elevation:4;
/*0x0C*/ struct Coords16 coords1;
/*0x10*/ struct Coords16 coords2;
/*0x14*/ struct Coords16 coords3;
/*0x18*/ u8 mapobj_unk_18:4;
/*0x18*/ u8 placeholder18:4;
/*0x19*/ u8 mapobj_unk_19:4;
/*0x19*/ u8 mapobj_unk_19b:4;
/*0x1A*/ u8 mapobj_unk_1A; /*0x1A*/ u8 mapobj_unk_1A;
/*0x1B*/ u8 mapobj_unk_1B; /*0x1B*/ u8 mapobj_unk_1B;
/*0x1C*/ u8 mapobj_unk_1C; /*0x1C*/ u8 mapobj_unk_1C;

View File

@ -117,7 +117,7 @@ static u32 state_to_direction(u8, u32, u32);
static void FieldObjectExecSpecialAnim(struct MapObject *, struct Sprite *); static void FieldObjectExecSpecialAnim(struct MapObject *, struct Sprite *);
/*static*/ void npc_obj_transfer_image_anim_pause_flag(struct MapObject *, struct Sprite *); /*static*/ void npc_obj_transfer_image_anim_pause_flag(struct MapObject *, struct Sprite *);
static bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject2 *, s16, s16); static bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject *, s16, s16);
static bool8 IsMetatileDirectionallyImpassable(struct MapObject *, s16, s16, u8); static bool8 IsMetatileDirectionallyImpassable(struct MapObject *, s16, s16, u8);
static bool8 CheckForCollisionBetweenFieldObjects(struct MapObject *, s16, s16); static bool8 CheckForCollisionBetweenFieldObjects(struct MapObject *, s16, s16);
@ -253,14 +253,15 @@ static u8 GetFieldObjectIdByLocalId(u8 localId)
// This function has the same nonmatching quirk as in Ruby/Sapphire. // This function has the same nonmatching quirk as in Ruby/Sapphire.
#ifdef NONMATCHING #ifdef NONMATCHING
static u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *template, u8 mapId, u8 mapGroupId) static u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *template, u8 mapNum, u8 mapGroup)
{ {
u8 slot;
struct MapObject *mapObject; struct MapObject *mapObject;
u16 x; s16 x;
u16 y; s16 y;
u8 slot;
if (GetAvailableFieldObjectSlot(template->localId, mapId, mapGroupId, &slot)) // mapNum and mapGroup are in the wrong registers (r7/r6 instead of r6/r7)
if (GetAvailableFieldObjectSlot(template->localId, mapNum, mapGroup, &slot))
{ {
return NUM_FIELD_OBJECTS; return NUM_FIELD_OBJECTS;
} }
@ -273,8 +274,8 @@ static u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *template, u
mapObject->graphicsId = template->graphicsId; mapObject->graphicsId = template->graphicsId;
mapObject->animPattern = template->movementType; mapObject->animPattern = template->movementType;
mapObject->localId = template->localId; mapObject->localId = template->localId;
mapObject->mapNum = mapId; mapObject->mapNum = mapNum;
mapObject->mapGroup = mapGroupId; mapObject->mapGroup = mapGroup;
mapObject->coords1.x = x; mapObject->coords1.x = x;
mapObject->coords1.y = y; mapObject->coords1.y = y;
mapObject->coords2.x = x; mapObject->coords2.x = x;
@ -283,24 +284,25 @@ static u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *template, u
mapObject->coords3.y = y; mapObject->coords3.y = y;
mapObject->mapobj_unk_0B_0 = template->elevation; mapObject->mapobj_unk_0B_0 = template->elevation;
mapObject->elevation = template->elevation; mapObject->elevation = template->elevation;
mapObject->mapobj_unk_19 = template->unkA_0; // For some reason, 0x0F is placed in r9, to be used later
mapObject->mapobj_unk_19b = template->unkA_4; mapObject->range.as_nybbles.x = template->unkA_0;
mapObject->range.as_nybbles.y = template->unkA_4;
mapObject->trainerType = template->unkC; mapObject->trainerType = template->unkC;
mapObject->trainerRange_berryTreeId = template->unkE; mapObject->trainerRange_berryTreeId = template->unkE;
mapObject->mapobj_unk_20 = gUnknown_085055CD[template->movementType]; mapObject->mapobj_unk_20 = gUnknown_085055CD[template->movementType];
FieldObjectSetDirection(mapObject, mapObject->mapobj_unk_20); FieldObjectSetDirection(mapObject, mapObject->mapobj_unk_20);
FieldObjectHandleDynamicGraphicsId(mapObject); FieldObjectHandleDynamicGraphicsId(mapObject);
// This block is the culprit
if (gUnknown_0850557C[mapObject->animPattern]) if (gUnknown_0850557C[mapObject->animPattern])
{ {
if (mapObject->mapobj_unk_19 == 0) if ((mapObject->range.as_nybbles.x) == 0)
{ {
mapObject->mapobj_unk_19 ++; // r9 is invoked here
mapObject->range.as_nybbles.x ++;
} }
if (mapObject->mapobj_unk_19b == 0) if ((mapObject->range.as_nybbles.y) == 0)
{ {
mapObject->mapobj_unk_19b ++; mapObject->range.as_nybbles.y ++;
} }
} }
return slot; return slot;
@ -3654,7 +3656,7 @@ u8 npc_block_way(struct MapObject *mapObject, s16 x, s16 y, u32 dirn)
u8 direction; u8 direction;
direction = dirn; direction = dirn;
if (IsCoordOutsideFieldObjectMovementRect((struct MapObject2 *)mapObject, x, y)) if (IsCoordOutsideFieldObjectMovementRect(mapObject, x, y))
{ {
return 1; return 1;
} }
@ -3682,7 +3684,7 @@ u8 sub_8092C8C(struct MapObject *mapObject, s16 x, s16 y, u8 direction)
u8 retval; u8 retval;
retval = 0x00; retval = 0x00;
if (IsCoordOutsideFieldObjectMovementRect((struct MapObject2 *)mapObject, x, y)) if (IsCoordOutsideFieldObjectMovementRect(mapObject, x, y))
{ {
retval |= 1; retval |= 1;
} }
@ -3701,26 +3703,26 @@ u8 sub_8092C8C(struct MapObject *mapObject, s16 x, s16 y, u8 direction)
return retval; return retval;
} }
static bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject2 *mapObject, s16 x, s16 y) static bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject *mapObject, s16 x, s16 y)
{ {
s16 left; s16 left;
s16 right; s16 right;
s16 top; s16 top;
s16 bottom; s16 bottom;
if (mapObject->mapobj_unk_19 != 0) if (mapObject->range.as_nybbles.x != 0)
{ {
left = mapObject->coords1.x - mapObject->mapobj_unk_19; left = mapObject->coords1.x - mapObject->range.as_nybbles.x;
right = mapObject->coords1.x + mapObject->mapobj_unk_19; right = mapObject->coords1.x + mapObject->range.as_nybbles.x;
if (left > x || right < x) if (left > x || right < x)
{ {
return TRUE; return TRUE;
} }
} }
if (mapObject->mapobj_unk_19b != 0) if (mapObject->range.as_nybbles.y != 0)
{ {
top = mapObject->coords1.y - mapObject->mapobj_unk_19b; top = mapObject->coords1.y - mapObject->range.as_nybbles.y;
bottom = mapObject->coords1.y + mapObject->mapobj_unk_19b; bottom = mapObject->coords1.y + mapObject->range.as_nybbles.y;
if (top > y || bottom < y) if (top > y || bottom < y)
{ {
return TRUE; return TRUE;