summaryrefslogtreecommitdiff
path: root/src/map/map.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2014-01-18 18:34:21 -0200
committershennetsind <ind@henn.et>2014-01-18 18:34:21 -0200
commita9cc02e1dea69e14a1b1e3d1cf27aaa271ac0b4b (patch)
tree1f8951ab4a7b8d8adc715e00edeb24ab0c492c8e /src/map/map.c
parent59662a1656aa1db6f7cd0f92ce10a3ff66a979a4 (diff)
downloadhercules-a9cc02e1dea69e14a1b1e3d1cf27aaa271ac0b4b.tar.gz
hercules-a9cc02e1dea69e14a1b1e3d1cf27aaa271ac0b4b.tar.bz2
hercules-a9cc02e1dea69e14a1b1e3d1cf27aaa271ac0b4b.tar.xz
hercules-a9cc02e1dea69e14a1b1e3d1cf27aaa271ac0b4b.zip
Libconfig Interfaced
Ready for plugin use. Thanks to Haruna Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/map.c')
-rw-r--r--src/map/map.c160
1 files changed, 80 insertions, 80 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 5344d11bf..052d589b4 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -4577,10 +4577,10 @@ void read_map_zone_db(void) {
#else
const char *config_filename = "db/pre-re/map_zone_db.conf"; // FIXME hardcoded name
#endif
- if (conf_read_file(&map_zone_db, config_filename))
+ if (libconfig->read_file(&map_zone_db, config_filename))
return;
- zones = config_lookup(&map_zone_db, "zones");
+ zones = libconfig->lookup(&map_zone_db, "zones");
if (zones != NULL) {
struct map_zone_data *zone;
@@ -4597,16 +4597,16 @@ void read_map_zone_db(void) {
disabled_commands_count = 0, capped_skills_count = 0;
enum map_zone_skill_subtype subtype;
- zone_count = config_setting_length(zones);
+ zone_count = libconfig->setting_length(zones);
for (i = 0; i < zone_count; ++i) {
bool is_all = false;
- zone_e = config_setting_get_elem(zones, i);
+ zone_e = libconfig->setting_get_elem(zones, i);
- if (!config_setting_lookup_string(zone_e, "name", &zonename)) {
+ if (!libconfig->setting_lookup_string(zone_e, "name", &zonename)) {
ShowError("map_zone_db: missing zone name, skipping... (%s:%d)\n",
config_setting_source_file(zone_e), config_setting_source_line(zone_e));
- config_setting_remove_elem(zones,i);/* remove from the tree */
+ libconfig->setting_remove_elem(zones,i);/* remove from the tree */
--zone_count;
--i;
continue;
@@ -4614,7 +4614,7 @@ void read_map_zone_db(void) {
if( strdb_exists(map->zone_db, zonename) ) {
ShowError("map_zone_db: duplicate zone name '%s', skipping...\n",zonename);
- config_setting_remove_elem(zones,i);/* remove from the tree */
+ libconfig->setting_remove_elem(zones,i);/* remove from the tree */
--zone_count;
--i;
continue;
@@ -4634,31 +4634,31 @@ void read_map_zone_db(void) {
}
safestrncpy(zone->name, zonename, MAP_ZONE_NAME_LENGTH);
- if( (skills = config_setting_get_member(zone_e, "disabled_skills")) != NULL ) {
- disabled_skills_count = config_setting_length(skills);
+ if( (skills = libconfig->setting_get_member(zone_e, "disabled_skills")) != NULL ) {
+ disabled_skills_count = libconfig->setting_length(skills);
/* validate */
- for(h = 0; h < config_setting_length(skills); h++) {
- config_setting_t *skillinfo = config_setting_get_elem(skills, h);
+ for(h = 0; h < libconfig->setting_length(skills); h++) {
+ config_setting_t *skillinfo = libconfig->setting_get_elem(skills, h);
name = config_setting_name(skillinfo);
if( !map->zone_str2skillid(name) ) {
ShowError("map_zone_db: unknown skill (%s) in disabled_skills for zone '%s', skipping skill...\n",name,zone->name);
- config_setting_remove_elem(skills,h);
+ libconfig->setting_remove_elem(skills,h);
--disabled_skills_count;
--h;
continue;
}
- if( !map->zone_bl_type(config_setting_get_string_elem(skills,h),&subtype) )/* we dont remove it from the three due to inheritance */
+ if( !map->zone_bl_type(libconfig->setting_get_string_elem(skills,h),&subtype) )/* we dont remove it from the three due to inheritance */
--disabled_skills_count;
}
/* all ok, process */
CREATE( zone->disabled_skills, struct map_zone_disabled_skill_entry *, disabled_skills_count );
- for(h = 0, v = 0; h < config_setting_length(skills); h++) {
- config_setting_t *skillinfo = config_setting_get_elem(skills, h);
+ for(h = 0, v = 0; h < libconfig->setting_length(skills); h++) {
+ config_setting_t *skillinfo = libconfig->setting_get_elem(skills, h);
struct map_zone_disabled_skill_entry * entry;
enum bl_type type;
name = config_setting_name(skillinfo);
- if( (type = map->zone_bl_type(config_setting_get_string_elem(skills,h),&subtype)) ) { /* only add if enabled */
+ if( (type = map->zone_bl_type(libconfig->setting_get_string_elem(skills,h),&subtype)) ) { /* only add if enabled */
CREATE( entry, struct map_zone_disabled_skill_entry, 1 );
entry->nameid = map->zone_str2skillid(name);
@@ -4672,28 +4672,28 @@ void read_map_zone_db(void) {
zone->disabled_skills_count = disabled_skills_count;
}
- if( (items = config_setting_get_member(zone_e, "disabled_items")) != NULL ) {
- disabled_items_count = config_setting_length(items);
+ if( (items = libconfig->setting_get_member(zone_e, "disabled_items")) != NULL ) {
+ disabled_items_count = libconfig->setting_length(items);
/* validate */
- for(h = 0; h < config_setting_length(items); h++) {
- config_setting_t *item = config_setting_get_elem(items, h);
+ for(h = 0; h < libconfig->setting_length(items); h++) {
+ config_setting_t *item = libconfig->setting_get_elem(items, h);
name = config_setting_name(item);
if( !map->zone_str2itemid(name) ) {
ShowError("map_zone_db: unknown item (%s) in disabled_items for zone '%s', skipping item...\n",name,zone->name);
- config_setting_remove_elem(items,h);
+ libconfig->setting_remove_elem(items,h);
--disabled_items_count;
--h;
continue;
}
- if( !config_setting_get_bool(item) )/* we dont remove it from the three due to inheritance */
+ if( !libconfig->setting_get_bool(item) )/* we dont remove it from the three due to inheritance */
--disabled_items_count;
}
/* all ok, process */
CREATE( zone->disabled_items, int, disabled_items_count );
- for(h = 0, v = 0; h < config_setting_length(items); h++) {
- config_setting_t *item = config_setting_get_elem(items, h);
+ for(h = 0, v = 0; h < libconfig->setting_length(items); h++) {
+ config_setting_t *item = libconfig->setting_get_elem(items, h);
- if( config_setting_get_bool(item) ) { /* only add if enabled */
+ if( libconfig->setting_get_bool(item) ) { /* only add if enabled */
name = config_setting_name(item);
zone->disabled_items[v++] = map->zone_str2itemid(name);
}
@@ -4702,14 +4702,14 @@ void read_map_zone_db(void) {
zone->disabled_items_count = disabled_items_count;
}
- if( (mapflags = config_setting_get_member(zone_e, "mapflags")) != NULL ) {
- mapflags_count = config_setting_length(mapflags);
+ if( (mapflags = libconfig->setting_get_member(zone_e, "mapflags")) != NULL ) {
+ mapflags_count = libconfig->setting_length(mapflags);
/* mapflags are not validated here, so we save all anyway */
CREATE( zone->mapflags, char *, mapflags_count );
for(h = 0; h < mapflags_count; h++) {
CREATE( zone->mapflags[h], char, MAP_ZONE_MAPFLAG_LENGTH );
- name = config_setting_get_string_elem(mapflags, h);
+ name = libconfig->setting_get_string_elem(mapflags, h);
safestrncpy(zone->mapflags[h], name, MAP_ZONE_MAPFLAG_LENGTH);
@@ -4717,31 +4717,31 @@ void read_map_zone_db(void) {
zone->mapflags_count = mapflags_count;
}
- if( (commands = config_setting_get_member(zone_e, "disabled_commands")) != NULL ) {
- disabled_commands_count = config_setting_length(commands);
+ if( (commands = libconfig->setting_get_member(zone_e, "disabled_commands")) != NULL ) {
+ disabled_commands_count = libconfig->setting_length(commands);
/* validate */
- for(h = 0; h < config_setting_length(commands); h++) {
- config_setting_t *command = config_setting_get_elem(commands, h);
+ for(h = 0; h < libconfig->setting_length(commands); h++) {
+ config_setting_t *command = libconfig->setting_get_elem(commands, h);
name = config_setting_name(command);
if( !atcommand->exists(name) ) {
ShowError("map_zone_db: unknown command '%s' in disabled_commands for zone '%s', skipping entry...\n",name,zone->name);
- config_setting_remove_elem(commands,h);
+ libconfig->setting_remove_elem(commands,h);
--disabled_commands_count;
--h;
continue;
}
- if( !config_setting_get_int(command) )/* we dont remove it from the three due to inheritance */
+ if( !libconfig->setting_get_int(command) )/* we dont remove it from the three due to inheritance */
--disabled_commands_count;
}
/* all ok, process */
CREATE( zone->disabled_commands, struct map_zone_disabled_command_entry *, disabled_commands_count );
- for(h = 0, v = 0; h < config_setting_length(commands); h++) {
- config_setting_t *command = config_setting_get_elem(commands, h);
+ for(h = 0, v = 0; h < libconfig->setting_length(commands); h++) {
+ config_setting_t *command = libconfig->setting_get_elem(commands, h);
struct map_zone_disabled_command_entry * entry;
int group_lv;
name = config_setting_name(command);
- if( (group_lv = config_setting_get_int(command)) ) { /* only add if enabled */
+ if( (group_lv = libconfig->setting_get_int(command)) ) { /* only add if enabled */
CREATE( entry, struct map_zone_disabled_command_entry, 1 );
entry->cmd = atcommand->exists(name)->func;
@@ -4753,35 +4753,35 @@ void read_map_zone_db(void) {
zone->disabled_commands_count = disabled_commands_count;
}
- if( (caps = config_setting_get_member(zone_e, "skill_damage_cap")) != NULL ) {
- capped_skills_count = config_setting_length(caps);
+ if( (caps = libconfig->setting_get_member(zone_e, "skill_damage_cap")) != NULL ) {
+ capped_skills_count = libconfig->setting_length(caps);
/* validate */
- for(h = 0; h < config_setting_length(caps); h++) {
- config_setting_t *cap = config_setting_get_elem(caps, h);
+ for(h = 0; h < libconfig->setting_length(caps); h++) {
+ config_setting_t *cap = libconfig->setting_get_elem(caps, h);
name = config_setting_name(cap);
if( !map->zone_str2skillid(name) ) {
ShowError("map_zone_db: unknown skill (%s) in skill_damage_cap for zone '%s', skipping skill...\n",name,zone->name);
- config_setting_remove_elem(caps,h);
+ libconfig->setting_remove_elem(caps,h);
--capped_skills_count;
--h;
continue;
}
- if( !map->zone_bl_type(config_setting_get_string_elem(cap,1),&subtype) )/* we dont remove it from the three due to inheritance */
+ if( !map->zone_bl_type(libconfig->setting_get_string_elem(cap,1),&subtype) )/* we dont remove it from the three due to inheritance */
--capped_skills_count;
}
/* all ok, process */
CREATE( zone->capped_skills, struct map_zone_skill_damage_cap_entry *, capped_skills_count );
- for(h = 0, v = 0; h < config_setting_length(caps); h++) {
- config_setting_t *cap = config_setting_get_elem(caps, h);
+ for(h = 0, v = 0; h < libconfig->setting_length(caps); h++) {
+ config_setting_t *cap = libconfig->setting_get_elem(caps, h);
struct map_zone_skill_damage_cap_entry * entry;
enum bl_type type;
name = config_setting_name(cap);
- if( (type = map->zone_bl_type(config_setting_get_string_elem(cap,1),&subtype)) ) { /* only add if enabled */
+ if( (type = map->zone_bl_type(libconfig->setting_get_string_elem(cap,1),&subtype)) ) { /* only add if enabled */
CREATE( entry, struct map_zone_skill_damage_cap_entry, 1 );
entry->nameid = map->zone_str2skillid(name);
- entry->cap = config_setting_get_int_elem(cap,0);
+ entry->cap = libconfig->setting_get_int_elem(cap,0);
entry->type = type;
entry->subtype = subtype;
zone->capped_skills[v++] = entry;
@@ -4801,24 +4801,24 @@ void read_map_zone_db(void) {
config_setting_t *new_entry = NULL;
int inherit_count;
- zone_e = config_setting_get_elem(zones, i);
- config_setting_lookup_string(zone_e, "name", &zonename);
+ zone_e = libconfig->setting_get_elem(zones, i);
+ libconfig->setting_lookup_string(zone_e, "name", &zonename);
if( strncmpi(zonename,MAP_ZONE_ALL_NAME,MAP_ZONE_NAME_LENGTH) == 0 ) {
continue;/* all zone doesn't inherit anything (if it did, everything would link to each other and boom endless loop) */
}
- if( (inherit_tree = config_setting_get_member(zone_e, "inherit")) != NULL ) {
+ if( (inherit_tree = libconfig->setting_get_member(zone_e, "inherit")) != NULL ) {
/* append global zone to this */
- new_entry = config_setting_add(inherit_tree,MAP_ZONE_ALL_NAME,CONFIG_TYPE_STRING);
- config_setting_set_string(new_entry,MAP_ZONE_ALL_NAME);
+ new_entry = libconfig->setting_add(inherit_tree,MAP_ZONE_ALL_NAME,CONFIG_TYPE_STRING);
+ libconfig->setting_set_string(new_entry,MAP_ZONE_ALL_NAME);
} else {
/* create inherit member and add global zone to it */
- inherit_tree = config_setting_add(zone_e, "inherit",CONFIG_TYPE_ARRAY);
- new_entry = config_setting_add(inherit_tree,MAP_ZONE_ALL_NAME,CONFIG_TYPE_STRING);
- config_setting_set_string(new_entry,MAP_ZONE_ALL_NAME);
+ inherit_tree = libconfig->setting_add(zone_e, "inherit",CONFIG_TYPE_ARRAY);
+ new_entry = libconfig->setting_add(inherit_tree,MAP_ZONE_ALL_NAME,CONFIG_TYPE_STRING);
+ libconfig->setting_set_string(new_entry,MAP_ZONE_ALL_NAME);
}
- inherit_count = config_setting_length(inherit_tree);
+ inherit_count = libconfig->setting_length(inherit_tree);
for(h = 0; h < inherit_count; h++) {
struct map_zone_data *izone; /* inherit zone */
int disabled_skills_count_i = 0; /* disabled skill count from inherit zone */
@@ -4828,8 +4828,8 @@ void read_map_zone_db(void) {
int capped_skills_count_i = 0; /* skill capped count from inherit zone */
int j;
- name = config_setting_get_string_elem(inherit_tree, h);
- config_setting_lookup_string(zone_e, "name", &zonename);/* will succeed for we validated it earlier */
+ name = libconfig->setting_get_string_elem(inherit_tree, h);
+ libconfig->setting_lookup_string(zone_e, "name", &zonename);/* will succeed for we validated it earlier */
if( !(izone = strdb_get(map->zone_db, name)) ) {
ShowError("map_zone_db: Unknown zone '%s' being inherit by zone '%s', skipping...\n",name,zonename);
@@ -4851,13 +4851,13 @@ void read_map_zone_db(void) {
/* process everything to override, paying attention to config_setting_get_bool */
if( disabled_skills_count_i ) {
- if( (skills = config_setting_get_member(zone_e, "disabled_skills")) == NULL )
- skills = config_setting_add(zone_e, "disabled_skills",CONFIG_TYPE_GROUP);
- disabled_skills_count = config_setting_length(skills);
+ if( (skills = libconfig->setting_get_member(zone_e, "disabled_skills")) == NULL )
+ skills = libconfig->setting_add(zone_e, "disabled_skills",CONFIG_TYPE_GROUP);
+ disabled_skills_count = libconfig->setting_length(skills);
for(j = 0; j < disabled_skills_count_i; j++) {
int k;
for(k = 0; k < disabled_skills_count; k++) {
- config_setting_t *skillinfo = config_setting_get_elem(skills, k);
+ config_setting_t *skillinfo = libconfig->setting_get_elem(skills, k);
if( map->zone_str2skillid(config_setting_name(skillinfo)) == izone->disabled_skills[j]->nameid ) {
break;
}
@@ -4874,18 +4874,18 @@ void read_map_zone_db(void) {
}
if( disabled_items_count_i ) {
- if( (items = config_setting_get_member(zone_e, "disabled_items")) == NULL )
- items = config_setting_add(zone_e, "disabled_items",CONFIG_TYPE_GROUP);
- disabled_items_count = config_setting_length(items);
+ if( (items = libconfig->setting_get_member(zone_e, "disabled_items")) == NULL )
+ items = libconfig->setting_add(zone_e, "disabled_items",CONFIG_TYPE_GROUP);
+ disabled_items_count = libconfig->setting_length(items);
for(j = 0; j < disabled_items_count_i; j++) {
int k;
for(k = 0; k < disabled_items_count; k++) {
- config_setting_t *item = config_setting_get_elem(items, k);
+ config_setting_t *item = libconfig->setting_get_elem(items, k);
name = config_setting_name(item);
if( map->zone_str2itemid(name) == izone->disabled_items[j] ) {
- if( config_setting_get_bool(item) )
+ if( libconfig->setting_get_bool(item) )
continue;
break;
}
@@ -4898,13 +4898,13 @@ void read_map_zone_db(void) {
}
if( mapflags_count_i ) {
- if( (mapflags = config_setting_get_member(zone_e, "mapflags")) == NULL )
- mapflags = config_setting_add(zone_e, "mapflags",CONFIG_TYPE_ARRAY);
- mapflags_count = config_setting_length(mapflags);
+ if( (mapflags = libconfig->setting_get_member(zone_e, "mapflags")) == NULL )
+ mapflags = libconfig->setting_add(zone_e, "mapflags",CONFIG_TYPE_ARRAY);
+ mapflags_count = libconfig->setting_length(mapflags);
for(j = 0; j < mapflags_count_i; j++) {
int k;
for(k = 0; k < mapflags_count; k++) {
- name = config_setting_get_string_elem(mapflags, k);
+ name = libconfig->setting_get_string_elem(mapflags, k);
if( strcmpi(name,izone->mapflags[j]) == 0 ) {
break;
@@ -4919,14 +4919,14 @@ void read_map_zone_db(void) {
}
if( disabled_commands_count_i ) {
- if( (commands = config_setting_get_member(zone_e, "disabled_commands")) == NULL )
- commands = config_setting_add(zone_e, "disabled_commands",CONFIG_TYPE_GROUP);
+ if( (commands = libconfig->setting_get_member(zone_e, "disabled_commands")) == NULL )
+ commands = libconfig->setting_add(zone_e, "disabled_commands",CONFIG_TYPE_GROUP);
- disabled_commands_count = config_setting_length(commands);
+ disabled_commands_count = libconfig->setting_length(commands);
for(j = 0; j < disabled_commands_count_i; j++) {
int k;
for(k = 0; k < disabled_commands_count; k++) {
- config_setting_t *command = config_setting_get_elem(commands, k);
+ config_setting_t *command = libconfig->setting_get_elem(commands, k);
if( atcommand->exists(config_setting_name(command))->func == izone->disabled_commands[j]->cmd ) {
break;
}
@@ -4943,14 +4943,14 @@ void read_map_zone_db(void) {
}
if( capped_skills_count_i ) {
- if( (caps = config_setting_get_member(zone_e, "skill_damage_cap")) == NULL )
- caps = config_setting_add(zone_e, "skill_damage_cap",CONFIG_TYPE_GROUP);
+ if( (caps = libconfig->setting_get_member(zone_e, "skill_damage_cap")) == NULL )
+ caps = libconfig->setting_add(zone_e, "skill_damage_cap",CONFIG_TYPE_GROUP);
- capped_skills_count = config_setting_length(caps);
+ capped_skills_count = libconfig->setting_length(caps);
for(j = 0; j < capped_skills_count_i; j++) {
int k;
for(k = 0; k < capped_skills_count; k++) {
- config_setting_t *cap = config_setting_get_elem(caps, k);
+ config_setting_t *cap = libconfig->setting_get_elem(caps, k);
if( map->zone_str2skillid(config_setting_name(cap)) == izone->capped_skills[j]->nameid ) {
break;
}
@@ -4972,7 +4972,7 @@ void read_map_zone_db(void) {
ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' zones in '"CL_WHITE"%s"CL_RESET"'.\n", zone_count, config_filename);
/* not supposed to go in here but in skill_final whatever */
- config_destroy(&map_zone_db);
+ libconfig->destroy(&map_zone_db);
}
}