Converted const.txt to YAML (#6187)

* Converts the Constant Tables file into YAML.
* Includes CSV2YAML converter.

Co-authored-by: Aleos <aleos89@users.noreply.github.com>
Co-authored-by: Lemongrass3110 <lemongrass@kstp.at>
This commit is contained in:
Atemo 2021-08-27 23:54:31 +02:00 committed by GitHub
parent 72aafdadea
commit fe7cb5a33f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 186 additions and 86 deletions

View File

@ -1,21 +0,0 @@
// Script Constant Database
//
// Structure of Database:
// Identifier Value[ Type]
//
// Alternatively:
// Identifier,Value[,Type]
//
// 01. Identifier Unique name for the constant, must not have same name as script commands, functions or variables.
// 02. Value Value assigned to the constant. This value cannot be changed during the runtime of the server.
// 03. Type Specifies whether the identifier is a constant (0) or a parameter (1) (optional, defaults to 0).
//
// NOTE: Parameters are special in that they retrieve certain runtime values depending on the specified ID
// in field Value. Depending on the implementation values assigned by scripts to parameters will affect
// runtime values, such as Zeny, as well (see pc_readparam/pc_setparam).
SWORDCLAN 1
ARCWANDCLAN 2
GOLDENMACECLAN 3
CROSSBOWCLAN 4
JUMPINGCLAN 5

51
db/const.yml Normal file
View File

@ -0,0 +1,51 @@
# 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 <http://www.gnu.org/licenses/>.
#
###########################################################################
# Script Constant Database
###########################################################################
#
# Script Constant Settings
#
###########################################################################
# - Name Unique name for the constant. Must not have same name as script commands, functions, or variables.
# Value Value assigned to the constant. This value cannot be changed during the runtime of the server.
# Parameter Specifies whether the identifier is a parameter. (Default: false)
# Note: Parameters are special in that they retrieve certain runtime values depending on the specified ID
# in field Value. Depending on the implementation values assigned by scripts the parameters will affect
# runtime values, such as Zeny, as well (see pc_readparam/pc_setparam).
###########################################################################
Header:
Type: CONSTANT_DB
Version: 1
Body:
- Name: SWORDCLAN
Value: 1
- Name: ARCWANDCLAN
Value: 2
- Name: GOLDENMACECLAN
Value: 3
- Name: CROSSBOWCLAN
Value: 4
- Name: JUMPINGCLAN
Value: 5
Footer:
Imports:
- Path: db/import/const.yml

View File

@ -1,15 +0,0 @@
// Script Constant Database
//
// Structure of Database:
// Identifier Value[ Type]
//
// Alternatively:
// Identifier,Value[,Type]
//
// 01. Identifier Unique name for the constant, must not have same name as script commands, functions or variables.
// 02. Value Value assigned to the constant. This value cannot be changed during the runtime of the server.
// 03. Type Specifies whether the identifier is a constant (0) or a parameter (1) (optional, defaults to 0).
//
// NOTE: Parameters are special in that they retrieve certain runtime values depending on the specified ID
// in field Value. Depending on the implementation values assigned by scripts to parameters will affect
// runtime values, such as Zeny, as well (see pc_readparam/pc_setparam).

35
db/import-tmpl/const.yml Normal file
View File

@ -0,0 +1,35 @@
# 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 <http://www.gnu.org/licenses/>.
#
###########################################################################
# Script Constant Database
###########################################################################
#
# Script Constant Settings
#
###########################################################################
# - Name Unique name for the constant. Must not have same name as script commands, functions, or variables.
# Value Value assigned to the constant. This value cannot be changed during the runtime of the server.
# Parameter Specifies whether the identifier is a parameter. (Default: false)
# Note: Parameters are special in that they retrieve certain runtime values depending on the specified ID
# in field Value. Depending on the implementation values assigned by scripts the parameters will affect
# runtime values, such as Zeny, as well (see pc_readparam/pc_setparam).
###########################################################################
Header:
Type: CONSTANT_DB
Version: 1

View File

@ -1420,7 +1420,7 @@ Affected files:
-- pcdb: statpoint.txt, job_exp.txt, skill_tree.txt, attr_fix.txt, job_db1.txt, job_db2.txt, job_basehpsp_db.txt, job_param_db.txt, level_penalty.yml
-- questdb: quest_db.yml
-- script: /npc/*.txt, /npc/*.conf
-- skilldb: skill_db.yml, const.txt, skill_nocast_db.txt, skill_changematerial_db.txt, skill_damage_db.txt, abra_db.yml, create_arrow_db.txt, produce_db.txt, spellbook_db.yml, magicmushroom_db.yml
-- skilldb: skill_db.yml, skill_nocast_db.txt, skill_changematerial_db.txt, skill_damage_db.txt, abra_db.yml, create_arrow_db.txt, produce_db.txt, spellbook_db.yml, magicmushroom_db.yml
-- statusdb: attr_fix.txt, size_fix.yml, refine.yml
-- achievementdb: achievement_db.yml
-- attendancedb: attendance.yml

View File

@ -66,9 +66,9 @@ This list contains all available constants referenced in the 'bonus' commands.
* Other values:
Skill (sk): see 'db/(pre-)re/skill_db.yml' (NOTE: Both skill IDs and names, in quotes, are supported.)
Monster id (mid): see 'db/(pre-)re/mob_db.txt'
Monster id (mid): see 'db/(pre-)re/mob_db.yml'
Item id (iid): see 'db/item_db.yml'
Item group (ig): see 'db/(pre-)re/item_group_db.txt' and the constants in 'db/const.txt', prefixed with IG_*
Item group (ig): see 'db/(pre-)re/item_group_db.yml' and the constants in 'src/map/script_constants.hpp', prefixed with IG_*
Weapon type (w): see 'doc/item_db.txt' -> SubType

View File

@ -3651,7 +3651,7 @@ in percent.
if (rand(100) > getscrate(Eff_Blind, 50)) goto BlindHimNow;
You can see the full list of available effect types you can possibly inflict in
'db/const.txt' under 'Eff_'.
'src/map/script_constants.hpp' under 'Eff_'.
---------------------------------------
@ -10381,7 +10381,7 @@ See 'getequipid' for a full list of valid equipment slots.
index parameter can be 0 to MAX_ITEM_RDM_OPT-1 (default 0-4).
ID - ID of random option. See db/const.txt for constants.
ID - ID of random option. See db/item_randomopt_db.yml for constants.
Value - Value of random option
Param - Parameter of random option

14
doc/yaml/db/const.yml Normal file
View File

@ -0,0 +1,14 @@
###########################################################################
# Script Constant Database
###########################################################################
#
# Script Constant Settings
#
###########################################################################
# - Name Unique name for the constant. Must not have same name as script commands, functions, or variables.
# Value Value assigned to the constant. This value cannot be changed during the runtime of the server.
# Parameter Specifies whether the identifier is a parameter. (Default: false)
# Note: Parameters are special in that they retrieve certain runtime values depending on the specified ID
# in field Value. Depending on the implementation values assigned by scripts the parameters will affect
# runtime values, such as Zeny, as well (see pc_readparam/pc_setparam).
###########################################################################

View File

@ -301,7 +301,7 @@
<Copy SourceFiles="$(SolutionDir)db\import-tmpl\attr_fix.yml" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\attr_fix.yml')" />
<Copy SourceFiles="$(SolutionDir)db\import-tmpl\battleground_db.yml" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\battleground_db.yml')" />
<Copy SourceFiles="$(SolutionDir)db\import-tmpl\castle_db.yml" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\castle_db.yml')" />
<Copy SourceFiles="$(SolutionDir)db\import-tmpl\const.txt" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\const.txt')" />
<Copy SourceFiles="$(SolutionDir)db\import-tmpl\const.yml" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\const.yml')" />
<Copy SourceFiles="$(SolutionDir)db\import-tmpl\create_arrow_db.yml" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\create_arrow_db.yml')" />
<Copy SourceFiles="$(SolutionDir)db\import-tmpl\elemental_db.txt" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\elemental_db.txt')" />
<Copy SourceFiles="$(SolutionDir)db\import-tmpl\elemental_skill_db.txt" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\elemental_skill_db.txt')" />

View File

@ -2674,7 +2674,7 @@ static void npc_parsename(struct npc_data* nd, const char* name, const char* sta
*/
int npc_parseview(const char* w4, const char* start, const char* buffer, const char* filepath) {
int i = 0;
char viewid[1024]; // Max size of name from const.txt, see read_constdb.
char viewid[1024]; // Max size of name from const.yml, see ConstantDatabase::parseBodyNode.
// Extract view ID / constant
while (w4[i] != '\0') {

View File

@ -2352,52 +2352,40 @@ void script_set_constant_(const char* name, int64 value, const char* constant_na
}
}
static bool read_constdb_sub( char* fields[], int columns, int current ){
char name[1024], val[1024];
int type = 0;
if( columns > 1 ){
if( sscanf(fields[0], "%1023[A-Za-z0-9/_]", name) != 1 ||
sscanf(fields[1], "%1023[A-Za-z0-9/_]", val) != 1 ||
( columns >= 2 && sscanf(fields[2], "%11d", &type) != 1 ) ){
ShowWarning("Skipping line '" CL_WHITE "%d" CL_RESET "', invalid constant definition\n", current);
return false;
}
}else{
if( sscanf(fields[0], "%1023[A-Za-z0-9/_] %1023[A-Za-z0-9/_-] %11d", name, val, &type) < 2 ){
ShowWarning( "Skipping line '" CL_WHITE "%d" CL_RESET "', invalid constant definition\n", current );
return false;
}
}
script_set_constant(name, (int)strtol(val, NULL, 0), (type != 0), false);
return true;
const std::string ConstantDatabase::getDefaultLocation(){
return std::string(db_path) + "/const.yml";
}
/*==========================================
* Reading constant databases
* const.txt
*------------------------------------------*/
static void read_constdb(void){
const char* dbsubpath[] = {
"",
"/" DBIMPORT,
};
uint64 ConstantDatabase::parseBodyNode( const YAML::Node& node ) {
std::string constant_name;
for( int i = 0; i < ARRAYLENGTH(dbsubpath); i++ ){
int n2 = strlen(db_path) + strlen(dbsubpath[i]) + 1;
char* dbsubpath2 = (char*)aMalloc(n2 + 1);
bool silent = i > 0;
if (!this->asString( node, "Name", constant_name ))
return 0;
safesnprintf(dbsubpath2, n2, "%s%s", db_path, dbsubpath[i]);
char name[1024];
sv_readdb(dbsubpath2, "const.txt", ',', 1, 3, -1, &read_constdb_sub, silent);
aFree(dbsubpath2);
if (sscanf(constant_name.c_str(), "%1023[A-Za-z0-9/_]", name) != 1) {
this->invalidWarning( node["Name"], "Invalid constant definition \"%s\", skipping.\n", constant_name.c_str() );
return 0;
}
int64 val;
if (!this->asInt64( node, "Value", val ))
return 0;
bool type = false;
if (this->nodeExists(node, "Parameter") && !this->asBool( node, "Parameter", type ))
return 0;
script_set_constant(name, val, type, false);
return 1;
}
ConstantDatabase constant_db;
/**
* Sets source-end constants for NPC scripts to access.
**/
@ -4844,7 +4832,7 @@ void do_init_script(void) {
mapreg_init();
add_buildin_func();
read_constdb();
constant_db.load();
script_hardcoded_constants();
}
@ -19481,7 +19469,7 @@ BUILDIN_FUNC(openauction)
///
/// checkcell("<map name>",<x>,<y>,<type>) -> <bool>
///
/// @see cell_chk* constants in const.txt for the types
/// @see cell_chk* constants in src/map/script_constants.hpp for the types
BUILDIN_FUNC(checkcell)
{
int16 m = map_mapname2mapid(script_getstr(st,2));
@ -19498,7 +19486,7 @@ BUILDIN_FUNC(checkcell)
///
/// setcell "<map name>",<x1>,<y1>,<x2>,<y2>,<type>,<flag>;
///
/// @see cell_* constants in const.txt for the types
/// @see cell_* constants in src/map/script_constants.hpp for the types
BUILDIN_FUNC(setcell)
{
int16 m = map_mapname2mapid(script_getstr(st,2));

View File

@ -4,6 +4,7 @@
#ifndef SCRIPT_HPP
#define SCRIPT_HPP
#include "../common/database.hpp"
#include "../common/cbasetypes.hpp"
#include "../common/db.hpp"
#include "../common/mmo.hpp"
@ -2058,6 +2059,17 @@ enum e_iteminfo : uint8 {
ITEMINFO_AEGISNAME // 18
};
class ConstantDatabase : public YamlDatabase {
public:
ConstantDatabase() : YamlDatabase("CONSTANT_DB", 1) {
}
void clear() { }
const std::string getDefaultLocation();
uint64 parseBodyNode(const YAML::Node& node);
};
/**
* used to generate quick script_array entries
**/

View File

@ -3852,7 +3852,7 @@
export_constant(ATF_WEAPON);
export_constant(ATF_MAGIC);
export_constant(ATF_MISC);
// TODO: Check why this was in const.txt, but not on source side
// TODO: Check why this was in const.yml, but not on source side
export_constant2("ATF_SKILL",ATF_MAGIC|ATF_MISC);
/* emoticons */

View File

@ -426,6 +426,12 @@ int do_init( int argc, char** argv ){
return 0;
}
if (!process("CONSTANT_DB", 1, root_paths, "const", [](const std::string& path, const std::string& name_ext) -> bool {
return sv_readdb(path.c_str(), name_ext.c_str(), ',', 1, 3, -1, &read_constdb, false);
})) {
return 0;
}
// TODO: add implementations ;-)
return 0;
@ -4058,3 +4064,32 @@ static bool status_readdb_attrfix(const char* file) {
ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file);
return true;
}
// Copied and adjusted from script.cpp
static bool read_constdb(char* fields[], int columns, int current) {
char name[1024], val[1024];
int type = 0;
if( columns > 1 ){
if( sscanf(fields[0], "%1023[A-Za-z0-9/_]", name) != 1 ||
sscanf(fields[1], "%1023[A-Za-z0-9/_]", val) != 1 ||
( columns >= 2 && sscanf(fields[2], "%11d", &type) != 1 ) ){
ShowWarning("Skipping line '" CL_WHITE "%d" CL_RESET "', invalid constant definition\n", current);
return false;
}
}else{
if( sscanf(fields[0], "%1023[A-Za-z0-9/_] %1023[A-Za-z0-9/_-] %11d", name, val, &type) < 2 ){
ShowWarning( "Skipping line '" CL_WHITE "%d" CL_RESET "', invalid constant definition\n", current );
return false;
}
}
body << YAML::BeginMap;
body << YAML::Key << "Name" << YAML::Value << name;
body << YAML::Key << "Value" << YAML::Value << val;
if (type != 0)
body << YAML::Key << "Parameter" << YAML::Value << "true";
body << YAML::EndMap;
return true;
}

View File

@ -449,5 +449,6 @@ static bool itemdb_read_group(char* fields[], int columns, int current);
static bool itemdb_read_group_yaml(void);
static bool mob_readdb_itemratio(char* fields[], int columns, int current);
static bool status_readdb_attrfix(const char* file);
static bool read_constdb(char* fields[], int columns, int current);
#endif /* CSV2YAML_HPP */

View File

@ -287,7 +287,7 @@ int skill_split_atoi(char *str, int *val) {
}
/**
* Split string to int by constant value (const.txt) or atoi()
* Split string to int by constant value (const.yml) or atoi()
* @param *str: String input
* @param *val: Temporary storage
* @param *delim: Delimiter (for multiple value support)