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

Build experience tables from source #147

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion platinum.us/filesys.sha1
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ e32324642d5ec29155743970ac8bc14dd74f63e1 *res/prebuilt/poketool/trgra/trfgra.nar
1f8689cbc763d9efedac9e6f12e940dbd361f7a9 *res/pokemon/pl_personal.narc
7755e3a884a11b098122ca9dd656223fd4b02dd0 *res/pokemon/evo.narc
fbbf1287b2ac10c5212be0e4a69461507e860005 *res/prebuilt/poketool/personal/growtbl.narc
fbbf1287b2ac10c5212be0e4a69461507e860005 *res/prebuilt/poketool/personal/pl_growtbl.narc
fbbf1287b2ac10c5212be0e4a69461507e860005 *res/pokemon/pl_growtbl.narc
de5c1035595e3cb52990b183497e513246bd0efe *res/prebuilt/poketool/personal/pms.narc
cd4b737f173cc6ac1a25636efa4edfd83da79599 *res/pokemon/wotbl.narc
59f49fe682ef8cf4dfb8f6b7da2e0f51401b50cc *res/trainers/trdata.narc
Expand Down
8 changes: 7 additions & 1 deletion platinum.us/rom.rsf
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ RomSpec
Root /
HostRoot res/prebuilt
File poketool/personal/growtbl.narc
File poketool/personal/pl_growtbl.narc

Root /poketool/personal
HostRoot res/pokemon
File pl_growtbl.narc

Root /
HostRoot res/prebuilt
File poketool/personal/pms.narc

Root /poketool/personal
Expand Down
102 changes: 102 additions & 0 deletions res/pokemon/.shared/exp_tables.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
level,medium_fast,erratic,fluctuating,medium_slow,fast,slow,unused_6,unused_7
0,0,0,0,0,0,0,0,0
1,0,0,0,0,0,0,0,0
2,8,15,4,9,6,10,8,8
3,27,52,13,57,21,33,27,27
4,64,122,32,96,51,80,64,64
5,125,237,65,135,100,156,125,125
6,216,406,112,179,172,270,216,216
7,343,637,178,236,274,428,343,343
8,512,942,276,314,409,640,512,512
9,729,1326,393,419,583,911,729,729
10,1000,1800,540,560,800,1250,1000,1000
11,1331,2369,745,742,1064,1663,1331,1331
12,1728,3041,967,973,1382,2160,1728,1728
13,2197,3822,1230,1261,1757,2746,2197,2197
14,2744,4719,1591,1612,2195,3430,2744,2744
15,3375,5737,1957,2035,2700,4218,3375,3375
16,4096,6881,2457,2535,3276,5120,4096,4096
17,4913,8155,3046,3120,3930,6141,4913,4913
18,5832,9564,3732,3798,4665,7290,5832,5832
19,6859,11111,4526,4575,5487,8573,6859,6859
20,8000,12800,5440,5460,6400,10000,8000,8000
21,9261,14632,6482,6458,7408,11576,9261,9261
22,10648,16610,7666,7577,8518,13310,10648,10648
23,12167,18737,9003,8825,9733,15208,12167,12167
24,13824,21012,10506,10208,11059,17280,13824,13824
25,15625,23437,12187,11735,12500,19531,15625,15625
26,17576,26012,14060,13411,14060,21970,17576,17576
27,19683,28737,16140,15244,15746,24603,19683,19683
28,21952,31610,18439,17242,17561,27440,21952,21952
29,24389,34632,20974,19411,19511,30486,24389,24389
30,27000,37800,23760,21760,21600,33750,27000,27000
31,29791,41111,26811,24294,23832,37238,29791,29791
32,32768,44564,30146,27021,26214,40960,32768,32768
33,35937,48155,33780,29949,28749,44921,35937,35937
34,39304,51881,37731,33084,31443,49130,39304,39304
35,42875,55737,42017,36435,34300,53593,42875,42875
36,46656,59719,46656,40007,37324,58320,46656,46656
37,50653,63822,50653,43808,40522,63316,50653,50653
38,54872,68041,55969,47846,43897,68590,54872,54872
39,59319,72369,60505,52127,47455,74148,59319,59319
40,64000,76800,66560,56660,51200,80000,64000,64000
41,68921,81326,71677,61450,55136,86151,68921,68921
42,74088,85942,78533,66505,59270,92610,74088,74088
43,79507,90637,84277,71833,63605,99383,79507,79507
44,85184,95406,91998,77440,68147,106480,85184,85184
45,91125,100237,98415,83335,72900,113906,91125,91125
46,97336,105122,107069,89523,77868,121670,97336,97336
47,103823,110052,114205,96012,83058,129778,103823,103823
48,110592,115015,123863,102810,88473,138240,110592,110592
49,117649,120001,131766,109923,94119,147061,117649,117649
50,125000,125000,142500,117360,100000,156250,125000,125000
51,132651,131324,151222,125126,106120,165813,132651,132651
52,140608,137795,163105,133229,112486,175760,140608,140608
53,148877,144410,172697,141677,119101,186096,148877,148877
54,157464,151165,185807,150476,125971,196830,157464,157464
55,166375,158056,196322,159635,133100,207968,166375,166375
56,175616,165079,210739,169159,140492,219520,175616,175616
57,185193,172229,222231,179056,148154,231491,185193,185193
58,195112,179503,238036,189334,156089,243890,195112,195112
59,205379,186894,250562,199999,164303,256723,205379,205379
60,216000,194400,267840,211060,172800,270000,216000,216000
61,226981,202013,281456,222522,181584,283726,226981,226981
62,238328,209728,300293,234393,190662,297910,238328,238328
63,250047,217540,315059,246681,200037,312558,250047,250047
64,262144,225443,335544,259392,209715,327680,262144,262144
65,274625,233431,351520,272535,219700,343281,274625,274625
66,287496,241496,373744,286115,229996,359370,287496,287496
67,300763,249633,390991,300140,240610,375953,300763,300763
68,314432,257834,415050,314618,251545,393040,314432,314432
69,328509,267406,433631,329555,262807,410636,328509,328509
70,343000,276458,459620,344960,274400,428750,343000,343000
71,357911,286328,479600,360838,286328,447388,357911,357911
72,373248,296358,507617,377197,298598,466560,373248,373248
73,389017,305767,529063,394045,311213,486271,389017,389017
74,405224,316074,559209,411388,324179,506530,405224,405224
75,421875,326531,582187,429235,337500,527343,421875,421875
76,438976,336255,614566,447591,351180,548720,438976,438976
77,456533,346965,639146,466464,365226,570666,456533,456533
78,474552,357812,673863,485862,379641,593190,474552,474552
79,493039,367807,700115,505791,394431,616298,493039,493039
80,512000,378880,737280,526260,409600,640000,512000,512000
81,531441,390077,765275,547274,425152,664301,531441,531441
82,551368,400293,804997,568841,441094,689210,551368,551368
83,571787,411686,834809,590969,457429,714733,571787,571787
84,592704,423190,877201,613664,474163,740880,592704,592704
85,614125,433572,908905,636935,491300,767656,614125,614125
86,636056,445239,954084,660787,508844,795070,636056,636056
87,658503,457001,987754,685228,526802,823128,658503,658503
88,681472,467489,1035837,710266,545177,851840,681472,681472
89,704969,479378,1071552,735907,563975,881211,704969,704969
90,729000,491346,1122660,762160,583200,911250,729000,729000
91,753571,501878,1160499,789030,602856,941963,753571,753571
92,778688,513934,1214753,816525,622950,973360,778688,778688
93,804357,526049,1254796,844653,643485,1005446,804357,804357
94,830584,536557,1312322,873420,664467,1038230,830584,830584
95,857375,548720,1354652,902835,685900,1071718,857375,857375
96,884736,560922,1415577,932903,707788,1105920,884736,884736
97,912673,571333,1460276,963632,730138,1140841,912673,912673
98,941192,583539,1524731,995030,752953,1176490,941192,941192
99,970299,591882,1571884,1027103,776239,1212873,970299,970299
100,1000000,600000,1640000,1059860,800000,1250000,1000000,1000000
16 changes: 16 additions & 0 deletions res/pokemon/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ otherpoke_shared = files(

sinnoh_pokedex = files('sinnoh_pokedex.json')

pl_growtbl_files = files('.shared/exp_tables.csv')

# Process mons in national dex order
pokemon_subdirs = [
'000', # Glitch pokemon "-----" aka DPBox, Invisible Shiny Bulbasau
Expand Down Expand Up @@ -754,6 +756,19 @@ shinzukan_narc = custom_target('shinzukan.narc',
]
)

pl_growtbl_narc = custom_target('pl_growtbl.narc',
output: 'pl_growtbl.narc',
input: pl_growtbl_files,
command: [
make_pl_growtbl_py,
'--knarc', knarc_exe,
'--source-dir', '@CURRENT_SOURCE_DIR@',
'--private-dir', '@PRIVATE_DIR@',
'--output-dir', '@OUTDIR@',
pl_growtbl_files
]
)

nitrofs_files += pl_personal_narc
nitrofs_files += evo_narc
nitrofs_files += pl_poke_icon_narc
Expand All @@ -764,3 +779,4 @@ nitrofs_files += height_narc
nitrofs_files += pl_poke_data_narc
nitrofs_files += pl_pokezukan_narc
nitrofs_files += shinzukan_narc
nitrofs_files += pl_growtbl_narc
1 change: 0 additions & 1 deletion res/prebuilt/poketool/personal/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
prebuilt_files = [
'growtbl.narc',
'personal.narc',
'pl_growtbl.narc',
'pms.narc',
]

Expand Down
Binary file removed res/prebuilt/poketool/personal/pl_growtbl.narc
Binary file not shown.
16 changes: 8 additions & 8 deletions src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ static void BoxPokemon_SetDataInternal(BoxPokemon *boxMon, enum PokemonDataParam
static void Pokemon_IncreaseDataInternal(Pokemon *mon, enum PokemonDataParam param, int value);
static void BoxPokemon_IncreaseDataInternal(BoxPokemon *boxMon, enum PokemonDataParam param, int value);
static u32 BoxPokemon_GetExpToNextLevel(BoxPokemon *boxMon);
static void Pokemon_LoadExperienceTableOf(int monExpRate, u32 *monExpTable);
static u32 Pokemon_GetExpRateBaseExpAt(int monExpRate, int monLevel);
static void Pokemon_LoadExperienceTableOf(enum PokemonExpRate monExpRate, u32 *monExpTable);
static u32 Pokemon_GetExpRateBaseExpAt(enum PokemonExpRate monExpRate, int monLevel);
static u16 Pokemon_GetNatureStatValue(u8 monNature, u16 monStatValue, u8 statType);
static u8 BoxPokemon_IsShiny(BoxPokemon *boxMon);
static inline BOOL Pokemon_InlineIsPersonalityShiny(u32 monOTID, u32 monPersonality);
Expand Down Expand Up @@ -2201,16 +2201,16 @@ u32 Pokemon_GetSpeciesBaseExpAt(int monSpecies, int monLevel)
return Pokemon_GetExpRateBaseExpAt(PokemonPersonalData_GetSpeciesValue(monSpecies, MON_DATA_PERSONAL_EXP_RATE), monLevel);
}

static void Pokemon_LoadExperienceTableOf(int monExpRate, u32 *monExpTable)
static void Pokemon_LoadExperienceTableOf(enum PokemonExpRate monExpRate, u32 *monExpTable)
{
// TODO const for table size, enum for exp rate types
// TODO const for table size
GF_ASSERT(monExpRate < 8);
NARC_ReadWholeMemberByIndexPair(monExpTable, NARC_INDEX_POKETOOL__PERSONAL__PL_GROWTBL, monExpRate);
}

static u32 Pokemon_GetExpRateBaseExpAt(int monExpRate, int monLevel)
static u32 Pokemon_GetExpRateBaseExpAt(enum PokemonExpRate monExpRate, int monLevel)
{
// TODO const for table size, enum for exp rate types
// TODO const for table size
GF_ASSERT(monExpRate < 8);
GF_ASSERT(monLevel <= 101);

Expand Down Expand Up @@ -2251,10 +2251,10 @@ u32 Pokemon_GetSpeciesLevelAt(u16 monSpecies, u32 monExp)

u32 PokemonPersonalData_GetLevelAt(PokemonPersonalData *monPersonalData, u16 unused_monSpecies, u32 monExp)
{
// TODO const for table size, enum for exp rate types
// TODO const for table size
static u32 monExpTable[101];

int monExpRate = PokemonPersonalData_GetValue(monPersonalData, MON_DATA_PERSONAL_EXP_RATE);
enum PokemonExpRate monExpRate = PokemonPersonalData_GetValue(monPersonalData, MON_DATA_PERSONAL_EXP_RATE);
Pokemon_LoadExperienceTableOf(monExpRate, monExpTable);

int i;
Expand Down
51 changes: 51 additions & 0 deletions tools/scripts/make_pl_growtbl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
import argparse
import csv
import pathlib
import subprocess


argparser = argparse.ArgumentParser(
prog='make_pl_growtbl',
description='Packs the archive containing pokemon exp tables'
)
argparser.add_argument('-k', '--knarc',
required=True,
help='Path to knarc executable')
argparser.add_argument('-s', '--source-dir',
required=True,
help='Path to the source directory (res/pokemon)')
argparser.add_argument('-p', '--private-dir',
required=True,
help='Path to the private directory (where binaries will be made)')
argparser.add_argument('-o', '--output-dir',
required=True,
help='Path to the output directory (where the NARC will be made)')
argparser.add_argument('table',
help='Experience tables in csv format')
args = argparser.parse_args()

source_dir = pathlib.Path(args.source_dir)
private_dir = pathlib.Path(args.private_dir)
output_dir = pathlib.Path(args.output_dir)

private_dir.mkdir(parents=True, exist_ok=True)

with open(args.table) as data_file:
file_reader = csv.reader(data_file)
table_data = list(file_reader)
transpose = list(zip(*table_data))
count = 0
for table in transpose:
if table[0] == 'level':
continue
out = bytes()
for n in table[1:]:
out = out + int(n).to_bytes(4, byteorder='little')

target_fname = private_dir / f'pl_growtbl_{count}.bin'
with open(target_fname, 'wb+') as target_file:
target_file.write(out)
count += 1

subprocess.run([args.knarc, '-d', private_dir, '-p', output_dir / 'pl_growtbl.narc'])
1 change: 1 addition & 0 deletions tools/scripts/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ make_height_py = find_program('make_height.py', native: true)
make_script_bin_sh = find_program('make_script_bin.sh', native: true)
make_pl_pokezukan_py = find_program('make_pl_pokezukan.py', native: true)
make_shinzukan_py = find_program('make_shinzukan.py', native: true)
make_pl_growtbl_py = find_program('make_pl_growtbl.py', native: true)
Loading