more work on battle setup

This commit is contained in:
DizzyEggg 2017-11-29 19:54:15 +01:00
parent 10470ef536
commit e8ecb01ab2
15 changed files with 332 additions and 540 deletions

View File

@ -9,405 +9,7 @@
thumb_func_start sub_80B100C
sub_80B100C: @ 80B100C
push {r4,r5,lr}
adds r5, r0, 0
ldr r0, =gEnemyParty
movs r1, 0x38
bl GetMonData
adds r4, r0, 0
lsls r4, 24
lsrs r4, 24
movs r0, 0x1
bl GetSumOfPlayerPartyLevel
lsls r0, 24
lsrs r0, 24
cmp r4, r0
bcs _080B1090
cmp r5, 0xA
beq _080B1048
cmp r5, 0xA
bgt _080B1040
cmp r5, 0x3
beq _080B105C
b _080B106C
.pool
_080B1040:
cmp r5, 0xD
bgt _080B106C
movs r0, 0x4
b _080B1120
_080B1048:
ldr r4, =gUnknown_0854FEA4
bl Random
lsls r0, 16
lsrs r0, 16
movs r1, 0x3
b _080B1114
.pool
_080B105C:
ldr r4, =gUnknown_0854FEA7
bl Random
ands r5, r0
lsls r0, r5, 16
b _080B111A
.pool
_080B106C:
ldr r0, =0x000040ce
bl VarGet
lsls r0, 16
lsrs r0, 16
cmp r0, 0x3
beq _080B10EC
ldr r4, =gUnknown_0854FE98
bl Random
lsls r0, 16
lsrs r0, 16
b _080B1112
.pool
_080B1090:
cmp r5, 0xA
beq _080B10A6
cmp r5, 0xA
bgt _080B109E
cmp r5, 0x3
beq _080B10B8
b _080B10C8
_080B109E:
cmp r5, 0xD
bgt _080B10C8
movs r0, 0x3
b _080B1120
_080B10A6:
ldr r4, =gUnknown_0854FEA4
bl Random
lsls r0, 16
lsrs r0, 16
movs r1, 0x3
b _080B1114
.pool
_080B10B8:
ldr r4, =gUnknown_0854FEA7
bl Random
ands r5, r0
lsls r0, r5, 16
b _080B111A
.pool
_080B10C8:
ldr r0, =0x000040ce
bl VarGet
lsls r0, 16
lsrs r0, 16
cmp r0, 0x3
beq _080B10EC
ldr r4, =gUnknown_0854FE98
bl Random
lsls r0, 16
lsrs r0, 16
b _080B1112
.pool
_080B10EC:
ldr r0, =gSaveBlock2Ptr
ldr r1, [r0]
ldr r2, =0x00000cb2
adds r0, r1, r2
ldrh r0, [r0]
lsls r2, r0, 2
ldr r3, =0x00000cb4
adds r1, r3
adds r2, r1, r2
lsls r0, 1
adds r0, 0x1
lsls r0, 1
adds r1, r0
ldrh r0, [r1]
ldrh r2, [r2]
adds r0, r2
lsls r0, 16
lsrs r0, 16
ldr r4, =gUnknown_0854FE98
_080B1112:
movs r1, 0xC
_080B1114:
bl __umodsi3
lsls r0, 16
_080B111A:
lsrs r0, 16
adds r0, r4
ldrb r0, [r0]
_080B1120:
pop {r4,r5}
pop {r1}
bx r1
.pool
thumb_func_end sub_80B100C
thumb_func_start sub_80B1138
sub_80B1138: @ 80B1138
push {lr}
ldr r0, =CB2_ChooseStarter
bl SetMainCallback2
ldr r1, =gMain
ldr r0, =sub_80B1158
str r0, [r1, 0x8]
pop {r0}
bx r0
.pool
thumb_func_end sub_80B1138
thumb_func_start sub_80B1158
sub_80B1158: @ 80B1158
push {lr}
sub sp, 0x8
ldr r0, =0x00004023
bl GetVarPointer
ldr r2, =gSpecialVar_Result
ldrh r1, [r2]
strh r1, [r0]
ldrh r0, [r2]
bl GetStarterPokemon
lsls r0, 16
lsrs r0, 16
movs r1, 0
str r1, [sp]
str r1, [sp, 0x4]
movs r1, 0x5
movs r2, 0
movs r3, 0
bl ScriptGiveMon
bl ResetTasks
bl PlayBattleBGM
ldr r0, =sub_80B11A8
bl SetMainCallback2
movs r0, 0
bl sub_8145F10
add sp, 0x8
pop {r0}
bx r0
.pool
thumb_func_end sub_80B1158
thumb_func_start sub_80B11A8
sub_80B11A8: @ 80B11A8
push {lr}
bl UpdatePaletteFade
bl RunTasks
bl IsBattleTransitionDone
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1
bne _080B11F0
ldr r1, =gBattleTypeFlags
movs r0, 0x10
str r0, [r1]
ldr r1, =gMain
ldr r0, =sub_80B1204
str r0, [r1, 0x8]
bl FreeAllWindowBuffers
ldr r0, =CB2_InitBattle
bl SetMainCallback2
bl prev_quest_postbuffer_cursor_backup_reset
bl ResetPoisonStepCounter
movs r0, 0x7
bl IncrementGameStat
movs r0, 0x8
bl IncrementGameStat
bl sub_80EECC8
bl sub_80B1218
_080B11F0:
pop {r0}
bx r0
.pool
thumb_func_end sub_80B11A8
thumb_func_start sub_80B1204
sub_80B1204: @ 80B1204
push {lr}
bl sav1_reset_battle_music_maybe
ldr r0, =c2_exit_to_overworld_1_continue_scripts_restart_music
bl SetMainCallback2
pop {r0}
bx r0
.pool
thumb_func_end sub_80B1204
thumb_func_start sub_80B1218
sub_80B1218: @ 80B1218
push {lr}
movs r0, 0x8
bl GetGameStat
movs r1, 0x3C
bl __umodsi3
cmp r0, 0
bne _080B122E
bl sub_81DA57C
_080B122E:
pop {r0}
bx r0
thumb_func_end sub_80B1218
thumb_func_start sub_80B1234
sub_80B1234: @ 80B1234
push {lr}
movs r0, 0x9
bl GetGameStat
movs r1, 0x14
bl __umodsi3
cmp r0, 0
bne _080B124A
bl sub_81DA57C
_080B124A:
pop {r0}
bx r0
thumb_func_end sub_80B1234
thumb_func_start TrainerBattleLoadArg32
@ u32 TrainerBattleLoadArg32(u8 *arg)
TrainerBattleLoadArg32: @ 80B1250
adds r2, r0, 0
ldrb r0, [r2]
ldrb r1, [r2, 0x1]
lsls r1, 8
orrs r0, r1
ldrb r1, [r2, 0x2]
lsls r1, 16
orrs r0, r1
ldrb r1, [r2, 0x3]
lsls r1, 24
orrs r0, r1
bx lr
thumb_func_end TrainerBattleLoadArg32
thumb_func_start TrainerBattleLoadArg16
@ u16 TrainerBattleLoadArg16(u8 *arg)
TrainerBattleLoadArg16: @ 80B1268
adds r1, r0, 0
ldrb r0, [r1]
ldrb r1, [r1, 0x1]
lsls r1, 8
orrs r0, r1
bx lr
thumb_func_end TrainerBattleLoadArg16
thumb_func_start TrainerBattleLoadArg8
@ u8 TrainerBattleLoadArg8(u8 *arg)
TrainerBattleLoadArg8: @ 80B1274
ldrb r0, [r0]
bx lr
thumb_func_end TrainerBattleLoadArg8
thumb_func_start trainerflag_opponent
trainerflag_opponent: @ 80B1278
ldr r1, =gTrainerBattleOpponent_A
movs r2, 0xA0
lsls r2, 3
adds r0, r2, 0
ldrh r1, [r1]
adds r0, r1
lsls r0, 16
lsrs r0, 16
bx lr
.pool
thumb_func_end trainerflag_opponent
thumb_func_start sub_80B1290
sub_80B1290: @ 80B1290
ldr r1, =gTrainerBattleOpponent_B
movs r2, 0xA0
lsls r2, 3
adds r0, r2, 0
ldrh r1, [r1]
adds r0, r1
lsls r0, 16
lsrs r0, 16
bx lr
.pool
thumb_func_end sub_80B1290
thumb_func_start IsPlayerDefeated
IsPlayerDefeated: @ 80B12A8
push {lr}
subs r0, 0x1
cmp r0, 0x6
bhi _080B12E0
lsls r0, 2
ldr r1, =_080B12C0
adds r0, r1
ldr r0, [r0]
mov pc, r0
.pool
.align 2, 0
_080B12C0:
.4byte _080B12E0
.4byte _080B12DC
.4byte _080B12DC
.4byte _080B12E0
.4byte _080B12E0
.4byte _080B12E0
.4byte _080B12E0
_080B12DC:
movs r0, 0x1
b _080B12E2
_080B12E0:
movs r0, 0
_080B12E2:
pop {r1}
bx r1
thumb_func_end IsPlayerDefeated
thumb_func_start ResetTrainerOpponentIds
ResetTrainerOpponentIds: @ 80B12E8
ldr r0, =gTrainerBattleOpponent_A
movs r1, 0
strh r1, [r0]
ldr r0, =gTrainerBattleOpponent_B
strh r1, [r0]
bx lr
.pool
thumb_func_end ResetTrainerOpponentIds
thumb_func_start InitTrainerBattleVariables
@ void InitTrainerBattleVariables()
InitTrainerBattleVariables: @ 80B12FC
push {lr}
ldr r0, =gUnknown_02038BC8
movs r1, 0
strh r1, [r0]
ldr r0, =gUnknown_02038BFC
ldrb r1, [r0]
cmp r1, 0
bne _080B132C
ldr r0, =gUnknown_02038BD4
str r1, [r0]
ldr r0, =gUnknown_02038BDC
str r1, [r0]
ldr r0, =gUnknown_02038BF0
b _080B1338
.pool
_080B132C:
ldr r0, =gUnknown_02038BD8
movs r1, 0
str r1, [r0]
ldr r0, =gUnknown_02038BE0
str r1, [r0]
ldr r0, =gUnknown_02038BF4
_080B1338:
str r1, [r0]
ldr r1, =gUnknown_02038BD0
movs r0, 0
strh r0, [r1]
ldr r0, =gUnknown_02038BE4
movs r1, 0
str r1, [r0]
ldr r0, =gUnknown_02038BE8
str r1, [r0]
ldr r0, =gUnknown_02038BEC
str r1, [r0]
pop {r0}
bx r0
.pool
thumb_func_end InitTrainerBattleVariables
thumb_func_start TrainerBattleLoadArgs
@ void TrainerBattleLoadArgs(struct TrainerBattleArgSpec *argSpecs, u8 *args)
@ -483,7 +85,7 @@ _080B13EC:
thumb_func_start battle_80801F0
battle_80801F0: @ 80B13F8
push {lr}
ldr r0, =gUnknown_02038BD0
ldr r0, =sTrainerMapObjectLocalId
ldrh r1, [r0]
cmp r1, 0
beq _080B141A
@ -510,7 +112,7 @@ BattleSetup_ConfigureTrainerBattle: @ 80B1430
push {r4,r5,lr}
adds r5, r0, 0
bl InitTrainerBattleVariables
ldr r4, =gUnknown_02038BC8
ldr r4, =sTrainerBattleMode
adds r0, r5, 0
bl TrainerBattleLoadArg8
lsls r0, 24
@ -554,7 +156,7 @@ _080B14A8:
b _080B14D6
.pool
_080B14B0:
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r0, [r0]
cmp r0, 0
bne _080B14C4
@ -603,7 +205,7 @@ _080B1514:
b _080B161E
.pool
_080B153C:
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r0, [r0]
cmp r0, 0
bne _080B156C
@ -643,7 +245,7 @@ _080B159A:
b _080B161E
.pool
_080B15A8:
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r0, [r0]
cmp r0, 0
bne _080B15D8
@ -667,7 +269,7 @@ _080B15D8:
b _080B157C
.pool
_080B15F4:
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r0, [r0]
cmp r0, 0
bne _080B1614
@ -802,7 +404,7 @@ sub_80B16D8: @ 80B16D8
thumb_func_start sub_80B170C
sub_80B170C: @ 80B170C
ldr r0, =gUnknown_02038BC8
ldr r0, =sTrainerBattleMode
ldrb r0, [r0]
bx lr
.pool
@ -825,7 +427,7 @@ _080B1734:
bl InTrainerHill
cmp r0, 0
bne _080B174A
bl trainerflag_opponent
bl GetTrainerAFlag
lsls r0, 16
lsrs r0, 16
bl FlagGet
@ -849,12 +451,12 @@ rom_npc_set_flag_for_script_id: @ 80B1760
ldrh r0, [r0]
cmp r0, 0
beq _080B1776
bl sub_80B1290
bl GetTrainerBFlag
lsls r0, 16
lsrs r0, 16
bl FlagSet
_080B1776:
bl trainerflag_opponent
bl GetTrainerAFlag
lsls r0, 16
lsrs r0, 16
bl FlagSet
@ -866,7 +468,7 @@ _080B1776:
thumb_func_start sub_80B178C
sub_80B178C: @ 80B178C
push {lr}
bl trainerflag_opponent
bl GetTrainerAFlag
lsls r0, 16
lsrs r0, 16
bl FlagSet
@ -1161,7 +763,7 @@ sub_80B1A14: @ 80B1A14
_080B1A44:
ldr r3, =gMapObjects
ldr r2, =gUnknown_03006090
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r1, [r0]
lsls r0, r1, 1
adds r0, r1
@ -1201,7 +803,7 @@ _080B1A7C:
_080B1AAC:
ldr r3, =gMapObjects
ldr r2, =gUnknown_03006090
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r1, [r0]
lsls r0, r1, 1
adds r0, r1
@ -1295,7 +897,7 @@ special_trainer_unable_to_battle: @ 80B1B60
@ void SetUpTrainerEncounterMusic()
SetUpTrainerEncounterMusic: @ 80B1B70
push {lr}
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r0, [r0]
cmp r0, 0
bne _080B1B88
@ -1306,7 +908,7 @@ _080B1B88:
ldr r0, =gTrainerBattleOpponent_B
_080B1B8A:
ldrh r1, [r0]
ldr r0, =gUnknown_02038BC8
ldr r0, =sTrainerBattleMode
ldrh r0, [r0]
cmp r0, 0x1
beq _080B1C62
@ -1418,15 +1020,15 @@ _080B1C74:
thumb_func_start sub_80B1C7C
sub_80B1C7C: @ 80B1C7C
push {lr}
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r0, [r0]
cmp r0, 0
beq _080B1C94
ldr r0, =gUnknown_02038BD8
ldr r0, =sTrainerBIntroSpeech
b _080B1C96
.pool
_080B1C94:
ldr r0, =gUnknown_02038BD4
ldr r0, =sTrainerAIntroSpeech
_080B1C96:
ldr r0, [r0]
bl ReturnEmptyStringIfNull
@ -1448,7 +1050,7 @@ GetTrainer1LoseText: @ 80B1CA4
b _080B1CC0
.pool
_080B1CBC:
ldr r0, =gUnknown_02038BDC
ldr r0, =sTrainerADefeatSpeech
ldr r0, [r0]
_080B1CC0:
ldr r4, =gStringVar4
@ -1467,7 +1069,7 @@ _080B1CC0:
GetTrainer2LoseText: @ 80B1CE0
push {r4,lr}
ldr r4, =gStringVar4
ldr r0, =gUnknown_02038BE0
ldr r0, =sTrainerBDefeatSpeech
ldr r0, [r0]
bl ReturnEmptyStringIfNull
adds r1, r0, 0
@ -1483,7 +1085,7 @@ GetTrainer2LoseText: @ 80B1CE0
thumb_func_start sub_80B1D04
sub_80B1D04: @ 80B1D04
push {lr}
ldr r0, =gUnknown_02038BE4
ldr r0, =sTrainerVictorySpeech
ldr r0, [r0]
bl ReturnEmptyStringIfNull
pop {r1}
@ -1494,7 +1096,7 @@ sub_80B1D04: @ 80B1D04
thumb_func_start sub_80B1D18
sub_80B1D18: @ 80B1D18
push {lr}
ldr r0, =gUnknown_02038BE8
ldr r0, =sTrainerCannotBattleSpeech
ldr r0, [r0]
bl ReturnEmptyStringIfNull
pop {r1}

View File

@ -3544,7 +3544,7 @@ _08163E2C:
ldr r5, =0x00000c03
adds r0, r5, 0
bl sub_8165404
ldr r4, =gUnknown_02038BFC
ldr r4, =gApproachingTrainerId
movs r0, 0
strb r0, [r4]
ldr r0, =MossdeepCity_SpaceCenter_2F_EventScript_224157 + 1

View File

@ -71,15 +71,15 @@ BattleTransition_StartOnField: @ 8145EF4
.pool
thumb_func_end BattleTransition_StartOnField
thumb_func_start sub_8145F10
sub_8145F10: @ 8145F10
thumb_func_start BattleTransition_Start
BattleTransition_Start: @ 8145F10
push {lr}
lsls r0, 24
lsrs r0, 24
bl LaunchBattleTransitionTask
pop {r0}
bx r0
thumb_func_end sub_8145F10
thumb_func_end BattleTransition_Start
thumb_func_start IsBattleTransitionDone
IsBattleTransitionDone: @ 8145F20

View File

@ -2004,7 +2004,7 @@ GetOnOffBike: @ 811A080
beq _0811A0B0
movs r0, 0x1
bl SetPlayerAvatarTransitionFlags
bl sav1_reset_battle_music_maybe
bl Overworld_ClearSavedMusic
bl sub_8085784
b _0811A0C4
.pool

View File

@ -6295,7 +6295,7 @@ sub_80B8D44: @ 80B8D44
ldr r0, =gFieldEffectArguments
ldr r0, [r0]
strh r0, [r1, 0x26]
bl sav1_reset_battle_music_maybe
bl Overworld_ClearSavedMusic
ldr r0, =0x0000016d
bl Overworld_ChangeMusicTo
movs r0, 0

View File

@ -3896,7 +3896,7 @@ sub_808C750: @ 808C750
lsls r4, 24
lsrs r4, 24
bl ScriptContext2_Enable
bl sav1_reset_battle_music_maybe
bl Overworld_ClearSavedMusic
bl Overworld_ChangeMusicToDefault
ldr r2, =gPlayerAvatar
ldrb r1, [r2]

View File

@ -1386,7 +1386,7 @@ _080850C8:
bl sub_80AEDBC
bl sub_8085B2C
bl update_sav1_flash_used_on_map
bl sav1_reset_battle_music_maybe
bl Overworld_ClearSavedMusic
bl mapheader_run_script_with_tag_x3
bl not_trainer_hill_battle_pyramid
ldr r0, [r4]
@ -1491,7 +1491,7 @@ _080851EE:
bl FlagClear
_08085200:
bl update_sav1_flash_used_on_map
bl sav1_reset_battle_music_maybe
bl Overworld_ClearSavedMusic
bl mapheader_run_script_with_tag_x3
bl UpdateLocationHistoryForRoamer
bl RoamerMoveToOtherLocationSet
@ -2272,15 +2272,15 @@ Overworld_SetSavedMusic: @ 80857F4
.pool
thumb_func_end Overworld_SetSavedMusic
thumb_func_start sav1_reset_battle_music_maybe
sav1_reset_battle_music_maybe: @ 8085800
thumb_func_start Overworld_ClearSavedMusic
Overworld_ClearSavedMusic: @ 8085800
ldr r0, =gSaveBlock1Ptr
ldr r1, [r0]
movs r0, 0
strh r0, [r1, 0x2C]
bx lr
.pool
thumb_func_end sav1_reset_battle_music_maybe
thumb_func_end Overworld_ClearSavedMusic
thumb_func_start sub_8085810
sub_8085810: @ 8085810

View File

@ -12,7 +12,7 @@ CheckForTrainersWantingBattle: @ 80B3BE8
ldr r0, =gUnknown_030060A8
movs r1, 0
strb r1, [r0]
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
strb r1, [r0]
movs r4, 0
ldr r6, =gMapObjects
@ -89,7 +89,7 @@ _080B3C88:
bcs _080B3CC6
ldr r6, =gUnknown_03006090
adds r7, r6, 0x4
ldr r5, =gUnknown_02038BFC
ldr r5, =gApproachingTrainerId
_080B3CA0:
lsls r1, r4, 1
adds r1, r4
@ -111,7 +111,7 @@ _080B3CA0:
bcc _080B3CA0
_080B3CC6:
bl TwoTrainersWantBattleExecuteScript
ldr r1, =gUnknown_02038BFC
ldr r1, =gApproachingTrainerId
movs r0, 0
strb r0, [r1]
ldr r1, =gUnknown_030060AC
@ -645,7 +645,7 @@ TrainerApproachPlayer: @ 80B406C
sub_80B40C8: @ 80B40C8
push {r4,r5,lr}
adds r2, r0, 0
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r0, [r0]
cmp r0, 0
bne _080B40E4
@ -1294,7 +1294,7 @@ sub_80B45D0: @ 80B45D0
ldrb r0, [r0]
cmp r0, 0x2
bne _080B4610
ldr r1, =gUnknown_02038BFC
ldr r1, =gApproachingTrainerId
ldrb r0, [r1]
cmp r0, 0
bne _080B460C
@ -1531,7 +1531,7 @@ _080B47B2:
thumb_func_start sub_80B47BC
sub_80B47BC: @ 80B47BC
push {lr}
ldr r0, =gUnknown_02038BFC
ldr r0, =gApproachingTrainerId
ldrb r0, [r0]
cmp r0, 0
beq _080B47D4

View File

@ -4,96 +4,88 @@
.section .rodata
.align 2, 0
gUnknown_0854FE98:: @ 854FE98
.byte 0x1d, 0x1e, 0x1f, 0x20, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29
gUnknown_0854FEA4:: @ 854FEA4
.byte 0x1f, 0x20, 0x21
gUnknown_0854FEA7:: @ 854FEA7
.byte 0x1d, 0x1f, 0x20, 0x21, 0x00
.align 2
gUnknown_0854FEAC:: @ 854FEAC
.4byte gUnknown_02038BC8, 0x00000000
.4byte sTrainerBattleMode, 0x00000000
.4byte gTrainerBattleOpponent_A, 0x00000001
.4byte gUnknown_02038BD0, 0x00000001
.4byte gUnknown_02038BD4, 0x00000002
.4byte gUnknown_02038BDC, 0x00000002
.4byte gUnknown_02038BE4, 0x00000005
.4byte gUnknown_02038BE8, 0x00000005
.4byte sTrainerMapObjectLocalId, 0x00000001
.4byte sTrainerAIntroSpeech, 0x00000002
.4byte sTrainerADefeatSpeech, 0x00000002
.4byte sTrainerVictorySpeech, 0x00000005
.4byte sTrainerCannotBattleSpeech, 0x00000005
.4byte gUnknown_02038BF0, 0x00000005
.4byte gUnknown_02038BEC, 0x00000006
.align 2
gUnknown_0854FEF4:: @ 854FEF4
.4byte gUnknown_02038BC8, 0x00000000
.4byte sTrainerBattleMode, 0x00000000
.4byte gTrainerBattleOpponent_A, 0x00000001
.4byte gUnknown_02038BD0, 0x00000001
.4byte gUnknown_02038BD4, 0x00000002
.4byte gUnknown_02038BDC, 0x00000002
.4byte gUnknown_02038BE4, 0x00000005
.4byte gUnknown_02038BE8, 0x00000005
.4byte sTrainerMapObjectLocalId, 0x00000001
.4byte sTrainerAIntroSpeech, 0x00000002
.4byte sTrainerADefeatSpeech, 0x00000002
.4byte sTrainerVictorySpeech, 0x00000005
.4byte sTrainerCannotBattleSpeech, 0x00000005
.4byte gUnknown_02038BF0, 0x00000002
.4byte gUnknown_02038BEC, 0x00000006
.align 2
gUnknown_0854FF3C:: @ 854FF3C
.4byte gUnknown_02038BC8, 0x00000000
.4byte sTrainerBattleMode, 0x00000000
.4byte gTrainerBattleOpponent_A, 0x00000001
.4byte gUnknown_02038BD0, 0x00000001
.4byte gUnknown_02038BD4, 0x00000002
.4byte gUnknown_02038BDC, 0x00000002
.4byte gUnknown_02038BE4, 0x00000005
.4byte gUnknown_02038BE8, 0x00000002
.4byte sTrainerMapObjectLocalId, 0x00000001
.4byte sTrainerAIntroSpeech, 0x00000002
.4byte sTrainerADefeatSpeech, 0x00000002
.4byte sTrainerVictorySpeech, 0x00000005
.4byte sTrainerCannotBattleSpeech, 0x00000002
.4byte gUnknown_02038BF0, 0x00000005
.4byte gUnknown_02038BEC, 0x00000006
.align 2
gUnknown_0854FF84:: @ 854FF84
.4byte gUnknown_02038BC8, 0x00000000
.4byte sTrainerBattleMode, 0x00000000
.4byte gTrainerBattleOpponent_A, 0x00000001
.4byte gUnknown_02038BD0, 0x00000001
.4byte gUnknown_02038BD4, 0x00000005
.4byte gUnknown_02038BDC, 0x00000002
.4byte gUnknown_02038BE4, 0x00000005
.4byte gUnknown_02038BE8, 0x00000005
.4byte sTrainerMapObjectLocalId, 0x00000001
.4byte sTrainerAIntroSpeech, 0x00000005
.4byte sTrainerADefeatSpeech, 0x00000002
.4byte sTrainerVictorySpeech, 0x00000005
.4byte sTrainerCannotBattleSpeech, 0x00000005
.4byte gUnknown_02038BF0, 0x00000005
.4byte gUnknown_02038BEC, 0x00000006
.align 2
gUnknown_0854FFCC:: @ 854FFCC
.4byte gUnknown_02038BC8, 0x00000000
.4byte sTrainerBattleMode, 0x00000000
.4byte gTrainerBattleOpponent_A, 0x00000001
.4byte gUnknown_02038BD0, 0x00000001
.4byte gUnknown_02038BD4, 0x00000002
.4byte gUnknown_02038BDC, 0x00000002
.4byte gUnknown_02038BE4, 0x00000005
.4byte gUnknown_02038BE8, 0x00000002
.4byte sTrainerMapObjectLocalId, 0x00000001
.4byte sTrainerAIntroSpeech, 0x00000002
.4byte sTrainerADefeatSpeech, 0x00000002
.4byte sTrainerVictorySpeech, 0x00000005
.4byte sTrainerCannotBattleSpeech, 0x00000002
.4byte gUnknown_02038BF0, 0x00000002
.4byte gUnknown_02038BEC, 0x00000006
.align 2
gUnknown_08550014:: @ 8550014
.4byte gUnknown_02038BC8, 0x00000000
.4byte sTrainerBattleMode, 0x00000000
.4byte gTrainerBattleOpponent_B, 0x00000001
.4byte gUnknown_02038BD0, 0x00000001
.4byte gUnknown_02038BD8, 0x00000002
.4byte gUnknown_02038BE0, 0x00000002
.4byte gUnknown_02038BE4, 0x00000005
.4byte gUnknown_02038BE8, 0x00000005
.4byte sTrainerMapObjectLocalId, 0x00000001
.4byte sTrainerBIntroSpeech, 0x00000002
.4byte sTrainerBDefeatSpeech, 0x00000002
.4byte sTrainerVictorySpeech, 0x00000005
.4byte sTrainerCannotBattleSpeech, 0x00000005
.4byte gUnknown_02038BF4, 0x00000005
.4byte gUnknown_02038BEC, 0x00000006
.align 2
gUnknown_0855005C:: @ 855005C
.4byte gUnknown_02038BC8, 0x00000000
.4byte sTrainerBattleMode, 0x00000000
.4byte gTrainerBattleOpponent_B, 0x00000001
.4byte gUnknown_02038BD0, 0x00000001
.4byte gUnknown_02038BD8, 0x00000002
.4byte gUnknown_02038BE0, 0x00000002
.4byte gUnknown_02038BE4, 0x00000005
.4byte gUnknown_02038BE8, 0x00000005
.4byte sTrainerMapObjectLocalId, 0x00000001
.4byte sTrainerBIntroSpeech, 0x00000002
.4byte sTrainerBDefeatSpeech, 0x00000002
.4byte sTrainerVictorySpeech, 0x00000005
.4byte sTrainerCannotBattleSpeech, 0x00000005
.4byte gUnknown_02038BF4, 0x00000002
.4byte gUnknown_02038BEC, 0x00000006

View File

@ -225,7 +225,7 @@ Route101_EventScript_1EBE16:: @ 81EBE16
setobjectxy 255, 6, 13
applymovement 255, Route101_Movement_2725A4
waitmovement 0
special sub_80B1138
special ChooseStarter
waitstate
applymovement 2, Route101_Movement_1EBE8D
waitmovement 0

View File

@ -166,7 +166,7 @@ gSpecials:: @ 81DBA64
def_special sub_8085784
def_special Special_StartWallClock
def_special Special_ViewWallClock
def_special sub_80B1138
def_special ChooseStarter
def_special StartWallyTutorialBattle
def_special ChangePokemonNickname
def_special sub_81B94B0

View File

@ -36,6 +36,24 @@ extern u8 gStringVar2[];
extern u8 gStringVar3[];
extern u8 gStringVar4[];
// There are many quirks in the source code which have overarching behavioral differences from
// a number of other files. For example, diploma.c seems to declare rodata before each use while
// other files declare out of order and must be at the beginning. There are also a number of
// macros which differ from one file to the next due to the method of obtaining the result, such
// as these below. Because of this, there is a theory (Two Team Theory) that states that these
// programming projects had more than 1 "programming team" which utilized different macros for
// each of the files that were worked on.
#define T1_READ_8(ptr) ((ptr)[0])
#define T1_READ_16(ptr) ((ptr)[0] | ((ptr)[1] << 8))
#define T1_READ_32(ptr) ((ptr)[0] | ((ptr)[1] << 8) | ((ptr)[2] << 16) | ((ptr)[3] << 24))
#define T1_READ_PTR(ptr) (u8*) T1_READ_32(ptr)
// T2_READ_8 is a duplicate to remain consistent with each group.
#define T2_READ_8(ptr) ((ptr)[0])
#define T2_READ_16(ptr) ((ptr)[0] + ((ptr)[1] << 8))
#define T2_READ_32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
#define T2_READ_PTR(ptr) (void*) T2_READ_32(ptr)
enum
{
VERSION_SAPPHIRE = 1,
@ -45,7 +63,8 @@ enum
VERSION_LEAF_GREEN = 5,
};
enum LanguageId {
enum LanguageId
{
LANGUAGE_JAPANESE = 1,
LANGUAGE_ENGLISH = 2,
LANGUAGE_GERMAN = 5,
@ -240,7 +259,7 @@ struct SaveBlock2
/*0xCA9*/ u8 field_CA9_f : 1; // 0x80
/*0xCAA*/ u16 field_CAA[4];
/*0xCB2*/ u16 battlePyramidWildHeaderId;
/*0xCB4*/ u8 field_CB4[82];
/*0xCB4*/ u16 field_CB4[82];
/*0xD06*/ u8 field_D06;
/*0xD07*/ u8 field_D07;
/*0xD08*/ u8 filler_D08[0x112];

View File

@ -21,7 +21,7 @@
#define VAR_RECYCLE_GOODS 0x4020
#define VAR_REPEL_STEP_COUNT 0x4021
#define VAR_ICE_STEP_COUNT 0x4022
#define VAR_FIRST_POKE 0x4023
#define VAR_STARTER_ID 0x4023
#define VAR_MIRAGE_RND_H 0x4024
#define VAR_MIRAGE_RND_L 0x4025
#define VAR_SECRET_BASE_MAP 0x4026
@ -58,6 +58,7 @@
#define VAR_0x40BC 0x40BC
#define VAR_0x40C2 0x40C2
#define VAR_0x40CE 0x40CE
#define VAR_FRONTIER_FACILITY 0x40CF
#define VAR_DAILY_SLOTS 0x40E6

View File

@ -17,6 +17,12 @@
#include "fieldmap.h"
#include "trainer_classes.h"
#include "trainer_ids.h"
#include "rng.h"
#include "starter_choose.h"
#include "script_pokemon_80F8.h"
#include "items.h"
#include "palette.h"
#include "window.h"
extern bool8 InBattlePyramid(void);
extern bool8 InBattlePike(void);
@ -30,16 +36,18 @@ extern void sub_808BCF4(void);
extern void sub_80EECC8(void);
extern void c2_exit_to_overworld_1_continue_scripts_restart_music(void);
extern void c2_exit_to_overworld_2_switch(void);
extern void Overworld_ClearSavedMusic(void);
extern void CB2_WhiteOut(void);
extern void sub_80AF6F0(void);
extern void PlayBattleBGM(void);
extern void sub_81DA57C(void);
extern u8 GetSav1Weather(void);
extern u8 Overworld_GetFlashLevel(void);
extern u32 gBattleTypeFlags;
extern u8 gBattleOutcome;
extern void (*gFieldCallback)(void);
extern u16 gTrainerBattleOpponent_A;
extern u16 gTrainerBattleOpponent_B;
extern u8 gApproachingTrainerId;
// this file's functions
void DoBattlePikeWildBattle(void);
@ -49,10 +57,29 @@ void CB2_EndWildBattle(void);
void CB2_EndScriptedWildBattle(void);
u8 GetWildBattleTransition(void);
u8 GetTrainerBattleTransition(void);
u8 sub_80B100C(u8 arg0);
u8 sub_80B100C(s32 arg0);
void sub_80B1218(void);
void sub_80B1234(void);
bool32 IsPlayerDefeated(u8 battleOutcome);
void CB2_GiveStarter(void);
void CB2_StartFirstBattle(void);
void CB2_EndFirstBattle(void);
bool32 IsPlayerDefeated(u32 battleOutcome);
// ewram data
EWRAM_DATA u16 sTrainerBattleMode = 0;
EWRAM_DATA u16 gTrainerBattleOpponent_A = 0;
EWRAM_DATA u16 gTrainerBattleOpponent_B = 0;
EWRAM_DATA u16 gPartnerTrainerId = 0;
EWRAM_DATA u16 sTrainerMapObjectLocalId = 0;
EWRAM_DATA u8 *sTrainerAIntroSpeech = NULL;
EWRAM_DATA u8 *sTrainerBIntroSpeech = NULL;
EWRAM_DATA u8 *sTrainerADefeatSpeech = NULL;
EWRAM_DATA u8 *sTrainerBDefeatSpeech = NULL;
EWRAM_DATA u8 *sTrainerVictorySpeech = NULL;
EWRAM_DATA u8 *sTrainerCannotBattleSpeech = NULL;
EWRAM_DATA u8 *gUnknown_02038BEC = NULL;
EWRAM_DATA u8 *gUnknown_02038BF0 = NULL;
EWRAM_DATA u8 *gUnknown_02038BF4 = NULL;
// const rom data
@ -74,6 +101,21 @@ static const u8 sBattleTransitionTable_Trainer[][2] =
{B_TRANSITION_SWIRL, B_TRANSITION_RIPPLE}, // Water
};
static const u8 sUnknown_0854FE98[] =
{
0x1d, 0x1e, 0x1f, 0x20, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29
};
static const u8 sUnknown_0854FEA4[] =
{
0x1f, 0x20, 0x21
};
static const u8 sUnknown_0854FEA7[] =
{
0x1d, 0x1f, 0x20, 0x21
};
#define tState data[0]
#define tTransition data[1]
@ -579,8 +621,184 @@ u8 GetTrainerBattleTransition(void)
transitionType = GetBattleTransitionTypeByMap();
enemyLevel = GetSumOfEnemyPartyLevel(gTrainerBattleOpponent_A, minPartyCount);
playerLevel = GetSumOfPlayerPartyLevel(minPartyCount);
if (enemyLevel < playerLevel) // is wild mon level than the player's mon level?
if (enemyLevel < playerLevel)
return sBattleTransitionTable_Trainer[transitionType][0];
else
return sBattleTransitionTable_Trainer[transitionType][1];
}
u8 sub_80B100C(s32 arg0)
{
u16 var;
u8 enemyLevel = GetMonData(&gEnemyParty[0], MON_DATA_LEVEL);
u8 playerLevel = GetSumOfPlayerPartyLevel(1);
if (enemyLevel < playerLevel)
{
switch (arg0)
{
case 11:
case 12:
case 13:
return B_TRANSITION_POKEBALLS_TRAIL;
case 10:
return sUnknown_0854FEA4[Random() % ARRAY_COUNT(sUnknown_0854FEA4)];
case 3:
return sUnknown_0854FEA7[Random() % ARRAY_COUNT(sUnknown_0854FEA7)];
}
if (VarGet(VAR_0x40CE) != 3)
return sUnknown_0854FE98[Random() % ARRAY_COUNT(sUnknown_0854FE98)];
}
else
{
switch (arg0)
{
case 11:
case 12:
case 13:
return B_TRANSITION_BIG_POKEBALL;
case 10:
return sUnknown_0854FEA4[Random() % ARRAY_COUNT(sUnknown_0854FEA4)];
case 3:
return sUnknown_0854FEA7[Random() % ARRAY_COUNT(sUnknown_0854FEA7)];
}
if (VarGet(VAR_0x40CE) != 3)
return sUnknown_0854FE98[Random() % ARRAY_COUNT(sUnknown_0854FE98)];
}
var = gSaveBlock2Ptr->field_CB4[gSaveBlock2Ptr->battlePyramidWildHeaderId * 2 + 0]
+ gSaveBlock2Ptr->field_CB4[gSaveBlock2Ptr->battlePyramidWildHeaderId * 2 + 1];
return sUnknown_0854FE98[var % ARRAY_COUNT(sUnknown_0854FE98)];
}
void ChooseStarter(void)
{
SetMainCallback2(CB2_ChooseStarter);
gMain.savedCallback = CB2_GiveStarter;
}
void CB2_GiveStarter(void)
{
u16 starterMon;
*GetVarPointer(VAR_STARTER_ID) = gSpecialVar_Result;
starterMon = GetStarterPokemon(gSpecialVar_Result);
ScriptGiveMon(starterMon, 5, 0, 0, 0, 0);
ResetTasks();
PlayBattleBGM();
SetMainCallback2(CB2_StartFirstBattle);
BattleTransition_Start(B_TRANSITION_BLUR);
}
void CB2_StartFirstBattle(void)
{
UpdatePaletteFade();
RunTasks();
if (IsBattleTransitionDone() == TRUE)
{
gBattleTypeFlags = BATTLE_TYPE_FIRST_BATTLE;
gMain.savedCallback = CB2_EndFirstBattle;
FreeAllWindowBuffers();
SetMainCallback2(CB2_InitBattle);
prev_quest_postbuffer_cursor_backup_reset();
ResetPoisonStepCounter();
IncrementGameStat(GAME_STAT_TOTAL_BATTLES);
IncrementGameStat(GAME_STAT_WILD_BATTLES);
sub_80EECC8();
sub_80B1218();
}
}
void CB2_EndFirstBattle(void)
{
Overworld_ClearSavedMusic();
SetMainCallback2(c2_exit_to_overworld_1_continue_scripts_restart_music);
}
void sub_80B1218(void)
{
if (GetGameStat(GAME_STAT_WILD_BATTLES) % 60 == 0)
sub_81DA57C();
}
void sub_80B1234(void)
{
if (GetGameStat(GAME_STAT_TRAINER_BATTLES) % 20 == 0)
sub_81DA57C();
}
// why not just use the macros? maybe its because they didnt want to uncast const every time?
u32 TrainerBattleLoadArg32(const u8 *ptr)
{
return T1_READ_32(ptr);
}
u16 TrainerBattleLoadArg16(const u8 *ptr)
{
return T1_READ_16(ptr);
}
u8 TrainerBattleLoadArg8(const u8 *ptr)
{
return T1_READ_8(ptr);
}
u16 GetTrainerAFlag(void)
{
return FLAG_TRAINER_FLAG_START + gTrainerBattleOpponent_A;
}
u16 GetTrainerBFlag(void)
{
return FLAG_TRAINER_FLAG_START + gTrainerBattleOpponent_B;
}
bool32 IsPlayerDefeated(u32 battleOutcome)
{
switch (battleOutcome)
{
case BATTLE_LOST:
case BATTLE_DREW:
return TRUE;
case BATTLE_WON:
case BATTLE_RAN:
case BATTLE_PLAYER_TELEPORTED:
case BATTLE_POKE_FLED:
case BATTLE_CAUGHT:
return FALSE;
default:
return FALSE;
}
}
void ResetTrainerOpponentIds(void)
{
gTrainerBattleOpponent_A = 0;
gTrainerBattleOpponent_B = 0;
}
void InitTrainerBattleVariables(void)
{
sTrainerBattleMode = 0;
if (gApproachingTrainerId == 0)
{
sTrainerAIntroSpeech = NULL;
sTrainerADefeatSpeech = NULL;
gUnknown_02038BF0 = NULL;
}
else
{
sTrainerBIntroSpeech = NULL;
sTrainerBDefeatSpeech = NULL;
gUnknown_02038BF4 = NULL;
}
sTrainerMapObjectLocalId = 0;
sTrainerVictorySpeech = NULL;
sTrainerCannotBattleSpeech = NULL;
gUnknown_02038BEC = NULL;
}

View File

@ -706,47 +706,7 @@ gUnknown_02038BC4: @ 2038BC4
gUnknown_02038BC6: @ 2038BC6
.space 0x2
gUnknown_02038BC8: @ 2038BC8
.space 0x2
gTrainerBattleOpponent_A: @ 2038BCA
.space 0x2
gTrainerBattleOpponent_B: @ 2038BCC
.space 0x2
gPartnerTrainerId: @ 2038BCE
.space 0x2
gUnknown_02038BD0: @ 2038BD0
.space 0x4
gUnknown_02038BD4: @ 2038BD4
.space 0x4
gUnknown_02038BD8: @ 2038BD8
.space 0x4
gUnknown_02038BDC: @ 2038BDC
.space 0x4
gUnknown_02038BE0: @ 2038BE0
.space 0x4
gUnknown_02038BE4: @ 2038BE4
.space 0x4
gUnknown_02038BE8: @ 2038BE8
.space 0x4
gUnknown_02038BEC: @ 2038BEC
.space 0x4
gUnknown_02038BF0: @ 2038BF0
.space 0x4
gUnknown_02038BF4: @ 2038BF4
.space 0x4
.include "src/battle_setup.o"
gUnknown_02038BF8: @ 2038BF8
.space 0x1
@ -754,7 +714,7 @@ gUnknown_02038BF8: @ 2038BF8
gUnknown_02038BF9: @ 2038BF9
.space 0x3
gUnknown_02038BFC: @ 2038BFC
gApproachingTrainerId: @ 2038BFC
.space 0x4
.include "src/wild_encounter.o"