Skip to content

Commit

Permalink
Converted const.txt to libconfig format
Browse files Browse the repository at this point in the history
- This is necessary for upcoming improvements

Signed-off-by: Haru <haru@dotalux.com>
  • Loading branch information
MishimaHaruna committed Jan 13, 2016
1 parent 77ebd05 commit a815472
Show file tree
Hide file tree
Showing 8 changed files with 3,888 additions and 3,707 deletions.
3,641 changes: 0 additions & 3,641 deletions db/const.txt

This file was deleted.

3,791 changes: 3,791 additions & 0 deletions db/constants.conf

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/atcommands.txt
Expand Up @@ -209,7 +209,7 @@ New warp NPC 'my_warp_sample' created.
@effect <effect ID>

Creates a visual effect on or around the character.
A list of IDs can be found in '/db/const.txt'.
A list of IDs can be found in '/db/constants.conf'.
Descriptions of the effects can be found in '/doc/effect_list.txt'.

---------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/ea_job_system.txt
Expand Up @@ -12,7 +12,7 @@
Preface:
-------------------------------------------------------------------------------

Most scripters are aware of the class values used in RO and their constants specified on db/const.txt. Each class has a number associated to it for referencing, so when someone's class is 9 that means they are a wizard. However, this list of job numbers has no real order behind it, and no logic behind it's assignation.
Most scripters are aware of the class values used in RO and their constants specified on db/constants.conf. Each class has a number associated to it for referencing, so when someone's class is 9 that means they are a wizard. However, this list of job numbers has no real order behind it, and no logic behind it's assignation.

You can add 3999 to a job to get their rebirth ID, but if you try to do the same to get the Baby class ID, that fails on the super Baby class. Also, there's no way to calculate, from a given first class, which classes would be their "evolution". That is, given the Archer's ID, you cannot just add a value that will return you "Hunter", and will still work if applied to the other classes. It didn't help much when they added Taekwon Boy, a first class, with an ID of 4046, and much later they added Ninja/Gunslinger with the IDs 25/24. How do you identify a first class on all this mess without recurring to very ugly range checks?

Expand Down
83 changes: 43 additions & 40 deletions doc/script_commands.txt
Expand Up @@ -242,7 +242,7 @@ and to make it look southeast it's facing 5.)

Sprite is the sprite identifier used to display this particular NPC. For a
full list of sprite numbers see http://kalen.s79.xrea.com/npc/npce.shtml as
well as db/const.txt.
well as db/constants.conf.
You may also use a monster's ID constant instead to display a monster sprite
for this NPC, in npcs that have view ids of mobs it's encouraged to use
OnTouch events with a 2,2 range and with an 'end' after the header to avoid
Expand Down Expand Up @@ -528,12 +528,12 @@ forever, and no trace remains of it even if it was stored with character
or account data. The maximum length of variable name including prefix and
suffix is 32.

Some variables are special, that is, they are already defined for you by
the scripting engine. You can see the full list somewhere in
'db/const.txt', which is a file you should read, since it also allows you
to replace lots of numbered arguments for many commands with easier to
read text. The special variables most commonly used are all permanent
character-based variables:
Some variables are special, that is, they are already defined for you by
the scripting engine. You can see the full list somewhere in
'db/constants.conf', which is a file you should read, since it also
allows you to replace lots of numbered arguments for many commands with
easier to read text. The special variables most commonly used are all
permanent character-based variables:

Zeny - Amount of Zeny.
Hp - Current amount of hit points.
Expand Down Expand Up @@ -692,9 +692,9 @@ Variable References
Hard-coded constants
--------------------
Most of the constants defined by the scripting engine can be found in
'db/const.txt' and have the same value independently of settings that
are core related, but there are constants that can be used to retrieve
core information that's set when the server is compiled.
'db/constants.conf' and have the same value independently of settings
that are core related, but there are constants that can be used to
retrieve core information that's set when the server is compiled.

PACKETVER - Server packet version
MAX_LEVEL - Maximum level
Expand Down Expand Up @@ -1196,15 +1196,16 @@ the string is empty, it will show up as an empty line.

mes "Text that will appear in the box";

Inside the string you may put color codes, which will alter the color of
the text printed after them. The color codes are all '^<R><G><B>' and
contain three hexadecimal numbers representing colors as if they were HTML
colors - ^FF0000 is bright red, ^00FF00 is bright green, ^0000FF is bright
blue, ^000000 is black. ^FF00FF is a pure magenta, but it's also a color
that is considered transparent whenever the client is drawing windows on
screen, so printing text in that color will have kind of a weird effect.
You may also use C_ constants accompany with "F_MesColor" function for the
color effect, see the full list of the available ones in 'db/const.txt'
Inside the string you may put color codes, which will alter the color of
the text printed after them. The color codes are all '^<R><G><B>' and
contain three hexadecimal numbers representing colors as if they were
HTML colors - ^FF0000 is bright red, ^00FF00 is bright green, ^0000FF is
bright blue, ^000000 is black. ^FF00FF is a pure magenta, but it's also
a color that is considered transparent whenever the client is drawing
windows on screen, so printing text in that color will have kind of a
weird effect. You may also use C_ constants accompany with "F_MesColor"
function for the color effect, see the full list of the available ones
in 'db/constants.conf'
under 'C_'. Once you've set a text's color to something, you have to set
it back to black unless you want all the rest of the text be in that color:

Expand Down Expand Up @@ -2387,7 +2388,7 @@ arrays:

This function will return the basic stats of an invoking character,
referred to by the parameter number. Instead of a number, you can use a
parameter name if it is defined in 'db/const.txt'.
parameter name if it is defined in 'db/constants.conf'.

Example parameters:

Expand Down Expand Up @@ -3563,7 +3564,7 @@ mob database and return the info set by TYPE argument.
It will return -1 if there is no such monster (or the type value is
invalid), or "null" if you requested the monster's name.

Valid types are listed in const.txt:
Valid types are listed in constants.conf:
MOB_NAME 0
MOB_LV 1
MOB_MAXHP 2
Expand Down Expand Up @@ -3712,7 +3713,7 @@ effect being inflicted, in percent.
}

You can see the full list of available effect types you can possibly
inflict in 'db/const.txt' under 'Eff_'.
inflict in 'db/constants.conf' under 'Eff_'.

---------------------------------------
//=====================================
Expand Down Expand Up @@ -4341,7 +4342,7 @@ This command will change the job class of the invoking character.

This command does work with numbers, but you can also use job names. The
full list of job names and the numbers they correspond to can be found in
'db/const.txt'.
'db/constants.conf'.

// This would change your player into a Swordman
jobchange Job_Swordman;
Expand Down Expand Up @@ -4502,7 +4503,8 @@ Is subject to EXP bonuses and to the `quest_exp_rate` config option.

getexp 10000,5000;

You can also assign directly to the parameters defined in 'db/const.txt':
You can also assign directly to the parameters defined in
'db/constants.conf':

BaseExp += 10000;
JobExp += 5000;
Expand Down Expand Up @@ -4580,7 +4582,7 @@ installation that you can look at: 'npc/custom/stylist.txt'
This command will push the currently attached player to given direction by
given amount of square cells. Direction is the same as used when declaring
NPCs, and can be specified by using one of the DIR_* constants
(db/const.txt).
(db/constants.conf).

The knock-back is not restricted by items or map flags, only obstacles are
taken into account. If there is not enough space to perform the push (e.g.
Expand Down Expand Up @@ -5514,9 +5516,9 @@ Used in reset NPC's (duh!).
These commands will bestow a status effect on a character.

The <effect type> determines which status is invoked. This can be either a number
or constant, with the common statuses (mostly negative) found in 'db/const.txt'
with the 'SC_' prefix. A full list is located in 'src/map/status.h', though
they are not currently documented.
or constant, with the common statuses (mostly negative) found in
'db/constants.conf' with the 'SC_' prefix. A full list is located in
'src/map/status.h', though they are not currently documented.

The duration of the status is given in <ticks>, or milleseconds.

Expand Down Expand Up @@ -6253,9 +6255,10 @@ Examples:
*unitemote <GID>,<Emote>;

Okay, these commands should be fairly self explaining.
For the emotions, you can look in db/const.txt for prefixes with e_
PS: unitwarp supports a <GID> of zero, which causes the executor of the
script to be affected. This can be used with OnTouchNPC to warp monsters:
For the emotions, you can look in db/constants.conf for prefixes with e_
PS: unitwarp supports a <GID> of zero, which causes the executor of the
script to be affected. This can be used with OnTouchNPC to warp
monsters:

OnTouchNPC:
unitwarp 0,"this",-1,-1;
Expand Down Expand Up @@ -6610,8 +6613,8 @@ This command will broadcast a message to all or most players, similar to
The region the broadcast is heard in (target), source of the broadcast and
the color the message will come up as is determined by the flags.

The flag values are coded as constants in db/const.txt to make them easier
to use.
The flag values are coded as constants in db/constants.conf to make them
easier to use.

Target flags:
- bc_all: Broadcast message is sent server-wide (default).
Expand Down Expand Up @@ -6643,7 +6646,7 @@ depending on a game client used.

The color parameter is a single number which can be in hexadecimal
notation. C_ constant can also be used for color effects, see the full list
of the available ones in 'db/const.txt' under 'C_'.
of the available ones in 'db/constants.conf' under 'C_'.

For example:
announce "This announcement will be shown to everyone in green.",bc_all,0x00FF00;
Expand Down Expand Up @@ -6937,7 +6940,7 @@ to the coordinates specified.

This command marks a specified map with a map flag given. Map flags alter
the behavior of the map, you can see the list of the available ones in
'db/const.txt' under 'mf_'.
'db/constants.conf' under 'mf_'.

The map flags alter the behavior of the map regarding teleporting
(mf_nomemo, mf_noteleport, mf_nowarp, mf_nogo), storing location when
Expand Down Expand Up @@ -7326,7 +7329,7 @@ A full list of pet IDs can be found inside 'db/pet_db.txt'

This command makes an object display an emotion sprite above their own as
if they were doing that emotion. For a full list of emotion numbers, see
'db/const.txt' under 'e_'. The not so obvious ones are 'e_what' (a
'db/constants.conf' under 'e_'. The not so obvious ones are 'e_what' (a
question mark) and 'e_gasp' (the exclamation mark).

The optional target parameter specifies who will get the emotion on top of
Expand Down Expand Up @@ -8187,14 +8190,14 @@ same time.

This command will make the pet give a bonus to the owner's stat (bonus
type - bInt,bVit,bDex,bAgi,bLuk,bStr,bSpeedRate - for a full list, see the
values starting with 'b' in 'db/const.txt').
values starting with 'b' in 'db/constants.conf').

*petrecovery <status type>,<delay>;

This command will make the pet cure a specified status condition. The
curing actions will occur once every <delay> seconds. For a full list of
status conditions that can be cured, see the list of 'SC_' status
condition constants in 'db/const.txt'
condition constants in 'db/constants.conf'

*petloot <max items>;

Expand Down Expand Up @@ -8289,7 +8292,7 @@ Each of these can be 'on' or 'off'. Together they define a cell's behavior.
This command lets you alter these flags for all map cells in the specified
(x1,y1)-(x2,y2) rectangle.
'type' defines which flag to modify. Possible options include cell_walkable,
cell_shootable, cell_basilica. For a full list, see const.txt.
cell_shootable, cell_basilica. For a full list, see constants.conf.
'flag' can be 0 or 1 (0:clear flag, 1:set flag).

Example:
Expand Down Expand Up @@ -8326,7 +8329,7 @@ remove a nonwalkable row of cells after the barricade mobs.
This command will return 1 or 0, depending on whether the specified cell
has the 'type' flag set or not. There are various types to check, all
mimicking the server's cell_chk enumeration. The types can be found in
db/const.txt.
db/constants.conf.

The meaning of the individual types can be confusing, so here's an
overview:
Expand Down
2 changes: 1 addition & 1 deletion src/map/npc.c
Expand Up @@ -2551,7 +2551,7 @@ void npc_parsename(struct npc_data* nd, const char* name, const char* start, con
// Support for using Constants in place of NPC View IDs.
int npc_parseview(const char* w4, const char* start, const char* buffer, const char* filepath) {
int val = FAKE_NPC, i = 0;
char viewid[1024]; // Max size of name from const.txt, see script->read_constdb.
char viewid[1024]; // Max size of name from constants.conf, see script->read_constdb.

// Extract view ID / constant
while (w4[i] != '\0') {
Expand Down
72 changes: 50 additions & 22 deletions src/map/script.c
Expand Up @@ -2277,32 +2277,57 @@ void script_set_constant2(const char *name, int value, bool isparameter) {
script->str_data[n].val = value;

}
/*==========================================
* Reading constant databases
* const.txt
*------------------------------------------*/
void read_constdb(void) {
FILE *fp;
char line[1024],name[1024],val[1024];
int type;

sprintf(line, "%s/const.txt", map->db_path);
fp=fopen(line, "r");
if(fp==NULL) {
ShowError("can't read %s\n", line);
return ;
/**
* Loads the constants database from constants.conf
*/
void read_constdb(void)
{
config_t constants_conf;
char filepath[256];
config_setting_t *cdb;
config_setting_t *t;
int i = 0;

sprintf(filepath, "%s/constants.conf", map->db_path);

if (libconfig->read_file(&constants_conf, filepath) || !(cdb = libconfig->setting_get_member(constants_conf.root, "constants_db"))) {
ShowError("can't read %s\n", filepath);
return;
}
while (fgets(line, sizeof(line), fp)) {
if (line[0] == '/' && line[1] == '/')

while ((t = libconfig->setting_get_elem(cdb, i++))) {
bool is_parameter = false;
int value = 0;
const char *name = config_setting_name(t);
const char *p = name;

while (*p != '\0') {
if (!ISALNUM(*p) && *p != '_')
break;
p++;
}
if (*p != '\0') {
ShowWarning("read_constdb: Invalid constant name %s. Skipping.\n", name);
continue;
type = 0;
if (sscanf(line, "%1023[A-Za-z0-9_],%1023[-0-9xXA-Fa-f],%d", name, val, &type) >=2
|| sscanf(line, "%1023[A-Za-z0-9_] %1023[-0-9xXA-Fa-f] %d", name, val, &type) >=2
) {
script->set_constant(name, (int)strtol(val, NULL, 0), (bool)type);
}
if (config_setting_is_aggregate(t)) {
int i32;
if (!libconfig->setting_lookup_int(t, "Value", &i32)) {
ShowWarning("read_constdb: Invalid entry for %s. Skipping.\n", name);
continue;
}
value = i32;
if (libconfig->setting_lookup_bool(t, "Parameter", &i32)) {
if (i32 != 0)
is_parameter = true;
}
} else {
value = libconfig->setting_get_int(t);
}
script->set_constant(name, value, is_parameter);
}
fclose(fp);
libconfig->destroy(&constants_conf);
}

// Standard UNIX tab size is 8
Expand Down Expand Up @@ -20778,7 +20803,10 @@ void script_label_add(int key, int pos) {
/**
* Sets source-end constants for scripts to play with
**/
void script_hardcoded_constants(void) {
void script_hardcoded_constants(void)
{
script->set_constant("true", 1, false);
script->set_constant("false", 0, false);
/* server defines */
script->set_constant("PACKETVER",PACKETVER,false);
script->set_constant("MAX_LEVEL",MAX_LEVEL,false);
Expand Down
2 changes: 1 addition & 1 deletion tools/Script-Checker.applescript
Expand Up @@ -85,7 +85,7 @@ on build_hercules(hercules_repo)
display dialog "Build successfully completed. Please check the log file for details." with title "Build result" buttons {"Abort", "Continue"} default button 2 cancel button 1
set the files_to_copy to {"map-server", "script-checker"}
set the conf_files_to_copy to {"inter-server.conf", "import", "packet.conf", "script.conf"}
set the db_files_to_copy to {"map_index.txt", "item_db2.txt", "const.txt", "mob_db2.txt"}
set the db_files_to_copy to {"map_index.txt", "item_db2.txt", "constants.conf", "mob_db2.txt"}
set the db2_files_to_copy to {"map_cache.dat", "item_db.txt", "skill_db.txt", "mob_db.txt"}
try
set the hercules_path to path to resource "Hercules"
Expand Down

0 comments on commit a815472

Please sign in to comment.