diff --git a/data/data_8107224.s b/data/data_8107224.s index c81f95548..5481d66a2 100644 --- a/data/data_8107224.s +++ b/data/data_8107224.s @@ -1,16 +1,5 @@ .section .rodata -@ START code_808417C #1 -.string "pksdir0\0" - -.string "pksdir0\0" - -.global gUnknown_8107224 -gUnknown_8107224: @ 8107224 -.string "??????\0" -.align 2, 0 -@ END code_808417C #1 -@ code_8085B0C .string "pksdir0\0" .global gUnknown_8107234 diff --git a/data/pksdir_3.s b/data/pksdir_3.s index 9ccc2af69..f8df0a71f 100644 --- a/data/pksdir_3.s +++ b/data/pksdir_3.s @@ -4,4 +4,4 @@ .string "pksdir0\0" .string "pksdir0\0" -.string "pksdir0\0" \ No newline at end of file +.string "pksdir0\0" diff --git a/data/pksdir_4.s b/data/pksdir_4.s new file mode 100644 index 000000000..43dacf9e3 --- /dev/null +++ b/data/pksdir_4.s @@ -0,0 +1,4 @@ +.section .rodata + +.align 2 +.string "pksdir0\0" diff --git a/include/code_8084778.h b/include/code_8084778.h deleted file mode 100644 index e28b078ce..000000000 --- a/include/code_8084778.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef GUARD_CODE_8084778_H -#define GUARD_CODE_8084778_H - -void sub_8084778(void); - -#endif diff --git a/include/dungeon_jobs.h b/include/dungeon_jobs.h new file mode 100644 index 000000000..761ca180d --- /dev/null +++ b/include/dungeon_jobs.h @@ -0,0 +1,13 @@ +#ifndef GUARD_DUNGEON_JOBS_H +#define GUARD_DUNGEON_JOBS_H + +#include "structs/dungeon_entity.h" + +void sub_80842F0(void); +void sub_80843BC(s32 id); +void sub_8084424(void); +void sub_8084448(Entity *pokemon); +void sub_80845E0(Entity *pokemon); +void sub_8084778(void); + +#endif diff --git a/include/dungeon_util_1.h b/include/dungeon_util_1.h index f0f5a00f0..2ace77a58 100644 --- a/include/dungeon_util_1.h +++ b/include/dungeon_util_1.h @@ -21,13 +21,11 @@ void sub_80856C8(Entity * pokemon, s32 x, s32 y); void sub_80856E0(Entity * pokemon, s32 direction); void sub_8085764(void); void sub_8085860(s32 x, s32 y); -void sub_8085890(s32 x, s32 y); void ShiftCameraToPosition(PixelPos *posStruct, s32 cameraSteps); void SetFacingDirection(Entity *pokemon, s32 direction); void sub_8085930(s32 direction); void sub_80859F0(s32 direction); bool8 ShouldRunMonsterAI(Entity *entity); -void sub_8085B0C(Entity *pokemon); void sub_8085B4C(struct_8085B80 a0[], s16 *a1[], Entity *a2[], s32 a3); void sub_80857B8(void); diff --git a/ld_script.txt b/ld_script.txt index 7bf1a9a41..da3f13896 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -280,9 +280,8 @@ SECTIONS { src/dungeon_music.o(.text); src/dungeon_random.o(.text); src/dungeon_cleared_window.o(.text); - src/code_8084778.o(.text); + src/dungeon_jobs.o(.text); src/code_80848F0.o(.text); - src/dungeon_util_1.o(.text); asm/code_8085B80.o(.text); src/code_8085E98.o(.text); src/code_80861A8.o(.text); @@ -619,11 +618,13 @@ SECTIONS { src/trap.o(.rodata); data/pksdir_3.o(.rodata); src/dungeon_serializer.o(.rodata); + data/pksdir_4.o(.rodata); src/dungeon_range.o(.rodata); src/dungeon_8083AB0.o(.rodata); src/dungeon_music.o(.rodata); src/dungeon_random.o(.rodata); src/dungeon_cleared_window.o(.rodata); + src/dungeon_jobs.o(.rodata); data/data_8107224.o(.rodata); src/pokemon.o(.rodata); data/data_81076E4.o(.rodata); diff --git a/src/code_80848F0.c b/src/code_80848F0.c index c9b47a2b3..79685ae5b 100644 --- a/src/code_80848F0.c +++ b/src/code_80848F0.c @@ -1,7 +1,10 @@ #include "global.h" #include "constants/weather.h" #include "constants/dungeon.h" +#include "constants/direction.h" +#include "constants/dungeon.h" #include "structs/str_dungeon.h" +#include "structs/str_806B7F8.h" #include "dungeon_cutscenes.h" #include "dungeon_music.h" #include "dungeon_logic.h" @@ -11,10 +14,25 @@ #include "pokemon.h" #include "dungeon_util.h" #include "dungeon_map_access.h" -#include "structs/str_806B7F8.h" +#include "dungeon_misc.h" +#include "code_803E46C.h" +#include "code_803E668.h" +#include "code_806CD90.h" +#include "code_80861A8.h" +#include "dungeon_leader.h" +#include "random.h" +#include "math.h" +extern s32 gUnknown_202F3D8; + +extern const u8 gUnknown_8107358[25]; extern const DungeonPos gUnknown_80F4598[]; + extern void ShowWholeRevealedDungeonMap(void); +extern s32 GetCameraXPos(void); +extern s32 GetCameraYPos(void); +extern void sub_803F4A0(u32); +extern void sub_803F878(s32, s32); struct unkData_8107234 { @@ -694,3 +712,432 @@ void sub_8085374(void) j++; } } + +Entity *xxx_call_GetLeader(void) +{ + return GetLeader(); +} + +Entity *GetPartnerEntity(void) +{ + s32 counter; + Entity *entity; + for(counter = 0; counter < MAX_TEAM_MEMBERS; counter++) + { + entity = gDungeon->teamPokemon[counter]; + if(EntityIsValid(entity) && GetEntInfo(entity)->joinedAt.id == DUNGEON_JOIN_LOCATION_PARTNER) + { + return entity; + } + } + return GetEntityFromMonsterBehavior(BEHAVIOR_ALLY); +} + +void sub_80854D4(void) +{ + Entity *stack1[MAX_TEAM_MEMBERS]; + Entity *stack2[MAX_TEAM_MEMBERS]; + s32 counter = 0; + s32 index; + Entity *entity; + Entity *entity2; + Entity *entity3; + Entity *entity4; + Entity *entity5; + + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity = gDungeon->teamPokemon[index]; + if(EntityIsValid(entity)) + { + stack1[counter] = entity; + counter++; + } + } + for(; counter < MAX_TEAM_MEMBERS; counter++) + { + stack1[counter] = NULL; + } + counter = 0; + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity2 = stack1[index]; + if(entity2 != NULL && GetEntInfo(entity2)->isTeamLeader) + { + stack1[index] = NULL; + stack2[counter] = entity2; + counter++; + } + } + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity3 = stack1[index]; + if(entity3 != NULL && GetEntInfo(entity3)->joinedAt.id == DUNGEON_JOIN_LOCATION_PARTNER) + { + stack1[index] = NULL; + stack2[counter] = entity3; + counter++; + } + } + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity4 = stack1[index]; + if(entity4 != NULL) + { + stack1[index] = NULL; + stack2[counter] = entity4; + counter++; + } + } + for(; counter < MAX_TEAM_MEMBERS; counter++) + { + stack2[counter] = NULL; + } + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity5 = stack2[index]; + if(entity5 != NULL) + sub_80856C8(entity5, gDungeon->unkE220[index].x, gDungeon->unkE220[index].y); + } +} + +void sub_80855E4(DungeonCallback func) +{ + bool8 flag; + Entity * entity; + Entity * partnerEntity; + s32 index; + + flag = FALSE; + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity = gDungeon->teamPokemon[index]; + if (EntityIsValid(entity)) { + if (GetEntInfo(entity)->joinedAt.id == DUNGEON_JOIN_LOCATION_PARTNER) { + flag = TRUE; + } + func(entity); + } + } + if ((!flag) && (partnerEntity = GetPartnerEntity(), partnerEntity != NULL)) { + func(partnerEntity); + } +} + +void sub_808563C(DungeonCallback func) +{ + Entity * entity; + s32 index; + + for(index = 0; index < DUNGEON_MAX_WILD_POKEMON; index++) + { + entity = gDungeon->wildPokemon[index]; + if ((EntityIsValid(entity)) && (GetEntInfo(entity)->joinedAt.id != 0x41)) { + func(entity); + } + } +} + +Entity *GetEntityFromMonsterBehavior(u8 entityType) +{ + Entity * entity; + s32 index; + + for(index = 0; index < DUNGEON_MAX_POKEMON; index++) + { + entity = gDungeon->activePokemon[index]; + if ((EntityIsValid(entity)) && (GetEntInfo(entity)->monsterBehavior == entityType)) return entity; + } + return NULL; +} + +void sub_80856C8(Entity * pokemon, s32 x, s32 y) +{ + sub_80694C0(pokemon, x, y, 1); + sub_804535C(pokemon,NULL); +} + +void sub_80856E0(Entity * pokemon, s32 direction) +{ + EntityInfo *entityInfo; + s32 counter; + + entityInfo = GetEntInfo(pokemon); + sub_80861D4(pokemon, 6, direction); + + for(counter = 0; counter < 5; counter++) + { + entityInfo->unk174 = F248_Add(entityInfo->unk174, IntToF248(2)); + DungeonRunFrameActions(0x46); + } + entityInfo->action.direction = direction & DIRECTION_MASK; + sub_806CE68(pokemon, direction); + + for(counter = 0; counter < 5; counter++) + { + entityInfo->unk174 = F248_Sub(entityInfo->unk174, IntToF248(2)); + DungeonRunFrameActions(0x46); + } + entityInfo->unk174.raw = 0; // weird one that doesn't match with struct assignment + DungeonRunFrameActions(0x46); +} + +void sub_8085764(void) +{ + Entity *entity; + s32 index; + Entity stackEntity; + + sub_80457DC(&stackEntity); + for(index = 0; index < DUNGEON_MAX_WILD_POKEMON; index++) + { + entity = gDungeon->wildPokemon[index]; + if ((EntityIsValid(entity)) && (GetEntInfo(entity)->monsterBehavior == BEHAVIOR_ALLY)) { + sub_8068FE0(entity,0x207,&stackEntity); + } + } +} + +void sub_80857B8(void) +{ + u8 *direction; + EntityInfo *entityInfo; + Entity *entity; + int index; + + for(index = 0; index < DUNGEON_MAX_POKEMON; index++) + { + entity = gDungeon->activePokemon[index]; + if (EntityIsValid(entity)) { + entityInfo = GetEntInfo(entity); + if ((gDungeon->unk4 == 0) && (gDungeon->unk2 == 0)) { + sub_804535C(entity, 0); + entityInfo->unk15C = 0; + entityInfo->unkFE = 99; + direction = &entityInfo->action.direction; + entityInfo->targetPos.x = gAdjacentTileOffsets[*direction].x + entity->pos.x; + entityInfo->targetPos.y = gAdjacentTileOffsets[*direction].y + entity->pos.y; + sub_806CE68(entity,*direction); + } + } + } +} + +void sub_8085860(s32 x, s32 y) +{ + sub_803F4A0(0); + sub_803F878(X_POS_TO_PIXELPOS(x), Y_POS_TO_PIXELPOS(y)); +} + +UNUSED static void sub_8085890(s32 x, s32 y) +{ + sub_803F4A0(0); + sub_803F878(x, y); +} + +void ShiftCameraToPosition(PixelPos *posStruct, s32 cameraSteps) +{ + s32 XPos; + s32 YPos; + s32 XIncrement; + s32 YIncrement; + + XPos = GetCameraXPos(); + YPos = GetCameraYPos(); + XIncrement = (posStruct->x - XPos) / cameraSteps; + YIncrement = (posStruct->y - YPos) / cameraSteps; + sub_803F4A0(0); + if (0 < cameraSteps) { + do { + XPos += XIncrement; + YPos += YIncrement; + sub_803F878(XPos,YPos); + DungeonRunFrameActions(0x46); + cameraSteps--; + } while (cameraSteps != 0); + } + sub_803F878(posStruct->x,posStruct->y); + DungeonRunFrameActions(0x46); +} + +void SetFacingDirection(Entity *pokemon, s32 direction) +{ + GetEntInfo(pokemon)->action.direction = direction & DIRECTION_MASK; + sub_806CE68(pokemon, direction); +} + +void sub_8085930(s32 direction) +{ + s32 index; + Entity *entity; + for(index = 0; index < MAX_TEAM_MEMBERS; index++) + { + entity = gDungeon->teamPokemon[index]; + if(EntityIsValid(entity)) + { + if(direction >= NUM_DIRECTIONS) + { + sub_806CE68(entity, RandInt(NUM_DIRECTIONS)); + } + else + { + GetEntInfo(entity)->action.direction = direction & DIRECTION_MASK; + sub_806CE68(entity, direction); + } + } + } + for(index = 0; index < DUNGEON_MAX_WILD_POKEMON; index++) + { + entity = gDungeon->wildPokemon[index]; + if(EntityIsValid(entity)) + { + if(GetEntInfo(entity)->monsterBehavior == BEHAVIOR_ALLY) + { + if(direction >= NUM_DIRECTIONS) + { + sub_806CE68(entity, RandInt(NUM_DIRECTIONS)); + } + else + { + GetEntInfo(entity)->action.direction = direction & DIRECTION_MASK; + sub_806CE68(entity, direction); + } + } + } + } +} + +void sub_80859F0(s32 direction) +{ + s32 index; + Entity *entity; + for(index = 0; index < DUNGEON_MAX_WILD_POKEMON; index++) + { + entity = gDungeon->wildPokemon[index]; + if(EntityIsValid(entity)) + { + if(direction >= NUM_DIRECTIONS) + { + sub_806CE68(entity, RandInt(NUM_DIRECTIONS)); + } + else + { + GetEntInfo(entity)->action.direction = direction & DIRECTION_MASK; + sub_806CE68(entity, direction); + } + } + } +} + +bool8 ShouldRunMonsterAI(Entity *pokemon) +{ + EntityInfo *pokemonInfo = GetEntInfo(pokemon); + switch (pokemonInfo->monsterBehavior) + { + case BEHAVIOR_RESCUE_TARGET: + case BEHAVIOR_SKARMORY: + case BEHAVIOR_GENGAR: + case BEHAVIOR_EKANS: + case BEHAVIOR_MEDICHAM: + case BEHAVIOR_ZAPDOS: + case BEHAVIOR_MOLTRES: + case BEHAVIOR_ARTICUNO: + case BEHAVIOR_GROUDON_2: + case BEHAVIOR_RAYQUAZA: + case BEHAVIOR_MANKEY: + case BEHAVIOR_MEWTWO: + case BEHAVIOR_ENTEI: + case BEHAVIOR_RAIKOU: + case BEHAVIOR_SUICUNE: + case BEHAVIOR_HO_OH: + case BEHAVIOR_LATIOS: + case BEHAVIOR_REGIROCK: + case BEHAVIOR_REGICE: + case BEHAVIOR_REGISTEEL: + case BEHAVIOR_JIRACHI: + case BEHAVIOR_LUGIA: + case BEHAVIOR_KYOGRE: + case BEHAVIOR_29: + case BEHAVIOR_CELEBI: + case BEHAVIOR_SMEARGLE: + case BEHAVIOR_32: + case BEHAVIOR_33: + case BEHAVIOR_34: + case BEHAVIOR_35: + case BEHAVIOR_MAZE_BOSS: + return TRUE; + case BEHAVIOR_FIXED_ENEMY: + case BEHAVIOR_ALLY: + case BEHAVIOR_DIGLETT: + case BEHAVIOR_ALAKAZAM_1: + case BEHAVIOR_GROUDON_1: + case BEHAVIOR_ALAKAZAM_2: + default: + return FALSE; + } +} + +UNUSED static void sub_8085B0C(Entity *pokemon) +{ + s32 index; + u8 local_28 [25]; + + index = 0; + + memcpy(local_28, gUnknown_8107358, 25); + while (local_28[index] != 0) { + SetFacingDirection(pokemon, local_28[index]); + sub_803E708(6,0x46); + index++; + } +} + +void sub_8085B4C(struct_8085B80 a0[], s16 *a1[], Entity *a2[], s32 a3) +{ + s32 i; + + gUnknown_202F3D8 = a3; + + for (i = 0; i < a3; i++) { + a0[i].unk0 = 1; + a0[i].unk4 = a2[i]; + a0[i].unkC = a1[i]; + a0[i].unk8 = a1[i][2]; + } +} + +bool8 sub_8085B80(struct_8085B80 *a0) +{ + s16 *unkCPtr; + int i; + bool8 ret = FALSE; + + for (i = 0; i < gUnknown_202F3D8; i++) { + Entity *entity = a0[i].unk4; + EntityInfo *enInfo = GetEntInfo(entity); + unkCPtr = a0[i].unkC; + if (a0[i].unk0 != 0) { + ret = TRUE; + if (a0[i].unk8 == 0) { + unkCPtr = unkCPtr + 4; + if (unkCPtr[2] == 0) { + a0[i].unk0 = 0; + enInfo->action.direction = unkCPtr[0] & DIRECTION_MASK; + sub_806CDD4(entity, 7, unkCPtr[0]); + sub_80856C8(entity, unkCPtr[5], unkCPtr[6]); + continue; + } + a0[i].unk8 = unkCPtr[2]; + a0[i].unkC = unkCPtr; + enInfo->action.direction = unkCPtr[0] & DIRECTION_MASK; + sub_806CDD4(entity, 0, (int)*unkCPtr); + } + + a0[i].unk8--; + IncreaseEntityPixelPos(entity, + gAdjacentTileOffsets[*unkCPtr].x * unkCPtr[1] * 0x100, + gAdjacentTileOffsets[*unkCPtr].y * unkCPtr[1] * 0x100); + } + } + return ret; +} diff --git a/src/code_8085E98.c b/src/code_8085E98.c index e68112acb..462077400 100644 --- a/src/code_8085E98.c +++ b/src/code_8085E98.c @@ -29,8 +29,7 @@ void sub_8085EB0(void) gDungeon->unk181e8.unk18215 = 1; } -u32 sub_8085EC8(s16 param_1,u32 param_2,u32 param_3,DungeonPos *param_4, - bool32 param_5) +u32 sub_8085EC8(s16 param_1,u32 param_2,u32 param_3,DungeonPos *param_4, bool32 param_5) { u32 uVar1; unkStruct_80416E0 local_40; @@ -92,12 +91,10 @@ void sub_8085F78(void) default: break; } - return; } bool8 sub_80860A8(u8 id) { - Item *item; EntityInfo *info; Entity *entity; diff --git a/src/code_80861A8.c b/src/code_80861A8.c index 631569927..69f4d0703 100644 --- a/src/code_80861A8.c +++ b/src/code_80861A8.c @@ -26,7 +26,7 @@ void sub_8085F44(s32); void sub_8052FB8(const u8 *); -void sub_8086124(Entity *entity, u8 param_2) +UNUSED static void sub_8086124(Entity *entity, u8 param_2) { GetEntInfo(entity)->unk160 = param_2; } diff --git a/src/code_80869E4.c b/src/code_80869E4.c index a64cc5c99..9ca1e94cd 100644 --- a/src/code_80869E4.c +++ b/src/code_80869E4.c @@ -8,6 +8,9 @@ #include "dungeon_util.h" #include "dungeon_util_1.h" #include "random.h" +#include "pokemon_3.h" +#include "dungeon_logic.h" +#include "exclusive_pokemon.h" #include "structs/str_dungeon.h" // This file may originally be merged with code_8086A3C.c and code_8057824_1.c @@ -24,8 +27,7 @@ s8 sub_8002984(s8, u8); extern void BgColorCallNullsub4(void); extern void SetDungeonBGColorRGB(u32, u32, u32, u32, u32); extern void PlaySoundEffect(u32); - - +extern u8 sub_8044B28(void); extern void sub_8085EB0(void); extern void sub_803E748(void); extern s32 GetCameraXPos(void); @@ -490,3 +492,53 @@ void sub_80869E4(struct Entity *entity, s32 a1, u8 a2, s32 _someDirection) } } +void sub_8086A3C(Entity *pokemon) +{ + GetEntInfo(pokemon)->unk15C = 1; + GetEntInfo(pokemon)->unk15E = 1; +} + +void sub_8086A54(Entity *pokemon) +{ + GetEntInfo(pokemon)->unk15C = 1; + GetEntInfo(pokemon)->unk15E = 0; +} + +void SetupBossFightHP(Entity *pokemon, s32 newHP, u16 songIndex) +{ + EntityInfo *entityInfo = GetEntInfo(pokemon); + + entityInfo->bossFlag = TRUE; + + // BUG: Source of the Reviver Seed Boss Glitch + // + // Video to demonstration: + // https://www.youtube.com/watch?v=rHu7EehrZ68 + entityInfo->originalHP = entityInfo->maxHPStat; + if (newHP != 0) { + entityInfo->maxHPStat = newHP; + entityInfo->HP = newHP; + } + + gDungeon->unk644.bossSongIndex = songIndex; + SetDefaultIQSkills(&entityInfo->IQSkillMenuFlags, entityInfo->bossFlag); + LoadIQSkills(pokemon); +} + +void sub_8086AC0(void) +{ + if(!sub_8044B28()) + if(gDungeon->unk2 == 0) + sub_8097FF8(); +} + +u8 sub_8086AE4(s16 _index) +{ + s32 pokeIndex = _index; + + if(gDungeon->unk644.unk18 == 0) + return 1; + else + return HasRecruitedMon(pokeIndex); +} + diff --git a/src/dungeon_cutscenes.c b/src/dungeon_cutscenes.c index bd98fcc6d..648ad2217 100644 --- a/src/dungeon_cutscenes.c +++ b/src/dungeon_cutscenes.c @@ -28,7 +28,6 @@ #include "pokemon_3.h" #include "pokemon.h" #include "position_util.h" -#include "exclusive_pokemon.h" #include "trap.h" #include "math.h" #include "dungeon_config.h" @@ -82,8 +81,10 @@ extern void sub_807EAA0(u32, u32); extern void sub_8072008(Entity *, Entity *, s16, u32, u32); extern void sub_8085374(void); extern u32 GetRandomFloorItem(u32); -extern u8 sub_8044B28(void); extern bool8 sub_8085B80(struct_8085B80 *); +extern void sub_8086A3C(Entity *pokemon); +extern void SetupBossFightHP(Entity *pokemon, s32 newHP, u16 songIndex); +extern u8 sub_8086AE4(s16 _index); void sub_8085F44(s32); void sub_808BBA8(Entity * ); @@ -146,56 +147,6 @@ void sub_808BB3C(DungeonPos *pos); void sub_8087144(); void SkarmoryEntry(Entity *); -void sub_8086A3C(Entity *pokemon) -{ - GetEntInfo(pokemon)->unk15C = 1; - GetEntInfo(pokemon)->unk15E = 1; -} - -void sub_8086A54(Entity *pokemon) -{ - GetEntInfo(pokemon)->unk15C = 1; - GetEntInfo(pokemon)->unk15E = 0; -} - -void SetupBossFightHP(Entity *pokemon, s32 newHP, u16 songIndex) -{ - EntityInfo *entityInfo = GetEntInfo(pokemon); - - entityInfo->bossFlag = TRUE; - - // BUG: Source of the Reviver Seed Boss Glitch - // - // Video to demonstration: - // https://www.youtube.com/watch?v=rHu7EehrZ68 - entityInfo->originalHP = entityInfo->maxHPStat; - if (newHP != 0) { - entityInfo->maxHPStat = newHP; - entityInfo->HP = newHP; - } - - gDungeon->unk644.bossSongIndex = songIndex; - SetDefaultIQSkills(&entityInfo->IQSkillMenuFlags, entityInfo->bossFlag); - LoadIQSkills(pokemon); -} - -void sub_8086AC0(void) -{ - if(!sub_8044B28()) - if(gDungeon->unk2 == 0) - sub_8097FF8(); -} - -u8 sub_8086AE4(s16 _index) -{ - s32 pokeIndex = _index; - - if(gDungeon->unk644.unk18 == 0) - return 1; - else - return HasRecruitedMon(pokeIndex); -} - void sub_8086B14(void) { Entity * leaderEntity; diff --git a/src/code_8084778.c b/src/dungeon_jobs.c similarity index 98% rename from src/code_8084778.c rename to src/dungeon_jobs.c index dc866dd4b..c21326b4f 100644 --- a/src/code_8084778.c +++ b/src/dungeon_jobs.c @@ -1,11 +1,12 @@ #include "global.h" +#include "globaldata.h" +#include "dungeon_jobs.h" #include "dungeon_strings.h" #include "dungeon_util.h" #include "dungeon_message.h" #include "dungeon_misc.h" #include "dungeon_logic.h" #include "dungeon_leader.h" -#include "code_8084778.h" #include "string_format.h" #include "code_80958E8.h" #include "mailbox.h" @@ -13,8 +14,6 @@ #include "structs/str_dungeon.h" #include "constants/dungeon.h" -extern const u8 gUnknown_8107224[]; - extern void sub_8042A34(DungeonPos *r0); extern void sub_804178C(u32); @@ -208,7 +207,7 @@ void sub_8084778(void) s32 i; WonderMail *wm; - strcpy(gFormatBuffer_Monsters[3], gUnknown_8107224); + InlineStrcpy(gFormatBuffer_Monsters[3], "??????"); for (i = 0; i < MAX_ACCEPTED_JOBS; i++) { wm = GetJobSlotInfo(i); diff --git a/src/dungeon_util_1.c b/src/dungeon_util_1.c deleted file mode 100644 index ef2df02e7..000000000 --- a/src/dungeon_util_1.c +++ /dev/null @@ -1,451 +0,0 @@ -#include "global.h" -#include "dungeon_util_1.h" -#include "dungeon_misc.h" -#include "code_803E46C.h" -#include "code_803E668.h" -#include "code_806CD90.h" -#include "constants/direction.h" -#include "constants/dungeon.h" -#include "code_80861A8.h" -#include "dungeon_leader.h" -#include "dungeon_util.h" -#include "random.h" -#include "math.h" -#include "structs/str_dungeon.h" - -extern s32 gUnknown_202F3D8; -extern const u8 gUnknown_8107358[25]; - -extern s32 GetCameraXPos(void); -extern s32 GetCameraYPos(void); -extern void sub_803F4A0(u32); -extern void sub_803F878(s32, s32); - -Entity *xxx_call_GetLeader(void) -{ - return GetLeader(); -} - -Entity *GetPartnerEntity(void) -{ - s32 counter; - Entity *entity; - for(counter = 0; counter < MAX_TEAM_MEMBERS; counter++) - { - entity = gDungeon->teamPokemon[counter]; - if(EntityIsValid(entity) && GetEntInfo(entity)->joinedAt.id == DUNGEON_JOIN_LOCATION_PARTNER) - { - return entity; - } - } - return GetEntityFromMonsterBehavior(BEHAVIOR_ALLY); -} - -void sub_80854D4(void) -{ - Entity *stack1[MAX_TEAM_MEMBERS]; - Entity *stack2[MAX_TEAM_MEMBERS]; - s32 counter = 0; - s32 index; - Entity *entity; - Entity *entity2; - Entity *entity3; - Entity *entity4; - Entity *entity5; - - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity = gDungeon->teamPokemon[index]; - if(EntityIsValid(entity)) - { - stack1[counter] = entity; - counter++; - } - } - for(; counter < MAX_TEAM_MEMBERS; counter++) - { - stack1[counter] = NULL; - } - counter = 0; - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity2 = stack1[index]; - if(entity2 != NULL && GetEntInfo(entity2)->isTeamLeader) - { - stack1[index] = NULL; - stack2[counter] = entity2; - counter++; - } - } - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity3 = stack1[index]; - if(entity3 != NULL && GetEntInfo(entity3)->joinedAt.id == DUNGEON_JOIN_LOCATION_PARTNER) - { - stack1[index] = NULL; - stack2[counter] = entity3; - counter++; - } - } - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity4 = stack1[index]; - if(entity4 != NULL) - { - stack1[index] = NULL; - stack2[counter] = entity4; - counter++; - } - } - for(; counter < MAX_TEAM_MEMBERS; counter++) - { - stack2[counter] = NULL; - } - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity5 = stack2[index]; - if(entity5 != NULL) - sub_80856C8(entity5, gDungeon->unkE220[index].x, gDungeon->unkE220[index].y); - } -} - -void sub_80855E4(DungeonCallback func) -{ - bool8 flag; - Entity * entity; - Entity * partnerEntity; - s32 index; - - flag = FALSE; - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity = gDungeon->teamPokemon[index]; - if (EntityIsValid(entity)) { - if (GetEntInfo(entity)->joinedAt.id == DUNGEON_JOIN_LOCATION_PARTNER) { - flag = TRUE; - } - func(entity); - } - } - if ((!flag) && (partnerEntity = GetPartnerEntity(), partnerEntity != NULL)) { - func(partnerEntity); - } -} - -void sub_808563C(DungeonCallback func) -{ - Entity * entity; - s32 index; - - for(index = 0; index < DUNGEON_MAX_WILD_POKEMON; index++) - { - entity = gDungeon->wildPokemon[index]; - if ((EntityIsValid(entity)) && (GetEntInfo(entity)->joinedAt.id != 0x41)) { - func(entity); - } - } -} - -Entity *GetEntityFromMonsterBehavior(u8 entityType) -{ - Entity * entity; - s32 index; - - for(index = 0; index < DUNGEON_MAX_POKEMON; index++) - { - entity = gDungeon->activePokemon[index]; - if ((EntityIsValid(entity)) && (GetEntInfo(entity)->monsterBehavior == entityType)) return entity; - } - return NULL; -} - -void sub_80856C8(Entity * pokemon, s32 x, s32 y) -{ - sub_80694C0(pokemon, x, y, 1); - sub_804535C(pokemon,NULL); -} - -void sub_80856E0(Entity * pokemon, s32 direction) -{ - EntityInfo *entityInfo; - s32 counter; - - entityInfo = GetEntInfo(pokemon); - sub_80861D4(pokemon, 6, direction); - - for(counter = 0; counter < 5; counter++) - { - entityInfo->unk174 = F248_Add(entityInfo->unk174, IntToF248(2)); - DungeonRunFrameActions(0x46); - } - entityInfo->action.direction = direction & DIRECTION_MASK; - sub_806CE68(pokemon, direction); - - for(counter = 0; counter < 5; counter++) - { - entityInfo->unk174 = F248_Sub(entityInfo->unk174, IntToF248(2)); - DungeonRunFrameActions(0x46); - } - entityInfo->unk174.raw = 0; // weird one that doesn't match with struct assignment - DungeonRunFrameActions(0x46); -} - -void sub_8085764(void) -{ - Entity *entity; - s32 index; - Entity stackEntity; - - sub_80457DC(&stackEntity); - for(index = 0; index < DUNGEON_MAX_WILD_POKEMON; index++) - { - entity = gDungeon->wildPokemon[index]; - if ((EntityIsValid(entity)) && (GetEntInfo(entity)->monsterBehavior == BEHAVIOR_ALLY)) { - sub_8068FE0(entity,0x207,&stackEntity); - } - } -} - -void sub_80857B8(void) -{ - u8 *direction; - EntityInfo *entityInfo; - Entity *entity; - int index; - - for(index = 0; index < DUNGEON_MAX_POKEMON; index++) - { - entity = gDungeon->activePokemon[index]; - if (EntityIsValid(entity)) { - entityInfo = GetEntInfo(entity); - if ((gDungeon->unk4 == 0) && (gDungeon->unk2 == 0)) { - sub_804535C(entity, 0); - entityInfo->unk15C = 0; - entityInfo->unkFE = 99; - direction = &entityInfo->action.direction; - entityInfo->targetPos.x = gAdjacentTileOffsets[*direction].x + entity->pos.x; - entityInfo->targetPos.y = gAdjacentTileOffsets[*direction].y + entity->pos.y; - sub_806CE68(entity,*direction); - } - } - } -} - -void sub_8085860(s32 x, s32 y) -{ - sub_803F4A0(0); - sub_803F878(X_POS_TO_PIXELPOS(x), Y_POS_TO_PIXELPOS(y)); -} - -void sub_8085890(s32 x, s32 y) -{ - sub_803F4A0(0); - sub_803F878(x, y); -} - -void ShiftCameraToPosition(PixelPos *posStruct, s32 cameraSteps) -{ - s32 XPos; - s32 YPos; - s32 XIncrement; - s32 YIncrement; - - XPos = GetCameraXPos(); - YPos = GetCameraYPos(); - XIncrement = (posStruct->x - XPos) / cameraSteps; - YIncrement = (posStruct->y - YPos) / cameraSteps; - sub_803F4A0(0); - if (0 < cameraSteps) { - do { - XPos += XIncrement; - YPos += YIncrement; - sub_803F878(XPos,YPos); - DungeonRunFrameActions(0x46); - cameraSteps--; - } while (cameraSteps != 0); - } - sub_803F878(posStruct->x,posStruct->y); - DungeonRunFrameActions(0x46); -} - -void SetFacingDirection(Entity *pokemon, s32 direction) -{ - GetEntInfo(pokemon)->action.direction = direction & DIRECTION_MASK; - sub_806CE68(pokemon, direction); -} - -void sub_8085930(s32 direction) -{ - s32 index; - Entity *entity; - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity = gDungeon->teamPokemon[index]; - if(EntityIsValid(entity)) - { - if(direction >= NUM_DIRECTIONS) - { - sub_806CE68(entity, RandInt(NUM_DIRECTIONS)); - } - else - { - GetEntInfo(entity)->action.direction = direction & DIRECTION_MASK; - sub_806CE68(entity, direction); - } - } - } - for(index = 0; index < DUNGEON_MAX_WILD_POKEMON; index++) - { - entity = gDungeon->wildPokemon[index]; - if(EntityIsValid(entity)) - { - if(GetEntInfo(entity)->monsterBehavior == BEHAVIOR_ALLY) - { - if(direction >= NUM_DIRECTIONS) - { - sub_806CE68(entity, RandInt(NUM_DIRECTIONS)); - } - else - { - GetEntInfo(entity)->action.direction = direction & DIRECTION_MASK; - sub_806CE68(entity, direction); - } - } - } - } -} - -void sub_80859F0(s32 direction) -{ - s32 index; - Entity *entity; - for(index = 0; index < DUNGEON_MAX_WILD_POKEMON; index++) - { - entity = gDungeon->wildPokemon[index]; - if(EntityIsValid(entity)) - { - if(direction >= NUM_DIRECTIONS) - { - sub_806CE68(entity, RandInt(NUM_DIRECTIONS)); - } - else - { - GetEntInfo(entity)->action.direction = direction & DIRECTION_MASK; - sub_806CE68(entity, direction); - } - } - } -} - -bool8 ShouldRunMonsterAI(Entity *pokemon) -{ - EntityInfo *pokemonInfo = GetEntInfo(pokemon); - switch (pokemonInfo->monsterBehavior) - { - case BEHAVIOR_RESCUE_TARGET: - case BEHAVIOR_SKARMORY: - case BEHAVIOR_GENGAR: - case BEHAVIOR_EKANS: - case BEHAVIOR_MEDICHAM: - case BEHAVIOR_ZAPDOS: - case BEHAVIOR_MOLTRES: - case BEHAVIOR_ARTICUNO: - case BEHAVIOR_GROUDON_2: - case BEHAVIOR_RAYQUAZA: - case BEHAVIOR_MANKEY: - case BEHAVIOR_MEWTWO: - case BEHAVIOR_ENTEI: - case BEHAVIOR_RAIKOU: - case BEHAVIOR_SUICUNE: - case BEHAVIOR_HO_OH: - case BEHAVIOR_LATIOS: - case BEHAVIOR_REGIROCK: - case BEHAVIOR_REGICE: - case BEHAVIOR_REGISTEEL: - case BEHAVIOR_JIRACHI: - case BEHAVIOR_LUGIA: - case BEHAVIOR_KYOGRE: - case BEHAVIOR_29: - case BEHAVIOR_CELEBI: - case BEHAVIOR_SMEARGLE: - case BEHAVIOR_32: - case BEHAVIOR_33: - case BEHAVIOR_34: - case BEHAVIOR_35: - case BEHAVIOR_MAZE_BOSS: - return TRUE; - case BEHAVIOR_FIXED_ENEMY: - case BEHAVIOR_ALLY: - case BEHAVIOR_DIGLETT: - case BEHAVIOR_ALAKAZAM_1: - case BEHAVIOR_GROUDON_1: - case BEHAVIOR_ALAKAZAM_2: - default: - return FALSE; - } -} - -void sub_8085B0C(Entity *pokemon) -{ - s32 index; - u8 local_28 [25]; - - index = 0; - - memcpy(local_28, gUnknown_8107358, 25); - while (local_28[index] != 0) { - SetFacingDirection(pokemon, local_28[index]); - sub_803E708(6,0x46); - index++; - } -} - -void sub_8085B4C(struct_8085B80 a0[], s16 *a1[], Entity *a2[], s32 a3) -{ - s32 i; - - gUnknown_202F3D8 = a3; - - for (i = 0; i < a3; i++) { - a0[i].unk0 = 1; - a0[i].unk4 = a2[i]; - a0[i].unkC = a1[i]; - a0[i].unk8 = a1[i][2]; - } -} - -bool8 sub_8085B80(struct_8085B80 *a0) -{ - s16 *unkCPtr; - int i; - bool8 ret = FALSE; - - for (i = 0; i < gUnknown_202F3D8; i++) { - Entity *entity = a0[i].unk4; - EntityInfo *enInfo = GetEntInfo(entity); - unkCPtr = a0[i].unkC; - if (a0[i].unk0 != 0) { - ret = TRUE; - if (a0[i].unk8 == 0) { - unkCPtr = unkCPtr + 4; - if (unkCPtr[2] == 0) { - a0[i].unk0 = 0; - enInfo->action.direction = unkCPtr[0] & DIRECTION_MASK; - sub_806CDD4(entity, 7, unkCPtr[0]); - sub_80856C8(entity, unkCPtr[5], unkCPtr[6]); - continue; - } - a0[i].unk8 = unkCPtr[2]; - a0[i].unkC = unkCPtr; - enInfo->action.direction = unkCPtr[0] & DIRECTION_MASK; - sub_806CDD4(entity, 0, (int)*unkCPtr); - } - - a0[i].unk8--; - IncreaseEntityPixelPos(entity, - gAdjacentTileOffsets[*unkCPtr].x * unkCPtr[1] * 0x100, - gAdjacentTileOffsets[*unkCPtr].y * unkCPtr[1] * 0x100); - } - } - return ret; -}