more battle pytamid

This commit is contained in:
DizzyEggg 2018-11-17 22:55:39 +01:00
parent eb66b60f38
commit 40a44a8508
4 changed files with 415 additions and 1203 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,12 +14,22 @@
#include "sound.h"
#include "task.h"
#include "start_menu.h"
#include "trainer_see.h"
#include "main.h"
#include "load_save.h"
#include "script.h"
#include "malloc.h"
#include "constants/battle_frontier.h"
#include "constants/event_objects.h"
#include "constants/event_object_movement_constants.h"
#include "constants/moves.h"
extern u8 gUnknown_0203CEF8[3];
extern void door_upload_tiles(void);
#define PICKUP_ITEMS_SET_COUNT 20
extern const struct MapLayout *const gMapLayouts[];
#define TOTAL_ROUNDS 20
struct Struct_08613650
{
@ -42,18 +52,25 @@ u8 sub_81AA9E4(void);
u16 sub_81A9AA8(u8);
u8 sub_81A9998(s32 *, u8, u8);
u8 sub_81AAA40(void);
bool8 InBattlePyramid(void);
u8 InBattlePyramid(void);
void sub_81A97DC(u8 taskId);
void sub_81A9B44(u16 trainerId);
void sub_81AA96C(u8 *);
void sub_81AA33C(u8 *, u8 *);
// Const rom data.
extern void (* const gUnknown_08613EE0[])(void);
extern const struct Struct_08613650 gUnknown_08613650[];
extern const u16 sPickupItemsLvl50[PICKUP_ITEMS_SET_COUNT][10];
extern const u16 sPickupItemsLvlOpen[PICKUP_ITEMS_SET_COUNT][10];
extern const u16 sPickupItemsLvl50[TOTAL_ROUNDS][10];
extern const u16 sPickupItemsLvlOpen[TOTAL_ROUNDS][10];
extern const u8 gUnknown_08613ABC[63][2];
extern const u8 gUnknown_08613B3A[];
extern const u16 gUnknown_08613F34[9];
extern const u16 gUnknown_08613F28[6];
extern const u16 gUnknown_08D856C8[][16];
extern const u8 gUnknown_08613C1C[50][2];
extern const u8 gUnknown_08613ED8[];
extern const u8 *const *const *const gUnknown_08613EC0[];
// code
void sub_81A8E7C(void)
@ -203,10 +220,10 @@ void sub_81A9290(void)
u8 id;
u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
u32 floor = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
u32 setId = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7) % PICKUP_ITEMS_SET_COUNT;
u32 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7) % TOTAL_ROUNDS;
if (setId >= PICKUP_ITEMS_SET_COUNT)
setId = PICKUP_ITEMS_SET_COUNT - 1;
if (round >= TOTAL_ROUNDS)
round = TOTAL_ROUNDS - 1;
id = sub_81AA9E4();
r7 = (gSpecialVar_LastTalked - gUnknown_08613650[id].unk1) - 1;
@ -223,9 +240,9 @@ void sub_81A9290(void)
}
if (lvlMode != FRONTIER_LVL_50)
gSpecialVar_0x8000 = sPickupItemsLvlOpen[setId][gUnknown_08613ABC[i][1]];
gSpecialVar_0x8000 = sPickupItemsLvlOpen[round][gUnknown_08613ABC[i][1]];
else
gSpecialVar_0x8000 = sPickupItemsLvl50[setId][gUnknown_08613ABC[i][1]];
gSpecialVar_0x8000 = sPickupItemsLvl50[round][gUnknown_08613ABC[i][1]];
gSpecialVar_0x8001 = 1;
}
@ -254,10 +271,6 @@ void sub_81A9414(void)
gFacilityTrainers = gBattleFrontierTrainers;
}
extern const u8 gUnknown_08613C1C[50][2];
extern const u8 gUnknown_08613ED8[];
extern const u8 *const *const *const gUnknown_08613EC0[];
void sub_81A9424(void)
{
s32 i;
@ -408,8 +421,6 @@ void sub_81A97C8(void)
CreateTask(sub_81A97DC, 0);
}
extern const u16 gUnknown_08D856C8[][16];
void sub_81A97DC(u8 taskId)
{
if (gPaletteFade.active)
@ -423,3 +434,387 @@ void sub_81A9828(void)
{
sub_809FDD4();
}
void sub_81A9834(void)
{
s32 i, j, k, l;
for (i = 0; i < 3; i++)
{
s32 id = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1;
for (j = 0; j < 3; j++)
{
if (GetMonData(&gSaveBlock1Ptr->playerParty[id], MON_DATA_SPECIES, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_SPECIES, NULL))
{
for (k = 0; k < 4; k++)
{
for (l = 0; l < 4; l++)
{
if (GetMonData(&gSaveBlock1Ptr->playerParty[id], MON_DATA_MOVE1 + l, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_MOVE1 + k, NULL))
break;
}
if (l == 4)
SetMonMoveSlot(&gPlayerParty[j], MOVE_SKETCH, k);
}
gSaveBlock1Ptr->playerParty[id] = gPlayerParty[j];
gUnknown_0203CEF8[j] = id + 1;
break;
}
}
}
for (i = 0; i < 3; i++)
gSaveBlock2Ptr->frontier.selectedPartyMons[i] = gUnknown_0203CEF8[i];
}
u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2)
{
s32 i, j;
u8 ret = 0;
u16 *map = gUnknown_03005DC0.map;
map += gUnknown_03005DC0.width * 7 + 7;
for (i = 0; i < 32; map += 47, i++)
{
for (j = 0; j < 32; j++)
{
if ((map[j] & 0x3FF) == 0x28E)
{
j += 7 - gEventObjects[gSelectedEventObject].initialCoords.x;
i += 7 - gEventObjects[gSelectedEventObject].initialCoords.y;
if (j >= arg1 || j <= -arg1 || i >= arg1 || i <= -arg1 || arg2 == 0)
{
if (j > 0 && i > 0)
{
if (j >= i)
ret = 2;
else
ret = 3;
}
else if (j < 0 && i < 0)
{
if (j > i)
ret = 0;
else
ret = 1;
}
else if (j == 0)
{
if (i > 0)
ret = 3;
else
ret = 0;
}
else if (i == 0)
{
if (j > 0)
ret = 2;
else
ret = 1;
}
else if (j < 0)
{
if (j + i > 0)
ret = 3;
else
ret = 1;
}
else
{
ret = (~(j + i) >= 0) ? 0 : 2;
}
*arg0 = 0;
}
else
{
*arg0 = arg2;
}
return ret;
}
}
}
return ret;
}
u16 sub_81A9AA8(u8 arg0)
{
return gSaveBlock2Ptr->frontier.field_CB4[arg0 - 1];
}
bool8 GetBattlePyramidTrainerFlag(u8 eventId)
{
return gSaveBlock2Ptr->frontier.field_E2A & gBitTable[gEventObjects[eventId].localId - 1];
}
void sub_81A9B04(void)
{
sub_81A9B44(gTrainerBattleOpponent_A);
if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS)
{
gSelectedEventObject = GetChosenApproachingTrainerEventObjectId(1);
sub_81A9B44(gTrainerBattleOpponent_B);
}
}
struct PyramidWildMon
{
u16 species;
u8 lvl;
u8 abilityBit;
u16 moves[4];
};
extern const struct PyramidWildMon *const gBattlePyramidOpenLevelWildMonPointers[];
extern const struct PyramidWildMon *const gBattlePyramidLevel50WildMonPointers[];
void sub_81A9B44(u16 trainerId)
{
s32 i;
for (i = 0; i < 8; i++)
{
if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId)
gSaveBlock2Ptr->frontier.field_E2A |= gBitTable[i];
}
gEventObjects[gSelectedEventObject].movementType = MOVEMENT_TYPE_WANDER_AROUND;
gSaveBlock1Ptr->eventObjectTemplates[gSpecialVar_LastTalked - 1].movementType = MOVEMENT_TYPE_WANDER_AROUND;
gEventObjects[gSelectedEventObject].initialCoords.x = gEventObjects[gSelectedEventObject].currentCoords.x;
gEventObjects[gSelectedEventObject].initialCoords.y = gEventObjects[gSelectedEventObject].currentCoords.y;
}
void GenerateBattlePyramidWildMon(void)
{
u8 name[POKEMON_NAME_LENGTH + 1];
s32 i;
const struct PyramidWildMon *wildMons;
u32 id;
u32 lvl = gSaveBlock2Ptr->frontier.lvlMode;
u16 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] / 7) % TOTAL_ROUNDS;
if (round >= TOTAL_ROUNDS)
round = TOTAL_ROUNDS - 1;
if (lvl != FRONTIER_LVL_50)
wildMons = gBattlePyramidOpenLevelWildMonPointers[round];
else
wildMons = gBattlePyramidLevel50WildMonPointers[round];
id = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL) - 1;
SetMonData(&gEnemyParty[0], MON_DATA_SPECIES, &wildMons[id].species);
GetSpeciesName(name, wildMons[id].species);
SetMonData(&gEnemyParty[0], MON_DATA_NICKNAME, &name);
if (lvl != FRONTIER_LVL_50)
{
lvl = SetFacilityPtrsGetLevel();
lvl -= wildMons[id].lvl;
lvl = lvl - 5 + (Random() % 11);
}
else
{
lvl = wildMons[id].lvl - 5 + ((Random() % 11));
}
SetMonData(&gEnemyParty[0],
MON_DATA_EXP,
&gExperienceTables[gBaseStats[wildMons[id].species].growthRate][lvl]);
switch (wildMons[id].abilityBit)
{
case 0:
case 1:
SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &wildMons[id].abilityBit);
break;
case 2:
default:
if (gBaseStats[wildMons[id].species].ability2)
{
i = GetMonData(&gEnemyParty[0], MON_DATA_PERSONALITY, NULL) % 2;
SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &i);
}
else
{
i = 0;
SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &i);
}
break;
}
for (i = 0; i < 4; i++)
SetMonMoveSlot(&gEnemyParty[0], wildMons[id].moves[i], i);
if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] >= 140) // BUG: Reading outside the array as lvl was used for mon level instead of frontier lvl mode.
{
id = (Random() % 17) + 15;
for (i = 0; i < NUM_STATS; i++)
SetMonData(&gEnemyParty[0], MON_DATA_HP_IV + i, &id);
}
CalculateMonStats(&gEnemyParty[0]);
}
u8 sub_81A9E28(void)
{
u8 id = sub_81AA9E4();
return gUnknown_08613650[id].unk4;
}
u8 InBattlePyramid(void)
{
if (gMapHeader.mapLayoutId == 361)
return 1;
else if (gMapHeader.mapLayoutId == 378)
return 2;
else
return FALSE;
}
bool8 InBattlePyramid_(void)
{
return (gMapHeader.mapLayoutId == 361 || gMapHeader.mapLayoutId == 378);
}
void sub_81A9E90(void)
{
if (InBattlePyramid())
{
sub_81A9834();
gSaveBlock2Ptr->frontier.field_CA8 = 2;
VarSet(VAR_TEMP_E, 0);
LoadPlayerParty();
}
}
void sub_81A9EC8(void)
{
if (InBattlePyramid())
DoSoftReset();
}
void sub_81A9EDC(u16 trainerId)
{
FrontierSpeechToString(gFacilityTrainers[trainerId].speechBefore);
}
void sub_81A9EFC(u16 trainerId)
{
FrontierSpeechToString(gFacilityTrainers[trainerId].speechWin);
}
void sub_81A9F1C(u16 trainerId)
{
FrontierSpeechToString(gFacilityTrainers[trainerId].speechLose);
}
struct ClassMusic
{
u8 class;
u8 music;
};
extern const struct ClassMusic gUnknown_08613B44[54];
extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88[];
u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerId)
{
s32 i;
for (i = 0; i < ARRAY_COUNT(gUnknown_08613B44); i++)
{
if (gUnknown_08613B44[i].class == gFacilityClassToTrainerClass[gFacilityTrainers[trainerId].facilityClass])
return gUnknown_08613B44[i].music;
}
return 0;
}
void sub_81A9F80(void)
{
ScriptContext1_SetupScript(BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88);
}
u16 sub_81A9F90(u8 count)
{
s32 i;
u16 trainerId;
u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
u32 challengeNum = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7;
u32 battleNum = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
if (battleNum == 7)
{
do
{
trainerId = sub_8162548(challengeNum + 1, battleNum);
for (i = 0 ; i < count; i++)
{
if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId)
break;
}
} while (i != count);
}
else
{
do
{
trainerId = sub_8162548(challengeNum, battleNum);
for (i = 0 ; i < count; i++)
{
if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId)
break;
}
} while (i != count);
}
return trainerId;
}
void sub_81AA078(u16 *mapArg, u8 arg1)
{
s32 j, k;
s32 i;
u8 var0, var1;
u8 *allocated = AllocZeroed(0x10);
sub_81AA96C(allocated);
sub_81AA33C(&var0, &var1);
for (i = 0; i < 16; i++)
{
u16 *map;
s32 heightAdd, widthAdd;
const struct MapLayout *mapLayout = gMapLayouts[allocated[i] + 0x169];
const u16 *layoutMap = mapLayout->map;
gUnknown_03005DC0.map = mapArg;
gUnknown_03005DC0.width = mapLayout->width * 4 + 15;
gUnknown_03005DC0.height = mapLayout->height * 4 + 14;
map = mapArg;
heightAdd = (((i / 4 * mapLayout->height) + 7) * (gUnknown_03005DC0.width));
widthAdd = ((i % 4 * mapLayout->width) + 7);
map += heightAdd + widthAdd;
for (j = 0; j < mapLayout->height; j++)
{
for (k = 0; k < mapLayout->width; k++)
{
if ((layoutMap[k] & 0x3FF) != 0x28E)
{
map[k] = layoutMap[k];
}
else if (i != var1)
{
if (i == var0 && arg1 == 0)
{
gSaveBlock1Ptr->pos.x = (mapLayout->width * (i % 4)) + k;
gSaveBlock1Ptr->pos.y = (mapLayout->height * (i / 4)) + j;
}
map[k] = (layoutMap[k] & 0xFC00) | 0x28D;
}
else
{
map[k] = layoutMap[k];
}
}
map += 15 + (mapLayout->width * 4);
layoutMap += mapLayout->width;
}
}
mapheader_run_script_with_tag_x1();
free(allocated);
}

View File

@ -113,7 +113,7 @@ extern void ShowMapNamePopup(void);
extern bool32 InTrainerHill(void);
extern bool32 sub_808651C(void);
extern bool8 sub_80AF6A4(void);
extern bool8 sub_81A9E6C(void);
extern bool8 InBattlePyramid_(void);
extern bool8 sub_80E909C(void);
extern void sub_81AA1D8(void);
extern void c2_change_map(void);
@ -1808,7 +1808,7 @@ static void InitCurrentFlashLevelScanlineEffect(void)
{
u8 flashLevel;
if (sub_81A9E6C())
if (InBattlePyramid_())
{
door_upload_tiles();
ScanlineEffect_SetParams(sFlashEffectParams);

View File

@ -460,18 +460,18 @@ static bool32 InitStartMenuStep(void)
sUnknown_02037619[0]++;
break;
case 3:
if (GetSafariZoneFlag() != FALSE)
if (GetSafariZoneFlag())
{
ShowSafariBallsWindow();
}
if (InBattlePyramid() != FALSE)
if (InBattlePyramid())
{
ShowPyramidFloorWindow();
}
sUnknown_02037619[0]++;
break;
case 4:
if (PrintStartMenuActions(&sUnknown_02037619[1], 2) == FALSE)
if (!PrintStartMenuActions(&sUnknown_02037619[1], 2))
{
break;
}