mirror of
https://github.com/pret/pmd-red.git
synced 2026-04-24 23:17:03 -05:00
Labeled CalculateFacingDir()
This commit is contained in:
parent
cbf41c6bf3
commit
52e7368f30
|
|
@ -1,63 +0,0 @@
|
|||
#include "asm/constants/gba_constants.inc"
|
||||
#include "asm/macros.inc"
|
||||
|
||||
.syntax unified
|
||||
|
||||
.text
|
||||
|
||||
thumb_func_start CalculateFacingDir
|
||||
CalculateFacingDir:
|
||||
push {r4,lr}
|
||||
movs r2, 0
|
||||
ldrsh r3, [r1, r2]
|
||||
movs r4, 0
|
||||
ldrsh r2, [r0, r4]
|
||||
subs r2, r3, r2
|
||||
movs r3, 0x2
|
||||
ldrsh r1, [r1, r3]
|
||||
movs r4, 0x2
|
||||
ldrsh r0, [r0, r4]
|
||||
subs r1, r0
|
||||
cmp r2, 0
|
||||
bne _080983FA
|
||||
cmp r1, 0
|
||||
bne _080983FA
|
||||
movs r0, 0
|
||||
b _08098428
|
||||
_080983FA:
|
||||
cmp r2, 0
|
||||
ble _08098400
|
||||
movs r2, 0x1
|
||||
_08098400:
|
||||
cmp r1, 0
|
||||
ble _08098406
|
||||
movs r1, 0x1
|
||||
_08098406:
|
||||
movs r0, 0x1
|
||||
negs r0, r0
|
||||
cmp r2, r0
|
||||
bgt _08098410
|
||||
adds r2, r0, 0
|
||||
_08098410:
|
||||
cmp r1, r0
|
||||
bgt _08098416
|
||||
adds r1, r0, 0
|
||||
_08098416:
|
||||
ldr r3, _08098430
|
||||
adds r2, 0x1
|
||||
adds r1, 0x1
|
||||
lsls r0, r1, 1
|
||||
adds r0, r1
|
||||
adds r0, r2
|
||||
lsls r0, 2
|
||||
adds r0, r3
|
||||
ldr r0, [r0]
|
||||
_08098428:
|
||||
pop {r4}
|
||||
pop {r1}
|
||||
bx r1
|
||||
.align 2, 0
|
||||
_08098430: .4byte gUnknown_8115E94
|
||||
thumb_func_end CalculateFacingDir
|
||||
|
||||
.align 2,0
|
||||
3424
data/data_810AE24.s
3424
data/data_810AE24.s
File diff suppressed because it is too large
Load Diff
3425
data/data_8115EB8.s
Normal file
3425
data/data_8115EB8.s
Normal file
File diff suppressed because it is too large
Load Diff
9
include/position_util.h
Normal file
9
include/position_util.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef GUARD_POSITION_UTIL_H
|
||||
#define GUARD_POSITION_UTIL_H
|
||||
|
||||
#include "position.h"
|
||||
|
||||
// 0x983D8
|
||||
s32 CalculateFacingDir(struct Position *originPos, struct Position *targetPos);
|
||||
|
||||
#endif
|
||||
|
|
@ -284,7 +284,7 @@ SECTIONS {
|
|||
src/exclusive_pokemon.o(.text);
|
||||
asm/exclusive_pokemon.o(.text);
|
||||
src/exclusive_pokemon_1.o(.text);
|
||||
src/code_80983D8.o(.text);
|
||||
src/position_util.o(.text);
|
||||
asm/code_8098468.o(.text);
|
||||
src/code_8098BDC.o(.text);
|
||||
asm/code_8098BDC.o(.text);
|
||||
|
|
@ -407,6 +407,8 @@ SECTIONS {
|
|||
src/rescue_team_info.o(.rodata);
|
||||
src/text_util.o(.rodata);
|
||||
data/data_810AE24.o(.rodata);
|
||||
src/position_util.o(.rodata);
|
||||
data/data_8115EB8.o(.rodata);
|
||||
data/friend_area_dialogue.o(.rodata);
|
||||
data/cutscenes.o(.rodata);
|
||||
data/cutscenes_1.o(.rodata);
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
extern u32 gUnknown_8115E94[5][3]; // NOTE: Factor of two difference in array sizes
|
||||
|
||||
s32 CalculateFacingDir(short *param_1,short *param_2)
|
||||
{
|
||||
s32 uVar1;
|
||||
s32 uVar2;
|
||||
s32 uVar3;
|
||||
|
||||
uVar3 = param_2[0] - param_1[0];
|
||||
uVar2 = param_2[1] - param_1[1];
|
||||
if ((uVar3 == 0) && (uVar2 == 0)) {
|
||||
uVar1 = 0;
|
||||
}
|
||||
else {
|
||||
if (0 < uVar3) {
|
||||
uVar3 = 1;
|
||||
}
|
||||
if (0 < uVar2) {
|
||||
uVar2 = 1;
|
||||
}
|
||||
if (-1 >= uVar3) {
|
||||
uVar3 = -1;
|
||||
}
|
||||
if (-1 >= uVar2) {
|
||||
uVar2 = -1;
|
||||
}
|
||||
uVar1 = gUnknown_8115E94[(uVar2 + 1)][(uVar3 + 1)];
|
||||
}
|
||||
return uVar1;
|
||||
}
|
||||
|
||||
s32 GetMaxPositionDifference(short param_1[],short param_2[])
|
||||
{
|
||||
s32 diff_index1;
|
||||
s32 diff_index0;
|
||||
|
||||
diff_index0 = param_1[0] - param_2[0];
|
||||
if (diff_index0 < 0) {
|
||||
diff_index0 = -diff_index0;
|
||||
}
|
||||
diff_index1 = param_1[1] - param_2[1];
|
||||
if (diff_index1 < 0) {
|
||||
diff_index1 = -diff_index1;
|
||||
}
|
||||
if (diff_index1 < diff_index0) {
|
||||
diff_index1 = diff_index0;
|
||||
}
|
||||
return diff_index1;
|
||||
}
|
||||
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
#include "dungeon_visibility.h"
|
||||
#include "item.h"
|
||||
#include "position.h"
|
||||
#include "position_util.h"
|
||||
#include "team_inventory.h"
|
||||
|
||||
#define NUM_POTENTIAL_ROCK_TARGETS 20
|
||||
|
|
@ -35,7 +36,6 @@ enum ItemTargetFlag
|
|||
ITEM_TARGET_ALLY = 1 << 1
|
||||
};
|
||||
|
||||
extern s32 CalculateFacingDir(struct Position*, struct Position*);
|
||||
extern void sub_8077274(struct DungeonEntity *, struct DungeonEntity *);
|
||||
|
||||
extern s32 gNumPotentialTargets;
|
||||
|
|
|
|||
65
src/position_util.c
Normal file
65
src/position_util.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include "global.h"
|
||||
#include "position_util.h"
|
||||
|
||||
#include "constants/direction.h"
|
||||
|
||||
const s32 gFacingDirMapping[3][3] = {
|
||||
{DIRECTION_NORTHWEST, DIRECTION_NORTH, DIRECTION_NORTHEAST},
|
||||
{DIRECTION_WEST, DIRECTION_SOUTH, DIRECTION_EAST},
|
||||
{DIRECTION_SOUTHWEST, DIRECTION_SOUTH, DIRECTION_SOUTHEAST}
|
||||
};
|
||||
|
||||
s32 CalculateFacingDir(struct Position *originPos, struct Position *targetPos)
|
||||
{
|
||||
s32 facingDir;
|
||||
s32 yDiff;
|
||||
s32 xDiff;
|
||||
|
||||
xDiff = targetPos->x - originPos->x;
|
||||
yDiff = targetPos->y - originPos->y;
|
||||
if (xDiff == 0 && yDiff == 0)
|
||||
{
|
||||
facingDir = DIRECTION_SOUTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xDiff > 0)
|
||||
{
|
||||
xDiff = 1;
|
||||
}
|
||||
if (yDiff > 0)
|
||||
{
|
||||
yDiff = 1;
|
||||
}
|
||||
if (xDiff <= -1)
|
||||
{
|
||||
xDiff = -1;
|
||||
}
|
||||
if (yDiff <= -1)
|
||||
{
|
||||
yDiff = -1;
|
||||
}
|
||||
facingDir = gFacingDirMapping[yDiff + 1][xDiff + 1];
|
||||
}
|
||||
return facingDir;
|
||||
}
|
||||
|
||||
s32 GetMaxPositionDifference(short param_1[],short param_2[])
|
||||
{
|
||||
s32 diff_index1;
|
||||
s32 diff_index0;
|
||||
|
||||
diff_index0 = param_1[0] - param_2[0];
|
||||
if (diff_index0 < 0) {
|
||||
diff_index0 = -diff_index0;
|
||||
}
|
||||
diff_index1 = param_1[1] - param_2[1];
|
||||
if (diff_index1 < 0) {
|
||||
diff_index1 = -diff_index1;
|
||||
}
|
||||
if (diff_index1 < diff_index0) {
|
||||
diff_index1 = diff_index0;
|
||||
}
|
||||
return diff_index1;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user