summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm/code_807C4A0.s606
-rw-r--r--asm/code_807C648.s514
-rw-r--r--include/dungeon_ai_attack_1.h4
-rw-r--r--include/dungeon_ai_attack_2.h9
-rw-r--r--include/moves.h2
-rw-r--r--include/targeting_flags.h2
-rwxr-xr-xld_script.txt2
-rw-r--r--src/dungeon_ai_attack.c20
-rw-r--r--src/dungeon_ai_attack_1.c194
-rw-r--r--src/dungeon_ai_attack_2.c76
-rw-r--r--src/dungeon_ai_items.c10
-rw-r--r--src/moves.c2
-rw-r--r--src/targeting_flags.c2
-rw-r--r--sym_ewram.txt4
14 files changed, 755 insertions, 692 deletions
diff --git a/asm/code_807C4A0.s b/asm/code_807C4A0.s
index 865f009..9cbdbb5 100644
--- a/asm/code_807C4A0.s
+++ b/asm/code_807C4A0.s
@@ -133,610 +133,4 @@ _0807C57A:
bx r1
thumb_func_end IsTargetInLineRange
- thumb_func_start WeightMoveIfUsable
-WeightMoveIfUsable:
- push {r4-r7,lr}
- mov r7, r10
- mov r6, r9
- mov r5, r8
- push {r5-r7}
- sub sp, 0x4
- adds r6, r0, 0
- adds r5, r2, 0
- adds r7, r3, 0
- ldr r0, [sp, 0x28]
- lsls r1, 16
- asrs r1, 16
- mov r9, r1
- lsls r0, 24
- lsrs r0, 24
- mov r10, r0
- ldr r2, [r5, 0x70]
- ldr r1, [r5, 0x4]
- ldr r0, [r7, 0x4]
- cmp r1, r0
- beq _0807C5BC
- movs r0, 0xF0
- mov r1, r9
- ands r0, r1
- cmp r0, 0x30
- beq _0807C5BC
- cmp r0, 0x60
- beq _0807C5BC
- cmp r0, 0x70
- bne _0807C5C4
-_0807C5BC:
- adds r0, r2, 0
- adds r0, 0x46
- ldrb r4, [r0]
- b _0807C5CE
-_0807C5C4:
- adds r0, r5, 0x4
- adds r1, r7, 0x4
- bl CalculateFacingDir
- adds r4, r0, 0
-_0807C5CE:
- ldr r0, _0807C638
- adds r0, r4
- mov r8, r0
- ldrb r0, [r0]
- cmp r0, 0
- bne _0807C624
- mov r0, r10
- str r0, [sp]
- mov r0, r9
- adds r1, r5, 0
- adds r2, r7, 0
- ldr r3, [sp, 0x24]
- bl CanUseStatusMove
- lsls r0, 24
- cmp r0, 0
- beq _0807C624
- movs r0, 0x1
- mov r1, r8
- strb r0, [r1]
- ldr r0, _0807C63C
- adds r0, r6, r0
- strb r4, [r0]
- adds r0, r5, 0
- ldr r1, [sp, 0x24]
- bl GetMoveTypeForPokemon
- adds r3, r0, 0
- lsls r3, 24
- lsrs r3, 24
- adds r0, r5, 0
- mov r1, r9
- adds r2, r7, 0
- bl WeightMove
- ldr r1, _0807C640
- lsls r2, r6, 2
- adds r1, r2, r1
- str r0, [r1]
- ldr r0, _0807C644
- adds r2, r0
- str r7, [r2]
- adds r6, 0x1
-_0807C624:
- adds r0, r6, 0
- add sp, 0x4
- pop {r3-r5}
- mov r8, r3
- mov r9, r4
- mov r10, r5
- pop {r4-r7}
- pop {r1}
- bx r1
- .align 2, 0
-_0807C638: .4byte gCanAttackInDirection
-_0807C63C: .4byte gPotentialAttackTargetDirections
-_0807C640: .4byte gPotentialTargetWeights_2
-_0807C644: .4byte gPotentialTargets
- thumb_func_end WeightMoveIfUsable
-
- thumb_func_start CanUseStatusMove
-CanUseStatusMove:
- push {r4-r7,lr}
- mov r7, r9
- mov r6, r8
- push {r6,r7}
- adds r5, r1, 0
- adds r4, r2, 0
- mov r8, r3
- ldr r1, [sp, 0x1C]
- lsls r0, 16
- asrs r6, r0, 16
- lsls r1, 24
- lsrs r1, 24
- mov r9, r1
- movs r7, 0
- movs r0, 0xF
- ands r0, r6
- adds r1, r0, 0
- cmp r1, 0
- bne _0807C686
- adds r0, r5, 0
- adds r1, r4, 0
- movs r2, 0
- movs r3, 0x1
- bl CanTarget
- lsls r0, 24
- lsrs r0, 24
- cmp r0, 0x1
- bne _0807C6E0
- movs r7, 0x1
- b _0807C6E4
-_0807C686:
- cmp r1, 0x1
- beq _0807C6BE
- cmp r1, 0x2
- bne _0807C692
- ldr r1, [r4, 0x70]
- b _0807C69C
-_0807C692:
- cmp r1, 0x5
- bne _0807C6B6
- ldr r1, [r4, 0x70]
- cmp r5, r4
- beq _0807C6B2
-_0807C69C:
- movs r7, 0x1
- ldrb r0, [r1, 0x8]
- cmp r0, 0x1
- beq _0807C6B2
- adds r0, r1, 0
- adds r0, 0xA4
- ldrb r0, [r0]
- cmp r0, 0x4
- beq _0807C6B2
- cmp r0, 0x1
- bne _0807C6E0
-_0807C6B2:
- movs r0, 0
- b _0807C7A0
-_0807C6B6:
- cmp r1, 0x6
- bne _0807C6D4
- cmp r5, r4
- beq _0807C6B2
-_0807C6BE:
- adds r0, r5, 0
- adds r1, r4, 0
- movs r2, 0
- movs r3, 0x1
- bl CanTarget
- lsls r0, 24
- cmp r0, 0
- bne _0807C6E0
- movs r7, 0x1
- b _0807C6E4
-_0807C6D4:
- subs r0, 0x3
- lsls r0, 16
- lsrs r0, 16
- cmp r0, 0x1
- bhi _0807C6E0
- movs r7, 0x1
-_0807C6E0:
- cmp r7, 0
- beq _0807C79E
-_0807C6E4:
- mov r0, r9
- cmp r0, 0
- beq _0807C77C
- adds r0, r5, 0
- adds r1, r4, 0
- mov r2, r8
- bl CanUseOnTargetWithStatusChecker
- lsls r0, 24
- cmp r0, 0
- beq _0807C6B2
- movs r1, 0xF0
- lsls r1, 4
- ands r1, r6
- movs r0, 0x80
- lsls r0, 1
- cmp r1, r0
- beq _0807C78A
- movs r0, 0x80
- lsls r0, 2
- cmp r1, r0
- beq _0807C76E
- movs r0, 0xC0
- lsls r0, 2
- cmp r1, r0
- bne _0807C720
- adds r0, r4, 0
- bl HasNegativeStatus
- b _0807C774
-_0807C720:
- movs r0, 0x80
- lsls r0, 3
- cmp r1, r0
- bne _0807C730
- adds r0, r4, 0
- bl IsSleeping
- b _0807C774
-_0807C730:
- movs r0, 0xC0
- lsls r0, 3
- cmp r1, r0
- bne _0807C75A
- ldr r1, [r4, 0x70]
- adds r0, r1, 0
- adds r0, 0x5C
- ldrb r0, [r0]
- cmp r0, 0xE
- beq _0807C74E
- adds r0, r1, 0
- adds r0, 0x5D
- ldrb r0, [r0]
- cmp r0, 0xE
- bne _0807C6B2
-_0807C74E:
- adds r0, r1, 0
- adds r0, 0xF5
- ldrb r0, [r0]
- cmp r0, 0
- beq _0807C79E
- b _0807C6B2
-_0807C75A:
- movs r0, 0xA0
- lsls r0, 3
- cmp r1, r0
- bne _0807C79E
- adds r0, r4, 0
- bl HasNegativeStatus
- lsls r0, 24
- cmp r0, 0
- bne _0807C79E
-_0807C76E:
- adds r0, r4, 0
- bl HasQuarterHPOrLess
-_0807C774:
- lsls r0, 24
- cmp r0, 0
- bne _0807C79E
- b _0807C6B2
-_0807C77C:
- movs r0, 0xF0
- lsls r0, 4
- ands r0, r6
- movs r1, 0x80
- lsls r1, 1
- cmp r0, r1
- bne _0807C79E
-_0807C78A:
- mov r0, r8
- movs r1, 0x2
- bl GetMoveAccuracy
- adds r4, r0, 0
- movs r0, 0x64
- bl DungeonRandomCapped
- cmp r0, r4
- bge _0807C6B2
-_0807C79E:
- adds r0, r7, 0
-_0807C7A0:
- pop {r3,r4}
- mov r8, r3
- mov r9, r4
- pop {r4-r7}
- pop {r1}
- bx r1
- thumb_func_end CanUseStatusMove
-
- thumb_func_start WeightMove
-WeightMove:
- push {r4-r7,lr}
- mov r7, r9
- mov r6, r8
- push {r6,r7}
- adds r5, r0, 0
- mov r8, r2
- lsls r1, 16
- asrs r1, 16
- lsls r3, 24
- lsrs r3, 24
- mov r9, r3
- movs r6, 0x1
- ldr r4, [r2, 0x70]
- adds r7, r4, 0
- ldrb r0, [r4, 0x6]
- cmp r0, 0
- beq _0807C7D6
- movs r0, 0xF
- ands r0, r1
- cmp r0, 0
- beq _0807C7DA
-_0807C7D6:
- movs r0, 0x1
- b _0807C848
-_0807C7DA:
- adds r0, r5, 0
- movs r1, 0x9
- bl HasIQSkill
- lsls r0, 24
- cmp r0, 0
- beq _0807C804
- ldr r0, _0807C7FC
- ldr r0, [r0]
- movs r2, 0x2
- ldrsh r1, [r4, r2]
- ldr r2, _0807C800
- adds r0, r2
- adds r0, r1
- ldrb r6, [r0]
- b _0807C846
- .align 2, 0
-_0807C7FC: .4byte gDungeonGlobalData
-_0807C800: .4byte 0x0000363c
-_0807C804:
- adds r0, r5, 0
- movs r1, 0xA
- bl HasIQSkill
- lsls r0, 24
- cmp r0, 0
- beq _0807C828
- ldrb r1, [r7, 0xE]
- movs r2, 0xC
- negs r2, r2
- adds r0, r2, 0
- subs r0, r1
- lsls r0, 24
- lsrs r6, r0, 24
- cmp r6, 0
- bne _0807C846
- movs r6, 0x1
- b _0807C846
-_0807C828:
- adds r0, r5, 0
- movs r1, 0xB
- bl HasIQSkill
- lsls r0, 24
- cmp r0, 0
- beq _0807C846
- adds r0, r5, 0
- mov r1, r8
- mov r2, r9
- bl WeightWeakTypePicker
- adds r0, 0x1
- lsls r0, 24
- lsrs r6, r0, 24
-_0807C846:
- adds r0, r6, 0
-_0807C848:
- pop {r3,r4}
- mov r8, r3
- mov r9, r4
- pop {r4-r7}
- pop {r1}
- bx r1
- thumb_func_end WeightMove
-
- thumb_func_start TargetRegularAttack
-TargetRegularAttack:
- push {r4-r7,lr}
- mov r7, r10
- mov r6, r9
- mov r5, r8
- push {r5-r7}
- sub sp, 0x50
- adds r7, r0, 0
- str r1, [sp, 0x40]
- lsls r2, 24
- lsrs r2, 24
- str r2, [sp, 0x44]
- ldr r0, [r7, 0x70]
- movs r1, 0
- mov r8, r1
- adds r1, r0, 0
- adds r1, 0x46
- ldrb r6, [r1]
- adds r0, 0xE8
- ldrb r0, [r0]
- movs r3, 0x8
- mov r10, r3
- cmp r0, 0x1
- bne _0807C886
- movs r0, 0x1
- mov r10, r0
-_0807C886:
- movs r4, 0
- adds r0, r7, 0
- movs r1, 0x9
- bl HasIQSkill
- lsls r0, 24
- cmp r0, 0
- bne _0807C8A4
- adds r0, r7, 0
- movs r1, 0xA
- bl HasIQSkill
- lsls r0, 24
- cmp r0, 0
- beq _0807C8A6
-_0807C8A4:
- movs r4, 0x1
-_0807C8A6:
- str r4, [sp, 0x48]
- adds r0, r7, 0
- movs r1, 0x8
- bl HasIQSkill
- lsls r0, 24
- lsrs r0, 24
- str r0, [sp, 0x4C]
- movs r1, 0
- mov r9, r1
- cmp r9, r10
- bge _0807C952
-_0807C8BE:
- movs r0, 0x7
- ands r6, r0
- movs r3, 0x4
- ldrsh r0, [r7, r3]
- ldr r1, _0807C95C
- lsls r2, r6, 2
- adds r2, r1
- movs r3, 0
- ldrsh r1, [r2, r3]
- adds r0, r1
- movs r3, 0x6
- ldrsh r1, [r7, r3]
- movs r3, 0x2
- ldrsh r2, [r2, r3]
- adds r1, r2
- bl GetMapTile_1
- ldr r5, [r0, 0x10]
- cmp r5, 0
- beq _0807C948
- adds r0, r5, 0
- bl GetEntityType
- cmp r0, 0x1
- bne _0807C948
- adds r0, r7, 0
- adds r1, r6, 0
- bl CanAttackInFront
- lsls r0, 24
- cmp r0, 0
- beq _0807C948
- adds r0, r7, 0
- adds r1, r5, 0
- movs r2, 0
- ldr r3, [sp, 0x44]
- bl CanTarget
- lsls r0, 24
- lsrs r0, 24
- cmp r0, 0x1
- bne _0807C948
- ldr r0, [sp, 0x4C]
- cmp r0, 0
- beq _0807C922
- ldr r0, [r5, 0x70]
- adds r0, 0xB0
- ldrb r0, [r0]
- cmp r0, 0x1
- beq _0807C948
-_0807C922:
- mov r1, r8
- lsls r4, r1, 2
- mov r3, sp
- adds r0, r3, r4
- str r6, [r0]
- adds r0, r7, 0
- movs r1, 0
- adds r2, r5, 0
- movs r3, 0
- bl WeightMove
- add r1, sp, 0x20
- adds r1, r4
- str r0, [r1]
- ldr r0, [sp, 0x48]
- cmp r0, 0
- beq _0807C960
- movs r1, 0x1
- add r8, r1
-_0807C948:
- movs r3, 0x1
- add r9, r3
- adds r6, 0x1
- cmp r9, r10
- blt _0807C8BE
-_0807C952:
- mov r0, r8
- cmp r0, 0
- bne _0807C966
- movs r0, 0
- b _0807C9E8
- .align 2, 0
-_0807C95C: .4byte gAdjacentTileOffsets
-_0807C960:
- ldr r1, [sp, 0x40]
- str r6, [r1]
- b _0807C9E6
-_0807C966:
- movs r4, 0
- movs r3, 0
- mov r0, r8
- cmp r0, 0
- ble _0807C984
- add r1, sp, 0x20
- mov r2, r8
-_0807C974:
- ldr r0, [r1]
- cmp r3, r0
- bge _0807C97C
- adds r3, r0, 0
-_0807C97C:
- adds r1, 0x4
- subs r2, 0x1
- cmp r2, 0
- bne _0807C974
-_0807C984:
- mov r1, r8
- cmp r1, 0
- ble _0807C9A0
- movs r5, 0
- add r1, sp, 0x20
- mov r2, r8
-_0807C990:
- ldr r0, [r1]
- cmp r3, r0
- beq _0807C998
- str r5, [r1]
-_0807C998:
- adds r1, 0x4
- subs r2, 0x1
- cmp r2, 0
- bne _0807C990
-_0807C9A0:
- mov r3, r8
- cmp r3, 0
- ble _0807C9B4
- add r1, sp, 0x20
- mov r2, r8
-_0807C9AA:
- ldm r1!, {r0}
- adds r4, r0
- subs r2, 0x1
- cmp r2, 0
- bne _0807C9AA
-_0807C9B4:
- adds r0, r4, 0
- bl DungeonRandomCapped
- adds r1, r0, 0
- movs r2, 0
- cmp r2, r8
- bge _0807C9DC
- ldr r0, [sp, 0x20]
- subs r1, r0
- cmp r1, 0
- blt _0807C9DC
- add r3, sp, 0x20
-_0807C9CC:
- adds r3, 0x4
- adds r2, 0x1
- cmp r2, r8
- bge _0807C9DC
- ldr r0, [r3]
- subs r1, r0
- cmp r1, 0
- bge _0807C9CC
-_0807C9DC:
- lsls r0, r2, 2
- add r0, sp
- ldr r0, [r0]
- ldr r1, [sp, 0x40]
- str r0, [r1]
-_0807C9E6:
- movs r0, 0x1
-_0807C9E8:
- add sp, 0x50
- pop {r3-r5}
- mov r8, r3
- mov r9, r4
- mov r10, r5
- pop {r4-r7}
- pop {r1}
- bx r1
- thumb_func_end TargetRegularAttack
-
.align 2, 0 \ No newline at end of file
diff --git a/asm/code_807C648.s b/asm/code_807C648.s
new file mode 100644
index 0000000..d94a155
--- /dev/null
+++ b/asm/code_807C648.s
@@ -0,0 +1,514 @@
+ #include "asm/constants/gba_constants.inc"
+ #include "asm/macros.inc"
+
+ .syntax unified
+
+ .text
+
+ thumb_func_start CanUseStatusMove
+CanUseStatusMove:
+ push {r4-r7,lr}
+ mov r7, r9
+ mov r6, r8
+ push {r6,r7}
+ adds r5, r1, 0
+ adds r4, r2, 0
+ mov r8, r3
+ ldr r1, [sp, 0x1C]
+ lsls r0, 16
+ asrs r6, r0, 16
+ lsls r1, 24
+ lsrs r1, 24
+ mov r9, r1
+ movs r7, 0
+ movs r0, 0xF
+ ands r0, r6
+ adds r1, r0, 0
+ cmp r1, 0
+ bne _0807C686
+ adds r0, r5, 0
+ adds r1, r4, 0
+ movs r2, 0
+ movs r3, 0x1
+ bl CanTarget
+ lsls r0, 24
+ lsrs r0, 24
+ cmp r0, 0x1
+ bne _0807C6E0
+ movs r7, 0x1
+ b _0807C6E4
+_0807C686:
+ cmp r1, 0x1
+ beq _0807C6BE
+ cmp r1, 0x2
+ bne _0807C692
+ ldr r1, [r4, 0x70]
+ b _0807C69C
+_0807C692:
+ cmp r1, 0x5
+ bne _0807C6B6
+ ldr r1, [r4, 0x70]
+ cmp r5, r4
+ beq _0807C6B2
+_0807C69C:
+ movs r7, 0x1
+ ldrb r0, [r1, 0x8]
+ cmp r0, 0x1
+ beq _0807C6B2
+ adds r0, r1, 0
+ adds r0, 0xA4
+ ldrb r0, [r0]
+ cmp r0, 0x4
+ beq _0807C6B2
+ cmp r0, 0x1
+ bne _0807C6E0
+_0807C6B2:
+ movs r0, 0
+ b _0807C7A0
+_0807C6B6:
+ cmp r1, 0x6
+ bne _0807C6D4
+ cmp r5, r4
+ beq _0807C6B2
+_0807C6BE:
+ adds r0, r5, 0
+ adds r1, r4, 0
+ movs r2, 0
+ movs r3, 0x1
+ bl CanTarget
+ lsls r0, 24
+ cmp r0, 0
+ bne _0807C6E0
+ movs r7, 0x1
+ b _0807C6E4
+_0807C6D4:
+ subs r0, 0x3
+ lsls r0, 16
+ lsrs r0, 16
+ cmp r0, 0x1
+ bhi _0807C6E0
+ movs r7, 0x1
+_0807C6E0:
+ cmp r7, 0
+ beq _0807C79E
+_0807C6E4:
+ mov r0, r9
+ cmp r0, 0
+ beq _0807C77C
+ adds r0, r5, 0
+ adds r1, r4, 0
+ mov r2, r8
+ bl CanUseOnTargetWithStatusChecker
+ lsls r0, 24
+ cmp r0, 0
+ beq _0807C6B2
+ movs r1, 0xF0
+ lsls r1, 4
+ ands r1, r6
+ movs r0, 0x80
+ lsls r0, 1
+ cmp r1, r0
+ beq _0807C78A
+ movs r0, 0x80
+ lsls r0, 2
+ cmp r1, r0
+ beq _0807C76E
+ movs r0, 0xC0
+ lsls r0, 2
+ cmp r1, r0
+ bne _0807C720
+ adds r0, r4, 0
+ bl HasNegativeStatus
+ b _0807C774
+_0807C720:
+ movs r0, 0x80
+ lsls r0, 3
+ cmp r1, r0
+ bne _0807C730
+ adds r0, r4, 0
+ bl IsSleeping
+ b _0807C774
+_0807C730:
+ movs r0, 0xC0
+ lsls r0, 3
+ cmp r1, r0
+ bne _0807C75A
+ ldr r1, [r4, 0x70]
+ adds r0, r1, 0
+ adds r0, 0x5C
+ ldrb r0, [r0]
+ cmp r0, 0xE
+ beq _0807C74E
+ adds r0, r1, 0
+ adds r0, 0x5D
+ ldrb r0, [r0]
+ cmp r0, 0xE
+ bne _0807C6B2
+_0807C74E:
+ adds r0, r1, 0
+ adds r0, 0xF5
+ ldrb r0, [r0]
+ cmp r0, 0
+ beq _0807C79E
+ b _0807C6B2
+_0807C75A:
+ movs r0, 0xA0
+ lsls r0, 3
+ cmp r1, r0
+ bne _0807C79E
+ adds r0, r4, 0
+ bl HasNegativeStatus
+ lsls r0, 24
+ cmp r0, 0
+ bne _0807C79E
+_0807C76E:
+ adds r0, r4, 0
+ bl HasQuarterHPOrLess
+_0807C774:
+ lsls r0, 24
+ cmp r0, 0
+ bne _0807C79E
+ b _0807C6B2
+_0807C77C:
+ movs r0, 0xF0
+ lsls r0, 4
+ ands r0, r6
+ movs r1, 0x80
+ lsls r1, 1
+ cmp r0, r1
+ bne _0807C79E
+_0807C78A:
+ mov r0, r8
+ movs r1, 0x2
+ bl GetMoveAccuracy
+ adds r4, r0, 0
+ movs r0, 0x64
+ bl DungeonRandomCapped
+ cmp r0, r4
+ bge _0807C6B2
+_0807C79E:
+ adds r0, r7, 0
+_0807C7A0:
+ pop {r3,r4}
+ mov r8, r3
+ mov r9, r4
+ pop {r4-r7}
+ pop {r1}
+ bx r1
+ thumb_func_end CanUseStatusMove
+
+ thumb_func_start WeightMove
+WeightMove:
+ push {r4-r7,lr}
+ mov r7, r9
+ mov r6, r8
+ push {r6,r7}
+ adds r5, r0, 0
+ mov r8, r2
+ lsls r1, 16
+ asrs r1, 16
+ lsls r3, 24
+ lsrs r3, 24
+ mov r9, r3
+ movs r6, 0x1
+ ldr r4, [r2, 0x70]
+ adds r7, r4, 0
+ ldrb r0, [r4, 0x6]
+ cmp r0, 0
+ beq _0807C7D6
+ movs r0, 0xF
+ ands r0, r1
+ cmp r0, 0
+ beq _0807C7DA
+_0807C7D6:
+ movs r0, 0x1
+ b _0807C848
+_0807C7DA:
+ adds r0, r5, 0
+ movs r1, 0x9
+ bl HasIQSkill
+ lsls r0, 24
+ cmp r0, 0
+ beq _0807C804
+ ldr r0, _0807C7FC
+ ldr r0, [r0]
+ movs r2, 0x2
+ ldrsh r1, [r4, r2]
+ ldr r2, _0807C800
+ adds r0, r2
+ adds r0, r1
+ ldrb r6, [r0]
+ b _0807C846
+ .align 2, 0
+_0807C7FC: .4byte gDungeonGlobalData
+_0807C800: .4byte 0x0000363c
+_0807C804:
+ adds r0, r5, 0
+ movs r1, 0xA
+ bl HasIQSkill
+ lsls r0, 24
+ cmp r0, 0
+ beq _0807C828
+ ldrb r1, [r7, 0xE]
+ movs r2, 0xC
+ negs r2, r2
+ adds r0, r2, 0
+ subs r0, r1
+ lsls r0, 24
+ lsrs r6, r0, 24
+ cmp r6, 0
+ bne _0807C846
+ movs r6, 0x1
+ b _0807C846
+_0807C828:
+ adds r0, r5, 0
+ movs r1, 0xB
+ bl HasIQSkill
+ lsls r0, 24
+ cmp r0, 0
+ beq _0807C846
+ adds r0, r5, 0
+ mov r1, r8
+ mov r2, r9
+ bl WeightWeakTypePicker
+ adds r0, 0x1
+ lsls r0, 24
+ lsrs r6, r0, 24
+_0807C846:
+ adds r0, r6, 0
+_0807C848:
+ pop {r3,r4}
+ mov r8, r3
+ mov r9, r4
+ pop {r4-r7}
+ pop {r1}
+ bx r1
+ thumb_func_end WeightMove
+
+ thumb_func_start TargetRegularAttack
+TargetRegularAttack:
+ push {r4-r7,lr}
+ mov r7, r10
+ mov r6, r9
+ mov r5, r8
+ push {r5-r7}
+ sub sp, 0x50
+ adds r7, r0, 0
+ str r1, [sp, 0x40]
+ lsls r2, 24
+ lsrs r2, 24
+ str r2, [sp, 0x44]
+ ldr r0, [r7, 0x70]
+ movs r1, 0
+ mov r8, r1
+ adds r1, r0, 0
+ adds r1, 0x46
+ ldrb r6, [r1]
+ adds r0, 0xE8
+ ldrb r0, [r0]
+ movs r3, 0x8
+ mov r10, r3
+ cmp r0, 0x1
+ bne _0807C886
+ movs r0, 0x1
+ mov r10, r0
+_0807C886:
+ movs r4, 0
+ adds r0, r7, 0
+ movs r1, 0x9
+ bl HasIQSkill
+ lsls r0, 24
+ cmp r0, 0
+ bne _0807C8A4
+ adds r0, r7, 0
+ movs r1, 0xA
+ bl HasIQSkill
+ lsls r0, 24
+ cmp r0, 0
+ beq _0807C8A6
+_0807C8A4:
+ movs r4, 0x1
+_0807C8A6:
+ str r4, [sp, 0x48]
+ adds r0, r7, 0
+ movs r1, 0x8
+ bl HasIQSkill
+ lsls r0, 24
+ lsrs r0, 24
+ str r0, [sp, 0x4C]
+ movs r1, 0
+ mov r9, r1
+ cmp r9, r10
+ bge _0807C952
+_0807C8BE:
+ movs r0, 0x7
+ ands r6, r0
+ movs r3, 0x4
+ ldrsh r0, [r7, r3]
+ ldr r1, _0807C95C
+ lsls r2, r6, 2
+ adds r2, r1
+ movs r3, 0
+ ldrsh r1, [r2, r3]
+ adds r0, r1
+ movs r3, 0x6
+ ldrsh r1, [r7, r3]
+ movs r3, 0x2
+ ldrsh r2, [r2, r3]
+ adds r1, r2
+ bl GetMapTile_1
+ ldr r5, [r0, 0x10]
+ cmp r5, 0
+ beq _0807C948
+ adds r0, r5, 0
+ bl GetEntityType
+ cmp r0, 0x1
+ bne _0807C948
+ adds r0, r7, 0
+ adds r1, r6, 0
+ bl CanAttackInFront
+ lsls r0, 24
+ cmp r0, 0
+ beq _0807C948
+ adds r0, r7, 0
+ adds r1, r5, 0
+ movs r2, 0
+ ldr r3, [sp, 0x44]
+ bl CanTarget
+ lsls r0, 24
+ lsrs r0, 24
+ cmp r0, 0x1
+ bne _0807C948
+ ldr r0, [sp, 0x4C]
+ cmp r0, 0
+ beq _0807C922
+ ldr r0, [r5, 0x70]
+ adds r0, 0xB0
+ ldrb r0, [r0]
+ cmp r0, 0x1
+ beq _0807C948
+_0807C922:
+ mov r1, r8
+ lsls r4, r1, 2
+ mov r3, sp
+ adds r0, r3, r4
+ str r6, [r0]
+ adds r0, r7, 0
+ movs r1, 0
+ adds r2, r5, 0
+ movs r3, 0
+ bl WeightMove
+ add r1, sp, 0x20
+ adds r1, r4
+ str r0, [r1]
+ ldr r0, [sp, 0x48]
+ cmp r0, 0
+ beq _0807C960
+ movs r1, 0x1
+ add r8, r1
+_0807C948:
+ movs r3, 0x1
+ add r9, r3
+ adds r6, 0x1
+ cmp r9, r10
+ blt _0807C8BE
+_0807C952:
+ mov r0, r8
+ cmp r0, 0
+ bne _0807C966
+ movs r0, 0
+ b _0807C9E8
+ .align 2, 0
+_0807C95C: .4byte gAdjacentTileOffsets
+_0807C960:
+ ldr r1, [sp, 0x40]
+ str r6, [r1]
+ b _0807C9E6
+_0807C966:
+ movs r4, 0
+ movs r3, 0
+ mov r0, r8
+ cmp r0, 0
+ ble _0807C984
+ add r1, sp, 0x20
+ mov r2, r8
+_0807C974:
+ ldr r0, [r1]
+ cmp r3, r0
+ bge _0807C97C
+ adds r3, r0, 0
+_0807C97C:
+ adds r1, 0x4
+ subs r2, 0x1
+ cmp r2, 0
+ bne _0807C974
+_0807C984:
+ mov r1, r8
+ cmp r1, 0
+ ble _0807C9A0
+ movs r5, 0
+ add r1, sp, 0x20
+ mov r2, r8
+_0807C990:
+ ldr r0, [r1]
+ cmp r3, r0
+ beq _0807C998
+ str r5, [r1]
+_0807C998:
+ adds r1, 0x4
+ subs r2, 0x1
+ cmp r2, 0
+ bne _0807C990
+_0807C9A0:
+ mov r3, r8
+ cmp r3, 0
+ ble _0807C9B4
+ add r1, sp, 0x20
+ mov r2, r8
+_0807C9AA:
+ ldm r1!, {r0}
+ adds r4, r0
+ subs r2, 0x1
+ cmp r2, 0
+ bne _0807C9AA
+_0807C9B4:
+ adds r0, r4, 0
+ bl DungeonRandomCapped
+ adds r1, r0, 0
+ movs r2, 0
+ cmp r2, r8
+ bge _0807C9DC
+ ldr r0, [sp, 0x20]
+ subs r1, r0
+ cmp r1, 0
+ blt _0807C9DC
+ add r3, sp, 0x20
+_0807C9CC:
+ adds r3, 0x4
+ adds r2, 0x1
+ cmp r2, r8
+ bge _0807C9DC
+ ldr r0, [r3]
+ subs r1, r0
+ cmp r1, 0
+ bge _0807C9CC
+_0807C9DC:
+ lsls r0, r2, 2
+ add r0, sp
+ ldr r0, [r0]
+ ldr r1, [sp, 0x40]
+ str r0, [r1]
+_0807C9E6:
+ movs r0, 0x1
+_0807C9E8:
+ add sp, 0x50
+ pop {r3-r5}
+ mov r8, r3
+ mov r9, r4
+ mov r10, r5
+ pop {r4-r7}
+ pop {r1}
+ bx r1
+ thumb_func_end TargetRegularAttack
+
+ .align 2, 0 \ No newline at end of file
diff --git a/include/dungeon_ai_attack_1.h b/include/dungeon_ai_attack_1.h
index 89a1f0d..19969f2 100644
--- a/include/dungeon_ai_attack_1.h
+++ b/include/dungeon_ai_attack_1.h
@@ -3,7 +3,7 @@
#include "dungeon_entity.h"
-// 0x7C9F8
-bool8 IsTargetStraightAhead(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, s32 facingDir, s32 maxRange);
+// 0x7C580
+s32 WeightMoveIfUsable(s32 numPotentialTargets, s32 targetingFlags, struct DungeonEntity *user, struct DungeonEntity *target, struct PokemonMove *move, u32 hasStatusChecker);
#endif
diff --git a/include/dungeon_ai_attack_2.h b/include/dungeon_ai_attack_2.h
new file mode 100644
index 0000000..00711b6
--- /dev/null
+++ b/include/dungeon_ai_attack_2.h
@@ -0,0 +1,9 @@
+#ifndef GUARD_DUNGEON_AI_ATTACK_2_H
+#define GUARD_DUNGEON_AI_ATTACK_2_H
+
+#include "dungeon_entity.h"
+
+// 0x7C9F8
+bool8 IsTargetStraightAhead(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, s32 facingDir, s32 maxRange);
+
+#endif
diff --git a/include/moves.h b/include/moves.h
index 22f7ba6..ad68320 100644
--- a/include/moves.h
+++ b/include/moves.h
@@ -6,7 +6,7 @@
// 0x92A88
void InitPokemonMove(struct PokemonMove *move, u16 moveID);
// 0x92AE0
-s16 GetMoveTargetingFlags(struct PokemonMove *move, u32 isAI);
+s16 GetMoveTargetingFlags(struct PokemonMove *move, bool32 isAI);
u8 GetMoveType(struct PokemonMove *move);
// 0x92B90
u8 GetMoveWeight(struct PokemonMove *move);
diff --git a/include/targeting_flags.h b/include/targeting_flags.h
index 54e7063..d7d4737 100644
--- a/include/targeting_flags.h
+++ b/include/targeting_flags.h
@@ -5,6 +5,6 @@
#include "dungeon_entity.h"
// 0x7CD64
-s16 GetMoveTargetingFlagsForPokemon(struct DungeonEntity *pokemon, struct PokemonMove *move, u32 isAI);
+s16 GetMoveTargetingFlagsForPokemon(struct DungeonEntity *pokemon, struct PokemonMove *move, bool32 isAI);
#endif
diff --git a/ld_script.txt b/ld_script.txt
index 71a1ad7..b8111e3 100755
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -239,6 +239,8 @@ SECTIONS {
src/dungeon_ai_attack.o(.text);
asm/code_807C4A0.o(.text);
src/dungeon_ai_attack_1.o(.text);
+ asm/code_807C648.o(.text);
+ src/dungeon_ai_attack_2.o(.text);
asm/code_807CABC.o(.text);
src/targeting_flags.o(.text);
asm/code_807CD9C.o(.text);
diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c
index 7368e66..65973a1 100644
--- a/src/dungeon_ai_attack.c
+++ b/src/dungeon_ai_attack.c
@@ -13,6 +13,7 @@
#include "dungeon_ai_targeting.h"
#include "dungeon_ai_targeting_1.h"
#include "dungeon_ai_attack_1.h"
+#include "dungeon_ai_attack_2.h"
#include "dungeon_capabilities_1.h"
#include "dungeon_global_data.h"
#include "dungeon_map_access.h"
@@ -34,13 +35,12 @@ const s16 gRegularAttackWeights[] = {100, 20, 30, 40, 50};
extern bool8 gCanAttackInDirection[NUM_DIRECTIONS];
extern s32 gNumPotentialTargets;
-extern s32 gPotentialTargetWeights_2[NUM_DIRECTIONS];
+extern s32 gPotentialAttackTargetWeights[NUM_DIRECTIONS];
extern u8 gPotentialAttackTargetDirections[NUM_DIRECTIONS];
extern struct DungeonEntity *gPotentialTargets[NUM_DIRECTIONS];
extern bool8 IsMoveUsable_1(struct DungeonEntity*, s32, bool8);
extern bool8 TargetRegularAttack(struct DungeonEntity*, u32*, bool8);
-extern s32 WeightMoveIfUsable(s32, s32, struct DungeonEntity*, struct DungeonEntity*, struct PokemonMove*, bool8);
extern bool8 IsTargetInLineRange(struct DungeonEntity*, struct DungeonEntity*, s32);
extern bool8 CanUseStatusMove(s32, struct DungeonEntity*, struct DungeonEntity*, struct PokemonMove*, bool8);
extern s32 WeightMove(struct DungeonEntity*, s32, struct DungeonEntity*, u8);
@@ -366,7 +366,7 @@ s32 FindMoveTarget(struct MoveTargetResults *moveTargetResults, struct DungeonEn
{
gCanAttackInDirection[i] = TRUE;
gPotentialAttackTargetDirections[numPotentialTargets] = i;
- gPotentialTargetWeights_2[numPotentialTargets] = 99;
+ gPotentialAttackTargetWeights[numPotentialTargets] = 99;
gPotentialTargets[numPotentialTargets] = NULL;
numPotentialTargets++;
}
@@ -457,7 +457,7 @@ s32 FindMoveTarget(struct MoveTargetResults *moveTargetResults, struct DungeonEn
{
gCanAttackInDirection[facingDir] = TRUE;
gPotentialAttackTargetDirections[numPotentialTargets] = facingDir;
- gPotentialTargetWeights_2[numPotentialTargets] = WeightMove(pokemon, targetingFlags, target, GetMoveTypeForPokemon(pokemon, move));
+ gPotentialAttackTargetWeights[numPotentialTargets] = WeightMove(pokemon, targetingFlags, target, GetMoveTypeForPokemon(pokemon, move));
gPotentialTargets[numPotentialTargets] = target;
numPotentialTargets++;
}
@@ -492,27 +492,27 @@ s32 FindMoveTarget(struct MoveTargetResults *moveTargetResults, struct DungeonEn
s32 i;
for (i = 0; i < numPotentialTargets; i++)
{
- if (maxWeight < gPotentialTargetWeights_2[i])
+ if (maxWeight < gPotentialAttackTargetWeights[i])
{
- maxWeight = gPotentialTargetWeights_2[i];
+ maxWeight = gPotentialAttackTargetWeights[i];
}
}
for (i = 0; i < numPotentialTargets; i++)
{
- if (maxWeight != gPotentialTargetWeights_2[i])
+ if (maxWeight != gPotentialAttackTargetWeights[i])
{
- gPotentialTargetWeights_2[i] = 0;
+ gPotentialAttackTargetWeights[i] = 0;
}
}
moveWeight = maxWeight;
for (i = 0; i < numPotentialTargets; i++)
{
- totalWeight += gPotentialTargetWeights_2[i];
+ totalWeight += gPotentialAttackTargetWeights[i];
}
weightCounter = DungeonRandomCapped(totalWeight);
for (i = 0; i < numPotentialTargets; i++)
{
- weightCounter -= gPotentialTargetWeights_2[i];
+ weightCounter -= gPotentialAttackTargetWeights[i];
if (weightCounter < 0)
{
break;
diff --git a/src/dungeon_ai_attack_1.c b/src/dungeon_ai_attack_1.c
index 641bc8c..fb088fb 100644
--- a/src/dungeon_ai_attack_1.c
+++ b/src/dungeon_ai_attack_1.c
@@ -1,76 +1,144 @@
#include "global.h"
#include "dungeon_ai_attack_1.h"
-#include "constants/iq_skill.h"
-#include "dungeon_global_data.h"
-#include "dungeon_map_access.h"
+#include "constants/direction.h"
#include "dungeon_pokemon_attributes.h"
-#include "dungeon_util.h"
+#include "position_util.h"
-bool8 IsTargetStraightAhead(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, s32 facingDir, s32 maxRange)
+extern bool8 gCanAttackInDirection[NUM_DIRECTIONS];
+extern s32 gPotentialAttackTargetWeights[NUM_DIRECTIONS];
+extern u8 gPotentialAttackTargetDirections[NUM_DIRECTIONS];
+extern struct DungeonEntity *gPotentialTargets[NUM_DIRECTIONS];
+
+extern bool8 CanUseStatusMove(s32, struct DungeonEntity*, struct DungeonEntity*, struct PokemonMove*, bool8);
+extern s32 WeightMove(struct DungeonEntity*, s32, struct DungeonEntity*, u8);
+
+s32 WeightMoveIfUsable(s32 numPotentialTargets, s32 targetingFlags, struct DungeonEntity *user, struct DungeonEntity *target, struct PokemonMove *move, bool32 hasStatusChecker)
{
- s32 posDiffX = pokemon->posWorld.x - targetPokemon->posWorld.x;
- s32 effectiveMaxRange;
- if (posDiffX < 0)
- {
- posDiffX = -posDiffX;
- }
- effectiveMaxRange = pokemon->posWorld.y - targetPokemon->posWorld.y;
- if (effectiveMaxRange < 0)
- {
- effectiveMaxRange = -effectiveMaxRange;
- }
- if (effectiveMaxRange < posDiffX)
+ s32 facingDir;
+ s32 targetingFlags2 = (s16) targetingFlags;
+ bool8 hasStatusChecker2 = hasStatusChecker;
+ struct DungeonEntityData *userData = user->entityData;
+ if ((user->posWorld.x == target->posWorld.x && user->posWorld.y == target->posWorld.y) ||
+ (targetingFlags2 & 0xF0) == TARGETING_FLAG_TARGET_ROOM ||
+ (targetingFlags2 & 0xF0) == TARGETING_FLAG_TARGET_FLOOR ||
+ (targetingFlags2 & 0xF0) == TARGETING_FLAG_TARGET_SELF)
{
- effectiveMaxRange = posDiffX;
+ facingDir = userData->action.facingDir;
}
- if (effectiveMaxRange > maxRange)
+ else
{
- effectiveMaxRange = maxRange;
+ facingDir = CalculateFacingDir(&user->posWorld, &target->posWorld);
}
- if (!HasIQSkill(pokemon, IQ_SKILL_COURSE_CHECKER))
+ if (!gCanAttackInDirection[facingDir] &&
+ CanUseStatusMove(targetingFlags2, user, target, move, hasStatusChecker2))
{
- // BUG: effectiveMaxRange is already capped at maxRange, so this condition always evaluates to TRUE.
- // The AI also has range checks elsewhere, so this doesn't become an issue in most cases.
- // If the AI has the Long Toss or Pierce statuses and Course Checker is disabled,
- // this incorrect check causes the AI to throw items at targets further than 10 tiles away.
- if (effectiveMaxRange <= maxRange)
- {
- return TRUE;
- }
+ gCanAttackInDirection[facingDir] = TRUE;
+ do { gPotentialAttackTargetDirections[numPotentialTargets] = facingDir; } while (0);
+ gPotentialAttackTargetWeights[numPotentialTargets] = WeightMove(user, targetingFlags2, target, GetMoveTypeForPokemon(user, move));
+ gPotentialTargets[numPotentialTargets] = target;
+ numPotentialTargets++;
}
- else
- {
- s32 currentPosX = pokemon->posWorld.x;
- s32 currentPosY = pokemon->posWorld.y;
- s32 adjacentTileOffsetX = gAdjacentTileOffsets[facingDir].x;
- s32 adjacentTileOffsetY = gAdjacentTileOffsets[facingDir].y;
- s32 i;
- for (i = 0; i <= effectiveMaxRange; i++)
- {
- struct MapTile *mapTile;
- currentPosX += adjacentTileOffsetX;
- currentPosY += adjacentTileOffsetY;
- if (currentPosX <= 0 || currentPosY <= 0 ||
- currentPosX >= DUNGEON_MAX_SIZE_X - 1 || currentPosY >= DUNGEON_MAX_SIZE_Y - 1)
- {
- break;
- }
- while (0); // Extra label needed to swap branch locations in ASM.
- mapTile = GetMapTile_1(currentPosX, currentPosY);
- if (!(mapTile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_LIQUID)))
- {
- break;
- }
- if (mapTile->pokemon == targetPokemon)
- {
- return TRUE;
- }
- if (mapTile->pokemon != NULL)
- {
- break;
- }
- }
- }
- return FALSE;
+ return numPotentialTargets;
}
+
+// NAKED
+// s32 WeightMoveIfUsable(s32 numPotentialTargets, s32 targetingFlags, struct DungeonEntity *user, struct DungeonEntity *target, struct PokemonMove *move, bool8 hasStatusChecker)
+// {
+// asm_unified("push {r4-r7,lr}\n"
+// "mov r7, r10\n"
+// "mov r6, r9\n"
+// "mov r5, r8\n"
+// "push {r5-r7}\n"
+// "sub sp, 0x4\n"
+// "adds r6, r0, 0\n"
+// "adds r5, r2, 0\n"
+// "adds r7, r3, 0\n"
+// "ldr r0, [sp, 0x28]\n"
+// "lsls r1, 16\n"
+// "asrs r1, 16\n"
+// "mov r9, r1\n"
+// "lsls r0, 24\n"
+// "lsrs r0, 24\n"
+// "mov r10, r0\n"
+// "ldr r2, [r5, 0x70]\n"
+// "ldr r1, [r5, 0x4]\n"
+// "ldr r0, [r7, 0x4]\n"
+// "cmp r1, r0\n"
+// "beq _0807C5BC\n"
+// "movs r0, 0xF0\n"
+// "mov r1, r9\n"
+// "ands r0, r1\n"
+// "cmp r0, 0x30\n"
+// "beq _0807C5BC\n"
+// "cmp r0, 0x60\n"
+// "beq _0807C5BC\n"
+// "cmp r0, 0x70\n"
+// "bne _0807C5C4\n"
+// "_0807C5BC:\n"
+// "adds r0, r2, 0\n"
+// "adds r0, 0x46\n"
+// "ldrb r4, [r0]\n"
+// "b _0807C5CE\n"
+// "_0807C5C4:\n"
+// "adds r0, r5, 0x4\n"
+// "adds r1, r7, 0x4\n"
+// "bl CalculateFacingDir\n"
+// "adds r4, r0, 0\n"
+// "_0807C5CE:\n"
+// "ldr r0, _0807C638\n"
+// "adds r0, r4\n"
+// "mov r8, r0\n"
+// "ldrb r0, [r0]\n"
+// "cmp r0, 0\n"
+// "bne _0807C624\n"
+// "mov r0, r10\n"
+// "str r0, [sp]\n"
+// "mov r0, r9\n"
+// "adds r1, r5, 0\n"
+// "adds r2, r7, 0\n"
+// "ldr r3, [sp, 0x24]\n"
+// "bl CanUseStatusMove\n"
+// "lsls r0, 24\n"
+// "cmp r0, 0\n"
+// "beq _0807C624\n"
+// "movs r0, 0x1\n"
+// "mov r1, r8\n"
+// "strb r0, [r1]\n"
+// "ldr r0, _0807C63C\n"
+// "adds r0, r6, r0\n"
+// "strb r4, [r0]\n"
+// "adds r0, r5, 0\n"
+// "ldr r1, [sp, 0x24]\n"
+// "bl GetMoveTypeForPokemon\n"
+// "adds r3, r0, 0\n"
+// "lsls r3, 24\n"
+// "lsrs r3, 24\n"
+// "adds r0, r5, 0\n"
+// "mov r1, r9\n"
+// "adds r2, r7, 0\n"
+// "bl WeightMove\n"
+// "ldr r1, _0807C640\n"
+// "lsls r2, r6, 2\n"
+// "adds r1, r2, r1\n"
+// "str r0, [r1]\n"
+// "ldr r0, _0807C644\n"
+// "adds r2, r0\n"
+// "str r7, [r2]\n"
+// "adds r6, 0x1\n"
+// "_0807C624:\n"
+// "adds r0, r6, 0\n"
+// "add sp, 0x4\n"
+// "pop {r3-r5}\n"
+// "mov r8, r3\n"
+// "mov r9, r4\n"
+// "mov r10, r5\n"
+// "pop {r4-r7}\n"
+// "pop {r1}\n"
+// "bx r1\n"
+// ".align 2, 0\n"
+// "_0807C638: .4byte gCanAttackInDirection\n"
+// "_0807C63C: .4byte gPotentialAttackTargetDirections\n"
+// "_0807C640: .4byte gPotentialAttackTargetWeights\n"
+// "_0807C644: .4byte gPotentialTargets");
+// }
diff --git a/src/dungeon_ai_attack_2.c b/src/dungeon_ai_attack_2.c
new file mode 100644
index 0000000..41e924a
--- /dev/null
+++ b/src/dungeon_ai_attack_2.c
@@ -0,0 +1,76 @@
+#include "global.h"
+#include "dungeon_ai_attack_2.h"
+
+#include "constants/iq_skill.h"
+#include "dungeon_global_data.h"
+#include "dungeon_map_access.h"
+#include "dungeon_pokemon_attributes.h"
+#include "dungeon_util.h"
+
+bool8 IsTargetStraightAhead(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, s32 facingDir, s32 maxRange)
+{
+ s32 posDiffX = pokemon->posWorld.x - targetPokemon->posWorld.x;
+ s32 effectiveMaxRange;
+ if (posDiffX < 0)
+ {
+ posDiffX = -posDiffX;
+ }
+ effectiveMaxRange = pokemon->posWorld.y - targetPokemon->posWorld.y;
+ if (effectiveMaxRange < 0)
+ {
+ effectiveMaxRange = -effectiveMaxRange;
+ }
+ if (effectiveMaxRange < posDiffX)
+ {
+ effectiveMaxRange = posDiffX;
+ }
+ if (effectiveMaxRange > maxRange)
+ {
+ effectiveMaxRange = maxRange;
+ }
+ if (!HasIQSkill(pokemon, IQ_SKILL_COURSE_CHECKER))
+ {
+ // BUG: effectiveMaxRange is already capped at maxRange, so this condition always evaluates to TRUE.
+ // The AI also has range checks elsewhere, so this doesn't become an issue in most cases.
+ // If the AI has the Long Toss or Pierce statuses and Course Checker is disabled,
+ // this incorrect check causes the AI to throw items at targets further than 10 tiles away.
+ if (effectiveMaxRange <= maxRange)
+ {
+ return TRUE;
+ }
+ }
+ else
+ {
+ s32 currentPosX = pokemon->posWorld.x;
+ s32 currentPosY = pokemon->posWorld.y;
+ s32 adjacentTileOffsetX = gAdjacentTileOffsets[facingDir].x;
+ s32 adjacentTileOffsetY = gAdjacentTileOffsets[facingDir].y;
+ s32 i;
+ for (i = 0; i <= effectiveMaxRange; i++)
+ {
+ struct MapTile *mapTile;
+ currentPosX += adjacentTileOffsetX;
+ currentPosY += adjacentTileOffsetY;
+ if (currentPosX <= 0 || currentPosY <= 0 ||
+ currentPosX >= DUNGEON_MAX_SIZE_X - 1 || currentPosY >= DUNGEON_MAX_SIZE_Y - 1)
+ {
+ break;
+ }
+ while (0); // Extra label needed to swap branch locations in ASM.
+ mapTile = GetMapTile_1(currentPosX, currentPosY);
+ if (!(mapTile->tileType & (TILE_TYPE_FLOOR | TILE_TYPE_LIQUID)))
+ {
+ break;
+ }
+ if (mapTile->pokemon == targetPokemon)
+ {
+ return TRUE;
+ }
+ if (mapTile->pokemon != NULL)
+ {
+ break;
+ }
+ }
+ }
+ return FALSE;
+}
diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c
index 0135c62..31d57ff 100644
--- a/src/dungeon_ai_items.c
+++ b/src/dungeon_ai_items.c
@@ -6,7 +6,7 @@
#include "constants/status.h"
#include "constants/targeting.h"
#include "dungeon_action.h"
-#include "dungeon_ai_attack_1.h"
+#include "dungeon_ai_attack_2.h"
#include "dungeon_ai_item_weight.h"
#include "dungeon_ai_items.h"
#include "dungeon_ai_targeting_2.h"
@@ -39,7 +39,7 @@ enum ItemTargetFlag
extern void sub_8077274(struct DungeonEntity *, struct DungeonEntity *);
extern s32 gNumPotentialTargets;
-extern u32 gPotentialTargetWeights[NUM_DIRECTIONS];
+extern u32 gPotentialItemTargetWeights[NUM_DIRECTIONS];
extern u32 gPotentialItemTargetDirections[NUM_DIRECTIONS];
extern bool8 gTargetAhead[NUM_DIRECTIONS];
extern struct TeamInventory *gTeamInventory_203B460;
@@ -95,7 +95,7 @@ void DecideUseItem(struct DungeonEntity *pokemon)
FindStraightThrowableTargets(pokemon, 2, item, 1);
for (targetIndex = 0; targetIndex < gNumPotentialTargets; targetIndex++)
{
- if (RollPercentChance(gPotentialTargetWeights[targetIndex]))
+ if (RollPercentChance(gPotentialItemTargetWeights[targetIndex]))
{
SetAction(&pokemonData->action, DUNGEON_ACTION_THROW_ITEM_AI);
pokemonData->action.actionUseIndex = selectedToolboxIndex;
@@ -229,7 +229,7 @@ void DecideUseItem(struct DungeonEntity *pokemon)
s32 thrownAIFlag;
for (thrownAIFlag = ITEM_AI_FLAG_TARGET_ALLY; thrownAIFlag <= ITEM_AI_FLAG_TARGET_ENEMY; thrownAIFlag++)
{
- potentialTargetWeights = gPotentialTargetWeights;
+ potentialTargetWeights = gPotentialItemTargetWeights;
if (GetItemAIFlag(item->itemIndex, thrownAIFlag))
{
u8 itemType = GetItemType(item->itemIndex);
@@ -422,7 +422,7 @@ void TargetThrownItem(struct DungeonEntity *pokemon, struct DungeonEntity *targe
u32 *targetWeight;
gTargetAhead[targetDirection] = TRUE;
gPotentialItemTargetDirections[gNumPotentialTargets] = targetDirection;
- targetWeight = &gPotentialTargetWeights[gNumPotentialTargets];
+ targetWeight = &gPotentialItemTargetWeights[gNumPotentialTargets];
itemWeight = !ignoreRollChance ? EvaluateItem(targetPokemon, item, targetingFlags) : 100;
*targetWeight = itemWeight;
gNumPotentialTargets++;
diff --git a/src/moves.c b/src/moves.c
index 0874f00..a7caed6 100644
--- a/src/moves.c
+++ b/src/moves.c
@@ -158,7 +158,7 @@ void InitZeroedPPPokemonMove(struct PokemonMove *move, u16 moveID)
move->PP = 0;
}
-s16 GetMoveTargetingFlags(struct PokemonMove *move, u32 isAI)
+s16 GetMoveTargetingFlags(struct PokemonMove *move, bool32 isAI)
{
return gMovesData[move->moveID].targetingFlags[isAI];
}
diff --git a/src/targeting_flags.c b/src/targeting_flags.c
index f315cdf..bc6010b 100644
--- a/src/targeting_flags.c
+++ b/src/targeting_flags.c
@@ -6,7 +6,7 @@
#include "dungeon_pokemon_attributes.h"
#include "moves.h"
-s16 GetMoveTargetingFlagsForPokemon(struct DungeonEntity *pokemon, struct PokemonMove *move, u32 isAI)
+s16 GetMoveTargetingFlagsForPokemon(struct DungeonEntity *pokemon, struct PokemonMove *move, bool32 isAI)
{
if (move->moveID == MOVE_CURSE && !isAI && !HasType(pokemon, TYPE_GHOST))
{
diff --git a/sym_ewram.txt b/sym_ewram.txt
index bacec19..ebfd117 100644
--- a/sym_ewram.txt
+++ b/sym_ewram.txt
@@ -852,7 +852,7 @@ gPotentialItemTargetDirections = .; /* 202F330 */
gTargetAhead = .; /* 202F350 */
. += 0x8;
-gPotentialTargetWeights = .; /* 202F358 */
+gPotentialItemTargetWeights = .; /* 202F358 */
. += 0x20;
gUnknown_202F378 = .; /* 202F378 */
@@ -864,7 +864,7 @@ gCanAttackInDirection = .; /* 202F380 */
gPotentialAttackTargetDirections = .; /* 202F388 */
. += 0x8;
-gPotentialTargetWeights_2 = .; /* 202F390 */
+gPotentialAttackTargetWeights = .; /* 202F390 */
. += 0x20;
gPotentialTargets = .; /* 202F3B0 */