mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2025-01-13 15:13:42 +01:00
Merge branch 'master' into decompile_reshow_battle_screen
This commit is contained in:
commit
b229a1c295
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,5 +23,6 @@ tools/*
|
|||||||
*.dump
|
*.dump
|
||||||
*.sa*
|
*.sa*
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
build/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.ddump
|
*.ddump
|
||||||
|
104
Makefile
104
Makefile
@ -1,5 +1,19 @@
|
|||||||
SHELL := /bin/bash -o pipefail
|
SHELL := /bin/bash -o pipefail
|
||||||
|
|
||||||
|
ROM := pokeemerald.gba
|
||||||
|
OBJ_DIR := build/emerald
|
||||||
|
|
||||||
|
ELF = $(ROM:.gba=.elf)
|
||||||
|
MAP = $(ROM:.gba=.map)
|
||||||
|
|
||||||
|
C_SUBDIR = src
|
||||||
|
ASM_SUBDIR = asm
|
||||||
|
DATA_ASM_SUBDIR = data
|
||||||
|
|
||||||
|
C_BUILDDIR = $(OBJ_DIR)/$(C_SUBDIR)
|
||||||
|
ASM_BUILDDIR = $(OBJ_DIR)/$(ASM_SUBDIR)
|
||||||
|
DATA_ASM_BUILDDIR = $(OBJ_DIR)/$(DATA_ASM_SUBDIR)
|
||||||
|
|
||||||
AS := $(DEVKITARM)/bin/arm-none-eabi-as
|
AS := $(DEVKITARM)/bin/arm-none-eabi-as
|
||||||
ASFLAGS := -mcpu=arm7tdmi
|
ASFLAGS := -mcpu=arm7tdmi
|
||||||
|
|
||||||
@ -10,7 +24,7 @@ CPP := $(DEVKITARM)/bin/arm-none-eabi-cpp
|
|||||||
CPPFLAGS := -I tools/agbcc/include -iquote include -nostdinc -undef
|
CPPFLAGS := -I tools/agbcc/include -iquote include -nostdinc -undef
|
||||||
|
|
||||||
LD := $(DEVKITARM)/bin/arm-none-eabi-ld
|
LD := $(DEVKITARM)/bin/arm-none-eabi-ld
|
||||||
LDFLAGS := -T ld_script.ld -Map pokeemerald.map
|
LDFLAGS = -Map $(MAP)
|
||||||
|
|
||||||
OBJCOPY := $(DEVKITARM)/bin/arm-none-eabi-objcopy
|
OBJCOPY := $(DEVKITARM)/bin/arm-none-eabi-objcopy
|
||||||
|
|
||||||
@ -20,7 +34,7 @@ SHA1 := sha1sum -c
|
|||||||
|
|
||||||
GFX := tools/gbagfx/gbagfx
|
GFX := tools/gbagfx/gbagfx
|
||||||
AIF := tools/aif2pcm/aif2pcm
|
AIF := tools/aif2pcm/aif2pcm
|
||||||
MID := tools/mid2agb/mid2agb
|
MID := $(abspath tools/mid2agb/mid2agb)
|
||||||
SCANINC := tools/scaninc/scaninc
|
SCANINC := tools/scaninc/scaninc
|
||||||
PREPROC := tools/preproc/preproc
|
PREPROC := tools/preproc/preproc
|
||||||
RAMSCRGEN := tools/ramscrgen/ramscrgen
|
RAMSCRGEN := tools/ramscrgen/ramscrgen
|
||||||
@ -35,19 +49,19 @@ RAMSCRGEN := tools/ramscrgen/ramscrgen
|
|||||||
|
|
||||||
.PHONY: rom clean compare tidy
|
.PHONY: rom clean compare tidy
|
||||||
|
|
||||||
C_SRCS := $(wildcard src/*.c)
|
$(shell mkdir -p $(C_BUILDDIR) $(ASM_BUILDDIR) $(DATA_ASM_BUILDDIR))
|
||||||
C_OBJS := $(C_SRCS:%.c=%.o)
|
|
||||||
|
|
||||||
ASM_SRCS := $(wildcard asm/*.s)
|
C_SRCS := $(wildcard $(C_SUBDIR)/*.c)
|
||||||
ASM_OBJS := $(ASM_SRCS:%.s=%.o)
|
C_OBJS := $(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o,$(C_SRCS))
|
||||||
|
|
||||||
DATA_ASM_SRCS := $(wildcard data/*.s)
|
ASM_SRCS := $(wildcard $(ASM_SUBDIR)/*.s)
|
||||||
DATA_ASM_OBJS := $(DATA_ASM_SRCS:%.s=%.o)
|
ASM_OBJS := $(patsubst $(ASM_SUBDIR)/%.s,$(ASM_BUILDDIR)/%.o,$(ASM_SRCS))
|
||||||
|
|
||||||
|
DATA_ASM_SRCS := $(wildcard $(DATA_ASM_SUBDIR)/*.s)
|
||||||
|
DATA_ASM_OBJS := $(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o,$(DATA_ASM_SRCS))
|
||||||
|
|
||||||
OBJS := $(C_OBJS) $(ASM_OBJS) $(DATA_ASM_OBJS)
|
OBJS := $(C_OBJS) $(ASM_OBJS) $(DATA_ASM_OBJS)
|
||||||
|
OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS))
|
||||||
ROM := pokeemerald.gba
|
|
||||||
ELF := $(ROM:.gba=.elf)
|
|
||||||
|
|
||||||
rom: $(ROM)
|
rom: $(ROM)
|
||||||
|
|
||||||
@ -59,8 +73,8 @@ clean: tidy
|
|||||||
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
|
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
|
||||||
|
|
||||||
tidy:
|
tidy:
|
||||||
rm -f ld_script.ld sym_bss.ld sym_common.ld sym_ewram.ld
|
rm -f $(ROM) $(ELF) $(MAP)
|
||||||
rm -f $(ROM) $(ELF) $(OBJS) $(C_SRCS:%.c=%.i) pokeemerald.map
|
rm -r build/*
|
||||||
|
|
||||||
include graphics_file_rules.mk
|
include graphics_file_rules.mk
|
||||||
|
|
||||||
@ -75,56 +89,62 @@ include graphics_file_rules.mk
|
|||||||
%.lz: % ; $(GFX) $< $@
|
%.lz: % ; $(GFX) $< $@
|
||||||
%.rl: % ; $(GFX) $< $@
|
%.rl: % ; $(GFX) $< $@
|
||||||
|
|
||||||
src/libc.o: CC1 := tools/agbcc/bin/old_agbcc
|
$(C_BUILDDIR)/libc.o: CC1 := tools/agbcc/bin/old_agbcc
|
||||||
src/libc.o: CFLAGS := -O2
|
$(C_BUILDDIR)/libc.o: CFLAGS := -O2
|
||||||
|
|
||||||
src/siirtc.o: CFLAGS := -mthumb-interwork
|
$(C_BUILDDIR)/siirtc.o: CFLAGS := -mthumb-interwork
|
||||||
|
|
||||||
src/agb_flash.o: CFLAGS := -O -mthumb-interwork
|
$(C_BUILDDIR)/agb_flash.o: CFLAGS := -O -mthumb-interwork
|
||||||
src/agb_flash_1m.o: CFLAGS := -O -mthumb-interwork
|
$(C_BUILDDIR)/agb_flash_1m.o: CFLAGS := -O -mthumb-interwork
|
||||||
src/agb_flash_mx.o: CFLAGS := -O -mthumb-interwork
|
$(C_BUILDDIR)/agb_flash_mx.o: CFLAGS := -O -mthumb-interwork
|
||||||
|
|
||||||
src/m4a_2.o: CC1 := tools/agbcc/bin/old_agbcc
|
$(C_BUILDDIR)/m4a_2.o: CC1 := tools/agbcc/bin/old_agbcc
|
||||||
src/m4a_4.o: CC1 := tools/agbcc/bin/old_agbcc
|
$(C_BUILDDIR)/m4a_4.o: CC1 := tools/agbcc/bin/old_agbcc
|
||||||
|
|
||||||
ifeq ($(NODEP),)
|
ifeq ($(NODEP),)
|
||||||
%.o: c_dep = $(shell $(SCANINC) $*.c)
|
$(C_BUILDDIR)/%.o: c_dep = $(shell $(SCANINC) $(C_SUBDIR)/$*.c)
|
||||||
else
|
else
|
||||||
%.o: c_dep :=
|
$(C_BUILDDIR)/%.o: c_dep :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(C_OBJS): %.o : %.c $$(c_dep)
|
$(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c $$(c_dep)
|
||||||
@$(CPP) $(CPPFLAGS) $< -o $*.i
|
@$(CPP) $(CPPFLAGS) $< -o $(C_BUILDDIR)/$*.i
|
||||||
@$(PREPROC) $*.i charmap.txt | $(CC1) $(CFLAGS) -o $*.s
|
@$(PREPROC) $(C_BUILDDIR)/$*.i charmap.txt | $(CC1) $(CFLAGS) -o $(C_BUILDDIR)/$*.s
|
||||||
@echo -e ".text\n\t.align\t2, 0\n" >> $*.s
|
@echo -e ".text\n\t.align\t2, 0\n" >> $(C_BUILDDIR)/$*.s
|
||||||
$(AS) $(ASFLAGS) -o $@ $*.s
|
$(AS) $(ASFLAGS) -o $@ $(C_BUILDDIR)/$*.s
|
||||||
|
|
||||||
ifeq ($(NODEP),)
|
ifeq ($(NODEP),)
|
||||||
%.o: asm_dep = $(shell $(SCANINC) $*.s)
|
$(ASM_BUILDDIR)/%.o: asm_dep = $(shell $(SCANINC) $(ASM_SUBDIR)/$*.s)
|
||||||
else
|
else
|
||||||
%.o: asm_dep :=
|
$(ASM_BUILDDIR)/%.o: asm_dep :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(ASM_OBJS): %.o: %.s $$(asm_dep)
|
$(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s $$(asm_dep)
|
||||||
$(AS) $(ASFLAGS) -o $@ $<
|
$(AS) $(ASFLAGS) -o $@ $<
|
||||||
|
|
||||||
$(DATA_ASM_OBJS): %.o: %.s $$(asm_dep)
|
ifeq ($(NODEP),)
|
||||||
|
$(DATA_ASM_BUILDDIR)/%.o: data_dep = $(shell $(SCANINC) $(DATA_ASM_SUBDIR)/$*.s)
|
||||||
|
else
|
||||||
|
$(DATA_ASM_BUILDDIR)/%.o: data_dep :=
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s $$(data_dep)
|
||||||
$(PREPROC) $< charmap.txt | $(AS) $(ASFLAGS) -o $@
|
$(PREPROC) $< charmap.txt | $(AS) $(ASFLAGS) -o $@
|
||||||
|
|
||||||
sym_bss.ld: sym_bss.txt
|
$(OBJ_DIR)/sym_bss.ld: sym_bss.txt
|
||||||
$(RAMSCRGEN) .bss sym_bss.txt ENGLISH >$@
|
$(RAMSCRGEN) .bss $< ENGLISH > $@
|
||||||
|
|
||||||
sym_common.ld: sym_common.txt $(C_OBJS) $(wildcard common_syms/*.txt)
|
$(OBJ_DIR)/sym_common.ld: sym_common.txt $(C_OBJS) $(wildcard common_syms/*.txt)
|
||||||
$(RAMSCRGEN) COMMON sym_common.txt ENGLISH -c src,common_syms >$@
|
$(RAMSCRGEN) COMMON $< ENGLISH -c $(C_BUILDDIR),common_syms > $@
|
||||||
|
|
||||||
sym_ewram.ld: sym_ewram.txt
|
$(OBJ_DIR)/sym_ewram.ld: sym_ewram.txt
|
||||||
$(RAMSCRGEN) ewram_data sym_ewram.txt ENGLISH >$@
|
$(RAMSCRGEN) ewram_data $< ENGLISH > $@
|
||||||
|
|
||||||
ld_script.ld: ld_script.txt sym_bss.ld sym_common.ld sym_ewram.ld
|
$(OBJ_DIR)/ld_script.ld: ld_script.txt $(OBJ_DIR)/sym_bss.ld $(OBJ_DIR)/sym_common.ld $(OBJ_DIR)/sym_ewram.ld
|
||||||
sed -f ld_script.sed ld_script.txt >ld_script.ld
|
cd $(OBJ_DIR) && sed -f ../../ld_script.sed ../../$< | sed "s#tools/#../../tools/#g" | sed "s#sound/#../../sound/#g" > ld_script.ld
|
||||||
|
|
||||||
$(ELF): ld_script.ld $(OBJS)
|
$(ELF): $(OBJ_DIR)/ld_script.ld $(OBJS)
|
||||||
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBGCC)
|
cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ $(OBJS_REL) ../../$(LIBGCC)
|
||||||
|
|
||||||
$(ROM): $(ELF)
|
$(ROM): $(ELF)
|
||||||
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0x9000000 $< $@
|
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0x9000000 $< $@
|
||||||
|
2847
asm/battle_9.s
2847
asm/battle_9.s
File diff suppressed because it is too large
Load Diff
@ -5212,7 +5212,7 @@ sub_8061F90: @ 8061F90
|
|||||||
thumb_func_start sub_8061F9C
|
thumb_func_start sub_8061F9C
|
||||||
sub_8061F9C: @ 8061F9C
|
sub_8061F9C: @ 8061F9C
|
||||||
push {lr}
|
push {lr}
|
||||||
bl sub_8063880
|
bl AI_TrySwitchOrUseItem
|
||||||
bl OpponentBufferExecCompleted
|
bl OpponentBufferExecCompleted
|
||||||
pop {r0}
|
pop {r0}
|
||||||
bx r0
|
bx r0
|
||||||
@ -5243,7 +5243,7 @@ sub_8061FB8: @ 8061FB8
|
|||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
_08061FD6:
|
_08061FD6:
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
_08061FDA:
|
_08061FDA:
|
||||||
bl OpponentBufferExecCompleted
|
bl OpponentBufferExecCompleted
|
||||||
b _08062156
|
b _08062156
|
||||||
@ -5347,7 +5347,7 @@ _0806209C:
|
|||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
adds r2, r4, 0
|
adds r2, r4, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
b _08061FDA
|
b _08061FDA
|
||||||
.pool
|
.pool
|
||||||
_080620C4:
|
_080620C4:
|
||||||
@ -5378,7 +5378,7 @@ _080620C6:
|
|||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
adds r2, r4, 0
|
adds r2, r4, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
b _08062152
|
b _08062152
|
||||||
.pool
|
.pool
|
||||||
_08062108:
|
_08062108:
|
||||||
@ -5401,7 +5401,7 @@ _08062108:
|
|||||||
orrs r2, r4
|
orrs r2, r4
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
b _08062152
|
b _08062152
|
||||||
.pool
|
.pool
|
||||||
_0806213C:
|
_0806213C:
|
||||||
@ -5413,7 +5413,7 @@ _0806213C:
|
|||||||
orrs r2, r4
|
orrs r2, r4
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
_08062152:
|
_08062152:
|
||||||
bl OpponentBufferExecCompleted
|
bl OpponentBufferExecCompleted
|
||||||
_08062156:
|
_08062156:
|
||||||
@ -5456,7 +5456,7 @@ sub_8062188: @ 8062188
|
|||||||
ldrb r0, [r1]
|
ldrb r0, [r1]
|
||||||
cmp r0, 0x6
|
cmp r0, 0x6
|
||||||
bne _08062254
|
bne _08062254
|
||||||
bl sub_8063A90
|
bl GetMostSuitableMonToSwitchInto
|
||||||
lsls r0, 24
|
lsls r0, 24
|
||||||
lsrs r4, r0, 24
|
lsrs r4, r0, 24
|
||||||
cmp r4, 0x6
|
cmp r4, 0x6
|
||||||
|
@ -226,7 +226,7 @@ _0805764C:
|
|||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0x3
|
movs r1, 0x3
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
b _080577C2
|
b _080577C2
|
||||||
_08057658:
|
_08057658:
|
||||||
movs r0, 0x20
|
movs r0, 0x20
|
||||||
@ -393,7 +393,7 @@ _080577B2:
|
|||||||
movs r1, 0xC
|
movs r1, 0xC
|
||||||
_080577BC:
|
_080577BC:
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
_080577C2:
|
_080577C2:
|
||||||
bl PlayerBufferExecCompleted
|
bl PlayerBufferExecCompleted
|
||||||
b _080577E8
|
b _080577E8
|
||||||
@ -518,7 +518,7 @@ _080578A0:
|
|||||||
orrs r2, r0
|
orrs r2, r0
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
ldrb r0, [r4]
|
ldrb r0, [r4]
|
||||||
movs r1, 0x1
|
movs r1, 0x1
|
||||||
bl dp11b_obj_free
|
bl dp11b_obj_free
|
||||||
@ -1086,7 +1086,7 @@ _08057E14:
|
|||||||
_08057E1C:
|
_08057E1C:
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl PlayerBufferExecCompleted
|
bl PlayerBufferExecCompleted
|
||||||
b _08057F9E
|
b _08057F9E
|
||||||
.pool
|
.pool
|
||||||
@ -3413,7 +3413,7 @@ _080591FE:
|
|||||||
lsrs r2, 16
|
lsrs r2, 16
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xB
|
movs r1, 0xB
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
strb r5, [r4]
|
strb r5, [r4]
|
||||||
bl IsDoubleBattle
|
bl IsDoubleBattle
|
||||||
lsls r0, 24
|
lsls r0, 24
|
||||||
@ -3686,7 +3686,7 @@ _08059430:
|
|||||||
lsrs r2, 16
|
lsrs r2, 16
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xB
|
movs r1, 0xB
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
strb r5, [r4]
|
strb r5, [r4]
|
||||||
ldr r0, =sub_8059544
|
ldr r0, =sub_8059544
|
||||||
str r0, [r6]
|
str r0, [r6]
|
||||||
@ -4291,14 +4291,14 @@ _08059A2C:
|
|||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xE
|
movs r1, 0xE
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
b _08059A76
|
b _08059A76
|
||||||
.pool
|
.pool
|
||||||
_08059A6C:
|
_08059A6C:
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xD
|
movs r1, 0xD
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
_08059A76:
|
_08059A76:
|
||||||
bl PlayerBufferExecCompleted
|
bl PlayerBufferExecCompleted
|
||||||
_08059A7A:
|
_08059A7A:
|
||||||
@ -8658,7 +8658,7 @@ sub_805C158: @ 805C158
|
|||||||
lsrs r2, 16
|
lsrs r2, 16
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl PlayerBufferExecCompleted
|
bl PlayerBufferExecCompleted
|
||||||
_0805C194:
|
_0805C194:
|
||||||
pop {r0}
|
pop {r0}
|
||||||
@ -9378,7 +9378,7 @@ sub_805C80C: @ 805C80C
|
|||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0
|
movs r1, 0
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl PlayerBufferExecCompleted
|
bl PlayerBufferExecCompleted
|
||||||
pop {r0}
|
pop {r0}
|
||||||
bx r0
|
bx r0
|
||||||
|
@ -645,7 +645,7 @@ _081BB2E2:
|
|||||||
lsrs r2, 16
|
lsrs r2, 16
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xB
|
movs r1, 0xB
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
strb r5, [r4]
|
strb r5, [r4]
|
||||||
bl IsDoubleBattle
|
bl IsDoubleBattle
|
||||||
lsls r0, 24
|
lsls r0, 24
|
||||||
@ -918,7 +918,7 @@ _081BB514:
|
|||||||
lsrs r2, 16
|
lsrs r2, 16
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xB
|
movs r1, 0xB
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
strb r5, [r4]
|
strb r5, [r4]
|
||||||
ldr r0, =sub_81BB628
|
ldr r0, =sub_81BB628
|
||||||
str r0, [r6]
|
str r0, [r6]
|
||||||
@ -4990,7 +4990,7 @@ sub_81BDAA0: @ 81BDAA0
|
|||||||
thumb_func_start sub_81BDAAC
|
thumb_func_start sub_81BDAAC
|
||||||
sub_81BDAAC: @ 81BDAAC
|
sub_81BDAAC: @ 81BDAAC
|
||||||
push {lr}
|
push {lr}
|
||||||
bl sub_8063880
|
bl AI_TrySwitchOrUseItem
|
||||||
bl PlayerPartnerBufferExecCompleted
|
bl PlayerPartnerBufferExecCompleted
|
||||||
pop {r0}
|
pop {r0}
|
||||||
bx r0
|
bx r0
|
||||||
@ -5068,7 +5068,7 @@ _081BDB3C:
|
|||||||
orrs r2, r5
|
orrs r2, r5
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl PlayerPartnerBufferExecCompleted
|
bl PlayerPartnerBufferExecCompleted
|
||||||
pop {r4-r6}
|
pop {r4-r6}
|
||||||
pop {r0}
|
pop {r0}
|
||||||
@ -5087,7 +5087,7 @@ sub_81BDB70: @ 81BDB70
|
|||||||
thumb_func_start sub_81BDB7C
|
thumb_func_start sub_81BDB7C
|
||||||
sub_81BDB7C: @ 81BDB7C
|
sub_81BDB7C: @ 81BDB7C
|
||||||
push {r4-r6,lr}
|
push {r4-r6,lr}
|
||||||
bl sub_8063A90
|
bl GetMostSuitableMonToSwitchInto
|
||||||
lsls r0, 24
|
lsls r0, 24
|
||||||
lsrs r4, r0, 24
|
lsrs r4, r0, 24
|
||||||
cmp r4, 0x6
|
cmp r4, 0x6
|
||||||
|
@ -4754,7 +4754,7 @@ sub_8188EF0: @ 8188EF0
|
|||||||
lsrs r1, 24
|
lsrs r1, 24
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl RecordedOpponentBufferExecCompleted
|
bl RecordedOpponentBufferExecCompleted
|
||||||
pop {r0}
|
pop {r0}
|
||||||
bx r0
|
bx r0
|
||||||
@ -4785,7 +4785,7 @@ sub_8188F20: @ 8188F20
|
|||||||
lsrs r2, 16
|
lsrs r2, 16
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
b _08188F6C
|
b _08188F6C
|
||||||
.pool
|
.pool
|
||||||
_08188F48:
|
_08188F48:
|
||||||
@ -4803,7 +4803,7 @@ _08188F48:
|
|||||||
orrs r2, r4
|
orrs r2, r4
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
_08188F6C:
|
_08188F6C:
|
||||||
bl RecordedOpponentBufferExecCompleted
|
bl RecordedOpponentBufferExecCompleted
|
||||||
pop {r4,r5}
|
pop {r4,r5}
|
||||||
|
@ -4861,7 +4861,7 @@ sub_818C49C: @ 818C49C
|
|||||||
lsrs r1, 24
|
lsrs r1, 24
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl RecordedPlayerBufferExecCompleted
|
bl RecordedPlayerBufferExecCompleted
|
||||||
_0818C4C6:
|
_0818C4C6:
|
||||||
pop {r0}
|
pop {r0}
|
||||||
@ -4897,7 +4897,7 @@ _0818C508:
|
|||||||
lsrs r1, 24
|
lsrs r1, 24
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl RecordedPlayerBufferExecCompleted
|
bl RecordedPlayerBufferExecCompleted
|
||||||
_0818C522:
|
_0818C522:
|
||||||
pop {r0}
|
pop {r0}
|
||||||
@ -4929,7 +4929,7 @@ sub_818C538: @ 818C538
|
|||||||
lsrs r2, 16
|
lsrs r2, 16
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
b _0818C584
|
b _0818C584
|
||||||
.pool
|
.pool
|
||||||
_0818C560:
|
_0818C560:
|
||||||
@ -4947,7 +4947,7 @@ _0818C560:
|
|||||||
orrs r2, r4
|
orrs r2, r4
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
_0818C584:
|
_0818C584:
|
||||||
bl RecordedPlayerBufferExecCompleted
|
bl RecordedPlayerBufferExecCompleted
|
||||||
pop {r4,r5}
|
pop {r4,r5}
|
||||||
|
@ -103,13 +103,13 @@ _0815942A:
|
|||||||
movs r1, 0x7
|
movs r1, 0x7
|
||||||
_0815942E:
|
_0815942E:
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
b _08159440
|
b _08159440
|
||||||
_08159436:
|
_08159436:
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0x8
|
movs r1, 0x8
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
_08159440:
|
_08159440:
|
||||||
bl SafariBufferExecCompleted
|
bl SafariBufferExecCompleted
|
||||||
b _0815954E
|
b _0815954E
|
||||||
|
@ -153,7 +153,7 @@ _081684CE:
|
|||||||
movs r1, 0x9
|
movs r1, 0x9
|
||||||
_081684E4:
|
_081684E4:
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl WallyBufferExecCompleted
|
bl WallyBufferExecCompleted
|
||||||
ldr r1, [r4]
|
ldr r1, [r4]
|
||||||
adds r1, 0x94
|
adds r1, 0x94
|
||||||
@ -208,7 +208,7 @@ _08168540:
|
|||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0x1
|
movs r1, 0x1
|
||||||
movs r2, 0
|
movs r2, 0
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl WallyBufferExecCompleted
|
bl WallyBufferExecCompleted
|
||||||
_08168564:
|
_08168564:
|
||||||
pop {r4,r5}
|
pop {r4,r5}
|
||||||
@ -3777,7 +3777,7 @@ _0816A550:
|
|||||||
lsls r2, 1
|
lsls r2, 1
|
||||||
movs r0, 0x1
|
movs r0, 0x1
|
||||||
movs r1, 0xA
|
movs r1, 0xA
|
||||||
bl dp01_build_cmdbuf_x21_a_bb
|
bl EmitCmd_x21
|
||||||
bl WallyBufferExecCompleted
|
bl WallyBufferExecCompleted
|
||||||
_0816A574:
|
_0816A574:
|
||||||
pop {r4}
|
pop {r4}
|
||||||
|
@ -3259,8 +3259,8 @@ _0803413E:
|
|||||||
.pool
|
.pool
|
||||||
thumb_func_end sub_8034110
|
thumb_func_end sub_8034110
|
||||||
|
|
||||||
thumb_func_start dp01_build_cmdbuf_x21_a_bb
|
thumb_func_start EmitCmd_x21
|
||||||
dp01_build_cmdbuf_x21_a_bb: @ 8034158
|
EmitCmd_x21: @ 8034158
|
||||||
push {r4,lr}
|
push {r4,lr}
|
||||||
adds r4, r1, 0
|
adds r4, r1, 0
|
||||||
lsls r0, 24
|
lsls r0, 24
|
||||||
@ -3280,7 +3280,7 @@ dp01_build_cmdbuf_x21_a_bb: @ 8034158
|
|||||||
pop {r0}
|
pop {r0}
|
||||||
bx r0
|
bx r0
|
||||||
.pool
|
.pool
|
||||||
thumb_func_end dp01_build_cmdbuf_x21_a_bb
|
thumb_func_end EmitCmd_x21
|
||||||
|
|
||||||
thumb_func_start dp01_build_cmdbuf_x22_a_three_bytes
|
thumb_func_start dp01_build_cmdbuf_x22_a_three_bytes
|
||||||
dp01_build_cmdbuf_x22_a_three_bytes: @ 8034184
|
dp01_build_cmdbuf_x22_a_three_bytes: @ 8034184
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "battle_util.h"
|
#include "battle_util.h"
|
||||||
#include "battle_script_commands.h"
|
#include "battle_script_commands.h"
|
||||||
#include "battle_2.h"
|
#include "battle_2.h"
|
||||||
|
#include "battle_ai_switch_items.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Banks are a name given to what could be called a 'battlerId' or 'monControllerId'.
|
Banks are a name given to what could be called a 'battlerId' or 'monControllerId'.
|
||||||
@ -476,7 +477,7 @@ struct BattleHistory
|
|||||||
struct UsedMoves usedMoves[BATTLE_BANKS_COUNT];
|
struct UsedMoves usedMoves[BATTLE_BANKS_COUNT];
|
||||||
u8 abilities[BATTLE_BANKS_COUNT];
|
u8 abilities[BATTLE_BANKS_COUNT];
|
||||||
u8 itemEffects[BATTLE_BANKS_COUNT];
|
u8 itemEffects[BATTLE_BANKS_COUNT];
|
||||||
u16 TrainerItems[BATTLE_BANKS_COUNT];
|
u16 trainerItems[BATTLE_BANKS_COUNT];
|
||||||
u8 itemsNo;
|
u8 itemsNo;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -632,8 +633,8 @@ struct BattleStruct
|
|||||||
void (*savedCallback)(void);
|
void (*savedCallback)(void);
|
||||||
u16 usedHeldItems[BATTLE_BANKS_COUNT];
|
u16 usedHeldItems[BATTLE_BANKS_COUNT];
|
||||||
u8 field_C0[4];
|
u8 field_C0[4];
|
||||||
u8 field_C4[2];
|
u8 AI_itemType[2];
|
||||||
u8 field_C6[2];
|
u8 AI_itemFlags[2];
|
||||||
u16 choicedMove[BATTLE_BANKS_COUNT];
|
u16 choicedMove[BATTLE_BANKS_COUNT];
|
||||||
u16 changedItems[BATTLE_BANKS_COUNT];
|
u16 changedItems[BATTLE_BANKS_COUNT];
|
||||||
u8 intimidateBank;
|
u8 intimidateBank;
|
||||||
|
17
include/battle_ai_switch_items.h
Normal file
17
include/battle_ai_switch_items.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef GUARD_BATTLE_AI_SWITCH_ITEMS_H
|
||||||
|
#define GUARD_BATTLE_AI_SWITCH_ITEMS_H
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
AI_ITEM_FULL_RESTORE = 1,
|
||||||
|
AI_ITEM_HEAL_HP,
|
||||||
|
AI_ITEM_CURE_CONDITION,
|
||||||
|
AI_ITEM_X_STAT,
|
||||||
|
AI_ITEM_GUARD_SPECS,
|
||||||
|
AI_ITEM_NOT_RECOGNIZABLE
|
||||||
|
};
|
||||||
|
|
||||||
|
void AI_TrySwitchOrUseItem(void);
|
||||||
|
u8 GetMostSuitableMonToSwitchInto(void);
|
||||||
|
|
||||||
|
#endif // GUARD_BATTLE_AI_SWITCH_ITEMS_H
|
@ -86,5 +86,6 @@ void Emit_x32(u8 bufferId);
|
|||||||
void EmitPrintString(u8 bufferId, u16 stringId);
|
void EmitPrintString(u8 bufferId, u16 stringId);
|
||||||
void EmitResetActionMoveSelection(u8 bufferId, u8 caseId);
|
void EmitResetActionMoveSelection(u8 bufferId, u8 caseId);
|
||||||
void EmitBallThrow(u8 bufferId, u8 caseId);
|
void EmitBallThrow(u8 bufferId, u8 caseId);
|
||||||
|
void EmitCmd_x21(u8 bufferId, u8 arg1, u16 arg2);
|
||||||
|
|
||||||
#endif // GUARD_BATTLE_CONTROLLERS_H
|
#endif // GUARD_BATTLE_CONTROLLERS_H
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
void AI_CalcDmg(u8 bankAtk, u8 bankDef);
|
void AI_CalcDmg(u8 bankAtk, u8 bankDef);
|
||||||
u8 TypeCalc(u16 move, u8 bankAtk, u8 bankDef);
|
u8 TypeCalc(u16 move, u8 bankAtk, u8 bankDef);
|
||||||
u8 AI_TypeCalc(u16 move, u16 species, u8 ability);
|
u8 AI_TypeCalc(u16 move, u16 targetSpecies, u8 targetAbility);
|
||||||
u8 BankGetTurnOrder(u8 bank);
|
u8 BankGetTurnOrder(u8 bank);
|
||||||
void SetMoveEffect(bool8 primary, u8 certain);
|
void SetMoveEffect(bool8 primary, u8 certain);
|
||||||
void BattleDestroyCursorAt(u8 cursorPosition);
|
void BattleDestroyCursorAt(u8 cursorPosition);
|
||||||
|
6
include/diploma.h
Normal file
6
include/diploma.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef GUARD_DIPLOMA_H
|
||||||
|
#define GUARD_DIPLOMA_H
|
||||||
|
|
||||||
|
void CB2_ShowDiploma(void);
|
||||||
|
|
||||||
|
#endif // GUARD_DIPLOMA_H
|
@ -642,6 +642,7 @@ void UpdatePartyPokerusTime(u16 days);
|
|||||||
void PartySpreadPokerus(struct Pokemon *party);
|
void PartySpreadPokerus(struct Pokemon *party);
|
||||||
s8 GetMonFlavourRelation(struct Pokemon *mon, u8 a2);
|
s8 GetMonFlavourRelation(struct Pokemon *mon, u8 a2);
|
||||||
s8 GetFlavourRelationByPersonality(u32 personality, u8 a2);
|
s8 GetFlavourRelationByPersonality(u32 personality, u8 a2);
|
||||||
|
u8 GetItemEffectParamOffset(u16 itemId, u8 effectByte, u8 effectBit);
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
|
||||||
|
@ -3,6 +3,60 @@
|
|||||||
|
|
||||||
#include "pokemon.h"
|
#include "pokemon.h"
|
||||||
|
|
||||||
|
// TODO once pokemon item effects is decompiled
|
||||||
|
/*
|
||||||
|
struct PokemonItemEffect
|
||||||
|
{
|
||||||
|
//field 0
|
||||||
|
u8 xAtk : 4; // x1, x2, x4, x8 = xF
|
||||||
|
u8 field_0_x10 : 1; // x10
|
||||||
|
u8 critRatioUp : 1; // x20
|
||||||
|
u8 field_0_x40 : 1; // x40
|
||||||
|
u8 cureInfatuation : 1; // x80
|
||||||
|
|
||||||
|
/*field 1
|
||||||
|
u8 xSpeed : 4; // x1, x2, x4, x8 = xF
|
||||||
|
u8 xDefense : 4; // x10, x20, x40, xF0
|
||||||
|
|
||||||
|
/*field 2
|
||||||
|
u8 xSpAtk : 4; // x1, x2, x4, x8 = xF
|
||||||
|
u8 xAccuracy : 4; // x10, x20, x40, xF0
|
||||||
|
|
||||||
|
/*field 3
|
||||||
|
u8 cureConfusion : 1; // x1
|
||||||
|
u8 cureParalysis : 1; // x2
|
||||||
|
u8 cureFreeze : 1; // x4
|
||||||
|
u8 cureBurn : 1; // x8
|
||||||
|
u8 curePoison : 1; // x10
|
||||||
|
u8 cureSleep : 1; // x20
|
||||||
|
u8 field_3_x40 : 1; // x40
|
||||||
|
u8 cantLowerStats : 1; // x80
|
||||||
|
|
||||||
|
/*field 4
|
||||||
|
u8 hpEv : 1; // x1
|
||||||
|
u8 attackEv : 1; // x2
|
||||||
|
u8 healHp : 1; // x4
|
||||||
|
u8 field_4_x8 : 1; // x8
|
||||||
|
u8 field_4_x10 : 1; // x10
|
||||||
|
u8 ppUp : 1; // x20
|
||||||
|
u8 levelUp : 1; // x40
|
||||||
|
u8 evolutionStone : 1; // x80
|
||||||
|
|
||||||
|
/*field 5
|
||||||
|
u8 defEv: 1; // x1
|
||||||
|
u8 speedEv : 1; // x2
|
||||||
|
u8 spDefEv : 1; // x4
|
||||||
|
u8 spAtkEv : 1; // x8
|
||||||
|
u8 ppMax : 1; // x10
|
||||||
|
u8 field_5_x20 : 1; // x20
|
||||||
|
u8 field_5_x40 : 1; // x40
|
||||||
|
u8 field_5_x80 : 1; // x80
|
||||||
|
|
||||||
|
/*field 6
|
||||||
|
u8 value;
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
bool8 ExecuteTableBasedItemEffect(struct Pokemon *mon, u16 itemId, u8 partyId, u8 monMoveIndex, u8 a5);
|
bool8 ExecuteTableBasedItemEffect(struct Pokemon *mon, u16 itemId, u8 partyId, u8 monMoveIndex, u8 a5);
|
||||||
|
|
||||||
#endif // GUARD_POKEMON_ITEM_EFFECTS
|
#endif // GUARD_POKEMON_ITEM_EFFECTS
|
||||||
|
@ -64,7 +64,7 @@ SECTIONS {
|
|||||||
asm/battle_controller_player.o(.text);
|
asm/battle_controller_player.o(.text);
|
||||||
asm/battle_7.o(.text);
|
asm/battle_7.o(.text);
|
||||||
asm/battle_controller_opponent.o(.text);
|
asm/battle_controller_opponent.o(.text);
|
||||||
asm/battle_9.o(.text);
|
src/battle_ai_switch_items.o(.text);
|
||||||
asm/battle_controller_linkopponent.o(.text);
|
asm/battle_controller_linkopponent.o(.text);
|
||||||
src/pokemon_1.o(.text);
|
src/pokemon_1.o(.text);
|
||||||
asm/pokemon_1.o(.text);
|
asm/pokemon_1.o(.text);
|
||||||
|
@ -5324,30 +5324,30 @@ static void HandleAction_UseItem(void)
|
|||||||
{
|
{
|
||||||
gBattleScripting.bank = gBankAttacker;
|
gBattleScripting.bank = gBankAttacker;
|
||||||
|
|
||||||
switch (*(gBattleStruct->field_C4 + (gBankAttacker >> 1)))
|
switch (*(gBattleStruct->AI_itemType + (gBankAttacker >> 1)))
|
||||||
{
|
{
|
||||||
case 1:
|
case AI_ITEM_FULL_RESTORE:
|
||||||
case 2:
|
case AI_ITEM_HEAL_HP:
|
||||||
break;
|
break;
|
||||||
case 3:
|
case AI_ITEM_CURE_CONDITION:
|
||||||
gBattleCommunication[MULTISTRING_CHOOSER] = 0;
|
gBattleCommunication[MULTISTRING_CHOOSER] = 0;
|
||||||
if (*(gBattleStruct->field_C6 + gBankAttacker / 2) & 1)
|
if (*(gBattleStruct->AI_itemFlags + gBankAttacker / 2) & 1)
|
||||||
{
|
{
|
||||||
if (*(gBattleStruct->field_C6 + gBankAttacker / 2) & 0x3E)
|
if (*(gBattleStruct->AI_itemFlags + gBankAttacker / 2) & 0x3E)
|
||||||
gBattleCommunication[MULTISTRING_CHOOSER] = 5;
|
gBattleCommunication[MULTISTRING_CHOOSER] = 5;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (!(*(gBattleStruct->field_C6 + gBankAttacker / 2) & 1))
|
while (!(*(gBattleStruct->AI_itemFlags + gBankAttacker / 2) & 1))
|
||||||
{
|
{
|
||||||
*(gBattleStruct->field_C6 + gBankAttacker / 2) >>= 1;
|
*(gBattleStruct->AI_itemFlags + gBankAttacker / 2) >>= 1;
|
||||||
gBattleCommunication[MULTISTRING_CHOOSER]++;
|
gBattleCommunication[MULTISTRING_CHOOSER]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case AI_ITEM_X_STAT:
|
||||||
gBattleCommunication[MULTISTRING_CHOOSER] = 4;
|
gBattleCommunication[MULTISTRING_CHOOSER] = 4;
|
||||||
if (*(gBattleStruct->field_C6 + (gBankAttacker >> 1)) & 0x80)
|
if (*(gBattleStruct->AI_itemFlags + (gBankAttacker >> 1)) & 0x80)
|
||||||
{
|
{
|
||||||
gBattleCommunication[MULTISTRING_CHOOSER] = 5;
|
gBattleCommunication[MULTISTRING_CHOOSER] = 5;
|
||||||
}
|
}
|
||||||
@ -5356,9 +5356,9 @@ static void HandleAction_UseItem(void)
|
|||||||
PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK)
|
PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK)
|
||||||
PREPARE_STRING_BUFFER(gBattleTextBuff2, 0xD2)
|
PREPARE_STRING_BUFFER(gBattleTextBuff2, 0xD2)
|
||||||
|
|
||||||
while (!((*(gBattleStruct->field_C6 + (gBankAttacker >> 1))) & 1))
|
while (!((*(gBattleStruct->AI_itemFlags + (gBankAttacker >> 1))) & 1))
|
||||||
{
|
{
|
||||||
*(gBattleStruct->field_C6 + gBankAttacker / 2) >>= 1;
|
*(gBattleStruct->AI_itemFlags + gBankAttacker / 2) >>= 1;
|
||||||
gBattleTextBuff1[2]++;
|
gBattleTextBuff1[2]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5366,7 +5366,7 @@ static void HandleAction_UseItem(void)
|
|||||||
gBattleScripting.animArg2 = 0;
|
gBattleScripting.animArg2 = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case AI_ITEM_GUARD_SPECS:
|
||||||
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||||
gBattleCommunication[MULTISTRING_CHOOSER] = 2;
|
gBattleCommunication[MULTISTRING_CHOOSER] = 2;
|
||||||
else
|
else
|
||||||
@ -5374,7 +5374,7 @@ static void HandleAction_UseItem(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
gBattlescriptCurrInstr = gUnknown_082DBD3C[*(gBattleStruct->field_C4 + gBankAttacker / 2)];
|
gBattlescriptCurrInstr = gUnknown_082DBD3C[*(gBattleStruct->AI_itemType + gBankAttacker / 2)];
|
||||||
}
|
}
|
||||||
gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT;
|
gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ void BattleAI_HandleItemUseBeforeAISetup(u8 defaultScoreMoves)
|
|||||||
{
|
{
|
||||||
if (gTrainers[gTrainerBattleOpponent_A].items[i] != 0)
|
if (gTrainers[gTrainerBattleOpponent_A].items[i] != 0)
|
||||||
{
|
{
|
||||||
gBattleResources->battleHistory->TrainerItems[gBattleResources->battleHistory->itemsNo] = gTrainers[gTrainerBattleOpponent_A].items[i];
|
gBattleResources->battleHistory->trainerItems[gBattleResources->battleHistory->itemsNo] = gTrainers[gTrainerBattleOpponent_A].items[i];
|
||||||
gBattleResources->battleHistory->itemsNo++;
|
gBattleResources->battleHistory->itemsNo++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
951
src/battle_ai_switch_items.c
Normal file
951
src/battle_ai_switch_items.c
Normal file
@ -0,0 +1,951 @@
|
|||||||
|
#include "global.h"
|
||||||
|
#include "battle.h"
|
||||||
|
#include "battle_controllers.h"
|
||||||
|
#include "abilities.h"
|
||||||
|
#include "moves.h"
|
||||||
|
#include "pokemon.h"
|
||||||
|
#include "species.h"
|
||||||
|
#include "rng.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "items.h"
|
||||||
|
#include "pokemon_item_effects.h"
|
||||||
|
|
||||||
|
extern u8 gActiveBank;
|
||||||
|
extern u8 gAbsentBankFlags;
|
||||||
|
extern u32 gBattleTypeFlags;
|
||||||
|
extern u32 gStatuses3[BATTLE_BANKS_COUNT];
|
||||||
|
extern struct BattlePokemon gBattleMons[BATTLE_BANKS_COUNT];
|
||||||
|
extern u16 gBattlePartyID[BATTLE_BANKS_COUNT];
|
||||||
|
extern u16 gUnknown_02024250[BATTLE_BANKS_COUNT];
|
||||||
|
extern u8 gUnknown_02024270[BATTLE_BANKS_COUNT];
|
||||||
|
extern u16 gDynamicBasePower;
|
||||||
|
extern u8 gBattleMoveFlags;
|
||||||
|
extern u8 gCritMultiplier;
|
||||||
|
extern s32 gBattleMoveDamage;
|
||||||
|
|
||||||
|
extern const struct BattleMove gBattleMoves[];
|
||||||
|
extern const struct BaseStats gBaseStats[];
|
||||||
|
extern const u8 gTypeEffectiveness[];
|
||||||
|
extern const u8 * const gItemEffectTable[]; // todo: fix once struct is declared
|
||||||
|
|
||||||
|
// this file's functions
|
||||||
|
static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng);
|
||||||
|
static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent);
|
||||||
|
static bool8 ShouldUseItem(void);
|
||||||
|
|
||||||
|
static bool8 ShouldSwitchIfPerishSong(void)
|
||||||
|
{
|
||||||
|
if (gStatuses3[gActiveBank] & STATUS3_PERISH_SONG
|
||||||
|
&& gDisableStructs[gActiveBank].perishSong1 == 0)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->field_294 + gActiveBank) = 6;
|
||||||
|
EmitCmd_x21(1, 2, 0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool8 ShouldSwitchIfWonderGuard(void)
|
||||||
|
{
|
||||||
|
u8 opposingIdentity;
|
||||||
|
u8 opposingBank;
|
||||||
|
u8 moveFlags;
|
||||||
|
s32 i, j;
|
||||||
|
s32 firstId;
|
||||||
|
s32 lastId; // + 1
|
||||||
|
struct Pokemon *party = NULL;
|
||||||
|
u16 move;
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
opposingIdentity = GetBankIdentity(gActiveBank) ^ BIT_SIDE;
|
||||||
|
|
||||||
|
if (gBattleMons[GetBankByIdentity(opposingIdentity)].ability != ABILITY_WONDER_GUARD)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
// check if pokemon has a super effective move
|
||||||
|
for (opposingBank = GetBankByIdentity(opposingIdentity), i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
move = gBattleMons[gActiveBank].moves[i];
|
||||||
|
if (move == MOVE_NONE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability);
|
||||||
|
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get party information
|
||||||
|
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||||
|
{
|
||||||
|
if ((gActiveBank & BIT_MON) == 0)
|
||||||
|
firstId = 0, lastId = 3;
|
||||||
|
else
|
||||||
|
firstId = 3, lastId = 6;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
firstId = 0, lastId = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||||
|
party = gPlayerParty;
|
||||||
|
else
|
||||||
|
party = gEnemyParty;
|
||||||
|
|
||||||
|
// find a pokemon in the party that has a super effective move
|
||||||
|
for (i = firstId; i < lastId; i++)
|
||||||
|
{
|
||||||
|
if (GetMonData(&party[i], MON_DATA_HP) == 0)
|
||||||
|
continue;
|
||||||
|
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_NONE)
|
||||||
|
continue;
|
||||||
|
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG)
|
||||||
|
continue;
|
||||||
|
if (i == gBattlePartyID[gActiveBank])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
GetMonData(&party[i], MON_DATA_SPECIES); // unused return value
|
||||||
|
GetMonData(&party[i], MON_DATA_ALT_ABILITY); // unused return value
|
||||||
|
|
||||||
|
for (opposingBank = GetBankByIdentity(opposingIdentity), j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
move = GetMonData(&party[i], MON_DATA_MOVE1 + j);
|
||||||
|
if (move == MOVE_NONE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability);
|
||||||
|
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE && Random() % 3 < 2)
|
||||||
|
{
|
||||||
|
// we found a mon
|
||||||
|
*(gBattleStruct->field_294 + gActiveBank) = i;
|
||||||
|
EmitCmd_x21(1, 2, 0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE; // at this point there is not a single pokemon in the party that has a super effective move against a pokemon with wonder guard
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool8 FindMonThatAbsorbsOpponentsMove(void)
|
||||||
|
{
|
||||||
|
u8 bankIn1, bankIn2;
|
||||||
|
u8 absorbingTypeAbility;
|
||||||
|
s32 firstId;
|
||||||
|
s32 lastId; // + 1
|
||||||
|
struct Pokemon *party;
|
||||||
|
s32 i;
|
||||||
|
|
||||||
|
if (HasSuperEffectiveMoveAgainstOpponents(TRUE) && Random() % 3 != 0)
|
||||||
|
return FALSE;
|
||||||
|
if (gUnknown_02024250[gActiveBank] == 0)
|
||||||
|
return FALSE;
|
||||||
|
if (gUnknown_02024250[gActiveBank] == 0xFFFF)
|
||||||
|
return FALSE;
|
||||||
|
if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||||
|
{
|
||||||
|
bankIn1 = gActiveBank;
|
||||||
|
if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON)])
|
||||||
|
bankIn2 = gActiveBank;
|
||||||
|
else
|
||||||
|
bankIn2 = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bankIn1 = gActiveBank;
|
||||||
|
bankIn2 = gActiveBank;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gBattleMoves[gUnknown_02024250[gActiveBank]].type == TYPE_FIRE)
|
||||||
|
absorbingTypeAbility = ABILITY_FLASH_FIRE;
|
||||||
|
else if (gBattleMoves[gUnknown_02024250[gActiveBank]].type == TYPE_WATER)
|
||||||
|
absorbingTypeAbility = ABILITY_WATER_ABSORB;
|
||||||
|
else if (gBattleMoves[gUnknown_02024250[gActiveBank]].type == TYPE_ELECTRIC)
|
||||||
|
absorbingTypeAbility = ABILITY_VOLT_ABSORB;
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (gBattleMons[gActiveBank].ability == absorbingTypeAbility)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||||
|
{
|
||||||
|
if ((gActiveBank & BIT_MON) == 0)
|
||||||
|
firstId = 0, lastId = 3;
|
||||||
|
else
|
||||||
|
firstId = 3, lastId = 6;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
firstId = 0, lastId = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||||
|
party = gPlayerParty;
|
||||||
|
else
|
||||||
|
party = gEnemyParty;
|
||||||
|
|
||||||
|
for (i = firstId; i < lastId; i++)
|
||||||
|
{
|
||||||
|
u16 species;
|
||||||
|
u8 monAbility;
|
||||||
|
|
||||||
|
if (GetMonData(&party[i], MON_DATA_HP) == 0)
|
||||||
|
continue;
|
||||||
|
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_NONE)
|
||||||
|
continue;
|
||||||
|
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG)
|
||||||
|
continue;
|
||||||
|
if (i == gBattlePartyID[bankIn1])
|
||||||
|
continue;
|
||||||
|
if (i == gBattlePartyID[bankIn2])
|
||||||
|
continue;
|
||||||
|
if (i == *(gBattleStruct->field_5C + bankIn1))
|
||||||
|
continue;
|
||||||
|
if (i == *(gBattleStruct->field_5C + bankIn2))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
species = GetMonData(&party[i], MON_DATA_SPECIES);
|
||||||
|
if (GetMonData(&party[i], MON_DATA_ALT_ABILITY) != 0)
|
||||||
|
monAbility = gBaseStats[species].ability2;
|
||||||
|
else
|
||||||
|
monAbility = gBaseStats[species].ability1;
|
||||||
|
|
||||||
|
if (absorbingTypeAbility == monAbility && Random() & 1)
|
||||||
|
{
|
||||||
|
// we found a mon
|
||||||
|
*(gBattleStruct->field_294 + gActiveBank) = i;
|
||||||
|
EmitCmd_x21(1, 2, 0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool8 ShouldSwitchIfNaturalCure(void)
|
||||||
|
{
|
||||||
|
if (!(gBattleMons[gActiveBank].status1 & STATUS_SLEEP))
|
||||||
|
return FALSE;
|
||||||
|
if (gBattleMons[gActiveBank].ability != ABILITY_NATURAL_CURE)
|
||||||
|
return FALSE;
|
||||||
|
if (gBattleMons[gActiveBank].hp < gBattleMons[gActiveBank].maxHP / 2)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if ((gUnknown_02024250[gActiveBank] == 0 || gUnknown_02024250[gActiveBank] == 0xFFFF) && Random() & 1)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->field_294 + gActiveBank) = 6;
|
||||||
|
EmitCmd_x21(1, 2, 0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0 && Random() & 1)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->field_294 + gActiveBank) = 6;
|
||||||
|
EmitCmd_x21(1, 2, 0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTAFFECTED, 1))
|
||||||
|
return TRUE;
|
||||||
|
if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTVERYEFFECTIVE, 1))
|
||||||
|
return TRUE;
|
||||||
|
if (Random() & 1)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->field_294 + gActiveBank) = 6;
|
||||||
|
EmitCmd_x21(1, 2, 0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng)
|
||||||
|
{
|
||||||
|
u8 opposingIdentity;
|
||||||
|
u8 opposingBank;
|
||||||
|
s32 i;
|
||||||
|
u8 moveFlags;
|
||||||
|
u16 move;
|
||||||
|
|
||||||
|
opposingIdentity = GetBankIdentity(gActiveBank) ^ BIT_SIDE;
|
||||||
|
opposingBank = GetBankByIdentity(opposingIdentity);
|
||||||
|
|
||||||
|
if (!(gAbsentBankFlags & gBitTable[opposingBank]))
|
||||||
|
{
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
move = gBattleMons[gActiveBank].moves[i];
|
||||||
|
if (move == MOVE_NONE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability);
|
||||||
|
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE)
|
||||||
|
{
|
||||||
|
if (noRng)
|
||||||
|
return TRUE;
|
||||||
|
if (Random() % 10 != 0)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
opposingBank = GetBankByIdentity(opposingIdentity ^ BIT_MON);
|
||||||
|
|
||||||
|
if (!(gAbsentBankFlags & gBitTable[opposingBank]))
|
||||||
|
{
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
move = gBattleMons[gActiveBank].moves[i];
|
||||||
|
if (move == MOVE_NONE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability);
|
||||||
|
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE)
|
||||||
|
{
|
||||||
|
if (noRng)
|
||||||
|
return TRUE;
|
||||||
|
if (Random() % 10 != 0)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool8 AreStatsRaised(void)
|
||||||
|
{
|
||||||
|
u8 buffedStatsValue = 0;
|
||||||
|
s32 i;
|
||||||
|
|
||||||
|
for (i = 0; i < BATTLE_STATS_NO; i++)
|
||||||
|
{
|
||||||
|
if (gBattleMons[gActiveBank].statStages[i] > 6)
|
||||||
|
buffedStatsValue += gBattleMons[gActiveBank].statStages[i] - 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (buffedStatsValue > 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent)
|
||||||
|
{
|
||||||
|
u8 bankIn1, bankIn2;
|
||||||
|
s32 firstId;
|
||||||
|
s32 lastId; // + 1
|
||||||
|
struct Pokemon *party;
|
||||||
|
s32 i, j;
|
||||||
|
u16 move;
|
||||||
|
u8 moveFlags;
|
||||||
|
|
||||||
|
if (gUnknown_02024250[gActiveBank] == 0)
|
||||||
|
return FALSE;
|
||||||
|
if (gUnknown_02024250[gActiveBank] == 0xFFFF)
|
||||||
|
return FALSE;
|
||||||
|
if (gUnknown_02024270[gActiveBank] == 0xFF)
|
||||||
|
return FALSE;
|
||||||
|
if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||||
|
{
|
||||||
|
bankIn1 = gActiveBank;
|
||||||
|
if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON)])
|
||||||
|
bankIn2 = gActiveBank;
|
||||||
|
else
|
||||||
|
bankIn2 = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bankIn1 = gActiveBank;
|
||||||
|
bankIn2 = gActiveBank;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||||
|
{
|
||||||
|
if ((gActiveBank & BIT_MON) == 0)
|
||||||
|
firstId = 0, lastId = 3;
|
||||||
|
else
|
||||||
|
firstId = 3, lastId = 6;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
firstId = 0, lastId = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||||
|
party = gPlayerParty;
|
||||||
|
else
|
||||||
|
party = gEnemyParty;
|
||||||
|
|
||||||
|
for (i = firstId; i < lastId; i++)
|
||||||
|
{
|
||||||
|
u16 species;
|
||||||
|
u8 monAbility;
|
||||||
|
|
||||||
|
if (GetMonData(&party[i], MON_DATA_HP) == 0)
|
||||||
|
continue;
|
||||||
|
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_NONE)
|
||||||
|
continue;
|
||||||
|
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG)
|
||||||
|
continue;
|
||||||
|
if (i == gBattlePartyID[bankIn1])
|
||||||
|
continue;
|
||||||
|
if (i == gBattlePartyID[bankIn2])
|
||||||
|
continue;
|
||||||
|
if (i == *(gBattleStruct->field_5C + bankIn1))
|
||||||
|
continue;
|
||||||
|
if (i == *(gBattleStruct->field_5C + bankIn2))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
species = GetMonData(&party[i], MON_DATA_SPECIES);
|
||||||
|
if (GetMonData(&party[i], MON_DATA_ALT_ABILITY) != 0)
|
||||||
|
monAbility = gBaseStats[species].ability2;
|
||||||
|
else
|
||||||
|
monAbility = gBaseStats[species].ability1;
|
||||||
|
|
||||||
|
moveFlags = AI_TypeCalc(gUnknown_02024250[gActiveBank], species, monAbility);
|
||||||
|
if (moveFlags & flags)
|
||||||
|
{
|
||||||
|
bankIn1 = gUnknown_02024270[gActiveBank];
|
||||||
|
|
||||||
|
for (j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
move = GetMonData(&party[i], MON_DATA_MOVE1 + j);
|
||||||
|
if (move == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
moveFlags = AI_TypeCalc(move, gBattleMons[bankIn1].species, gBattleMons[bankIn1].ability);
|
||||||
|
if (moveFlags & MOVESTATUS_SUPEREFFECTIVE && Random() % moduloPercent == 0)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->field_294 + gActiveBank) = i;
|
||||||
|
EmitCmd_x21(1, 2, 0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool8 ShouldSwitch(void)
|
||||||
|
{
|
||||||
|
u8 bankIn1, bankIn2;
|
||||||
|
u8 *activeBankPtr; // needed to match
|
||||||
|
s32 firstId;
|
||||||
|
s32 lastId; // + 1
|
||||||
|
struct Pokemon *party;
|
||||||
|
s32 i;
|
||||||
|
s32 availableToSwitch;
|
||||||
|
|
||||||
|
if (gBattleMons[*(activeBankPtr = &gActiveBank)].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION))
|
||||||
|
return FALSE;
|
||||||
|
if (gStatuses3[gActiveBank] & STATUS3_ROOTED)
|
||||||
|
return FALSE;
|
||||||
|
if (AbilityBattleEffects(ABILITYEFFECT_CHECK_OTHER_SIDE, gActiveBank, ABILITY_SHADOW_TAG, 0, 0))
|
||||||
|
return FALSE;
|
||||||
|
if (AbilityBattleEffects(ABILITYEFFECT_CHECK_OTHER_SIDE, gActiveBank, ABILITY_ARENA_TRAP, 0, 0))
|
||||||
|
return FALSE; // misses the flying or levitate check
|
||||||
|
if (AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_MAGNET_PULL, 0, 0))
|
||||||
|
{
|
||||||
|
if (gBattleMons[gActiveBank].type1 == TYPE_STEEL)
|
||||||
|
return FALSE;
|
||||||
|
if (gBattleMons[gActiveBank].type2 == TYPE_STEEL)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (gBattleTypeFlags & BATTLE_TYPE_ARENA)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
availableToSwitch = 0;
|
||||||
|
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||||
|
{
|
||||||
|
bankIn1 = *activeBankPtr;
|
||||||
|
if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(*activeBankPtr) ^ BIT_MON)])
|
||||||
|
bankIn2 = *activeBankPtr;
|
||||||
|
else
|
||||||
|
bankIn2 = GetBankByIdentity(GetBankIdentity(*activeBankPtr) ^ BIT_MON);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bankIn1 = *activeBankPtr;
|
||||||
|
bankIn2 = *activeBankPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||||
|
{
|
||||||
|
if ((gActiveBank & BIT_MON) == 0)
|
||||||
|
firstId = 0, lastId = 3;
|
||||||
|
else
|
||||||
|
firstId = 3, lastId = 6;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
firstId = 0, lastId = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||||
|
party = gPlayerParty;
|
||||||
|
else
|
||||||
|
party = gEnemyParty;
|
||||||
|
|
||||||
|
for (i = firstId; i < lastId; i++)
|
||||||
|
{
|
||||||
|
if (GetMonData(&party[i], MON_DATA_HP) == 0)
|
||||||
|
continue;
|
||||||
|
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_NONE)
|
||||||
|
continue;
|
||||||
|
if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG)
|
||||||
|
continue;
|
||||||
|
if (i == gBattlePartyID[bankIn1])
|
||||||
|
continue;
|
||||||
|
if (i == gBattlePartyID[bankIn2])
|
||||||
|
continue;
|
||||||
|
if (i == *(gBattleStruct->field_5C + bankIn1))
|
||||||
|
continue;
|
||||||
|
if (i == *(gBattleStruct->field_5C + bankIn2))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
availableToSwitch++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (availableToSwitch == 0)
|
||||||
|
return FALSE;
|
||||||
|
if (ShouldSwitchIfPerishSong())
|
||||||
|
return TRUE;
|
||||||
|
if (ShouldSwitchIfWonderGuard())
|
||||||
|
return TRUE;
|
||||||
|
if (FindMonThatAbsorbsOpponentsMove())
|
||||||
|
return TRUE;
|
||||||
|
if (ShouldSwitchIfNaturalCure())
|
||||||
|
return TRUE;
|
||||||
|
if (HasSuperEffectiveMoveAgainstOpponents(FALSE))
|
||||||
|
return FALSE;
|
||||||
|
if (AreStatsRaised())
|
||||||
|
return FALSE;
|
||||||
|
if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTAFFECTED, 2)
|
||||||
|
|| FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTVERYEFFECTIVE, 3))
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AI_TrySwitchOrUseItem(void)
|
||||||
|
{
|
||||||
|
struct Pokemon *party;
|
||||||
|
u8 bankIn1, bankIn2;
|
||||||
|
s32 firstId;
|
||||||
|
s32 lastId; // + 1
|
||||||
|
u8 bankIdentity = GetBankIdentity(gActiveBank);
|
||||||
|
|
||||||
|
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||||
|
party = gPlayerParty;
|
||||||
|
else
|
||||||
|
party = gEnemyParty;
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
|
||||||
|
{
|
||||||
|
if (ShouldSwitch())
|
||||||
|
{
|
||||||
|
if (*(gBattleStruct->field_294 + gActiveBank) == 6)
|
||||||
|
{
|
||||||
|
s32 monToSwitchId = GetMostSuitableMonToSwitchInto();
|
||||||
|
if (monToSwitchId == 6)
|
||||||
|
{
|
||||||
|
if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
|
||||||
|
{
|
||||||
|
bankIn1 = GetBankByIdentity(bankIdentity);
|
||||||
|
bankIn2 = bankIn1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bankIn1 = GetBankByIdentity(bankIdentity);
|
||||||
|
bankIn2 = GetBankByIdentity(bankIdentity ^ BIT_MON);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||||
|
{
|
||||||
|
if ((gActiveBank & BIT_MON) == 0)
|
||||||
|
firstId = 0, lastId = 3;
|
||||||
|
else
|
||||||
|
firstId = 3, lastId = 6;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
firstId = 0, lastId = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (monToSwitchId = firstId; monToSwitchId < lastId; monToSwitchId++)
|
||||||
|
{
|
||||||
|
if (GetMonData(&party[monToSwitchId], MON_DATA_HP) == 0)
|
||||||
|
continue;
|
||||||
|
if (monToSwitchId == gBattlePartyID[bankIn1])
|
||||||
|
continue;
|
||||||
|
if (monToSwitchId == gBattlePartyID[bankIn2])
|
||||||
|
continue;
|
||||||
|
if (monToSwitchId == *(gBattleStruct->field_5C + bankIn1))
|
||||||
|
continue;
|
||||||
|
if (monToSwitchId == *(gBattleStruct->field_5C + bankIn2))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*(gBattleStruct->field_294 + gActiveBank) = monToSwitchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(gBattleStruct->field_5C + gActiveBank) = *(gBattleStruct->field_294 + gActiveBank);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (ShouldUseItem())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EmitCmd_x21(1, 0, (gActiveBank ^ BIT_SIDE) << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TYPE_FORESIGHT 0xFE
|
||||||
|
#define TYPE_ENDTABLE 0xFF
|
||||||
|
|
||||||
|
static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8 *var)
|
||||||
|
{
|
||||||
|
s32 i = 0;
|
||||||
|
|
||||||
|
while (gTypeEffectiveness[i] != TYPE_ENDTABLE)
|
||||||
|
{
|
||||||
|
if (gTypeEffectiveness[i] == TYPE_FORESIGHT)
|
||||||
|
{
|
||||||
|
i += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (gTypeEffectiveness[i] == atkType)
|
||||||
|
{
|
||||||
|
// check type1
|
||||||
|
if (gTypeEffectiveness[i + 1] == defType1)
|
||||||
|
*var = (*var * gTypeEffectiveness[i + 2]) / 10;
|
||||||
|
// check type2
|
||||||
|
if (gTypeEffectiveness[i + 1] == defType2 && defType1 != defType2)
|
||||||
|
*var = (*var * gTypeEffectiveness[i + 2]) / 10;
|
||||||
|
}
|
||||||
|
i += 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 GetMostSuitableMonToSwitchInto(void)
|
||||||
|
{
|
||||||
|
u8 opposingBank;
|
||||||
|
u8 bestDmg; // note : should be changed to u32 for obvious reasons
|
||||||
|
u8 bestMonId;
|
||||||
|
u8 bankIn1, bankIn2;
|
||||||
|
s32 firstId;
|
||||||
|
s32 lastId; // + 1
|
||||||
|
struct Pokemon *party;
|
||||||
|
s32 i, j;
|
||||||
|
u8 invalidMons;
|
||||||
|
u16 move;
|
||||||
|
|
||||||
|
if (*(gBattleStruct->field_5C + gActiveBank) != 6)
|
||||||
|
return *(gBattleStruct->field_5C + gActiveBank);
|
||||||
|
if (gBattleTypeFlags & BATTLE_TYPE_ARENA)
|
||||||
|
return gBattlePartyID[gActiveBank] + 1;
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||||
|
{
|
||||||
|
bankIn1 = gActiveBank;
|
||||||
|
if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON)])
|
||||||
|
bankIn2 = gActiveBank;
|
||||||
|
else
|
||||||
|
bankIn2 = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON);
|
||||||
|
|
||||||
|
// UB: It considers the opponent only player's side even though it can battle alongside player;
|
||||||
|
opposingBank = Random() & BIT_MON;
|
||||||
|
if (gAbsentBankFlags & gBitTable[opposingBank])
|
||||||
|
opposingBank ^= BIT_MON;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
opposingBank = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_SIDE);
|
||||||
|
bankIn1 = gActiveBank;
|
||||||
|
bankIn2 = gActiveBank;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000))
|
||||||
|
{
|
||||||
|
if ((gActiveBank & BIT_MON) == 0)
|
||||||
|
firstId = 0, lastId = 3;
|
||||||
|
else
|
||||||
|
firstId = 3, lastId = 6;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
firstId = 0, lastId = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||||
|
party = gPlayerParty;
|
||||||
|
else
|
||||||
|
party = gEnemyParty;
|
||||||
|
|
||||||
|
invalidMons = 0;
|
||||||
|
|
||||||
|
while (invalidMons != 0x3F) // all mons are invalid
|
||||||
|
{
|
||||||
|
bestDmg = 0;
|
||||||
|
bestMonId = 6;
|
||||||
|
// find the mon which type is the most suitable offensively
|
||||||
|
for (i = firstId; i < lastId; i++)
|
||||||
|
{
|
||||||
|
u16 species = GetMonData(&party[i], MON_DATA_SPECIES);
|
||||||
|
if (species != SPECIES_NONE
|
||||||
|
&& GetMonData(&party[i], MON_DATA_HP) != 0
|
||||||
|
&& !(gBitTable[i] & invalidMons)
|
||||||
|
&& gBattlePartyID[bankIn1] != i
|
||||||
|
&& gBattlePartyID[bankIn2] != i
|
||||||
|
&& i != *(gBattleStruct->field_5C + bankIn1)
|
||||||
|
&& i != *(gBattleStruct->field_5C + bankIn2))
|
||||||
|
{
|
||||||
|
u8 type1 = gBaseStats[species].type1;
|
||||||
|
u8 type2 = gBaseStats[species].type2;
|
||||||
|
u8 typeDmg = 10;
|
||||||
|
ModulateByTypeEffectiveness(gBattleMons[opposingBank].type1, type1, type2, &typeDmg);
|
||||||
|
ModulateByTypeEffectiveness(gBattleMons[opposingBank].type2, type1, type2, &typeDmg);
|
||||||
|
if (bestDmg < typeDmg)
|
||||||
|
{
|
||||||
|
bestDmg = typeDmg;
|
||||||
|
bestMonId = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
invalidMons |= gBitTable[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ok, we know the mon has the right typing but does it have at least one super effective move?
|
||||||
|
if (bestMonId != 6)
|
||||||
|
{
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
move = GetMonData(&party[bestMonId], MON_DATA_MOVE1 + i);
|
||||||
|
if (move != MOVE_NONE && TypeCalc(move, gActiveBank, opposingBank) & MOVESTATUS_SUPEREFFECTIVE)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i != 4)
|
||||||
|
return bestMonId; // has both the typing and at least one super effective move
|
||||||
|
|
||||||
|
invalidMons |= gBitTable[bestMonId]; // sorry buddy, we want something better
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
invalidMons = 0x3F; // no viable mon to switch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gDynamicBasePower = 0;
|
||||||
|
gBattleStruct->dynamicMoveType = 0;
|
||||||
|
gBattleScripting.dmgMultiplier = 1;
|
||||||
|
gBattleMoveFlags = 0;
|
||||||
|
gCritMultiplier = 1;
|
||||||
|
bestDmg = 0;
|
||||||
|
bestMonId = 6;
|
||||||
|
|
||||||
|
// if we couldn't find the best mon in terms of typing, find the one that deals most damage
|
||||||
|
for (i = firstId; i < lastId; i++)
|
||||||
|
{
|
||||||
|
if ((u16)(GetMonData(&party[i], MON_DATA_SPECIES)) == SPECIES_NONE)
|
||||||
|
continue;
|
||||||
|
if (GetMonData(&party[i], MON_DATA_HP) == 0)
|
||||||
|
continue;
|
||||||
|
if (gBattlePartyID[bankIn1] == i)
|
||||||
|
continue;
|
||||||
|
if (gBattlePartyID[bankIn2] == i)
|
||||||
|
continue;
|
||||||
|
if (i == *(gBattleStruct->field_5C + bankIn1))
|
||||||
|
continue;
|
||||||
|
if (i == *(gBattleStruct->field_5C + bankIn2))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
move = GetMonData(&party[i], MON_DATA_MOVE1 + j);
|
||||||
|
gBattleMoveDamage = 0;
|
||||||
|
if (move != MOVE_NONE && gBattleMoves[move].power != 1)
|
||||||
|
{
|
||||||
|
AI_CalcDmg(gActiveBank, opposingBank);
|
||||||
|
TypeCalc(move, gActiveBank, opposingBank);
|
||||||
|
}
|
||||||
|
if (bestDmg < gBattleMoveDamage)
|
||||||
|
{
|
||||||
|
bestDmg = gBattleMoveDamage;
|
||||||
|
bestMonId = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bestMonId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use PokemonItemEffect struct instead of u8 once it's documented
|
||||||
|
static u8 GetAI_ItemType(u8 itemId, const u8 *itemEffect) // NOTE: should take u16 as item Id argument
|
||||||
|
{
|
||||||
|
if (itemId == ITEM_FULL_RESTORE)
|
||||||
|
return AI_ITEM_FULL_RESTORE;
|
||||||
|
if (itemEffect[4] & 4)
|
||||||
|
return AI_ITEM_HEAL_HP;
|
||||||
|
if (itemEffect[3] & 0x3F)
|
||||||
|
return AI_ITEM_CURE_CONDITION;
|
||||||
|
if (itemEffect[0] & 0x3F || itemEffect[1] != 0 || itemEffect[2] != 0)
|
||||||
|
return AI_ITEM_X_STAT;
|
||||||
|
if (itemEffect[3] & 0x80)
|
||||||
|
return AI_ITEM_GUARD_SPECS;
|
||||||
|
|
||||||
|
return AI_ITEM_NOT_RECOGNIZABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool8 ShouldUseItem(void)
|
||||||
|
{
|
||||||
|
struct Pokemon *party;
|
||||||
|
s32 i;
|
||||||
|
u8 validMons = 0;
|
||||||
|
bool8 shouldUse = FALSE;
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && GetBankIdentity(gActiveBank) == IDENTITY_PLAYER_MON2)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (GetBankSide(gActiveBank) == SIDE_PLAYER)
|
||||||
|
party = gPlayerParty;
|
||||||
|
else
|
||||||
|
party = gEnemyParty;
|
||||||
|
|
||||||
|
for (i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
if (GetMonData(&party[i], MON_DATA_HP) != 0
|
||||||
|
&& GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_NONE
|
||||||
|
&& GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG)
|
||||||
|
{
|
||||||
|
validMons++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
u16 item;
|
||||||
|
const u8 *itemEffects;
|
||||||
|
u8 paramOffset;
|
||||||
|
u8 bankSide;
|
||||||
|
|
||||||
|
if (i != 0 && validMons > (gBattleResources->battleHistory->itemsNo - i) + 1)
|
||||||
|
continue;
|
||||||
|
item = gBattleResources->battleHistory->trainerItems[i];
|
||||||
|
if (item == ITEM_NONE)
|
||||||
|
continue;
|
||||||
|
if (gItemEffectTable[item - 13] == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (item == ITEM_ENIGMA_BERRY)
|
||||||
|
itemEffects = gSaveBlock1Ptr->enigmaBerry.itemEffect;
|
||||||
|
else
|
||||||
|
itemEffects = gItemEffectTable[item - 13];
|
||||||
|
|
||||||
|
*(gBattleStruct->AI_itemType + gActiveBank / 2) = GetAI_ItemType(item, itemEffects);
|
||||||
|
|
||||||
|
switch (*(gBattleStruct->AI_itemType + gActiveBank / 2))
|
||||||
|
{
|
||||||
|
case AI_ITEM_FULL_RESTORE:
|
||||||
|
if (gBattleMons[gActiveBank].hp >= gBattleMons[gActiveBank].maxHP / 4)
|
||||||
|
break;
|
||||||
|
if (gBattleMons[gActiveBank].hp == 0)
|
||||||
|
break;
|
||||||
|
shouldUse = TRUE;
|
||||||
|
break;
|
||||||
|
case AI_ITEM_HEAL_HP:
|
||||||
|
paramOffset = GetItemEffectParamOffset(item, 4, 4);
|
||||||
|
if (paramOffset == 0)
|
||||||
|
break;
|
||||||
|
if (gBattleMons[gActiveBank].hp == 0)
|
||||||
|
break;
|
||||||
|
if (gBattleMons[gActiveBank].hp < gBattleMons[gActiveBank].maxHP / 4 || gBattleMons[gActiveBank].maxHP - gBattleMons[gActiveBank].hp > itemEffects[paramOffset])
|
||||||
|
shouldUse = TRUE;
|
||||||
|
break;
|
||||||
|
case AI_ITEM_CURE_CONDITION:
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) = 0;
|
||||||
|
if (itemEffects[3] & 0x20 && gBattleMons[gActiveBank].status1 & STATUS_SLEEP)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x20;
|
||||||
|
shouldUse = TRUE;
|
||||||
|
}
|
||||||
|
if (itemEffects[3] & 0x10 && (gBattleMons[gActiveBank].status1 & STATUS_POISON || gBattleMons[gActiveBank].status1 & STATUS_TOXIC_POISON))
|
||||||
|
{
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x10;
|
||||||
|
shouldUse = TRUE;
|
||||||
|
}
|
||||||
|
if (itemEffects[3] & 0x8 && gBattleMons[gActiveBank].status1 & STATUS_BURN)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x8;
|
||||||
|
shouldUse = TRUE;
|
||||||
|
}
|
||||||
|
if (itemEffects[3] & 0x4 && gBattleMons[gActiveBank].status1 & STATUS_FREEZE)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x4;
|
||||||
|
shouldUse = TRUE;
|
||||||
|
}
|
||||||
|
if (itemEffects[3] & 0x2 && gBattleMons[gActiveBank].status1 & STATUS_PARALYSIS)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x2;
|
||||||
|
shouldUse = TRUE;
|
||||||
|
}
|
||||||
|
if (itemEffects[3] & 0x1 && gBattleMons[gActiveBank].status2 & STATUS2_CONFUSION)
|
||||||
|
{
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x1;
|
||||||
|
shouldUse = TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AI_ITEM_X_STAT:
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) = 0;
|
||||||
|
if (gDisableStructs[gActiveBank].isFirstTurn == 0)
|
||||||
|
break;
|
||||||
|
if (itemEffects[0] & 0xF)
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x1;
|
||||||
|
if (itemEffects[1] & 0xF0)
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x2;
|
||||||
|
if (itemEffects[1] & 0xF)
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x4;
|
||||||
|
if (itemEffects[2] & 0xF)
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x8;
|
||||||
|
if (itemEffects[2] & 0xF0)
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x20;
|
||||||
|
if (itemEffects[0] & 0x30)
|
||||||
|
*(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x80;
|
||||||
|
shouldUse = TRUE;
|
||||||
|
break;
|
||||||
|
case AI_ITEM_GUARD_SPECS:
|
||||||
|
bankSide = GetBankSide(gActiveBank);
|
||||||
|
if (gDisableStructs[gActiveBank].isFirstTurn != 0 && gSideTimers[bankSide].mistTimer == 0)
|
||||||
|
shouldUse = TRUE;
|
||||||
|
break;
|
||||||
|
case AI_ITEM_NOT_RECOGNIZABLE:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldUse)
|
||||||
|
{
|
||||||
|
EmitCmd_x21(1, 1, 0);
|
||||||
|
*(gBattleStruct->field_C0 + (gActiveBank / 2) * 2) = item;
|
||||||
|
gBattleResources->battleHistory->trainerItems[i] = 0;
|
||||||
|
return shouldUse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
@ -1772,11 +1772,11 @@ u8 TypeCalc(u16 move, u8 bankAtk, u8 bankDef)
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 AI_TypeCalc(u16 move, u16 species, u8 ability)
|
u8 AI_TypeCalc(u16 move, u16 targetSpecies, u8 targetAbility)
|
||||||
{
|
{
|
||||||
s32 i = 0;
|
s32 i = 0;
|
||||||
u8 flags = 0;
|
u8 flags = 0;
|
||||||
u8 type1 = gBaseStats[species].type1, type2 = gBaseStats[species].type2;
|
u8 type1 = gBaseStats[targetSpecies].type1, type2 = gBaseStats[targetSpecies].type2;
|
||||||
u8 moveType;
|
u8 moveType;
|
||||||
|
|
||||||
if (move == MOVE_STRUGGLE)
|
if (move == MOVE_STRUGGLE)
|
||||||
@ -1784,7 +1784,7 @@ u8 AI_TypeCalc(u16 move, u16 species, u8 ability)
|
|||||||
|
|
||||||
moveType = gBattleMoves[move].type;
|
moveType = gBattleMoves[move].type;
|
||||||
|
|
||||||
if (ability == ABILITY_LEVITATE && moveType == TYPE_GROUND)
|
if (targetAbility == ABILITY_LEVITATE && moveType == TYPE_GROUND)
|
||||||
{
|
{
|
||||||
flags = MOVESTATUS_MISSED | MOVESTATUS_NOTAFFECTED;
|
flags = MOVESTATUS_MISSED | MOVESTATUS_NOTAFFECTED;
|
||||||
}
|
}
|
||||||
@ -1809,7 +1809,7 @@ u8 AI_TypeCalc(u16 move, u16 species, u8 ability)
|
|||||||
i += 3;
|
i += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ability == ABILITY_WONDER_GUARD
|
if (targetAbility == ABILITY_WONDER_GUARD
|
||||||
&& (!(flags & MOVESTATUS_SUPEREFFECTIVE) || ((flags & (MOVESTATUS_SUPEREFFECTIVE | MOVESTATUS_NOTVERYEFFECTIVE)) == (MOVESTATUS_SUPEREFFECTIVE | MOVESTATUS_NOTVERYEFFECTIVE)))
|
&& (!(flags & MOVESTATUS_SUPEREFFECTIVE) || ((flags & (MOVESTATUS_SUPEREFFECTIVE | MOVESTATUS_NOTVERYEFFECTIVE)) == (MOVESTATUS_SUPEREFFECTIVE | MOVESTATUS_NOTVERYEFFECTIVE)))
|
||||||
&& gBattleMoves[move].power)
|
&& gBattleMoves[move].power)
|
||||||
flags |= MOVESTATUS_NOTAFFECTED;
|
flags |= MOVESTATUS_NOTAFFECTED;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include "diploma.h"
|
||||||
#include "palette.h"
|
#include "palette.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "gpu_regs.h"
|
#include "gpu_regs.h"
|
||||||
@ -33,7 +34,7 @@ static void InitDiplomaBg(void);
|
|||||||
static void InitDiplomaWindow(void);
|
static void InitDiplomaWindow(void);
|
||||||
static void PrintDiplomaText(u8 *, u8, u8);
|
static void PrintDiplomaText(u8 *, u8, u8);
|
||||||
|
|
||||||
EWRAM_DATA void **gDiplomaTilemapPtr = {NULL};
|
EWRAM_DATA static void **sDiplomaTilemapPtr = {NULL};
|
||||||
|
|
||||||
static void VBlankCB(void)
|
static void VBlankCB(void)
|
||||||
{
|
{
|
||||||
@ -42,14 +43,14 @@ static void VBlankCB(void)
|
|||||||
TransferPlttBuffer();
|
TransferPlttBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const u16 gDiplomaPalettes[][16] =
|
static const u16 sDiplomaPalettes[][16] =
|
||||||
{
|
{
|
||||||
INCBIN_U16("graphics/misc/diploma_national.gbapal"),
|
INCBIN_U16("graphics/misc/diploma_national.gbapal"),
|
||||||
INCBIN_U16("graphics/misc/diploma_hoenn.gbapal"),
|
INCBIN_U16("graphics/misc/diploma_hoenn.gbapal"),
|
||||||
};
|
};
|
||||||
|
|
||||||
static const u8 gDiplomaTilemap[] = INCBIN_U8("graphics/misc/diploma_map.bin.lz");
|
static const u8 sDiplomaTilemap[] = INCBIN_U8("graphics/misc/diploma_map.bin.lz");
|
||||||
static const u8 gDiplomaTiles[] = INCBIN_U8("graphics/misc/diploma.4bpp.lz");
|
static const u8 sDiplomaTiles[] = INCBIN_U8("graphics/misc/diploma.4bpp.lz");
|
||||||
|
|
||||||
void CB2_ShowDiploma(void)
|
void CB2_ShowDiploma(void)
|
||||||
{
|
{
|
||||||
@ -76,15 +77,15 @@ void CB2_ShowDiploma(void)
|
|||||||
ResetSpriteData();
|
ResetSpriteData();
|
||||||
ResetPaletteFade();
|
ResetPaletteFade();
|
||||||
FreeAllSpritePalettes();
|
FreeAllSpritePalettes();
|
||||||
LoadPalette(gDiplomaPalettes, 0, 64);
|
LoadPalette(sDiplomaPalettes, 0, 64);
|
||||||
gDiplomaTilemapPtr = malloc(0x1000);
|
sDiplomaTilemapPtr = malloc(0x1000);
|
||||||
InitDiplomaBg();
|
InitDiplomaBg();
|
||||||
InitDiplomaWindow();
|
InitDiplomaWindow();
|
||||||
reset_temp_tile_data_buffers();
|
reset_temp_tile_data_buffers();
|
||||||
decompress_and_copy_tile_data_to_vram(1, &gDiplomaTiles, 0, 0, 0);
|
decompress_and_copy_tile_data_to_vram(1, &sDiplomaTiles, 0, 0, 0);
|
||||||
while (free_temp_tile_data_buffers_if_possible())
|
while (free_temp_tile_data_buffers_if_possible())
|
||||||
;
|
;
|
||||||
LZDecompressWram(&gDiplomaTilemap, gDiplomaTilemapPtr);
|
LZDecompressWram(&sDiplomaTilemap, sDiplomaTilemapPtr);
|
||||||
CopyBgTilemapBufferToVram(1);
|
CopyBgTilemapBufferToVram(1);
|
||||||
DisplayDiplomaText();
|
DisplayDiplomaText();
|
||||||
BlendPalettes(-1, 16, 0);
|
BlendPalettes(-1, 16, 0);
|
||||||
@ -122,7 +123,7 @@ static void Task_DiplomaFadeOut(u8 taskId)
|
|||||||
{
|
{
|
||||||
if (!gPaletteFade.active)
|
if (!gPaletteFade.active)
|
||||||
{
|
{
|
||||||
Free(gDiplomaTilemapPtr);
|
Free(sDiplomaTilemapPtr);
|
||||||
FreeAllWindowBuffers();
|
FreeAllWindowBuffers();
|
||||||
DestroyTask(taskId);
|
DestroyTask(taskId);
|
||||||
SetMainCallback2(sub_80861E8);
|
SetMainCallback2(sub_80861E8);
|
||||||
@ -147,7 +148,7 @@ static void DisplayDiplomaText(void)
|
|||||||
CopyWindowToVram(0, 3);
|
CopyWindowToVram(0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct BgTemplate gDiplomaBgTemplates[2] =
|
static const struct BgTemplate sDiplomaBgTemplates[2] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
.bg = 0,
|
.bg = 0,
|
||||||
@ -172,8 +173,8 @@ static const struct BgTemplate gDiplomaBgTemplates[2] =
|
|||||||
static void InitDiplomaBg(void)
|
static void InitDiplomaBg(void)
|
||||||
{
|
{
|
||||||
ResetBgsAndClearDma3BusyFlags(0);
|
ResetBgsAndClearDma3BusyFlags(0);
|
||||||
InitBgsFromTemplates(0, gDiplomaBgTemplates, 2);
|
InitBgsFromTemplates(0, sDiplomaBgTemplates, 2);
|
||||||
SetBgTilemapBuffer(1, gDiplomaTilemapPtr);
|
SetBgTilemapBuffer(1, sDiplomaTilemapPtr);
|
||||||
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
|
||||||
ShowBg(0);
|
ShowBg(0);
|
||||||
ShowBg(1);
|
ShowBg(1);
|
||||||
@ -182,7 +183,7 @@ static void InitDiplomaBg(void)
|
|||||||
SetGpuReg(REG_OFFSET_BLDY, DISPCNT_MODE_0);
|
SetGpuReg(REG_OFFSET_BLDY, DISPCNT_MODE_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct WindowTemplate gDiplomaWinTemplates[2] =
|
static const struct WindowTemplate sDiplomaWinTemplates[2] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
.priority = 0,
|
.priority = 0,
|
||||||
@ -198,7 +199,7 @@ static const struct WindowTemplate gDiplomaWinTemplates[2] =
|
|||||||
|
|
||||||
static void InitDiplomaWindow(void)
|
static void InitDiplomaWindow(void)
|
||||||
{
|
{
|
||||||
InitWindows(gDiplomaWinTemplates);
|
InitWindows(sDiplomaWinTemplates);
|
||||||
DeactivateAllTextPrinters();
|
DeactivateAllTextPrinters();
|
||||||
LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
|
LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
|
||||||
FillWindowPixelBuffer(0, 0);
|
FillWindowPixelBuffer(0, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user