diff options
author | scnorton <scnorton@biociphers.org> | 2017-12-17 15:56:14 -0500 |
---|---|---|
committer | scnorton <scnorton@biociphers.org> | 2017-12-17 15:56:14 -0500 |
commit | 6bc9b82b1b47a0d2a4bd87bd6d654a34866b9344 (patch) | |
tree | d1327bd67bdcc73adf476c1d73dc638f844176df | |
parent | 27ca4fb2944e86d71a28b04c7b16126ee6f248b8 (diff) |
Fix CheckPathBetweenTrainerAndPlayer and remove MapObject2 struct definition and references
-rw-r--r-- | include/global.fieldmap.h | 71 | ||||
-rw-r--r-- | src/field/field_map_obj.c | 38 | ||||
-rw-r--r-- | src/field/overworld.c | 26 | ||||
-rw-r--r-- | src/field/trainer_see.c | 22 |
4 files changed, 51 insertions, 106 deletions
diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index 488cc11d9..20190dcb7 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -224,7 +224,14 @@ struct MapObject /*0x14*/ struct Coords16 coords3; /*0x18*/ u8 mapobj_unk_18:4; //current direction? /*0x18*/ u8 placeholder18:4; - /*0x19*/ u8 mapobj_unk_19; + /*0x19*/ union __attribute__((packed)) { + u8 as_byte; + struct __attribute__((packed)) { + u8 x:4; + u8 y:4; + } __attribute((aligned (1))) as_nybbles; + } __attribute((aligned (1))) range; + // /*0x19*/ u8 mapobj_unk_19; /*0x1A*/ u8 mapobj_unk_1A; /*0x1B*/ u8 mapobj_unk_1B; /*0x1C*/ u8 mapobj_unk_1C; @@ -237,68 +244,6 @@ struct MapObject /*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; - /*0x1B*/ u8 mapobj_unk_1B; - /*0x1C*/ u8 mapobj_unk_1C; - /*0x1D*/ u8 trainerRange_berryTreeId; - /*0x1E*/ u8 mapobj_unk_1E; - /*0x1F*/ u8 mapobj_unk_1F; - /*0x20*/ u8 mapobj_unk_20; - /*0x21*/ u8 mapobj_unk_21; - /*size = 0x24*/ -}; - struct MapObjectGraphicsInfo { /*0x00*/ u16 tileTag; diff --git a/src/field/field_map_obj.c b/src/field/field_map_obj.c index 81c0c5854..ba7c3d68e 100644 --- a/src/field/field_map_obj.c +++ b/src/field/field_map_obj.c @@ -2020,7 +2020,7 @@ u8 GetFieldObjectIdByLocalId(u8 localId) #ifdef NONMATCHING u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *template, u8 b, u8 c) { - struct MapObject2 *mapObj; //TODO: resolve the mapobj_unk_19b weirdness + struct MapObject *mapObj; //TODO: resolve the mapobj_unk_19b weirdness u8 var; u16 r3; u16 r2; @@ -2029,8 +2029,8 @@ u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *template, u8 b, u8 if (GetAvailableFieldObjectSlot(template->localId, b, c, &var) != 0) return 16; //_0805ACCE - mapObj = (struct MapObject2 *)&gMapObjects[var]; - npc_clear_ids_and_state((struct MapObject *)mapObj); + mapObj = &gMapObjects[var]; + npc_clear_ids_and_state(mapObj); r3 = template->x + 7; r2 = template->y + 7; mapObj->active = TRUE; @@ -2048,8 +2048,8 @@ u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *template, u8 b, u8 mapObj->coords3.y = r2; mapObj->mapobj_unk_0B_0 = template->elevation; mapObj->elevation = template->elevation; - mapObj->mapobj_unk_19 = template->unkA_0; - mapObj->mapobj_unk_19b = template->unkA_4; + mapObj->range.as_nybbles.x = template->unkA_0; + mapObj->range.as_nybbles.y = template->unkA_4; mapObj->trainerType = template->unkC; mapObj->trainerRange_berryTreeId = template->unkE; mapObj->mapobj_unk_20 = gUnknown_0836DC09[template->movementType]; @@ -2058,10 +2058,10 @@ u8 InitFieldObjectStateFromTemplate(struct MapObjectTemplate *template, u8 b, u8 //asm("":::"r5","r6"); if (gUnknown_0836DBBC[mapObj->animPattern] != 0) { - if (mapObj->mapobj_unk_19 == 0) - mapObj->mapobj_unk_19++; - if (mapObj->mapobj_unk_19b == 0) - mapObj->mapobj_unk_19b++; + if (mapObj->range.as_nybbles.x == 0) + mapObj->range.as_nybbles.x++; + if (mapObj->range.as_nybbles.y == 0) + mapObj->range.as_nybbles.y++; } return var; } @@ -5464,7 +5464,7 @@ u8 sub_805FF20(struct MapObject *mapObject, u8 direction) return npc_block_way(mapObject, x, y, direction); } -bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject2 *mapObject, s16 x, s16 y); +bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject *mapObject, s16 x, s16 y); static bool8 DoesObjectCollideWithObjectAt(struct MapObject *mapObject, s16 x, s16 y); bool8 IsMetatileDirectionallyImpassable(struct MapObject *mapObject, s16 x, s16 y, u8 direction); @@ -5472,7 +5472,7 @@ u8 npc_block_way(struct MapObject *mapObject, s16 x, s16 y, u32 dirn) { u8 direction; direction = dirn; - if (IsCoordOutsideFieldObjectMovementRect((struct MapObject2 *)mapObject, x, y)) + if (IsCoordOutsideFieldObjectMovementRect(mapObject, x, y)) return 1; else if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(mapObject, x, y, direction)) return 2; @@ -5489,7 +5489,7 @@ u8 sub_8060024(struct MapObject *mapObject, s16 x, s16 y, u8 direction) { u8 flags = 0; - if (IsCoordOutsideFieldObjectMovementRect((struct MapObject2 *)mapObject, x, y)) + if (IsCoordOutsideFieldObjectMovementRect(mapObject, x, y)) flags |= 1; if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(mapObject, x, y, direction) || (mapObject->mapobj_bit_15 && !CanCameraMoveInDirection(direction))) flags |= 2; @@ -5500,22 +5500,22 @@ u8 sub_8060024(struct MapObject *mapObject, s16 x, s16 y, u8 direction) return flags; } -bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject2 *mapObject, s16 x, s16 y) +bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject *mapObject, s16 x, s16 y) { s16 minv; s16 maxv; - if (mapObject->mapobj_unk_19 != 0) + if (mapObject->range.as_nybbles.x != 0) { - minv = mapObject->coords1.x - (mapObject->mapobj_unk_19); - maxv = mapObject->coords1.x + (mapObject->mapobj_unk_19); + minv = mapObject->coords1.x - (mapObject->range.as_nybbles.x); + maxv = mapObject->coords1.x + (mapObject->range.as_nybbles.x); if (minv > x || maxv < x) return TRUE; } - if (mapObject->mapobj_unk_19b != 0) + if (mapObject->range.as_nybbles.y != 0) { - minv = mapObject->coords1.y - (mapObject->mapobj_unk_19b); - maxv = mapObject->coords1.y + (mapObject->mapobj_unk_19b); + minv = mapObject->coords1.y - (mapObject->range.as_nybbles.y); + maxv = mapObject->coords1.y + (mapObject->range.as_nybbles.y); if (minv > y || maxv < y) return TRUE; } diff --git a/src/field/overworld.c b/src/field/overworld.c index 21f3f98ef..b9a40488e 100644 --- a/src/field/overworld.c +++ b/src/field/overworld.c @@ -287,7 +287,7 @@ void LoadMapObjTemplatesFromHeader(void) { // Clear map object templates CpuFill32(0, gSaveBlock1.mapObjectTemplates, sizeof(gSaveBlock1.mapObjectTemplates)); - + // Copy map header events to save block CpuCopy32(gMapHeader.events->mapObjects, gSaveBlock1.mapObjectTemplates, @@ -981,7 +981,7 @@ static void PlayAmbientCry(void) s16 x, y; s8 pan; s8 volume; - + PlayerGetDestCoords(&x, &y); if (sIsAmbientCryWaterMon == TRUE && !MetatileBehavior_IsSurfableWaterOrUnderwater(MapGridGetMetatileBehaviorAt(x, y))) @@ -1158,7 +1158,7 @@ void OverworldBasic(void) sub_8072EDC(); } -// This CB2 is used when starting +// This CB2 is used when starting void CB2_OverworldBasic(void) { OverworldBasic(); @@ -2430,7 +2430,7 @@ void SpawnLinkPlayerMapObject(u8 linkPlayerId, s16 x, s16 y, u8 a4) mapObj->active = 1; mapObj->mapobj_bit_1 = a4; - mapObj->mapobj_unk_19 = 2; + mapObj->range.as_byte = 2; mapObj->spriteId = 64; InitLinkPlayerMapObjectPos(mapObj, x, y); @@ -2453,7 +2453,7 @@ void unref_sub_8055A6C(u8 linkPlayerId, u8 a2) { u8 mapObjId = gLinkPlayerMapObjects[linkPlayerId].mapObjId; struct MapObject *mapObj = &gMapObjects[mapObjId]; - mapObj->mapobj_unk_19 = a2; + mapObj->range.as_byte = a2; } } @@ -2487,7 +2487,7 @@ u8 sub_8055B30(u8 linkPlayerId) { u8 mapObjId = gLinkPlayerMapObjects[linkPlayerId].mapObjId; struct MapObject *mapObj = &gMapObjects[mapObjId]; - return mapObj->mapobj_unk_19; + return mapObj->range.as_byte; } u8 sub_8055B50(u8 linkPlayerId) @@ -2559,10 +2559,10 @@ static u8 sub_8055CB0(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapOb { s16 x, y; - mapObj->mapobj_unk_19 = npc_something3(a3, mapObj->mapobj_unk_19); - FieldObjectMoveDestCoords(mapObj, mapObj->mapobj_unk_19, &x, &y); + mapObj->range.as_byte = npc_something3(a3, mapObj->range.as_byte); + FieldObjectMoveDestCoords(mapObj, mapObj->range.as_byte, &x, &y); - if (LinkPlayerDetectCollision(linkPlayerMapObj->mapObjId, mapObj->mapobj_unk_19, x, y)) + if (LinkPlayerDetectCollision(linkPlayerMapObj->mapObjId, mapObj->range.as_byte, x, y)) { return 0; } @@ -2577,7 +2577,7 @@ static u8 sub_8055CB0(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapOb static u8 sub_8055D18(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) { - mapObj->mapobj_unk_19 = npc_something3(a3, mapObj->mapobj_unk_19); + mapObj->range.as_byte = npc_something3(a3, mapObj->range.as_byte); return 0; } @@ -2590,7 +2590,7 @@ static void sub_8055D38(struct LinkPlayerMapObject *linkPlayerMapObj, struct Map { mapObj->mapobj_unk_21--; linkPlayerMapObj->mode = 1; - MoveCoords(mapObj->mapobj_unk_19, &mapObj->coords1.x, &mapObj->coords1.y); + MoveCoords(mapObj->range.as_byte, &mapObj->coords1.x, &mapObj->coords1.y); if (!mapObj->mapobj_unk_21) { npc_coords_shift_still(mapObj); @@ -2662,9 +2662,9 @@ void SpriteCB_LinkPlayer(struct Sprite *sprite) SetObjectSubpriorityByZCoord(mapObj->elevation, sprite, 1); sprite->oam.priority = ZCoordToPriority(mapObj->elevation); if (!linkPlayerMapObj->mode) - StartSpriteAnim(sprite, FieldObjectDirectionToImageAnimId(mapObj->mapobj_unk_19)); + StartSpriteAnim(sprite, FieldObjectDirectionToImageAnimId(mapObj->range.as_byte)); else - StartSpriteAnimIfDifferent(sprite, get_go_image_anim_num(mapObj->mapobj_unk_19)); + StartSpriteAnimIfDifferent(sprite, get_go_image_anim_num(mapObj->range.as_byte)); sub_806487C(sprite, 0); if (mapObj->mapobj_bit_2) { diff --git a/src/field/trainer_see.c b/src/field/trainer_see.c index 4e92d95ca..3034b2b65 100644 --- a/src/field/trainer_see.c +++ b/src/field/trainer_see.c @@ -14,7 +14,7 @@ static void sub_8084894(struct Sprite *sprite, u16 a2, u8 a3); static void objc_exclamation_mark_probably(struct Sprite *sprite); static bool8 TrainerCanApproachPlayer(struct MapObject *); static void sub_80842C8(struct MapObject *, u8); -static bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject2 *trainerObj, u8 approachDistance, u8 direction); +static bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject *trainerObj, u8 approachDistance, u8 direction); static void RunTrainerSeeFuncList(u8 taskId); const u8 gSpriteImage_839B308[] = INCBIN_U8("graphics/unknown_sprites/839B4E0/0.4bpp"); @@ -84,14 +84,14 @@ static bool8 TrainerCanApproachPlayer(struct MapObject *trainerObj) if (trainerObj->trainerType == 1) // can only see in one direction { approachDistance = sDirectionalApproachDistanceFuncs[trainerObj->mapobj_unk_18 - 1](trainerObj, trainerObj->trainerRange_berryTreeId, x, y); - return CheckPathBetweenTrainerAndPlayer((struct MapObject2 *)trainerObj, approachDistance, trainerObj->mapobj_unk_18); + return CheckPathBetweenTrainerAndPlayer(trainerObj, approachDistance, trainerObj->mapobj_unk_18); } else // can see in all directions { for (i = 0; i < 4; i++) { approachDistance = sDirectionalApproachDistanceFuncs[i](trainerObj, trainerObj->trainerRange_berryTreeId, x, y); - if (CheckPathBetweenTrainerAndPlayer((struct MapObject2 *)trainerObj, approachDistance, i + 1)) // directions are 1-4 instead of 0-3. south north west east + if (CheckPathBetweenTrainerAndPlayer(trainerObj, approachDistance, i + 1)) // directions are 1-4 instead of 0-3. south north west east return approachDistance; } } @@ -148,7 +148,7 @@ static u8 GetTrainerApproachDistanceEast(struct MapObject *trainerObj, s16 range #define COLLISION_MASK 1 #endif -static bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject2 *trainerObj, u8 approachDistance, u8 direction) +static bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject *trainerObj, u8 approachDistance, u8 direction) { s16 x, y; u8 unk19_temp; @@ -164,21 +164,21 @@ static bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject2 *trainerObj, u8 for (i = 0; i <= approachDistance - 1; i++, MoveCoords(direction, &x, &y)) { - collision = sub_8060024((struct MapObject *)trainerObj, x, y, direction); + collision = sub_8060024(trainerObj, x, y, direction); if (collision != 0 && (collision & COLLISION_MASK)) return FALSE; } // preserve mapobj_unk_19 before clearing. - unk19_temp = trainerObj->mapobj_unk_19; - unk19b_temp = trainerObj->mapobj_unk_19b; - trainerObj->mapobj_unk_19 = 0; - trainerObj->mapobj_unk_19b = 0; + unk19_temp = trainerObj->range.as_nybbles.x; + unk19b_temp = trainerObj->range.as_nybbles.y; + trainerObj->range.as_nybbles.x = 0; + trainerObj->range.as_nybbles.y = 0; collision = npc_block_way((struct MapObject *)trainerObj, x, y, direction); - trainerObj->mapobj_unk_19 = unk19_temp; - trainerObj->mapobj_unk_19b = unk19b_temp; + trainerObj->range.as_nybbles.x = unk19_temp; + trainerObj->range.as_nybbles.y = unk19b_temp; if (collision == 4) return approachDistance; |