Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed type1 and type2 to be consistent #2021

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ STATIC_ASSERT(sizeof(((struct BattleStruct *)0)->palaceFlags) * 8 >= MAX_BATTLER

#define TARGET_TURN_DAMAGED ((gSpecialStatuses[gBattlerTarget].physicalDmg != 0 || gSpecialStatuses[gBattlerTarget].specialDmg != 0))

#define IS_BATTLER_OF_TYPE(battlerId, type)((gBattleMons[battlerId].type1 == type || gBattleMons[battlerId].type2 == type))
#define IS_BATTLER_OF_TYPE(battlerId, type)((gBattleMons[battlerId].types[0] == type || gBattleMons[battlerId].types[1] == type))
#define SET_BATTLER_TYPE(battlerId, type) \
{ \
gBattleMons[battlerId].type1 = type; \
gBattleMons[battlerId].type2 = type; \
gBattleMons[battlerId].types[0] = type; \
gBattleMons[battlerId].types[1] = type; \
}

#define GET_STAT_BUFF_ID(n)((n & 0xF)) // first four bits 0x1, 0x2, 0x4, 0x8
Expand Down
3 changes: 1 addition & 2 deletions include/battle_controllers.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ struct ChooseMoveStruct
u8 currentPp[MAX_MON_MOVES];
u8 maxPp[MAX_MON_MOVES];
u16 species;
u8 monType1;
u8 monType2;
u8 monTypes[2];
};

enum
Expand Down
3 changes: 1 addition & 2 deletions include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ struct BattlePokemon
/*0x17*/ u32 abilityNum:1;
/*0x18*/ s8 statStages[NUM_BATTLE_STATS];
/*0x20*/ u8 ability;
/*0x21*/ u8 type1;
/*0x22*/ u8 type2;
/*0x21*/ u8 types[2];
/*0x23*/ u8 unknown;
/*0x24*/ u8 pp[MAX_MON_MOVES];
/*0x28*/ u16 hp;
Expand Down
10 changes: 5 additions & 5 deletions src/battle_ai_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,16 +1119,16 @@ static void Cmd_get_type(void)
switch (typeVar)
{
case AI_TYPE1_USER: // AI user primary type
AI_THINKING_STRUCT->funcResult = gBattleMons[sBattler_AI].type1;
AI_THINKING_STRUCT->funcResult = gBattleMons[sBattler_AI].types[0];
break;
case AI_TYPE1_TARGET: // target primary type
AI_THINKING_STRUCT->funcResult = gBattleMons[gBattlerTarget].type1;
AI_THINKING_STRUCT->funcResult = gBattleMons[gBattlerTarget].types[0];
break;
case AI_TYPE2_USER: // AI user secondary type
AI_THINKING_STRUCT->funcResult = gBattleMons[sBattler_AI].type2;
AI_THINKING_STRUCT->funcResult = gBattleMons[sBattler_AI].types[1];
break;
case AI_TYPE2_TARGET: // target secondary type
AI_THINKING_STRUCT->funcResult = gBattleMons[gBattlerTarget].type2;
AI_THINKING_STRUCT->funcResult = gBattleMons[gBattlerTarget].types[1];
break;
case AI_TYPE_MOVE: // type of move being pointed to
AI_THINKING_STRUCT->funcResult = gBattleMoves[AI_THINKING_STRUCT->moveConsidered].type;
Expand Down Expand Up @@ -1527,7 +1527,7 @@ static void Cmd_if_type_effectiveness(void)

// TypeCalc does not assign to gMoveResultFlags, Cmd_typecalc does
// This makes the check for gMoveResultFlags below always fail
// This is how you get the "dual non-immunity" glitch, where AI
// This is how you get the "dual non-immunity" glitch, where AI
// will use ineffective moves on immune pokémon if the second type
// has a non-neutral, non-immune effectiveness
#ifdef BUGFIX
Expand Down
4 changes: 2 additions & 2 deletions src/battle_ai_switch_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ u8 GetMostSuitableMonToSwitchInto(void)
u8 type1 = gSpeciesInfo[species].types[0];
u8 type2 = gSpeciesInfo[species].types[1];
u8 typeDmg = TYPE_MUL_NORMAL;
ModulateByTypeEffectiveness(gBattleMons[opposingBattler].type1, type1, type2, &typeDmg);
ModulateByTypeEffectiveness(gBattleMons[opposingBattler].type2, type1, type2, &typeDmg);
ModulateByTypeEffectiveness(gBattleMons[opposingBattler].types[0], type1, type2, &typeDmg);
ModulateByTypeEffectiveness(gBattleMons[opposingBattler].types[1], type1, type2, &typeDmg);

/* Possible bug: this comparison gives the type that takes the most damage, when
a "good" AI would want to select the type that takes the least damage. Unknown if this
Expand Down
2 changes: 1 addition & 1 deletion src/battle_controller_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ static void HandleInputChooseMove(void)
PlaySE(SE_SELECT);
if (moveInfo->moves[gMoveSelectionCursor[gActiveBattler]] == MOVE_CURSE)
{
if (moveInfo->monType1 != TYPE_GHOST && moveInfo->monType2 != TYPE_GHOST)
if (moveInfo->monTypes[0] != TYPE_GHOST && moveInfo->monTypes[1] != TYPE_GHOST)
moveTarget = MOVE_TARGET_USER;
else
moveTarget = MOVE_TARGET_SELECTED;
Expand Down
2 changes: 1 addition & 1 deletion src/battle_gfx_sfx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void)

if (moveInfo->moves[chosenMoveId] == MOVE_CURSE)
{
if (moveInfo->monType1 != TYPE_GHOST && moveInfo->monType2 != TYPE_GHOST)
if (moveInfo->monTypes[0] != TYPE_GHOST && moveInfo->monTypes[1] != TYPE_GHOST)
moveTarget = MOVE_TARGET_USER;
else
moveTarget = MOVE_TARGET_SELECTED;
Expand Down
12 changes: 6 additions & 6 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3343,8 +3343,8 @@ void FaintClearSetData(void)

gBattleResources->flags->flags[gActiveBattler] = 0;

gBattleMons[gActiveBattler].type1 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[0];
gBattleMons[gActiveBattler].type2 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1];
gBattleMons[gActiveBattler].types[0] = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[0];
gBattleMons[gActiveBattler].types[1] = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1];

ClearBattlerMoveHistory(gActiveBattler);
ClearBattlerAbilityHistory(gActiveBattler);
Expand Down Expand Up @@ -3411,8 +3411,8 @@ static void BattleIntroDrawTrainersOrMonsSprites(void)
for (i = 0; i < sizeof(struct BattlePokemon); i++)
ptr[i] = gBattleBufferB[gActiveBattler][4 + i];

gBattleMons[gActiveBattler].type1 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[0];
gBattleMons[gActiveBattler].type2 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1];
gBattleMons[gActiveBattler].types[0] = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[0];
gBattleMons[gActiveBattler].types[1] = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1];
gBattleMons[gActiveBattler].ability = GetAbilityBySpecies(gBattleMons[gActiveBattler].species, gBattleMons[gActiveBattler].abilityNum);
hpOnSwitchout = &gBattleStruct->hpOnSwitchout[GetBattlerSide(gActiveBattler)];
*hpOnSwitchout = gBattleMons[gActiveBattler].hp;
Expand Down Expand Up @@ -4173,8 +4173,8 @@ static void HandleTurnActionSelectionState(void)
struct ChooseMoveStruct moveInfo;

moveInfo.species = gBattleMons[gActiveBattler].species;
moveInfo.monType1 = gBattleMons[gActiveBattler].type1;
moveInfo.monType2 = gBattleMons[gActiveBattler].type2;
moveInfo.monTypes[0] = gBattleMons[gActiveBattler].types[0];
moveInfo.monTypes[1] = gBattleMons[gActiveBattler].types[1];

for (i = 0; i < MAX_MON_MOVES; i++)
{
Expand Down
68 changes: 34 additions & 34 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,11 +1395,11 @@ static void Cmd_typecalc(void)
else if (TYPE_EFFECT_ATK_TYPE(i) == moveType)
{
// check type1
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type1)
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[0])
ModulateDmgByType(TYPE_EFFECT_MULTIPLIER(i));
// check type2
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type2 &&
gBattleMons[gBattlerTarget].type1 != gBattleMons[gBattlerTarget].type2)
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[1] &&
gBattleMons[gBattlerTarget].types[0] != gBattleMons[gBattlerTarget].types[1])
ModulateDmgByType(TYPE_EFFECT_MULTIPLIER(i));
}
i += 3;
Expand Down Expand Up @@ -1454,33 +1454,33 @@ static void CheckWonderGuardAndLevitate(void)
if (TYPE_EFFECT_ATK_TYPE(i) == moveType)
{
// check no effect
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type1
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[0]
&& TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NO_EFFECT)
{
gMoveResultFlags |= MOVE_RESULT_DOESNT_AFFECT_FOE;
gProtectStructs[gBattlerAttacker].targetNotAffected = 1;
}
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type2 &&
gBattleMons[gBattlerTarget].type1 != gBattleMons[gBattlerTarget].type2 &&
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[1] &&
gBattleMons[gBattlerTarget].types[0] != gBattleMons[gBattlerTarget].types[1] &&
TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NO_EFFECT)
{
gMoveResultFlags |= MOVE_RESULT_DOESNT_AFFECT_FOE;
gProtectStructs[gBattlerAttacker].targetNotAffected = 1;
}

// check super effective
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type1 && TYPE_EFFECT_MULTIPLIER(i) == 20)
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[0] && TYPE_EFFECT_MULTIPLIER(i) == 20)
flags |= 1;
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type2
&& gBattleMons[gBattlerTarget].type1 != gBattleMons[gBattlerTarget].type2
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[1]
&& gBattleMons[gBattlerTarget].types[0] != gBattleMons[gBattlerTarget].types[1]
&& TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE)
flags |= 1;

// check not very effective
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type1 && TYPE_EFFECT_MULTIPLIER(i) == 5)
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[0] && TYPE_EFFECT_MULTIPLIER(i) == 5)
flags |= 2;
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type2
&& gBattleMons[gBattlerTarget].type1 != gBattleMons[gBattlerTarget].type2
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[1]
&& gBattleMons[gBattlerTarget].types[0] != gBattleMons[gBattlerTarget].types[1]
&& TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NOT_EFFECTIVE)
flags |= 2;
}
Expand Down Expand Up @@ -1570,11 +1570,11 @@ u8 TypeCalc(u16 move, u8 attacker, u8 defender)
else if (TYPE_EFFECT_ATK_TYPE(i) == moveType)
{
// check type1
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[defender].type1)
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[defender].types[0])
ModulateDmgByType2(TYPE_EFFECT_MULTIPLIER(i), move, &flags);
// check type2
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[defender].type2 &&
gBattleMons[defender].type1 != gBattleMons[defender].type2)
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[defender].types[1] &&
gBattleMons[defender].types[0] != gBattleMons[defender].types[1])
ModulateDmgByType2(TYPE_EFFECT_MULTIPLIER(i), move, &flags);
}
i += 3;
Expand Down Expand Up @@ -3971,7 +3971,7 @@ static void Cmd_jumpiftype2(void)
{
u8 battlerId = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);

if (gBattlescriptCurrInstr[2] == gBattleMons[battlerId].type1 || gBattlescriptCurrInstr[2] == gBattleMons[battlerId].type2)
if (gBattlescriptCurrInstr[2] == gBattleMons[battlerId].types[0] || gBattlescriptCurrInstr[2] == gBattleMons[battlerId].types[1])
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3);
else
gBattlescriptCurrInstr += 7;
Expand Down Expand Up @@ -4520,7 +4520,7 @@ static void Cmd_typecalc2(void)
if (TYPE_EFFECT_ATK_TYPE(i) == moveType)
{
// check type1
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type1)
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[0])
{
if (TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NO_EFFECT)
{
Expand All @@ -4537,22 +4537,22 @@ static void Cmd_typecalc2(void)
}
}
// check type2
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type2)
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[1])
{
if (gBattleMons[gBattlerTarget].type1 != gBattleMons[gBattlerTarget].type2
if (gBattleMons[gBattlerTarget].types[0] != gBattleMons[gBattlerTarget].types[1]
&& TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NO_EFFECT)
{
gMoveResultFlags |= MOVE_RESULT_DOESNT_AFFECT_FOE;
break;
}
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type2
&& gBattleMons[gBattlerTarget].type1 != gBattleMons[gBattlerTarget].type2
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[1]
&& gBattleMons[gBattlerTarget].types[0] != gBattleMons[gBattlerTarget].types[1]
&& TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_NOT_EFFECTIVE)
{
flags |= MOVE_RESULT_NOT_VERY_EFFECTIVE;
}
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].type2
&& gBattleMons[gBattlerTarget].type1 != gBattleMons[gBattlerTarget].type2
if (TYPE_EFFECT_DEF_TYPE(i) == gBattleMons[gBattlerTarget].types[1]
&& gBattleMons[gBattlerTarget].types[0] != gBattleMons[gBattlerTarget].types[1]
&& TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE)
{
flags |= MOVE_RESULT_SUPER_EFFECTIVE;
Expand Down Expand Up @@ -4623,8 +4623,8 @@ static void Cmd_switchindataupdate(void)
for (i = 0; i < sizeof(struct BattlePokemon); i++)
monData[i] = gBattleBufferB[gActiveBattler][4 + i];

gBattleMons[gActiveBattler].type1 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[0];
gBattleMons[gActiveBattler].type2 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1];
gBattleMons[gActiveBattler].types[0] = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[0];
gBattleMons[gActiveBattler].types[1] = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1];
gBattleMons[gActiveBattler].ability = GetAbilityBySpecies(gBattleMons[gActiveBattler].species, gBattleMons[gActiveBattler].abilityNum);

// check knocked off item
Expand Down Expand Up @@ -7354,8 +7354,8 @@ static void Cmd_tryconversiontypechange(void)
else
moveType = TYPE_NORMAL;
}
if (moveType != gBattleMons[gBattlerAttacker].type1
&& moveType != gBattleMons[gBattlerAttacker].type2)
if (moveType != gBattleMons[gBattlerAttacker].types[0]
&& moveType != gBattleMons[gBattlerAttacker].types[1])
{
break;
}
Expand All @@ -7381,7 +7381,7 @@ static void Cmd_tryconversiontypechange(void)
moveType = TYPE_NORMAL;
}
}
while (moveType == gBattleMons[gBattlerAttacker].type1 || moveType == gBattleMons[gBattlerAttacker].type2);
while (moveType == gBattleMons[gBattlerAttacker].types[0] || moveType == gBattleMons[gBattlerAttacker].types[1]);

SET_BATTLER_TYPE(gBattlerAttacker, moveType);
PREPARE_TYPE_BUFFER(gBattleTextBuff1, moveType);
Expand Down Expand Up @@ -7548,12 +7548,12 @@ static void Cmd_weatherdamage(void)
{
if (gBattleWeather & B_WEATHER_SANDSTORM)
{
if (gBattleMons[gBattlerAttacker].type1 != TYPE_ROCK
&& gBattleMons[gBattlerAttacker].type1 != TYPE_STEEL
&& gBattleMons[gBattlerAttacker].type1 != TYPE_GROUND
&& gBattleMons[gBattlerAttacker].type2 != TYPE_ROCK
&& gBattleMons[gBattlerAttacker].type2 != TYPE_STEEL
&& gBattleMons[gBattlerAttacker].type2 != TYPE_GROUND
if (gBattleMons[gBattlerAttacker].types[0] != TYPE_ROCK
&& gBattleMons[gBattlerAttacker].types[0] != TYPE_STEEL
&& gBattleMons[gBattlerAttacker].types[0] != TYPE_GROUND
&& gBattleMons[gBattlerAttacker].types[1] != TYPE_ROCK
&& gBattleMons[gBattlerAttacker].types[1] != TYPE_STEEL
&& gBattleMons[gBattlerAttacker].types[1] != TYPE_GROUND
&& gBattleMons[gBattlerAttacker].ability != ABILITY_SAND_VEIL
&& !(gStatuses3[gBattlerAttacker] & STATUS3_UNDERGROUND)
&& !(gStatuses3[gBattlerAttacker] & STATUS3_UNDERWATER))
Expand Down
4 changes: 2 additions & 2 deletions src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -4670,8 +4670,8 @@ void CopyPlayerPartyMonToBattleData(u8 battlerId, u8 partyIndex)
gBattleMons[battlerId].isEgg = GetMonData(&gPlayerParty[partyIndex], MON_DATA_IS_EGG, NULL);
gBattleMons[battlerId].abilityNum = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ABILITY_NUM, NULL);
gBattleMons[battlerId].otId = GetMonData(&gPlayerParty[partyIndex], MON_DATA_OT_ID, NULL);
gBattleMons[battlerId].type1 = gSpeciesInfo[gBattleMons[battlerId].species].types[0];
gBattleMons[battlerId].type2 = gSpeciesInfo[gBattleMons[battlerId].species].types[1];
gBattleMons[battlerId].types[0] = gSpeciesInfo[gBattleMons[battlerId].species].types[0];
gBattleMons[battlerId].types[1] = gSpeciesInfo[gBattleMons[battlerId].species].types[1];
gBattleMons[battlerId].ability = GetAbilityBySpecies(gBattleMons[battlerId].species, gBattleMons[battlerId].abilityNum);
GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, nickname);
StringCopy_Nickname(gBattleMons[battlerId].nickname, nickname);
Expand Down