diff --git a/db/const.txt b/db/const.txt
deleted file mode 100644
index d1a57fd9a3..0000000000
--- a/db/const.txt
+++ /dev/null
@@ -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
diff --git a/db/const.yml b/db/const.yml
new file mode 100644
index 0000000000..c5047bc978
--- /dev/null
+++ b/db/const.yml
@@ -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 .
+#
+###########################################################################
+# 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
diff --git a/db/import-tmpl/const.txt b/db/import-tmpl/const.txt
deleted file mode 100644
index f587b3d04c..0000000000
--- a/db/import-tmpl/const.txt
+++ /dev/null
@@ -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).
diff --git a/db/import-tmpl/const.yml b/db/import-tmpl/const.yml
new file mode 100644
index 0000000000..16ff042cda
--- /dev/null
+++ b/db/import-tmpl/const.yml
@@ -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 .
+#
+###########################################################################
+# 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
diff --git a/doc/atcommands.txt b/doc/atcommands.txt
index daa2753641..f3ec2b6fcb 100644
--- a/doc/atcommands.txt
+++ b/doc/atcommands.txt
@@ -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
diff --git a/doc/item_bonus.txt b/doc/item_bonus.txt
index 60e8dd291b..c79d8bd720 100644
--- a/doc/item_bonus.txt
+++ b/doc/item_bonus.txt
@@ -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
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 3de9deaf9a..8fc4355eef 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -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
diff --git a/doc/yaml/db/const.yml b/doc/yaml/db/const.yml
new file mode 100644
index 0000000000..37e0b79dbd
--- /dev/null
+++ b/doc/yaml/db/const.yml
@@ -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).
+###########################################################################
diff --git a/src/map/map-server.vcxproj b/src/map/map-server.vcxproj
index 92c46bd4f7..b04b7dcd63 100644
--- a/src/map/map-server.vcxproj
+++ b/src/map/map-server.vcxproj
@@ -301,7 +301,7 @@
-
+
diff --git a/src/map/npc.cpp b/src/map/npc.cpp
index 01c79c8ccb..4e69c5e05d 100644
--- a/src/map/npc.cpp
+++ b/src/map/npc.cpp
@@ -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') {
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 86da652980..3b79abaf0a 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -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("