Skip to content

Commit

Permalink
Merge pull request #260 from cbt6/battle_bg_terrain
Browse files Browse the repository at this point in the history
Document battle background and terrain
  • Loading branch information
red031000 authored Oct 23, 2023
2 parents 3a18972 + 726696a commit a39cb88
Show file tree
Hide file tree
Showing 9 changed files with 649 additions and 616 deletions.
4 changes: 2 additions & 2 deletions include/battle/battle_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ struct BattleSetup { //declared in trainer_data.h
struct BattleSetupSub_138 unk138;
GAME_STATS* gameStats; // 144
SavePalPad* palPad; // 148
u32 battleBg; // 14C
u32 terrain;
BattleBg battleBg; // 14C
Terrain terrain;
u32 mapSection; // 154
u32 mapNumber; // 158
TIMEOFDAY timeOfDay; // 15C
Expand Down
66 changes: 48 additions & 18 deletions include/constants/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,64 @@ enum BattleSide {
B_SIDE_18
};

typedef enum BattleBg {
BATTLE_BG_GENERAL,
BATTLE_BG_OCEAN,
BATTLE_BG_CITY,
BATTLE_BG_FOREST,
BATTLE_BG_MOUNTAIN,
BATTLE_BG_SNOW,
BATTLE_BG_BUILDING_1,
BATTLE_BG_BUILDING_2,
BATTLE_BG_BUILDING_3,
BATTLE_BG_CAVE_1,
BATTLE_BG_CAVE_2,
BATTLE_BG_CAVE_3,
BATTLE_BG_WILL,
BATTLE_BG_KOGA,
BATTLE_BG_BRUNO,
BATTLE_BG_KAREN,
BATTLE_BG_LANCE,
BATTLE_BG_DISTORTION_WORLD,
BATTLE_BG_BATTLE_TOWER,
BATTLE_BG_BATTLE_FACTORY,
BATTLE_BG_BATTLE_ARCADE,
BATTLE_BG_BATTLE_CASTLE,
BATTLE_BG_BATTLE_HALL,
} BattleBg;

typedef enum Terrain {
TERRAIN_PLAIN,
TERRAIN_SAND,
TERRAIN_GRASS,
TERRAIN_PUDDLE,
TERRAIN_ROCKS,
TERRAIN_CAVE, //5
TERRAIN_MOUNTAIN,
TERRAIN_CAVE,
TERRAIN_SNOW,
TERRAIN_WATER,
TERRAIN_ICE,
TERRAIN_BUILDING,
TERRAIN_MARSH, //10
TERRAIN_BRIDGE,
TERRAIN_LINK,
TERRAIN_END,
//Special terrains
TERRAIN_ELITE_4_WILL,
TERRAIN_ELITE_4_KOGA, //15
TERRAIN_ELITE_4_BRUNO,
TERRAIN_ELITE_4_KAREN,
TERRAIN_CHAMPION_LANCE,
TERRAIN_17,
TERRAIN_TOWER, //20
TERRAIN_ARCADE,
TERRAIN_CASTLE,
TERRAIN_22,
TERRAIN_MAX
TERRAIN_GREAT_MARSH, // unused
TERRAIN_UNKNOWN, // unused
TERRAIN_WILL,
TERRAIN_KOGA,
TERRAIN_BRUNO,
TERRAIN_KAREN,
TERRAIN_LANCE,
TERRAIN_DISTORTION_WORLD, // unused
TERRAIN_BATTLE_TOWER,
TERRAIN_BATTLE_FACTORY,
TERRAIN_BATTLE_ARCADE,
TERRAIN_BATTLE_CASTLE,
TERRAIN_BATTLE_HALL,
TERRAIN_GIRATINA, // unused
TERRAIN_MAX
} Terrain;

// This is a catch-all terrain that includes Pokemon League, Distortion World
// and Battle Frontier.
#define TERRAIN_OTHERS (TERRAIN_WILL)

#endif //PM_ASM

// Battle outcome
Expand Down
4 changes: 3 additions & 1 deletion include/map_header.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef POKEHEARTGOLD_MAP_HEADER_H
#define POKEHEARTGOLD_MAP_HEADER_H

#include "constants/battle.h"

#define MAP_FOLLOWMODE_PREVENT 0
#define MAP_FOLLOWMODE_HEIGHT_RESTRICT 1
#define MAP_FOLLOWMODE_ALLOW 2
Expand Down Expand Up @@ -53,7 +55,7 @@ u8 MapHeader_GetMomCallIntroParam(u32 map_no);
BOOL MapHeader_IsKanto(u32 map_no);
u32 MapHeader_GetWeatherType(u32 map_no);
u32 MapHeader_GetCameraType(u32 map_no);
u32 MapHeader_GetBattleBg(u32 map_no);
BattleBg MapHeader_GetBattleBg(u32 map_no);
BOOL MapHeader_IsEscapeRopeAllowed(u32 map_no);
BOOL MapHeader_IsFlyAllowed(u32 map_no);
BOOL MapHeader_IsBikeAllowed(u32 map_no);
Expand Down
4 changes: 2 additions & 2 deletions src/battle/battle_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -4857,8 +4857,8 @@ BOOL BtlCmd_TryCamouflage(BattleSystem *bsys, BattleContext *ctx) {
}

Terrain terrain = BattleSystem_GetTerrainId(bsys);
if (terrain > TERRAIN_END - 1) {
terrain = (Terrain) (TERRAIN_END - 1);
if (terrain > TERRAIN_OTHERS) {
terrain = TERRAIN_OTHERS;
}
int type = sCamouflageTypeTable[terrain];

Expand Down
70 changes: 35 additions & 35 deletions src/battle/battle_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void BattleSetup_SetParty(BattleSetup* setup, Party* party, int battlerId
static void BattleSetup_SetProfile(BattleSetup* setup, PlayerProfile* profile, int battlerId);
static void BattleSetup_SetChatotVoiceClip(BattleSetup* setup, SOUND_CHATOT* chatot, int battlerId);
static void sub_0205230C(FieldSystem* fieldSystem, PlayerProfile* profile1, PlayerProfile* profile2);
static u32 sub_02052470(FieldSystem* fieldSystem, u32 battleBg);
static Terrain sub_02052470(FieldSystem* fieldSystem, BattleBg battleBg);
static void sub_02052504(BattleSetup* setup, FieldSystem* fieldSystem);

BattleSetup* BattleSetup_New(HeapID heapId, u32 battleTypeFlags) {
Expand All @@ -38,7 +38,7 @@ BattleSetup* BattleSetup_New(HeapID heapId, u32 battleTypeFlags) {
setup->battleType = battleTypeFlags;
setup->battleSpecial = 0;
setup->winFlag = 0;
setup->battleBg = 0;
setup->battleBg = BATTLE_BG_GENERAL;
setup->terrain = TERRAIN_MAX;
setup->mapSection = 0;
setup->timeOfDay = RTC_TIMEOFDAY_MORN;
Expand Down Expand Up @@ -199,7 +199,7 @@ void sub_02051D18(BattleSetup* setup, FieldSystem* fieldSystem, SaveData* saveDa
Options* options;
LocalFieldData* local;
BOOL forceNite;
u32 battle_bg;
BattleBg battle_bg;

profile = Save_PlayerData_GetProfileAddr(saveData);
party = SaveArray_Party_Get(saveData);
Expand All @@ -212,7 +212,7 @@ void sub_02051D18(BattleSetup* setup, FieldSystem* fieldSystem, SaveData* saveDa
if (fieldSystem != NULL) {
forceNite = FALSE;
battle_bg = MapHeader_GetBattleBg(fieldSystem->location->mapId);
if (battle_bg == 9 || battle_bg == 10 || battle_bg == 11) {
if (battle_bg == BATTLE_BG_CAVE_1 || battle_bg == BATTLE_BG_CAVE_2 || battle_bg == BATTLE_BG_CAVE_3) {
forceNite = TRUE;
}
sub_02052504(setup, fieldSystem);
Expand Down Expand Up @@ -279,7 +279,7 @@ void BattleSetup_InitForFixedLevelFacility(BattleSetup* setup, FieldSystem *fiel
chatot = Save_Chatot_Get(fieldSystem->saveData);
options = Save_PlayerData_GetOptionsAddr(fieldSystem->saveData);

setup->battleBg = 6;
setup->battleBg = BATTLE_BG_BUILDING_1;
setup->terrain = TERRAIN_BUILDING;
BattleSetup_SetProfile(setup, profile, BATTLER_PLAYER);

Expand Down Expand Up @@ -327,7 +327,7 @@ void sub_020520B0(BattleSetup* setup, FieldSystem *fieldSystem, Party *party, u8
options = Save_PlayerData_GetOptionsAddr(fieldSystem->saveData);
fieldSystem_unkA4 = fieldSystem->unkA4;

setup->battleBg = 6;
setup->battleBg = BATTLE_BG_BUILDING_1;
setup->terrain = TERRAIN_BUILDING;
BattleSetup_SetProfile(setup, profile, BATTLER_PLAYER);

Expand Down Expand Up @@ -465,33 +465,33 @@ void sub_02052444(BattleSetup* setup, FieldSystem* fieldSystem) {
Pokedex_Copy(setup->pokedex, pokedex);
}

static const u32 _020FC4C0[] = {
TERRAIN_PLAIN,
TERRAIN_WATER,
TERRAIN_BUILDING,
TERRAIN_GRASS,
TERRAIN_ROCKS,
TERRAIN_SNOW,
TERRAIN_BUILDING,
TERRAIN_BUILDING,
TERRAIN_BUILDING,
TERRAIN_CAVE,
TERRAIN_CAVE,
TERRAIN_CAVE,
TERRAIN_LINK,
TERRAIN_END,
TERRAIN_ELITE_4_WILL,
TERRAIN_ELITE_4_KOGA,
TERRAIN_ELITE_4_BRUNO,
TERRAIN_ELITE_4_KAREN,
TERRAIN_CHAMPION_LANCE,
TERRAIN_17,
TERRAIN_TOWER,
TERRAIN_ARCADE,
TERRAIN_CASTLE,
static const Terrain _020FC4C0[] = {
[BATTLE_BG_GENERAL] = TERRAIN_PLAIN,
[BATTLE_BG_OCEAN] = TERRAIN_WATER,
[BATTLE_BG_CITY] = TERRAIN_BUILDING,
[BATTLE_BG_FOREST] = TERRAIN_GRASS,
[BATTLE_BG_MOUNTAIN] = TERRAIN_MOUNTAIN,
[BATTLE_BG_SNOW] = TERRAIN_SNOW,
[BATTLE_BG_BUILDING_1] = TERRAIN_BUILDING,
[BATTLE_BG_BUILDING_2] = TERRAIN_BUILDING,
[BATTLE_BG_BUILDING_3] = TERRAIN_BUILDING,
[BATTLE_BG_CAVE_1] = TERRAIN_CAVE,
[BATTLE_BG_CAVE_2] = TERRAIN_CAVE,
[BATTLE_BG_CAVE_3] = TERRAIN_CAVE,
[BATTLE_BG_WILL] = TERRAIN_WILL,
[BATTLE_BG_KOGA] = TERRAIN_KOGA,
[BATTLE_BG_BRUNO] = TERRAIN_BRUNO,
[BATTLE_BG_KAREN] = TERRAIN_KAREN,
[BATTLE_BG_LANCE] = TERRAIN_LANCE,
[BATTLE_BG_DISTORTION_WORLD] = TERRAIN_DISTORTION_WORLD,
[BATTLE_BG_BATTLE_TOWER] = TERRAIN_BATTLE_TOWER,
[BATTLE_BG_BATTLE_FACTORY] = TERRAIN_BATTLE_FACTORY,
[BATTLE_BG_BATTLE_ARCADE] = TERRAIN_BATTLE_ARCADE,
[BATTLE_BG_BATTLE_CASTLE] = TERRAIN_BATTLE_CASTLE,
[BATTLE_BG_BATTLE_HALL] = TERRAIN_BATTLE_HALL,
};

static u32 sub_02052470(FieldSystem* fieldSystem, u32 battleBg) {
static Terrain sub_02052470(FieldSystem* fieldSystem, BattleBg battleBg) {
u8 behavior = GetMetatileBehaviorAt(fieldSystem, fieldSystem->location->x, fieldSystem->location->y);

if (sub_0205B828(behavior)) {
Expand All @@ -507,7 +507,7 @@ static u32 sub_02052470(FieldSystem* fieldSystem, u32 battleBg) {
return TERRAIN_SNOW;
}
if (sub_0205B8AC(behavior)) {
return TERRAIN_MARSH;
return TERRAIN_GREAT_MARSH;
}
if (sub_0205B8D0(behavior)) {
return TERRAIN_CAVE;
Expand All @@ -519,16 +519,16 @@ static u32 sub_02052470(FieldSystem* fieldSystem, u32 battleBg) {
return _020FC4C0[battleBg];
}

GF_ASSERT(0);
return NELEMS(_020FC4C0) + 1;
GF_ASSERT(FALSE);
return TERRAIN_MAX;
}

static void sub_02052504(BattleSetup* setup, FieldSystem* fieldSystem) {
PlayerSaveData* player = LocalFieldData_GetPlayer(Save_LocalFieldData_Get(fieldSystem->saveData));
setup->battleBg = MapHeader_GetBattleBg(fieldSystem->location->mapId);

if (player->unk4 == 2) {
setup->battleBg = 1;
setup->battleBg = BATTLE_BG_OCEAN;
}

setup->terrain = sub_02052470(fieldSystem, setup->battleBg);
Expand Down
30 changes: 15 additions & 15 deletions src/battle/battle_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,30 +769,30 @@ void BattleSystem_TryChangeForm(BattleSystem *bsys) {
case TERRAIN_SNOW:
case TERRAIN_WATER:
case TERRAIN_ICE:
case TERRAIN_MARSH:
case TERRAIN_GREAT_MARSH:
default:
form = BURMY_PLANT;
break;
case TERRAIN_PLAIN:
case TERRAIN_SAND:
case TERRAIN_CAVE:
case TERRAIN_ROCKS:
case TERRAIN_ELITE_4_KAREN:
case TERRAIN_22:
case TERRAIN_MOUNTAIN:
case TERRAIN_DISTORTION_WORLD:
case TERRAIN_GIRATINA:
form = BURMY_SANDY;
break;
case TERRAIN_BUILDING:
case TERRAIN_BRIDGE:
case TERRAIN_LINK:
case TERRAIN_END:
case TERRAIN_ELITE_4_WILL:
case TERRAIN_ELITE_4_KOGA:
case TERRAIN_ELITE_4_BRUNO:
case TERRAIN_CHAMPION_LANCE:
case TERRAIN_17:
case TERRAIN_TOWER:
case TERRAIN_ARCADE:
case TERRAIN_CASTLE:
case TERRAIN_UNKNOWN:
case TERRAIN_WILL:
case TERRAIN_KOGA:
case TERRAIN_BRUNO:
case TERRAIN_KAREN:
case TERRAIN_LANCE:
case TERRAIN_BATTLE_TOWER:
case TERRAIN_BATTLE_FACTORY:
case TERRAIN_BATTLE_ARCADE:
case TERRAIN_BATTLE_CASTLE:
case TERRAIN_BATTLE_HALL:
form = BURMY_TRASH;
break;
}
Expand Down
Loading

0 comments on commit a39cb88

Please sign in to comment.