diff --git a/include/ground_map_1.h b/include/ground_map_1.h index 505dd1749..9000d073e 100644 --- a/include/ground_map_1.h +++ b/include/ground_map_1.h @@ -3,7 +3,7 @@ void GroundMap_ExecuteEnter(s16); void GroundMap_ExecuteEvent(s16 scriptIndex, u32); -void GroundMap_ExecuteStation(s16, s16, s8, u32); +void GroundMap_ExecuteStation(s32 _map, s32 _group, s32 _sector, bool32 _setScriptState); bool8 GroundMapNotifyAll(s16); bool8 sub_80A4D48(s16 index); @@ -11,4 +11,4 @@ bool8 sub_80A4D48(s16 index); // ground_map_1.s extern s16 sub_80A5728(void); -#endif // GUARD_GROUND_MAP_1_H \ No newline at end of file +#endif // GUARD_GROUND_MAP_1_H diff --git a/include/rescue_team_info.h b/include/rescue_team_info.h index 169a9184d..31f4ab6e2 100644 --- a/include/rescue_team_info.h +++ b/include/rescue_team_info.h @@ -33,7 +33,7 @@ s32 GetPtsToNextRank(void); void SetTeamRankPoints(s32 newPts); void AddToTeamRankPts(s32 newPts); u8 GetRescueTeamRank(void); -const u8 *GetTeamRankString(u8 index); +const u8 *GetTeamRankString(u32 index); u8 GetIsTeamRenamed(void); u32 SaveRescueTeamInfo(u8 *param_1,u32 param_2); u32 ReadRescueTeamInfo(u8 *param_1, u32 param_2); diff --git a/ld_script.txt b/ld_script.txt index e36d1cd8f..f923d3e50 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -316,7 +316,6 @@ SECTIONS { asm/code_809C5C4.o(.text); src/code_809D148.o(.text); src/ground_script.o(.text); - src/ground_script_2.o(.text); src/code_80A26CC.o(.text); asm/code_80A26CC_1.o(.text); src/ground_map.o(.text); diff --git a/src/ground_map.c b/src/ground_map.c index fd8b6c72a..38a123e2f 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -129,22 +129,22 @@ void GroundMap_ExecuteEvent(s16 scriptIndex, u32 param_2) GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_81175E0); } -void GroundMap_ExecuteStation(s16 param_1, s16 param_2, s8 param_3, u32 param_4) +void GroundMap_ExecuteStation(s32 _map, s32 _group, s32 _sector, bool32 _setScriptState) { ScriptInfoSmall script; - s32 iVar1; - s32 iVar2; - s32 iVar3; - u8 iVar4; + s32 map; + s32 group; + s32 sector; + bool8 setScriptState; - iVar1 = param_1; - iVar2 = param_2; - iVar3 = param_3; - iVar4 = param_4; + map = (s16)_map; + group = (s16)_group; + sector = (s8)_sector; + setScriptState = (bool8)_setScriptState; - Log(0, gUnknown_81175EC, iVar1, iVar2, iVar3, iVar4); // GroundMap ExecuteStation %3d %3d %3d %d - GroundMap_GetStationScript(&script, iVar1, iVar2, iVar3); - if (iVar4 != 0) + Log(0, gUnknown_81175EC, map, group, sector, setScriptState); // GroundMap ExecuteStation %3d %3d %3d %d + GroundMap_GetStationScript(&script, map, group, sector); + if (setScriptState != 0) script.state = 5; GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_8117644); diff --git a/src/ground_script.c b/src/ground_script.c index b4953e42d..8ea4017e3 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -1,32 +1,49 @@ #include "global.h" +#include "ground_script.h" +#include "constants/dungeon.h" +#include "constants/friend_area.h" +#include "constants/item.h" +#include "constants/monster.h" +#include "constants/move_id.h" #include "code_8002774.h" #include "code_80118A4.h" +#include "code_8099360.h" +#include "code_8094F88.h" +#include "code_80958E8.h" +#include "code_80972F4.h" #include "code_8097670.h" #include "code_80A26CC.h" #include "debug.h" #include "dungeon.h" #include "event_flag.h" #include "exclusive_pokemon.h" +#include "friend_area.h" #include "ground_link.h" -#include "ground_script.h" #include "ground_lives.h" -#include "ground_sprite.h" #include "ground_main.h" #include "ground_map.h" +#include "ground_map_1.h" +#include "ground_script.h" +#include "ground_sprite.h" +#include "input.h" #include "items.h" +#include "main_loops.h" #include "math.h" +#include "music.h" #include "other_random.h" +#include "random.h" #include "rescue_team_info.h" +#include "save.h" #include "string_format.h" +#include "text_util.h" +#include "pokemon.h" #include "wigglytuff_shop1.h" #include "wonder_mail.h" + void GroundMap_Select(s16); void GroundMap_SelectDungeon(s16, DungeonLocation*, u8); -void GroundMap_ExecuteEnter(s16); -void GroundMap_ExecuteEvent(s16, bool8); void GroundMap_GetStationScript(ScriptInfoSmall *out, s16, s32, s32); -void GroundMap_ExecuteStation(s32, s32, s32, bool8); void GroundLives_ExecuteScript(s32, s16 *, ScriptInfoSmall *); void GroundObject_ExecuteScript(s32, s16 *, ScriptInfoSmall *); void GroundEffect_ExecuteScript(s32, s16 *, ScriptInfoSmall *); @@ -54,17 +71,12 @@ bool8 sub_802FCF0(void); void sub_809733C(s16, bool8); void sub_80973A8(s16, bool8); -void sub_8097418(s16, bool8); void sub_80975A8(s16, bool8); -void sub_8098D1C(s32, u32, s32); -void sub_8098E18(s32, s32); u32 sub_80999E8(); void sub_80999FC(s32); u32 sub_8099A10(); u32 sub_8099A34(); u32 sub_8099A48(); -u32 sub_8099A5C(); -u32 sub_8099AFC(); u32 sub_809A6E4(); u32 sub_809A6F8(); u32 sub_809A738(); @@ -95,7 +107,6 @@ void sub_809D1CC(s32, PixelPos*, s32); void sub_809D1E4(s32, s32, s32); void sub_809D208(s32, PixelPos*, s32); void sub_809D220(s32, s32, s32); -bool8 GroundCancelAllEntities(void); void GroundScriptLockJumpZero(s16); s16 GetAdjustedGroundMap(s32); void sub_80A87AC(s32, s32); @@ -117,14 +128,10 @@ void DeleteGroundObjects(void); void DeleteGroundEffects(void); s32 ExecuteScriptCommand(Action *action); bool8 IsFanfareSEPlaying_1(u16 songIndex); -bool8 sub_8099B94(void); bool8 IsEqualtoBGTrack(u16 songIndex); -s32 ExecuteScriptCommand(Action *action); -void InitScriptData(ScriptData *); bool8 sub_8099B94(void); s8 VecDirection8Radial(PixelPos*); PixelPos SetVecFromDirectionSpeed(s8, s32); -void CopyStringtoBuffer(u8 *buffer, u8 *string); bool8 sub_8098DCC(u32 speed); extern const PixelPos gUnknown_81164DC; extern u32 gUnknown_2039DA4; @@ -132,26 +139,12 @@ extern char *gUnknown_203B4B0; extern char gUnknown_2039D98[10]; void sub_8099220(void *param_1, s32 param_2); extern u32 gUnlockBranchLabels[]; -u8 ScriptPrintNullTextbox(void); s16 sub_8002694(u8 param_1); // value -> GroundEnter lookup bool8 sub_809B260(void *dst); bool8 sub_809B18C(s32 *sp); bool8 sub_809AFFC(u8 *); -u8 GroundScriptCheckLockCondition(Action *param_1, s16 param_2); bool8 sub_809D234(void); -s32 GroundLink_GetPos(s32 _arg0, PixelPos *pos); -void sub_80999FC(s32); -bool8 sub_809B1C0(s32, s32, char[12]); -bool8 sub_80023E4(u32 param_1); // some kind of helper for predefined scenario checks s32 sub_80A14E8(Action *, u8, u32, s32); -void sub_80A87AC(s32, s32); -const ScriptCommand *FindLabel(Action *action, s32 r1); -void SetRescueTeamName(u8 *buffer); -s32 GetScriptVarValue(u8 *localVarBuf, s32 varId); -s32 GetScriptVarArrayValue(u8 *localVarBuf, s32 varId, s32 idx); -void SetScriptVarValue(u8 *localVarBuf, s32 varId, s32 val); -void SetScriptVarArrayValue(u8 *localVarBuf, s32 varId, s32 idx, s32 val); -unkStruct_203B480 * GetMailatIndex(u8 index); u8 sub_80990EC(struct unkStruct_20398C8 *param_1, s32 param_2); extern s16 gCurrentMap; @@ -198,6 +191,66 @@ extern Action *sub_80A882C(s16); extern Action *sub_80AC240(s16); extern Action *sub_80AD158(s16); +extern u8 gUnknown_8116848[]; + +bool8 GroundLivesNotifyAll(s16); +bool8 GroundObjectsNotifyAll(s16); +bool8 GroundEffectsNotifyAll(s16); + +void sub_8098C58(void); +void sub_8098CC8(void); +bool8 sub_80961D8(void); +void ResetMailbox(void); +void sub_80963FC(void); +void sub_8096488(void); +bool8 sub_80964B4(void); +extern void nullsub_104(void); +s16 sub_80A8C4C(); +s16 sub_80A90C8(); +bool8 sub_8097640(); +u8 sub_80964E4(); +s32 sub_80A8E9C(); +u8 sub_80A8D20(); +bool8 sub_80A87E0(); +s16 sub_80A8BFC(s16); +void sub_80A8F50(const u8 *buffer, s32, s32 size); + +extern const u8 *gFriendAreaDialogue[]; +extern struct unkStruct_808D144 gUnknown_8116710; +extern struct unkStruct_808D144 gUnknown_8116760; +extern struct unkStruct_808D144 gUnknown_8116794; +extern struct unkStruct_808D144 gUnknown_81167BC; +extern struct unkStruct_808D144 gUnknown_8116738; +extern struct unkStruct_808D144 gUnknown_811681C; +extern DungeonLocation gUnknown_81167E8; +extern DungeonLocation gUnknown_8116788; +extern DungeonLocation gUnknown_811678C; +extern DungeonLocation gUnknown_8116790; +extern u16 gUnknown_2039DA8; + +PokemonStruct1 *sub_808D2E8(s32 species, u8 *name, u32 _itemID, DungeonLocation *location, u16 *moveID); +bool8 HasRecruitedMon(s32 species); +extern Item gUnknown_8116844; +extern Item gUnknown_81167E4; +bool8 sub_809124C(u8 id, u8 param_3); +extern const u8 gUnknown_81167EC[]; +void sub_80A56A0(s32, s32); +void sub_80A56F0(); +void sub_80A5704(); +void sub_809C760(void); +void sub_809C6EC(void); +void sub_809C6CC(u16 param_1); +void sub_80A86C8(s16, s32); +void sub_80AC1B0(s16, s32); +void sub_80AD0C8(s16, s32); +s32 sub_80A5984(); +void sub_80A59A0(s32, s32 *, u16); +void GroundSprite_ExtendPaletteAdd(u32, u16); +void GroundSprite_ExtendPaletteDelete(u32); +extern void sub_80997F4(u16, u16); +s32 sub_809CFE8(u16 param_1); +extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); + EWRAM_INIT static int sNumChoices = 0; // -1 didn't match @@ -3047,3 +3100,882 @@ UNUSED bool8 GroundScript_ExecuteTrigger(s16 r0) return FALSE; } +s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) +{ + switch(idx) + { + case 1: + sub_8098C58(); + return 0; + case 2: + if(sub_8011C34() == -1) + sub_8011C40(Rand32Bit()); + sub_8011C28(1); + sub_8001064(); + sub_809965C(); + return 0; + case 3: + sub_8098CC8(); + return 0; + case 4: + return sub_80961D8() == 0 ? 0 : 1; + case 5: + ResetMailbox(); + return 0; + case 6: + sub_80963FC(); + return 0; + case 7: + sub_8096488(); + return 0; + case 8: + return sub_80964B4() == 0 ? 0 : 1; + case 9: + { + u8 var; + if (sub_80023E4(8) == 0) { + var = sub_808D4B0(); + } + else { + var = sub_808D500(); + } + nullsub_104(); + return var != 0; + } + break; + case 0xA: + { + s32 ret; + s32 ret2; + if ((action->unkC).arr[0] == 1) + { + u8 text[0x100]; + DungeonLocation dungLocation; + ret = sub_80A8C4C((action->unkC).arr[1], &dungLocation); + if(ret != 0) + { + if (dungLocation.id == DUNGEON_HOWLING_FOREST_2 && ret == 0x104) { + return 2; + } + + ret2 = sub_80A90C8((action->unkC).arr[1]); + InlineStrcpy(text, gFriendAreaDialogue[ret2]); + if (ScriptPrintText(0, 1, text) != 0) + return 1; + } + } + } + return 0; + case 0xB: + return (CountJobsinDungeon(sub_80A2740(GetScriptVarValue(0, DUNGEON_ENTER_INDEX))) > 0); + case 0xC: + { + u8 sp_104; + if(sub_8099394(&sp_104) != 0) + { + unkStruct_203B480 *p = gUnknown_203B480; + p += sp_104; + if(p->rescuesAllowed > 0) + return 1; + } + } + return 0; + case 0xD: + return sub_8097640() ? 1 : 0; + break; + case 0xE: + { + s32 index; + for(index = 0x11; index < NUM_DUNGEON_MAZE; index++) + { + if (IsMazeCompleted((s16) index)) { + if (!GetScriptVarArrayValue(0, TRAINING_PRESENT_LIST, (u16) index)) { + SetScriptVarArrayValue(0, TRAINING_PRESENT_LIST, (u16) index, 1); + return index - 0x10; + } + } + } + return 0; + } + case 0xF: + return sub_80964E4() == 0 ? 0 : 1; + case 0x10: + if(action->unk8[0] == 1) + if(action->unk8[1] == 0) + if(action->unkC.arr[0] == 1) + { + if(sub_80A87E0(action->unk8[1], sub_80A8E9C(action->unkC.arr[1])) != 0) + return 1; + } + return 0; + case 0x11: + return sub_80A8D20() == 0 ? 0 : 1; + case 0x12: + { + s32 held = gRealInputs.held; + if((held & (R_BUTTON | L_BUTTON))) + return 1; + else + return 0; + } + + case 0x13: + { + PokemonStruct1 *ptr; + + ptr = sub_80A8D54(r2); + if(ptr) + return PokemonFlag2(ptr); + } + return 0; + case 0x14: + if(action->unk8[0] == 1) { + if(GetCanMoveFlag(sub_80A8BFC(action->unk8[1]))) + return 1; + } + return 0; + case 0x15: + { + s32 r4; + PixelPos sp_318; + PixelPos sp_320; + s32 r5 = sub_80A7AE8(r2); + if(r5 >= 0) { + r4 = (r3 << 8); + action->callbacks->getHitboxCenter(action->parentObject, &sp_318); + sub_80A8FD8(r5, &sp_320); + + if(sp_318.x - r4 <= sp_320.x + && sp_318.x + r4 >= sp_320.x + && sp_318.y - r4 <= sp_320.y + && sp_318.y + r4 >= sp_320.y) + { + return 1; + } + } + } + return 0; + case 0x16: + { + s32 index; + PokemonStruct1 *ptr; ptr = sub_80A8D54(1); + if(ptr) + { + for(index = 0; index < POKEMON_NAME_LENGTH; index++) + { + ptr->name[index] = 0; + } + return 1; + } + } + return 0; + case 0x17: + UnlockFriendArea(WILD_PLAINS); + UnlockFriendArea(MIST_RISE_FOREST); + return 0; + case 0x18: + sub_80A8F50(gUnknown_2039D98, 0x3C, POKEMON_NAME_LENGTH); + return 0; + case 0x19: + { + struct unkStruct_808D144 sp_4; + PokemonStruct1 sp_2c; + PokemonStruct1 *ptr; + s32 index; + + + UnlockFriendArea(GetFriendArea(MONSTER_MAGNEMITE)); + sp_4 = gUnknown_8116710; + sub_808D144(&sp_2c, &sp_4); + ptr = sub_808D1DC(&sp_2c); + if (ptr == NULL) return 1; + for(index = 0; index < POKEMON_NAME_LENGTH; index++) + { + ptr->name[index] = gUnknown_2039D98[index]; + } + sub_80922B4(gFormatBuffer_Names[r2], gUnknown_2039D98, POKEMON_NAME_LENGTH); + IncrementAdventureNumJoined(); + return 0; + } + break; + + case 0x1A: + sub_80A8F50(gUnknown_2039D98, 0x53, POKEMON_NAME_LENGTH); + return 0; + + case 0x1B: + { + PokemonStruct1 *pokemon; + struct unkStruct_808D144 sp_84; + PokemonStruct1 sp_ac; + + UnlockFriendArea(GetFriendArea(MONSTER_ABSOL)); + sp_84 = gUnknown_8116738; + sub_808D144(&sp_ac, &sp_84); + pokemon = sub_808D1DC(&sp_ac); + if(pokemon == NULL) return 1; + IncrementAdventureNumJoined(); + pokemon->unk0 |= FLAG_ON_TEAM; + return 0; + } + case 0x1C: + { + PokemonStruct1 *pokemon = sub_808D434(MONSTER_ABSOL, 0); + if(pokemon == NULL) return 1; + pokemon->unk0 |= FLAG_ON_TEAM; + return 0; + } + case 0x1D: + { + if( sub_808D278(MONSTER_SMEARGLE) == 0) + return 1; + else + return 0; + } + case 0x1E: + sub_80A8F50(gUnknown_2039D98, 0x7C, POKEMON_NAME_LENGTH); + return 0; + + case 0x1F: + { + PokemonStruct1 *pokemon; + s32 index; + struct unkStruct_808D144 sp_108; + PokemonStruct1 sp_130; + + sp_108 = gUnknown_8116760; + sub_808D144(&sp_130, &sp_108); + pokemon = sub_808D1DC(&sp_130); + if(!pokemon) return 1; + for(index = 0; index < POKEMON_NAME_LENGTH; index++) + { + pokemon->name[index] = gUnknown_2039D98[index]; + } + sub_80922B4(gFormatBuffer_Names[r2], gUnknown_2039D98, POKEMON_NAME_LENGTH); + IncrementAdventureNumJoined(); + return 0; + + } + break; + + case 0x20: + { + sub_80026E8(0x9E, 0x1); + if(sub_808D434(MONSTER_ZAPDOS, 0) == NULL) + { + if(sub_808D2E8(MONSTER_ZAPDOS, NULL, ITEM_NOTHING, &gUnknown_8116788, NULL)) + IncrementAdventureNumJoined(); + } + if(sub_808D434(MONSTER_MOLTRES, 0) == NULL) + { + if(sub_808D2E8(MONSTER_MOLTRES, NULL, ITEM_NOTHING, &gUnknown_811678C, NULL)) + IncrementAdventureNumJoined(); + } + if(sub_808D434(MONSTER_ARTICUNO, 0) == NULL) + { + if(sub_808D2E8(MONSTER_ARTICUNO, NULL, ITEM_NOTHING, &gUnknown_8116790, NULL)) + IncrementAdventureNumJoined(); + } + return 0; + } + break; + + + case 0x21: + if(HasRecruitedMon(MONSTER_ARTICUNO)) + if(HasRecruitedMon(MONSTER_ZAPDOS)) + if(HasRecruitedMon(MONSTER_MOLTRES)) + return 1; + return 0; + case 0x22: + { + PokemonStruct1 *pokemon = GetPlayerPokemonStruct(); + + if(pokemon->speciesNum != MONSTER_ARTICUNO && pokemon->speciesNum != MONSTER_ZAPDOS && pokemon->speciesNum != MONSTER_MOLTRES) + return 1; + } + return 0; + case 0x23: + { + PokemonStruct1 *pokemon; + pokemon = GetPlayerPokemonStruct(); + if (pokemon != NULL && pokemon->speciesNum == MONSTER_HO_OH) + return 2; + else if (sub_8098134(MONSTER_HO_OH) != 0) + return 1; + } + return 0; + case 0x24: + sub_80A8F50(gUnknown_2039D98, 0x79, POKEMON_NAME_LENGTH); + return 0; + + case 0x25: + { + PokemonStruct1 *pokemon; + s32 index; + struct unkStruct_808D144 sp_188; + PokemonStruct1 sp_1b0; + + if(!GetFriendAreaStatus(GetFriendArea(MONSTER_LATIOS))) + UnlockFriendArea(GetFriendArea(MONSTER_LATIOS)); + sp_188 = gUnknown_8116794; + sub_808D144(&sp_1b0, &sp_188); + pokemon = sub_808D1DC(&sp_1b0); + if(pokemon == NULL) return 1; + for(index = 0; index < POKEMON_NAME_LENGTH; index++) + { + pokemon->name[index] = gUnknown_2039D98[index]; + } + IncrementAdventureNumJoined(); + return 0; + } + + break; + case 0x26: + sub_80A8F50(gUnknown_2039D98, 0x7A, POKEMON_NAME_LENGTH); + return 0; + case 0x27: + { + PokemonStruct1 *pokemon; + s32 index; + struct unkStruct_808D144 sp_208; + PokemonStruct1 sp_230; + + sp_208 = gUnknown_81167BC; + sub_808D144(&sp_230, &sp_208); + pokemon = sub_808D1DC(&sp_230); + if(pokemon == NULL) return 1; + for(index = 0; index < POKEMON_NAME_LENGTH; index++) + { + pokemon->name[index] = gUnknown_2039D98[index]; + } + IncrementAdventureNumJoined(); + return 0; + } + break; + + case 0x28: + { + if(GetNumberOfFilledInventorySlots() >= INVENTORY_SIZE) + { + Item *item = &gUnknown_81167E4; + s32 id = item->id; + if(IsNotMoneyOrUsedTMItem(id)) + if(gTeamInventoryRef->teamStorage[id] < 999) + gTeamInventoryRef->teamStorage[id] += 1; + + } + else + { + Item *item = &gUnknown_81167E4; + sub_809124C(item->id, 0); + FillInventoryGaps(); + } + } + return 0; + + case 0x29: + { + s32 index = (s16)(RandInt(0x1A2) + 1); + s32 r4 = RandInt(0x20); + s32 r7 = 0x1A4; + s32 r6 = 0; + + while (1) + { + s16 indexS16; + index = (s16)(index + 1); + if (index >= 0x1a4) { + index = 1; + } + if (--r7 < 0) { + if (r6 == 0) { + SetScriptVarValue(NULL, NEW_FRIEND_KIND, 0); + return 0; + } + if (r4 >= r6) { + r4 = RandInt(r6); + r7 = 0x1A4; + } + } + // S16 memes AGAIN... + indexS16 = index; + index = indexS16; + if (indexS16 == MONSTER_ARTICUNO || indexS16 == MONSTER_ZAPDOS || indexS16 == MONSTER_MOLTRES + || indexS16 == MONSTER_GROUDON + || indexS16 == MONSTER_RAYQUAZA + || indexS16 == MONSTER_RAYQUAZA_CUTSCENE + || indexS16 == MONSTER_KYOGRE + || indexS16 == MONSTER_LUGIA + || indexS16 == MONSTER_CASTFORM_SNOWY + || indexS16 == MONSTER_CASTFORM_SUNNY + || indexS16 == MONSTER_CASTFORM_RAINY + || indexS16 == MONSTER_DEOXYS_NORMAL + || indexS16 == MONSTER_DEOXYS_ATTACK + || indexS16 == MONSTER_DEOXYS_DEFENSE + || indexS16 == MONSTER_DEOXYS_SPEED + || indexS16 == MONSTER_MEWTWO + || indexS16 == MONSTER_JIRACHI + || indexS16 == MONSTER_MEW + || indexS16 == MONSTER_LATIAS + || indexS16 == MONSTER_LATIOS + || indexS16 == MONSTER_ENTEI + || indexS16 == MONSTER_RAIKOU + || indexS16 == MONSTER_SUICUNE + || indexS16 == MONSTER_HO_OH + || indexS16 == MONSTER_REGIROCK + || indexS16 == MONSTER_REGICE + || indexS16 == MONSTER_REGISTEEL + || indexS16 == MONSTER_CELEBI + ) + continue; + if(!IsExclusivePokemonUnlocked(index)) continue; + if(GetFriendAreaStatus(GetFriendArea(index))) { + if(HasRecruitedMon(index)) continue; + if(sub_808D278(index) == 0) continue; + } + + r6++; + r4--; + if (r4 < 0) + break; + } + + SetScriptVarValue(NULL, NEW_FRIEND_KIND, index); + WriteFriendAreaName(gFormatBuffer_FriendArea, GetFriendArea(index), FALSE); + if (GetFriendAreaStatus(GetFriendArea(index)) != 0) + return 1; + else + return 2; + } + case 0x2A: + { + s32 id = (s16) GetScriptVarValue(0, NEW_FRIEND_KIND); + WriteFriendAreaName(gFormatBuffer_FriendArea,(GetFriendArea(id)), FALSE); + if (id == 0) + return 0; + else if(GetFriendAreaStatus(GetFriendArea(id)) != 0) + return 1; + else + return 2; + } + break; + case 0x2B: + sub_80A8F50(gUnknown_2039D98, 0x20, POKEMON_NAME_LENGTH); + return 0; + case 0x2C: + { + PokemonStruct1 *pokemon; + s32 index; + if(r2 != 0) + { + s32 id = (s16) GetScriptVarValue(0, NEW_FRIEND_KIND); + s32 matchMe = id; + WriteFriendAreaName(gFormatBuffer_FriendArea,(GetFriendArea((s16) id)), FALSE); + if(id == 0) + return 0; + + if(!GetFriendAreaStatus(GetFriendArea(id))) + UnlockFriendArea(GetFriendArea(id)); + pokemon = sub_808D2E8(matchMe, NULL ,ITEM_NOTHING, &gUnknown_81167E8, MOVE_NOTHING); + if(pokemon == NULL) + return 0; + + for(index = 0; index < POKEMON_NAME_LENGTH; index++) + pokemon->name[index] = gUnknown_2039D98[index]; + IncrementAdventureNumJoined(); + return 1; + } + else + { + SetScriptVarValue(NULL, NEW_FRIEND_KIND, 0); + return 0; + } + } + + case 0x2D: + if(GetPtsToNextRank() > 0) + return 1; + else + return 0; + case 0x2E: + { + s32 rankBefore = GetRescueTeamRank(); + s32 points = GetPtsToNextRank(); + if(points > 0) { + s32 rankAfter; + AddToTeamRankPts(points); + rankAfter = GetRescueTeamRank(); + InlineStrcpy(gFormatBuffer_Items[0], GetTeamRankString(rankBefore)); + InlineStrcpy(gFormatBuffer_Items[1], GetTeamRankString(rankAfter)); + if(ScriptPrintText(0, -1, gUnknown_81167EC) != 0) + return 1; + } + else { + return 0; + } + } + // breakthrough + case 0x2F: + AddToTeamMoney(0x2710); + return 0; + case 0x30: + { + if(sub_808D278(MONSTER_GARDEVOIR) == 0) + return 1; + else + return 0; + } + break; + case 0x31: + sub_80A8F50(gUnknown_2039D98, 0x52, POKEMON_NAME_LENGTH); + return 0; + + case 0x32: + { + struct unkStruct_808D144 sp_288; + PokemonStruct1 sp_2b0; + sp_288 = gUnknown_811681C; + sub_808D144(&sp_2b0, &sp_288); + if(sub_808D1DC(&sp_2b0) == 0) { + return 1; + } + else { + IncrementAdventureNumJoined(); + return 0; + } + } + case 0x33: + if(ScriptVarScenarioAfter(SCENARIO_MAIN, 0x12, -1)) + { + if(GetScriptVarValue(0, GROUND_GETOUT) != 4) + { + if (GetScriptVarArrayValue(0, EVENT_GONBE, 0) <= 0) + { + if(OtherRandInt(0x100) == 0) + { + SetScriptVarArrayValue(0, EVENT_GONBE, 0, 4); + return 1; + } + else + SetScriptVarArrayValue(0, EVENT_GONBE, 0, 1); + } + } + } + return 0; + + case 0x34: + { + s32 index; + s32 id; + Item *item = &gUnknown_8116844; + for(index = 0; index < 3; index++) + { + if(GetNumberOfFilledInventorySlots() >= INVENTORY_SIZE) + { + id = item->id; + if(IsNotMoneyOrUsedTMItem(id)) + if(gTeamInventoryRef->teamStorage[id] < 999) + gTeamInventoryRef->teamStorage[id] += 1; + + } + else + { + sub_809124C(item->id, 0); + FillInventoryGaps(); + } + } + } + return 0; + case 0x35: + { + PokemonStruct1 *pokemon = GetPlayerPokemonStruct(); + if(pokemon != NULL && pokemon->speciesNum == MONSTER_CHANSEY) + return 2; + else + if(sub_8098134(MONSTER_CHANSEY) != 0) + return 1; + else + return 0; + } + break; + + case 0x38: + sub_80A56A0(0, 1); + return 0; + case 0x36: { + s32 sp_328[2]; + sp_328[0] = r2; + sp_328[1] = r3; + sub_80A56F0(sp_328); + return 0; + } + case 0x37: { + s32 sp_330[2]; + sp_330[0] = r2; + sp_330[1] = r3; + sub_80A5704(sp_330); + return 0; + } + case 0x39: + sub_809C6CC(r2); + return 0; + case 0x3A: + sub_809C6EC(); + return 0; + case 0x3B: + sub_809C760(); + return 0; + case 0x3C: + { + s32 index; + index = 0; + for(index = 0; index < 0x18; index = (s16)(index + 1)) + { + sub_80A86C8(index, 0x400000); + } + for (index = 0; index < 0x10; index = (s16)(index + 1)) + { + sub_80AC1B0(index, 0x400000); + } + for (index = 0; index < 0x10; index = (s16)(index + 1)) + { + sub_80AD0C8(index, 0x400000); + } + } + return 0; + case 0x3D: { + s32 sp_338[2]; + sp_338[0] = r2; + sp_338[1] = r3; + sub_80A59A0(0, sp_338, sub_80A5984(1, sp_338)); + return 0; + } + case 0x3E: + { + s32 ret; + Action *r7; + GroundEffectData sp_308; + PixelPos sp_340; + PixelPos sp_348; + PixelPos sp_350; + PixelPos sp_358; + + sp_308.kind = 1; + sp_308.unk1 = 0; + sp_308.width = 1; + sp_308.height = 1; + sp_308.pos = (CompactPos) {0}; + sp_308.script = gFunctionScriptTable[406].script; // MOVE_DEBUG_CAMERA + ret = GroundEffect_Add(-1, &sp_308, r2, r3); + if(ret < 0) break; + r7 = sub_80AD158(ret); + sub_80A579C(&sp_340, &sp_348); + sp_340.y += 0xC00; + sp_348.y += 0xC00; + action->callbacks->getHitboxCenter(action->parentObject, &sp_350); + if(sp_350.x < sp_340.x) + sp_350.x = sp_340.x; + else if (sp_350.x >= sp_348.x) + sp_350.x = sp_348.x - 1; + if(sp_350.y < sp_340.y) + sp_350.y = sp_340.y; + else if (sp_350.y >= sp_348.y) + sp_350.y = sp_348.y - 1; + + sp_340.x -= 1024; + sp_340.y -= 1024; + sp_348.x += 1024; + sp_348.y += 1024; + + r7->callbacks->setPositionBounds(r7->parentObject, &sp_340, &sp_348); + r7->callbacks->moveReal(r7->parentObject, &sp_350); + sp_358 = (PixelPos) {0}; + r7->callbacks->moveRelative(r7->parentObject, &sp_358); + return 1; + } + break; + + case 0x3F: + { + s32 index; + s32 ret; + s32 held = gRealInputs.held; + s32 pressed = gRealInputs.pressed; + if(!(pressed & (START_BUTTON | SELECT_BUTTON))) + { + PixelPos sp_368; + ret = sub_809CFE8(held); + if((s8)ret != -1) + { + s32 to; + sp_368 = SetVecFromDirectionSpeed(ret,0x100); + + to = 2; + if(held & B_BUTTON) { + to = 4; + } + + for(index = 0; index < to; index++) + { + if(action->callbacks->moveRelative(action->parentObject, &sp_368) != 0) + { + PixelPos pixelPos = {0, sp_368.y}; + if(action->callbacks->moveRelative(action->parentObject, &pixelPos) != 0) + { + PixelPos pixelPos = {sp_368.x, 0}; + action->callbacks->moveRelative(action->parentObject, &pixelPos); + } + } + } + } + return -1; + } + } + break; + + case 0x40: + sub_80993C0(r2 == 0 ? 0 : 1); + return 0; + case 0x42: + sub_8011C28(1); + GroundMainGameEndRequest(r2); + FadeOutAllMusic(r2); + return 0; + case 0x41: + GroundMainGameEndRequest(r2); + FadeOutAllMusic(r2); + return 0; + case 0x43: + gUnknown_2039DA8 = GetCurrentBGSong(); + if(gUnknown_2039DA8 != STOP_BGM) + return 1; + return 0; + case 0x44: + if (gUnknown_2039DA8 != STOP_BGM) + { + xxx_call_start_new_bgm(gUnknown_2039DA8); + gUnknown_2039DA8 = STOP_BGM; + return 1; + } + return 0; + case 0x45: + if (gUnknown_2039DA8 != STOP_BGM) + { + xxx_call_fade_in_new_bgm(gUnknown_2039DA8, r2); + gUnknown_2039DA8 = STOP_BGM; + return 1; + } + return 0; + case 0x46: + if (gUnknown_2039DA8 != STOP_BGM) + { + xxx_call_queue_bgm(gUnknown_2039DA8); + gUnknown_2039DA8 = STOP_BGM; + return 1; + } + return 0; + case 0x47: + sub_80997F4(r2, r3); + return 0; + case 0x48: + sub_80997F4(0x1E, r2); + return 0; + case 0x49: + GroundSprite_ExtendPaletteAdd(0, r2); + return 0; + case 0x4A: + GroundSprite_ExtendPaletteDelete(0); + return 0; + } + + return 0; +} + +void GroundScript_Unlock(void) +{ + s32 index; + bool8 cond; + + if(gAnyScriptLocked == 0) return; + + gAnyScriptLocked = 0; + index = 0; + for (index = 0; index <= 0x80; index++) { + if(gScriptLocks[index] != 0) { + Log(1, gUnknown_8116848, index); + cond = GroundMapNotifyAll(index); + cond |= GroundLivesNotifyAll(index); + cond |= GroundObjectsNotifyAll(index); + cond |= GroundEffectsNotifyAll(index); + + if(gScriptLockConds[index] != 0) { + if (cond) { + GroundMapNotifyAll(index | 0x80); + GroundLivesNotifyAll(index | 0x80); + GroundObjectsNotifyAll(index | 0x80); + GroundEffectsNotifyAll(index | 0x80); + gScriptLocks[index] = gScriptLockConds[index] = 0; + } + } else { + gScriptLocks[index] = 0; + } + } + } +} + +const ScriptCommand *FindLabel(Action *action, s32 r1) +{ + ScriptCommand script; + const ScriptCommand *scriptPtr2; + const ScriptCommand *scriptPtr; + + scriptPtr2 = action->scriptData.script.ptr2; + scriptPtr = scriptPtr2 + 1; + + while(1) { + script = *scriptPtr; + scriptPtr++; + + if(script.op == 0xF4 && r1 == script.argShort) break; + + // DS: Assert(script.op != 0, "script search label error %d", label) + // DS: Assert(script.op != 0xF6, "script search label error %d", label) + } + return scriptPtr; +} + +const ScriptCommand *ResolveJump(Action *action, s32 r1) +{ + ScriptCommand script; + const ScriptCommand *scriptPtr; + s32 temp; + + scriptPtr = action->scriptData.script.ptr; + + while(1) { + script = *scriptPtr; + + if (script.op == 0xCC) + { + if(FlagJudge(r1, script.arg1, JUDGE_EQ)) + return FindLabel(action, script.argShort); + } + else if (script.op == 0xCD) + { + if(FlagJudge(r1, script.arg1, script.argByte)) + return FindLabel(action, script.argShort); + } + else if (script.op == 0xCE) + { + temp = GetScriptVarValue(action->scriptData.localVars.buf, (s16)script.arg1); + if(FlagJudge(r1, temp, script.argByte)) + return FindLabel(action, script.argShort); + } + else + { + return scriptPtr; + } + scriptPtr++; + } +} diff --git a/src/ground_script_2.c b/src/ground_script_2.c deleted file mode 100644 index 121e8ed62..000000000 --- a/src/ground_script_2.c +++ /dev/null @@ -1,998 +0,0 @@ -#include "global.h" -#include "ground_script.h" -#include "constants/dungeon.h" -#include "constants/friend_area.h" -#include "constants/item.h" -#include "constants/monster.h" -#include "constants/move_id.h" -#include "code_80118A4.h" -#include "code_8099360.h" -#include "code_8094F88.h" -#include "code_80958E8.h" -#include "code_80972F4.h" -#include "code_80A26CC.h" -#include "debug.h" -#include "event_flag.h" -#include "exclusive_pokemon.h" -#include "friend_area.h" -#include "ground_lives.h" -#include "ground_main.h" -#include "ground_map_1.h" -#include "ground_script.h" -#include "input.h" -#include "items.h" -#include "main_loops.h" -#include "music.h" -#include "other_random.h" -#include "random.h" -#include "string_format.h" -#include "structs/str_wonder_mail.h" -#include "text_util.h" -#include "pokemon.h" - - -extern u8 gAnyScriptLocked; -extern u8 gScriptLocks[]; -extern u8 gScriptLockConds[]; -extern u8 gUnknown_8116848[]; - -bool8 GroundLivesNotifyAll(s16); -bool8 GroundObjectsNotifyAll(s16); -bool8 GroundEffectsNotifyAll(s16); - -void sub_8098C58(void); -void sub_8098CC8(void); -bool8 sub_80961D8(void); -void ResetMailbox(void); -void sub_80963FC(void); -void sub_8096488(void); -bool8 sub_80964B4(void); -extern void nullsub_104(void); -s16 sub_80A8C4C(); -s16 sub_80A90C8(); -bool8 sub_8097640(); -u8 sub_80964E4(); -s32 sub_80A8E9C(); -u8 sub_80A8D20(); -bool8 sub_80A87E0(); -s16 sub_80A8BFC(s16); -void sub_80A8F50(const u8 *buffer, s32, s32 size); - -extern const u8 *gFriendAreaDialogue[]; -extern struct unkStruct_808D144 gUnknown_8116710; -extern struct unkStruct_808D144 gUnknown_8116760; -extern struct unkStruct_808D144 gUnknown_8116794; -extern struct unkStruct_808D144 gUnknown_81167BC; -extern struct unkStruct_808D144 gUnknown_8116738; -extern struct unkStruct_808D144 gUnknown_811681C; -extern DungeonLocation gUnknown_81167E8; -extern DungeonLocation gUnknown_8116788; -extern DungeonLocation gUnknown_811678C; -extern DungeonLocation gUnknown_8116790; -extern u16 gUnknown_2039DA8; -extern u8 gUnknown_2039D98[POKEMON_NAME_LENGTH]; - -PokemonStruct1 *sub_808D278(s32 species); -PokemonStruct1 *sub_808D2E8(s32 species, u8 *name, u32 _itemID, DungeonLocation *location, u16 *moveID); -bool8 HasRecruitedMon(s32 species); -extern Item gUnknown_8116844; -extern Item gUnknown_81167E4; -bool8 sub_809124C(u8 id, u8 param_3); -extern const u8 gUnknown_81167EC[]; -void sub_80A56A0(s32, s32); -void sub_80A56F0(); -void sub_80A5704(); -void sub_809C760(void); -void sub_809C6EC(void); -void sub_809C6CC(u16 param_1); -void sub_80A86C8(s16, s32); -void sub_80AC1B0(s16, s32); -void sub_80AD0C8(s16, s32); -s32 sub_80A5984(); -void sub_80A59A0(s32, s32 *, u16); -void GroundSprite_ExtendPaletteAdd(u32, u16); -void GroundSprite_ExtendPaletteDelete(u32); -extern void sub_80997F4(u16, u16); -s32 sub_809CFE8(u16 param_1); -extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); - -// save.h -void sub_8011C40(s32 x); -s32 sub_8011C34(void); -extern void sub_8011C28(u32); - -bool8 ScriptPrintText(s32, s16, const char*); -PokemonStruct1 *sub_80A8D54(s16); -void IncrementAdventureNumJoined(void); // sub_8097848 - -// resuce_team_info -u8 GetRescueTeamRank(void); -void AddToTeamRankPts(s32); -s32 GetPtsToNextRank(void); -const u8 *GetTeamRankString(s32); - -PixelPos SetVecFromDirectionSpeed(s8 r1, u32 r2); - -s16 GroundEffect_Add(s16 id, GroundEffectData*, s16 group, s8 sector); -extern Action *sub_80AD158(s16); - -s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) -{ - switch(idx) - { - case 1: - sub_8098C58(); - return 0; - case 2: - if(sub_8011C34() == -1) - sub_8011C40(Rand32Bit()); - sub_8011C28(1); - sub_8001064(); - sub_809965C(); - return 0; - case 3: - sub_8098CC8(); - return 0; - case 4: - return sub_80961D8() == 0 ? 0 : 1; - case 5: - ResetMailbox(); - return 0; - case 6: - sub_80963FC(); - return 0; - case 7: - sub_8096488(); - return 0; - case 8: - return sub_80964B4() == 0 ? 0 : 1; - case 9: - { - u8 var; - if (sub_80023E4(8) == 0) { - var = sub_808D4B0(); - } - else { - var = sub_808D500(); - } - nullsub_104(); - return var != 0; - } - break; - case 0xA: - { - s32 ret; - s32 ret2; - if ((action->unkC).arr[0] == 1) - { - u8 text[0x100]; - DungeonLocation dungLocation; - ret = sub_80A8C4C((action->unkC).arr[1], &dungLocation); - if(ret != 0) - { - if (dungLocation.id == 0x44 && ret == 0x104) { - return 2; - } - - ret2 = sub_80A90C8((action->unkC).arr[1]); - InlineStrcpy(text, gFriendAreaDialogue[ret2]); - if (ScriptPrintText(0, 1, text) != 0) - return 1; - } - } - } - return 0; - case 0xB: - return (CountJobsinDungeon(sub_80A2740(GetScriptVarValue(0, DUNGEON_ENTER_INDEX))) > 0); - case 0xC: - { - u8 sp_104; - if(sub_8099394(&sp_104) != 0) - { - unkStruct_203B480 *p = gUnknown_203B480; - p += sp_104; - if(p->rescuesAllowed > 0) - return 1; - } - } - return 0; - case 0xD: - return sub_8097640() ? 1 : 0; - break; - case 0xE: - { - s32 index; - for(index = 0x11; index < NUM_DUNGEON_MAZE; index++) - { - if (IsMazeCompleted((s16) index)) { - if (!GetScriptVarArrayValue(0, TRAINING_PRESENT_LIST, (u16) index)) { - SetScriptVarArrayValue(0, TRAINING_PRESENT_LIST, (u16) index, 1); - return index - 0x10; - } - } - } - return 0; - } - case 0xF: - return sub_80964E4() == 0 ? 0 : 1; - case 0x10: - if(action->unk8[0] == 1) - if(action->unk8[1] == 0) - if(action->unkC.arr[0] == 1) - { - if(sub_80A87E0(action->unk8[1], sub_80A8E9C(action->unkC.arr[1])) != 0) - return 1; - } - return 0; - case 0x11: - return sub_80A8D20() == 0 ? 0 : 1; - case 0x12: - { - s32 held = gRealInputs.held; - if((held & (R_BUTTON | L_BUTTON))) - return 1; - else - return 0; - } - - case 0x13: - { - PokemonStruct1 *ptr; - - ptr = sub_80A8D54(r2); - if(ptr) - return PokemonFlag2(ptr); - } - return 0; - case 0x14: - if(action->unk8[0] == 1) { - if(GetCanMoveFlag(sub_80A8BFC(action->unk8[1]))) - return 1; - } - return 0; - case 0x15: - { - s32 r4; - PixelPos sp_318; - PixelPos sp_320; - s32 r5 = sub_80A7AE8(r2); - if(r5 >= 0) { - r4 = (r3 << 8); - action->callbacks->getHitboxCenter(action->parentObject, &sp_318); - sub_80A8FD8(r5, &sp_320); - - if(sp_318.x - r4 <= sp_320.x - && sp_318.x + r4 >= sp_320.x - && sp_318.y - r4 <= sp_320.y - && sp_318.y + r4 >= sp_320.y) - { - return 1; - } - } - } - return 0; - case 0x16: - { - s32 index; - PokemonStruct1 *ptr; ptr = sub_80A8D54(1); - if(ptr) - { - for(index = 0; index < POKEMON_NAME_LENGTH; index++) - { - ptr->name[index] = 0; - } - return 1; - } - } - return 0; - case 0x17: - UnlockFriendArea(WILD_PLAINS); - UnlockFriendArea(MIST_RISE_FOREST); - return 0; - case 0x18: - sub_80A8F50(gUnknown_2039D98, 0x3C, POKEMON_NAME_LENGTH); - return 0; - case 0x19: - { - struct unkStruct_808D144 sp_4; - PokemonStruct1 sp_2c; - PokemonStruct1 *ptr; - s32 index; - - - UnlockFriendArea(GetFriendArea(MONSTER_MAGNEMITE)); - sp_4 = gUnknown_8116710; - sub_808D144(&sp_2c, &sp_4); - ptr = sub_808D1DC(&sp_2c); - if (ptr == NULL) return 1; - for(index = 0; index < POKEMON_NAME_LENGTH; index++) - { - ptr->name[index] = gUnknown_2039D98[index]; - } - sub_80922B4(gFormatBuffer_Names[r2], gUnknown_2039D98, POKEMON_NAME_LENGTH); - IncrementAdventureNumJoined(); - return 0; - } - break; - - case 0x1A: - sub_80A8F50(gUnknown_2039D98, 0x53, POKEMON_NAME_LENGTH); - return 0; - - case 0x1B: - { - PokemonStruct1 *pokemon; - struct unkStruct_808D144 sp_84; - PokemonStruct1 sp_ac; - - UnlockFriendArea(GetFriendArea(MONSTER_ABSOL)); - sp_84 = gUnknown_8116738; - sub_808D144(&sp_ac, &sp_84); - pokemon = sub_808D1DC(&sp_ac); - if(pokemon == NULL) return 1; - IncrementAdventureNumJoined(); - pokemon->unk0 |= FLAG_ON_TEAM; - return 0; - } - case 0x1C: - { - PokemonStruct1 *pokemon = sub_808D434(MONSTER_ABSOL, 0); - if(pokemon == NULL) return 1; - pokemon->unk0 |= FLAG_ON_TEAM; - return 0; - } - case 0x1D: - { - if( sub_808D278(MONSTER_SMEARGLE) == 0) - return 1; - else - return 0; - } - case 0x1E: - sub_80A8F50(gUnknown_2039D98, 0x7C, POKEMON_NAME_LENGTH); - return 0; - - case 0x1F: - { - PokemonStruct1 *pokemon; - s32 index; - struct unkStruct_808D144 sp_108; - PokemonStruct1 sp_130; - - sp_108 = gUnknown_8116760; - sub_808D144(&sp_130, &sp_108); - pokemon = sub_808D1DC(&sp_130); - if(!pokemon) return 1; - for(index = 0; index < POKEMON_NAME_LENGTH; index++) - { - pokemon->name[index] = gUnknown_2039D98[index]; - } - sub_80922B4(gFormatBuffer_Names[r2], gUnknown_2039D98, POKEMON_NAME_LENGTH); - IncrementAdventureNumJoined(); - return 0; - - } - break; - - case 0x20: - { - sub_80026E8(0x9E, 0x1); - if(sub_808D434(MONSTER_ZAPDOS, 0) == NULL) - { - if(sub_808D2E8(MONSTER_ZAPDOS, NULL, ITEM_NOTHING, &gUnknown_8116788, NULL)) - IncrementAdventureNumJoined(); - } - if(sub_808D434(MONSTER_MOLTRES, 0) == NULL) - { - if(sub_808D2E8(MONSTER_MOLTRES, NULL, ITEM_NOTHING, &gUnknown_811678C, NULL)) - IncrementAdventureNumJoined(); - } - if(sub_808D434(MONSTER_ARTICUNO, 0) == NULL) - { - if(sub_808D2E8(MONSTER_ARTICUNO, NULL, ITEM_NOTHING, &gUnknown_8116790, NULL)) - IncrementAdventureNumJoined(); - } - return 0; - } - break; - - - case 0x21: - if(HasRecruitedMon(MONSTER_ARTICUNO)) - if(HasRecruitedMon(MONSTER_ZAPDOS)) - if(HasRecruitedMon(MONSTER_MOLTRES)) - return 1; - return 0; - case 0x22: - { - PokemonStruct1 *pokemon = GetPlayerPokemonStruct(); - - if(pokemon->speciesNum != MONSTER_ARTICUNO && pokemon->speciesNum != MONSTER_ZAPDOS && pokemon->speciesNum != MONSTER_MOLTRES) - return 1; - } - return 0; - case 0x23: - { - PokemonStruct1 *pokemon; - pokemon = GetPlayerPokemonStruct(); - if (pokemon != NULL && pokemon->speciesNum == MONSTER_HO_OH) - return 2; - else if (sub_8098134(MONSTER_HO_OH) != 0) - return 1; - } - return 0; - case 0x24: - sub_80A8F50(gUnknown_2039D98, 0x79, POKEMON_NAME_LENGTH); - return 0; - - case 0x25: - { - PokemonStruct1 *pokemon; - s32 index; - struct unkStruct_808D144 sp_188; - PokemonStruct1 sp_1b0; - - if(!GetFriendAreaStatus(GetFriendArea(MONSTER_LATIOS))) - UnlockFriendArea(GetFriendArea(MONSTER_LATIOS)); - sp_188 = gUnknown_8116794; - sub_808D144(&sp_1b0, &sp_188); - pokemon = sub_808D1DC(&sp_1b0); - if(pokemon == NULL) return 1; - for(index = 0; index < POKEMON_NAME_LENGTH; index++) - { - pokemon->name[index] = gUnknown_2039D98[index]; - } - IncrementAdventureNumJoined(); - return 0; - } - - break; - case 0x26: - sub_80A8F50(gUnknown_2039D98, 0x7A, POKEMON_NAME_LENGTH); - return 0; - case 0x27: - { - PokemonStruct1 *pokemon; - s32 index; - struct unkStruct_808D144 sp_208; - PokemonStruct1 sp_230; - - sp_208 = gUnknown_81167BC; - sub_808D144(&sp_230, &sp_208); - pokemon = sub_808D1DC(&sp_230); - if(pokemon == NULL) return 1; - for(index = 0; index < POKEMON_NAME_LENGTH; index++) - { - pokemon->name[index] = gUnknown_2039D98[index]; - } - IncrementAdventureNumJoined(); - return 0; - } - break; - - case 0x28: - { - if(GetNumberOfFilledInventorySlots() >= INVENTORY_SIZE) - { - Item *item = &gUnknown_81167E4; - s32 id = item->id; - if(IsNotMoneyOrUsedTMItem(id)) - if(gTeamInventoryRef->teamStorage[id] < 999) - gTeamInventoryRef->teamStorage[id] += 1; - - } - else - { - Item *item = &gUnknown_81167E4; - sub_809124C(item->id, 0); - FillInventoryGaps(); - } - } - return 0; - - case 0x29: - { - s32 index = (s16)(RandInt(0x1A2) + 1); - s32 r4 = RandInt(0x20); - s32 r7 = 0x1A4; - s32 r6 = 0; - - while (1) - { - s16 indexS16; - index = (s16)(index + 1); - if (index >= 0x1a4) { - index = 1; - } - if (--r7 < 0) { - if (r6 == 0) { - SetScriptVarValue(NULL, NEW_FRIEND_KIND, 0); - return 0; - } - if (r4 >= r6) { - r4 = RandInt(r6); - r7 = 0x1A4; - } - } - // S16 memes AGAIN... - indexS16 = index; - index = indexS16; - if (indexS16 == MONSTER_ARTICUNO || indexS16 == MONSTER_ZAPDOS || indexS16 == MONSTER_MOLTRES - || indexS16 == MONSTER_GROUDON - || indexS16 == MONSTER_RAYQUAZA - || indexS16 == MONSTER_RAYQUAZA_CUTSCENE - || indexS16 == MONSTER_KYOGRE - || indexS16 == MONSTER_LUGIA - || indexS16 == MONSTER_CASTFORM_SNOWY - || indexS16 == MONSTER_CASTFORM_SUNNY - || indexS16 == MONSTER_CASTFORM_RAINY - || indexS16 == MONSTER_DEOXYS_NORMAL - || indexS16 == MONSTER_DEOXYS_ATTACK - || indexS16 == MONSTER_DEOXYS_DEFENSE - || indexS16 == MONSTER_DEOXYS_SPEED - || indexS16 == MONSTER_MEWTWO - || indexS16 == MONSTER_JIRACHI - || indexS16 == MONSTER_MEW - || indexS16 == MONSTER_LATIAS - || indexS16 == MONSTER_LATIOS - || indexS16 == MONSTER_ENTEI - || indexS16 == MONSTER_RAIKOU - || indexS16 == MONSTER_SUICUNE - || indexS16 == MONSTER_HO_OH - || indexS16 == MONSTER_REGIROCK - || indexS16 == MONSTER_REGICE - || indexS16 == MONSTER_REGISTEEL - || indexS16 == MONSTER_CELEBI - ) - continue; - if(!IsExclusivePokemonUnlocked(index)) continue; - if(GetFriendAreaStatus(GetFriendArea(index))) { - if(HasRecruitedMon(index)) continue; - if(sub_808D278(index) == 0) continue; - } - - r6++; - r4--; - if (r4 < 0) - break; - } - - SetScriptVarValue(NULL, NEW_FRIEND_KIND, index); - WriteFriendAreaName(gFormatBuffer_FriendArea, GetFriendArea(index), FALSE); - if (GetFriendAreaStatus(GetFriendArea(index)) != 0) - return 1; - else - return 2; - } - case 0x2A: - { - s32 id = (s16) GetScriptVarValue(0, NEW_FRIEND_KIND); - WriteFriendAreaName(gFormatBuffer_FriendArea,(GetFriendArea(id)), FALSE); - if (id == 0) - return 0; - else if(GetFriendAreaStatus(GetFriendArea(id)) != 0) - return 1; - else - return 2; - } - break; - case 0x2B: - sub_80A8F50(gUnknown_2039D98, 0x20, POKEMON_NAME_LENGTH); - return 0; - case 0x2C: - { - PokemonStruct1 *pokemon; - s32 index; - if(r2 != 0) - { - s32 id = (s16) GetScriptVarValue(0, NEW_FRIEND_KIND); - s32 matchMe = id; - WriteFriendAreaName(gFormatBuffer_FriendArea,(GetFriendArea((s16) id)), FALSE); - if(id == 0) - return 0; - - if(!GetFriendAreaStatus(GetFriendArea(id))) - UnlockFriendArea(GetFriendArea(id)); - pokemon = sub_808D2E8(matchMe, NULL ,ITEM_NOTHING, &gUnknown_81167E8, MOVE_NOTHING); - if(pokemon == NULL) - return 0; - - for(index = 0; index < POKEMON_NAME_LENGTH; index++) - pokemon->name[index] = gUnknown_2039D98[index]; - IncrementAdventureNumJoined(); - return 1; - } - else - { - SetScriptVarValue(NULL, NEW_FRIEND_KIND, 0); - return 0; - } - } - - case 0x2D: - if(GetPtsToNextRank() > 0) - return 1; - else - return 0; - case 0x2E: - { - s32 rankBefore = GetRescueTeamRank(); - s32 points = GetPtsToNextRank(); - if(points > 0) { - s32 rankAfter; - AddToTeamRankPts(points); - rankAfter = GetRescueTeamRank(); - InlineStrcpy(gFormatBuffer_Items[0], GetTeamRankString(rankBefore)); - InlineStrcpy(gFormatBuffer_Items[1], GetTeamRankString(rankAfter)); - if(ScriptPrintText(0, -1, gUnknown_81167EC) != 0) - return 1; - } - else { - return 0; - } - } - // breakthrough - case 0x2F: - AddToTeamMoney(0x2710); - return 0; - case 0x30: - { - if(sub_808D278(MONSTER_GARDEVOIR) == 0) - return 1; - else - return 0; - } - break; - case 0x31: - sub_80A8F50(gUnknown_2039D98, 0x52, POKEMON_NAME_LENGTH); - return 0; - - case 0x32: - { - struct unkStruct_808D144 sp_288; - PokemonStruct1 sp_2b0; - sp_288 = gUnknown_811681C; - sub_808D144(&sp_2b0, &sp_288); - if(sub_808D1DC(&sp_2b0) == 0) { - return 1; - } - else { - IncrementAdventureNumJoined(); - return 0; - } - } - case 0x33: - if(ScriptVarScenarioAfter(SCENARIO_MAIN, 0x12, -1)) - { - if(GetScriptVarValue(0, GROUND_GETOUT) != 4) - { - if (GetScriptVarArrayValue(0, EVENT_GONBE, 0) <= 0) - { - if(OtherRandInt(0x100) == 0) - { - SetScriptVarArrayValue(0, EVENT_GONBE, 0, 4); - return 1; - } - else - SetScriptVarArrayValue(0, EVENT_GONBE, 0, 1); - } - } - } - return 0; - - case 0x34: - { - s32 index; - s32 id; - Item *item = &gUnknown_8116844; - for(index = 0; index < 3; index++) - { - if(GetNumberOfFilledInventorySlots() >= INVENTORY_SIZE) - { - id = item->id; - if(IsNotMoneyOrUsedTMItem(id)) - if(gTeamInventoryRef->teamStorage[id] < 999) - gTeamInventoryRef->teamStorage[id] += 1; - - } - else - { - sub_809124C(item->id, 0); - FillInventoryGaps(); - } - } - } - return 0; - case 0x35: - { - PokemonStruct1 *pokemon = GetPlayerPokemonStruct(); - if(pokemon != NULL && pokemon->speciesNum == MONSTER_CHANSEY) - return 2; - else - if(sub_8098134(MONSTER_CHANSEY) != 0) - return 1; - else - return 0; - } - break; - - case 0x38: - sub_80A56A0(0, 1); - return 0; - case 0x36: { - s32 sp_328[2]; - sp_328[0] = r2; - sp_328[1] = r3; - sub_80A56F0(sp_328); - return 0; - } - case 0x37: { - s32 sp_330[2]; - sp_330[0] = r2; - sp_330[1] = r3; - sub_80A5704(sp_330); - return 0; - } - case 0x39: - sub_809C6CC(r2); - return 0; - case 0x3A: - sub_809C6EC(); - return 0; - case 0x3B: - sub_809C760(); - return 0; - case 0x3C: - { - s32 index; - index = 0; - for(index = 0; index < 0x18; index = (s16)(index + 1)) - { - sub_80A86C8(index, 0x400000); - } - for (index = 0; index < 0x10; index = (s16)(index + 1)) - { - sub_80AC1B0(index, 0x400000); - } - for (index = 0; index < 0x10; index = (s16)(index + 1)) - { - sub_80AD0C8(index, 0x400000); - } - } - return 0; - case 0x3D: { - s32 sp_338[2]; - sp_338[0] = r2; - sp_338[1] = r3; - sub_80A59A0(0, sp_338, sub_80A5984(1, sp_338)); - return 0; - } - case 0x3E: - { - s32 ret; - Action *r7; - GroundEffectData sp_308; - PixelPos sp_340; - PixelPos sp_348; - PixelPos sp_350; - PixelPos sp_358; - - sp_308.kind = 1; - sp_308.unk1 = 0; - sp_308.width = 1; - sp_308.height = 1; - sp_308.pos = (CompactPos) {0}; - sp_308.script = gFunctionScriptTable[406].script; // MOVE_DEBUG_CAMERA - ret = GroundEffect_Add(-1, &sp_308, r2, r3); - if(ret < 0) break; - r7 = sub_80AD158(ret); - sub_80A579C(&sp_340, &sp_348); - sp_340.y += 0xC00; - sp_348.y += 0xC00; - action->callbacks->getHitboxCenter(action->parentObject, &sp_350); - if(sp_350.x < sp_340.x) - sp_350.x = sp_340.x; - else if (sp_350.x >= sp_348.x) - sp_350.x = sp_348.x - 1; - if(sp_350.y < sp_340.y) - sp_350.y = sp_340.y; - else if (sp_350.y >= sp_348.y) - sp_350.y = sp_348.y - 1; - - sp_340.x -= 1024; - sp_340.y -= 1024; - sp_348.x += 1024; - sp_348.y += 1024; - - r7->callbacks->setPositionBounds(r7->parentObject, &sp_340, &sp_348); - r7->callbacks->moveReal(r7->parentObject, &sp_350); - sp_358 = (PixelPos) {0}; - r7->callbacks->moveRelative(r7->parentObject, &sp_358); - return 1; - } - break; - - case 0x3F: - { - s32 index; - s32 ret; - s32 held = gRealInputs.held; - s32 pressed = gRealInputs.pressed; - if(!(pressed & (START_BUTTON | SELECT_BUTTON))) - { - PixelPos sp_368; - ret = sub_809CFE8(held); - if((s8)ret != -1) - { - s32 to; - sp_368 = SetVecFromDirectionSpeed(ret,0x100); - - to = 2; - if(held & B_BUTTON) { - to = 4; - } - - for(index = 0; index < to; index++) - { - if(action->callbacks->moveRelative(action->parentObject, &sp_368) != 0) - { - PixelPos pixelPos = {0, sp_368.y}; - if(action->callbacks->moveRelative(action->parentObject, &pixelPos) != 0) - { - PixelPos pixelPos = {sp_368.x, 0}; - action->callbacks->moveRelative(action->parentObject, &pixelPos); - } - } - } - } - return -1; - } - } - break; - - case 0x40: - sub_80993C0(r2 == 0 ? 0 : 1); - return 0; - case 0x42: - sub_8011C28(1); - GroundMainGameEndRequest(r2); - FadeOutAllMusic(r2); - return 0; - case 0x41: - GroundMainGameEndRequest(r2); - FadeOutAllMusic(r2); - return 0; - case 0x43: - gUnknown_2039DA8 = GetCurrentBGSong(); - if(gUnknown_2039DA8 != STOP_BGM) - return 1; - return 0; - case 0x44: - if (gUnknown_2039DA8 != STOP_BGM) - { - xxx_call_start_new_bgm(gUnknown_2039DA8); - gUnknown_2039DA8 = STOP_BGM; - return 1; - } - return 0; - case 0x45: - if (gUnknown_2039DA8 != STOP_BGM) - { - xxx_call_fade_in_new_bgm(gUnknown_2039DA8, r2); - gUnknown_2039DA8 = STOP_BGM; - return 1; - } - return 0; - case 0x46: - if (gUnknown_2039DA8 != STOP_BGM) - { - xxx_call_queue_bgm(gUnknown_2039DA8); - gUnknown_2039DA8 = STOP_BGM; - return 1; - } - return 0; - case 0x47: - sub_80997F4(r2, r3); - return 0; - case 0x48: - sub_80997F4(0x1E, r2); - return 0; - case 0x49: - GroundSprite_ExtendPaletteAdd(0, r2); - return 0; - case 0x4A: - GroundSprite_ExtendPaletteDelete(0); - return 0; - } - - return 0; -} - -void GroundScript_Unlock(void) -{ - s32 index; - bool8 cond; - - if(gAnyScriptLocked == 0) return; - - gAnyScriptLocked = 0; - index = 0; - for (index = 0; index <= 0x80; index++) { - if(gScriptLocks[index] != 0) { - Log(1, gUnknown_8116848, index); - cond = GroundMapNotifyAll(index); - cond |= GroundLivesNotifyAll(index); - cond |= GroundObjectsNotifyAll(index); - cond |= GroundEffectsNotifyAll(index); - - if(gScriptLockConds[index] != 0) { - if (cond) { - GroundMapNotifyAll(index | 0x80); - GroundLivesNotifyAll(index | 0x80); - GroundObjectsNotifyAll(index | 0x80); - GroundEffectsNotifyAll(index | 0x80); - gScriptLocks[index] = gScriptLockConds[index] = 0; - } - } else { - gScriptLocks[index] = 0; - } - } - } -} - -const ScriptCommand *FindLabel(Action *action, s32 r1) -{ - ScriptCommand script; - const ScriptCommand *scriptPtr2; - const ScriptCommand *scriptPtr; - - scriptPtr2 = action->scriptData.script.ptr2; - scriptPtr = scriptPtr2 + 1; - - while(1) { - script = *scriptPtr; - scriptPtr++; - - if(script.op == 0xF4 && r1 == script.argShort) break; - - // DS: Assert(script.op != 0, "script search label error %d", label) - // DS: Assert(script.op != 0xF6, "script search label error %d", label) - } - return scriptPtr; -} - -const ScriptCommand *ResolveJump(Action *action, s32 r1) -{ - ScriptCommand script; - const ScriptCommand *scriptPtr; - s32 temp; - - scriptPtr = action->scriptData.script.ptr; - - while(1) { - script = *scriptPtr; - - if (script.op == 0xCC) - { - if(FlagJudge(r1, script.arg1, JUDGE_EQ)) - return FindLabel(action, script.argShort); - } - else if (script.op == 0xCD) - { - if(FlagJudge(r1, script.arg1, script.argByte)) - return FindLabel(action, script.argShort); - } - else if (script.op == 0xCE) - { - temp = GetScriptVarValue(action->scriptData.localVars.buf, (s16)script.arg1); - if(FlagJudge(r1, temp, script.argByte)) - return FindLabel(action, script.argShort); - } - else - { - return scriptPtr; - } - scriptPtr++; - } -} - diff --git a/src/rescue_team_info.c b/src/rescue_team_info.c index df4a3e2de..54d400208 100644 --- a/src/rescue_team_info.c +++ b/src/rescue_team_info.c @@ -98,9 +98,10 @@ u8 GetRescueTeamRank(void) return LUCARIO_RANK; } -const u8 *GetTeamRankString(u8 index) +const u8 *GetTeamRankString(u32 index) { - return gRescueTeamRanks[index]; + u8 index_u8 = (u8)index; + return gRescueTeamRanks[index_u8]; } // Unused