diff --git a/include/constants/union_room.h b/include/constants/union_room.h index 9243ea15d..7b1d1a1be 100644 --- a/include/constants/union_room.h +++ b/include/constants/union_room.h @@ -1,6 +1,8 @@ #ifndef GUARD_CONSTANTS_UNION_ROOM_H #define GUARD_CONSTANTS_UNION_ROOM_H +#define MAX_UNION_ROOM_PLAYERS 8 + #define UNION_ROOM_SPAWN_NONE 0 #define UNION_ROOM_SPAWN_IN 1 #define UNION_ROOM_SPAWN_OUT 2 diff --git a/include/event_object_movement.h b/include/event_object_movement.h index f0caa38aa..6ccd4759e 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -81,11 +81,11 @@ void sub_808E16C(s16, s16); void OverrideSecretBaseDecorationSpriteScript(u8 localId, u8 mapNum, u8 mapGroup, u8 decorCat); void sub_8092FF0(s16, s16, s16 *, s16 *); u8 GetFaceDirectionAnimNum(u8); -void sub_80930E0(s16 *, s16 *, s16, s16); +void SetSpritePosToOffsetMapCoords(s16 *, s16 *, s16, s16); void ObjectEventClearHeldMovement(struct ObjectEvent *); void ObjectEventClearHeldMovementIfActive(struct ObjectEvent *); void TrySpawnObjectEvents(s16, s16); -u8 sprite_new(u8 graphicsId, u8 a1, s16 x, s16 y, u8 z, u8 direction); +u8 CreateObjectSprite(u8 graphicsId, u8 a1, s16 x, s16 y, u8 z, u8 direction); u8 AddPseudoObjectEvent(u16, void (*)(struct Sprite *), s16 x, s16 y, u8 subpriority); u8 TrySpawnObjectEvent(u8, u8, u8); u8 SpawnSpecialObjectEventParameterized(u8 graphicsId, u8 movementBehavior, u8 localId, s16 x, s16 y, u8 z); @@ -180,7 +180,7 @@ void CreateLevitateMovementTask(struct ObjectEvent *); void DestroyExtraMovementTask(u8); void UnfreezeObjectEvents(void); void FreezeObjectEventsExceptOne(u8 objectEventId); -void sub_8097B78(u8, u8); +void TurnObjectEventSprite(u8, u8); void sub_8098074(u8 var1, u8 var2); void FreezeObjectEvents(void); bool8 FreezeObjectEvent(struct ObjectEvent *objectEvent); @@ -194,7 +194,7 @@ void UpdateObjectEventSpriteVisibility(struct Sprite *sprite, bool8 invisible); s16 sub_809773C(s16 a1); s16 sub_8097728(s16 a1); void CameraObjectReset2(void); -u8 ObjectEventGetBerryTreeId(u8 objectEventId); +u8 GetObjectEventBerryTreeId(u8 objectEventId); void sub_8092EF0(u8 mapId, u8 mapNumber, u8 mapGroup); bool8 IsBerryTreeSparkling(u8, u8, u8); @@ -414,10 +414,10 @@ u8 MovementType_RunInPlace_Step0(struct ObjectEvent *, struct Sprite *); u8 MovementType_Invisible_Step0(struct ObjectEvent *, struct Sprite *); u8 MovementType_Invisible_Step1(struct ObjectEvent *, struct Sprite *); u8 MovementType_Invisible_Step2(struct ObjectEvent *, struct Sprite *); -void sub_8097C44(u8 var, bool32 var2); -bool32 sub_8097C8C(u8 var); -void sub_8097BB4(u8 var1, u8 graphicsId); -void sub_8097CC4(u8 var1, u8 var2); -bool32 sub_8097D9C(u8 var); +void SetObjectEventSpriteInvisibility(u8 var, bool32 var2); +bool32 IsObjectEventSpriteInvisible(u8 var); +void SetObjectEventSpriteGraphics(u8 var1, u8 graphicsId); +void SetObjectEventSpriteAnim(u8 var1, u8 var2); +bool32 IsObjectEventSpriteAnimating(u8 var); #endif //GUARD_EVENT_OBJECT_MOVEMENT_H diff --git a/include/fieldmap.h b/include/fieldmap.h index dc81d1766..aff458eb1 100644 --- a/include/fieldmap.h +++ b/include/fieldmap.h @@ -43,6 +43,7 @@ void copy_map_tileset1_to_vram(const struct MapLayout *); void copy_map_tileset2_to_vram(const struct MapLayout *); struct MapHeader const *const mapconnection_get_mapheader(struct MapConnection *connection); struct MapConnection *GetConnectionAtCoords(s16 x, s16 y); +void MapGridSetMetatileImpassabilityAt(int x, int y, bool32 impassable); void SpriteCB_PokeballGlow(struct Sprite *); void SpriteCB_PokecenterMonitor(struct Sprite *); @@ -50,6 +51,5 @@ void SpriteCB_HallOfFameMonitor(struct Sprite *); // field_region_map.c void FieldInitRegionMap(MainCallback callback); -void sub_8088B94(int x, int y, int a2); #endif //GUARD_FIELDMAP_H diff --git a/include/union_room.h b/include/union_room.h index 0f0075344..4cdb17662 100644 --- a/include/union_room.h +++ b/include/union_room.h @@ -2,6 +2,7 @@ #define GUARD_UNION_ROOM_H #include "link_rfu.h" +#include "constants/union_room.h" // Exported type declarations @@ -31,7 +32,7 @@ struct UnkStruct_x20 // WirelessLink_Member? struct UnkStruct_Main0 { - struct UnkStruct_x20 arr[8]; + struct UnkStruct_x20 arr[MAX_UNION_ROOM_PLAYERS]; }; struct UnkStruct_Main4 @@ -85,12 +86,12 @@ struct WirelessLink_Group u8 delayBeforePrint; }; -struct UnkStruct_8019BA8 +struct UnionRoomObject { - u8 field_0; - u8 field_1; - s8 field_2; - u8 field_3; + u8 state; + u8 gfxId; + s8 animState; + u8 schedAnim; }; struct WirelessLink_URoom @@ -121,7 +122,7 @@ struct WirelessLink_URoom u8 activityRequestStrbufs[4][16]; u16 partnerYesNoResponse; u16 recvActivityRequest[3]; - struct UnkStruct_8019BA8 field_A0[8]; + struct UnionRoomObject objects[MAX_UNION_ROOM_PLAYERS]; u8 field_C0[12][15]; u8 field_174[48]; u8 field_1A4[200]; diff --git a/include/union_room_player_avatar.h b/include/union_room_player_avatar.h index 698fc1693..072126949 100644 --- a/include/union_room_player_avatar.h +++ b/include/union_room_player_avatar.h @@ -1,14 +1,14 @@ #ifndef GUARD_UNION_ROOM_PLAYER_AVATAR_H #define GUARD_UNION_ROOM_PLAYER_AVATAR_H -u8 sub_8019BA8(struct UnkStruct_8019BA8 * ptr); -void sub_8019E3C(void); -void CreateGroupMemberObjectsInvisible(u8 *arg0, s32 arg1); -void DestroyGroupMemberObjects(u8 *spriteIds); -void sub_8019F2C(void); -void ScheduleUnionRoomPlayerRefresh(struct WirelessLink_URoom *arg0); -void HandleUnionRoomPlayerRefresh(struct WirelessLink_URoom *arg0); -bool32 RfuUnionTool_GetGroupAndMemberInFrontOfPlayer(struct UnkStruct_Main0 *arg0, s16 *arg1, s16 *arg2, u8 *arg3); -void UpdateUnionGroupMemberFacing(u32 arg0, u32 arg1, struct UnkStruct_Main0 *arg2); +u8 InitUnionRoomPlayerObjects(struct UnionRoomObject *players); +void DestroyUnionRoomPlayerObjects(void); +void CreateGroupMemberSpritesInvisible(u8 *spriteIds, s32 playerIdx); +void DestroyGroupMemberSprites(u8 *spriteIds); +void SetTilesAroundUnionRoomPlayersPassable(void); +void ScheduleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom); +void HandleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom); +bool32 TrySetUnionRoomMemberFacePlayer(struct UnkStruct_Main0 *main0, s16 *directionPtr, s16 *playerIdxPtr, u8 *spriteIds); +void UpdateUnionRoomMemberFacing(u32 currDirection, u32 playerIdx, struct UnkStruct_Main0 *main0); #endif //GUARD_UNION_ROOM_PLAYER_AVATAR_H diff --git a/src/berry.c b/src/berry.c index fe4a66af6..98264f37b 100644 --- a/src/berry.c +++ b/src/berry.c @@ -997,7 +997,7 @@ struct BerryTree *GetBerryTreeInfo(u8 id) bool32 ObjectEventInteractionWaterBerryTree(void) { - struct BerryTree *tree = GetBerryTreeInfo(ObjectEventGetBerryTreeId(gSelectedObjectEvent)); + struct BerryTree *tree = GetBerryTreeInfo(GetObjectEventBerryTreeId(gSelectedObjectEvent)); switch (tree->stage) { @@ -1022,7 +1022,7 @@ bool32 ObjectEventInteractionWaterBerryTree(void) bool8 IsPlayerFacingEmptyBerryTreePatch(void) { if (GetObjectEventScriptPointerPlayerFacing() == BerryTreeScript - && GetStageByBerryTreeId(ObjectEventGetBerryTreeId(gSelectedObjectEvent)) == BERRY_STAGE_NO_BERRY) + && GetStageByBerryTreeId(GetObjectEventBerryTreeId(gSelectedObjectEvent)) == BERRY_STAGE_NO_BERRY) return TRUE; else return FALSE; @@ -1260,7 +1260,7 @@ void ObjectEventInteractionGetBerryTreeData(void) u8 group; u8 num; - id = ObjectEventGetBerryTreeId(gSelectedObjectEvent); + id = GetObjectEventBerryTreeId(gSelectedObjectEvent); berry = GetBerryTypeByBerryTreeId(id); ResetBerryTreeSparkleFlag(id); localId = gSpecialVar_LastTalked; @@ -1277,13 +1277,13 @@ void ObjectEventInteractionGetBerryTreeData(void) void ObjectEventInteractionGetBerryName(void) { - u8 berryType = GetBerryTypeByBerryTreeId(ObjectEventGetBerryTreeId(gSelectedObjectEvent)); + u8 berryType = GetBerryTypeByBerryTreeId(GetObjectEventBerryTreeId(gSelectedObjectEvent)); GetBerryNameByBerryType(berryType, gStringVar1); } void ObjectEventInteractionGetBerryCountString(void) { - u8 treeId = ObjectEventGetBerryTreeId(gSelectedObjectEvent); + u8 treeId = GetObjectEventBerryTreeId(gSelectedObjectEvent); u8 berry = GetBerryTypeByBerryTreeId(treeId); u8 count = GetBerryCountByBerryTreeId(treeId); GetBerryCountStringByBerryType(berry, gStringVar1, count); @@ -1298,13 +1298,13 @@ void ObjectEventInteractionPlantBerryTree(void) { u8 berry = ItemIdToBerryType(gSpecialVar_ItemId); - PlantBerryTree(ObjectEventGetBerryTreeId(gSelectedObjectEvent), berry, 1, TRUE); + PlantBerryTree(GetObjectEventBerryTreeId(gSelectedObjectEvent), berry, 1, TRUE); ObjectEventInteractionGetBerryTreeData(); } void ObjectEventInteractionPickBerryTree(void) { - u8 id = ObjectEventGetBerryTreeId(gSelectedObjectEvent); + u8 id = GetObjectEventBerryTreeId(gSelectedObjectEvent); u8 berry = GetBerryTypeByBerryTreeId(id); gSpecialVar_0x8004 = AddBagItem(BerryTypeToItemId(berry), GetBerryCountByBerryTreeId(id)); @@ -1312,7 +1312,7 @@ void ObjectEventInteractionPickBerryTree(void) void ObjectEventInteractionRemoveBerryTree(void) { - RemoveBerryTree(ObjectEventGetBerryTreeId(gSelectedObjectEvent)); + RemoveBerryTree(GetObjectEventBerryTreeId(gSelectedObjectEvent)); sub_8092EF0(gSpecialVar_LastTalked, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); } diff --git a/src/event_object_movement.c b/src/event_object_movement.c index d6a2fe2ec..ad839e006 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -28,6 +28,7 @@ #include "constants/items.h" #include "constants/mauville_old_man.h" #include "constants/trainer_types.h" +#include "constants/union_room.h" // this file was known as evobjmv.c in Game Freak's original source @@ -97,7 +98,7 @@ static void DoRippleFieldEffect(struct ObjectEvent*, struct Sprite*); static void DoGroundEffects_OnSpawn(struct ObjectEvent*, struct Sprite*); static void DoGroundEffects_OnBeginStep(struct ObjectEvent*, struct Sprite*); static void DoGroundEffects_OnFinishStep(struct ObjectEvent*, struct Sprite*); -static void sub_8097D68(struct Sprite*); +static void UpdateObjectEventSpritePosition(struct Sprite*); static void ApplyLevitateMovement(u8); static bool8 MovementType_Disguise_Callback(struct ObjectEvent *, struct Sprite *); static bool8 MovementType_Hidden_Callback(struct ObjectEvent *, struct Sprite *); @@ -129,7 +130,7 @@ static struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8 localId, static void ClearObjectEventMovement(struct ObjectEvent *, struct Sprite *); static void ObjectEventSetSingleMovement(struct ObjectEvent *, struct Sprite *, u8); static void oamt_npc_ministep_reset(struct Sprite *, u8, u8); -static void UpdateObjectEventSpriteSubpriorityAndVisibility(struct Sprite *); +static void UpdateObjectEventSprite(struct Sprite *); const u8 gReflectionEffectPaletteMap[] = {1, 1, 6, 7, 8, 9, 6, 7, 8, 9, 11, 11, 0, 0, 0, 0}; @@ -1522,7 +1523,9 @@ u8 AddPseudoObjectEvent(u16 graphicsId, void (*callback)(struct Sprite *), s16 x return spriteId; } -u8 sprite_new(u8 graphicsId, u8 a1, s16 x, s16 y, u8 z, u8 direction) +// Used to create sprite object events instead of a full object event +// Used when resources are limiting, e.g. for the audience in contests or group members in Union Room +u8 CreateObjectSprite(u8 graphicsId, u8 a1, s16 x, s16 y, u8 z, u8 direction) { u8 spriteId; struct Sprite *sprite; @@ -1531,11 +1534,11 @@ u8 sprite_new(u8 graphicsId, u8 a1, s16 x, s16 y, u8 z, u8 direction) const struct ObjectEventGraphicsInfo *graphicsInfo; graphicsInfo = GetObjectEventGraphicsInfo(graphicsId); - MakeObjectTemplateFromObjectEventGraphicsInfo(graphicsId, UpdateObjectEventSpriteSubpriorityAndVisibility, &spriteTemplate, &subspriteTables); + MakeObjectTemplateFromObjectEventGraphicsInfo(graphicsId, UpdateObjectEventSprite, &spriteTemplate, &subspriteTables); *(u16 *)&spriteTemplate.paletteTag = 0xFFFF; x += 7; y += 7; - sub_80930E0(&x, &y, 8, 16); + SetSpritePosToOffsetMapCoords(&x, &y, 8, 16); spriteId = CreateSpriteAtEnd(&spriteTemplate, x, y, 0); if (spriteId != MAX_SPRITES) { @@ -2363,7 +2366,8 @@ static u8 GetObjectTrainerTypeByObjectEventId(u8 objectEventId) return gObjectEvents[objectEventId].trainerType; } -u8 sub_808F0D4(u8 localId, u8 mapNum, u8 mapGroup) +// Unused +u8 GetObjectEventBerryTreeIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup) { u8 objectEventId; @@ -2374,7 +2378,7 @@ u8 sub_808F0D4(u8 localId, u8 mapNum, u8 mapGroup) return gObjectEvents[objectEventId].trainerRange_berryTreeId; } -u8 ObjectEventGetBerryTreeId(u8 objectEventId) +u8 GetObjectEventBerryTreeId(u8 objectEventId) { return gObjectEvents[objectEventId].trainerRange_berryTreeId; } @@ -4864,22 +4868,22 @@ void SetSpritePosToMapCoords(s16 mapX, s16 mapY, s16 *destX, s16 *destY) s16 dx = -gTotalCameraPixelOffsetX - gFieldCamera.x; s16 dy = -gTotalCameraPixelOffsetY - gFieldCamera.y; if (gFieldCamera.x > 0) - dx += 1 << 4; + dx += 16; if (gFieldCamera.x < 0) - dx -= 1 << 4; + dx -= 16; if (gFieldCamera.y > 0) - dy += 1 << 4; + dy += 16; if (gFieldCamera.y < 0) - dy -= 1 << 4; + dy -= 16; *destX = ((mapX - gSaveBlock1Ptr->pos.x) << 4) + dx; *destY = ((mapY - gSaveBlock1Ptr->pos.y) << 4) + dy; } -void sub_80930E0(s16 *x, s16 *y, s16 dx, s16 dy) +void SetSpritePosToOffsetMapCoords(s16 *x, s16 *y, s16 dx, s16 dy) { SetSpritePosToMapCoords(*x, *y, x, y); *x += dx; @@ -8630,51 +8634,56 @@ void UpdateObjectEventSpriteVisibility(struct Sprite *sprite, bool8 invisible) sprite->invisible = TRUE; } -static void UpdateObjectEventSpriteSubpriorityAndVisibility(struct Sprite *sprite) +#define tInvisible data[2] +#define tAnimNum data[3] +#define tAnimState data[4] + +static void UpdateObjectEventSprite(struct Sprite *sprite) { - sub_8097D68(sprite); + UpdateObjectEventSpritePosition(sprite); SetObjectSubpriorityByZCoord(sprite->data[1], sprite, 1); - UpdateObjectEventSpriteVisibility(sprite, sprite->data[2]); + UpdateObjectEventSpriteVisibility(sprite, sprite->tInvisible); } -void sub_8097AF0(void) +// Unused +static void DestroyObjectEventSprites(void) { int i; - for(i = 0; i < MAX_SPRITES; i++) + for (i = 0; i < MAX_SPRITES; i++) { struct Sprite *sprite = &gSprites[i]; - if(sprite->inUse && sprite->callback == UpdateObjectEventSpriteSubpriorityAndVisibility) + if(sprite->inUse && sprite->callback == UpdateObjectEventSprite) DestroySprite(sprite); } } -int sub_8097B2C(u8 var) // this should return a u8, because all that call this shifts to u8, but it wont match because it doesnt shift u8 at the end. +static int GetObjectEventSpriteId(u8 var) // this should return a u8, because all that call this shifts to u8, but it wont match because it doesnt shift u8 at the end. { int i; - for(i = 0; i < MAX_SPRITES; i++) + for (i = 0; i < MAX_SPRITES; i++) { struct Sprite *sprite = &gSprites[i]; - if(sprite->inUse && sprite->callback == UpdateObjectEventSpriteSubpriorityAndVisibility && (u8)sprite->data[0] == var) + if(sprite->inUse && sprite->callback == UpdateObjectEventSprite && (u8)sprite->data[0] == var) return i; } return MAX_SPRITES; } -void sub_8097B78(u8 var1, u8 var2) +void TurnObjectEventSprite(u8 objectEventId, u8 direction) { - u8 spriteId = sub_8097B2C(var1); + u8 spriteId = GetObjectEventSpriteId(objectEventId); - if(spriteId != MAX_SPRITES) - StartSpriteAnim(&gSprites[spriteId], GetFaceDirectionAnimNum(var2)); + if (spriteId != MAX_SPRITES) + StartSpriteAnim(&gSprites[spriteId], GetFaceDirectionAnimNum(direction)); } -void sub_8097BB4(u8 var1, u8 graphicsId) +void SetObjectEventSpriteGraphics(u8 objectEventId, u8 graphicsId) { - int spriteId = sub_8097B2C(var1); + int spriteId = GetObjectEventSpriteId(objectEventId); - if(spriteId != MAX_SPRITES) + if (spriteId != MAX_SPRITES) { struct Sprite *sprite = &gSprites[spriteId]; const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(graphicsId); @@ -8685,7 +8694,7 @@ void sub_8097BB4(u8 var1, u8 graphicsId) sprite->oam.paletteNum = graphicsInfo->paletteSlot; sprite->images = graphicsInfo->images; - if(graphicsInfo->subspriteTables == NULL) + if (graphicsInfo->subspriteTables == NULL) { sprite->subspriteTables = NULL; sprite->subspriteTableNum = 0; @@ -8700,102 +8709,102 @@ void sub_8097BB4(u8 var1, u8 graphicsId) } } -void sub_8097C44(u8 var, bool32 var2) +void SetObjectEventSpriteInvisibility(u8 objectEventId, bool32 invisible) { - u8 spriteId = sub_8097B2C(var); + u8 spriteId = GetObjectEventSpriteId(objectEventId); - if(spriteId == MAX_SPRITES) + if (spriteId == MAX_SPRITES) return; - if(var2) - gSprites[spriteId].data[2] = 1; + if (invisible) + gSprites[spriteId].tInvisible = TRUE; else - gSprites[spriteId].data[2] = 0; + gSprites[spriteId].tInvisible = FALSE; } -bool32 sub_8097C8C(u8 var) +bool32 IsObjectEventSpriteInvisible(u8 objectEventId) { - u8 spriteId = sub_8097B2C(var); + u8 spriteId = GetObjectEventSpriteId(objectEventId); - if(spriteId == MAX_SPRITES) + if (spriteId == MAX_SPRITES) return FALSE; - return (gSprites[spriteId].data[2] == TRUE); + return (gSprites[spriteId].tInvisible == TRUE); } -void sub_8097CC4(u8 var1, u8 var2) +void SetObjectEventSpriteAnim(u8 objectEventId, u8 animNum) { - u8 spriteId = sub_8097B2C(var1); + u8 spriteId = GetObjectEventSpriteId(objectEventId); - if(spriteId != MAX_SPRITES) + if (spriteId != MAX_SPRITES) { - gSprites[spriteId].data[3] = var2; - gSprites[spriteId].data[4] = 0; + gSprites[spriteId].tAnimNum = animNum; + gSprites[spriteId].tAnimState = 0; } } -void sub_8097CF4(struct Sprite *sprite) +static void MoveUnionRoomObjectUp(struct Sprite *sprite) { - switch(sprite->data[4]) + switch(sprite->tAnimState) { case 0: sprite->pos2.y = 0; - sprite->data[4]++; + sprite->tAnimState++; case 1: sprite->pos2.y -= 8; - if(sprite->pos2.y == -160) + if (sprite->pos2.y == -160) { sprite->pos2.y = 0; - sprite->data[2] = 1; - sprite->data[3] = 0; - sprite->data[4] = 0; + sprite->tInvisible = TRUE; + sprite->tAnimNum = 0; + sprite->tAnimState = 0; } } } -void sub_8097D30(struct Sprite *sprite) +static void MoveUnionRoomObjectDown(struct Sprite *sprite) { - switch(sprite->data[4]) + switch(sprite->tAnimState) { case 0: sprite->pos2.y = -160; - sprite->data[4]++; + sprite->tAnimState++; case 1: sprite->pos2.y += 8; if(sprite->pos2.y == 0) { - sprite->data[3] = 0; - sprite->data[4] = 0; + sprite->tAnimNum = 0; + sprite->tAnimState = 0; } } } -static void sub_8097D68(struct Sprite *sprite) +static void UpdateObjectEventSpritePosition(struct Sprite *sprite) { - switch(sprite->data[3]) + switch(sprite->tAnimNum) { - case 1: - sub_8097D30(sprite); + case UNION_ROOM_SPAWN_IN: + MoveUnionRoomObjectDown(sprite); break; - case 2: - sub_8097CF4(sprite); + case UNION_ROOM_SPAWN_OUT: + MoveUnionRoomObjectUp(sprite); break; case 0: break; default: - sprite->data[3] = 0; + sprite->tAnimNum = 0; break; } } -bool32 sub_8097D9C(u8 var) +bool32 IsObjectEventSpriteAnimating(u8 var) { - u8 spriteId = sub_8097B2C(var); + u8 spriteId = GetObjectEventSpriteId(var); - if(spriteId == MAX_SPRITES) + if (spriteId == MAX_SPRITES) return FALSE; - if(gSprites[spriteId].data[3] != FALSE) + if (gSprites[spriteId].tAnimNum != 0) return TRUE; return FALSE; diff --git a/src/faraway_island.c b/src/faraway_island.c index f8e3eac14..2ac9d5c1f 100755 --- a/src/faraway_island.c +++ b/src/faraway_island.c @@ -378,7 +378,7 @@ void sub_81D4A90(void) x = mew->currentCoords.x; y = mew->currentCoords.y; - sub_80930E0(&x, &y, 8, 8); + SetSpritePosToOffsetMapCoords(&x, &y, 8, 8); sUnknown_0203CF50 = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[15], x, y, gSprites[mew->spriteId].subpriority - 1); if (sUnknown_0203CF50 != MAX_SPRITES) { diff --git a/src/field_effect.c b/src/field_effect.c index c4e9fc40a..07579f55d 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -2043,7 +2043,7 @@ static bool8 LavaridgeGymB1FWarpExitEffect_4(struct Task *task, struct ObjectEve u8 FldEff_LavaridgeGymWarp(void) { u8 spriteId; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[33], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); gSprites[spriteId].oam.priority = gFieldEffectArguments[3]; gSprites[spriteId].coordOffsetEnabled = 1; @@ -2136,7 +2136,7 @@ static bool8 LavaridgeGym1FWarpEffect_5(struct Task *task, struct ObjectEvent *o u8 FldEff_PopOutOfAsh(void) { u8 spriteId; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[32], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); gSprites[spriteId].oam.priority = gFieldEffectArguments[3]; gSprites[spriteId].coordOffsetEnabled = 1; diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index 52c30ab0f..e02de959b 100755 --- a/src/field_effect_helpers.c +++ b/src/field_effect_helpers.c @@ -274,7 +274,7 @@ u32 FldEff_TallGrass(void) x = gFieldEffectArguments[0]; y = gFieldEffectArguments[1]; - sub_80930E0(&x, &y, 8, 8); + SetSpritePosToOffsetMapCoords(&x, &y, 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[4], x, y, 0); if (spriteId != MAX_SPRITES) { @@ -340,7 +340,7 @@ u32 FldEff_JumpTallGrass(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 12); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 12); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[10], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { @@ -380,7 +380,7 @@ u32 FldEff_LongGrass(void) x = gFieldEffectArguments[0]; y = gFieldEffectArguments[1]; - sub_80930E0(&x, &y, 8, 8); + SetSpritePosToOffsetMapCoords(&x, &y, 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[15], x, y, 0); if (spriteId != MAX_SPRITES) { @@ -443,7 +443,7 @@ u32 FldEff_JumpLongGrass(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[16], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { @@ -521,7 +521,7 @@ u32 FldEff_SandFootprints(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[11], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { @@ -539,7 +539,7 @@ u32 FldEff_DeepSandFootprints(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[23], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { @@ -557,7 +557,7 @@ u32 FldEff_BikeTireTracks(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[27], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { @@ -649,7 +649,7 @@ u32 FldEff_JumpSmallSplash(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 12); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 12); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[14], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { @@ -667,7 +667,7 @@ u32 FldEff_JumpBigSplash(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[12], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { @@ -805,7 +805,7 @@ u32 FldEff_Unknown19(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[17], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { @@ -822,7 +822,7 @@ u32 FldEff_Unknown20(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[18], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { @@ -839,7 +839,7 @@ u32 FldEff_Unknown21(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[19], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { @@ -856,7 +856,7 @@ u32 FldEff_Unknown22(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[20], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { @@ -888,7 +888,7 @@ u32 FldEff_Ash(void) x = gFieldEffectArguments[0]; y = gFieldEffectArguments[1]; - sub_80930E0(&x, &y, 8, 8); + SetSpritePosToOffsetMapCoords(&x, &y, 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[6], x, y, gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { @@ -944,7 +944,7 @@ u32 FldEff_SurfBlob(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[7], gFieldEffectArguments[0], gFieldEffectArguments[1], 0x96); if (spriteId !=MAX_SPRITES) { @@ -1106,7 +1106,7 @@ u32 FldEff_Dust(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 12); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 12); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[9], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { @@ -1182,7 +1182,7 @@ u32 FldEff_Bubbles(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 0); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 0); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[34], gFieldEffectArguments[0], gFieldEffectArguments[1], 0x52); if (spriteId != MAX_SPRITES) { @@ -1210,7 +1210,7 @@ u32 FldEff_BerryTreeGrowthSparkle(void) u8 spriteId; struct Sprite *sprite; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 4); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 4); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[22], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { @@ -1330,7 +1330,7 @@ u32 FldEff_Sparkle(void) gFieldEffectArguments[0] += 7; gFieldEffectArguments[1] += 7; - sub_80930E0((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[35], gFieldEffectArguments[0], gFieldEffectArguments[1], 0x52); if (spriteId != MAX_SPRITES) { diff --git a/src/fieldmap.c b/src/fieldmap.c index 21bbaa8f8..753f4451f 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -917,11 +917,11 @@ void GetCameraCoords(u16 *x, u16 *y) *y = gSaveBlock1Ptr->pos.y; } -void sub_8088B94(int x, int y, int a2) +void MapGridSetMetatileImpassabilityAt(int x, int y, bool32 impassable) { if (x >= 0 && x < gBackupMapLayout.width && y >= 0 && y < gBackupMapLayout.height) { - if (a2 != 0) + if (impassable) gBackupMapLayout.map[x + gBackupMapLayout.width * y] |= METATILE_COLLISION_MASK; else gBackupMapLayout.map[x + gBackupMapLayout.width * y] &= ~METATILE_COLLISION_MASK; diff --git a/src/fldeff_misc.c b/src/fldeff_misc.c index 9574ac563..ab04e47ff 100644 --- a/src/fldeff_misc.c +++ b/src/fldeff_misc.c @@ -1008,7 +1008,7 @@ void DoSecretBaseGlitterMatSparkle(void) s16 y = gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.y; u8 spriteId; - sub_80930E0(&x, &y, 8, 4); + SetSpritePosToOffsetMapCoords(&x, &y, 8, 4); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[22], x, y, 0); if (spriteId != MAX_SPRITES) diff --git a/src/scrcmd.c b/src/scrcmd.c index ad01791a9..d7d52b349 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1185,22 +1185,22 @@ bool8 ScrCmd_setobjectmovementtype(struct ScriptContext *ctx) bool8 ScrCmd_createvobject(struct ScriptContext *ctx) { u8 graphicsId = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); + u8 objectEventId = ScriptReadByte(ctx); u16 x = VarGet(ScriptReadHalfword(ctx)); u32 y = VarGet(ScriptReadHalfword(ctx)); u8 elevation = ScriptReadByte(ctx); u8 direction = ScriptReadByte(ctx); - sprite_new(graphicsId, v2, x, y, elevation, direction); + CreateObjectSprite(graphicsId, objectEventId, x, y, elevation, direction); return FALSE; } bool8 ScrCmd_turnvobject(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); + u8 objectEventId = ScriptReadByte(ctx); u8 direction = ScriptReadByte(ctx); - sub_8097B78(v1, direction); + TurnObjectEventSprite(objectEventId, direction); return FALSE; } diff --git a/src/union_room.c b/src/union_room.c index 28e1139dd..9687502b4 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -53,7 +53,6 @@ #include "constants/rgb.h" #include "constants/songs.h" #include "constants/species.h" -#include "constants/union_room.h" static EWRAM_DATA u8 sUnionRoomPlayerName[12] = {}; EWRAM_DATA u8 gPlayerCurrActivity = 0; @@ -104,7 +103,7 @@ static bool32 AreUnionRoomPlayerGnamesDifferent(struct WirelessGnameUnamePair *a static u32 GetPartyPositionOfRegisteredMon(struct UnionRoomTrade *arg0, u8 multiplayerId); static void ResetUnionRoomTrade(struct UnionRoomTrade *arg0); static void CreateTask_StartActivity(void); -static bool32 GetGnameWonderFlagByLinkGroup(struct GFtgtGname *arg0, s16 arg1); +static bool32 HasWonderCardOrNewsByLinkGroup(struct GFtgtGname *arg0, s16 arg1); static u8 CreateTask_SearchForChildOrParent(struct UnkStruct_Main4 *arg0, struct UnkStruct_Main4 *arg1, u32 arg2); static bool32 RegisterTradeMonAndGetIsEgg(u32 monId, struct UnionRoomTrade *trade); static void RegisterTradeMon(u32 monId, struct UnionRoomTrade *arg1); @@ -1191,14 +1190,14 @@ static void Task_ListenToWireless(u8 taskId) } } -static bool32 IsPartnerActivityAcceptable(u32 activity, u32 group) +static bool32 IsPartnerActivityAcceptable(u32 activity, u32 linkGroup) { - if (group == 0xFF) + if (linkGroup == 0xFF) return TRUE; - if (group <= ARRAY_COUNT(sAcceptedActivityIds)) // UB: <= may access data outside the array + if (linkGroup <= ARRAY_COUNT(sAcceptedActivityIds)) // UB: <= may access data outside the array { - const u8 *bytes = sAcceptedActivityIds[group]; + const u8 *bytes = sAcceptedActivityIds[linkGroup]; while ((*(bytes) != 0xFF)) { @@ -2149,7 +2148,7 @@ static void Task_CardOrNewsOverWireless(u8 taskId) { if (data->field_0->arr[0].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[0].gname_uname.gname.started) { - if (GetGnameWonderFlagByLinkGroup(&data->field_0->arr[0].gname_uname.gname, data->isWonderNews + LINK_GROUP_WONDER_CARD)) + if (HasWonderCardOrNewsByLinkGroup(&data->field_0->arr[0].gname_uname.gname, data->isWonderNews + LINK_GROUP_WONDER_CARD)) { data->leaderId = 0; data->refreshTimer = 0; @@ -2325,15 +2324,15 @@ static void Task_RunUnionRoom(u8 taskId) data->field_C = AllocZeroed(RFU_CHILD_MAX * sizeof(struct UnkStruct_x1C)); data->field_0 = AllocZeroed(8 * sizeof(struct UnkStruct_x20)); data->field_8 = AllocZeroed(sizeof(struct UnkStruct_x20)); - ClearUnkStruct_x20Array(data->field_0->arr, 8); + ClearUnkStruct_x20Array(data->field_0->arr, ARRAY_COUNT(data->field_0->arr)); gPlayerCurrActivity = IN_UNION_ROOM; data->field_20 = CreateTask_SearchForChildOrParent(data->field_C, data->field_4, LINK_GROUP_UNION_ROOM_RESUME); - sub_8019BA8(data->field_A0); - sub_8019F2C(); + InitUnionRoomPlayerObjects(data->objects); + SetTilesAroundUnionRoomPlayersPassable(); data->state = 1; break; case 1: - CreateGroupMemberObjectsInvisible(data->spriteIds, taskData[0]); + CreateGroupMemberSpritesInvisible(data->spriteIds, taskData[0]); if (++taskData[0] == 8) data->state = 2; break; @@ -2426,7 +2425,7 @@ static void Task_RunUnionRoom(u8 taskId) { if (gMain.newKeys & A_BUTTON) { - if (RfuUnionTool_GetGroupAndMemberInFrontOfPlayer(data->field_0, &taskData[0], &taskData[1], data->spriteIds)) + if (TrySetUnionRoomMemberFacePlayer(data->field_0, &taskData[0], &taskData[1], data->spriteIds)) { PlaySE(SE_SELECT); UR_EnableScriptContext2AndFreezeObjectEvents(); @@ -2526,7 +2525,7 @@ static void Task_RunUnionRoom(u8 taskId) if (!gReceivedRemoteLinkPlayers) { HandleCancelTrade(FALSE); - UpdateUnionGroupMemberFacing(taskData[0], taskData[1], data->field_0); + UpdateUnionRoomMemberFacing(taskData[0], taskData[1], data->field_0); data->state = 2; } break; @@ -2848,7 +2847,7 @@ static void Task_RunUnionRoom(u8 taskId) Free(data->field_C); Free(data->field_4); DestroyTask(data->field_20); - DestroyGroupMemberObjects(data->spriteIds); + DestroyGroupMemberSprites(data->spriteIds); data->state = 17; break; case 17: @@ -2858,7 +2857,7 @@ static void Task_RunUnionRoom(u8 taskId) case 18: if (!UpdatePaletteFade()) { - sub_8019E3C(); + DestroyUnionRoomPlayerObjects(); DestroyTask(taskId); Free(sWirelessLinkMain.uRoom); CreateTask_StartActivity(); @@ -3048,7 +3047,7 @@ static void Task_RunUnionRoom(u8 taskId) if (PrintOnTextbox(&data->textState, gStringVar4)) { HandleCancelTrade(TRUE); - UpdateUnionGroupMemberFacing(taskData[0], taskData[1], data->field_0); + UpdateUnionRoomMemberFacing(taskData[0], taskData[1], data->field_0); data->state = 4; } break; @@ -3221,7 +3220,7 @@ static u8 HandlePlayerListUpdate(void) return 4; } } - for (j = 0; j < 8; j++) + for (j = 0; j < ARRAY_COUNT(data->field_0->arr); j++) { if (data->field_0->arr[j].groupScheduledAnim != UNION_ROOM_SPAWN_NONE) { @@ -3350,29 +3349,21 @@ static void Task_ListenForPartnersWithCompatibleSerialNos(u8 taskId) } } -static bool32 GetGnameWonderFlagByLinkGroup(struct GFtgtGname *gname, s16 linkGroup) +static bool32 HasWonderCardOrNewsByLinkGroup(struct GFtgtGname *gname, s16 linkGroup) { if (linkGroup == LINK_GROUP_WONDER_CARD) { if (!gname->unk_00.hasCard) - { return FALSE; - } else - { return TRUE; - } } else if (linkGroup == LINK_GROUP_WONDER_NEWS) { if (!gname->unk_00.hasNews) - { return FALSE; - } else - { return TRUE; - } } else { @@ -3389,7 +3380,7 @@ static void Task_ListenForPartnersWithSerial7F7D(u8 taskId) { if (LinkRfu_GetNameIfSerial7F7D(&ptr[0]->arr[i].gname_uname.gname, ptr[0]->arr[i].gname_uname.playerName, i)) { - GetGnameWonderFlagByLinkGroup(&ptr[0]->arr[i].gname_uname.gname, gTasks[taskId].data[2]); + HasWonderCardOrNewsByLinkGroup(&ptr[0]->arr[i].gname_uname.gname, gTasks[taskId].data[2]); } ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy); } @@ -3980,7 +3971,7 @@ static void TradeBoardListMenuItemPrintFunc(u8 windowId, s32 itemId, u8 y) else { j = 0; - for (i = 0; i < 8; i++) + for (i = 0; i < (int)ARRAY_COUNT(data->field_0->arr); i++) { if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && data->field_0->arr[i].gname_uname.gname.species != SPECIES_NONE) { diff --git a/src/union_room_player_avatar.c b/src/union_room_player_avatar.c index 36f3fb653..0e62a2740 100644 --- a/src/union_room_player_avatar.c +++ b/src/union_room_player_avatar.c @@ -10,14 +10,17 @@ #include "constants/event_object_movement.h" #include "constants/flags.h" -EWRAM_DATA struct UnkStruct_8019BA8 * gUnknown_02022C64 = NULL; -EWRAM_DATA u32 gUnknown_02022C68 = 0; +#define UR_SPRITE_START_ID (MAX_SPRITES - MAX_UNION_ROOM_PLAYERS) +#define UR_PLAYER_SPRITE_ID(playerIdx, facingDir)(5 * playerIdx + facingDir) -static u8 sub_8019DF4(void); -static u32 sub_8019F8C(u32 playerIdx, u32 arg1); -static void sub_801A3B0(s32 arg0, s32 arg1, u8 arg2); +static EWRAM_DATA struct UnionRoomObject * sUnionObjWork = NULL; +static EWRAM_DATA u32 sUnionObjRefreshTimer = 0; -static const u8 sUnionRoomObjGfxIds[GENDER_COUNT][10] = { +static u8 CreateTask_AnimateUnionRoomPlayers(void); +static u32 IsUnionRoomPlayerInvisible(u32, u32); +static void SetUnionRoomObjectFacingDirection(s32, s32, u8); + +static const u8 sUnionRoomObjGfxIds[GENDER_COUNT][MAX_UNION_ROOM_PLAYERS + 2] = { [MALE] = { OBJ_EVENT_GFX_MAN_3, OBJ_EVENT_GFX_BLACK_BELT, @@ -40,7 +43,7 @@ static const u8 sUnionRoomObjGfxIds[GENDER_COUNT][10] = { } }; -static const s16 sUnionPartnerCoords[][2] = { +static const s16 sUnionRoomPlayerCoords[MAX_UNION_ROOM_PLAYERS][2] = { { 4, 6}, {13, 8}, {10, 6}, @@ -59,26 +62,42 @@ static const s8 sFacingDirectionOffsets[][2] = { [DIR_EAST] = { 0, 1} }; -static const u8 gUnknown_082F076A[] = { - 0x00, 0x02, 0x01, 0x04, 0x03 +static const u8 sOppositeFacingDirection[] = { + [DIR_NONE] = DIR_NONE, + [DIR_SOUTH] = DIR_NORTH, + [DIR_NORTH] = DIR_SOUTH, + [DIR_WEST] = DIR_EAST, + [DIR_EAST] = DIR_WEST }; -static const u8 gUnknown_082F076F[] = { - 0x01, 0x03, 0x01, 0x04, 0x02 +static const u8 sNextFacingDirection[] = { + [DIR_NONE] = DIR_SOUTH, + [DIR_SOUTH] = DIR_WEST, + [DIR_NORTH] = DIR_SOUTH, + [DIR_WEST] = DIR_EAST, + [DIR_EAST] = DIR_NORTH }; -static const u8 gUnknown_082F0774[] = { - 0x09, 0x08, 0x07, 0x02, 0x06, 0x05, 0x04, 0x03, - 0xbf, 0x02, 0xc0, 0x02, 0xc1, 0x02, 0xc2, 0x02, - 0xc3, 0x02, 0xc4, 0x02, 0xc5, 0x02, 0xc6, 0x02 +// Local id 1 is the Nurse/Aide +static const u8 sUnionRoomLocalIds[] = { 9, 8, 7, 2, 6, 5, 4, 3 }; + +static const u16 sUnknown[] = { + 0x2BF, + 0x2C0, + 0x2C1, + 0x2C2, + 0x2C3, + 0x2C4, + 0x2C5, + 0x2C6 }; -static const u8 gUnknown_082F078C[2] = { +static const u8 sMovement_UnionPlayerExit[2] = { MOVEMENT_ACTION_FLY_UP, MOVEMENT_ACTION_STEP_END }; -static const u8 gUnknown_082F078E[2] = { +static const u8 sMovement_UnionPlayerEnter[2] = { MOVEMENT_ACTION_FLY_DOWN, MOVEMENT_ACTION_STEP_END }; @@ -86,40 +105,29 @@ static const u8 gUnknown_082F078E[2] = { static bool32 is_walking_or_running(void) { if (gPlayerAvatar.tileTransitionState == 2 || gPlayerAvatar.tileTransitionState == 0) - { return TRUE; - } else - { return FALSE; - } } -static u8 sub_8019978(u32 a0, u32 a1) +static u8 GetUnionRoomPlayerGraphicsId(u32 gender, u32 id) { - return sUnionRoomObjGfxIds[a0][a1 % 8]; + return sUnionRoomObjGfxIds[gender][id % MAX_UNION_ROOM_PLAYERS]; } -static void sub_8019990(u32 a0, u32 a1, s32 * a2, s32 * a3) +static void GetUnionRoomPlayerFacingCoords(u32 playerIdx, u32 direction, s32 * x, s32 * y) { - *a2 = sUnionPartnerCoords[a0][0] + sFacingDirectionOffsets[a1][0] + 7; - *a3 = sUnionPartnerCoords[a0][1] + sFacingDirectionOffsets[a1][1] + 7; + *x = sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0] + 7; + *y = sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1] + 7; } -static bool32 sub_80199E0(u32 a0, u32 a1, s32 a2, s32 a3) +static bool32 IsUnionRoomPlayerFacingTileAt(u32 playerIdx, u32 direction, s32 x, s32 y) { - if (sUnionPartnerCoords[a0][0] + sFacingDirectionOffsets[a1][0] + 7 != a2) - { - return FALSE; - } - else if (sUnionPartnerCoords[a0][1] + sFacingDirectionOffsets[a1][1] + 7 != a3) - { - return FALSE; - } - else - { + if ((sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0] + 7 == x) + && (sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1] + 7 == y)) return TRUE; - } + else + return FALSE; } static bool32 IsUnionRoomPlayerHidden(u32 player_idx) @@ -144,19 +152,19 @@ static void SetUnionRoomPlayerGfx(u32 playerIdx, u32 gfxId) static void CreateUnionRoomPlayerObjectEvent(u32 playerIdx) { - TrySpawnObjectEvent(gUnknown_082F0774[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + TrySpawnObjectEvent(sUnionRoomLocalIds[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); } static void RemoveUnionRoomPlayerObjectEvent(u32 playerIdx) { - RemoveObjectEventByLocalIdAndMap(gUnknown_082F0774[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + RemoveObjectEventByLocalIdAndMap(sUnionRoomLocalIds[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); } static bool32 SetUnionRoomPlayerEnterExitMovement(u32 playerIdx, const u8 * movement) { u8 objectId; struct ObjectEvent * object; - if (TryGetObjectEventIdByLocalIdAndMap(gUnknown_082F0774[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) + if (TryGetObjectEventIdByLocalIdAndMap(sUnionRoomLocalIds[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) { return FALSE; } @@ -172,11 +180,11 @@ static bool32 SetUnionRoomPlayerEnterExitMovement(u32 playerIdx, const u8 * move return TRUE; } -static bool32 sub_8019B3C(u32 playerIdx) +static bool32 TryReleaseUnionRoomPlayerObjectEvent(u32 playerIdx) { u8 objectId; struct ObjectEvent * object; - if (TryGetObjectEventIdByLocalIdAndMap(gUnknown_082F0774[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) + if (TryGetObjectEventIdByLocalIdAndMap(sUnionRoomLocalIds[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) { return TRUE; } @@ -196,39 +204,39 @@ static bool32 sub_8019B3C(u32 playerIdx) return TRUE; } -u8 sub_8019BA8(struct UnkStruct_8019BA8 * ptr) +u8 InitUnionRoomPlayerObjects(struct UnionRoomObject * players) { s32 i; - gUnknown_02022C68 = 0; - gUnknown_02022C64 = ptr; - for (i = 0; i < 8; i++) + sUnionObjRefreshTimer = 0; + sUnionObjWork = players; + for (i = 0; i < MAX_UNION_ROOM_PLAYERS; i++) { - ptr[i].field_0 = 0; - ptr[i].field_1 = 0; - ptr[i].field_2 = 0; - ptr[i].field_3 = 0; + players[i].state = 0; + players[i].gfxId = 0; + players[i].animState = 0; + players[i].schedAnim = UNION_ROOM_SPAWN_NONE; } - return sub_8019DF4(); + return CreateTask_AnimateUnionRoomPlayers(); } -static bool32 sub_8019BDC(s8 * a0, u32 playerIdx, struct UnkStruct_8019BA8 * ptr) +static bool32 AnimateUnionRoomPlayerDespawn(s8 * state, u32 playerIdx, struct UnionRoomObject * ptr) { - switch (*a0) + switch (*state) { case 0: - if (SetUnionRoomPlayerEnterExitMovement(playerIdx, gUnknown_082F078C) == TRUE) + if (SetUnionRoomPlayerEnterExitMovement(playerIdx, sMovement_UnionPlayerExit) == TRUE) { HideUnionRoomPlayer(playerIdx); - (*a0)++; + (*state)++; } break; case 1: - if (sub_8019B3C(playerIdx)) + if (TryReleaseUnionRoomPlayerObjectEvent(playerIdx)) { RemoveUnionRoomPlayerObjectEvent(playerIdx); HideUnionRoomPlayer(playerIdx); - *a0 = 0; + *state = 0; return TRUE; } break; @@ -236,11 +244,11 @@ static bool32 sub_8019BDC(s8 * a0, u32 playerIdx, struct UnkStruct_8019BA8 * ptr return FALSE; } -static bool32 sub_8019C38(s8 * a0, u32 playerIdx, struct UnkStruct_8019BA8 * ptr) +static bool32 AnimateUnionRoomPlayerSpawn(s8 * state, u32 playerIdx, struct UnionRoomObject * ptr) { s16 x, y; - switch (*a0) + switch (*state) { case 0: if (!is_walking_or_running()) @@ -248,30 +256,30 @@ static bool32 sub_8019C38(s8 * a0, u32 playerIdx, struct UnkStruct_8019BA8 * ptr break; } PlayerGetDestCoords(&x, &y); - if (sub_80199E0(playerIdx, 0, x, y) == 1) + if (IsUnionRoomPlayerFacingTileAt(playerIdx, 0, x, y) == TRUE) { break; } player_get_pos_including_state_based_drift(&x, &y); - if (sub_80199E0(playerIdx, 0, x, y) == 1) + if (IsUnionRoomPlayerFacingTileAt(playerIdx, 0, x, y) == TRUE) { break; } - SetUnionRoomPlayerGfx(playerIdx, ptr->field_1); + SetUnionRoomPlayerGfx(playerIdx, ptr->gfxId); CreateUnionRoomPlayerObjectEvent(playerIdx); ShowUnionRoomPlayer(playerIdx); - (*a0)++; + (*state)++; // fallthrough case 3: // incorrect? - if (SetUnionRoomPlayerEnterExitMovement(playerIdx, gUnknown_082F078E) == 1) + if (SetUnionRoomPlayerEnterExitMovement(playerIdx, sMovement_UnionPlayerEnter) == TRUE) { - (*a0)++; + (*state)++; } break; case 2: - if (sub_8019B3C(playerIdx)) + if (TryReleaseUnionRoomPlayerObjectEvent(playerIdx)) { - *a0 = 0; + *state = 0; return TRUE; } break; @@ -279,44 +287,38 @@ static bool32 sub_8019C38(s8 * a0, u32 playerIdx, struct UnkStruct_8019BA8 * ptr return FALSE; } -static bool32 sub_8019CF0(u32 playerIdx, u32 a1, u32 a2) +static bool32 SpawnGroupLeader(u32 playerIdx, u32 gender, u32 id) { - struct UnkStruct_8019BA8 * ptr = &gUnknown_02022C64[playerIdx]; - ptr->field_3 = 1; - ptr->field_1 = sub_8019978(a1, a2); - if (ptr->field_0 == 0) - { + struct UnionRoomObject * ptr = &sUnionObjWork[playerIdx]; + ptr->schedAnim = UNION_ROOM_SPAWN_IN; + ptr->gfxId = GetUnionRoomPlayerGraphicsId(gender, id); + + if (ptr->state == 0) return TRUE; - } else - { return FALSE; - } } -static bool32 sub_8019D20(u32 playerIdx) +static bool32 DespawnGroupLeader(u32 playerIdx) { - struct UnkStruct_8019BA8 * ptr = &gUnknown_02022C64[playerIdx]; - ptr->field_3 = 2; - if (ptr->field_0 == 1) - { + struct UnionRoomObject * ptr = &sUnionObjWork[playerIdx]; + ptr->schedAnim = UNION_ROOM_SPAWN_OUT; + + if (ptr->state == 1) return TRUE; - } else - { return FALSE; - } } -static void sub_8019D44(u32 playerIdx, struct UnkStruct_8019BA8 * ptr) +static void AnimateUnionRoomPlayer(u32 playerIdx, struct UnionRoomObject * ptr) { - switch (ptr->field_0) + switch (ptr->state) { case 0: - if (ptr->field_3 == 1) + if (ptr->schedAnim == UNION_ROOM_SPAWN_IN) { - ptr->field_0 = 2; - ptr->field_2 = 0; + ptr->state = 2; + ptr->animState = 0; } else { @@ -324,23 +326,23 @@ static void sub_8019D44(u32 playerIdx, struct UnkStruct_8019BA8 * ptr) } // fallthrough case 2: - if (!sub_8019F8C(playerIdx, 0) && ptr->field_3 == 2) + if (!IsUnionRoomPlayerInvisible(playerIdx, 0) && ptr->schedAnim == UNION_ROOM_SPAWN_OUT) { - ptr->field_0 = 0; - ptr->field_2 = 0; + ptr->state = 0; + ptr->animState = 0; RemoveUnionRoomPlayerObjectEvent(playerIdx); HideUnionRoomPlayer(playerIdx); } - else if (sub_8019C38(&ptr->field_2, playerIdx, ptr) == 1) + else if (AnimateUnionRoomPlayerSpawn(&ptr->animState, playerIdx, ptr) == TRUE) { - ptr->field_0 = 1; + ptr->state = 1; } break; case 1: - if (ptr->field_3 == 2) + if (ptr->schedAnim == UNION_ROOM_SPAWN_OUT) { - ptr->field_0 = 3; - ptr->field_2 = 0; + ptr->state = 3; + ptr->animState = 0; } else { @@ -348,49 +350,43 @@ static void sub_8019D44(u32 playerIdx, struct UnkStruct_8019BA8 * ptr) } // fallthrough case 3: - if (sub_8019BDC(&ptr->field_2, playerIdx, ptr) == 1) + if (AnimateUnionRoomPlayerDespawn(&ptr->animState, playerIdx, ptr) == 1) { - ptr->field_0 = 0; + ptr->state = 0; } break; } - ptr->field_3 = 0; + ptr->schedAnim = UNION_ROOM_SPAWN_NONE; } -static void sub_8019DD0(u8 taskId) +static void Task_AnimateUnionRoomPlayers(u8 taskId) { s32 i; - for (i = 0; i < 8; i++) - { - sub_8019D44(i, &gUnknown_02022C64[i]); - } + for (i = 0; i < MAX_UNION_ROOM_PLAYERS; i++) + AnimateUnionRoomPlayer(i, &sUnionObjWork[i]); } -static u8 sub_8019DF4(void) +static u8 CreateTask_AnimateUnionRoomPlayers(void) { - if (FuncIsActiveTask(sub_8019DD0) == 1) - { + if (FuncIsActiveTask(Task_AnimateUnionRoomPlayers) == TRUE) return NUM_TASKS; - } else - { - return CreateTask(sub_8019DD0, 5); - } + return CreateTask(Task_AnimateUnionRoomPlayers, 5); } -static void sub_8019E20(void) +static void DestroyTask_AnimateUnionRoomPlayers(void) { - u8 taskId = FindTaskIdByFunc(sub_8019DD0); + u8 taskId = FindTaskIdByFunc(Task_AnimateUnionRoomPlayers); if (taskId < NUM_TASKS) { DestroyTask(taskId); } } -void sub_8019E3C(void) +void DestroyUnionRoomPlayerObjects(void) { s32 i; - for (i = 0; i < 8; i++) + for (i = 0; i < MAX_UNION_ROOM_PLAYERS; i++) { if (!IsUnionRoomPlayerHidden(i)) { @@ -398,233 +394,231 @@ void sub_8019E3C(void) HideUnionRoomPlayer(i); } } - gUnknown_02022C64 = NULL; - sub_8019E20(); + sUnionObjWork = NULL; + DestroyTask_AnimateUnionRoomPlayers(); } -void CreateGroupMemberObjectsInvisible(u8 * sp8, s32 r9) +void CreateGroupMemberSpritesInvisible(u8 * spriteIds, s32 playerIdx) { - s32 r7; + s32 direction; - for (r7 = 0; r7 < 5; r7++) + for (direction = DIR_NONE; direction <= DIR_EAST; direction++) { - s32 r5 = 5 * r9 + r7; - sp8[r5] = sprite_new(OBJ_EVENT_GFX_MAN_4, r5 - 0x38, sUnionPartnerCoords[r9][0] + sFacingDirectionOffsets[r7][0], sUnionPartnerCoords[r9][1] + sFacingDirectionOffsets[r7][1], 3, 1); - sub_8097C44(r5 - 0x38, TRUE); + s32 id = UR_PLAYER_SPRITE_ID(playerIdx, direction); + spriteIds[id] = CreateObjectSprite(OBJ_EVENT_GFX_MAN_4, + id - UR_SPRITE_START_ID, + sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0], + sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1], + 3, 1); + SetObjectEventSpriteInvisibility(id - UR_SPRITE_START_ID, TRUE); } } -void DestroyGroupMemberObjects(u8 * r5) +void DestroyGroupMemberSprites(u8 * spriteIds) { s32 i; - for (i = 0; i < 40; i++) - { - DestroySprite(&gSprites[r5[i]]); - } + for (i = 0; i < UR_PLAYER_SPRITE_ID(MAX_UNION_ROOM_PLAYERS, 0); i++) + DestroySprite(&gSprites[spriteIds[i]]); } -void sub_8019F2C(void) +void SetTilesAroundUnionRoomPlayersPassable(void) { - s32 i, j, x, y; - for (i = 0; i < 8; i++) + s32 i, direction, x, y; + for (i = 0; i < MAX_UNION_ROOM_PLAYERS; i++) { - for (j = 0; j < 5; j++) + for (direction = DIR_NONE; direction <= DIR_EAST; direction++) { - sub_8019990(i, j, &x, &y); - sub_8088B94(x, y, 0); + GetUnionRoomPlayerFacingCoords(i, direction, &x, &y); + MapGridSetMetatileImpassabilityAt(x, y, FALSE); } } } -static u8 sub_8019F64(u32 r1, u32 unused, struct GFtgtGname * r2) +static u8 GetNewFacingDirectionForUnionRoomPlayer(u32 direction, u32 playerIdx, struct GFtgtGname * gname) { - if (r1 != 0) - { - return gUnknown_082F076F[r1]; - } - else if (r2->activity == 0x45) - { - return 1; - } + if (direction != DIR_NONE) + return sNextFacingDirection[direction]; + else if (gname->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) + return DIR_SOUTH; else - { - return 4; - } + return DIR_EAST; } -static u32 sub_8019F8C(u32 a0, u32 a1) +static bool32 IsUnionRoomPlayerInvisible(u32 playerIdx, u32 direction) { - return sub_8097C8C(5 * a0 + a1 - 0x38); + return IsObjectEventSpriteInvisible(UR_PLAYER_SPRITE_ID(playerIdx, direction) - UR_SPRITE_START_ID); } -static void sub_8019FA4(u32 r5, u32 r6, u8 r8, struct GFtgtGname * r9) +static void SpawnGroupMember(u32 playerIdx, u32 direction, u8 graphicsId, struct GFtgtGname * gname) { s32 x, y; - s32 r7 = 5 * r5 + r6; - if (sub_8019F8C(r5, r6) == 1) + s32 id = UR_PLAYER_SPRITE_ID(playerIdx, direction); + if (IsUnionRoomPlayerInvisible(playerIdx, direction) == TRUE) { - sub_8097C44(r7 - 0x38, FALSE); - sub_8097CC4(r7 - 0x38, 1); + SetObjectEventSpriteInvisibility(id - UR_SPRITE_START_ID, FALSE); + SetObjectEventSpriteAnim(id - UR_SPRITE_START_ID, UNION_ROOM_SPAWN_IN); } - sub_8097BB4(r7 - 0x38, r8); - sub_801A3B0(r6, r5, sub_8019F64(r6, r5, r9)); - sub_8019990(r5, r6, &x, &y); - sub_8088B94(x, y, 1); + SetObjectEventSpriteGraphics(id - UR_SPRITE_START_ID, graphicsId); + SetUnionRoomObjectFacingDirection(direction, playerIdx, GetNewFacingDirectionForUnionRoomPlayer(direction, playerIdx, gname)); + GetUnionRoomPlayerFacingCoords(playerIdx, direction, &x, &y); + MapGridSetMetatileImpassabilityAt(x, y, TRUE); } -static void sub_801A02C(u32 a0, u32 a1) +static void DespawnGroupMember(u32 playerIdx, u32 direction) { s32 x, y; - sub_8097CC4(5 * a0 + a1 - 0x38, 2); - sub_8019990(a0, a1, &x, &y); - sub_8088B94(x, y, 0); + SetObjectEventSpriteAnim(UR_PLAYER_SPRITE_ID(playerIdx, direction) - UR_SPRITE_START_ID, UNION_ROOM_SPAWN_OUT); + GetUnionRoomPlayerFacingCoords(playerIdx, direction, &x, &y); + MapGridSetMetatileImpassabilityAt(x, y, FALSE); } -static void sub_801A064(u32 r7, struct GFtgtGname * r8) +static void AssembleGroup(u32 playerIdx, struct GFtgtGname * gname) { s16 x, y, x2, y2; s32 i; PlayerGetDestCoords(&x, &y); player_get_pos_including_state_based_drift(&x2, &y2); - if (sub_8097C8C(5 * r7 - 0x38) == 1) + if (IsObjectEventSpriteInvisible(UR_PLAYER_SPRITE_ID(playerIdx, 0) - UR_SPRITE_START_ID) == TRUE) { - if (sub_80199E0(r7, 0, x, y) == 1 || sub_80199E0(r7, 0, x2, y2) == 1) + if (IsUnionRoomPlayerFacingTileAt(playerIdx, 0, x, y) == TRUE || IsUnionRoomPlayerFacingTileAt(playerIdx, 0, x2, y2) == TRUE) { return; } - sub_8019FA4(r7, 0, sub_8019978(r8->playerGender, r8->unk_00.playerTrainerId[0]), r8); + SpawnGroupMember(playerIdx, 0, GetUnionRoomPlayerGraphicsId(gname->playerGender, gname->unk_00.playerTrainerId[0]), gname); } for (i = 1; i < 5; i++) { - if (r8->child_sprite_gender[i - 1] == 0) + if (gname->child_sprite_gender[i - 1] == 0) { - sub_801A02C(r7, i); + DespawnGroupMember(playerIdx, i); } - else if (sub_80199E0(r7, i, x, y) == 0 && sub_80199E0(r7, i, x2, y2) == 0) + else if (IsUnionRoomPlayerFacingTileAt(playerIdx, i, x, y) == FALSE && IsUnionRoomPlayerFacingTileAt(playerIdx, i, x2, y2) == FALSE) { - sub_8019FA4(r7, i, sub_8019978((r8->child_sprite_gender[i - 1] >> 3) & 1, r8->child_sprite_gender[i - 1] & 7), r8); + SpawnGroupMember(playerIdx, i, GetUnionRoomPlayerGraphicsId((gname->child_sprite_gender[i - 1] >> 3) & 1, gname->child_sprite_gender[i - 1] & 7), gname); } } } -static void sub_801A16C(u32 r5, struct GFtgtGname * r4) +static void SpawnGroupLeaderAndMembers(u32 playerIdx, struct GFtgtGname * gname) { u32 i; - switch (r4->activity) + switch (gname->activity) { - case 0x40: - case 0x54: - sub_8019CF0(r5, r4->playerGender, r4->unk_00.playerTrainerId[0]); + case ACTIVITY_NONE | IN_UNION_ROOM: + case ACTIVITY_PLYRTALK | IN_UNION_ROOM: + SpawnGroupLeader(playerIdx, gname->playerGender, gname->unk_00.playerTrainerId[0]); for (i = 0; i < 5; i++) { - sub_801A02C(r5, i); + DespawnGroupMember(playerIdx, i); } break; - case 0x41: - case 0x44: - case 0x45: - case 0x48: - case 0x51: - case 0x52: - case 0x53: - sub_8019D20(r5); - sub_801A064(r5, r4); + case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM: + case ACTIVITY_TRADE | IN_UNION_ROOM: + case ACTIVITY_CHAT | IN_UNION_ROOM: + case ACTIVITY_CARD | IN_UNION_ROOM: + case ACTIVITY_ACCEPT | IN_UNION_ROOM: + case ACTIVITY_DECLINE | IN_UNION_ROOM: + case ACTIVITY_NPCTALK | IN_UNION_ROOM: + DespawnGroupLeader(playerIdx); + AssembleGroup(playerIdx, gname); break; } } -static void sub_801A214(u32 r5, struct GFtgtGname * unused) +static void DespawnGroupLeaderAndMembers(u32 r5, struct GFtgtGname *gname) { s32 i; - sub_8019D20(r5); + DespawnGroupLeader(r5); for (i = 0; i < 5; i++) { - sub_801A02C(r5, i); + DespawnGroupMember(r5, i); } } -static void sub_801A234(struct WirelessLink_URoom *r0) +static void UpdateUnionRoomPlayerSprites(struct WirelessLink_URoom *uroom) { s32 i; struct UnkStruct_x20 * r4; - gUnknown_02022C68 = 0; - for (i = 0, r4 = r0->field_0->arr; i < 8; i++) + sUnionObjRefreshTimer = 0; + for (i = 0, r4 = uroom->field_0->arr; i < MAX_UNION_ROOM_PLAYERS; i++) { - if (r4[i].groupScheduledAnim == 1) + if (r4[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - sub_801A16C(i, &r4[i].gname_uname.gname); + SpawnGroupLeaderAndMembers(i, &r4[i].gname_uname.gname); } - else if (r4[i].groupScheduledAnim == 2) + else if (r4[i].groupScheduledAnim == UNION_ROOM_SPAWN_OUT) { - sub_801A214(i, &r4[i].gname_uname.gname); + DespawnGroupLeaderAndMembers(i, &r4[i].gname_uname.gname); } } } -void ScheduleUnionRoomPlayerRefresh(struct WirelessLink_URoom *unused) +void ScheduleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom) { - gUnknown_02022C68 = 300; + sUnionObjRefreshTimer = 300; } -void HandleUnionRoomPlayerRefresh(struct WirelessLink_URoom *r2) +void HandleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom) { - if (++gUnknown_02022C68 > 300) + if (++sUnionObjRefreshTimer > 300) { - sub_801A234(r2); + UpdateUnionRoomPlayerSprites(uroom); } } -bool32 RfuUnionTool_GetGroupAndMemberInFrontOfPlayer(struct UnkStruct_Main0 *arg0, s16 *arg1, s16 *arg2, u8 *arg3) +bool32 TrySetUnionRoomMemberFacePlayer(struct UnkStruct_Main0 *main0, s16 *directionPtr, s16 *playerIdxPtr, u8 *spriteIds) { s16 x, y; - s32 i, j; + s32 i, direction; struct UnkStruct_x20 * r4; if (!is_walking_or_running()) { return FALSE; } GetXYCoordsOneStepInFrontOfPlayer(&x, &y); - for (i = 0, r4 = arg0->arr; i < 8; i++) + for (i = 0, r4 = main0->arr; i < MAX_UNION_ROOM_PLAYERS; i++) { - for (j = 0; j < 5; j++) + for (direction = DIR_NONE; direction <= DIR_EAST; direction++) { - s32 r3 = 5 * i + j; - if (x != sUnionPartnerCoords[i][0] + sFacingDirectionOffsets[j][0] + 7) + s32 id = UR_PLAYER_SPRITE_ID(i, direction); + if (x != sUnionRoomPlayerCoords[i][0] + sFacingDirectionOffsets[direction][0] + 7) { continue; } - if (y != sUnionPartnerCoords[i][1] + sFacingDirectionOffsets[j][1] + 7) + if (y != sUnionRoomPlayerCoords[i][1] + sFacingDirectionOffsets[direction][1] + 7) { continue; } - if (sub_8097C8C(r3 - 0x38) != 0) + if (IsObjectEventSpriteInvisible(id - UR_SPRITE_START_ID)) { continue; } - if (sub_8097D9C(r3 - 0x38) != 0) + if (IsObjectEventSpriteAnimating(id - UR_SPRITE_START_ID)) { continue; } - if (r4[i].groupScheduledAnim != 1) + if (r4[i].groupScheduledAnim != UNION_ROOM_SPAWN_IN) { continue; } - sub_801A3B0(j, i, gUnknown_082F076A[GetPlayerFacingDirection()]); - *arg1 = j; - *arg2 = i; + SetUnionRoomObjectFacingDirection(direction, i, sOppositeFacingDirection[GetPlayerFacingDirection()]); + *directionPtr = direction; + *playerIdxPtr = i; return TRUE; } } return FALSE; } -static void sub_801A3B0(s32 arg0, s32 arg1, u8 arg2) +static void SetUnionRoomObjectFacingDirection(s32 currDirection, s32 playerIdx, u8 newDirection) { - sub_8097B78(5 * arg1 - 0x38 + arg0, arg2); + TurnObjectEventSprite(5 * playerIdx - UR_SPRITE_START_ID + currDirection, newDirection); + // should be line below, but order is swapped here + // TurnObjectEventSprite(UR_PLAYER_SPRITE_ID(playerIdx, currDirection) - UR_SPRITE_START_ID, newDirection); } -void UpdateUnionGroupMemberFacing(u32 arg0, u32 arg1, struct UnkStruct_Main0 *arg2) +void UpdateUnionRoomMemberFacing(u32 currDirection, u32 playerIdx, struct UnkStruct_Main0 *main0) { - return sub_801A3B0(arg0, arg1, sub_8019F64(arg0, arg1, &arg2->arr[arg1].gname_uname.gname)); + return SetUnionRoomObjectFacingDirection(currDirection, playerIdx, GetNewFacingDirectionForUnionRoomPlayer(currDirection, playerIdx, &main0->arr[playerIdx].gname_uname.gname)); }