summaryrefslogtreecommitdiff
path: root/src/map/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/map.c')
-rw-r--r--src/map/map.c841
1 files changed, 522 insertions, 319 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 16d5e645d..6212493c8 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2016 Hercules Dev Team
+ * Copyright (C) 2012-2018 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -30,6 +30,7 @@
#include "map/channel.h"
#include "map/chat.h"
#include "map/chrif.h"
+#include "map/clan.h"
#include "map/clif.h"
#include "map/duel.h"
#include "map/elemental.h"
@@ -55,8 +56,10 @@
#include "map/skill.h"
#include "map/status.h"
#include "map/storage.h"
+#include "map/rodex.h"
#include "map/trade.h"
#include "map/unit.h"
+#include "map/achievement.h"
#include "common/HPM.h"
#include "common/cbasetypes.h"
#include "common/conf.h"
@@ -64,6 +67,7 @@
#include "common/core.h"
#include "common/ers.h"
#include "common/grfio.h"
+#include "common/md5calc.h"
#include "common/memmgr.h"
#include "common/nullpo.h"
#include "common/random.h"
@@ -84,8 +88,8 @@
#include <unistd.h>
#endif
-struct map_interface map_s;
-struct mapit_interface mapit_s;
+static struct map_interface map_s;
+static struct mapit_interface mapit_s;
struct map_interface *map;
struct mapit_interface *mapit;
@@ -93,18 +97,21 @@ struct mapit_interface *mapit;
/*==========================================
* server player count (of all mapservers)
*------------------------------------------*/
-void map_setusers(int users) {
+static void map_setusers(int users)
+{
map->users = users;
}
-int map_getusers(void) {
+static int map_getusers(void)
+{
return map->users;
}
/**
* Expands map->bl_list on demand
**/
-static inline void map_bl_list_expand(void) {
+static inline void map_bl_list_expand(void)
+{
map->bl_list_size += 250;
RECREATE(map->bl_list, struct block_list *, map->bl_list_size);
}
@@ -112,7 +119,8 @@ static inline void map_bl_list_expand(void) {
/**
* Expands map->block_free on demand
**/
-static inline void map_block_free_expand(void) {
+static inline void map_block_free_expand(void)
+{
map->block_free_list_size += 100;
RECREATE(map->block_free, struct block_list *, map->block_free_list_size);
}
@@ -120,14 +128,16 @@ static inline void map_block_free_expand(void) {
/*==========================================
* server player count (this mapserver only)
*------------------------------------------*/
-int map_usercount(void) {
+static int map_usercount(void)
+{
return db_size(map->pc_db);
}
/*==========================================
* Attempt to free a map blocklist
*------------------------------------------*/
-int map_freeblock (struct block_list *bl) {
+static int map_freeblock(struct block_list *bl)
+{
nullpo_retr(map->block_free_lock, bl);
if (map->block_free_lock == 0) {
@@ -148,14 +158,16 @@ int map_freeblock (struct block_list *bl) {
/*==========================================
* Lock blocklist, (prevent map->freeblock usage)
*------------------------------------------*/
-int map_freeblock_lock (void) {
+static int map_freeblock_lock(void)
+{
return ++map->block_free_lock;
}
/*==========================================
* Remove the lock on map_bl
*------------------------------------------*/
-int map_freeblock_unlock (void) {
+static int map_freeblock_unlock(void)
+{
if ((--map->block_free_lock) == 0) {
int i;
for (i = 0; i < map->block_free_count; i++) {
@@ -176,7 +188,8 @@ int map_freeblock_unlock (void) {
// Timer function to check if there some remaining lock and remove them if so.
// Called each 1s
-int map_freeblock_timer(int tid, int64 tick, int id, intptr_t data) {
+static int map_freeblock_timer(int tid, int64 tick, int id, intptr_t data)
+{
if (map->block_free_lock > 0) {
ShowError("map_freeblock_timer: block_free_lock(%d) is invalid.\n", map->block_free_lock);
map->block_free_lock = 1;
@@ -190,7 +203,8 @@ int map_freeblock_timer(int tid, int64 tick, int id, intptr_t data) {
* Updates the counter (cell.cell_bl) of how many objects are on a tile.
* @param add Whether the counter should be increased or decreased
**/
-void map_update_cell_bl( struct block_list *bl, bool increase ) {
+static void map_update_cell_bl(struct block_list *bl, bool increase)
+{
#ifdef CELL_NOSTACK
int pos;
@@ -219,7 +233,7 @@ void map_update_cell_bl( struct block_list *bl, bool increase ) {
* Adds a block to the map.
* Returns 0 on success, 1 on failure (illegal coordinates).
*------------------------------------------*/
-int map_addblock(struct block_list* bl)
+static int map_addblock(struct block_list *bl)
{
int16 m, x, y;
int pos;
@@ -267,7 +281,7 @@ int map_addblock(struct block_list* bl)
/*==========================================
* Removes a block from the map.
*------------------------------------------*/
-int map_delblock(struct block_list* bl)
+static int map_delblock(struct block_list *bl)
{
int pos;
nullpo_ret(bl);
@@ -310,7 +324,8 @@ int map_delblock(struct block_list* bl)
* Pass flag as 1 to prevent doing skill->unit_move checks
* (which are executed by default on BL_CHAR types)
*------------------------------------------*/
-int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) {
+static int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick)
+{
struct status_change *sc = NULL;
int x0, y0;
int moveblock;
@@ -428,7 +443,8 @@ int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) {
* 0x2 - don't count invinsible units
* TODO: merge with bl_getall_area
*------------------------------------------*/
-int map_count_oncell(int16 m, int16 x, int16 y, int type, int flag) {
+static int map_count_oncell(int16 m, int16 x, int16 y, int type, int flag)
+{
int bx,by;
struct block_list *bl;
int count = 0;
@@ -446,6 +462,11 @@ int map_count_oncell(int16 m, int16 x, int16 y, int type, int flag) {
struct status_change *sc = status->get_sc(bl);
if (sc && (sc->option&OPTION_INVISIBLE))
continue;
+ if (bl->type == BL_NPC) {
+ const struct npc_data *nd = BL_UCCAST(BL_NPC, bl);
+ if (nd->class_ == FAKE_NPC || nd->class_ == HIDDEN_WARP_CLASS)
+ continue;
+ }
}
if (flag&0x1) {
struct unit_data *ud = unit->bl2ud(bl);
@@ -481,7 +502,8 @@ int map_count_oncell(int16 m, int16 x, int16 y, int type, int flag) {
* Looks for a skill unit on a given cell
* flag&1: runs battle_check_target check based on unit->group->target_flag
*/
-struct skill_unit* map_find_skill_unit_oncell(struct block_list* target,int16 x,int16 y,uint16 skill_id,struct skill_unit* out_unit, int flag) {
+static struct skill_unit *map_find_skill_unit_oncell(struct block_list *target, int16 x, int16 y, uint16 skill_id, struct skill_unit *out_unit, int flag)
+{
int16 m,bx,by;
struct block_list *bl;
struct skill_unit *su;
@@ -522,7 +544,8 @@ struct skill_unit* map_find_skill_unit_oncell(struct block_list* target,int16 x,
* @param args Extra arguments for func
* @return Sum of the values returned by func
*/
-static int bl_vforeach(int (*func)(struct block_list*, va_list), int blockcount, int max, va_list args) {
+static int bl_vforeach(int (*func)(struct block_list*, va_list), int blockcount, int max, va_list args)
+{
int i;
int returnCount = 0;
@@ -551,7 +574,8 @@ static int bl_vforeach(int (*func)(struct block_list*, va_list), int blockcount,
* @param args Extra arguments for func
* @return Sum of the values returned by func
*/
-static int map_vforeachinmap(int (*func)(struct block_list*, va_list), int16 m, int type, va_list args) {
+static int map_vforeachinmap(int (*func)(struct block_list*, va_list), int16 m, int type, va_list args)
+{
int i;
int returnCount = 0;
int bsize;
@@ -599,7 +623,8 @@ static int map_vforeachinmap(int (*func)(struct block_list*, va_list), int16 m,
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_foreachinmap(int (*func)(struct block_list*, va_list), int16 m, int type, ...) {
+static int map_foreachinmap(int (*func)(struct block_list*, va_list), int16 m, int type, ...)
+{
int returnCount;
va_list ap;
@@ -610,6 +635,18 @@ int map_foreachinmap(int (*func)(struct block_list*, va_list), int16 m, int type
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].xs, map->list[m].ys, 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.
@@ -621,7 +658,8 @@ int map_foreachinmap(int (*func)(struct block_list*, va_list), int16 m, int type
* @param ap Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_vforeachininstance(int (*func)(struct block_list*, va_list), int16 instance_id, int type, va_list ap) {
+static int map_vforeachininstance(int (*func)(struct block_list*, va_list), int16 instance_id, int type, va_list ap)
+{
int i;
int returnCount = 0;
@@ -647,7 +685,8 @@ int map_vforeachininstance(int (*func)(struct block_list*, va_list), int16 insta
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_foreachininstance(int (*func)(struct block_list*, va_list), int16 instance_id, int type, ...) {
+static int map_foreachininstance(int (*func)(struct block_list*, va_list), int16 instance_id, int type, ...)
+{
int returnCount;
va_list ap;
@@ -667,7 +706,8 @@ int map_foreachininstance(int (*func)(struct block_list*, va_list), int16 instan
* @param ... Extra arguments for func
* @return Number of found objects
*/
-static int bl_getall_area(int type, int m, int x0, int y0, int x1, int y1, int (*func)(struct block_list*, va_list), ...) {
+static int bl_getall_area(int type, int m, int x0, int y0, int x1, int y1, int (*func)(struct block_list*, va_list), ...)
+{
va_list args;
int bx, by;
struct block_list *bl;
@@ -805,7 +845,8 @@ static int bl_vgetall_inrange(struct block_list *bl, va_list args)
* @param ap Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_vforeachinrange(int (*func)(struct block_list*, va_list), struct block_list* center, int16 range, int type, va_list ap) {
+static int map_vforeachinrange(int (*func)(struct block_list*, va_list), struct block_list *center, int16 range, int type, va_list ap)
+{
int returnCount = 0;
int blockcount = map->bl_list_count;
va_list apcopy;
@@ -833,7 +874,8 @@ int map_vforeachinrange(int (*func)(struct block_list*, va_list), struct block_l
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_foreachinrange(int (*func)(struct block_list*, va_list), struct block_list* center, int16 range, int type, ...) {
+static int map_foreachinrange(int (*func)(struct block_list*, va_list), struct block_list *center, int16 range, int type, ...)
+{
int returnCount;
va_list ap;
@@ -857,7 +899,8 @@ int map_foreachinrange(int (*func)(struct block_list*, va_list), struct block_li
* @param ap Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_vforcountinrange(int (*func)(struct block_list*, va_list), struct block_list* center, int16 range, int count, int type, va_list ap) {
+static int map_vforcountinrange(int (*func)(struct block_list*, va_list), struct block_list *center, int16 range, int count, int type, va_list ap)
+{
int returnCount = 0;
int blockcount = map->bl_list_count;
va_list apcopy;
@@ -887,7 +930,8 @@ int map_vforcountinrange(int (*func)(struct block_list*, va_list), struct block_
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_forcountinrange(int (*func)(struct block_list*, va_list), struct block_list* center, int16 range, int count, int type, ...) {
+static int map_forcountinrange(int (*func)(struct block_list*, va_list), struct block_list *center, int16 range, int count, int type, ...)
+{
int returnCount;
va_list ap;
@@ -933,7 +977,8 @@ static int bl_vgetall_inshootrange(struct block_list *bl, va_list args)
* @param ap Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_vforeachinshootrange(int (*func)(struct block_list*, va_list), struct block_list* center, int16 range, int type, va_list ap) {
+static int map_vforeachinshootrange(int (*func)(struct block_list*, va_list), struct block_list *center, int16 range, int type, va_list ap)
+{
int returnCount = 0;
int blockcount = map->bl_list_count;
va_list apcopy;
@@ -961,7 +1006,8 @@ int map_vforeachinshootrange(int (*func)(struct block_list*, va_list), struct bl
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_foreachinshootrange(int (*func)(struct block_list*, va_list), struct block_list* center, int16 range, int type, ...) {
+static int map_foreachinshootrange(int (*func)(struct block_list*, va_list), struct block_list *center, int16 range, int type, ...)
+{
int returnCount;
va_list ap;
@@ -986,7 +1032,8 @@ int map_foreachinshootrange(int (*func)(struct block_list*, va_list), struct blo
* @param ap Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_vforeachinarea(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int type, va_list ap) {
+static int map_vforeachinarea(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int type, va_list ap)
+{
int returnCount = 0;
int blockcount = map->bl_list_count;
va_list apcopy;
@@ -1015,7 +1062,8 @@ int map_vforeachinarea(int (*func)(struct block_list*, va_list), int16 m, int16
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_foreachinarea(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int type, ...) {
+static int map_foreachinarea(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int type, ...)
+{
int returnCount;
va_list ap;
@@ -1042,7 +1090,8 @@ int map_foreachinarea(int (*func)(struct block_list*, va_list), int16 m, int16 x
* @param ap Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_vforcountinarea(int (*func)(struct block_list*,va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int count, int type, va_list ap) {
+static int map_vforcountinarea(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int count, int type, va_list ap)
+{
int returnCount = 0;
int blockcount = map->bl_list_count;
va_list apcopy;
@@ -1073,7 +1122,8 @@ int map_vforcountinarea(int (*func)(struct block_list*,va_list), int16 m, int16
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_forcountinarea(int (*func)(struct block_list*,va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int count, int type, ...) {
+static int map_forcountinarea(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int count, int type, ...)
+{
int returnCount;
va_list ap;
@@ -1130,7 +1180,8 @@ static int bl_vgetall_inmovearea(struct block_list *bl, va_list args)
* @param ap Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_vforeachinmovearea(int (*func)(struct block_list*, va_list), struct block_list* center, int16 range, int16 dx, int16 dy, int type, va_list ap) {
+static int map_vforeachinmovearea(int (*func)(struct block_list*, va_list), struct block_list *center, int16 range, int16 dx, int16 dy, int type, va_list ap)
+{
int returnCount = 0;
int blockcount = map->bl_list_count;
int m, x0, x1, y0, y1;
@@ -1188,7 +1239,8 @@ int map_vforeachinmovearea(int (*func)(struct block_list*, va_list), struct bloc
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_foreachinmovearea(int (*func)(struct block_list*, va_list), struct block_list* center, int16 range, int16 dx, int16 dy, int type, ...) {
+static int map_foreachinmovearea(int (*func)(struct block_list*, va_list), struct block_list *center, int16 range, int16 dx, int16 dy, int type, ...)
+{
int returnCount;
va_list ap;
@@ -1211,7 +1263,8 @@ int map_foreachinmovearea(int (*func)(struct block_list*, va_list), struct block
* @param ap Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_vforeachincell(int (*func)(struct block_list*, va_list), int16 m, int16 x, int16 y, int type, va_list ap) {
+static int map_vforeachincell(int (*func)(struct block_list*, va_list), int16 m, int16 x, int16 y, int type, va_list ap)
+{
int returnCount = 0;
int blockcount = map->bl_list_count;
va_list apcopy;
@@ -1237,7 +1290,8 @@ int map_vforeachincell(int (*func)(struct block_list*, va_list), int16 m, int16
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_foreachincell(int (*func)(struct block_list*, va_list), int16 m, int16 x, int16 y, int type, ...) {
+static int map_foreachincell(int (*func)(struct block_list*, va_list), int16 m, int16 x, int16 y, int type, ...)
+{
int returnCount;
va_list ap;
@@ -1316,7 +1370,8 @@ static int bl_vgetall_inpath(struct block_list *bl, va_list args)
* @param ap Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_vforeachinpath(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int16 range, int length, int type, va_list ap) {
+static int map_vforeachinpath(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int16 range, int length, int type, va_list ap)
+{
// [Skotlex]
// check for all targets in the square that
// contains the initial and final positions (area range increased to match the
@@ -1393,7 +1448,8 @@ int map_vforeachinpath(int (*func)(struct block_list*, va_list), int16 m, int16
* @param ... Extra arguments for func
* @return Sum of the values returned by func
*/
-int map_foreachinpath(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int16 range, int length, int type, ...) {
+static int map_foreachinpath(int (*func)(struct block_list*, va_list), int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int16 range, int length, int type, ...)
+{
int returnCount;
va_list ap;
@@ -1409,7 +1465,7 @@ int map_foreachinpath(int (*func)(struct block_list*, va_list), int16 m, int16 x
/// Generates a new flooritem object id from the interval [MIN_FLOORITEM, MAX_FLOORITEM).
/// Used for floor items, skill units and chatroom objects.
/// @return The new object id
-int map_get_new_object_id(void)
+static int map_get_new_object_id(void)
{
static int last_object_id = MIN_FLOORITEM - 1;
int i;
@@ -1441,7 +1497,7 @@ int map_get_new_object_id(void)
* Timered function to clear the floor (remove remaining item)
* Called each flooritem_lifetime ms
*------------------------------------------*/
-int map_clearflooritem_timer(int tid, int64 tick, int id, intptr_t data)
+static int map_clearflooritem_timer(int tid, int64 tick, int id, intptr_t data)
{
struct block_list *bl = idb_get(map->id_db, id);
struct flooritem_data *fitem = BL_CAST(BL_ITEM, bl);
@@ -1464,7 +1520,7 @@ int map_clearflooritem_timer(int tid, int64 tick, int id, intptr_t data)
/*
* clears a single bl item out of the bazooonga.
*/
-void map_clearflooritem(struct block_list *bl)
+static void map_clearflooritem(struct block_list *bl)
{
struct flooritem_data *fitem = BL_CAST(BL_ITEM, bl);
@@ -1484,7 +1540,8 @@ void map_clearflooritem(struct block_list *bl)
* to place an BL_ITEM object. Scan area is 9x9, returns 1 on success.
* x and y are modified with the target cell when successful.
*------------------------------------------*/
-int map_searchrandfreecell(int16 m, const struct block_list *bl, int16 *x, int16 *y, int stack) {
+static int map_searchrandfreecell(int16 m, const struct block_list *bl, int16 *x, int16 *y, int stack)
+{
int free_cell,i,j;
int free_cells[9][2];
@@ -1514,7 +1571,8 @@ int map_searchrandfreecell(int16 m, const struct block_list *bl, int16 *x, int16
return 1;
}
-int map_count_sub(struct block_list *bl,va_list ap) {
+static int map_count_sub(struct block_list *bl, va_list ap)
+{
return 1;
}
@@ -1530,7 +1588,7 @@ int map_count_sub(struct block_list *bl,va_list ap) {
* &2 = the target should be able to walk to the target tile.
* &4 = there shouldn't be any players around the target tile (use the no_spawn_on_player setting)
*------------------------------------------*/
-int map_search_freecell(struct block_list *src, int16 m, int16 *x,int16 *y, int16 rx, int16 ry, int flag)
+static int map_search_freecell(struct block_list *src, int16 m, int16 *x, int16 *y, int16 rx, int16 ry, int flag)
{
int tries, spawn=0;
int bx, by;
@@ -1604,7 +1662,7 @@ int map_search_freecell(struct block_list *src, int16 m, int16 *x,int16 *y, int1
* flag:
* 0x1 - only count standing units
*------------------------------------------*/
-bool map_closest_freecell(int16 m, const struct block_list *bl, int16 *x, int16 *y, int type, int flag)
+static bool map_closest_freecell(int16 m, const struct block_list *bl, int16 *x, int16 *y, int type, int flag)
{
uint8 dir = 6;
int16 tx;
@@ -1688,8 +1746,9 @@ bool map_closest_freecell(int16 m, const struct block_list *bl, int16 *x, int16
* @m, @x, @y mapid,x,y
* @first_charid, @second_charid, @third_charid, looting priority
* @flag: &1 MVP item. &2 do stacking check.
+ * @showdropeffect: show effect when the item is dropped.
*------------------------------------------*/
-int map_addflooritem(const struct block_list *bl, struct item *item_data, int amount, int16 m, int16 x, int16 y, int first_charid, int second_charid, int third_charid, int flags)
+static int map_addflooritem(const struct block_list *bl, struct item *item_data, int amount, int16 m, int16 x, int16 y, int first_charid, int second_charid, int third_charid, int flags, bool showdropeffect)
{
int r;
struct flooritem_data *fitem=NULL;
@@ -1708,6 +1767,7 @@ int map_addflooritem(const struct block_list *bl, struct item *item_data, int am
fitem->bl.x = x;
fitem->bl.y = y;
fitem->bl.id = map->get_new_object_id();
+ fitem->showdropeffect = showdropeffect;
if(fitem->bl.id==0){
ers_free(map->flooritem_ers, fitem);
return 0;
@@ -1736,7 +1796,7 @@ int map_addflooritem(const struct block_list *bl, struct item *item_data, int am
/**
* @see DBCreateData
*/
-struct DBData create_charid2nick(union DBKey key, va_list args)
+static struct DBData create_charid2nick(union DBKey key, va_list args)
{
struct charid2nick *p;
CREATE(p, struct charid2nick, 1);
@@ -1745,7 +1805,7 @@ struct DBData create_charid2nick(union DBKey key, va_list args)
/// Adds(or replaces) the nick of charid to nick_db and fullfils pending requests.
/// Does nothing if the character is online.
-void map_addnickdb(int charid, const char* nick)
+static void map_addnickdb(int charid, const char *nick)
{
struct charid2nick* p;
struct charid_request* req;
@@ -1769,7 +1829,7 @@ void map_addnickdb(int charid, const char* nick)
/// Removes the nick of charid from nick_db.
/// Sends name to all pending requests on charid.
-void map_delnickdb(int charid, const char* name)
+static void map_delnickdb(int charid, const char *name)
{
struct charid2nick* p;
struct charid_request* req;
@@ -1793,7 +1853,7 @@ void map_delnickdb(int charid, const char* name)
/// Notifies sd of the nick of charid.
/// Uses the name in the character if online.
/// Uses the name in nick_db if offline.
-void map_reqnickdb(struct map_session_data * sd, int charid)
+static void map_reqnickdb(struct map_session_data *sd, int charid)
{
struct charid2nick* p;
struct charid_request* req;
@@ -1822,7 +1882,7 @@ void map_reqnickdb(struct map_session_data * sd, int charid)
/*==========================================
* add bl to id_db
*------------------------------------------*/
-void map_addiddb(struct block_list *bl)
+static void map_addiddb(struct block_list *bl)
{
nullpo_retv(bl);
@@ -1834,7 +1894,7 @@ void map_addiddb(struct block_list *bl)
struct mob_data *md = BL_UCAST(BL_MOB, bl);
idb_put(map->mobid_db,bl->id,bl);
- if( md->state.boss )
+ if (md->state.boss == BTYPE_MVP)
idb_put(map->bossid_db, bl->id, bl);
}
@@ -1847,7 +1907,7 @@ void map_addiddb(struct block_list *bl)
/*==========================================
* remove bl from id_db
*------------------------------------------*/
-void map_deliddb(struct block_list *bl)
+static void map_deliddb(struct block_list *bl)
{
nullpo_retv(bl);
@@ -1869,7 +1929,8 @@ void map_deliddb(struct block_list *bl)
/*==========================================
* Standard call when a player connection is closed.
*------------------------------------------*/
-int map_quit(struct map_session_data *sd) {
+static int map_quit(struct map_session_data *sd)
+{
int i;
nullpo_ret(sd);
@@ -1896,6 +1957,9 @@ int map_quit(struct map_session_data *sd) {
if( sd->bg_id && !sd->bg_queue.arena ) /* TODO: dump this chunk after bg_queue is fully enabled */
bg->team_leave(sd,BGTL_QUIT);
+ if (sd->status.clan_id)
+ clan->member_offline(sd);
+
if (sd->state.autotrade && core->runflag != MAPSERVER_ST_SHUTDOWN && !channel->config->closing)
pc->autotrade_update(sd,PAUC_REMOVE);
@@ -1915,6 +1979,7 @@ int map_quit(struct map_session_data *sd) {
}
npc->script_event(sd, NPCE_LOGOUT);
+ rodex->clean(sd, 0);
//Unit_free handles clearing the player related data,
//map->quit handles extra specific data which is related to quitting normally
@@ -1995,7 +2060,7 @@ int map_quit(struct map_session_data *sd) {
* @return The searched map_session_data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to a player unit.
*/
-struct map_session_data *map_id2sd(int id)
+static struct map_session_data *map_id2sd(int id)
{
struct block_list *bl = NULL;
if (id <= 0)
@@ -2015,7 +2080,7 @@ struct map_session_data *map_id2sd(int id)
* @return The searched npc_data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to a NPC.
*/
-struct npc_data *map_id2nd(int id)
+static struct npc_data *map_id2nd(int id)
{
// just a id2bl lookup because there's no npc_db
struct block_list* bl = map->id2bl(id);
@@ -2032,7 +2097,7 @@ struct npc_data *map_id2nd(int id)
* @return The searched mob_data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to a mob unit.
*/
-struct mob_data *map_id2md(int id)
+static struct mob_data *map_id2md(int id)
{
struct block_list *bl = NULL;
if (id <= 0)
@@ -2052,7 +2117,7 @@ struct mob_data *map_id2md(int id)
* @return The searched flooritem_data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to a floor item.
*/
-struct flooritem_data *map_id2fi(int id)
+static struct flooritem_data *map_id2fi(int id)
{
struct block_list* bl = map->id2bl(id);
@@ -2066,7 +2131,7 @@ struct flooritem_data *map_id2fi(int id)
* @return The searched chat_data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to a chat.
*/
-struct chat_data *map_id2cd(int id)
+static struct chat_data *map_id2cd(int id)
{
struct block_list* bl = map->id2bl(id);
@@ -2080,7 +2145,7 @@ struct chat_data *map_id2cd(int id)
* @return The searched skill_unit data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to a skill unit.
*/
-struct skill_unit *map_id2su(int id)
+static struct skill_unit *map_id2su(int id)
{
struct block_list* bl = map->id2bl(id);
@@ -2094,7 +2159,7 @@ struct skill_unit *map_id2su(int id)
* @return The searched pet_data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to a pet.
*/
-struct pet_data *map_id2pd(int id)
+static struct pet_data *map_id2pd(int id)
{
struct block_list* bl = map->id2bl(id);
@@ -2108,7 +2173,7 @@ struct pet_data *map_id2pd(int id)
* @return The searched homun_data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to a homunculus.
*/
-struct homun_data *map_id2hd(int id)
+static struct homun_data *map_id2hd(int id)
{
struct block_list* bl = map->id2bl(id);
@@ -2122,7 +2187,7 @@ struct homun_data *map_id2hd(int id)
* @return The searched mercenary_data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to a mercenary.
*/
-struct mercenary_data *map_id2mc(int id)
+static struct mercenary_data *map_id2mc(int id)
{
struct block_list* bl = map->id2bl(id);
@@ -2136,7 +2201,7 @@ struct mercenary_data *map_id2mc(int id)
* @return The searched elemental_data, if it exists.
* @retval NULL if the ID is invalid or doesn't belong to an elemental.
*/
-struct elemental_data *map_id2ed(int id)
+static struct elemental_data *map_id2ed(int id)
{
struct block_list* bl = map->id2bl(id);
@@ -2152,7 +2217,7 @@ struct elemental_data *map_id2ed(int id)
* @return The searched block_list, if it exists.
* @retval NULL if the ID is invalid.
*/
-struct block_list *map_id2bl(int id)
+static struct block_list *map_id2bl(int id)
{
return idb_get(map->id_db, id);
}
@@ -2164,13 +2229,14 @@ struct block_list *map_id2bl(int id)
* @retval true if the ID exists and is valid.
* @retval false otherwise.
*/
-bool map_blid_exists(int id)
+static bool map_blid_exists(int id)
{
return (idb_exists(map->id_db,id));
}
/// Returns the nick of the target charid or NULL if unknown (requests the nick to the char server).
-const char *map_charid2nick(int charid) {
+static const char *map_charid2nick(int charid)
+{
struct charid2nick *p;
struct map_session_data* sd;
@@ -2187,7 +2253,7 @@ const char *map_charid2nick(int charid) {
}
/// Returns the struct map_session_data of the charid or NULL if the char is not online.
-struct map_session_data* map_charid2sd(int charid)
+static struct map_session_data *map_charid2sd(int charid)
{
struct block_list *bl = idb_get(map->charid_db, charid);
if (bl)
@@ -2200,7 +2266,7 @@ struct map_session_data* map_charid2sd(int charid)
* (without sensitive case if necessary)
* return map_session_data pointer or NULL
*------------------------------------------*/
-struct map_session_data * map_nick2sd(const char *nick)
+static struct map_session_data *map_nick2sd(const char *nick)
{
struct map_session_data* sd;
struct map_session_data* found_sd;
@@ -2248,7 +2314,7 @@ struct map_session_data * map_nick2sd(const char *nick)
/*==========================================
* Convext Mirror
*------------------------------------------*/
-struct mob_data *map_getmob_boss(int16 m)
+static struct mob_data *map_getmob_boss(int16 m)
{
struct DBIterator *iter;
struct mob_data *md = NULL;
@@ -2266,7 +2332,7 @@ struct mob_data *map_getmob_boss(int16 m)
return (found)? md : NULL;
}
-struct mob_data *map_id2boss(int id)
+static struct mob_data *map_id2boss(int id)
{
struct block_list *bl = NULL;
if (id <= 0)
@@ -2284,7 +2350,7 @@ struct mob_data *map_id2boss(int id)
*
* @return The equivalent race bitmask.
*/
-uint32 map_race_id2mask(int race)
+static uint32 map_race_id2mask(int race)
{
if (race >= RC_FORMLESS && race < RC_MAX)
return 1 << race;
@@ -2312,7 +2378,7 @@ uint32 map_race_id2mask(int race)
/// Applies func to all the players in the db.
/// Stops iterating if func returns -1.
-void map_vforeachpc(int (*func)(struct map_session_data* sd, va_list args), va_list args)
+static void map_vforeachpc(int (*func)(struct map_session_data *sd, va_list args), va_list args)
{
struct DBIterator *iter = db_iterator(map->pc_db);
struct map_session_data *sd = NULL;
@@ -2334,7 +2400,8 @@ void map_vforeachpc(int (*func)(struct map_session_data* sd, va_list args), va_l
/// Applies func to all the players in the db.
/// Stops iterating if func returns -1.
/// @see map_vforeachpc
-void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...) {
+static void map_foreachpc(int (*func)(struct map_session_data *sd, va_list args), ...)
+{
va_list args;
va_start(args, func);
@@ -2344,7 +2411,7 @@ void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...)
/// Applies func to all the mobs in the db.
/// Stops iterating if func returns -1.
-void map_vforeachmob(int (*func)(struct mob_data* md, va_list args), va_list args)
+static void map_vforeachmob(int (*func)(struct mob_data *md, va_list args), va_list args)
{
struct DBIterator *iter = db_iterator(map->mobid_db);
struct mob_data *md = NULL;
@@ -2365,7 +2432,8 @@ void map_vforeachmob(int (*func)(struct mob_data* md, va_list args), va_list arg
/// Applies func to all the mobs in the db.
/// Stops iterating if func returns -1.
/// @see map_vforeachmob
-void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...) {
+static void map_foreachmob(int (*func)(struct mob_data *md, va_list args), ...)
+{
va_list args;
va_start(args, func);
@@ -2375,7 +2443,7 @@ void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...) {
/// Applies func to all the npcs in the db.
/// Stops iterating if func returns -1.
-void map_vforeachnpc(int (*func)(struct npc_data* nd, va_list args), va_list args)
+static void map_vforeachnpc(int (*func)(struct npc_data *nd, va_list args), va_list args)
{
struct DBIterator *iter = db_iterator(map->id_db);
struct block_list *bl = NULL;
@@ -2399,7 +2467,8 @@ void map_vforeachnpc(int (*func)(struct npc_data* nd, va_list args), va_list arg
/// Applies func to all the npcs in the db.
/// Stops iterating if func returns -1.
/// @see map_vforeachnpc
-void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...) {
+static void map_foreachnpc(int (*func)(struct npc_data *nd, va_list args), ...)
+{
va_list args;
va_start(args, func);
@@ -2409,7 +2478,7 @@ void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...) {
/// Applies func to everything in the db.
/// Stops iterating gif func returns -1.
-void map_vforeachregen(int (*func)(struct block_list* bl, va_list args), va_list args)
+static void map_vforeachregen(int (*func)(struct block_list *bl, va_list args), va_list args)
{
struct DBIterator *iter = db_iterator(map->regen_db);
struct block_list *bl = NULL;
@@ -2430,7 +2499,8 @@ void map_vforeachregen(int (*func)(struct block_list* bl, va_list args), va_list
/// Applies func to everything in the db.
/// Stops iterating gif func returns -1.
/// @see map_vforeachregen
-void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...) {
+static void map_foreachregen(int (*func)(struct block_list *bl, va_list args), ...)
+{
va_list args;
va_start(args, func);
@@ -2440,7 +2510,7 @@ void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...) {
/// Applies func to everything in the db.
/// Stops iterating if func returns -1.
-void map_vforeachiddb(int (*func)(struct block_list* bl, va_list args), va_list args)
+static void map_vforeachiddb(int (*func)(struct block_list *bl, va_list args), va_list args)
{
struct DBIterator *iter = db_iterator(map->id_db);
struct block_list *bl = NULL;
@@ -2461,7 +2531,8 @@ void map_vforeachiddb(int (*func)(struct block_list* bl, va_list args), va_list
/// Applies func to everything in the db.
/// Stops iterating if func returns -1.
/// @see map_vforeachiddb
-void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...) {
+static void map_foreachiddb(int (*func)(struct block_list *bl, va_list args), ...)
+{
va_list args;
va_start(args, func);
@@ -2493,7 +2564,8 @@ struct s_mapiterator {
/// @param flags Flags of the iterator
/// @param type Target types
/// @return Iterator
-struct s_mapiterator* mapit_alloc(enum e_mapitflags flags, enum bl_type types) {
+static struct s_mapiterator *mapit_alloc(enum e_mapitflags flags, enum bl_type types)
+{
struct s_mapiterator* iter;
iter = ers_alloc(map->iterator_ers, struct s_mapiterator);
@@ -2508,7 +2580,8 @@ struct s_mapiterator* mapit_alloc(enum e_mapitflags flags, enum bl_type types) {
/// Frees the iterator.
///
/// @param iter Iterator
-void mapit_free(struct s_mapiterator* iter) {
+static void mapit_free(struct s_mapiterator *iter)
+{
nullpo_retv(iter);
dbi_destroy(iter->dbi);
@@ -2520,7 +2593,8 @@ void mapit_free(struct s_mapiterator* iter) {
///
/// @param iter Iterator
/// @return first block_list or NULL
-struct block_list* mapit_first(struct s_mapiterator* iter) {
+static struct block_list *mapit_first(struct s_mapiterator *iter)
+{
struct block_list* bl;
nullpo_retr(NULL,iter);
@@ -2537,7 +2611,8 @@ struct block_list* mapit_first(struct s_mapiterator* iter) {
///
/// @param iter Iterator
/// @return last block_list or NULL
-struct block_list* mapit_last(struct s_mapiterator* iter) {
+static struct block_list *mapit_last(struct s_mapiterator *iter)
+{
struct block_list* bl;
nullpo_retr(NULL,iter);
@@ -2554,7 +2629,8 @@ struct block_list* mapit_last(struct s_mapiterator* iter) {
///
/// @param iter Iterator
/// @return next block_list or NULL
-struct block_list* mapit_next(struct s_mapiterator* iter) {
+static struct block_list *mapit_next(struct s_mapiterator *iter)
+{
struct block_list* bl;
nullpo_retr(NULL,iter);
@@ -2575,7 +2651,8 @@ struct block_list* mapit_next(struct s_mapiterator* iter) {
///
/// @param iter Iterator
/// @return previous block_list or NULL
-struct block_list* mapit_prev(struct s_mapiterator* iter) {
+static struct block_list *mapit_prev(struct s_mapiterator *iter)
+{
struct block_list* bl;
nullpo_retr(NULL,iter);
@@ -2595,7 +2672,8 @@ struct block_list* mapit_prev(struct s_mapiterator* iter) {
///
/// @param iter Iterator
/// @return true if it exists
-bool mapit_exists(struct s_mapiterator* iter) {
+static bool mapit_exists(struct s_mapiterator *iter)
+{
nullpo_retr(false,iter);
return dbi_exists(iter->dbi);
@@ -2604,7 +2682,8 @@ bool mapit_exists(struct s_mapiterator* iter) {
/*==========================================
* Add npc-bl to id_db, basically register npc to map
*------------------------------------------*/
-bool map_addnpc(int16 m,struct npc_data *nd) {
+static bool map_addnpc(int16 m, struct npc_data *nd)
+{
nullpo_ret(nd);
if( m < 0 || m >= map->count )
@@ -2626,7 +2705,8 @@ bool map_addnpc(int16 m,struct npc_data *nd) {
*-----------------------------------------*/
// Stores the spawn data entry in the mob list.
// Returns the index of successful, or -1 if the list was full.
-int map_addmobtolist(unsigned short m, struct spawn_data *spawn) {
+static int map_addmobtolist(unsigned short m, struct spawn_data *spawn)
+{
int i;
nullpo_retr(-1, spawn);
ARR_FIND( 0, MAX_MOB_LIST_PER_MAP, i, map->list[m].moblist[i] == NULL );
@@ -2637,7 +2717,8 @@ int map_addmobtolist(unsigned short m, struct spawn_data *spawn) {
return -1;
}
-void map_spawnmobs(int16 m) {
+static void map_spawnmobs(int16 m)
+{
int i, k=0;
if (map->list[m].mob_delete_timer != INVALID_TIMER) {
//Mobs have not been removed yet [Skotlex]
@@ -2656,7 +2737,7 @@ void map_spawnmobs(int16 m) {
}
}
-int map_removemobs_sub(struct block_list *bl, va_list ap)
+static int map_removemobs_sub(struct block_list *bl, va_list ap)
{
struct mob_data *md = NULL;
nullpo_ret(bl);
@@ -2685,7 +2766,8 @@ int map_removemobs_sub(struct block_list *bl, va_list ap)
return 1;
}
-int map_removemobs_timer(int tid, int64 tick, int id, intptr_t data) {
+static int map_removemobs_timer(int tid, int64 tick, int id, intptr_t data)
+{
int count;
const int16 m = id;
@@ -2709,7 +2791,8 @@ int map_removemobs_timer(int tid, int64 tick, int id, intptr_t data) {
return 1;
}
-void map_removemobs(int16 m) {
+static void map_removemobs(int16 m)
+{
Assert_retv(m >= 0 && m < map->count);
if (map->list[m].mob_delete_timer != INVALID_TIMER) // should never happen
return; //Mobs are already scheduled for removal
@@ -2720,7 +2803,8 @@ void map_removemobs(int16 m) {
/*==========================================
* Hookup, get map_id from map_name
*------------------------------------------*/
-int16 map_mapname2mapid(const char* name) {
+static int16 map_mapname2mapid(const char *name)
+{
unsigned short map_index;
map_index = mapindex->name2id(name);
if (!map_index)
@@ -2731,7 +2815,8 @@ int16 map_mapname2mapid(const char* name) {
/*==========================================
* Returns the map of the given mapindex. [Skotlex]
*------------------------------------------*/
-int16 map_mapindex2mapid(unsigned short map_index) {
+static int16 map_mapindex2mapid(unsigned short map_index)
+{
if (!map_index || map_index >= MAX_MAPINDEX)
return -1;
@@ -2742,7 +2827,8 @@ int16 map_mapindex2mapid(unsigned short map_index) {
/*==========================================
* Switching Ip, port ? (like changing map_server) get ip/port from map_name
*------------------------------------------*/
-int map_mapname2ipport(unsigned short name, uint32* ip, uint16* port) {
+static int map_mapname2ipport(unsigned short name, uint32 *ip, uint16 *port)
+{
struct map_data_other_server *mdos;
nullpo_retr(-1, ip);
@@ -2756,9 +2842,9 @@ int map_mapname2ipport(unsigned short name, uint32* ip, uint16* port) {
}
/*==========================================
-* Checks if both dirs point in the same direction.
-*------------------------------------------*/
-int map_check_dir(int s_dir,int t_dir)
+ * Checks if both dirs point in the same direction.
+ *------------------------------------------*/
+static int map_check_dir(int s_dir, int t_dir)
{
if(s_dir == t_dir)
return 0;
@@ -2778,7 +2864,7 @@ int map_check_dir(int s_dir,int t_dir)
/*==========================================
* Returns the direction of the given cell, relative to 'src'
*------------------------------------------*/
-uint8 map_calc_dir(struct block_list* src, int16 x, int16 y)
+static uint8 map_calc_dir(struct block_list *src, int16 x, int16 y)
{
uint8 dir = 0;
int dx, dy;
@@ -2820,7 +2906,7 @@ uint8 map_calc_dir(struct block_list* src, int16 x, int16 y)
* Randomizes target cell x,y to a random walkable cell that
* has the same distance from object as given coordinates do. [Skotlex]
*------------------------------------------*/
-int map_random_dir(struct block_list *bl, int16 *x, int16 *y)
+static int map_random_dir(struct block_list *bl, int16 *x, int16 *y)
{
short xi;
short yi;
@@ -2856,7 +2942,8 @@ int map_random_dir(struct block_list *bl, int16 *x, int16 *y)
}
// gat system
-struct mapcell map_gat2cell(int gat) {
+static struct mapcell map_gat2cell(int gat)
+{
struct mapcell cell;
memset(&cell,0,sizeof(struct mapcell));
@@ -2877,7 +2964,8 @@ struct mapcell map_gat2cell(int gat) {
return cell;
}
-int map_cell2gat(struct mapcell cell) {
+static int map_cell2gat(struct mapcell cell)
+{
if( cell.walkable == 1 && cell.shootable == 1 && cell.water == 0 ) return 0;
if( cell.walkable == 0 && cell.shootable == 0 && cell.water == 0 ) return 1;
if( cell.walkable == 1 && cell.shootable == 1 && cell.water == 1 ) return 3;
@@ -2886,21 +2974,26 @@ int map_cell2gat(struct mapcell cell) {
ShowWarning("map_cell2gat: cell has no matching gat type\n");
return 1; // default to 'wall'
}
-void map_cellfromcache(struct map_data *m) {
- struct map_cache_map_info *info;
+/**
+ * Extracts a map's cell data from its compressed mapcache.
+ *
+ * @param[in, out] m The target map.
+ */
+static void map_cellfromcache(struct map_data *m)
+{
nullpo_retv(m);
- info = (struct map_cache_map_info *)m->cellPos;
- if (info) {
+ if (m->cell_buf.data != NULL) {
char decode_buffer[MAX_MAP_SIZE];
unsigned long size, xy;
int i;
- size = (unsigned long)info->xs*(unsigned long)info->ys;
+ size = (unsigned long)m->xs * (unsigned long)m->ys;
// TO-DO: Maybe handle the scenario, if the decoded buffer isn't the same size as expected? [Shinryo]
- grfio->decode_zip(decode_buffer, &size, m->cellPos+sizeof(struct map_cache_map_info), info->len);
+ grfio->decode_zip(decode_buffer, &size, m->cell_buf.data, m->cell_buf.len);
+
CREATE(m->cell, struct mapcell, size);
// Set cell properties
@@ -2920,11 +3013,13 @@ void map_cellfromcache(struct map_data *m) {
/*==========================================
* Confirm if celltype in (m,x,y) match the one given in cellchk
*------------------------------------------*/
-int map_getcell(int16 m, const struct block_list *bl, int16 x, int16 y, cell_chk cellchk) {
+static int map_getcell(int16 m, const struct block_list *bl, int16 x, int16 y, cell_chk cellchk)
+{
return (m < 0 || m >= map->count) ? 0 : map->list[m].getcellp(&map->list[m], bl, x, y, cellchk);
}
-int map_getcellp(struct map_data* m, const struct block_list *bl, int16 x, int16 y, cell_chk cellchk) {
+static int map_getcellp(struct map_data *m, const struct block_list *bl, int16 x, int16 y, cell_chk cellchk)
+{
struct mapcell cell;
nullpo_ret(m);
@@ -2992,7 +3087,8 @@ int map_getcellp(struct map_data* m, const struct block_list *bl, int16 x, int16
}
/* [Ind/Hercules] */
-int map_sub_getcellp(struct map_data* m, const struct block_list *bl, int16 x, int16 y, cell_chk cellchk) {
+static int map_sub_getcellp(struct map_data *m, const struct block_list *bl, int16 x, int16 y, cell_chk cellchk)
+{
nullpo_ret(m);
map->cellfromcache(m);
m->getcellp = map->getcellp;
@@ -3005,7 +3101,8 @@ int map_sub_getcellp(struct map_data* m, const struct block_list *bl, int16 x, i
* 'cell' - which flag to modify
* 'flag' - true = on, false = off
*------------------------------------------*/
-void map_setcell(int16 m, int16 x, int16 y, cell_t cell, bool flag) {
+static void map_setcell(int16 m, int16 x, int16 y, cell_t cell, bool flag)
+{
int j;
if( m < 0 || m >= map->count || x < 0 || x >= map->list[m].xs || y < 0 || y >= map->list[m].ys )
@@ -3031,7 +3128,8 @@ void map_setcell(int16 m, int16 x, int16 y, cell_t cell, bool flag) {
break;
}
}
-void map_sub_setcell(int16 m, int16 x, int16 y, cell_t cell, bool flag) {
+static void map_sub_setcell(int16 m, int16 x, int16 y, cell_t cell, bool flag)
+{
if( m < 0 || m >= map->count || x < 0 || x >= map->list[m].xs || y < 0 || y >= map->list[m].ys )
return;
@@ -3040,7 +3138,8 @@ void map_sub_setcell(int16 m, int16 x, int16 y, cell_t cell, bool flag) {
map->list[m].getcellp = map->getcellp;
map->list[m].setcell(m,x,y,cell,flag);
}
-void map_setgatcell(int16 m, int16 x, int16 y, int gat) {
+static void map_setgatcell(int16 m, int16 x, int16 y, int gat)
+{
int j;
struct mapcell cell;
@@ -3056,9 +3155,9 @@ void map_setgatcell(int16 m, int16 x, int16 y, int gat) {
}
/*==========================================
-* Invisible Walls
-*------------------------------------------*/
-void map_iwall_nextxy(int16 x, int16 y, int8 dir, int pos, int16 *x1, int16 *y1)
+ * Invisible Walls
+ *------------------------------------------*/
+static void map_iwall_nextxy(int16 x, int16 y, int8 dir, int pos, int16 *x1, int16 *y1)
{
nullpo_retv(x1);
nullpo_retv(y1);
@@ -3078,7 +3177,7 @@ void map_iwall_nextxy(int16 x, int16 y, int8 dir, int pos, int16 *x1, int16 *y1)
*y1 = y + pos;
}
-bool map_iwall_set(int16 m, int16 x, int16 y, int size, int8 dir, bool shootable, const char* wall_name)
+static bool map_iwall_set(int16 m, int16 x, int16 y, int size, int8 dir, bool shootable, const char *wall_name)
{
struct iwall_data *iwall;
int i;
@@ -3122,7 +3221,7 @@ bool map_iwall_set(int16 m, int16 x, int16 y, int size, int8 dir, bool shootable
return true;
}
-void map_iwall_get(struct map_session_data *sd)
+static void map_iwall_get(struct map_session_data *sd)
{
struct iwall_data *iwall;
struct DBIterator *iter;
@@ -3147,13 +3246,13 @@ void map_iwall_get(struct map_session_data *sd)
dbi_destroy(iter);
}
-void map_iwall_remove(const char *wall_name)
+static bool map_iwall_remove(const char *wall_name)
{
struct iwall_data *iwall;
int16 i, x1, y1;
if( (iwall = (struct iwall_data *)strdb_get(map->iwall_db, wall_name)) == NULL )
- return; // Nothing to do
+ return false;
for( i = 0; i < iwall->size; i++ ) {
map->iwall_nextxy(iwall->x, iwall->y, iwall->dir, i, &x1, &y1);
@@ -3166,12 +3265,13 @@ void map_iwall_remove(const char *wall_name)
map->list[iwall->m].iwall_num--;
strdb_remove(map->iwall_db, iwall->wall_name);
+ return true;
}
/**
* @see DBCreateData
*/
-struct DBData create_map_data_other_server(union DBKey key, va_list args)
+static struct DBData create_map_data_other_server(union DBKey key, va_list args)
{
struct map_data_other_server *mdos;
unsigned short map_index = (unsigned short)key.ui;
@@ -3184,7 +3284,7 @@ struct DBData create_map_data_other_server(union DBKey key, va_list args)
/*==========================================
* Add mapindex to db of another map server
*------------------------------------------*/
-int map_setipport(unsigned short map_index, uint32 ip, uint16 port)
+static int map_setipport(unsigned short map_index, uint32 ip, uint16 port)
{
struct map_data_other_server *mdos;
@@ -3206,7 +3306,7 @@ int map_setipport(unsigned short map_index, uint32 ip, uint16 port)
* Delete all the other maps server management
* @see DBApply
*/
-int map_eraseallipport_sub(union DBKey key, struct DBData *data, va_list va)
+static int map_eraseallipport_sub(union DBKey key, struct DBData *data, va_list va)
{
struct map_data_other_server *mdos = DB->data2ptr(data);
nullpo_ret(mdos);
@@ -3217,7 +3317,8 @@ int map_eraseallipport_sub(union DBKey key, struct DBData *data, va_list va)
return 0;
}
-int map_eraseallipport(void) {
+static int map_eraseallipport(void)
+{
map->map_db->foreach(map->map_db,map->eraseallipport_sub);
return 1;
}
@@ -3225,7 +3326,8 @@ int map_eraseallipport(void) {
/*==========================================
* Delete mapindex from db of another map server
*------------------------------------------*/
-int map_eraseipport(unsigned short map_index, uint32 ip, uint16 port) {
+static int map_eraseipport(unsigned short map_index, uint32 ip, uint16 port)
+{
struct map_data_other_server *mdos;
mdos = (struct map_data_other_server*)uidb_get(map->map_db,(unsigned int)map_index);
@@ -3240,97 +3342,125 @@ int map_eraseipport(unsigned short map_index, uint32 ip, uint16 port) {
return 0;
}
-/*==========================================
- * [Shinryo]: Init the mapcache
- *------------------------------------------*/
-char *map_init_mapcache(FILE *fp) {
- struct map_cache_main_header header;
- size_t size = 0;
- char *buffer;
-
- // No file open? Return..
- nullpo_ret(fp);
+/**
+ * Reads a map's compressed cell data from its mapcache file.
+ *
+ * @param[in,out] m The target map.
+ * @return The loading success state.
+ * @retval false in case of errors.
+ */
+static bool map_readfromcache(struct map_data *m)
+{
+ unsigned int file_size;
+ char file_path[256];
+ FILE *fp = NULL;
+ bool retval = false;
+ int16 version;
- // Get file size
- fseek(fp, 0, SEEK_END);
- size = ftell(fp);
- fseek(fp, 0, SEEK_SET);
+ nullpo_retr(false, m);
- // Allocate enough space
- CREATE(buffer, char, size);
+ snprintf(file_path, sizeof(file_path), "%s%s%s.%s", "maps/", DBPATH, m->name, "mcache");
+ fp = fopen(file_path, "rb");
- // No memory? Return..
- nullpo_ret(buffer);
+ if (fp == NULL) {
+ ShowWarning("map_readfromcache: Could not open the mapcache file for map '%s' at path '%s'.\n", m->name, file_path);
+ return false;
+ }
- // Read file into buffer..
- if(fread(buffer, sizeof(char), size, fp) != size) {
- ShowError("map_init_mapcache: Could not read entire mapcache file\n");
- aFree(buffer);
- return NULL;
+ if (fread(&version, sizeof(version), 1, fp) < 1) {
+ ShowError("map_readfromcache: Could not read file version for map '%s'.\n", m->name);
+ fclose(fp);
+ return false;
}
- rewind(fp);
+ fseek(fp, 0, SEEK_END);
+ file_size = (unsigned int)ftell(fp);
+ fseek(fp, 0, SEEK_SET); // Rewind file pointer before passing it to the read function.
- // Get main header to verify if data is corrupted
- if( fread(&header, sizeof(header), 1, fp) != 1 ) {
- ShowError("map_init_mapcache: Error obtaining main header!\n");
- aFree(buffer);
- return NULL;
- }
- if( GetULong((unsigned char *)&(header.file_size)) != size ) {
- ShowError("map_init_mapcache: Map cache is corrupted!\n");
- aFree(buffer);
- return NULL;
+ switch(version) {
+ case 1:
+ retval = map->readfromcache_v1(fp, m, file_size);
+ break;
+ default:
+ ShowError("map_readfromcache: Mapcache file has unknown version '%d' for map '%s'.\n", version, m->name);
+ break;
}
- return buffer;
+ fclose(fp);
+ return retval;
}
-/*==========================================
- * Map cache reading
- * [Shinryo]: Optimized some behaviour to speed this up
- *==========================================*/
-int map_readfromcache(struct map_data *m, char *buffer) {
- int i;
- struct map_cache_main_header *header = (struct map_cache_main_header *)buffer;
- struct map_cache_map_info *info = NULL;
- char *p = buffer + sizeof(struct map_cache_main_header);
-
- nullpo_ret(m);
- nullpo_ret(buffer);
-
- for(i = 0; i < header->map_count; i++) {
- info = (struct map_cache_map_info *)p;
+/**
+ * Reads a map's compressed cell data from its mapcache file (file format
+ * version 1).
+ *
+ * @param[in] fp The file pointer to read from (opened and closed by
+ * the caller).
+ * @param[in,out] m The target map.
+ * @param[in] file_size The size of the file to load from.
+ * @return The loading success state.
+ * @retval false in case of errors.
+ */
+static bool map_readfromcache_v1(FILE *fp, struct map_data *m, unsigned int file_size)
+{
+ struct map_cache_header mheader = { 0 };
+ uint8 md5buf[16] = { 0 };
+ int map_size;
+ nullpo_retr(false, fp);
+ nullpo_retr(false, m);
+
+ if (file_size <= sizeof(mheader) || fread(&mheader, sizeof(mheader), 1, fp) < 1) {
+ ShowError("map_readfromcache: Failed to read cache header for map '%s'.\n", m->name);
+ return false;
+ }
- if( strcmp(m->name, info->name) == 0 )
- break; // Map found
+ if (mheader.len <= 0) {
+ ShowError("map_readfromcache: A file with negative or zero compressed length passed '%d'.\n", mheader.len);
+ return false;
+ }
- // Jump to next entry..
- p += sizeof(struct map_cache_map_info) + info->len;
+ if (file_size < sizeof(mheader) + mheader.len) {
+ ShowError("map_readfromcache: An incomplete file passed for map '%s'.\n", m->name);
+ return false;
}
- if( info && i < header->map_count ) {
- unsigned long size;
+ if (mheader.ys <= 0 || mheader.xs <= 0) {
+ ShowError("map_readfromcache: A map with invalid size passed '%s' xs: '%d' ys: '%d'.\n", m->name, mheader.xs, mheader.ys);
+ return false;
+ }
- if( info->xs <= 0 || info->ys <= 0 )
- return 0;// Invalid
+ m->xs = mheader.xs;
+ m->ys = mheader.ys;
+ map_size = (int)mheader.xs * (int)mheader.ys;
- m->xs = info->xs;
- m->ys = info->ys;
- size = (unsigned long)info->xs*(unsigned long)info->ys;
+ if (map_size > MAX_MAP_SIZE) {
+ ShowWarning("map_readfromcache: %s exceeded MAX_MAP_SIZE of %d.\n", m->name, MAX_MAP_SIZE);
+ return false;
+ }
- if(size > MAX_MAP_SIZE) {
- ShowWarning("map_readfromcache: %s exceeded MAX_MAP_SIZE of %d\n", info->name, MAX_MAP_SIZE);
- return 0; // Say not found to remove it from list.. [Shinryo]
- }
+ CREATE(m->cell_buf.data, uint8, mheader.len);
+ m->cell_buf.len = mheader.len;
+ if (fread(m->cell_buf.data, mheader.len, 1, fp) < 1) {
+ ShowError("mapreadfromcache: Could not load the compressed cell data for map '%s'.\n", m->name);
+ aFree(m->cell_buf.data);
+ m->cell_buf.data = NULL;
+ m->cell_buf.len = 0;
+ return false;
+ }
- m->cellPos = p;
- m->cell = (struct mapcell *)0xdeadbeaf;
+ md5->binary(m->cell_buf.data, m->cell_buf.len, md5buf);
- return 1;
+ if (memcmp(md5buf, mheader.md5_checksum, sizeof(md5buf)) != 0) {
+ ShowError("mapreadfromcache: md5 checksum check failed for map '%s'\n", m->name);
+ aFree(m->cell_buf.data);
+ m->cell_buf.data = NULL;
+ m->cell_buf.len = 0;
+ return false;
}
- return 0; // Not found
+ m->cell = (struct mapcell *)0xdeadbeaf;
+
+ return true;
}
/**
@@ -3341,7 +3471,7 @@ int map_readfromcache(struct map_data *m, char *buffer) {
* @param mapname The new map's name.
* @return success state.
*/
-int map_addmap(const char *mapname)
+static int map_addmap(const char *mapname)
{
map->list[map->count].instance_id = -1;
mapindex->getmapname(mapname, map->list[map->count++].name);
@@ -3353,7 +3483,7 @@ int map_addmap(const char *mapname)
*
* @param id The map ID.
*/
-void map_delmapid(int id)
+static void map_delmapid(int id)
{
Assert_retv(id >= 0 && id < map->count);
ShowNotice("Removing map [ %s ] from maplist"CL_CLL"\n",map->list[id].name);
@@ -3367,7 +3497,7 @@ void map_delmapid(int id)
* @param mapname The name of the map to remove.
* @return the number of removed maps.
*/
-int map_delmap(const char *mapname)
+static int map_delmap(const char *mapname)
{
int i;
char map_name[MAP_NAME_LENGTH];
@@ -3391,7 +3521,8 @@ int map_delmap(const char *mapname)
/**
*
**/
-void map_zone_clear_single(struct map_zone_data *zone) {
+static void map_zone_clear_single(struct map_zone_data *zone)
+{
int i;
nullpo_retv(zone);
@@ -3433,7 +3564,7 @@ void map_zone_clear_single(struct map_zone_data *zone) {
/**
*
**/
-void map_zone_db_clear(void)
+static void map_zone_db_clear(void)
{
struct DBIterator *iter = db_iterator(map->zone_db);
struct map_zone_data *zone = NULL;
@@ -3451,7 +3582,8 @@ void map_zone_db_clear(void)
/* clear the main zone stuff */
map->zone_clear_single(&map->zone_all);
}
-void map_clean(int i) {
+static void map_clean(int i)
+{
int v;
Assert_retv(i >= 0 && i < map->count);
if(map->list[i].cell && map->list[i].cell != (struct mapcell *)0xdeadbeaf) aFree(map->list[i].cell);
@@ -3502,7 +3634,8 @@ void map_clean(int i) {
if( map->list[i].channel )
channel->delete(map->list[i].channel);
}
-void do_final_maps(void) {
+static void do_final_maps(void)
+{
int i, v = 0;
for( i = 0; i < map->count; i++ ) {
@@ -3561,8 +3694,7 @@ void do_final_maps(void) {
if( map->list[i].channel )
channel->delete(map->list[i].channel);
- if( map->list[i].qi_data )
- aFree(map->list[i].qi_data);
+ quest->questinfo_vector_clear(i);
HPM->data_store_destroy(&map->list[i].hdata);
}
@@ -3570,8 +3702,36 @@ 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.
-void map_flags_init(void) {
+static void map_flags_init(void)
+{
int i, v = 0;
for( i = 0; i < map->count; i++ ) {
@@ -3631,11 +3791,7 @@ void map_flags_init(void) {
map->list[i].short_damage_rate = 100;
map->list[i].long_damage_rate = 100;
- if( map->list[i].qi_data )
- aFree(map->list[i].qi_data);
-
- map->list[i].qi_data = NULL;
- map->list[i].qi_count = 0;
+ VECTOR_INIT(map->list[i].qi_data);
}
}
@@ -3647,7 +3803,7 @@ void map_flags_init(void) {
* Assumed path for file is data/mapname.rsw
* Credits to LittleWolf
*/
-int map_waterheight(char* mapname)
+static int map_waterheight(char *mapname)
{
char fn[256];
char *rsw = NULL;
@@ -3675,7 +3831,7 @@ int map_waterheight(char* mapname)
/*==================================
* .GAT format
*----------------------------------*/
-int map_readgat (struct map_data* m)
+static int map_readgat(struct map_data *m)
{
char filename[256];
uint8* gat;
@@ -3719,12 +3875,14 @@ int map_readgat (struct map_data* m)
/*======================================
* Add/Remove map to the map_db
*--------------------------------------*/
-void map_addmap2db(struct map_data *m) {
+static void map_addmap2db(struct map_data *m)
+{
nullpo_retv(m);
map->index2mapid[m->index] = m->m;
}
-void map_removemapdb(struct map_data *m) {
+static void map_removemapdb(struct map_data *m)
+{
nullpo_retv(m);
map->index2mapid[m->index] = -1;
}
@@ -3732,28 +3890,15 @@ void map_removemapdb(struct map_data *m) {
/*======================================
* Initiate maps loading stage
*--------------------------------------*/
-int map_readallmaps (void) {
+static int map_readallmaps(void)
+{
int i;
- FILE* fp=NULL;
int maps_removed = 0;
- if( map->enable_grf )
+ if (map->enable_grf) {
ShowStatus("Loading maps (using GRF files)...\n");
- else {
- char mapcachefilepath[256];
- snprintf(mapcachefilepath, 256, "%s/%s%s", map->db_path, DBPATH, "map_cache.dat");
- ShowStatus("Loading maps (using %s as map cache)...\n", mapcachefilepath);
- if( (fp = fopen(mapcachefilepath, "rb")) == NULL ) {
- ShowFatalError("Unable to open map cache file "CL_WHITE"%s"CL_RESET"\n", mapcachefilepath);
- exit(EXIT_FAILURE); //No use launching server if maps can't be read.
- }
-
- // Init mapcache data.. [Shinryo]
- map->cache_buffer = map->init_mapcache(fp);
- if(!map->cache_buffer) {
- ShowFatalError("Failed to initialize mapcache data (%s)..\n", mapcachefilepath);
- exit(EXIT_FAILURE);
- }
+ } else {
+ ShowStatus("Loading maps using map cache files...\n");
}
for(i = 0; i < map->count; i++) {
@@ -3767,7 +3912,7 @@ int map_readallmaps (void) {
if( !
(map->enable_grf?
map->readgat(&map->list[i])
- :map->readfromcache(&map->list[i], map->cache_buffer))
+ :map->readfromcache(&map->list[i]))
) {
map->delmapid(i);
maps_removed++;
@@ -3809,10 +3954,6 @@ int map_readallmaps (void) {
// intialization and configuration-dependent adjustments of mapflags
map->flags_init();
- if( !map->enable_grf ) {
- fclose(fp);
- }
-
// finished map loading
ShowInfo("Successfully loaded '"CL_WHITE"%d"CL_RESET"' maps."CL_CLL"\n",map->count);
instance->start_id = map->count; // Next Map Index will be instances
@@ -3832,7 +3973,7 @@ int map_readallmaps (void) {
*
* @retval false in case of error.
*/
-bool map_config_read_console(const char *filename, struct config_t *config, bool imported)
+static bool map_config_read_console(const char *filename, struct config_t *config, bool imported)
{
struct config_setting_t *setting = NULL;
@@ -3866,7 +4007,7 @@ bool map_config_read_console(const char *filename, struct config_t *config, bool
*
* @retval false in case of error.
*/
-bool map_config_read_connection(const char *filename, struct config_t *config, bool imported)
+static bool map_config_read_connection(const char *filename, struct config_t *config, bool imported)
{
struct config_setting_t *setting = NULL;
@@ -3899,7 +4040,7 @@ bool map_config_read_connection(const char *filename, struct config_t *config, b
*
* @retval false in case of error.
*/
-bool map_config_read_inter(const char *filename, struct config_t *config, bool imported)
+static bool map_config_read_inter(const char *filename, struct config_t *config, bool imported)
{
struct config_setting_t *setting = NULL;
const char *str = NULL;
@@ -3949,7 +4090,7 @@ bool map_config_read_inter(const char *filename, struct config_t *config, bool i
*
* @retval false in case of error.
*/
-bool map_config_read_database(const char *filename, struct config_t *config, bool imported)
+static bool map_config_read_database(const char *filename, struct config_t *config, bool imported)
{
struct config_setting_t *setting = NULL;
@@ -3989,7 +4130,7 @@ bool map_config_read_database(const char *filename, struct config_t *config, boo
*
* @retval false in case of error.
*/
-bool map_config_read_map_list(const char *filename, struct config_t *config, bool imported)
+static bool map_config_read_map_list(const char *filename, struct config_t *config, bool imported)
{
struct config_setting_t *setting = NULL;
int i, count = 0;
@@ -4064,7 +4205,7 @@ bool map_config_read_map_list(const char *filename, struct config_t *config, boo
*
* @retval false in case of error.
*/
-bool map_config_read(const char *filename, bool imported)
+static bool map_config_read(const char *filename, bool imported)
{
struct config_t config;
struct config_setting_t *setting = NULL;
@@ -4124,7 +4265,7 @@ bool map_config_read(const char *filename, bool imported)
*
* @retval false in case of error.
*/
-bool map_read_npclist(const char *filename, bool imported)
+static bool map_read_npclist(const char *filename, bool imported)
{
struct config_t config;
struct config_setting_t *setting = NULL;
@@ -4211,7 +4352,8 @@ bool map_read_npclist(const char *filename, bool imported)
*
* @param clear whether to clear the script list before reloading.
*/
-void map_reloadnpc(bool clear) {
+static void map_reloadnpc(bool clear)
+{
int i;
if (clear)
npc->clearsrcfile();
@@ -4236,7 +4378,7 @@ void map_reloadnpc(bool clear) {
*
* @retval false in case of error.
*/
-bool inter_config_read(const char *filename, bool imported)
+static bool inter_config_read(const char *filename, bool imported)
{
struct config_t config;
const struct config_setting_t *setting = NULL;
@@ -4287,7 +4429,7 @@ bool inter_config_read(const char *filename, bool imported)
*
* @retval false in case of error.
*/
-bool inter_config_read_connection(const char *filename, const struct config_t *config, bool imported)
+static bool inter_config_read_connection(const char *filename, const struct config_t *config, bool imported)
{
const struct config_setting_t *setting = NULL;
@@ -4319,7 +4461,7 @@ bool inter_config_read_connection(const char *filename, const struct config_t *c
*
* @retval false in case of error.
*/
-bool inter_config_read_database_names(const char *filename, const struct config_t *config, bool imported)
+static bool inter_config_read_database_names(const char *filename, const struct config_t *config, bool imported)
{
const struct config_setting_t *setting = NULL;
bool retval = true;
@@ -4337,6 +4479,7 @@ bool inter_config_read_database_names(const char *filename, const struct config_
libconfig->setting_lookup_mutable_string(setting, "autotrade_merchants_db", map->autotrade_merchants_db, sizeof(map->autotrade_merchants_db));
libconfig->setting_lookup_mutable_string(setting, "autotrade_data_db", map->autotrade_data_db, sizeof(map->autotrade_data_db));
libconfig->setting_lookup_mutable_string(setting, "npc_market_data_db", map->npc_market_data_db, sizeof(map->npc_market_data_db));
+ libconfig->setting_lookup_mutable_string(setting, "npc_barter_data_db", map->npc_barter_data_db, sizeof(map->npc_barter_data_db));
if (!mapreg->config_read(filename, setting, imported))
retval = false;
@@ -4353,7 +4496,7 @@ bool inter_config_read_database_names(const char *filename, const struct config_
/*=======================================
* MySQL Init
*---------------------------------------*/
-int map_sql_init(void)
+static int map_sql_init(void)
{
// main db connection
map->mysql_handle = SQL->Malloc();
@@ -4370,7 +4513,7 @@ int map_sql_init(void)
return 0;
}
-int map_sql_close(void)
+static int map_sql_close(void)
{
ShowStatus("Close Map DB Connection....\n");
SQL->Free(map->mysql_handle);
@@ -4388,7 +4531,8 @@ int map_sql_close(void)
*
* @return the newly created zone from merging main and other
**/
-struct map_zone_data *map_merge_zone(struct map_zone_data *main, struct map_zone_data *other) {
+static struct map_zone_data *map_merge_zone(struct map_zone_data *main, struct map_zone_data *other)
+{
char newzone[MAP_ZONE_NAME_LENGTH];
struct map_zone_data *zone = NULL;
int cursor, i, j;
@@ -4396,7 +4540,7 @@ struct map_zone_data *map_merge_zone(struct map_zone_data *main, struct map_zone
nullpo_retr(NULL, main);
nullpo_retr(NULL, other);
- snprintf(newzone, MAP_ZONE_NAME_LENGTH, "%s+%s", main->name, other->name);
+ safesnprintf(newzone, MAP_ZONE_NAME_LENGTH, "%s+%s", main->name, other->name);
if( (zone = strdb_get(map->zone_db, newzone)) )
return zone;/* this zone has already been merged */
@@ -4485,10 +4629,12 @@ struct map_zone_data *map_merge_zone(struct map_zone_data *main, struct map_zone
return zone;
}
-void map_zone_change2(int m, struct map_zone_data *zone)
+static void map_zone_change2(int m, struct map_zone_data *zone)
{
const char *empty = "";
+ if (zone == NULL)
+ return;
Assert_retv(m >= 0 && m < map->count);
if( map->list[m].zone == zone )
return;
@@ -4506,7 +4652,8 @@ void map_zone_change2(int m, struct map_zone_data *zone)
map->zone_apply(m,zone,empty,empty,empty);
}
/* when changing from a mapflag to another during runtime */
-void map_zone_change(int m, struct map_zone_data *zone, const char* start, const char* buffer, const char* filepath) {
+static void map_zone_change(int m, struct map_zone_data *zone, const char *start, const char *buffer, const char *filepath)
+{
Assert_retv(m >= 0 && m < map->count);
map->list[m].prev_zone = map->list[m].zone;
@@ -4515,7 +4662,7 @@ void map_zone_change(int m, struct map_zone_data *zone, const char* start, const
map->zone_apply(m,zone,start,buffer,filepath);
}
/* removes previous mapflags from this map */
-void map_zone_remove(int m)
+static void map_zone_remove(int m)
{
char flag[MAP_ZONE_MAPFLAG_LENGTH], params[MAP_ZONE_MAPFLAG_LENGTH];
unsigned short k;
@@ -4542,7 +4689,29 @@ void map_zone_remove(int m)
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) {
+// 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);
RECREATE(map->list[m].zone_mf, char *, ++map->list[m].zone_mf_count);
CREATE(map->list[m].zone_mf[map->list[m].zone_mf_count - 1], char, MAP_ZONE_MAPFLAG_LENGTH);
@@ -4550,7 +4719,8 @@ static inline void map_zone_mf_cache_add(int m, char *rflag) {
}
/* TODO: introduce enumerations to each mapflag so instead of reading the string a number of times we read it only once and use its value wherever we need */
/* cache previous values to revert */
-bool map_zone_mf_cache(int m, char *flag, char *params) {
+static bool map_zone_mf_cache(int m, char *flag, char *params)
+{
char rflag[MAP_ZONE_MAPFLAG_LENGTH];
int state = 1;
@@ -4806,6 +4976,15 @@ bool map_zone_mf_cache(int m, char *flag, char *params) {
else if( map->list[m].flag.battleground )
map_zone_mf_cache_add(m,"battleground");
}
+ } else if (!strcmpi(flag,"cvc")) {
+ if (state && map->list[m].flag.cvc) {
+ ;/* nothing to do */
+ } else {
+ if (state)
+ map_zone_mf_cache_add(m,"cvc\toff");
+ else if (map->list[m].flag.cvc)
+ map_zone_mf_cache_add(m,"cvc");
+ }
} else if (!strcmpi(flag,"noexppenalty")) {
if( state && map->list[m].flag.noexppenalty )
;/* nothing to do */
@@ -5078,11 +5257,12 @@ bool map_zone_mf_cache(int m, char *flag, char *params) {
}
} else if (!strcmpi(flag,"adjust_unit_duration")) {
int skill_id, k;
- char skill_name[MAP_ZONE_MAPFLAG_LENGTH], modifier[MAP_ZONE_MAPFLAG_LENGTH];
- size_t len = strlen(params);
+ char skill_name[MAX_SKILL_NAME_LENGTH], modifier[MAP_ZONE_MAPFLAG_LENGTH];
+ size_t len;
modifier[0] = '\0';
- memcpy(skill_name, params, MAP_ZONE_MAPFLAG_LENGTH);
+ safestrncpy(skill_name, params, MAX_SKILL_NAME_LENGTH);
+ len = strlen(skill_name);
for(k = 0; k < len; k++) {
if( skill_name[k] == '\t' ) {
@@ -5111,11 +5291,12 @@ bool map_zone_mf_cache(int m, char *flag, char *params) {
}
} else if (!strcmpi(flag,"adjust_skill_damage")) {
int skill_id, k;
- char skill_name[MAP_ZONE_MAPFLAG_LENGTH], modifier[MAP_ZONE_MAPFLAG_LENGTH];
- size_t len = strlen(params);
+ char skill_name[MAX_SKILL_NAME_LENGTH], modifier[MAP_ZONE_MAPFLAG_LENGTH];
+ size_t len;
modifier[0] = '\0';
- memcpy(skill_name, params, MAP_ZONE_MAPFLAG_LENGTH);
+ safestrncpy(skill_name, params, MAX_SKILL_NAME_LENGTH);
+ len = strlen(skill_name);
for(k = 0; k < len; k++) {
if( skill_name[k] == '\t' ) {
@@ -5249,7 +5430,7 @@ bool map_zone_mf_cache(int m, char *flag, char *params) {
return false;
}
-void map_zone_apply(int m, struct map_zone_data *zone, const char* start, const char* buffer, const char* filepath)
+static void map_zone_apply(int m, struct map_zone_data *zone, const char *start, const char *buffer, const char *filepath)
{
int i;
const char *empty = "";
@@ -5277,7 +5458,7 @@ void map_zone_apply(int m, struct map_zone_data *zone, const char* start, const
}
}
/* used on npc load and reload to apply all "Normal" and "PK Mode" zones */
-void map_zone_init(void)
+static void map_zone_init(void)
{
char flag[MAP_ZONE_MAPFLAG_LENGTH], params[MAP_ZONE_MAPFLAG_LENGTH];
struct map_zone_data *zone;
@@ -5331,12 +5512,13 @@ void map_zone_init(void)
}
}
-unsigned short map_zone_str2itemid(const char *name) {
+static int map_zone_str2itemid(const char *name)
+{
struct item_data *data;
if( !name )
return 0;
- if( name[0] == 'I' && name[1] == 'D' && strlen(name) < 8 ) {
+ if (name[0] == 'I' && name[1] == 'D' && strlen(name) <= 12) {
if( !( data = itemdb->exists(atoi(name+2))) ) {
return 0;
}
@@ -5347,13 +5529,14 @@ unsigned short map_zone_str2itemid(const char *name) {
}
return data->nameid;
}
-unsigned short map_zone_str2skillid(const char *name) {
+static unsigned short map_zone_str2skillid(const char *name)
+{
unsigned short nameid = 0;
if( !name )
return 0;
- if( name[0] == 'I' && name[1] == 'D' && strlen(name) < 8 ) {
+ if (name[0] == 'I' && name[1] == 'D' && strlen(name) <= 12) {
if( !skill->get_index((nameid = atoi(name+2))) )
return 0;
} else {
@@ -5363,7 +5546,8 @@ unsigned short map_zone_str2skillid(const char *name) {
}
return nameid;
}
-enum bl_type map_zone_bl_type(const char *entry, enum map_zone_skill_subtype *subtype) {
+static enum bl_type map_zone_bl_type(const char *entry, enum map_zone_skill_subtype *subtype)
+{
char temp[200], *parse;
enum bl_type bl = BL_NUL;
@@ -5409,7 +5593,8 @@ enum bl_type map_zone_bl_type(const char *entry, enum map_zone_skill_subtype *su
return bl;
}
/* [Ind/Hercules] */
-void read_map_zone_db(void) {
+static void read_map_zone_db(void)
+{
struct config_t map_zone_db;
struct config_setting_t *zones = NULL;
/* TODO: #ifndef required for re/pre-re */
@@ -5830,43 +6015,38 @@ void read_map_zone_db(void) {
zone->merge_type = MZMT_MERGEABLE;
if( (zone = strdb_get(map->zone_db, MAP_ZONE_BG_NAME)) )
zone->merge_type = MZMT_MERGEABLE;
+ if ((zone = strdb_get(map->zone_db, MAP_ZONE_CVC_NAME)))
+ zone->merge_type = MZMT_MERGEABLE;
}
/* not supposed to go in here but in skill_final whatever */
libconfig->destroy(&map_zone_db);
}
-int map_get_new_bonus_id (void) {
+static int map_get_new_bonus_id(void)
+{
return map->bonus_id++;
}
-void map_add_questinfo(int m, struct questinfo *qi) {
- unsigned short i;
-
+static void map_add_questinfo(int m, struct questinfo *qi)
+{
nullpo_retv(qi);
Assert_retv(m >= 0 && m < map->count);
- /* duplicate, override */
- for(i = 0; i < map->list[m].qi_count; i++) {
- if( map->list[m].qi_data[i].nd == qi->nd )
- break;
- }
-
- if( i == map->list[m].qi_count )
- RECREATE(map->list[m].qi_data, struct questinfo, ++map->list[m].qi_count);
- memcpy(&map->list[m].qi_data[i], qi, sizeof(struct questinfo));
+ VECTOR_ENSURE(map->list[m].qi_data, 1, 1);
+ VECTOR_PUSH(map->list[m].qi_data, *qi);
}
-bool map_remove_questinfo(int m, struct npc_data *nd) {
+static bool map_remove_questinfo(int m, struct npc_data *nd)
+{
unsigned short i;
+ nullpo_retr(false, nd);
Assert_retr(false, m >= 0 && m < map->count);
- for(i = 0; i < map->list[m].qi_count; i++) {
- struct questinfo *qi = &map->list[m].qi_data[i];
- if( qi->nd == nd ) {
- memset(&map->list[m].qi_data[i], 0, sizeof(struct questinfo));
- if( i != --map->list[m].qi_count ) {
- memmove(&map->list[m].qi_data[i],&map->list[m].qi_data[i+1],sizeof(struct questinfo)*(map->list[m].qi_count-i));
- }
+
+ for (i = 0; i < VECTOR_LENGTH(map->list[m].qi_data); i++) {
+ struct questinfo *qi_data = &VECTOR_INDEX(map->list[m].qi_data, i);
+ if (qi_data->nd == nd) {
+ VECTOR_ERASE(map->list[m].qi_data, i);
return true;
}
}
@@ -5876,7 +6056,7 @@ bool map_remove_questinfo(int m, struct npc_data *nd) {
/**
* @see DBApply
*/
-int map_db_final(union DBKey key, struct DBData *data, va_list ap)
+static int map_db_final(union DBKey key, struct DBData *data, va_list ap)
{
struct map_data_other_server *mdos = DB->data2ptr(data);
@@ -5889,7 +6069,7 @@ int map_db_final(union DBKey key, struct DBData *data, va_list ap)
/**
* @see DBApply
*/
-int nick_db_final(union DBKey key, struct DBData *data, va_list args)
+static int nick_db_final(union DBKey key, struct DBData *data, va_list args)
{
struct charid2nick* p = DB->data2ptr(data);
struct charid_request* req;
@@ -5906,7 +6086,8 @@ int nick_db_final(union DBKey key, struct DBData *data, va_list args)
return 0;
}
-int cleanup_sub(struct block_list *bl, va_list ap) {
+static int cleanup_sub(struct block_list *bl, va_list ap)
+{
nullpo_ret(bl);
switch(bl->type) {
@@ -5936,7 +6117,7 @@ int cleanup_sub(struct block_list *bl, va_list ap) {
/**
* @see DBApply
*/
-int cleanup_db_sub(union DBKey key, struct DBData *data, va_list va)
+static int cleanup_db_sub(union DBKey key, struct DBData *data, va_list va)
{
return map->cleanup_sub(DB->data2ptr(data), va);
}
@@ -5944,7 +6125,8 @@ int cleanup_db_sub(union DBKey key, struct DBData *data, va_list va)
/*==========================================
* map destructor
*------------------------------------------*/
-int do_final(void) {
+int do_final(void)
+{
int i;
struct map_session_data* sd;
struct s_mapiterator* iter;
@@ -5990,6 +6172,7 @@ int do_final(void) {
ircbot->final();/* before channel. */
channel->final();
chrif->final();
+ clan->final();
clif->final();
npc->final();
quest->final();
@@ -6012,6 +6195,8 @@ int do_final(void) {
elemental->final();
map->list_final();
vending->final();
+ rodex->final();
+ achievement->final();
HPM_map_do_final();
@@ -6034,6 +6219,11 @@ int do_final(void) {
ers_destroy(map->iterator_ers);
ers_destroy(map->flooritem_ers);
+ for (i = 0; i < map->count; ++i) {
+ if (map->list[i].cell_buf.data != NULL)
+ aFree(map->list[i].cell_buf.data);
+ map->list[i].cell_buf.len = 0;
+ }
aFree(map->list);
if( map->block_free )
@@ -6041,9 +6231,6 @@ int do_final(void) {
if( map->bl_list )
aFree(map->bl_list);
- if( !map->enable_grf )
- aFree(map->cache_buffer);
-
aFree(map->MAP_CONF_NAME);
aFree(map->BATTLE_CONF_FILENAME);
aFree(map->ATCOMMAND_CONF_FILENAME);
@@ -6059,7 +6246,8 @@ int do_final(void) {
return map->retval;
}
-int map_abort_sub(struct map_session_data* sd, va_list ap) {
+static int map_abort_sub(struct map_session_data *sd, va_list ap)
+{
chrif->save(sd,1);
return 1;
}
@@ -6088,12 +6276,13 @@ void do_abort(void)
chrif->flush();
}
-void set_server_type(void) {
+void set_server_type(void)
+{
SERVER_TYPE = SERVER_TYPE_MAP;
}
/// Called when a terminate signal is received.
-void do_shutdown(void)
+static void do_shutdown(void)
{
if( core->runflag != MAPSERVER_ST_SHUTDOWN )
{
@@ -6111,7 +6300,8 @@ void do_shutdown(void)
}
}
-CPCMD(gm_position) {
+static CPCMD(gm_position)
+{
int x = 0, y = 0, m = 0;
char map_name[25];
@@ -6135,7 +6325,8 @@ CPCMD(gm_position) {
map->cpsd->bl.y = y;
map->cpsd->bl.m = m;
}
-CPCMD(gm_use) {
+static CPCMD(gm_use)
+{
if( line == NULL ) {
ShowError("gm:use invalid syntax. use '"CL_WHITE"gm:use @command <optional params>"CL_RESET"'\n");
@@ -6152,7 +6343,8 @@ CPCMD(gm_use) {
map->cpsd_active = false;
}
/* Hercules Console Parser */
-void map_cp_defaults(void) {
+static void map_cp_defaults(void)
+{
#ifdef CONSOLE_INPUT
/* default HCP data */
map->cpsd = pc->get_dummy_sd();
@@ -6166,7 +6358,8 @@ void map_cp_defaults(void) {
#endif
}
-void map_load_defaults(void) {
+static void map_load_defaults(void)
+{
mapindex_defaults();
map_defaults();
/* */
@@ -6175,6 +6368,7 @@ void map_load_defaults(void) {
battleground_defaults();
buyingstore_defaults();
channel_defaults();
+ clan_defaults();
clif_defaults();
chrif_defaults();
guild_defaults();
@@ -6207,7 +6401,9 @@ void map_load_defaults(void) {
pet_defaults();
path_defaults();
quest_defaults();
+ achievement_defaults();
npc_chat_defaults();
+ rodex_defaults();
}
/**
* --run-once handler
@@ -6506,6 +6702,7 @@ int do_init(int argc, char *argv[])
ircbot->init(minimal);
script->init(minimal);
itemdb->init(minimal);
+ clan->init(minimal);
skill->init(minimal);
if (!minimal)
map->read_zone_db();/* read after item and skill initialization */
@@ -6520,11 +6717,13 @@ int do_init(int argc, char *argv[])
mercenary->init(minimal);
elemental->init(minimal);
quest->init(minimal);
+ achievement->init(minimal);
npc->init(minimal);
unit->init(minimal);
bg->init(minimal);
duel->init(minimal);
vending->init(minimal);
+ rodex->init(minimal);
if (map->scriptcheck) {
bool failed = map->extra_scripts_count > 0 ? false : true;
@@ -6544,6 +6743,7 @@ int do_init(int argc, char *argv[])
npc->event_do_oninit( false ); // Init npcs (OnInit)
npc->market_fromsql(); /* after OnInit */
+ npc->barter_fromsql(); /* after OnInit */
if (battle_config.pk_mode)
ShowNotice("Server is running on '"CL_WHITE"PK Mode"CL_RESET"'.\n");
@@ -6571,11 +6771,12 @@ int do_init(int argc, char *argv[])
}
/*=====================================
-* Default Functions : map.h
-* Generated by HerculesInterfaceMaker
-* created by Susu
-*-------------------------------------*/
-void map_defaults(void) {
+ * Default Functions : map.h
+ * Generated by HerculesInterfaceMaker
+ * created by Susu
+ *-------------------------------------*/
+void map_defaults(void)
+{
map = &map_s;
/* */
@@ -6655,7 +6856,6 @@ void map_defaults(void) {
map->list = NULL;
map->iterator_ers = NULL;
- map->cache_buffer = NULL;
map->flooritem_ers = NULL;
/* */
@@ -6663,9 +6863,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;
@@ -6735,6 +6937,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;
@@ -6802,8 +7005,8 @@ void map_defaults(void) {
map->iwall_nextxy = map_iwall_nextxy;
map->create_map_data_other_server = create_map_data_other_server;
map->eraseallipport_sub = map_eraseallipport_sub;
- map->init_mapcache = map_init_mapcache;
map->readfromcache = map_readfromcache;
+ map->readfromcache_v1 = map_readfromcache_v1;
map->addmap = map_addmap;
map->delmapid = map_delmapid;
map->zone_db_clear = map_zone_db_clear;