Add MonCoods size macro

This commit is contained in:
GriffinR 2021-11-01 12:02:08 -04:00
parent 7940f121f6
commit 1548e902cd
6 changed files with 934 additions and 920 deletions

View file

@ -337,7 +337,9 @@
#define NUM_MALE_LINK_FACILITY_CLASSES 8 #define NUM_MALE_LINK_FACILITY_CLASSES 8
#define NUM_FEMALE_LINK_FACILITY_CLASSES 8 #define NUM_FEMALE_LINK_FACILITY_CLASSES 8
#define MON_PIC_SIZE (64 * 64 / 2) #define MON_PIC_WIDTH 64
#define MON_PIC_HEIGHT 64
#define MON_PIC_SIZE (MON_PIC_WIDTH * MON_PIC_HEIGHT / 2)
#define BATTLE_ALIVE_EXCEPT_ACTIVE 0 #define BATTLE_ALIVE_EXCEPT_ACTIVE 0
#define BATTLE_ALIVE_ATK_SIDE 1 #define BATTLE_ALIVE_ATK_SIDE 1

View file

@ -21,6 +21,10 @@ struct MonCoords
u8 y_offset; u8 y_offset;
}; };
#define MON_COORDS_SIZE(width, height)(DIV_ROUND_UP(width, 8) << 4 | DIV_ROUND_UP(height, 8))
#define GET_MON_COORDS_WIDTH(size)((size >> 4) * 8)
#define GET_MON_COORDS_HEIGHT(size)((size & 0xF) * 8)
struct TrainerMonNoItemDefaultMoves struct TrainerMonNoItemDefaultMoves
{ {
u16 iv; u16 iv;

View file

@ -120,10 +120,12 @@
f; \ f; \
}) })
#define ROUND_BITS_TO_BYTES(numBits)(((numBits) / 8) + (((numBits) % 8) ? 1 : 0)) #define DIV_ROUND_UP(val, roundBy)(((val) / (roundBy)) + (((val) % (roundBy)) ? 1 : 0))
#define DEX_FLAGS_NO (ROUND_BITS_TO_BYTES(NUM_SPECIES)) #define ROUND_BITS_TO_BYTES(numBits) DIV_ROUND_UP(numBits, 8)
#define NUM_FLAG_BYTES (ROUND_BITS_TO_BYTES(FLAGS_COUNT))
#define DEX_FLAGS_NO ROUND_BITS_TO_BYTES(NUM_SPECIES)
#define NUM_FLAG_BYTES ROUND_BITS_TO_BYTES(FLAGS_COUNT)
struct Coords8 struct Coords8
{ {

View file

@ -33,10 +33,8 @@ static void AnimTask_BlendMonInAndOut_Step(u8 taskId);
static bool8 sub_80A7238(void); static bool8 sub_80A7238(void);
static void sub_80A8D78(struct Task *task, u8 taskId); static void sub_80A8D78(struct Task *task, u8 taskId);
// EWRAM vars EWRAM_DATA static union AffineAnimCmd *sAnimTaskAffineAnim = NULL;
EWRAM_DATA static union AffineAnimCmd *gAnimTaskAffineAnim = NULL;
// Const rom data
static const struct UCoords8 sBattlerCoords[][MAX_BATTLERS_COUNT] = static const struct UCoords8 sBattlerCoords[][MAX_BATTLERS_COUNT] =
{ {
{ // Single battle { // Single battle
@ -56,10 +54,10 @@ static const struct UCoords8 sBattlerCoords[][MAX_BATTLERS_COUNT] =
// One entry for each of the four Castform forms. // One entry for each of the four Castform forms.
const struct MonCoords gCastformFrontSpriteCoords[NUM_CASTFORM_FORMS] = const struct MonCoords gCastformFrontSpriteCoords[NUM_CASTFORM_FORMS] =
{ {
[CASTFORM_NORMAL] = { .size = 0x44, .y_offset = 17 }, [CASTFORM_NORMAL] = { .size = MON_COORDS_SIZE(32, 32), .y_offset = 17 },
[CASTFORM_FIRE] = { .size = 0x66, .y_offset = 9 }, [CASTFORM_FIRE] = { .size = MON_COORDS_SIZE(48, 48), .y_offset = 9 },
[CASTFORM_WATER] = { .size = 0x46, .y_offset = 9 }, [CASTFORM_WATER] = { .size = MON_COORDS_SIZE(32, 48), .y_offset = 9 },
[CASTFORM_ICE] = { .size = 0x86, .y_offset = 8 }, [CASTFORM_ICE] = { .size = MON_COORDS_SIZE(64, 48), .y_offset = 8 },
}; };
static const u8 sCastformElevations[NUM_CASTFORM_FORMS] = static const u8 sCastformElevations[NUM_CASTFORM_FORMS] =
@ -1740,34 +1738,34 @@ void PrepareAffineAnimInTaskData(struct Task *task, u8 spriteId, const union Aff
bool8 RunAffineAnimFromTaskData(struct Task *task) bool8 RunAffineAnimFromTaskData(struct Task *task)
{ {
gAnimTaskAffineAnim = &((union AffineAnimCmd *)LoadPointerFromVars(task->data[13], task->data[14]))[task->data[7]]; sAnimTaskAffineAnim = &((union AffineAnimCmd *)LoadPointerFromVars(task->data[13], task->data[14]))[task->data[7]];
switch (gAnimTaskAffineAnim->type) switch (sAnimTaskAffineAnim->type)
{ {
default: default:
if (!gAnimTaskAffineAnim->frame.duration) if (!sAnimTaskAffineAnim->frame.duration)
{ {
task->data[10] = gAnimTaskAffineAnim->frame.xScale; task->data[10] = sAnimTaskAffineAnim->frame.xScale;
task->data[11] = gAnimTaskAffineAnim->frame.yScale; task->data[11] = sAnimTaskAffineAnim->frame.yScale;
task->data[12] = gAnimTaskAffineAnim->frame.rotation; task->data[12] = sAnimTaskAffineAnim->frame.rotation;
task->data[7]++; task->data[7]++;
gAnimTaskAffineAnim++; sAnimTaskAffineAnim++;
} }
task->data[10] += gAnimTaskAffineAnim->frame.xScale; task->data[10] += sAnimTaskAffineAnim->frame.xScale;
task->data[11] += gAnimTaskAffineAnim->frame.yScale; task->data[11] += sAnimTaskAffineAnim->frame.yScale;
task->data[12] += gAnimTaskAffineAnim->frame.rotation; task->data[12] += sAnimTaskAffineAnim->frame.rotation;
SetSpriteRotScale(task->data[15], task->data[10], task->data[11], task->data[12]); SetSpriteRotScale(task->data[15], task->data[10], task->data[11], task->data[12]);
SetBattlerSpriteYOffsetFromYScale(task->data[15]); SetBattlerSpriteYOffsetFromYScale(task->data[15]);
if (++task->data[8] >= gAnimTaskAffineAnim->frame.duration) if (++task->data[8] >= sAnimTaskAffineAnim->frame.duration)
{ {
task->data[8] = 0; task->data[8] = 0;
task->data[7]++; task->data[7]++;
} }
break; break;
case AFFINEANIMCMDTYPE_JUMP: case AFFINEANIMCMDTYPE_JUMP:
task->data[7] = gAnimTaskAffineAnim->jump.target; task->data[7] = sAnimTaskAffineAnim->jump.target;
break; break;
case AFFINEANIMCMDTYPE_LOOP: case AFFINEANIMCMDTYPE_LOOP:
if (gAnimTaskAffineAnim->loop.count) if (sAnimTaskAffineAnim->loop.count)
{ {
if (task->data[9]) if (task->data[9])
{ {
@ -1779,7 +1777,7 @@ bool8 RunAffineAnimFromTaskData(struct Task *task)
} }
else else
{ {
task->data[9] = gAnimTaskAffineAnim->loop.count; task->data[9] = sAnimTaskAffineAnim->loop.count;
} }
if (!task->data[7]) if (!task->data[7])
{ {
@ -1788,8 +1786,8 @@ bool8 RunAffineAnimFromTaskData(struct Task *task)
for (;;) for (;;)
{ {
task->data[7]--; task->data[7]--;
gAnimTaskAffineAnim--; sAnimTaskAffineAnim--;
if (gAnimTaskAffineAnim->type == AFFINEANIMCMDTYPE_LOOP) if (sAnimTaskAffineAnim->type == AFFINEANIMCMDTYPE_LOOP)
{ {
task->data[7]++; task->data[7]++;
return TRUE; return TRUE;
@ -1813,12 +1811,12 @@ bool8 RunAffineAnimFromTaskData(struct Task *task)
// matrix's scale in the y dimension. // matrix's scale in the y dimension.
void SetBattlerSpriteYOffsetFromYScale(u8 spriteId) void SetBattlerSpriteYOffsetFromYScale(u8 spriteId)
{ {
int var = 64 - GetBattlerYDeltaFromSpriteId(spriteId) * 2; int var = MON_PIC_HEIGHT - GetBattlerYDeltaFromSpriteId(spriteId) * 2;
u16 matrix = gSprites[spriteId].oam.matrixNum; u16 matrix = gSprites[spriteId].oam.matrixNum;
int var2 = SAFE_DIV(var << 8, gOamMatrices[matrix].d); int var2 = SAFE_DIV(var << 8, gOamMatrices[matrix].d);
if (var2 > 128) if (var2 > MON_PIC_HEIGHT * 2)
var2 = 128; var2 = MON_PIC_HEIGHT * 2;
gSprites[spriteId].y2 = (var - var2) / 2; gSprites[spriteId].y2 = (var - var2) / 2;
} }
@ -1826,12 +1824,12 @@ void SetBattlerSpriteYOffsetFromYScale(u8 spriteId)
// matrix's scale in the y dimension. // matrix's scale in the y dimension.
void SetBattlerSpriteYOffsetFromOtherYScale(u8 spriteId, u8 otherSpriteId) void SetBattlerSpriteYOffsetFromOtherYScale(u8 spriteId, u8 otherSpriteId)
{ {
int var = 64 - GetBattlerYDeltaFromSpriteId(otherSpriteId) * 2; int var = MON_PIC_HEIGHT - GetBattlerYDeltaFromSpriteId(otherSpriteId) * 2;
u16 matrix = gSprites[spriteId].oam.matrixNum; u16 matrix = gSprites[spriteId].oam.matrixNum;
int var2 = SAFE_DIV(var << 8, gOamMatrices[matrix].d); int var2 = SAFE_DIV(var << 8, gOamMatrices[matrix].d);
if (var2 > 128) if (var2 > MON_PIC_HEIGHT * 2)
var2 = 128; var2 = MON_PIC_HEIGHT * 2;
gSprites[spriteId].y2 = (var - var2) / 2; gSprites[spriteId].y2 = (var - var2) / 2;
} }
@ -1882,7 +1880,7 @@ static u16 GetBattlerYDeltaFromSpriteId(u8 spriteId)
} }
} }
} }
return 64; return MON_PIC_HEIGHT;
} }
void StorePointerInVars(s16 *lo, s16 *hi, const void *ptr) void StorePointerInVars(s16 *lo, s16 *hi, const void *ptr)
@ -2209,17 +2207,17 @@ s16 GetBattlerSpriteCoordAttr(u8 battlerId, u8 attr)
switch (attr) switch (attr)
{ {
case BATTLER_COORD_ATTR_HEIGHT: case BATTLER_COORD_ATTR_HEIGHT:
return (coords->size & 0xf) * 8; return GET_MON_COORDS_HEIGHT(coords->size);
case BATTLER_COORD_ATTR_WIDTH: case BATTLER_COORD_ATTR_WIDTH:
return (coords->size >> 4) * 8; return GET_MON_COORDS_WIDTH(coords->size);
case BATTLER_COORD_ATTR_LEFT: case BATTLER_COORD_ATTR_LEFT:
return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X_2) - ((coords->size >> 4) * 4); return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X_2) - (GET_MON_COORDS_WIDTH(coords->size) / 2);
case BATTLER_COORD_ATTR_RIGHT: case BATTLER_COORD_ATTR_RIGHT:
return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X_2) + ((coords->size >> 4) * 4); return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X_2) + (GET_MON_COORDS_WIDTH(coords->size) / 2);
case BATTLER_COORD_ATTR_TOP: case BATTLER_COORD_ATTR_TOP:
return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y_PIC_OFFSET) - ((coords->size & 0xf) * 4); return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y_PIC_OFFSET) - (GET_MON_COORDS_HEIGHT(coords->size) / 2);
case BATTLER_COORD_ATTR_BOTTOM: case BATTLER_COORD_ATTR_BOTTOM:
return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y_PIC_OFFSET) + ((coords->size & 0xf) * 4); return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y_PIC_OFFSET) + (GET_MON_COORDS_HEIGHT(coords->size) / 2);
case BATTLER_COORD_ATTR_RAW_BOTTOM: case BATTLER_COORD_ATTR_RAW_BOTTOM:
ret = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y) + 31; ret = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y) + 31;
return ret - coords->y_offset; return ret - coords->y_offset;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff