summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnonymousRandomPerson <chenghanngan.us@gmail.com>2022-03-03 03:07:36 -0500
committerAnonymousRandomPerson <chenghanngan.us@gmail.com>2022-03-10 22:32:17 -0500
commit8c0df48b9ebd0fa794a97c6280cc59b6dfcb9eef (patch)
tree5fb291fa0203bb4b2fe4338076ebe43c4df137eb
parentf50e233c9171d7bdd76c1c53dd96c85cd0a4d99f (diff)
Decomped WeightMove()
-rw-r--r--asm/code_807C854.s (renamed from asm/code_807C7AC.s)88
-rw-r--r--include/dungeon_ai_attack_1.h2
-rwxr-xr-xld_script.txt2
-rw-r--r--src/dungeon_ai_attack.c1
-rw-r--r--src/dungeon_ai_attack_1.c42
5 files changed, 44 insertions, 91 deletions
diff --git a/asm/code_807C7AC.s b/asm/code_807C854.s
index b43caa8..40a8c49 100644
--- a/asm/code_807C7AC.s
+++ b/asm/code_807C854.s
@@ -5,94 +5,6 @@
.text
- 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}
diff --git a/include/dungeon_ai_attack_1.h b/include/dungeon_ai_attack_1.h
index 7272256..160c32e 100644
--- a/include/dungeon_ai_attack_1.h
+++ b/include/dungeon_ai_attack_1.h
@@ -7,5 +7,7 @@
s32 WeightMoveIfUsable(s32 numPotentialTargets, s32 targetingFlags, struct DungeonEntity *user, struct DungeonEntity *target, struct PokemonMove *move, u32 hasStatusChecker);
// 0x7C648
bool8 CanUseStatusMove(s32 targetingFlags, struct DungeonEntity *user, struct DungeonEntity *target, struct PokemonMove *move, bool32 hasStatusChecker);
+// 0x7C7AC
+s32 WeightMove(struct DungeonEntity *user, s32 targetingFlags, struct DungeonEntity *target, u32 moveType);
#endif
diff --git a/ld_script.txt b/ld_script.txt
index 58036e5..810f987 100755
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -241,7 +241,7 @@ SECTIONS {
src/dungeon_ai_attack.o(.text);
asm/code_807C4A0.o(.text);
src/dungeon_ai_attack_1.o(.text);
- asm/code_807C7AC.o(.text);
+ asm/code_807C854.o(.text);
src/dungeon_ai_attack_2.o(.text);
asm/code_807CABC.o(.text);
src/targeting_flags.o(.text);
diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c
index 835d207..35d15c8 100644
--- a/src/dungeon_ai_attack.c
+++ b/src/dungeon_ai_attack.c
@@ -42,7 +42,6 @@ extern struct DungeonEntity *gPotentialTargets[NUM_DIRECTIONS];
extern bool8 IsMoveUsable_1(struct DungeonEntity*, s32, bool8);
extern bool8 TargetRegularAttack(struct DungeonEntity*, u32*, bool8);
extern bool8 IsTargetInLineRange(struct DungeonEntity*, struct DungeonEntity*, s32);
-extern s32 WeightMove(struct DungeonEntity*, s32, struct DungeonEntity*, u8);
void DecideAttack(struct DungeonEntity *pokemon)
{
diff --git a/src/dungeon_ai_attack_1.c b/src/dungeon_ai_attack_1.c
index 8421cc9..6f70077 100644
--- a/src/dungeon_ai_attack_1.c
+++ b/src/dungeon_ai_attack_1.c
@@ -2,9 +2,11 @@
#include "dungeon_ai_attack_1.h"
#include "constants/direction.h"
+#include "constants/iq_skill.h"
#include "constants/targeting.h"
#include "constants/type.h"
#include "dungeon_ai_targeting_2.h"
+#include "dungeon_global_data.h"
#include "dungeon_pokemon_attributes.h"
#include "dungeon_random.h"
#include "moves.h"
@@ -17,7 +19,7 @@ extern s32 gPotentialAttackTargetWeights[NUM_DIRECTIONS];
extern u8 gPotentialAttackTargetDirections[NUM_DIRECTIONS];
extern struct DungeonEntity *gPotentialTargets[NUM_DIRECTIONS];
-extern s32 WeightMove(struct DungeonEntity*, s32, struct DungeonEntity*, u8);
+extern s32 WeightWeakTypePicker(struct DungeonEntity *user, struct DungeonEntity *target, u8 moveType);
s32 WeightMoveIfUsable(s32 numPotentialTargets, s32 targetingFlags, struct DungeonEntity *user, struct DungeonEntity *target, struct PokemonMove *move, bool32 hasStatusChecker)
{
@@ -173,3 +175,41 @@ bool8 CanUseStatusMove(s32 targetingFlags, struct DungeonEntity *user, struct Du
}
return hasTarget;
}
+
+s32 WeightMove(struct DungeonEntity *user, s32 targetingFlags, struct DungeonEntity *target, u32 moveType)
+{
+#ifndef NONMATCHING
+ register struct DungeonEntityData *targetData asm("r4");
+#else
+ struct DungeonEntityData *targetData;
+#endif
+ s32 targetingFlags2 = (s16) targetingFlags;
+ u8 moveType2 = moveType;
+ u8 weight = 1;
+ struct DungeonEntityData *targetData2;
+ targetData2 = targetData = target->entityData;
+ if (!targetData->isEnemy || (targetingFlags2 & 0xF) != TARGETING_FLAG_TARGET_OTHER)
+ {
+ return 1;
+ }
+ else if (HasIQSkill(user, IQ_SKILL_EXP_GO_GETTER))
+ {
+ // BUG: expYieldRankings has lower values as the Pokémon's experience yield increases.
+ // This causes Exp. Go-Getter to prioritizes Pokémon worth less experience
+ // instead of Pokémon worth more experience.
+ weight = gDungeonGlobalData->expYieldRankings[targetData->entityID];
+ }
+ else if (HasIQSkill(user, IQ_SKILL_EFFICIENCY_EXPERT))
+ {
+ weight = -12 - targetData2->HP;
+ if (weight == 0)
+ {
+ weight = 1;
+ }
+ }
+ else if (HasIQSkill(user, IQ_SKILL_WEAK_TYPE_PICKER))
+ {
+ weight = WeightWeakTypePicker(user, target, moveType2) + 1;
+ }
+ return weight;
+}