Converted Abra Database to YAML (#4480)

* Removed useless skill name usage in the database.
This commit is contained in:
Aleos
2019-12-18 18:40:50 -05:00
committed by GitHub
parent 84bdf59e36
commit 2fc7472001
9 changed files with 547 additions and 290 deletions

View File

@@ -70,6 +70,7 @@ int getch( void ){
static bool guild_read_guildskill_tree_db( char* split[], int columns, int current );
static size_t pet_read_db( const char* file );
static bool skill_parse_row_magicmushroomdb(char* split[], int column, int current);
static bool skill_parse_row_abradb(char* split[], int columns, int current);
// Constants for conversion
std::unordered_map<uint16, std::string> aegis_itemnames;
@@ -241,6 +242,12 @@ int do_init( int argc, char** argv ){
return 0;
}
if (!process("ABRA_DB", 1, root_paths, "abra_db", [](const std::string& path, const std::string& name_ext) -> bool {
return sv_readdb(path.c_str(), name_ext.c_str(), ',', 3, 3, -1, &skill_parse_row_abradb, false);
})) {
return 0;
}
// TODO: add implementations ;-)
return 0;
@@ -426,6 +433,34 @@ static bool parse_skill_constants( char* split[], int columns, int current ){
return true;
}
/**
* Split the string with ':' as separator and put each value for a skilllv
* if no more value found put the last value to fill the array
* @param str: String to split
* @param val: Array of MAX_SKILL_LEVEL to put value into
* @return 0:error, x:number of value assign (should be MAX_SKILL_LEVEL)
*/
int skill_split_atoi(char *str, int *val) {
int i;
for (i = 0; i < MAX_SKILL_LEVEL; i++) {
if (!str)
break;
val[i] = atoi(str);
str = strchr(str, ':');
if (str)
*str++ = 0;
}
if (i == 0) // No data found.
return 0;
if (i == 1) // Single value, have the whole range have the same value.
return 1;
return i;
}
// Implementation of the conversion functions
// Copied and adjusted from guild.cpp
@@ -654,6 +689,7 @@ static size_t pet_read_db( const char* file ){
return entries;
}
// Copied and adjusted from skill.cpp
static bool skill_parse_row_magicmushroomdb(char* split[], int column, int current)
{
uint16 skill_id = atoi(split[0]);
@@ -670,3 +706,43 @@ static bool skill_parse_row_magicmushroomdb(char* split[], int column, int curre
return true;
}
// Copied and adjusted from skill.cpp
static bool skill_parse_row_abradb(char* split[], int columns, int current)
{
uint16 skill_id = atoi(split[0]);
std::string *skill_name = util::umap_find(aegis_skillnames, skill_id);
if (skill_name == nullptr) {
ShowError("Skill name for Abra skill ID &hu is not known.\n", skill_id);
return false;
}
body << YAML::BeginMap;
body << YAML::Key << "Skill" << YAML::Value << *skill_name;
int arr[MAX_SKILL_LEVEL];
int arr_size = skill_split_atoi(split[2], arr);
if (arr_size == 1) {
if (arr[0] != 500)
body << YAML::Key << "Probability" << YAML::Value << arr[0];
} else {
body << YAML::Key << "Probability";
body << YAML::BeginSeq;
for (int i = 0; i < arr_size; i++) {
if (arr[i] > 0) {
body << YAML::BeginMap;
body << YAML::Key << "Level" << YAML::Value << i + 1;
body << YAML::Key << "Probability" << YAML::Value << arr[i];
body << YAML::EndMap;
}
}
body << YAML::EndSeq;
}
body << YAML::EndMap;
return true;
}