From e8385d812ba327f1019d1f59987233684a6e378d Mon Sep 17 00:00:00 2001 From: Atemo Date: Tue, 8 Jun 2021 19:59:49 +0200 Subject: [PATCH] Converted exp_homun database to yaml (#6002) * Converts the Homunculus Experience Database into YAML. * Includes CSV2YAML converter. Thanks to @Lemongrass3110 ! --- db/exp_homun.yml | 39 ++++ db/import-tmpl/exp_homun.txt | 1 - db/import-tmpl/exp_homun.yml | 31 +++ db/pre-re/exp_homun.txt | 100 --------- db/pre-re/exp_homun.yml | 229 +++++++++++++++++++++ db/re/exp_homun.txt | 176 ---------------- db/re/exp_homun.yml | 381 +++++++++++++++++++++++++++++++++++ doc/yaml/db/exp_homun.yml | 10 + src/map/homunculus.cpp | 113 ++++++----- src/map/homunculus.hpp | 18 ++ src/map/map-server.vcxproj | 2 +- src/tool/csv2yaml.cpp | 46 +++++ src/tool/csv2yaml.hpp | 1 + 13 files changed, 820 insertions(+), 327 deletions(-) create mode 100644 db/exp_homun.yml delete mode 100644 db/import-tmpl/exp_homun.txt create mode 100644 db/import-tmpl/exp_homun.yml delete mode 100644 db/pre-re/exp_homun.txt create mode 100644 db/pre-re/exp_homun.yml delete mode 100644 db/re/exp_homun.txt create mode 100644 db/re/exp_homun.yml create mode 100644 doc/yaml/db/exp_homun.yml diff --git a/db/exp_homun.yml b/db/exp_homun.yml new file mode 100644 index 0000000000..c0a736438f --- /dev/null +++ b/db/exp_homun.yml @@ -0,0 +1,39 @@ +# This file is a part of rAthena. +# Copyright(C) 2021 rAthena Development Team +# https://rathena.org - https://github.com/rathena +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +########################################################################### +# Homunculus Experience Database +########################################################################### +# +# Homunculus Experience Settings +# +########################################################################### +# - Level Level required. +# Exp Experience required for the next level. +########################################################################### + +Header: + Type: HOMUN_EXP_DB + Version: 1 + +Footer: + Imports: + - Path: db/pre-re/exp_homun.yml + Mode: Prerenewal + - Path: db/re/exp_homun.yml + Mode: Renewal + - Path: db/import/exp_homun.yml diff --git a/db/import-tmpl/exp_homun.txt b/db/import-tmpl/exp_homun.txt deleted file mode 100644 index 2da0c7a7cc..0000000000 --- a/db/import-tmpl/exp_homun.txt +++ /dev/null @@ -1 +0,0 @@ -// Homunculus Experience Tables diff --git a/db/import-tmpl/exp_homun.yml b/db/import-tmpl/exp_homun.yml new file mode 100644 index 0000000000..0ea2aff841 --- /dev/null +++ b/db/import-tmpl/exp_homun.yml @@ -0,0 +1,31 @@ +# This file is a part of rAthena. +# Copyright(C) 2021 rAthena Development Team +# https://rathena.org - https://github.com/rathena +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +########################################################################### +# Homunculus Experience Database +########################################################################### +# +# Homunculus Experience Settings +# +########################################################################### +# - Level Level required. +# Exp Experience required for the next level. +########################################################################### + +Header: + Type: HOMUN_EXP_DB + Version: 1 diff --git a/db/pre-re/exp_homun.txt b/db/pre-re/exp_homun.txt deleted file mode 100644 index e001c0bc37..0000000000 --- a/db/pre-re/exp_homun.txt +++ /dev/null @@ -1,100 +0,0 @@ -// Homunculus Experience Tables -50 -110 -180 -260 -350 -630 -950 -1310 -1710 -2150 -3180 -4300 -5510 -6810 -8200 -10800 -13560 -16480 -19560 -22800 -28090 -33630 -39420 -45460 -51750 -61500 -70910 -81030 -91510 -102350 -117580 -133300 -149510 -166210 -183400 -206480 -230200 -254560 -279560 -305200 -338450 -372510 -407380 -443060 -479550 -525590 -572630 -620670 -669710 -719750 -781500 -844460 -908630 -974010 -1040600 -1121280 -1203400 -1286960 -1371960 -1458400 -1561530 -1666350 -1772860 -1881060 -1990950 -2120350 -2251710 -2385030 -2520310 -2657550 -2817340 -2979380 -3143670 -3310210 -3479000 -3673600 -3870760 -4070480 -4272760 -4477600 -4711730 -4948750 -5188660 -5431460 -5677150 -5955830 -6237750 -6522910 -6811310 -7102950 -7431500 -7763660 -8099430 -8438810 -8781800 -9165840 -9553880 -9945920 -0 diff --git a/db/pre-re/exp_homun.yml b/db/pre-re/exp_homun.yml new file mode 100644 index 0000000000..ea59e0dfd6 --- /dev/null +++ b/db/pre-re/exp_homun.yml @@ -0,0 +1,229 @@ +# This file is a part of rAthena. +# Copyright(C) 2021 rAthena Development Team +# https://rathena.org - https://github.com/rathena +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +########################################################################### +# Homunculus Experience Database +########################################################################### +# +# Homunculus Experience Settings +# +########################################################################### +# - Level Level required. +# Exp Experience required for the next level. +########################################################################### + +Header: + Type: HOMUN_EXP_DB + Version: 1 + +Body: + - Level: 1 + Exp: 50 + - Level: 2 + Exp: 110 + - Level: 3 + Exp: 180 + - Level: 4 + Exp: 260 + - Level: 5 + Exp: 350 + - Level: 6 + Exp: 630 + - Level: 7 + Exp: 950 + - Level: 8 + Exp: 1310 + - Level: 9 + Exp: 1710 + - Level: 10 + Exp: 2150 + - Level: 11 + Exp: 3180 + - Level: 12 + Exp: 4300 + - Level: 13 + Exp: 5510 + - Level: 14 + Exp: 6810 + - Level: 15 + Exp: 8200 + - Level: 16 + Exp: 10800 + - Level: 17 + Exp: 13560 + - Level: 18 + Exp: 16480 + - Level: 19 + Exp: 19560 + - Level: 20 + Exp: 22800 + - Level: 21 + Exp: 28090 + - Level: 22 + Exp: 33630 + - Level: 23 + Exp: 39420 + - Level: 24 + Exp: 45460 + - Level: 25 + Exp: 51750 + - Level: 26 + Exp: 61500 + - Level: 27 + Exp: 70910 + - Level: 28 + Exp: 81030 + - Level: 29 + Exp: 91510 + - Level: 30 + Exp: 102350 + - Level: 31 + Exp: 117580 + - Level: 32 + Exp: 133300 + - Level: 33 + Exp: 149510 + - Level: 34 + Exp: 166210 + - Level: 35 + Exp: 183400 + - Level: 36 + Exp: 206480 + - Level: 37 + Exp: 230200 + - Level: 38 + Exp: 254560 + - Level: 39 + Exp: 279560 + - Level: 40 + Exp: 305200 + - Level: 41 + Exp: 338450 + - Level: 42 + Exp: 372510 + - Level: 43 + Exp: 407380 + - Level: 44 + Exp: 443060 + - Level: 45 + Exp: 479550 + - Level: 46 + Exp: 525590 + - Level: 47 + Exp: 572630 + - Level: 48 + Exp: 620670 + - Level: 49 + Exp: 669710 + - Level: 50 + Exp: 719750 + - Level: 51 + Exp: 781500 + - Level: 52 + Exp: 844460 + - Level: 53 + Exp: 908630 + - Level: 54 + Exp: 974010 + - Level: 55 + Exp: 1040600 + - Level: 56 + Exp: 1121280 + - Level: 57 + Exp: 1203400 + - Level: 58 + Exp: 1286960 + - Level: 59 + Exp: 1371960 + - Level: 60 + Exp: 1458400 + - Level: 61 + Exp: 1561530 + - Level: 62 + Exp: 1666350 + - Level: 63 + Exp: 1772860 + - Level: 64 + Exp: 1881060 + - Level: 65 + Exp: 1990950 + - Level: 66 + Exp: 2120350 + - Level: 67 + Exp: 2251710 + - Level: 68 + Exp: 2385030 + - Level: 69 + Exp: 2520310 + - Level: 70 + Exp: 2657550 + - Level: 71 + Exp: 2817340 + - Level: 72 + Exp: 2979380 + - Level: 73 + Exp: 3143670 + - Level: 74 + Exp: 3310210 + - Level: 75 + Exp: 3479000 + - Level: 76 + Exp: 3673600 + - Level: 77 + Exp: 3870760 + - Level: 78 + Exp: 4070480 + - Level: 79 + Exp: 4272760 + - Level: 80 + Exp: 4477600 + - Level: 81 + Exp: 4711730 + - Level: 82 + Exp: 4948750 + - Level: 83 + Exp: 5188660 + - Level: 84 + Exp: 5431460 + - Level: 85 + Exp: 5677150 + - Level: 86 + Exp: 5955830 + - Level: 87 + Exp: 6237750 + - Level: 88 + Exp: 6522910 + - Level: 89 + Exp: 6811310 + - Level: 90 + Exp: 7102950 + - Level: 91 + Exp: 7431500 + - Level: 92 + Exp: 7763660 + - Level: 93 + Exp: 8099430 + - Level: 94 + Exp: 8438810 + - Level: 95 + Exp: 8781800 + - Level: 96 + Exp: 9165840 + - Level: 97 + Exp: 9553880 + - Level: 98 + Exp: 9945920 diff --git a/db/re/exp_homun.txt b/db/re/exp_homun.txt deleted file mode 100644 index 26f1146f7a..0000000000 --- a/db/re/exp_homun.txt +++ /dev/null @@ -1,176 +0,0 @@ -// Homunculus Experience Tables -50 -110 -180 -260 -350 -630 -950 -1310 -1710 -2150 -3180 -4300 -5510 -6810 -8200 -10800 -13560 -16480 -19560 -22800 -28090 -33630 -39420 -45460 -51750 -61150 -70910 -81030 -91510 -102350 -117580 -133300 -149510 -166210 -183400 -206480 -230200 -254560 -279560 -305200 -338450 -372510 -407380 -443060 -479550 -525590 -572630 -620670 -669710 -719750 -781500 -844460 -908630 -974010 -1040600 -1121280 -1203400 -1286960 -1371960 -1458400 -1561530 -1666350 -1772860 -1881060 -1990950 -2120350 -2251710 -2385030 -2520310 -2657550 -2817340 -2979380 -3143670 -3310210 -3479000 -3673600 -3870760 -4070480 -4272760 -4477600 -4711730 -4948750 -5188660 -5431460 -5677150 -5955830 -6237750 -6522910 -6811310 -7102950 -7431500 -7763660 -8099430 -8438810 -8781800 -9165840 -9553880 -9945920 -10350000 -10462000 -10580000 -10700000 -10826000 -10980000 -11150000 -11334000 -11520000 -11712000 -11906000 -12108000 -12317000 -12530000 -12745000 -12968000 -13193000 -13420000 -13653000 -13890000 -14130000 -14374200 -14620000 -14870000 -15123200 -15378000 -15638000 -15900000 -16164000 -16430000 -16698000 -16970000 -17245000 -17523000 -17804000 -18090000 -18380000 -18675000 -18974000 -19280000 -19588000 -19900000 -20215000 -20534000 -20854200 -21180000 -21509500 -21847000 -22197000 -22558000 -22930000 -23320000 -24500000 -25750000 -26750000 -28000000 -29000000 -30250000 -31250000 -32500000 -33500000 -34750000 -36250000 -38050000 -40210000 -42800000 -47982500 -50572500 -53680000 -57410000 -61887500 -70842500 -75320000 -80692500 -87140000 -94875000 -0 diff --git a/db/re/exp_homun.yml b/db/re/exp_homun.yml new file mode 100644 index 0000000000..1e06b33e97 --- /dev/null +++ b/db/re/exp_homun.yml @@ -0,0 +1,381 @@ +# This file is a part of rAthena. +# Copyright(C) 2021 rAthena Development Team +# https://rathena.org - https://github.com/rathena +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +########################################################################### +# Homunculus Experience Database +########################################################################### +# +# Homunculus Experience Settings +# +########################################################################### +# - Level Level required. +# Exp Experience required for the next level. +########################################################################### + +Header: + Type: HOMUN_EXP_DB + Version: 1 + +Body: + - Level: 1 + Exp: 50 + - Level: 2 + Exp: 110 + - Level: 3 + Exp: 180 + - Level: 4 + Exp: 260 + - Level: 5 + Exp: 350 + - Level: 6 + Exp: 630 + - Level: 7 + Exp: 950 + - Level: 8 + Exp: 1310 + - Level: 9 + Exp: 1710 + - Level: 10 + Exp: 2150 + - Level: 11 + Exp: 3180 + - Level: 12 + Exp: 4300 + - Level: 13 + Exp: 5510 + - Level: 14 + Exp: 6810 + - Level: 15 + Exp: 8200 + - Level: 16 + Exp: 10800 + - Level: 17 + Exp: 13560 + - Level: 18 + Exp: 16480 + - Level: 19 + Exp: 19560 + - Level: 20 + Exp: 22800 + - Level: 21 + Exp: 28090 + - Level: 22 + Exp: 33630 + - Level: 23 + Exp: 39420 + - Level: 24 + Exp: 45460 + - Level: 25 + Exp: 51750 + - Level: 26 + Exp: 61150 + - Level: 27 + Exp: 70910 + - Level: 28 + Exp: 81030 + - Level: 29 + Exp: 91510 + - Level: 30 + Exp: 102350 + - Level: 31 + Exp: 117580 + - Level: 32 + Exp: 133300 + - Level: 33 + Exp: 149510 + - Level: 34 + Exp: 166210 + - Level: 35 + Exp: 183400 + - Level: 36 + Exp: 206480 + - Level: 37 + Exp: 230200 + - Level: 38 + Exp: 254560 + - Level: 39 + Exp: 279560 + - Level: 40 + Exp: 305200 + - Level: 41 + Exp: 338450 + - Level: 42 + Exp: 372510 + - Level: 43 + Exp: 407380 + - Level: 44 + Exp: 443060 + - Level: 45 + Exp: 479550 + - Level: 46 + Exp: 525590 + - Level: 47 + Exp: 572630 + - Level: 48 + Exp: 620670 + - Level: 49 + Exp: 669710 + - Level: 50 + Exp: 719750 + - Level: 51 + Exp: 781500 + - Level: 52 + Exp: 844460 + - Level: 53 + Exp: 908630 + - Level: 54 + Exp: 974010 + - Level: 55 + Exp: 1040600 + - Level: 56 + Exp: 1121280 + - Level: 57 + Exp: 1203400 + - Level: 58 + Exp: 1286960 + - Level: 59 + Exp: 1371960 + - Level: 60 + Exp: 1458400 + - Level: 61 + Exp: 1561530 + - Level: 62 + Exp: 1666350 + - Level: 63 + Exp: 1772860 + - Level: 64 + Exp: 1881060 + - Level: 65 + Exp: 1990950 + - Level: 66 + Exp: 2120350 + - Level: 67 + Exp: 2251710 + - Level: 68 + Exp: 2385030 + - Level: 69 + Exp: 2520310 + - Level: 70 + Exp: 2657550 + - Level: 71 + Exp: 2817340 + - Level: 72 + Exp: 2979380 + - Level: 73 + Exp: 3143670 + - Level: 74 + Exp: 3310210 + - Level: 75 + Exp: 3479000 + - Level: 76 + Exp: 3673600 + - Level: 77 + Exp: 3870760 + - Level: 78 + Exp: 4070480 + - Level: 79 + Exp: 4272760 + - Level: 80 + Exp: 4477600 + - Level: 81 + Exp: 4711730 + - Level: 82 + Exp: 4948750 + - Level: 83 + Exp: 5188660 + - Level: 84 + Exp: 5431460 + - Level: 85 + Exp: 5677150 + - Level: 86 + Exp: 5955830 + - Level: 87 + Exp: 6237750 + - Level: 88 + Exp: 6522910 + - Level: 89 + Exp: 6811310 + - Level: 90 + Exp: 7102950 + - Level: 91 + Exp: 7431500 + - Level: 92 + Exp: 7763660 + - Level: 93 + Exp: 8099430 + - Level: 94 + Exp: 8438810 + - Level: 95 + Exp: 8781800 + - Level: 96 + Exp: 9165840 + - Level: 97 + Exp: 9553880 + - Level: 98 + Exp: 9945920 + - Level: 99 + Exp: 10350000 + - Level: 100 + Exp: 10462000 + - Level: 101 + Exp: 10580000 + - Level: 102 + Exp: 10700000 + - Level: 103 + Exp: 10826000 + - Level: 104 + Exp: 10980000 + - Level: 105 + Exp: 11150000 + - Level: 106 + Exp: 11334000 + - Level: 107 + Exp: 11520000 + - Level: 108 + Exp: 11712000 + - Level: 109 + Exp: 11906000 + - Level: 110 + Exp: 12108000 + - Level: 111 + Exp: 12317000 + - Level: 112 + Exp: 12530000 + - Level: 113 + Exp: 12745000 + - Level: 114 + Exp: 12968000 + - Level: 115 + Exp: 13193000 + - Level: 116 + Exp: 13420000 + - Level: 117 + Exp: 13653000 + - Level: 118 + Exp: 13890000 + - Level: 119 + Exp: 14130000 + - Level: 120 + Exp: 14374200 + - Level: 121 + Exp: 14620000 + - Level: 122 + Exp: 14870000 + - Level: 123 + Exp: 15123200 + - Level: 124 + Exp: 15378000 + - Level: 125 + Exp: 15638000 + - Level: 126 + Exp: 15900000 + - Level: 127 + Exp: 16164000 + - Level: 128 + Exp: 16430000 + - Level: 129 + Exp: 16698000 + - Level: 130 + Exp: 16970000 + - Level: 131 + Exp: 17245000 + - Level: 132 + Exp: 17523000 + - Level: 133 + Exp: 17804000 + - Level: 134 + Exp: 18090000 + - Level: 135 + Exp: 18380000 + - Level: 136 + Exp: 18675000 + - Level: 137 + Exp: 18974000 + - Level: 138 + Exp: 19280000 + - Level: 139 + Exp: 19588000 + - Level: 140 + Exp: 19900000 + - Level: 141 + Exp: 20215000 + - Level: 142 + Exp: 20534000 + - Level: 143 + Exp: 20854200 + - Level: 144 + Exp: 21180000 + - Level: 145 + Exp: 21509500 + - Level: 146 + Exp: 21847000 + - Level: 147 + Exp: 22197000 + - Level: 148 + Exp: 22558000 + - Level: 149 + Exp: 22930000 + - Level: 150 + Exp: 23320000 + - Level: 151 + Exp: 24500000 + - Level: 152 + Exp: 25750000 + - Level: 153 + Exp: 26750000 + - Level: 154 + Exp: 28000000 + - Level: 155 + Exp: 29000000 + - Level: 156 + Exp: 30250000 + - Level: 157 + Exp: 31250000 + - Level: 158 + Exp: 32500000 + - Level: 159 + Exp: 33500000 + - Level: 160 + Exp: 34750000 + - Level: 161 + Exp: 36250000 + - Level: 162 + Exp: 38050000 + - Level: 163 + Exp: 40210000 + - Level: 164 + Exp: 42800000 + - Level: 165 + Exp: 47982500 + - Level: 166 + Exp: 50572500 + - Level: 167 + Exp: 53680000 + - Level: 168 + Exp: 57410000 + - Level: 169 + Exp: 61887500 + - Level: 170 + Exp: 70842500 + - Level: 171 + Exp: 75320000 + - Level: 172 + Exp: 80692500 + - Level: 173 + Exp: 87140000 + - Level: 174 + Exp: 94875000 diff --git a/doc/yaml/db/exp_homun.yml b/doc/yaml/db/exp_homun.yml new file mode 100644 index 0000000000..4cf004378a --- /dev/null +++ b/doc/yaml/db/exp_homun.yml @@ -0,0 +1,10 @@ +########################################################################### +# Homunculus Experience Database +########################################################################### +# +# Homunculus Experience Settings +# +########################################################################### +# - Level Level required. +# Exp Experience required for the next level. +########################################################################### diff --git a/src/map/homunculus.cpp b/src/map/homunculus.cpp index 79846f2a0e..989f9e1b85 100644 --- a/src/map/homunculus.cpp +++ b/src/map/homunculus.cpp @@ -30,7 +30,6 @@ struct homun_skill_tree_entry hskill_tree[MAX_HOMUNCULUS_CLASS][MAX_HOM_SKILL_TR static TIMER_FUNC(hom_hungry); static uint16 homunculus_count; -static t_exp hexptbl[MAX_LEVEL]; //For holding the view data of npc classes. [Skotlex] static struct view_data hom_viewdb[MAX_HOMUNCULUS_CLASS]; @@ -51,6 +50,65 @@ static struct s_homun_intimacy_grade intimacy_grades[] = { { /*"Loyal", */ 91100 }, }; +const std::string HomExpDatabase::getDefaultLocation() { + return std::string(db_path) + "/exp_homun.yml"; +} + +uint64 HomExpDatabase::parseBodyNode(const YAML::Node &node) { + if (!this->nodesExist(node, { "Level", "Exp" })) { + return 0; + } + + uint16 level; + + if (!this->asUInt16(node, "Level", level)) + return 0; + + uint64 exp; + + if (!this->asUInt64(node, "Exp", exp)) + return 0; + + if (level == 0) { + this->invalidWarning(node["Level"], "The minimum level is 1.\n"); + return 0; + } + if (level >= MAX_LEVEL) { + this->invalidWarning(node["Level"], "Homunculus level %d exceeds maximum level %d, skipping.\n", level, MAX_LEVEL); + return 0; + } + + std::shared_ptr homun_exp = this->find(level); + bool exists = homun_exp != nullptr; + + if (!exists) { + homun_exp = std::make_shared(); + homun_exp->level = level; + } + + homun_exp->exp = static_cast(exp); + + if (!exists) + this->put(level, homun_exp); + + return 1; +} + +HomExpDatabase homun_exp_db; + +/** + * Returns the experience required to level up according to the table. + * @param level: Homunculus level + * @return Experience + */ +t_exp HomExpDatabase::get_nextexp(uint16 level) { + auto next_exp = this->find(level); + if (next_exp) + return next_exp->exp; + else + return 0; +} + /** * Check if the skill is a valid homunculus skill based skill range or availablity in skill db * @param skill_id @@ -493,7 +551,7 @@ int hom_levelup(struct homun_data *hd) hom->skillpts++ ; //1 skillpoint each 3 base level hom->exp -= hd->exp_next ; - hd->exp_next = hexptbl[hom->level - 1] ; + hd->exp_next = homun_exp_db.get_nextexp(hom->level); if (!max) { max = &hd->homunculusDB->gmax; @@ -1042,7 +1100,7 @@ void hom_alloc(struct map_session_data *sd, struct s_homunculus *hom) hd->master = sd; hd->homunculusDB = &homunculus_db[i]; memcpy(&hd->homunculus, hom, sizeof(struct s_homunculus)); - hd->exp_next = hexptbl[hd->homunculus.level - 1]; + hd->exp_next = homun_exp_db.get_nextexp(hd->homunculus.level); status_set_viewdata(&hd->bl, hd->homunculus.class_); status_change_init(&hd->bl); @@ -1323,7 +1381,7 @@ void hom_reset_stats(struct homun_data *hd) hom->dex = base->dex *10; hom->luk = base->luk *10; hom->exp = 0; - hd->exp_next = hexptbl[0]; + hd->exp_next = homun_exp_db.get_nextexp(hom->level); memset(&hd->homunculus.hskill, 0, sizeof hd->homunculus.hskill); hd->homunculus.skillpts = 0; } @@ -1613,52 +1671,9 @@ static void read_homunculus_skilldb(void) { } } -/** -* Read homunculus exp db -*/ -void read_homunculus_expdb(void) -{ - int i; - const char *filename[]={ - DBPATH"exp_homun.txt", - DBIMPORT"/exp_homun.txt" - }; - - memset(hexptbl,0,sizeof(hexptbl)); - for (i = 0; i < ARRAYLENGTH(filename); i++) { - FILE *fp; - char path[1024]; - char line[1024]; - int j=0; - - sprintf(path, "%s/%s", db_path, filename[i]); - fp = fopen(path,"r"); - if (fp == NULL) { - if (i != 0) - continue; - ShowError("read_homunculus_expdb: Can't read %s\n",line); - return; - } - while (fgets(line, sizeof(line), fp) && j < MAX_LEVEL) { - if (line[0] == '/' && line[1] == '/') - continue; - - hexptbl[j] = strtoull(line, NULL, 10); - if (!hexptbl[j++]) - break; - } - if (hexptbl[MAX_LEVEL - 1]) { // Last permitted level have to be 0! - ShowWarning("read_homunculus_expdb: Reached max level in %s [%d]. Remaining lines were not read.\n ",path,MAX_LEVEL); - hexptbl[MAX_LEVEL - 1] = 0; - } - fclose(fp); - ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' levels in '" CL_WHITE "%s" CL_RESET "'.\n", j, path); - } -} - void hom_reload(void){ read_homunculusdb(); - read_homunculus_expdb(); + homun_exp_db.reload(); } void hom_reload_skill(void){ @@ -1669,7 +1684,7 @@ void do_init_homunculus(void){ int class_; read_homunculusdb(); - read_homunculus_expdb(); + homun_exp_db.load(); read_homunculus_skilldb(); // Add homunc timer function to timer func list [Toms] diff --git a/src/map/homunculus.hpp b/src/map/homunculus.hpp index e9732eb80b..c584780157 100644 --- a/src/map/homunculus.hpp +++ b/src/map/homunculus.hpp @@ -4,7 +4,9 @@ #ifndef HOMUNCULUS_HPP #define HOMUNCULUS_HPP +#include #include "../common/cbasetypes.hpp" +#include "../common/database.hpp" #include "status.hpp" // struct status_data, struct status_change #include "unit.hpp" // struct unit_data @@ -20,6 +22,22 @@ #define APPLY_HOMUN_LEVEL_STATWEIGHT() #endif +struct s_homun_exp_db { + uint16 level; + t_exp exp; +}; + +class HomExpDatabase : public TypesafeYamlDatabase { +public: + HomExpDatabase() : TypesafeYamlDatabase("HOMUN_EXP_DB", 1) { + + } + + const std::string getDefaultLocation(); + uint64 parseBodyNode(const YAML::Node& node); + t_exp get_nextexp(uint16 level); +}; + struct h_stats { unsigned int HP, SP; unsigned short str, agi, vit, int_, dex, luk; diff --git a/src/map/map-server.vcxproj b/src/map/map-server.vcxproj index 258fc46c8b..2e584416f7 100644 --- a/src/map/map-server.vcxproj +++ b/src/map/map-server.vcxproj @@ -306,7 +306,7 @@ - + diff --git a/src/tool/csv2yaml.cpp b/src/tool/csv2yaml.cpp index 17c789ccca..a0460c7e74 100644 --- a/src/tool/csv2yaml.cpp +++ b/src/tool/csv2yaml.cpp @@ -291,6 +291,18 @@ int do_init( int argc, char** argv ){ return 0; } + if (!process("HOMUN_EXP_DB", 1, { path_db_mode }, "exp_homun", [](const std::string &path, const std::string &name_ext) -> bool { + return read_homunculus_expdb((path + name_ext).c_str()); + })) { + return 0; + } + + if (!process("HOMUN_EXP_DB", 1, { path_db_import }, "exp_homun", [](const std::string &path, const std::string &name_ext) -> bool { + return read_homunculus_expdb((path + name_ext).c_str()); + })) { + return 0; + } + // TODO: add implementations ;-) return 0; @@ -3451,3 +3463,37 @@ static bool mob_parse_row_chatdb(char* fields[], int columns, int current) { return true; } +// Copied and adjusted from homunculus.cpp +static bool read_homunculus_expdb(const char* file) { + FILE* fp = fopen( file, "r" ); + + if( fp == nullptr ){ + ShowError( "Can't read %s\n", file ); + return false; + } + + uint32 lines = 0, count = 0; + char line[1024]; + + while (fgets(line, sizeof(line), fp)) { + lines++; + + if (line[0] == '/' && line[1] == '/') // Ignore comments + continue; + + t_exp exp = strtoull(line, nullptr, 10); + + if( exp > 0 ){ + body << YAML::BeginMap; + body << YAML::Key << "Level" << YAML::Value << (count+1); + body << YAML::Key << "Exp" << YAML::Value << exp; + body << YAML::EndMap; + } + + count++; + } + + fclose(fp); + ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file); + return true; +} diff --git a/src/tool/csv2yaml.hpp b/src/tool/csv2yaml.hpp index f806c33ff2..551748e8ae 100644 --- a/src/tool/csv2yaml.hpp +++ b/src/tool/csv2yaml.hpp @@ -381,5 +381,6 @@ static bool itemdb_randomopt_group_yaml(void); static bool pc_readdb_levelpenalty(char* fields[], int columns, int current); static bool pc_levelpenalty_yaml(); static bool mob_parse_row_chatdb(char* fields[], int columns, int current); +static bool read_homunculus_expdb(const char* file); #endif /* CSV2YAML_HPP */