diff options
Diffstat (limited to 'src/map/map.c')
-rw-r--r-- | src/map/map.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/map/map.c b/src/map/map.c index ce8f4cdf5..d4d6e3323 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -635,6 +635,18 @@ static int map_foreachinmap(int (*func)(struct block_list*, va_list), int16 m, i return returnCount; } +static int map_forcountinmap(int (*func)(struct block_list*, va_list), int16 m, int count, int type, ...) +{ + int returnCount; + va_list ap; + + va_start(ap, type); + returnCount = map->vforcountinarea(func, m, 0, 0, map->list[m].bxs, map->list[m].bys, count, type, ap); + va_end(ap); + + return returnCount; +} + /** * Applies func to every block_list object of bl_type type on all maps * of instance instance_id. @@ -3690,6 +3702,33 @@ static void do_final_maps(void) map->zone_db_clear(); } + +static void map_zonedb_reload(void) +{ + // first, reset maps to their initial zones: + for (int i = 0; i < map->count; i++) { + map->zone_remove_all(i); + + if (battle_config.pk_mode) { + map->list[i].flag.pvp = 1; + map->list[i].zone = &map->zone_pk; + } else { + map->list[i].flag.pvp = 0; + map->list[i].zone = &map->zone_all; + } + + map->list[i].prev_zone = map->list[i].zone; + } + + // now it's safe to remove the zones: + map->zone_db_clear(); + + // then reload everything from scratch: + map->zone_db = strdb_alloc(DB_OPT_DUP_KEY | DB_OPT_RELEASE_DATA, MAP_ZONE_NAME_LENGTH); + map->read_zone_db(); +} + + /// Initializes map flags and adjusts them depending on configuration. static void map_flags_init(void) { @@ -4649,6 +4688,27 @@ static void map_zone_remove(int m) map->list[m].zone_mf = NULL; map->list[m].zone_mf_count = 0; } +// this one removes every flag, even if they were previously turned on before +// the current zone was applied +static void map_zone_remove_all(int m) +{ + Assert_retv(m >= 0 && m < map->count); + + for (unsigned short k = 0; k < map->list[m].zone_mf_count; k++) { + char flag[MAP_ZONE_MAPFLAG_LENGTH]; + + memcpy(flag, map->list[m].zone_mf[k], MAP_ZONE_MAPFLAG_LENGTH); + strtok(flag, "\t"); + + npc->parse_mapflag(map->list[m].name, "", flag, "off", "", "", "", NULL); + aFree(map->list[m].zone_mf[k]); + map->list[m].zone_mf[k] = NULL; + } + + aFree(map->list[m].zone_mf); + map->list[m].zone_mf = NULL; + map->list[m].zone_mf_count = 0; +} static inline void map_zone_mf_cache_add(int m, char *rflag) { Assert_retv(m >= 0 && m < map->count); @@ -6801,9 +6861,11 @@ void map_defaults(void) /* funcs */ map->zone_init = map_zone_init; map->zone_remove = map_zone_remove; + map->zone_remove_all = map_zone_remove_all; map->zone_apply = map_zone_apply; map->zone_change = map_zone_change; map->zone_change2 = map_zone_change2; + map->zone_reload = map_zonedb_reload; map->getcell = map_getcell; map->setgatcell = map_setgatcell; @@ -6873,6 +6935,7 @@ void map_defaults(void) map->foreachinpath = map_foreachinpath; map->vforeachinmap = map_vforeachinmap; map->foreachinmap = map_foreachinmap; + map->forcountinmap = map_forcountinmap; map->vforeachininstance = map_vforeachininstance; map->foreachininstance = map_foreachininstance; |