Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configs for measurement systems and decimal separators #4183

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@
#define LOG_HANDLER (LOG_HANDLER_MGBA_PRINT)
#endif

#define ENGLISH

#ifdef ENGLISH
#define UNITS_IMPERIAL
#define CHAR_DEC_SEPARATOR CHAR_PERIOD // Period is used as a decimal separator only in the UK and the US.
#else
#define UNITS_METRIC
#define CHAR_DEC_SEPARATOR CHAR_COMMA
#endif

// Uncomment to fix some identified minor bugs
#define BUGFIX

Expand Down Expand Up @@ -81,4 +71,11 @@
#define SUMMARY_SCREEN_NATURE_COLORS TRUE // If TRUE, nature-based stat boosts and reductions will be red and blue in the summary screen.
#define HQ_RANDOM TRUE // If TRUE, replaces the default RNG with an implementation of SFC32 RNG. May break code that relies on RNG.

// Measurement system constants to be used for UNITS
#define UNITS_IMPERIAL 0 // Inches, feet, pounds
#define UNITS_METRIC 1 // meters, kilograms
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved

#define UNITS UNITS_IMPERIAL
#define CHAR_DEC_SEPARATOR CHAR_PERIOD // CHAR_PERIOD is used as a decimal separator only in the UK and the US. The rest of the world uses CHAR_COMMA.

#endif // GUARD_CONFIG_H
10 changes: 10 additions & 0 deletions include/constants/pokedex.h
Original file line number Diff line number Diff line change
Expand Up @@ -1307,4 +1307,14 @@ enum {

#define HOENN_DEX_COUNT (HOENN_DEX_DEOXYS + 1)

#define DECAGRAMS_IN_POUND 4536
#define CM_PER_INCH 2.54
#define CM_PER_INCH_FACTOR (CM_PER_INCH * 100)
#define INCHES_IN_FOOT 12
#define INCHES_IN_ONE_AND_HALF_FOOT (INCHES_IN_FOOT * 1.5)
#define INCHES_IN_FOOT_FACTOR (INCHES_IN_FOOT * 10)

#define WEIGHT_HEIGHT_STR_LEN 16
#define WEIGHT_HEIGHT_STR_MEM (WEIGHT_HEIGHT_STR_LEN * sizeof(u8))

#endif // GUARD_CONSTANTS_POKEDEX_H
2 changes: 2 additions & 0 deletions include/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,9 @@ extern const u8 gText_PokedexRegistration[];
extern const u8 gText_NumberClear01[];
extern const u8 gText_5MarksPokemon[];
extern const u8 gText_UnkHeight[];
extern const u8 gText_UnkHeightMetric[];
extern const u8 gText_UnkWeight[];
extern const u8 gText_UnkWeightMetric[];
extern const u8 gText_HTHeight[];
extern const u8 gText_WTWeight[];
extern const u8 gText_SearchingPleaseWait[];
Expand Down
271 changes: 258 additions & 13 deletions src/pokedex.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ static void Task_HandleCaughtMonPageInput(u8);
static void Task_ExitCaughtMonPage(u8);
static void SpriteCB_SlideCaughtMonToCenter(struct Sprite *sprite);
static void PrintMonInfo(u32 num, u32, u32 owned, u32 newEntry);
static void PrintMonMeasurements(u16 species, u32 owned);
static void PrintUnknownMonMeasurements(void);
static u8* GetUnknownMonHeightString(void);
static u8* GetUnknownMonWeightString(void);
static u8* ReplaceDecimalSeparator(const u8* originalString);
static void PrintOwnedMonMeasurements(u16 species);
static void PrintOwnedMonHeight(u16 species);
static void PrintOwnedMonWeight(u16 species);
static u8* ConvertMonHeightToImperialString(u32 height);
static u8* ConvertMonHeightToMetricString(u32 height);
static u8* ConvertMonWeightToImperialString(u32 weight);
static u8* ConvertMonWeightToMetricString(u32 weight);
static u8* ConvertMeasurementToMetricString(u16 num, u32* index);
static void PrintMonHeight(u16 height, u8 left, u8 top);
static void PrintMonWeight(u16 weight, u8 left, u8 top);
static void ResetOtherVideoRegisters(u16);
Expand Down Expand Up @@ -4141,7 +4154,7 @@ static void PrintMonInfo(u32 num, u32 value, u32 owned, u32 newEntry)
const u8 *name;
const u8 *category;
const u8 *description;
u8 digitCount = (NATIONAL_DEX_COUNT > 999 && IsNationalPokedexEnabled()) ? 4 : 3;
u8 digitCount = (NATIONAL_DEX_COUNT > 999 && IsNationalPokedexEnabled()) ? 4 : 3;

if (newEntry)
PrintInfoScreenText(gText_PokedexRegistration, GetStringCenterAlignXOffset(FONT_NORMAL, gText_PokedexRegistration, DISPLAY_WIDTH), 0);
Expand Down Expand Up @@ -4169,26 +4182,258 @@ static void PrintMonInfo(u32 num, u32 value, u32 owned, u32 newEntry)
category = gText_5MarksPokemon;
}
PrintInfoScreenText(category, 0x64, 0x29);
PrintInfoScreenText(gText_HTHeight, 0x60, 0x39);
PrintInfoScreenText(gText_WTWeight, 0x60, 0x49);
PrintMonMeasurements(species,owned);
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
if (owned)
description = GetSpeciesPokedexDescription(species);
else
description = sExpandedPlaceholder_PokedexDescription;
PrintInfoScreenText(description, GetStringCenterAlignXOffset(FONT_NORMAL, description, DISPLAY_WIDTH), 95);
}

static void PrintMonMeasurements(u16 species, u32 owned)
{
PrintInfoScreenText(gText_HTHeight, 96, 57);
PrintInfoScreenText(gText_WTWeight, 96, 73);

if (owned)
PrintOwnedMonMeasurements(species);
else
PrintUnknownMonMeasurements();
}

static void PrintUnknownMonMeasurements(void)
{
u8* heightString = GetUnknownMonHeightString();
u8* weightString = GetUnknownMonWeightString();

PrintInfoScreenText(heightString, 129, 57);
PrintInfoScreenText(weightString, 129, 73);

Free(heightString);
Free(weightString);
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
}

static u8* GetUnknownMonHeightString(void)
{
if (UNITS == UNITS_IMPERIAL)
return ReplaceDecimalSeparator(gText_UnkHeight);
else
return ReplaceDecimalSeparator(gText_UnkHeightMetric);
}

static u8* GetUnknownMonWeightString(void)
{
if (UNITS == UNITS_IMPERIAL)
return ReplaceDecimalSeparator(gText_UnkWeight);
else
return ReplaceDecimalSeparator(gText_UnkWeightMetric);
}

static u8* ReplaceDecimalSeparator(const u8* originalString)
{
bool32 replaced = FALSE;
u32 length = StringLength(originalString);
u8* modifiedString = Alloc(WEIGHT_HEIGHT_STR_MEM);

for (u32 i = 0; i < length; i++)
{
if ((originalString[i] != CHAR_PERIOD) || replaced)
{
modifiedString[i] = originalString[i];
continue;
}

modifiedString[i] = CHAR_DEC_SEPARATOR;
replaced = TRUE;
}
modifiedString[length] = EOS;
return modifiedString;
}

static void PrintOwnedMonMeasurements(u16 species)
{
PrintOwnedMonHeight(species);
PrintOwnedMonWeight(species);
}

static void PrintOwnedMonHeight(u16 species)
{
u32 height = GetSpeciesHeight(species);
u8* heightString;

if (UNITS == UNITS_IMPERIAL)
heightString = ConvertMonHeightToImperialString(height);
else
heightString = ConvertMonHeightToMetricString(height);

PrintInfoScreenText(heightString, 129, 57);
Free(heightString);
}

static void PrintOwnedMonWeight(u16 species)
{
u32 weight = GetSpeciesWeight(species);
u8* weightString;

if (UNITS == UNITS_IMPERIAL)
weightString = ConvertMonWeightToImperialString(weight);
else
weightString = ConvertMonWeightToMetricString(weight);

PrintInfoScreenText(weightString, 129, 73);
Free(weightString);
}
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved

static u8* ConvertMonHeightToImperialString(u32 height)
{
u8* heightString = Alloc(WEIGHT_HEIGHT_STR_MEM);
u32 inches, feet, index = 0;

inches = (height * 10000) / CM_PER_INCH_FACTOR;
if (inches % 10 >= 5)
inches += 10;
feet = inches / INCHES_IN_FOOT_FACTOR;
inches = (inches - (feet * INCHES_IN_FOOT_FACTOR)) / 10;

heightString[index++] = EXT_CTRL_CODE_BEGIN;
heightString[index++] = EXT_CTRL_CODE_CLEAR_TO;
if (feet / 10 == 0)
{
PrintMonHeight(GetSpeciesHeight(species), 0x81, 0x39);
PrintMonWeight(GetSpeciesWeight(species), 0x81, 0x49);
heightString[index++] = INCHES_IN_ONE_AND_HALF_FOOT;
heightString[index++] = feet + CHAR_0;
}
else
{
PrintInfoScreenText(gText_UnkHeight, 0x81, 0x39);
PrintInfoScreenText(gText_UnkWeight, 0x81, 0x49);
heightString[index++] = INCHES_IN_FOOT;
heightString[index++] = feet / 10 + CHAR_0;
heightString[index++] = (feet % 10) + CHAR_0;
}
heightString[index++] = CHAR_SGL_QUOTE_RIGHT;
heightString[index++] = (inches / 10) + CHAR_0;
heightString[index++] = (inches % 10) + CHAR_0;
heightString[index++] = CHAR_DBL_QUOTE_RIGHT;
heightString[index++] = EOS;

return heightString;
}

static u8* ConvertMonHeightToMetricString(u32 height)
{
u32 index = 0;
u8* heightString = ConvertMeasurementToMetricString(height, &index);

heightString[index++] = CHAR_m;
heightString[index++] = EOS;
return heightString;
}

static u8* ConvertMonWeightToImperialString(u32 weight)
{
u8* weightString = Alloc(WEIGHT_HEIGHT_STR_MEM);
bool32 output = FALSE;
u32 index = 0, lbs = (weight * 100000) / DECAGRAMS_IN_POUND;

if (lbs % 10u >= 5)
lbs += 10;

if ((weightString[index] = (lbs / 100000) + CHAR_0) == CHAR_0 && !output)
{
weightString[index++] = CHAR_SPACER;
}
if (owned)
description = GetSpeciesPokedexDescription(species);
else
description = sExpandedPlaceholder_PokedexDescription;
PrintInfoScreenText(description, GetStringCenterAlignXOffset(FONT_NORMAL, description, DISPLAY_WIDTH), 95);
{
output = TRUE;
index++;
}

lbs %= 100000;
if ((weightString[index] = (lbs / 10000) + CHAR_0) == CHAR_0 && !output)
{
weightString[index++] = CHAR_SPACER;
}
else
{
output = TRUE;
index++;
}

lbs %= 10000;
if ((weightString[index] = (lbs / 1000) + CHAR_0) == CHAR_0 && !output)
{
weightString[index++] = CHAR_SPACER;
}
else
{
output = TRUE;
index++;
}

lbs %= 1000;
weightString[index++] = (lbs / 100) + CHAR_0;
lbs %= 100;
weightString[index++] = CHAR_DEC_SEPARATOR;
weightString[index++] = (lbs / 10) + CHAR_0;
weightString[index++] = CHAR_SPACE;
weightString[index++] = CHAR_l;
weightString[index++] = CHAR_b;
weightString[index++] = CHAR_s;
weightString[index++] = CHAR_PERIOD;
weightString[index++] = EOS;

return weightString;
}

static u8* ConvertMonWeightToMetricString(u32 weight)
{
u32 index = 0;
u8* weightString = ConvertMeasurementToMetricString(weight, &index);

weightString[index++] = CHAR_k;
weightString[index++] = CHAR_g;
weightString[index++] = CHAR_PERIOD;
weightString[index++] = EOS;
return weightString;
}

static u8* ConvertMeasurementToMetricString(u16 num, u32* index)
{
u8* string = Alloc(WEIGHT_HEIGHT_STR_MEM);
bool32 outputted = FALSE;
u32 result;

result = num / 1000;
if (result == 0)
{
string[(*index)++] = CHAR_SPACER;
outputted = FALSE;
}
else
{
string[(*index)++] = CHAR_0 + result;
outputted = TRUE;
}

result = (num % 1000) / 100;
if (result == 0 && !outputted)
{
string[(*index)++] = CHAR_SPACER;
outputted = FALSE;
}
else
{
string[(*index)++] = CHAR_0 + result;
outputted = TRUE;
}

string[(*index)++] = CHAR_0 + ((num % 1000) % 100) / 10;
string[(*index)++] = CHAR_DEC_SEPARATOR;
string[(*index)++] = CHAR_0 + ((num % 1000) % 100) % 10;
string[(*index)++] = CHAR_SPACE;

return string;
}

static void PrintMonHeight(u16 height, u8 left, u8 top)
static void UNUSED PrintMonHeight(u16 height, u8 left, u8 top)
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
{
u8 buffer[16];
u32 inches, feet;
Expand Down Expand Up @@ -4221,7 +4466,7 @@ static void PrintMonHeight(u16 height, u8 left, u8 top)
PrintInfoScreenText(buffer, left, top);
}

static void PrintMonWeight(u16 weight, u8 left, u8 top)
static void UNUSED PrintMonWeight(u16 weight, u8 left, u8 top)
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
{
u8 buffer[16];
bool8 output;
Expand Down
6 changes: 1 addition & 5 deletions src/pokemon_size_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ static const u8 sGiftRibbonsMonDataIds[GIFT_RIBBONS_COUNT - 4] =
extern const u8 gText_DecimalPoint[];
extern const u8 gText_Marco[];

#define CM_PER_INCH 2.54

static u32 GetMonSizeHash(struct Pokemon *pkmn)
{
u16 personality = GetMonData(pkmn, MON_DATA_PERSONALITY);
Expand Down Expand Up @@ -95,10 +93,8 @@ static u32 GetMonSize(u16 species, u16 b)

static void FormatMonSizeRecord(u8 *string, u32 size)
{
#ifdef UNITS_IMPERIAL
//Convert size from centimeters to inches
size = (f64)(size * 10) / (CM_PER_INCH * 10);
#endif
size = (f64)(size * 10) / (CM_PER_INCH * 10);
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved

string = ConvertIntToDecimalStringN(string, size / 10, STR_CONV_MODE_LEFT_ALIGN, 8);
string = StringAppend(string, gText_DecimalPoint);
Expand Down
2 changes: 2 additions & 0 deletions src/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ const u8 gText_DefaultNameHalie[] = _("HALIE");
const u8 gText_ThisIsAPokemon[] = _("This is what we call a “POKéMON.”{PAUSE 96}\p");
const u8 gText_5MarksPokemon[] = _("????? POKéMON");
const u8 gText_UnkHeight[] = _("{CLEAR_TO 0x0C}??'??”");
const u8 gText_UnkHeightMetric[] = _("???.? m");
const u8 gText_UnkWeight[] = _("????.? lbs.");
const u8 gText_UnkWeightMetric[] = _("???.? kg.");
const u8 gText_EmptyPkmnCategory[] = _(" POKéMON"); // Unused
const u8 gText_EmptyHeight[] = _("{CLEAR_TO 0x0C} ' ”"); // Unused
const u8 gText_EmptyWeight[] = _(" . lbs."); // Unused
Expand Down
Loading