From a2306446c86b3333e69b082e41ae76ba71a42d9d Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 24 Mar 2011 13:57:13 -0700 Subject: Optimize common objects, and adjust other objects accordingly. Major changes still need to be made to each of the servers. --- src/map/Makefile | 4 +- src/map/atcommand.c | 29 ++--- src/map/battle.c | 26 ++--- src/map/chat.c | 5 +- src/map/chrif.c | 33 +++--- src/map/clif.c | 56 ++++----- src/map/clif.h | 2 +- src/map/guild.c | 77 +++++-------- src/map/itemdb.c | 26 ++--- src/map/magic-expr.c | 5 +- src/map/magic-interpreter-base.c | 11 +- src/map/magic-interpreter-parser.y | 14 +-- src/map/magic-interpreter.h | 1 - src/map/magic-stmt.c | 31 +++-- src/map/map.c | 125 ++++++++------------- src/map/map.h | 6 +- src/map/mob.c | 183 +++++++++++++----------------- src/map/mob.h | 8 +- src/map/npc.c | 215 +++++++++++++++-------------------- src/map/npc.h | 2 +- src/map/party.c | 26 ++--- src/map/pc.c | 125 ++++++++------------- src/map/pc.h | 10 +- src/map/script.c | 125 ++++++++------------- src/map/skill-pools.c | 2 +- src/map/skill.c | 225 +++++++++++++++++-------------------- src/map/skill.h | 4 +- src/map/storage.c | 20 +--- src/map/tmw.c | 3 +- 29 files changed, 580 insertions(+), 819 deletions(-) (limited to 'src/map') diff --git a/src/map/Makefile b/src/map/Makefile index f31279c..d340015 100644 --- a/src/map/Makefile +++ b/src/map/Makefile @@ -5,8 +5,8 @@ all: map obj: mkdir obj -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/grfio.o ../common/db.o ../common/lock.o ../common/nullpo.o ../common/malloc.o ../common/mt_rand.o ../common/md5calc.o -LDLIBS = -lz -lm +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/grfio.o ../common/db.o ../common/lock.o ../common/nullpo.o ../common/mt_rand.o ../common/md5calc.o +LDLIBS = -lm map: obj/tmw.o obj/magic-interpreter-lexer.o obj/magic-interpreter-parser.o obj/magic-interpreter-base.o obj/magic-expr.o obj/magic-stmt.o obj/magic.o obj/map.o obj/chrif.o obj/clif.o obj/pc.o obj/npc.o obj/chat.o obj/path.o obj/itemdb.o obj/mob.o obj/script.o obj/storage.o obj/skill.o obj/skill-pools.o obj/atcommand.o obj/battle.o obj/intif.o obj/trade.o obj/party.o obj/guild.o $(COMMON_OBJ) ${LINK.c} $^ ${LDLIBS} -o $@ diff --git a/src/map/atcommand.c b/src/map/atcommand.c index cb9e93c..6a09970 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -13,6 +13,7 @@ #include "../common/socket.h" #include "../common/timer.h" #include "../common/nullpo.h" +#include "../common/mt_rand.h" #include "atcommand.h" #include "battle.h" @@ -794,7 +795,7 @@ AtCommandType atcommand (const int level, const char *message, while (atcommand_info[i].type != AtCommand_Unknown) { - if (strcmpi (command + 1, atcommand_info[i].command + 1) == 0 + if (strcasecmp (command + 1, atcommand_info[i].command + 1) == 0 && level >= atcommand_info[i].level) { p[0] = atcommand_info[i].command[0]; // set correct first symbol for after. @@ -862,7 +863,7 @@ int msg_config_read (const char *cfgName) continue; if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) == 2) { - if (strcmpi (w1, "import") == 0) + if (strcasecmp (w1, "import") == 0) { msg_config_read (w2); } @@ -891,7 +892,7 @@ static AtCommandInfo *get_atcommandinfo_byname (const char *name) int i; for (i = 0; atcommand_info[i].type != AtCommand_Unknown; i++) - if (strcmpi (atcommand_info[i].command + 1, name) == 0) + if (strcasecmp (atcommand_info[i].command + 1, name) == 0) return &atcommand_info[i]; return NULL; @@ -930,9 +931,9 @@ int atcommand_config_read (const char *cfgName) p->level = 0; } - if (strcmpi (w1, "import") == 0) + if (strcasecmp (w1, "import") == 0) atcommand_config_read (w2); - else if (strcmpi (w1, "command_symbol") == 0 && w2[0] > 31 && w2[0] != '/' && // symbol of standard ragnarok GM commands + else if (strcasecmp (w1, "command_symbol") == 0 && w2[0] > 31 && w2[0] != '/' && // symbol of standard ragnarok GM commands w2[0] != '%') // symbol of party chat speaking command_symbol = w2[0]; } @@ -3506,7 +3507,7 @@ int atcommand_param (const int fd, struct map_session_data *sd, index = -1; for (i = 0; param[i] != NULL; i++) { - if (strcmpi (command, param[i]) == 0) + if (strcasecmp (command, param[i]) == 0) { index = i; break; @@ -7131,12 +7132,12 @@ int atcommand_email (const int fd, struct map_session_data *sd, clif_displaymessage (fd, msg_table[145]); // Invalid new email. Please enter a real e-mail. return -1; } - else if (strcmpi (new_email, "a@a.com") == 0) + else if (strcasecmp (new_email, "a@a.com") == 0) { clif_displaymessage (fd, msg_table[146]); // New email must be a real e-mail. return -1; } - else if (strcmpi (actual_email, new_email) == 0) + else if (strcasecmp (actual_email, new_email) == 0) { clif_displaymessage (fd, msg_table[147]); // New email must be different of the actual e-mail. return -1; @@ -7829,7 +7830,7 @@ atcommand_dropall (const int fd, struct map_session_data *sd, /*========================================== * @chardropall by [MouseJstr] - * + * * Throw all the characters possessions on the ground. Normally * done in response to them being disrespectful of a GM *------------------------------------------ @@ -7967,8 +7968,8 @@ atcommand_skillid (const int fd, struct map_session_data *sd, skillen = strlen (message); while (skill_names[idx].id != 0) { - if ((strnicmp (skill_names[idx].name, message, skillen) == 0) || - (strnicmp (skill_names[idx].desc, message, skillen) == 0)) + if ((strncasecmp (skill_names[idx].name, message, skillen) == 0) || + (strncasecmp (skill_names[idx].desc, message, skillen) == 0)) { char output[255]; sprintf (output, "skill %d: %s", skill_names[idx].id, @@ -8116,7 +8117,7 @@ atcommand_leaves (const int fd, struct map_session_data *sd, } /*========================================== - * + * *------------------------------------------ */ int atcommand_summon (const int fd, struct map_session_data *sd, @@ -8182,7 +8183,7 @@ atcommand_adjcmdlvl (const int fd, struct map_session_data *sd, } for (i = 0; atcommand_info[i].type != AtCommand_None; i++) - if (strcmpi (cmd, atcommand_info[i].command + 1) == 0) + if (strcasecmp (cmd, atcommand_info[i].command + 1) == 0) { atcommand_info[i].level = newlev; clif_displaymessage (fd, "@command level changed."); @@ -8230,7 +8231,7 @@ atcommand_adjgmlvl (const int fd, struct map_session_data *sd, * * Open a trade window with a remote player * - * If I have to jump to a remote player one more time, I am + * If I have to jump to a remote player one more time, I am * gonna scream! *------------------------------------------ */ diff --git a/src/map/battle.c b/src/map/battle.c index c9e341d..a6a803a 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -8,7 +8,6 @@ #include "../common/timer.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "clif.h" #include "guild.h" @@ -1423,22 +1422,19 @@ struct battle_delay_damage_ int damage; int flag; }; -int battle_delay_damage_sub (int tid, unsigned int tick, int id, int data) +void battle_delay_damage_sub (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct battle_delay_damage_ *dat = (struct battle_delay_damage_ *) data; if (dat && map_id2bl (id) == dat->src && dat->target->prev != NULL) battle_damage (dat->src, dat->target, dat->damage, dat->flag); free (dat); - return 0; } int battle_delay_damage (unsigned int tick, struct block_list *src, struct block_list *target, int damage, int flag) { - struct battle_delay_damage_ *dat = - (struct battle_delay_damage_ *) aCalloc (1, - sizeof (struct - battle_delay_damage_)); + struct battle_delay_damage_ *dat; + CREATE (dat, struct battle_delay_damage_, 1); nullpo_retr (0, src); nullpo_retr (0, target); @@ -5432,12 +5428,12 @@ int battle_check_range (struct block_list *src, struct block_list *bl, */ int battle_config_switch (const char *str) { - if (strcmpi (str, "on") == 0 || strcmpi (str, "yes") == 0 - || strcmpi (str, "oui") == 0 || strcmpi (str, "ja") == 0 - || strcmpi (str, "si") == 0) + if (strcasecmp (str, "on") == 0 || strcasecmp (str, "yes") == 0 + || strcasecmp (str, "oui") == 0 || strcasecmp (str, "ja") == 0 + || strcasecmp (str, "si") == 0) return 1; - if (strcmpi (str, "off") == 0 || strcmpi (str, "no") == 0 - || strcmpi (str, "non") == 0 || strcmpi (str, "nein") == 0) + if (strcasecmp (str, "off") == 0 || strcasecmp (str, "no") == 0 + || strcasecmp (str, "non") == 0 || strcasecmp (str, "nein") == 0) return 0; return atoi (str); } @@ -6118,10 +6114,10 @@ int battle_config_read (const char *cfgName) if (sscanf (line, "%[^:]:%s", w1, w2) != 2) continue; for (i = 0; i < sizeof (data) / (sizeof (data[0])); i++) - if (strcmpi (w1, data[i].str) == 0) + if (strcasecmp (w1, data[i].str) == 0) *data[i].val = battle_config_switch (w2); - if (strcmpi (w1, "import") == 0) + if (strcasecmp (w1, "import") == 0) battle_config_read (w2); } fclose_ (fp); @@ -6276,8 +6272,6 @@ int battle_config_read (const char *cfgName) if ((battle_config.packet_ver_flag & 63) == 0) // added by [Yor] battle_config.packet_ver_flag = 63; // accept all clients - add_timer_func_list (battle_delay_damage_sub, - "battle_delay_damage_sub"); } return 0; diff --git a/src/map/chat.c b/src/map/chat.c index 0163eed..00aadea 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -5,7 +5,6 @@ #include "../common/db.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "map.h" #include "clif.h" #include "pc.h" @@ -29,7 +28,7 @@ int chat_createchat (struct map_session_data *sd, int limit, int pub, nullpo_retr (0, sd); - cd = aCalloc (1, sizeof (struct chat_data)); + cd = calloc (1, sizeof (struct chat_data)); cd->limit = limit; cd->pub = pub; @@ -280,7 +279,7 @@ int chat_createnpcchat (struct npc_data *nd, int limit, int pub, int trigger, nullpo_retr (1, nd); - cd = aCalloc (1, sizeof (struct chat_data)); + cd = calloc (1, sizeof (struct chat_data)); cd->limit = cd->trigger = limit; if (trigger > 0) diff --git a/src/map/chrif.c b/src/map/chrif.c index 8bbeb59..b80b4fd 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -1121,7 +1121,7 @@ void ladmin_itemfrob (int fd) * *------------------------------------------ */ -int chrif_parse (int fd) +void chrif_parse (int fd) { int packet_len, cmd; @@ -1138,7 +1138,7 @@ int chrif_parse (int fd) } close (fd); delete_session (fd); - return 0; + return; } while (RFIFOREST (fd) >= 2) @@ -1156,20 +1156,20 @@ int chrif_parse (int fd) if (r == 1) continue; // intifで処理した if (r == 2) - return 0; // intifで処理したが、データが足りない + return; // intifで処理したが、データが足りない session[fd]->eof = 1; - return 0; + return; } packet_len = packet_len_table[cmd - 0x2af8]; if (packet_len == -1) { if (RFIFOREST (fd) < 4) - return 0; + return; packet_len = RFIFOW (fd, 2); } if (RFIFOREST (fd) < packet_len) - return 0; + return; switch (cmd) { @@ -1235,12 +1235,10 @@ int chrif_parse (int fd) printf ("chrif_parse : unknown packet %d %d\n", fd, RFIFOW (fd, 0)); session[fd]->eof = 1; - return 0; + return; } RFIFOSKIP (fd, packet_len); } - - return 0; } /*========================================== @@ -1248,13 +1246,13 @@ int chrif_parse (int fd) * 今このmap鯖に繋がっているクライアント人数をchar鯖へ送る *------------------------------------------ */ -int send_users_tochar (int tid, unsigned int tick, int id, int data) +void send_users_tochar (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int users = 0, i; struct map_session_data *sd; if (char_fd <= 0 || session[char_fd] == NULL) - return 0; + return; WFIFOW (char_fd, 0) = 0x2aff; for (i = 0; i < fd_max; i++) @@ -1271,8 +1269,6 @@ int send_users_tochar (int tid, unsigned int tick, int id, int data) WFIFOW (char_fd, 2) = 6 + 4 * users; WFIFOW (char_fd, 4) = users; WFIFOSET (char_fd, 6 + 4 * users); - - return 0; } /*========================================== @@ -1280,21 +1276,19 @@ int send_users_tochar (int tid, unsigned int tick, int id, int data) * char鯖との接続を確認し、もし切れていたら再度接続する *------------------------------------------ */ -int check_connect_char_server (int tid, unsigned int tick, int id, int data) +void check_connect_char_server (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { if (char_fd <= 0 || session[char_fd] == NULL) { printf ("Attempt to connect to char-server...\n"); chrif_state = 0; if ((char_fd = make_connection (char_ip, char_port)) < 0) - return 0; + return; session[char_fd]->func_parse = chrif_parse; realloc_fifo (char_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); chrif_connect (char_fd); } - - return 0; } /*========================================== @@ -1303,9 +1297,8 @@ int check_connect_char_server (int tid, unsigned int tick, int id, int data) */ int do_init_chrif (void) { - add_timer_func_list (check_connect_char_server, - "check_connect_char_server"); - add_timer_func_list (send_users_tochar, "send_users_tochar"); +// add_timer_func_list (check_connect_char_server, "check_connect_char_server"); +// add_timer_func_list (send_users_tochar, "send_users_tochar"); add_timer_interval (gettick () + 1000, check_connect_char_server, 0, 0, 10 * 1000); add_timer_interval (gettick () + 1000, send_users_tochar, 0, 0, 5 * 1000); diff --git a/src/map/clif.c b/src/map/clif.c index d630815..8bbf112 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -20,10 +20,10 @@ #include "../common/socket.h" #include "../common/timer.h" -#include "../common/malloc.h" #include "../common/version.h" #include "../common/nullpo.h" #include "../common/md5calc.h" +#include "../common/mt_rand.h" #include "atcommand.h" #include "battle.h" @@ -755,15 +755,13 @@ int clif_clearchar (struct block_list *bl, int type) return 0; } -static int clif_clearchar_delay_sub (int tid, unsigned int tick, int id, - int data) +static void clif_clearchar_delay_sub (timer_id tid, tick_t tick, custom_id_t id, + custom_data_t data) { struct block_list *bl = (struct block_list *) id; clif_clearchar (bl, data); map_freeblock (bl); - - return 0; } int clif_clearchar_delay (unsigned int tick, struct block_list *bl, int type) @@ -775,7 +773,7 @@ int clif_clearchar_delay (unsigned int tick, struct block_list *bl, int type) exit (1); } memcpy (tmpbl, bl, sizeof (struct block_list)); - add_timer (tick, clif_clearchar_delay_sub, (int) tmpbl, type); + add_timer (tick, clif_clearchar_delay_sub, (custom_id_t) tmpbl, type); return 0; } @@ -1513,12 +1511,10 @@ void clif_quitsave (int fd, struct map_session_data *sd) * *------------------------------------------ */ -static int clif_waitclose (int tid, unsigned int tick, int id, int data) +static void clif_waitclose (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { if (session[id]) session[id]->eof = 1; - - return 0; } /*========================================== @@ -5653,7 +5649,7 @@ int clif_combo_delay (struct block_list *bl, int wait) *白刃取り *------------------------------------------ */ -int clif_bladestop (struct block_list *src, struct block_list *dst, int bool) +int clif_bladestop (struct block_list *src, struct block_list *dst, int boolean) { unsigned char buf[32]; @@ -5663,7 +5659,7 @@ int clif_bladestop (struct block_list *src, struct block_list *dst, int bool) WBUFW (buf, 0) = 0x1d1; WBUFL (buf, 2) = src->id; WBUFL (buf, 6) = dst->id; - WBUFL (buf, 10) = bool; + WBUFL (buf, 10) = boolean; clif_send (buf, packet_len_table[0x1d1], src, AREA); @@ -8582,7 +8578,7 @@ void clif_parse_PartyMessage (int fd, struct map_session_data *sd) clif_displaymessage (fd, msg_txt (505)); return; } - + if (is_atcommand (fd, sd, message, 0) != AtCommand_None || (sd->sc_data && (sd->sc_data[SC_BERSERK].timer != -1 //バーサーク時は会話も不可 || sd->sc_data[SC_NOCHAT].timer != -1))) //チャット禁止 @@ -9907,7 +9903,7 @@ func_table clif_parse_func_table[0x220] = // *INDENT-ON* // Checks for packet flooding -int clif_check_packet_flood(fd, cmd) +int clif_check_packet_flood(int fd, int cmd) { struct map_session_data *sd = session[fd]->session_data; unsigned int rate, tick = gettick(); @@ -10025,7 +10021,7 @@ static char *clif_validate_chat (struct map_session_data *sd, int type, fd = sd->fd; msg_len = RFIFOW (fd, 2) - 4; name_len = strlen (sd->status.name); - /* + /* * At least one character is required in all instances. * Notes for length checks: * @@ -10063,9 +10059,9 @@ static char *clif_validate_chat (struct map_session_data *sd, int type, p = (char *) (type != 1) ? RFIFOP (fd, 4) : RFIFOP (fd, 28); buf_len = (type == 1) ? msg_len - min_len: msg_len; - /* + /* * The client attempted to exceed the maximum message length. - * + * * The conf suggests up to chat_maxline characters, after which the message * is truncated. But the previous behavior was to drop the message, so * we'll do that, too. @@ -10079,7 +10075,7 @@ static char *clif_validate_chat (struct map_session_data *sd, int type, /* We're leaving an extra eight bytes for public/global chat, 1 for NUL. */ buf_len += (type == 2) ? 8 + 1 : 1; - buf = (char *) aMalloc (buf_len); + buf = (char *) malloc (buf_len); memcpy ((type != 2) ? buf : buf + 8, p, (type != 2) ? buf_len - 1 : buf_len - 8 - 1); buf[buf_len - 1] = '\0'; @@ -10118,7 +10114,7 @@ static char *clif_validate_chat (struct map_session_data *sd, int type, * socket.cのdo_parsepacketから呼び出される *------------------------------------------ */ -static int clif_parse (int fd) +static void clif_parse (int fd) { int packet_len = 0, cmd = 0; struct map_session_data *sd = NULL; @@ -10158,11 +10154,11 @@ static int clif_parse (int fd) close (fd); if (fd) delete_session (fd); - return 0; + return; } if (RFIFOREST (fd) < 2) - return 0; // Too small (no packet number) + return; // Too small (no packet number) cmd = RFIFOW (fd, 0); @@ -10187,10 +10183,10 @@ static int clif_parse (int fd) session[fd]->eof = 1; break; } - return 0; + return; } else if (cmd >= 0x200) - return 0; + return; // パケット長を計算 packet_len = packet_len_table[cmd]; @@ -10198,19 +10194,19 @@ static int clif_parse (int fd) { if (RFIFOREST (fd) < 4) { - return 0; // Runt packet (variable length without a length sent) + return; // Runt packet (variable length without a length sent) } packet_len = RFIFOW (fd, 2); if (packet_len < 4 || packet_len > 32768) { session[fd]->eof = 1; - return 0; // Runt packet (variable out of bounds) + return; // Runt packet (variable out of bounds) } } if (RFIFOREST (fd) < packet_len) { - return 0; // Runt packet (sent legnth is too small) + return; // Runt packet (sent legnth is too small) } if (sd && sd->state.auth == 1 && sd->state.waitingdisconnect == 1) @@ -10223,7 +10219,7 @@ static int clif_parse (int fd) { // Flood triggered. Skip packet. RFIFOSKIP(sd->fd, packet_len); - return 0; + return; } clif_parse_func_table[cmd].func (fd, sd); @@ -10267,7 +10263,7 @@ static int clif_parse (int fd) { printf ("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt); - return 1; + return; } else { @@ -10306,8 +10302,6 @@ static int clif_parse (int fd) } } RFIFOSKIP (fd, packet_len); - - return 0; } /*========================================== @@ -10335,9 +10329,5 @@ int do_init_clif (void) exit (1); } - add_timer_func_list (clif_waitclose, "clif_waitclose"); - add_timer_func_list (clif_clearchar_delay_sub, - "clif_clearchar_delay_sub"); - return 0; } diff --git a/src/map/clif.h b/src/map/clif.h index a7da92d..d947f95 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -177,7 +177,7 @@ int clif_devotion (struct map_session_data *sd, int target); int clif_spiritball (struct map_session_data *sd); int clif_combo_delay (struct block_list *src, int wait); int clif_bladestop (struct block_list *src, struct block_list *dst, - int bool); + int boolean); int clif_changemapcell (int m, int x, int y, int cell_type, int type); int clif_status_change (struct block_list *bl, int type, int flag); diff --git a/src/map/guild.c b/src/map/guild.c index 4a7552a..6017b8e 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -9,7 +9,6 @@ #include "../common/timer.h" #include "../common/socket.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "battle.h" #include "npc.h" #include "pc.h" @@ -72,8 +71,8 @@ int guild_checkskill (struct guild *g, int id) return g->skill[id - 10000].lv; } -int guild_payexp_timer (int tid, unsigned int tick, int id, int data); -int guild_gvg_eliminate_timer (int tid, unsigned int tick, int id, int data); +void guild_payexp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); +void guild_gvg_eliminate_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); static int guild_read_castledb (void) { @@ -94,8 +93,7 @@ static int guild_read_castledb (void) if (line[0] == '/' && line[1] == '/') continue; memset (str, 0, sizeof (str)); - gc = (struct guild_castle *) aCalloc (1, - sizeof (struct guild_castle)); + CREATE (gc, struct guild_castle, 1); for (j = 0, p = line; j < 6 && p; j++) { str[j] = p; @@ -157,9 +155,6 @@ void do_init_guild (void) guild_read_castledb (); - add_timer_func_list (guild_gvg_eliminate_timer, - "guild_gvg_eliminate_timer"); - add_timer_func_list (guild_payexp_timer, "guild_payexp_timer"); add_timer_interval (gettick () + GUILD_PAYEXP_INVERVAL, guild_payexp_timer, 0, 0, GUILD_PAYEXP_INVERVAL); } @@ -170,15 +165,14 @@ struct guild *guild_search (int guild_id) return numdb_search (guild_db, guild_id); } -int guild_searchname_sub (void *key, void *data, va_list ap) +void guild_searchname_sub (db_key_t key, db_val_t data, va_list ap) { struct guild *g = (struct guild *) data, **dst; char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct guild **); - if (strcmpi (g->name, str) == 0) + if (strcasecmp (g->name, str) == 0) *dst = g; - return 0; } // ギルド名検索 @@ -282,22 +276,22 @@ int guild_check_conflict (struct map_session_data *sd) } // ギルドのEXPキャッシュをinter鯖にフラッシュする -int guild_payexp_timer_sub (void *key, void *data, va_list ap) +void guild_payexp_timer_sub (db_key_t key, db_val_t data, va_list ap) { - int i, *dellist, *delp, dataid = (int) key; + int i, *dellist, *delp, dataid = key.i; struct guild_expcache *c; struct guild *g; - nullpo_retr (0, ap); - nullpo_retr (0, c = (struct guild_expcache *) data); - nullpo_retr (0, dellist = va_arg (ap, int *)); - nullpo_retr (0, delp = va_arg (ap, int *)); + nullpo_retv (ap); + nullpo_retv (c = (struct guild_expcache *) data); + nullpo_retv (dellist = va_arg (ap, int *)); + nullpo_retv (delp = va_arg (ap, int *)); if (*delp >= GUILD_PAYEXP_LIST || (g = guild_search (c->guild_id)) == NULL) - return 0; + return; if ((i = guild_getindex (g, c->account_id, 0 /*c->char_id*/)) < 0) - return 0; + return; g->member[i].exp += c->exp; intif_guild_change_memberinfo (g->guild_id, c->account_id, 0 /*char_id*/, @@ -307,10 +301,9 @@ int guild_payexp_timer_sub (void *key, void *data, va_list ap) dellist[(*delp)++] = dataid; free (c); - return 0; } -int guild_payexp_timer (int tid, unsigned int tick, int id, int data) +void guild_payexp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int dellist[GUILD_PAYEXP_LIST], delp = 0, i; numdb_foreach (guild_expcache_db, guild_payexp_timer_sub, dellist, &delp); @@ -318,7 +311,6 @@ int guild_payexp_timer (int tid, unsigned int tick, int id, int data) numdb_erase (guild_expcache_db, dellist[i]); // if(battle_config.etc_log) // printf("guild exp %d charactor's exp flushed !\n",delp); - return 0; } //------------------------------------------------------------------------ @@ -424,7 +416,7 @@ int guild_npc_request_info (int guild_id, const char *event) if (event == NULL || *event == 0) return guild_request_info (guild_id); - ev = (struct eventlist *) aCalloc (1, sizeof (struct eventlist)); + CREATE (ev, struct eventlist, 1); memcpy (ev->name, event, sizeof (ev->name)); ev->next = (struct eventlist *) numdb_search (guild_infoevent_db, guild_id); @@ -494,7 +486,7 @@ int guild_recv_info (struct guild *sg) if ((g = numdb_search (guild_db, sg->guild_id)) == NULL) { - g = (struct guild *) aCalloc (1, sizeof (struct guild)); + CREATE (g, struct guild, 1); numdb_insert (guild_db, sg->guild_id, g); before = *sg; @@ -1094,9 +1086,7 @@ int guild_payexp (struct map_session_data *sd, int exp) if ((c = numdb_search (guild_expcache_db, sd->status.account_id /*char_id*/)) == NULL) { - c = (struct guild_expcache *) aCalloc (1, - sizeof (struct - guild_expcache)); + CREATE (c, struct guild_expcache, 1); c->guild_id = sd->status.guild_id; c->account_id = sd->status.account_id; c->char_id = 0; @@ -1452,14 +1442,14 @@ int guild_allianceack (int guild_id1, int guild_id2, int account_id1, } // ギルド解散通知用 -int guild_broken_sub (void *key, void *data, va_list ap) +void guild_broken_sub (db_key_t key, db_val_t data, va_list ap) { struct guild *g = (struct guild *) data; int guild_id = va_arg (ap, int); int i, j; struct map_session_data *sd = NULL; - nullpo_retr (0, g); + nullpo_retv (g); for (i = 0; i < MAX_GUILDALLIANCE; i++) { // 関係を破棄 @@ -1472,7 +1462,6 @@ int guild_broken_sub (void *key, void *data, va_list ap) g->alliance[i].guild_id = 0; } } - return 0; } // ギルド解散通知 @@ -1548,7 +1537,7 @@ int guild_addcastleinfoevent (int castle_id, int index, const char *name) if (name == NULL || *name == 0) return 0; - ev = (struct eventlist *) aCalloc (1, sizeof (struct eventlist)); + CREATE (ev, struct eventlist, 1); memcpy (ev->name, name, sizeof (ev->name)); ev->next = numdb_search (guild_castleinfoevent_db, code); numdb_insert (guild_castleinfoevent_db, code, ev); @@ -1812,19 +1801,19 @@ int guild_agit_end (void) return 0; } -int guild_gvg_eliminate_timer (int tid, unsigned int tick, int id, int data) +void guild_gvg_eliminate_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { // Run One NPC_Event[OnAgitEliminate] size_t len = strlen ((const char *) data); - char *evname = (char *) aCalloc (len + 4, sizeof (char)); + char *evname; + CREATE (evname, char, len + 4); int c = 0; if (!agit_flag) - return 0; // Agit already End + return; // Agit already End memcpy (evname, (const char *) data, len - 5); strcpy (evname + len - 5, "Eliminate"); c = npc_event_do (evname); printf ("NPC_Event:[%s] Run (%d) Events.\n", evname, c); - return 0; } int guild_agit_break (struct mob_data *md) @@ -1833,7 +1822,7 @@ int guild_agit_break (struct mob_data *md) nullpo_retr (0, md); - evname = (char *) aCalloc (strlen (md->npc_event) + 1, sizeof (char)); + CREATE (evname, char, strlen (md->npc_event) + 1); strcpy (evname, md->npc_event); // Now By User to Run [OnAgitBreak] NPC Event... @@ -1891,40 +1880,32 @@ int guild_isallied (struct guild *g, struct guild_castle *gc) return 0; } -static int guild_db_final (void *key, void *data, va_list ap) +static void guild_db_final (db_key_t key, db_val_t data, va_list ap) { struct guild *g = data; free (g); - - return 0; } -static int castle_db_final (void *key, void *data, va_list ap) +static void castle_db_final (db_key_t key, db_val_t data, va_list ap) { struct guild_castle *gc = data; free (gc); - - return 0; } -static int guild_expcache_db_final (void *key, void *data, va_list ap) +static void guild_expcache_db_final (db_key_t key, db_val_t data, va_list ap) { struct guild_expcache *c = data; free (c); - - return 0; } -static int guild_infoevent_db_final (void *key, void *data, va_list ap) +static void guild_infoevent_db_final (db_key_t key, db_val_t data, va_list ap) { struct eventlist *ev = data; free (ev); - - return 0; } void do_final_guild (void) diff --git a/src/map/itemdb.c b/src/map/itemdb.c index dfa3d36..6557d43 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -6,13 +6,13 @@ #include "../common/db.h" #include "../common/grfio.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "map.h" #include "battle.h" #include "itemdb.h" #include "script.h" #include "pc.h" #include "../common/socket.h" +#include "../common/mt_rand.h" #ifdef MEMWATCH #include "memwatch.h" @@ -49,17 +49,16 @@ void itemdb_reload (void); *------------------------------------------ */ // name = item alias, so we should find items aliases first. if not found then look for "jname" (full name) -int itemdb_searchname_sub (void *key, void *data, va_list ap) +void itemdb_searchname_sub (db_key_t key, db_val_t data, va_list ap) { struct item_data *item = (struct item_data *) data, **dst; char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct item_data **); -// if( strcmpi(item->name,str)==0 || strcmp(item->jname,str)==0 || +// if( strcasecmp(item->name,str)==0 || strcmp(item->jname,str)==0 || // memcmp(item->name,str,24)==0 || memcmp(item->jname,str,24)==0 ) - if (strcmpi (item->name, str) == 0) //by lupus + if (strcasecmp (item->name, str) == 0) //by lupus *dst = item; - return 0; } /*========================================== @@ -72,7 +71,7 @@ int itemdb_searchjname_sub (void *key, void *data, va_list ap) char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct item_data **); - if (strcmpi (item->jname, str) == 0) + if (strcasecmp (item->jname, str) == 0) *dst = item; return 0; } @@ -159,7 +158,7 @@ struct item_data *itemdb_search (int nameid) if (id) return id; - id = (struct item_data *) aCalloc (1, sizeof (struct item_data)); + id = (struct item_data *) calloc (1, sizeof (struct item_data)); numdb_insert (item_db, nameid, id); id->nameid = nameid; @@ -264,10 +263,9 @@ static int itemdb_read_itemslottable (void) char *buf, *p; int s; - buf = grfio_read ("data\\itemslottable.txt"); + buf = grfio_reads ("data\\itemslottable.txt", &s); if (buf == NULL) return -1; - s = grfio_size ("data\\itemslottable.txt"); buf[s] = 0; for (p = buf; p - buf < s;) { @@ -674,28 +672,26 @@ static int itemdb_read_noequip (void) * *------------------------------------------ */ -static int itemdb_final (void *key, void *data, va_list ap) +static void itemdb_final (db_key_t key, db_val_t data, va_list ap) { struct item_data *id; - nullpo_retr (0, id = data); + nullpo_retv (id = data); if (id->use_script) free (id->use_script); if (id->equip_script) free (id->equip_script); free (id); - - return 0; } void itemdb_reload (void) { /* - * + * * * itemdb_read(); - * + * */ do_init_itemdb (); diff --git a/src/map/magic-expr.c b/src/map/magic-expr.c index 18c293d..c3846e2 100644 --- a/src/map/magic-expr.c +++ b/src/map/magic-expr.c @@ -3,6 +3,8 @@ #include "itemdb.h" #include +#include "../common/mt_rand.h" + #define IS_SOLID(c) ((c) == 1 || (c) == 5) int map_is_solid (int m, int x, int y) @@ -180,7 +182,8 @@ static void intify (val_t * v) area_t *area_new (int ty) { - area_t *retval = (area_t *) aCalloc (sizeof (area_t), 1); + area_t *retval; + CREATE (retval, area_t, 1); retval->ty = ty; return retval; } diff --git a/src/map/magic-interpreter-base.c b/src/map/magic-interpreter-base.c index 9d21832..671f962 100644 --- a/src/map/magic-interpreter-base.c +++ b/src/map/magic-interpreter-base.c @@ -143,8 +143,9 @@ teleport_anchor_t *magic_find_anchor (char *name) static env_t *alloc_env (magic_conf_t * conf) { - env_t *env = (env_t *) aCalloc (sizeof (env_t), 1); - env->vars = (val_t *) aCalloc (sizeof (val_t), conf->vars_nr); + env_t *env; + CREATE (env, env_t, 1); + CREATE (env->vars, val_t, conf->vars_nr); env->base_env = conf; return env; } @@ -295,7 +296,7 @@ spellguard_can_satisfy (spellguard_check_t * check, character_t * caster, /* fprintf(stderr, "MC(%d/%s)? %d%d%d%d (%u <= %u)\n", caster->bl.id, caster->status.name, - retval, + retval, caster->cast_tick <= tick, check->mana <= caster->status.sp, check_prerequisites(caster, check->components), @@ -456,8 +457,8 @@ void spell_update_location (invocation_t * invocation) invocation_t *spell_instantiate (effect_set_t * effect_set, env_t * env) { - invocation_t *retval = - (invocation_t *) aCalloc (sizeof (invocation_t), 1); + invocation_t *retval; + CREATE (retval, invocation_t, 1); entity_t *caster; retval->env = env; diff --git a/src/map/magic-interpreter-parser.y b/src/map/magic-interpreter-parser.y index 8484902..c5ee41d 100644 --- a/src/map/magic-interpreter-parser.y +++ b/src/map/magic-interpreter-parser.y @@ -224,13 +224,13 @@ semicolons : /* empty */ proc_formals_list : /* empty */ - { $$ = aCalloc(sizeof(proc_t), 1); } + { CREATE ($$, proc_t, 1); } | proc_formals_list_ne { $$ = $1; } ; proc_formals_list_ne : ID - { $$ = aCalloc(sizeof(proc_t), 1); + { CREATE ($$, proc_t, 1); $$->args_nr = 1; $$->args = malloc(sizeof(int)); $$->args[0] = intern_id($1); @@ -414,7 +414,7 @@ arg_list : /* empty */ arg_list_ne : expr - { $$.args = aCalloc(sizeof(expr_t *), 1); + { CREATE($$.args, expr_t *, 1); $$.args_nr = 1; $$.args[0] = $1; } @@ -452,7 +452,7 @@ area : location spelldef : spellbody_list { $$ = new_spell($1); } | LET defs IN spellbody_list - { $$ = new_spell($4); + { $$ = new_spell($4); $$->letdefs_nr = $2.letdefs_nr; $$->letdefs = $2.letdefs; $$->spellguard = $4; @@ -693,7 +693,7 @@ effect_list : /* empty */ | effect semicolons effect_list { $$ = set_effect_continuation($1, $3); } ; - + %% @@ -743,7 +743,7 @@ add_spell(spell_t *spell, int line_nr) magic_conf.spells = realloc(magic_conf.spells, magic_conf.spells_nr * sizeof (spell_t*)); magic_conf.spells[index] = spell; - + } static void @@ -867,7 +867,7 @@ spellguard_implication(spellguard_t *a, spellguard_t *b) spellguard_implication(a->next, b); else a->next = b; - + return retval; } diff --git a/src/map/magic-interpreter.h b/src/map/magic-interpreter.h index 006c8fb..e9232bd 100644 --- a/src/map/magic-interpreter.h +++ b/src/map/magic-interpreter.h @@ -8,7 +8,6 @@ #include #include -#include "../common/malloc.h" #include "../common/nullpo.h" #include "battle.h" diff --git a/src/map/magic-stmt.c b/src/map/magic-stmt.c index b9833d6..4ae7e5d 100644 --- a/src/map/magic-stmt.c +++ b/src/map/magic-stmt.c @@ -64,8 +64,8 @@ static void clear_activation_record (cont_activation_record_t * ar) } } -static int -invocation_timer_callback (int _, unsigned int __, int id, int data) +static void +invocation_timer_callback (timer_id UNUSED, tick_t UNUSED, custom_id_t id, custom_data_t data) { invocation_t *invocation = (invocation_t *) map_id2bl (id); @@ -74,7 +74,6 @@ invocation_timer_callback (int _, unsigned int __, int id, int data) invocation->timer = 0; spell_execute (invocation); } - return 0; } static void clear_stack (invocation_t * invocation) @@ -224,12 +223,11 @@ static void char_update (character_t * character) character->bl.y); } -static int timer_callback_effect (int _, unsigned int __, int id, int data) +static void timer_callback_effect (timer_id UNUSED, tick_t UNUSED, custom_id_t id, custom_data_t data) { entity_t *target = map_id2bl (id); if (target) clif_misceffect (target, data); - return 0; } static void entity_effect (entity_t * entity, int effect_nr, int delay) @@ -247,14 +245,12 @@ void magic_unshroud (character_t * other_char) // entity_effect(&other_char->bl, MAGIC_EFFECT_REVEAL); } -static int -timer_callback_effect_npc_delete (int timer_id, unsigned int odelay, - int npc_id, int _) +static void +timer_callback_effect_npc_delete (timer_id UNUSED, tick_t odelay, + custom_id_t npc_id, custom_data_t UNUSED) { struct npc_data *effect_npc = (struct npc_data *) map_id2bl (npc_id); npc_free (effect_npc); - - return 0; } static struct npc_data *local_spell_effect (int m, int x, int y, int effect, @@ -370,15 +366,13 @@ static int op_message (env_t * env, int args_nr, val_t * args) return 0; } -static int -timer_callback_kill_npc (int timer_id, unsigned int odelay, int npc_id, - int data) +static void +timer_callback_kill_npc (timer_id UNUSED, tick_t odelay, custom_id_t npc_id, + custom_data_t data) { struct npc_data *npc = (struct npc_data *) map_id2bl (npc_id); if (npc) npc_free (npc); - - return 0; } static int op_messenger_npc (env_t * env, int args_nr, val_t * args) @@ -420,8 +414,8 @@ static void entity_warp (entity_t * target, int destm, int destx, int desty) // Warp part #1: update relevant data, interrupt trading etc.: pc_setpos (character, map_name, character->bl.x, character->bl.y, 0); // Warp part #2: now notify the client - clif_changemap (character, map_name, - character->bl.x, character->bl.y); + clif_changemap (character, map_name, + character->bl.x, character->bl.y); break; } case BL_MOB: @@ -1252,7 +1246,8 @@ static effect_t *run_call (invocation_t * invocation, cont_activation_record_t *ar; int args_nr = current->e.e_call.args_nr; int *formals = current->e.e_call.formals; - val_t *old_actuals = aCalloc (sizeof (val_t), args_nr); + val_t *old_actuals; + CREATE (old_actuals, val_t, args_nr); int i; ar = add_stack_entry (invocation, CONT_STACK_PROC, return_location); diff --git a/src/map/map.c b/src/map/map.c index e1adcef..8261e49 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -13,8 +13,7 @@ #include "../common/timer.h" #include "../common/db.h" #include "../common/grfio.h" -#include "../common/malloc.h" - +#include "../common/mt_rand.h" #include "map.h" #include "chrif.h" #include "clif.h" @@ -785,7 +784,7 @@ void map_foreachobject (int (*func) (struct block_list *, va_list), int type, * map.h内で#defineしてある *------------------------------------------ */ -int map_clearflooritem_timer (int tid, unsigned int tick, int id, int data) +void map_clearflooritem_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct flooritem_data *fitem = NULL; @@ -795,14 +794,12 @@ int map_clearflooritem_timer (int tid, unsigned int tick, int id, int data) { if (battle_config.error_log) printf ("map_clearflooritem_timer : error\n"); - return 1; + return; } if (data) delete_timer (fitem->cleartimer, map_clearflooritem_timer); clif_clearflooritem (fitem, 0); map_delobject (fitem->bl.id, BL_ITEM); - - return 0; } /*========================================== @@ -876,7 +873,7 @@ int map_addflooritem_any (struct item *item_data, int amount, int m, int x, return 0; r = mt_random (); - fitem = (struct flooritem_data *) aCalloc (1, sizeof (*fitem)); + CREATE (fitem, struct flooritem_data, 1); fitem->bl.type = BL_ITEM; fitem->bl.prev = fitem->bl.next = NULL; fitem->bl.m = m; @@ -1030,7 +1027,7 @@ void map_addchariddb (int charid, char *name) p = numdb_search (charid_db, charid); if (p == NULL) { // データベースにない - p = (struct charid2nick *) aCalloc (1, sizeof (struct charid2nick)); + CREATE (p, struct charid2nick, 1); p->req_id = 0; } else @@ -1061,7 +1058,7 @@ int map_reqchariddb (struct map_session_data *sd, int charid) p = numdb_search (charid_db, charid); if (p != NULL) // データベースにすでにある return 0; - p = (struct charid2nick *) aCalloc (1, sizeof (struct charid2nick)); + CREATE (p, struct charid2nick, 1); p->req_id = sd->bl.id; numdb_insert (charid_db, charid, p); return 0; @@ -1302,7 +1299,7 @@ struct map_session_data *map_nick2sd (char *nick) && pl_sd->state.auth) { // Without case sensitive check (increase the number of similar character names found) - if (strnicmp (pl_sd->status.name, nick, nicklen) == 0) + if (strncasecmp (pl_sd->status.name, nick, nicklen) == 0) { // Strict comparison (if found, we finish the function immediatly with correct value) if (strcmp (pl_sd->status.name, nick) == 0) @@ -1341,7 +1338,7 @@ struct block_list *map_id2bl (int id) * id_db内の全てにfuncを実行 *------------------------------------------ */ -int map_foreachiddb (int (*func) (void *, void *, va_list), ...) +int map_foreachiddb (db_func_t func, ...) { va_list ap = NULL; @@ -1573,10 +1570,7 @@ int map_setipport (char *name, unsigned long ip, int port) md = strdb_search (map_db, name); if (md == NULL) { // not exist -> add new data - mdos = - (struct map_data_other_server *) aCalloc (1, - sizeof (struct - map_data_other_server)); + CREATE (mdos, struct map_data_other_server, 1); memcpy (mdos->name, name, 24); mdos->gat = NULL; mdos->ip = ip; @@ -1609,7 +1603,7 @@ int map_setipport (char *name, unsigned long ip, int port) * 水場高さ設定 *------------------------------------------ */ -static struct +static struct Waterlist { char mapname[24]; int waterheight; @@ -1642,7 +1636,9 @@ static void map_readwater (char *watertxt) return; } if (waterlist == NULL) - waterlist = aCalloc (MAX_MAP_PER_SERVER, sizeof (*waterlist)); + { + CREATE (waterlist, struct Waterlist, MAX_MAP_PER_SERVER); + } while (fgets (line, 1020, fp) && n < MAX_MAP_PER_SERVER) { int wh, count; @@ -1777,7 +1773,8 @@ int map_readallmap (void) if (strstr (map[i].name, ".gat") == NULL) continue; sprintf (fn, "data\\%s", map[i].name); - if (grfio_size (fn) == -1) + // TODO - remove this, it is the last call to grfio_size, which is deprecated + if (!grfio_size (fn)) { map_delmap (map[i].name); maps_removed++; @@ -1825,7 +1822,7 @@ int map_readallmap (void) */ int map_addmap (char *mapname) { - if (strcmpi (mapname, "clear") == 0) + if (strcasecmp (mapname, "clear") == 0) { map_num = 0; return 0; @@ -1849,7 +1846,7 @@ int map_delmap (char *mapname) { int i; - if (strcmpi (mapname, "all") == 0) + if (strcasecmp (mapname, "all") == 0) { map_num = 0; return 0; @@ -1959,15 +1956,15 @@ int map_config_read (char *cfgName) continue; if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) == 2) { - if (strcmpi (w1, "userid") == 0) + if (strcasecmp (w1, "userid") == 0) { chrif_setuserid (w2); } - else if (strcmpi (w1, "passwd") == 0) + else if (strcasecmp (w1, "passwd") == 0) { chrif_setpasswd (w2); } - else if (strcmpi (w1, "char_ip") == 0) + else if (strcasecmp (w1, "char_ip") == 0) { h = gethostbyname (w2); if (h != NULL) @@ -1985,11 +1982,11 @@ int map_config_read (char *cfgName) } chrif_setip (w2); } - else if (strcmpi (w1, "char_port") == 0) + else if (strcasecmp (w1, "char_port") == 0) { chrif_setport (atoi (w2)); } - else if (strcmpi (w1, "map_ip") == 0) + else if (strcasecmp (w1, "map_ip") == 0) { h = gethostbyname (w2); if (h != NULL) @@ -2006,70 +2003,58 @@ int map_config_read (char *cfgName) } clif_setip (w2); } - else if (strcmpi (w1, "map_port") == 0) + else if (strcasecmp (w1, "map_port") == 0) { clif_setport (atoi (w2)); map_port = (atoi (w2)); } - else if (strcmpi (w1, "water_height") == 0) + else if (strcasecmp (w1, "water_height") == 0) { map_readwater (w2); } - else if (strcmpi (w1, "map") == 0) + else if (strcasecmp (w1, "map") == 0) { map_addmap (w2); } - else if (strcmpi (w1, "delmap") == 0) + else if (strcasecmp (w1, "delmap") == 0) { map_delmap (w2); } - else if (strcmpi (w1, "npc") == 0) + else if (strcasecmp (w1, "npc") == 0) { npc_addsrcfile (w2); } - else if (strcmpi (w1, "delnpc") == 0) + else if (strcasecmp (w1, "delnpc") == 0) { npc_delsrcfile (w2); } - else if (strcmpi (w1, "data_grf") == 0) - { - grfio_setdatafile (w2); - } - else if (strcmpi (w1, "sdata_grf") == 0) - { - grfio_setsdatafile (w2); - } - else if (strcmpi (w1, "adata_grf") == 0) - { - grfio_setadatafile (w2); - } - else if (strcmpi (w1, "autosave_time") == 0) + else if (strcasecmp (w1, "autosave_time") == 0) { autosave_interval = atoi (w2) * 1000; if (autosave_interval <= 0) autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; } - else if (strcmpi (w1, "motd_txt") == 0) + else if (strcasecmp (w1, "motd_txt") == 0) { strcpy (motd_txt, w2); } - else if (strcmpi (w1, "help_txt") == 0) + else if (strcasecmp (w1, "help_txt") == 0) { strcpy (help_txt, w2); } - else if (strcmpi (w1, "mapreg_txt") == 0) + else if (strcasecmp (w1, "mapreg_txt") == 0) { strcpy (mapreg_txt, w2); } - else if (strcmpi (w1, "gm_log") == 0) + else if (strcasecmp (w1, "gm_log") == 0) { gm_logfile_name = strdup (w2); } - else if (strcmpi (w1, "log_file") == 0) + else if (strcasecmp (w1, "log_file") == 0) { map_set_logfile (w2); } - else if (strcmpi (w1, "import") == 0) + else if (strcasecmp (w1, "import") == 0) { map_config_read (w2); } @@ -2080,26 +2065,6 @@ int map_config_read (char *cfgName) return 0; } -int id_db_final (void *k, void *d, va_list ap) -{ - return 0; -} - -int map_db_final (void *k, void *d, va_list ap) -{ - return 0; -} - -int nick_db_final (void *k, void *d, va_list ap) -{ - return 0; -} - -int charid_db_final (void *k, void *d, va_list ap) -{ - return 0; -} - static int cleanup_sub (struct block_list *bl, va_list ap) { nullpo_retr (0, bl); @@ -2150,10 +2115,10 @@ void do_final (void) map_removenpc (); timer_final (); - numdb_final (id_db, id_db_final); - strdb_final (map_db, map_db_final); - strdb_final (nick_db, nick_db_final); - numdb_final (charid_db, charid_db_final); + numdb_final (id_db, NULL); + strdb_final (map_db, NULL); + strdb_final (nick_db, NULL); + numdb_final (charid_db, NULL); for (i = 0; i <= map_num; i++) { @@ -2190,6 +2155,10 @@ int compare_item (struct item *a, struct item *b) (a->card[2] == b->card[2]) && (a->card[3] == b->card[3])); } +// TODO move shutdown stuff here +void term_func (void) +{ +} /*====================================================== * Map-Server Init and Command-line Arguments [Valaris] *------------------------------------------------------ @@ -2203,7 +2172,6 @@ int do_init (int argc, char *argv[]) unsigned char *ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf"; unsigned char *SCRIPT_CONF_NAME = "conf/script_athena.conf"; unsigned char *MSG_CONF_NAME = "conf/msg_athena.conf"; - unsigned char *GRF_PATH_FILENAME = "conf/grf-files.txt"; for (i = 1; i < argc; i++) { @@ -2221,8 +2189,6 @@ int do_init (int argc, char *argv[]) SCRIPT_CONF_NAME = argv[i + 1]; else if (strcmp (argv[i], "--msg_config") == 0) MSG_CONF_NAME = argv[i + 1]; - else if (strcmp (argv[i], "--grf_path_file") == 0) - GRF_PATH_FILENAME = argv[i + 1]; } map_config_read (MAP_CONF_NAME); @@ -2238,12 +2204,9 @@ int do_init (int argc, char *argv[]) nick_db = strdb_init (24); charid_db = numdb_init (); - grfio_init (GRF_PATH_FILENAME); - map_readallmap (); - add_timer_func_list (map_clearflooritem_timer, - "map_clearflooritem_timer"); +// add_timer_func_list (map_clearflooritem_timer, "map_clearflooritem_timer"); do_init_chrif (); do_init_clif (); diff --git a/src/map/map.h b/src/map/map.h index a558397..5955418 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -8,6 +8,8 @@ #include #include #include "../common/mmo.h" +#include "../common/timer.h" +#include "../common/db.h" #ifndef MAX # define MAX(x,y) (((x)>(y)) ? (x) : (y)) @@ -762,7 +764,7 @@ void map_write_log (char *format, ...); #define MAP_LOG_PC(sd, fmt, args...) MAP_LOG("PC%d %d:%d,%d " fmt, sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## args) // 床アイテム関連 -int map_clearflooritem_timer (int, unsigned int, int, int); +void map_clearflooritem_timer (timer_id, tick_t, custom_id_t, custom_data_t); #define map_clearflooritem(id) map_clearflooritem_timer(0,0,id,1) int map_addflooritem_any (struct item *, int amount, int m, int x, int y, struct map_session_data **owners, @@ -787,7 +789,7 @@ int map_setipport (char *name, unsigned long ip, int port); int map_eraseipport (char *name, unsigned long ip, int port); void map_addiddb (struct block_list *); void map_deliddb (struct block_list *bl); -int map_foreachiddb (int (*)(void *, void *, va_list), ...); +int map_foreachiddb (db_func_t, ...); void map_addnickdb (struct map_session_data *); int map_scriptcont (struct map_session_data *sd, int id); /* Continues a script either on a spell or on an NPC */ struct map_session_data *map_nick2sd (char *); diff --git a/src/map/mob.c b/src/map/mob.c index 99d1cc2..3e3297d 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -9,7 +9,7 @@ #include "../common/socket.h" #include "../common/db.h" #include "../common/nullpo.h" -#include "../common/malloc.h" +#include "../common/mt_rand.h" #include "map.h" #include "clif.h" #include "intif.h" @@ -43,7 +43,7 @@ struct mob_db mob_db[2001]; */ static int distance (int, int, int, int); static int mob_makedummymobdb (int); -static int mob_timer (int, unsigned int, int, int); +static void mob_timer (timer_id, tick_t, custom_id_t, custom_data_t); int mobskill_use (struct mob_data *md, unsigned int tick, int event); int mobskill_deltimer (struct mob_data *md); int mob_skillid2skillidx (int class, int skillid); @@ -61,7 +61,7 @@ int mobdb_searchname (const char *str) for (i = 0; i < sizeof (mob_db) / sizeof (mob_db[0]); i++) { - if (strcmpi (mob_db[i].name, str) == 0 + if (strcasecmp (mob_db[i].name, str) == 0 || strcmp (mob_db[i].jname, str) == 0 || memcmp (mob_db[i].name, str, 24) == 0 || memcmp (mob_db[i].jname, str, 24) == 0) @@ -188,7 +188,7 @@ static void mob_mutate (struct mob_data *md, int stat, int intensity) // inten { int old_stat; int new_stat; - int real_intensity; // relative intensity + int real_intensity; // relative intensity const int mut_base = mutation_base[stat]; int sign = 1; @@ -399,11 +399,10 @@ int mob_once_spawn (struct map_session_data *sd, char *mapname, for (count = 0; count < amount; count++) { - md = (struct mob_data *) aCalloc (1, sizeof (struct mob_data)); - memset (md, '\0', sizeof *md); + md = (struct mob_data *) calloc (1, sizeof (struct mob_data)); if (mob_db[class].mode & 0x02) md->lootitem = - (struct item *) aCalloc (LOOTITEM_SIZE, sizeof (struct item)); + (struct item *) calloc (LOOTITEM_SIZE, sizeof (struct item)); else md->lootitem = NULL; @@ -1035,33 +1034,33 @@ int mob_changestate (struct mob_data *md, int state, int type) * It branches to a walk and an attack. *------------------------------------------ */ -static int mob_timer (int tid, unsigned int tick, int id, int data) +static void mob_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct mob_data *md; struct block_list *bl; if ((bl = map_id2bl (id)) == NULL) { //攻撃してきた敵がもういないのは正常のようだ - return 1; + return; } if (!bl || !bl->type || bl->type != BL_MOB) - return 1; + return; - nullpo_retr (1, md = (struct mob_data *) bl); + nullpo_retv (md = (struct mob_data *) bl); if (!md->bl.type || md->bl.type != BL_MOB) - return 1; + return; if (md->timer != tid) { if (battle_config.error_log == 1) printf ("mob_timer %d != %d\n", md->timer, tid); - return 0; + return; } md->timer = -1; if (md->bl.prev == NULL || md->state.state == MS_DEAD) - return 1; + return; map_freeblock_lock (); switch (md->state.state) @@ -1082,7 +1081,7 @@ static int mob_timer (int tid, unsigned int tick, int id, int data) break; } map_freeblock_unlock (); - return 0; + return; } /*========================================== @@ -1141,10 +1140,9 @@ int mob_walktoxy (struct mob_data *md, int x, int y, int easy) * mob spawn with delay (timer function) *------------------------------------------ */ -static int mob_delayspawn (int tid, unsigned int tick, int m, int n) +static void mob_delayspawn (timer_id tid, tick_t tick, custom_id_t m, custom_data_t n) { mob_spawn (m); - return 0; } /*========================================== @@ -2311,44 +2309,42 @@ static int mob_ai_sub_foreachclient (struct map_session_data *sd, va_list ap) * Serious processing for mob in PC field of view (interval timer function) *------------------------------------------ */ -static int mob_ai_hard (int tid, unsigned int tick, int id, int data) +static void mob_ai_hard (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { clif_foreachclient (mob_ai_sub_foreachclient, tick); - - return 0; } /*========================================== * Negligent mode MOB AI (PC is not in near) *------------------------------------------ */ -static int mob_ai_sub_lazy (void *key, void *data, va_list app) +static void mob_ai_sub_lazy (db_key_t key, db_val_t data, va_list app) { struct mob_data *md = data; unsigned int tick; va_list ap; - nullpo_retr (0, md); - nullpo_retr (0, app); - nullpo_retr (0, ap = va_arg (app, va_list)); + nullpo_retv (md); + nullpo_retv (app); + nullpo_retv (ap = va_arg (app, va_list)); if (md == NULL) - return 0; + return; if (!md->bl.type || md->bl.type != BL_MOB) - return 0; + return; tick = va_arg (ap, unsigned int); if (DIFF_TICK (tick, md->last_thinktime) < MIN_MOBTHINKTIME * 10) - return 0; + return; md->last_thinktime = tick; if (md->bl.prev == NULL || md->skilltimer != -1) { if (DIFF_TICK (tick, md->next_walktime) > MIN_MOBTHINKTIME * 10) md->next_walktime = tick; - return 0; + return; } if (DIFF_TICK (md->next_walktime, tick) < 0 && @@ -2383,18 +2379,15 @@ static int mob_ai_sub_lazy (void *key, void *data, va_list app) md->next_walktime = tick + MPRAND (5000, 10000); } - return 0; } /*========================================== * Negligent processing for mob outside PC field of view (interval timer function) *------------------------------------------ */ -static int mob_ai_lazy (int tid, unsigned int tick, int id, int data) +static void mob_ai_lazy (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { map_foreachiddb (mob_ai_sub_lazy, tick); - - return 0; } /*========================================== @@ -2421,13 +2414,13 @@ struct delay_item_drop2 * item drop with delay (timer function) *------------------------------------------ */ -static int mob_delay_item_drop (int tid, unsigned int tick, int id, int data) +static void mob_delay_item_drop (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct delay_item_drop *ditem; struct item temp_item; int flag; - nullpo_retr (0, ditem = (struct delay_item_drop *) id); + nullpo_retv (ditem = (struct delay_item_drop *) id); memset (&temp_item, 0, sizeof (temp_item)); temp_item.nameid = ditem->nameid; @@ -2446,26 +2439,25 @@ static int mob_delay_item_drop (int tid, unsigned int tick, int id, int data) ditem->third_sd, 0); } free (ditem); - return 0; + return; } map_addflooritem (&temp_item, 1, ditem->m, ditem->x, ditem->y, ditem->first_sd, ditem->second_sd, ditem->third_sd, 0); free (ditem); - return 0; } /*========================================== * item drop (timer function)-lootitem with delay *------------------------------------------ */ -static int mob_delay_item_drop2 (int tid, unsigned int tick, int id, int data) +static void mob_delay_item_drop2 (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct delay_item_drop2 *ditem; int flag; - nullpo_retr (0, ditem = (struct delay_item_drop2 *) id); + nullpo_retv (ditem = (struct delay_item_drop2 *) id); if (battle_config.item_auto_get == 1) { @@ -2480,7 +2472,7 @@ static int mob_delay_item_drop2 (int tid, unsigned int tick, int id, int data) ditem->second_sd, ditem->third_sd, 0); } free (ditem); - return 0; + return; } map_addflooritem (&ditem->item_data, ditem->item_data.amount, ditem->m, @@ -2488,7 +2480,6 @@ static int mob_delay_item_drop2 (int tid, unsigned int tick, int id, int data) ditem->third_sd, 0); free (ditem); - return 0; } /*========================================== @@ -2524,16 +2515,15 @@ int mob_catch_delete (struct mob_data *md, int type) return 0; } -int mob_timer_delete (int tid, unsigned int tick, int id, int data) +void mob_timer_delete (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct block_list *bl = map_id2bl (id); struct mob_data *md; - nullpo_retr (0, bl); + nullpo_retv (bl); md = (struct mob_data *) bl; mob_catch_delete (md, 3); - return 0; } /*========================================== @@ -3009,10 +2999,8 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage, if (drop_rate <= MRAND (10000)) continue; - ditem = - (struct delay_item_drop *) aCalloc (1, - sizeof (struct - delay_item_drop)); + ditem = (struct delay_item_drop *) + calloc (1, sizeof (struct delay_item_drop)); ditem->nameid = mob_db[md->class].dropitem[i].nameid; ditem->amount = 1; ditem->m = md->bl.m; @@ -3021,8 +3009,7 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage, ditem->first_sd = mvp_sd; ditem->second_sd = second_sd; ditem->third_sd = third_sd; - add_timer (tick + 500 + i, mob_delay_item_drop, (int) ditem, - 0); + add_timer (tick + 500 + i, mob_delay_item_drop, (int) ditem, 0); } if (sd && sd->state.attack_type == BF_WEAPON) { @@ -3041,10 +3028,8 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage, if (sd->monster_drop_itemrate[i] <= MRAND (10000)) continue; - ditem = - (struct delay_item_drop *) aCalloc (1, - sizeof (struct - delay_item_drop)); + ditem = (struct delay_item_drop *) + calloc (1, sizeof (struct delay_item_drop)); ditem->nameid = sd->monster_drop_itemid[i]; ditem->amount = 1; ditem->m = md->bl.m; @@ -3068,10 +3053,8 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage, { struct delay_item_drop2 *ditem; - ditem = - (struct delay_item_drop2 *) aCalloc (1, - sizeof (struct - delay_item_drop2)); + ditem = (struct delay_item_drop2 *) + calloc (1, sizeof (struct delay_item_drop2)); memcpy (&ditem->item_data, &md->lootitem[i], sizeof (md->lootitem[0])); ditem->m = md->bl.m; @@ -3252,8 +3235,8 @@ int mob_class_change (struct mob_data *md, int *value) md->skilllv = 0; if (md->lootitem == NULL && mob_db[class].mode & 0x02) - md->lootitem = - (struct item *) aCalloc (LOOTITEM_SIZE, sizeof (struct item)); + md->lootitem = (struct item *) + calloc (LOOTITEM_SIZE, sizeof (struct item)); skill_clear_unitgroup (&md->bl); skill_cleartimerskill (&md->bl); @@ -3487,11 +3470,10 @@ int mob_summonslave (struct mob_data *md2, int *value, int amount, int flag) for (; amount > 0; amount--) { int x = 0, y = 0, c = 0, i = 0; - md = (struct mob_data *) aCalloc (1, sizeof (struct mob_data)); + md = (struct mob_data *) calloc (1, sizeof (struct mob_data)); if (mob_db[class].mode & 0x02) - md->lootitem = - (struct item *) aCalloc (LOOTITEM_SIZE, - sizeof (struct item)); + md->lootitem = (struct item *) + calloc (LOOTITEM_SIZE, sizeof (struct item)); else md->lootitem = NULL; @@ -3620,7 +3602,7 @@ int mob_skillid2skillidx (int class, int skillid) * スキル使用(詠唱完了、ID指定) *------------------------------------------ */ -int mobskill_castend_id (int tid, unsigned int tick, int id, int data) +void mobskill_castend_id (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct mob_data *md = NULL; struct block_list *bl; @@ -3628,16 +3610,16 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) int range; if ((mbl = map_id2bl (id)) == NULL) //詠唱したMobがもういないというのは良くある正常処理 - return 0; + return; if ((md = (struct mob_data *) mbl) == NULL) { printf ("mobskill_castend_id nullpo mbl->id:%d\n", mbl->id); - return 0; + return; } if (md->bl.type != BL_MOB || md->bl.prev == NULL) - return 0; + return; if (md->skilltimer != tid) // タイマIDの確認 - return 0; + return; md->skilltimer = -1; //沈黙や状態異常など @@ -3646,13 +3628,13 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) if (md->opt1 > 0 || md->sc_data[SC_DIVINA].timer != -1 || md->sc_data[SC_ROKISWEIL].timer != -1 || md->sc_data[SC_STEELBODY].timer != -1) - return 0; + return; if (md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //オートカウンター - return 0; + return; if (md->sc_data[SC_BLADESTOP].timer != -1) //白刃取り - return 0; + return; if (md->sc_data[SC_BERSERK].timer != -1) //バーサーク - return 0; + return; } if (md->skillid != NPC_EMOTION) md->last_thinktime = tick + battle_get_adelay (&md->bl); @@ -3660,10 +3642,10 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) if ((bl = map_id2bl (md->skilltarget)) == NULL || bl->prev == NULL) { //スキルターゲットが存在しない //printf("mobskill_castend_id nullpo\n");//ターゲットがいないときはnullpoじゃなくて普通に終了 - return 0; + return; } if (md->bl.m != bl->m) - return 0; + return; if (md->skillid == PR_LEXAETERNA) { @@ -3672,7 +3654,7 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) && (sc_data[SC_FREEZE].timer != -1 || (sc_data[SC_STONE].timer != -1 && sc_data[SC_STONE].val2 == 0))) - return 0; + return; } else if (md->skillid == RG_BACKSTAP) { @@ -3680,17 +3662,17 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) battle_get_dir (bl); int dist = distance (md->bl.x, md->bl.y, bl->x, bl->y); if (bl->type != BL_SKILL && (dist == 0 || map_check_dir (dir, t_dir))) - return 0; + return; } if (((skill_get_inf (md->skillid) & 1) || (skill_get_inf2 (md->skillid) & 4)) && // 彼我敵対関係チェック battle_check_target (&md->bl, bl, BCT_ENEMY) <= 0) - return 0; + return; range = skill_get_range (md->skillid, md->skilllv); if (range < 0) range = battle_get_range (&md->bl) - (range + 1); if (range + battle_config.mob_skill_add_range < distance (md->bl.x, md->bl.y, bl->x, bl->y)) - return 0; + return; md->skilldelay[md->skillidx] = tick; @@ -3720,15 +3702,13 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) md->skilllv, tick, 0); break; } - - return 0; } /*========================================== * スキル使用(詠唱完了、場所指定) *------------------------------------------ */ -int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) +void mobskill_castend_pos (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct mob_data *md = NULL; struct block_list *bl; @@ -3736,15 +3716,15 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) //mobskill_castend_id同様詠唱したMobが詠唱完了時にもういないというのはありそうなのでnullpoから除外 if ((bl = map_id2bl (id)) == NULL) - return 0; + return; - nullpo_retr (0, md = (struct mob_data *) bl); + nullpo_retv (md = (struct mob_data *) bl); if (md->bl.type != BL_MOB || md->bl.prev == NULL) - return 0; + return; if (md->skilltimer != tid) // タイマIDの確認 - return 0; + return; md->skilltimer = -1; if (md->sc_data) @@ -3752,13 +3732,13 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) if (md->opt1 > 0 || md->sc_data[SC_DIVINA].timer != -1 || md->sc_data[SC_ROKISWEIL].timer != -1 || md->sc_data[SC_STEELBODY].timer != -1) - return 0; + return; if (md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //オートカウンター - return 0; + return; if (md->sc_data[SC_BLADESTOP].timer != -1) //白刃取り - return 0; + return; if (md->sc_data[SC_BERSERK].timer != -1) //バーサーク - return 0; + return; } if (battle_config.monster_skill_reiteration == 0) @@ -3789,7 +3769,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) { if (skill_check_unit_range (md->bl.m, md->skillx, md->skilly, range, md->skillid) > 0) - return 0; + return; } } if (battle_config.monster_skill_nofootset == 1) @@ -3819,7 +3799,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) { if (skill_check_unit_range2 (md->bl.m, md->skillx, md->skilly, range) > 0) - return 0; + return; } } @@ -3836,7 +3816,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) c++; } if (c >= maxcount) - return 0; + return; } } @@ -3845,7 +3825,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) range = battle_get_range (&md->bl) - (range + 1); if (range + battle_config.mob_skill_add_range < distance (md->bl.x, md->bl.y, md->skillx, md->skilly)) - return 0; + return; md->skilldelay[md->skillidx] = tick; if (battle_config.mob_skill_log == 1) @@ -3856,7 +3836,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) skill_castend_pos2 (&md->bl, md->skillx, md->skilly, md->skillid, md->skilllv, tick, 0); - return 0; + return; } /*========================================== @@ -4292,7 +4272,7 @@ int mobskill_use (struct mob_data *md, unsigned int tick, int event) if (ms[i].target == MST_MASTER) { bl = &md->bl; - if (md->master_id) + if (md->master_id) bl = map_id2bl (md->master_id); } else @@ -5048,10 +5028,10 @@ static int mob_readskilldb (void) void mob_reload (void) { /* - * + * * * mob_read(); - * + * */ do_init_mob (); @@ -5069,15 +5049,6 @@ int do_init_mob (void) mob_read_randommonster (); mob_readskilldb (); - add_timer_func_list (mob_timer, "mob_timer"); - add_timer_func_list (mob_delayspawn, "mob_delayspawn"); - add_timer_func_list (mob_delay_item_drop, "mob_delay_item_drop"); - add_timer_func_list (mob_delay_item_drop2, "mob_delay_item_drop2"); - add_timer_func_list (mob_ai_hard, "mob_ai_hard"); - add_timer_func_list (mob_ai_lazy, "mob_ai_lazy"); - add_timer_func_list (mobskill_castend_id, "mobskill_castend_id"); - add_timer_func_list (mobskill_castend_pos, "mobskill_castend_pos"); - add_timer_func_list (mob_timer_delete, "mob_timer_delete"); add_timer_interval (gettick () + MIN_MOBTHINKTIME, mob_ai_hard, 0, 0, MIN_MOBTHINKTIME); add_timer_interval (gettick () + MIN_MOBTHINKTIME * 10, mob_ai_lazy, 0, 0, diff --git a/src/map/mob.h b/src/map/mob.h index 2463283..aff305b 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -1,7 +1,7 @@ // $Id: mob.h,v 1.4 2004/09/25 05:32:18 MouseJstr Exp $ #ifndef _MOB_H_ #define _MOB_H_ - +#include "../common/timer.h" #define MAX_RANDOMMONSTER 3 struct mob_skill @@ -129,7 +129,7 @@ int do_init_mob (void); int mob_delete (struct mob_data *md); int mob_catch_delete (struct mob_data *md, int type); -int mob_timer_delete (int tid, unsigned int tick, int id, int data); +void mob_timer_delete (timer_id, tick_t, custom_id_t, custom_data_t); int mob_deleteslave (struct mob_data *md); @@ -141,8 +141,8 @@ int mob_warp (struct mob_data *md, int m, int x, int y, int type); int mobskill_use (struct mob_data *md, unsigned int tick, int event); int mobskill_event (struct mob_data *md, int flag); -int mobskill_castend_id (int tid, unsigned int tick, int id, int data); -int mobskill_castend_pos (int tid, unsigned int tick, int id, int data); +void mobskill_castend_id (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); +void mobskill_castend_pos (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); int mob_summonslave (struct mob_data *md2, int *value, int amount, int flag); int mob_gvmobcheck (struct map_session_data *sd, struct block_list *bl); diff --git a/src/map/npc.c b/src/map/npc.c index 5fd8291..54b13d8 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -6,7 +6,6 @@ #include #include -#include "../common/malloc.h" #include "../common/nullpo.h" #include "../common/timer.h" @@ -63,7 +62,7 @@ int npc_enable_sub (struct block_list *bl, va_list ap) { struct map_session_data *sd; struct npc_data *nd; - char *name = (char *) aCalloc (50, sizeof (char)); + char *name = (char *) calloc (50, sizeof (char)); nullpo_retr (0, bl); nullpo_retr (0, ap); @@ -173,15 +172,14 @@ int npc_delete (struct npc_data *nd) * イベントの遅延実行 *------------------------------------------ */ -int npc_event_timer (int tid, unsigned int tick, int id, int data) +void npc_event_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = map_id2sd (id); if (sd == NULL) - return 0; + return; npc_event (sd, (const char *) data, 0); free ((void *) data); - return 0; } int npc_timer_event (const char *eventname) // Added by RoVeRT @@ -294,18 +292,18 @@ int npc_event_export (void *key, void *data, va_list ap) * 全てのNPCのOn*イベント実行 *------------------------------------------ */ -int npc_event_doall_sub (void *key, void *data, va_list ap) +void npc_event_doall_sub (db_key_t key, db_val_t data, va_list ap) { - char *p = (char *) key; + const char *p = key.s; int rid, argc; argrec_t *argv; struct event_data *ev; int *c; const char *name; - nullpo_retr (0, ev = (struct event_data *) data); - nullpo_retr (0, ap); - nullpo_retr (0, c = va_arg (ap, int *)); + nullpo_retv (ev = (struct event_data *) data); + nullpo_retv (ap); + nullpo_retv (c = va_arg (ap, int *)); name = va_arg (ap, const char *); rid = va_arg (ap, int); @@ -318,8 +316,6 @@ int npc_event_doall_sub (void *key, void *data, va_list ap) argv); (*c)++; } - - return 0; } int npc_event_doall_l (const char *name, int rid, int argc, argrec_t * args) @@ -333,18 +329,18 @@ int npc_event_doall_l (const char *name, int rid, int argc, argrec_t * args) return c; } -int npc_event_do_sub (void *key, void *data, va_list ap) +void npc_event_do_sub (db_key_t key, db_val_t data, va_list ap) { - char *p = (char *) key; + const char *p = key.s; struct event_data *ev; int *c; const char *name; int rid, argc; argrec_t *argv; - nullpo_retr (0, ev = (struct event_data *) data); - nullpo_retr (0, ap); - nullpo_retr (0, c = va_arg (ap, int *)); + nullpo_retv (ev = (struct event_data *) data); + nullpo_retv (ap); + nullpo_retv (c = va_arg (ap, int *)); name = va_arg (ap, const char *); rid = va_arg (ap, int); @@ -357,8 +353,6 @@ int npc_event_do_sub (void *key, void *data, va_list ap) argv); (*c)++; } - - return 0; } int npc_event_do_l (const char *name, int rid, int argc, argrec_t * args) @@ -378,7 +372,7 @@ int npc_event_do_l (const char *name, int rid, int argc, argrec_t * args) * 時計イベント実行 *------------------------------------------ */ -int npc_event_do_clock (int tid, unsigned int tick, int id, int data) +void npc_event_do_clock (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { time_t timer; struct tm *t; @@ -406,7 +400,6 @@ int npc_event_do_clock (int tid, unsigned int tick, int id, int data) c += npc_event_doall (buf); } memcpy (&ev_tm_b, t, sizeof (ev_tm_b)); - return c; } /*========================================== @@ -482,9 +475,9 @@ int npc_cleareventtimer (struct npc_data *nd) return 0; } -int npc_do_ontimer_sub (void *key, void *data, va_list ap) +void npc_do_ontimer_sub (db_key_t key, db_val_t data, va_list ap) { - char *p = (char *) key; + const char *p = key.s; struct event_data *ev = (struct event_data *) data; int *c = va_arg (ap, int *); // struct map_session_data *sd=va_arg(ap,struct map_session_data *); @@ -511,7 +504,6 @@ int npc_do_ontimer_sub (void *key, void *data, va_list ap) npc_deleventtimer (ev->nd, event); } } - return 0; } int npc_do_ontimer (int npc_id, struct map_session_data *sd, int option) @@ -567,7 +559,7 @@ int npc_timerevent_import (void *key, void *data, va_list ap) * タイマーイベント実行 *------------------------------------------ */ -int npc_timerevent (int tid, unsigned int tick, int id, int data) +void npc_timerevent (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int next, t; struct npc_data *nd = (struct npc_data *) map_id2bl (id); @@ -575,7 +567,7 @@ int npc_timerevent (int tid, unsigned int tick, int id, int data) if (nd == NULL || nd->u.scr.nexttimer < 0) { printf ("npc_timerevent: ??\n"); - return 0; + return; } nd->u.scr.timertick = tick; te = nd->u.scr.timer_event + nd->u.scr.nexttimer; @@ -590,7 +582,6 @@ int npc_timerevent (int tid, unsigned int tick, int id, int data) } run_script (nd->u.scr.script, te->pos, 0, nd->bl.id); - return 0; } /*========================================== @@ -770,9 +761,9 @@ int npc_event (struct map_session_data *sd, const char *eventname, return 0; } -int npc_command_sub (void *key, void *data, va_list ap) +void npc_command_sub (db_key_t key, db_val_t data, va_list ap) { - char *p = (char *) key; + const char *p = key.s; struct event_data *ev = (struct event_data *) data; char *npcname = va_arg (ap, char *); char *command = va_arg (ap, char *); @@ -786,8 +777,6 @@ int npc_command_sub (void *key, void *data, va_list ap) if (strcmp (command, temp) == 0) run_script (ev->nd->u.scr.script, ev->pos, 0, ev->nd->bl.id); } - - return 0; } int npc_command (struct map_session_data *sd, char *npcname, char *command) @@ -858,7 +847,7 @@ int npc_touch_areanpc (struct map_session_data *sd, int m, int x, int y) case MESSAGE: case SCRIPT: { - char *name = (char *) aCalloc (50, sizeof (char)); + char *name = calloc (50, 1); memcpy (name, map[m].npc[i]->name, 50); if (sd->areanpc_id == map[m].npc[i]->bl.id) @@ -1235,14 +1224,14 @@ void npc_addsrcfile (char *name) struct npc_src_list *new; size_t len; - if (strcmpi (name, "clear") == 0) + if (strcasecmp (name, "clear") == 0) { npc_clearsrcfile (); return; } len = sizeof (*new) + strlen (name); - new = (struct npc_src_list *) aCalloc (1, len); + new = (struct npc_src_list *) calloc (1, len); new->next = NULL; strncpy (new->name, name, strlen (name) + 1); if (npc_src_first == NULL) @@ -1261,7 +1250,7 @@ void npc_delsrcfile (char *name) { struct npc_src_list *p = npc_src_first, *pp = NULL, **lp = &npc_src_first; - if (strcmpi (name, "all") == 0) + if (strcasecmp (name, "all") == 0) { npc_clearsrcfile (); return; @@ -1302,7 +1291,7 @@ int npc_parse_warp (char *w1, char *w2, char *w3, char *w4) m = map_mapname2mapid (mapname); - nd = (struct npc_data *) aCalloc (1, sizeof (struct npc_data)); + nd = (struct npc_data *) calloc (1, sizeof (struct npc_data)); nd->bl.id = npc_get_new_npc_id (); nd->n = map_addnpc (m, nd); @@ -1377,7 +1366,7 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4) } m = map_mapname2mapid (mapname); - nd = (struct npc_data *) aCalloc (1, sizeof (struct npc_data) + + nd = (struct npc_data *) calloc (1, sizeof (struct npc_data) + sizeof (nd->u.shop_item[0]) * (max + 1)); p = strchr (w4, ','); @@ -1440,9 +1429,8 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4) nd->opt2 = 0; nd->opt3 = 0; - nd = (struct npc_data *) aRealloc (nd, - sizeof (struct npc_data) + - sizeof (nd->u.shop_item[0]) * pos); + nd = (struct npc_data *) + realloc (nd, sizeof (struct npc_data) + sizeof (nd->u.shop_item[0]) * pos); //printf("shop npc %s %d read done\n",mapname,nd->bl.id); npc_shop++; @@ -1460,33 +1448,29 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4) * NPCのラベルデータコンバート *------------------------------------------ */ -int npc_convertlabel_db (void *key, void *data, va_list ap) +void npc_convertlabel_db (db_key_t key, db_val_t data, va_list ap) { - char *lname = (char *) key; + const char *lname = key.s; int pos = (int) data; struct npc_data *nd; struct npc_label_list *lst; int num; char *p = strchr (lname, ':'); - nullpo_retr (0, ap); - nullpo_retr (0, nd = va_arg (ap, struct npc_data *)); + nullpo_retv (ap); + nullpo_retv (nd = va_arg (ap, struct npc_data *)); lst = nd->u.scr.label_list; num = nd->u.scr.label_list_num; if (!lst) { - lst = - (struct npc_label_list *) aCalloc (1, - sizeof (struct - npc_label_list)); + lst = (struct npc_label_list *) + calloc (1, sizeof (struct npc_label_list)); num = 0; } else - lst = - (struct npc_label_list *) aRealloc (lst, - sizeof (struct npc_label_list) - * (num + 1)); + lst = (struct npc_label_list *) + realloc (lst, sizeof (struct npc_label_list) * (num + 1)); *p = '\0'; strncpy (lst[num].name, lname, sizeof(lst[num].name)-1); @@ -1495,7 +1479,6 @@ int npc_convertlabel_db (void *key, void *data, va_list ap) lst[num].pos = pos; nd->u.scr.label_list = lst; nd->u.scr.label_list_num = num + 1; - return 0; } /*========================================== @@ -1541,7 +1524,7 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, if (strcmp (w2, "script") == 0) { // スクリプトの解析 - srcbuf = (char *) aCalloc (srcsize, sizeof (char)); + srcbuf = (char *) calloc (srcsize, sizeof (char)); if (strchr (first_line, '{')) { strcpy (srcbuf, strchr (first_line, '{')); @@ -1562,7 +1545,7 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, if (strlen (srcbuf) + strlen (line) + 1 >= srcsize) { srcsize += 65536; - srcbuf = (char *) aRealloc (srcbuf, srcsize); + srcbuf = (char *) realloc (srcbuf, srcsize); memset (srcbuf + srcsize - 65536, '\0', 65536); } if (srcbuf[0] != '{') @@ -1608,7 +1591,7 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, } // end of スクリプト解析 - nd = (struct npc_data *) aCalloc (1, sizeof (struct npc_data)); + nd = (struct npc_data *) calloc (1, sizeof (struct npc_data)); if (m == -1) { @@ -1702,7 +1685,7 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, if (evflag) { // イベント型 struct event_data *ev = - (struct event_data *) aCalloc (1, sizeof (struct event_data)); + (struct event_data *) calloc (1, sizeof (struct event_data)); ev->nd = nd; ev->pos = 0; strdb_insert (ev_db, nd->exname, ev); @@ -1750,9 +1733,9 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, struct event_data *ev; char *buf; // エクスポートされる - ev = (struct event_data *) aCalloc (1, + ev = (struct event_data *) calloc (1, sizeof (struct event_data)); - buf = (char *) aCalloc (50, sizeof (char)); + buf = (char *) calloc (50, sizeof (char)); if (strlen (lname) > 24) { printf ("npc_parse_script: label name error !\n"); @@ -1781,11 +1764,11 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, struct npc_timerevent_list *te = nd->u.scr.timer_event; int j, k = nd->u.scr.timeramount; if (te == NULL) - te = (struct npc_timerevent_list *) aCalloc (1, + te = (struct npc_timerevent_list *) calloc (1, sizeof (struct npc_timerevent_list)); else - te = (struct npc_timerevent_list *) aRealloc (te, + te = (struct npc_timerevent_list *) realloc (te, sizeof (struct npc_timerevent_list) * (k + 1)); @@ -1826,7 +1809,7 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4, char *p; // スクリプトの解析 - srcbuf = (char *) aCalloc (srcsize, sizeof (char)); + srcbuf = (char *) calloc (srcsize, sizeof (char)); if (strchr (first_line, '{')) { strcpy (srcbuf, strchr (first_line, '{')); @@ -1847,7 +1830,7 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4, if (strlen (srcbuf) + strlen (line) + 1 >= srcsize) { srcsize += 65536; - srcbuf = (char *) aRealloc (srcbuf, srcsize); + srcbuf = (char *) realloc (srcbuf, srcsize); memset (srcbuf + srcsize - 65536, '\0', 65536); } if (srcbuf[0] != '{') @@ -1869,7 +1852,7 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4, return 1; } - p = (char *) aCalloc (50, sizeof (char)); + p = (char *) calloc (50, sizeof (char)); strncpy (p, w3, 49); strdb_insert (script_get_userfunc_db (), p, script); @@ -1917,7 +1900,7 @@ int npc_parse_mob (char *w1, char *w2, char *w3, char *w4) for (i = 0; i < num; i++) { - md = (struct mob_data *) aCalloc (1, sizeof (struct mob_data)); + md = (struct mob_data *) calloc (1, sizeof (struct mob_data)); md->bl.prev = NULL; md->bl.next = NULL; @@ -1949,7 +1932,7 @@ int npc_parse_mob (char *w1, char *w2, char *w3, char *w4) if (mob_db[class].mode & 0x02) md->lootitem = - (struct item *) aCalloc (LOOTITEM_SIZE, sizeof (struct item)); + (struct item *) calloc (LOOTITEM_SIZE, sizeof (struct item)); else md->lootitem = NULL; @@ -1993,7 +1976,7 @@ static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4) return 1; //マップフラグ - if (strcmpi (w3, "nosave") == 0) + if (strcasecmp (w3, "nosave") == 0) { if (strcmp (w4, "SavePoint") == 0) { @@ -2009,51 +1992,51 @@ static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4) } map[m].flag.nosave = 1; } - else if (strcmpi (w3, "nomemo") == 0) + else if (strcasecmp (w3, "nomemo") == 0) { map[m].flag.nomemo = 1; } - else if (strcmpi (w3, "noteleport") == 0) + else if (strcasecmp (w3, "noteleport") == 0) { map[m].flag.noteleport = 1; } - else if (strcmpi (w3, "nowarp") == 0) + else if (strcasecmp (w3, "nowarp") == 0) { map[m].flag.nowarp = 1; } - else if (strcmpi (w3, "nowarpto") == 0) + else if (strcasecmp (w3, "nowarpto") == 0) { map[m].flag.nowarpto = 1; } - else if (strcmpi (w3, "noreturn") == 0) + else if (strcasecmp (w3, "noreturn") == 0) { map[m].flag.noreturn = 1; } - else if (strcmpi (w3, "monster_noteleport") == 0) + else if (strcasecmp (w3, "monster_noteleport") == 0) { map[m].flag.monster_noteleport = 1; } - else if (strcmpi (w3, "nobranch") == 0) + else if (strcasecmp (w3, "nobranch") == 0) { map[m].flag.nobranch = 1; } - else if (strcmpi (w3, "nopenalty") == 0) + else if (strcasecmp (w3, "nopenalty") == 0) { map[m].flag.nopenalty = 1; } - else if (strcmpi (w3, "pvp") == 0) + else if (strcasecmp (w3, "pvp") == 0) { map[m].flag.pvp = 1; } - else if (strcmpi (w3, "pvp_noparty") == 0) + else if (strcasecmp (w3, "pvp_noparty") == 0) { map[m].flag.pvp_noparty = 1; } - else if (strcmpi (w3, "pvp_noguild") == 0) + else if (strcasecmp (w3, "pvp_noguild") == 0) { map[m].flag.pvp_noguild = 1; } - else if (strcmpi (w3, "pvp_nightmaredrop") == 0) + else if (strcasecmp (w3, "pvp_nightmaredrop") == 0) { if (sscanf (w4, "%[^,],%[^,],%d", drop_arg1, drop_arg2, &drop_per) == 3) @@ -2086,64 +2069,64 @@ static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4) } } } - else if (strcmpi (w3, "pvp_nocalcrank") == 0) + else if (strcasecmp (w3, "pvp_nocalcrank") == 0) { map[m].flag.pvp_nocalcrank = 1; } - else if (strcmpi (w3, "gvg") == 0) + else if (strcasecmp (w3, "gvg") == 0) { map[m].flag.gvg = 1; } - else if (strcmpi (w3, "gvg_noparty") == 0) + else if (strcasecmp (w3, "gvg_noparty") == 0) { map[m].flag.gvg_noparty = 1; } - else if (strcmpi (w3, "nozenypenalty") == 0) + else if (strcasecmp (w3, "nozenypenalty") == 0) { map[m].flag.nozenypenalty = 1; } - else if (strcmpi (w3, "notrade") == 0) + else if (strcasecmp (w3, "notrade") == 0) { map[m].flag.notrade = 1; } - else if (strcmpi (w3, "noskill") == 0) + else if (strcasecmp (w3, "noskill") == 0) { map[m].flag.noskill = 1; } - else if (battle_config.pk_mode && strcmpi (w3, "nopvp") == 0) + else if (battle_config.pk_mode && strcasecmp (w3, "nopvp") == 0) { // nopvp for pk mode [Valaris] map[m].flag.nopvp = 1; map[m].flag.pvp = 0; } - else if (strcmpi (w3, "noicewall") == 0) + else if (strcasecmp (w3, "noicewall") == 0) { // noicewall [Valaris] map[m].flag.noicewall = 1; } - else if (strcmpi (w3, "snow") == 0) + else if (strcasecmp (w3, "snow") == 0) { // snow [Valaris] map[m].flag.snow = 1; } - else if (strcmpi (w3, "fog") == 0) + else if (strcasecmp (w3, "fog") == 0) { // fog [Valaris] map[m].flag.fog = 1; } - else if (strcmpi (w3, "sakura") == 0) + else if (strcasecmp (w3, "sakura") == 0) { // sakura [Valaris] map[m].flag.sakura = 1; } - else if (strcmpi (w3, "leaves") == 0) + else if (strcasecmp (w3, "leaves") == 0) { // leaves [Valaris] map[m].flag.leaves = 1; } - else if (strcmpi (w3, "rain") == 0) + else if (strcasecmp (w3, "rain") == 0) { // rain [Valaris] map[m].flag.rain = 1; } - else if (strcmpi (w3, "no_player_drops") == 0) + else if (strcasecmp (w3, "no_player_drops") == 0) { // no player drops [Jaxad0127] map[m].flag.no_player_drops = 1; } - else if (strcmpi (w3, "town") == 0) + else if (strcasecmp (w3, "town") == 0) { // town/safe zone [remoitnane] map[m].flag.town = 1; } @@ -2151,24 +2134,18 @@ static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4) return 0; } -static int ev_db_final (void *key, void *data, va_list ap) +static void ev_db_final (db_key_t key, db_val_t data, va_list ap) { free (data); - if (strstr (key, "::") != NULL) - free (key); - return 0; -} - -static int npcname_db_final (void *key, void *data, va_list ap) -{ - return 0; + if (strstr (key.s, "::") != NULL) + free ((char*)key.s); } struct npc_data *npc_spawn_text (int m, int x, int y, int class, char *name, char *message) { struct npc_data *retval = - (struct npc_data *) aCalloc (1, sizeof (struct npc_data)); + (struct npc_data *) calloc (1, sizeof (struct npc_data)); retval->bl.id = npc_get_new_npc_id (); retval->bl.x = x; retval->bl.y = y; @@ -2259,8 +2236,6 @@ int do_final_npc (void) if (ev_db) strdb_final (ev_db, ev_db_final); - if (npcname_db) - strdb_final (npcname_db, npcname_db_final); for (i = START_NPC_NUM; i < npc_id; i++) { @@ -2284,12 +2259,10 @@ int do_final_npc (void) return 0; } -void ev_release (struct dbn *db, int which) +void ev_release (db_key_t key, db_val_t val) { - if (which & 0x1) - free (db->key); - if (which & 0x2) - free (db->data); + free ((char*)key.s); + free (val); } /*========================================== @@ -2361,7 +2334,7 @@ int do_init_npc (void) continue; } // マップの存在確認 - if (strcmp (w1, "-") != 0 && strcmpi (w1, "function") != 0) + if (strcmp (w1, "-") != 0 && strcasecmp (w1, "function") != 0) { sscanf (w1, "%[^,]", mapname); m = map_mapname2mapid (mapname); @@ -2371,17 +2344,17 @@ int do_init_npc (void) continue; } } - if (strcmpi (w2, "warp") == 0 && count > 3) + if (strcasecmp (w2, "warp") == 0 && count > 3) { npc_parse_warp (w1, w2, w3, w4); } - else if (strcmpi (w2, "shop") == 0 && count > 3) + else if (strcasecmp (w2, "shop") == 0 && count > 3) { npc_parse_shop (w1, w2, w3, w4); } - else if (strcmpi (w2, "script") == 0 && count > 3) + else if (strcasecmp (w2, "script") == 0 && count > 3) { - if (strcmpi (w1, "function") == 0) + if (strcasecmp (w1, "function") == 0) { npc_parse_function (w1, w2, w3, w4, line + w4pos, fp, &lines); @@ -2399,11 +2372,11 @@ int do_init_npc (void) { npc_parse_script (w1, w2, w3, w4, line + w4pos, fp, &lines); } - else if (strcmpi (w2, "monster") == 0 && count > 3) + else if (strcasecmp (w2, "monster") == 0 && count > 3) { npc_parse_mob (w1, w2, w3, w4); } - else if (strcmpi (w2, "mapflag") == 0 && count >= 3) + else if (strcasecmp (w2, "mapflag") == 0 && count >= 3) { npc_parse_mapflag (w1, w2, w3, w4); } @@ -2416,11 +2389,5 @@ int do_init_npc (void) printf ("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d]\n", npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob); - add_timer_func_list (npc_event_timer, "npc_event_timer"); - add_timer_func_list (npc_event_do_clock, "npc_event_do_clock"); - add_timer_func_list (npc_timerevent, "npc_timerevent"); - - //exit(1); - return 0; } diff --git a/src/map/npc.h b/src/map/npc.h index 4c08c02..248bad7 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -9,7 +9,7 @@ #define INVISIBLE_CLASS 32767 int npc_event_dequeue (struct map_session_data *sd); -int npc_event_timer (int tid, unsigned int tick, int id, int data); +void npc_event_timer (timer_id, tick_t, custom_id_t, custom_data_t); int npc_event (struct map_session_data *sd, const char *npcname, int); int npc_timer_event (const char *eventname); // Added by RoVeRT int npc_command (struct map_session_data *sd, char *npcname, char *command); diff --git a/src/map/party.c b/src/map/party.c index 4e59fae..cc35d2a 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -8,7 +8,6 @@ #include "../common/timer.h" #include "../common/socket.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "pc.h" #include "map.h" #include "battle.h" @@ -25,15 +24,14 @@ static struct dbt *party_db; -int party_send_xyhp_timer (int tid, unsigned int tick, int id, int data); +void party_send_xyhp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); /*========================================== * 終了 *------------------------------------------ */ -static int party_db_final (void *key, void *data, va_list ap) +static void party_db_final (db_key_t key, db_val_t data, va_list ap) { free (data); - return 0; } void do_final_party (void) @@ -46,7 +44,6 @@ void do_final_party (void) void do_init_party (void) { party_db = numdb_init (); - add_timer_func_list (party_send_xyhp_timer, "party_send_xyhp_timer"); add_timer_interval (gettick () + PARTY_SEND_XYHP_INVERVAL, party_send_xyhp_timer, 0, 0, PARTY_SEND_XYHP_INVERVAL); @@ -58,15 +55,14 @@ struct party *party_search (int party_id) return numdb_search (party_db, party_id); } -int party_searchname_sub (void *key, void *data, va_list ap) +void party_searchname_sub (db_key_t key, db_val_t data, va_list ap) { struct party *p = (struct party *) data, **dst; char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct party **); - if (strcmpi (p->name, str) == 0) + if (strcasecmp (p->name, str) == 0) *dst = p; - return 0; } // パーティ名検索 @@ -120,7 +116,7 @@ int party_created (int account_id, int fail, int party_id, char *name) exit (1); } - p = (struct party *) aCalloc (1, sizeof (struct party)); + CREATE (p, struct party, 1); p->party_id = party_id; memcpy (p->name, name, 24); numdb_insert (party_db, party_id, p); @@ -205,7 +201,7 @@ int party_recv_info (struct party *sp) if ((p = numdb_search (party_db, sp->party_id)) == NULL) { - p = (struct party *) aCalloc (1, sizeof (struct party)); + CREATE (p, struct party, 1); numdb_insert (party_db, sp->party_id, p); // 最初のロードなのでユーザーのチェックを行う @@ -574,7 +570,7 @@ int party_send_movemap (struct map_session_data *sd) if (sd->party_sended != 0) // もうパーティデータは送信済み return 0; - // 競合確認 + // 競合確認 party_check_conflict (sd); // あるならパーティ情報送信 @@ -645,12 +641,12 @@ int party_check_conflict (struct map_session_data *sd) } // 位置やHP通知用 -int party_send_xyhp_timer_sub (void *key, void *data, va_list ap) +void party_send_xyhp_timer_sub (db_key_t key, db_val_t data, va_list ap) { struct party *p = (struct party *) data; int i; - nullpo_retr (0, p); + nullpo_retv (p); for (i = 0; i < MAX_PARTY; i++) { @@ -673,14 +669,12 @@ int party_send_xyhp_timer_sub (void *key, void *data, va_list ap) } } - return 0; } // 位置やHP通知 -int party_send_xyhp_timer (int tid, unsigned int tick, int id, int data) +void party_send_xyhp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { numdb_foreach (party_db, party_send_xyhp_timer_sub, tick); - return 0; } // 位置通知クリア diff --git a/src/map/pc.c b/src/map/pc.c index fc2732f..ac03334 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -9,8 +9,8 @@ #include "../common/timer.h" #include "../common/db.h" -#include "../common/malloc.h" #include "../common/nullpo.h" +#include "../common/mt_rand.h" #include "atcommand.h" #include "battle.h" @@ -171,23 +171,21 @@ static int distance (int x0, int y0, int x1, int y1) return dx > dy ? dx : dy; } -static int pc_invincible_timer (int tid, unsigned int tick, int id, int data) +static void pc_invincible_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd; if ((sd = (struct map_session_data *) map_id2sd (id)) == NULL || sd->bl.type != BL_PC) - return 1; + return; if (sd->invincible_timer != tid) { if (battle_config.error_log) printf ("invincible_timer %d != %d\n", sd->invincible_timer, tid); - return 0; + return; } sd->invincible_timer = -1; - - return 0; } int pc_setinvincibletimer (struct map_session_data *sd, int val) @@ -213,20 +211,20 @@ int pc_delinvincibletimer (struct map_session_data *sd) return 0; } -static int pc_spiritball_timer (int tid, unsigned int tick, int id, int data) +static void pc_spiritball_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd; int i; if ((sd = (struct map_session_data *) map_id2sd (id)) == NULL || sd->bl.type != BL_PC) - return 1; + return; if (sd->spirit_timer[0] != tid) { if (battle_config.error_log) printf ("spirit_timer %d != %d\n", sd->spirit_timer[0], tid); - return 0; + return; } sd->spirit_timer[0] = -1; for (i = 1; i < sd->spiritball; i++) @@ -238,8 +236,6 @@ static int pc_spiritball_timer (int tid, unsigned int tick, int id, int data) if (sd->spiritball < 0) sd->spiritball = 0; clif_spiritball (sd); - - return 0; } int pc_addspiritball (struct map_session_data *sd, int interval, int max) @@ -4334,7 +4330,7 @@ static int calc_next_walk_step (struct map_session_data *sd) * 半歩進む(timer関数) *------------------------------------------ */ -static int pc_walk (int tid, unsigned int tick, int id, int data) +static void pc_walk (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd; int i, ctype; @@ -4343,18 +4339,18 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) sd = map_id2sd (id); if (sd == NULL) - return 0; + return; if (sd->walktimer != tid) { if (battle_config.error_log) printf ("pc_walk %d != %d\n", sd->walktimer, tid); - return 0; + return; } sd->walktimer = -1; if (sd->walkpath.path_pos >= sd->walkpath.path_len || sd->walkpath.path_pos != data) - return 0; + return; //歩いたので息吹のタイマーを初期化 sd->inchealspirithptick = 0; @@ -4367,13 +4363,13 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) if (sd->state.change_walk_target) { pc_walktoxy_sub (sd); - return 0; + return; } } else { // マス目境界へ到着 if (sd->walkpath.path[sd->walkpath.path_pos] >= 8) - return 1; + return; x = sd->bl.x; y = sd->bl.y; @@ -4381,7 +4377,7 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) if (ctype == 1 || ctype == 5) { pc_stop_walking (sd, 1); - return 0; + return; } sd->dir = sd->head_dir = sd->walkpath.path[sd->walkpath.path_pos]; dx = dirx[(int) sd->dir]; @@ -4390,7 +4386,7 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) if (ctype == 1 || ctype == 5) { pc_walktoxy_sub (sd); - return 0; + return; } moveblock = (x / BLOCK_SIZE != (x + dx) / BLOCK_SIZE @@ -4465,8 +4461,6 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) sd->walktimer = add_timer (tick + i, pc_walk, id, sd->walkpath.path_pos); } - - return 0; } /*========================================== @@ -4804,7 +4798,7 @@ struct pc_base_job pc_calc_base_job (int b_class) * PCの攻撃 (timer関数) *------------------------------------------ */ -int pc_attack_timer (int tid, unsigned int tick, int id, int data) +void pc_attack_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd; struct block_list *bl; @@ -4815,48 +4809,48 @@ int pc_attack_timer (int tid, unsigned int tick, int id, int data) sd = map_id2sd (id); if (sd == NULL) - return 0; + return; if (sd->attacktimer != tid) { if (battle_config.error_log) printf ("pc_attack_timer %d != %d\n", sd->attacktimer, tid); - return 0; + return; } sd->attacktimer = -1; if (sd->bl.prev == NULL) - return 0; + return; bl = map_id2bl (sd->attacktarget); if (bl == NULL || bl->prev == NULL) - return 0; + return; if (bl->type == BL_PC && pc_isdead ((struct map_session_data *) bl)) - return 0; + return; // 同じmapでないなら攻撃しない // PCが死んでても攻撃しない if (sd->bl.m != bl->m || pc_isdead (sd)) - return 0; + return; if (sd->opt1 > 0 || sd->status.option & 2 || sd->status.option & 16388) // 異常などで攻撃できない - return 0; + return; if (sd->sc_data[SC_AUTOCOUNTER].timer != -1) - return 0; + return; if (sd->sc_data[SC_BLADESTOP].timer != -1) - return 0; + return; if ((opt = battle_get_option (bl)) != NULL && *opt & 0x46) - return 0; + return; if (((sc_data = battle_get_sc_data (bl)) != NULL && sc_data[SC_TRICKDEAD].timer != -1) || ((sc_data = battle_get_sc_data (bl)) != NULL && sc_data[SC_BASILICA].timer != -1)) - return 0; + return; if (sd->skilltimer != -1 && pc_checkskill (sd, SA_FREECAST) <= 0) - return 0; + return; if (!battle_config.sdelay_attack_enable && pc_checkskill (sd, SA_FREECAST) <= 0) @@ -4864,12 +4858,12 @@ int pc_attack_timer (int tid, unsigned int tick, int id, int data) if (DIFF_TICK (tick, sd->canact_tick) < 0) { clif_skill_fail (sd, 1, 4, 0); - return 0; + return; } } if (sd->attackabletime > tick) - return 0; // cannot attack yet + return; // cannot attack yet attack_spell_delay = sd->attack_spell_delay; if (sd->attack_spell_override // [Fate] If we have an active attack spell, use that @@ -4889,7 +4883,7 @@ int pc_attack_timer (int tid, unsigned int tick, int id, int data) { // 届 かないので移動 //if(pc_can_reach(sd,bl->x,bl->y)) //clif_movetoattack(sd,bl); - return 0; + return; } if (dist <= range && !battle_check_range (&sd->bl, bl, range)) @@ -4944,8 +4938,6 @@ int pc_attack_timer (int tid, unsigned int tick, int id, int data) sd->attacktimer = add_timer (sd->attackabletime, pc_attack_timer, sd->bl.id, 0); } - - return 0; } /*========================================== @@ -5011,13 +5003,13 @@ int pc_stopattack (struct map_session_data *sd) return 0; } -int pc_follow_timer (int tid, unsigned int tick, int id, int data) +void pc_follow_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd, *bl; sd = map_id2sd (id); if (sd == NULL || sd->followtimer != tid) - return 0; + return; sd->followtimer = -1; @@ -5029,14 +5021,14 @@ int pc_follow_timer (int tid, unsigned int tick, int id, int data) bl = (struct map_session_data *) map_id2bl (sd->followtarget); if (bl == NULL) - return 0; + return; if (bl->bl.prev == NULL) break; if (bl->bl.type == BL_PC && pc_isdead ((struct map_session_data *) bl)) - return 0; + return; if (sd->skilltimer == -1 && sd->attacktimer == -1 && sd->walktimer == -1) @@ -5056,8 +5048,6 @@ int pc_follow_timer (int tid, unsigned int tick, int id, int data) sd->followtimer = add_timer (tick + sd->aspd, pc_follow_timer, sd->bl.id, 0); - - return 0; } int pc_follow (struct map_session_data *sd, int target_id) @@ -5677,8 +5667,8 @@ int pc_resetlvl (struct map_session_data *sd, int type) sd->status.skill_point = 0; sd->status.base_level = 1; sd->status.job_level = 1; - sd->status.base_exp = sd->status.base_exp = 0; - sd->status.job_exp = sd->status.job_exp = 0; + sd->status.base_exp = 0; + sd->status.job_exp = 0; if (sd->status.option != 0) sd->status.option = 0; @@ -7213,12 +7203,12 @@ int pc_percentrefinery (struct map_session_data *sd, struct item *item) * イベントタイマー処理 *------------------------------------------ */ -int pc_eventtimer (int tid, unsigned int tick, int id, int data) +void pc_eventtimer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = map_id2sd (id); int i; if (sd == NULL) - return 0; + return; for (i = 0; i < MAX_EVENTTIMER; i++) { @@ -7235,8 +7225,6 @@ int pc_eventtimer (int tid, unsigned int tick, int id, int data) if (battle_config.error_log) printf ("pc_eventtimer: no such event timer\n"); } - - return 0; } /*========================================== @@ -7255,7 +7243,7 @@ int pc_addeventtimer (struct map_session_data *sd, int tick, const char *name) if (i < MAX_EVENTTIMER) { - char *evname = (char *) aCalloc (24, sizeof (char)); + char *evname = (char *) calloc (24, 1); strncpy (evname, name, 24); evname[23] = '\0'; sd->eventtimer[i] = add_timer (gettick () + tick, @@ -7811,20 +7799,19 @@ int pc_calc_pvprank (struct map_session_data *sd) * PVP順位計算(timer) *------------------------------------------ */ -int pc_calc_pvprank_timer (int tid, unsigned int tick, int id, int data) +void pc_calc_pvprank_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = NULL; if (battle_config.pk_mode) // disable pvp ranking if pk_mode on [Valaris] - return 0; + return; sd = map_id2sd (id); if (sd == NULL) - return 0; + return; sd->pvp_timer = -1; if (pc_calc_pvprank (sd) > 0) sd->pvp_timer = add_timer (gettick () + PVP_CALCRANK_INTERVAL, pc_calc_pvprank_timer, id, data); - return 0; } /*========================================== @@ -8387,7 +8374,7 @@ static int pc_natural_heal_sub (struct map_session_data *sd, va_list ap) * HP/SP自然回復 (interval timer関数) *------------------------------------------ */ -int pc_natural_heal (int tid, unsigned int tick, int id, int data) +void pc_natural_heal (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { natural_heal_tick = tick; natural_heal_diff_tick = @@ -8395,7 +8382,6 @@ int pc_natural_heal (int tid, unsigned int tick, int id, int data) clif_foreachclient (pc_natural_heal_sub); natural_heal_prev_tick = tick; - return 0; } /*========================================== @@ -8465,7 +8451,7 @@ static int pc_autosave_sub (struct map_session_data *sd, va_list ap) * 自動セーブ (timer関数) *------------------------------------------ */ -int pc_autosave (int tid, unsigned int tick, int id, int data) +void pc_autosave (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int interval; @@ -8478,8 +8464,6 @@ int pc_autosave (int tid, unsigned int tick, int id, int data) if (interval <= 0) interval = 1; add_timer (gettick () + interval, pc_autosave, 0, 0); - - return 0; } int pc_read_gm_account (int fd) @@ -8505,7 +8489,7 @@ int pc_read_gm_account (int fd) * timer to do the day *------------------------------------------ */ -int map_day_timer (int tid, unsigned int tick, int id, int data) +void map_day_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { // by [yor] struct map_session_data *pl_sd = NULL; int i; @@ -8530,15 +8514,13 @@ int map_day_timer (int tid, unsigned int tick, int id, int data) } } } - - return 0; } /*========================================== * timer to do the night *------------------------------------------ */ -int map_night_timer (int tid, unsigned int tick, int id, int data) +void map_night_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { // by [yor] struct map_session_data *pl_sd = NULL; int i; @@ -8563,8 +8545,6 @@ int map_night_timer (int tid, unsigned int tick, int id, int data) } } } - - return 0; } void pc_setstand (struct map_session_data *sd) @@ -8973,22 +8953,11 @@ int do_init_pc (void) // gm_account_db = numdb_init(); - add_timer_func_list (pc_walk, "pc_walk"); - add_timer_func_list (pc_attack_timer, "pc_attack_timer"); - add_timer_func_list (pc_natural_heal, "pc_natural_heal"); - add_timer_func_list (pc_invincible_timer, "pc_invincible_timer"); - add_timer_func_list (pc_eventtimer, "pc_eventtimer"); - add_timer_func_list (pc_calc_pvprank_timer, "pc_calc_pvprank_timer"); - add_timer_func_list (pc_autosave, "pc_autosave"); - add_timer_func_list (pc_spiritball_timer, "pc_spiritball_timer"); add_timer_interval ((natural_heal_prev_tick = gettick () + NATURAL_HEAL_INTERVAL), pc_natural_heal, 0, 0, NATURAL_HEAL_INTERVAL); add_timer (gettick () + autosave_interval, pc_autosave, 0, 0); - // add night/day timer (by [yor]) - add_timer_func_list (map_day_timer, "map_day_timer"); // by [yor] - add_timer_func_list (map_night_timer, "map_night_timer"); // by [yor] { int day_duration = battle_config.day_duration; int night_duration = battle_config.night_duration; diff --git a/src/map/pc.h b/src/map/pc.h index 20ae26e..742d9d4 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -169,7 +169,7 @@ int pc_addeventtimercount (struct map_session_data *sd, const char *name, int tick); int pc_calc_pvprank (struct map_session_data *sd); -int pc_calc_pvprank_timer (int tid, unsigned int tick, int id, int data); +void pc_calc_pvprank_timer (timer_id, tick_t, custom_id_t, custom_data_t); int pc_ismarried (struct map_session_data *sd); int pc_marriage (struct map_session_data *sd, @@ -202,9 +202,9 @@ enum { ADDITEM_EXIST, ADDITEM_NEW, ADDITEM_OVERAMOUNT }; // timer for night.day -int day_timer_tid; -int night_timer_tid; -int map_day_timer (int, unsigned int, int, int); // by [yor] -int map_night_timer (int, unsigned int, int, int); // by [yor] +timer_id day_timer_tid; +timer_id night_timer_tid; +void map_day_timer (timer_id, tick_t, custom_id_t, custom_data_t); // by [yor] +void map_night_timer (timer_id, tick_t, custom_id_t, custom_data_t); // by [yor] #endif diff --git a/src/map/script.c b/src/map/script.c index 0c01ac0..fb8b8af 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -17,8 +17,8 @@ #include "../common/socket.h" #include "../common/timer.h" -#include "../common/malloc.h" #include "../common/lock.h" +#include "../common/mt_rand.h" #include "atcommand.h" #include "battle.h" @@ -85,11 +85,6 @@ struct dbt *script_get_userfunc_db () return userfunc_db; } -int scriptlabel_final (void *k, void *d, va_list ap) -{ - return 0; -} - static char pos[11][100] = { "頭", "体", "左手", "右手", "ローブ", "靴", "アクセサリー1", "アクセサリー2", "頭2", "頭3", "装着していない" @@ -831,13 +826,13 @@ static int add_str (const unsigned char *p) if (str_num >= str_data_size) { str_data_size += 128; - str_data = aRealloc (str_data, sizeof (str_data[0]) * str_data_size); + str_data = realloc (str_data, sizeof (str_data[0]) * str_data_size); memset (str_data + (str_data_size - 128), '\0', 128); } while (str_pos + strlen (p) + 1 >= str_size) { str_size += 256; - str_buf = (char *) aRealloc (str_buf, str_size); + str_buf = (char *) realloc (str_buf, str_size); memset (str_buf + (str_size - 256), '\0', 256); } strcpy (str_buf + str_pos, p); @@ -860,7 +855,7 @@ static void check_script_buf (int size) if (script_pos + size >= script_size) { script_size += SCRIPT_BLOCK_SIZE; - script_buf = (char *) aRealloc (script_buf, script_size); + script_buf = (char *) realloc (script_buf, script_size); memset (script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0', SCRIPT_BLOCK_SIZE); } @@ -1474,8 +1469,7 @@ unsigned char *parse_script (unsigned char *src, int line) read_constdb (); } first = 0; - script_buf = - (unsigned char *) aCalloc (SCRIPT_BLOCK_SIZE, sizeof (unsigned char)); + script_buf = (unsigned char *) calloc (SCRIPT_BLOCK_SIZE, 1); script_pos = 0; script_size = SCRIPT_BLOCK_SIZE; str_data[LABEL_NEXTLINE].type = C_NOP; @@ -1493,7 +1487,7 @@ unsigned char *parse_script (unsigned char *src, int line) // 外部用label dbの初期化 if (scriptlabel_db != NULL) - strdb_final (scriptlabel_db, scriptlabel_final); + strdb_final (scriptlabel_db, NULL); scriptlabel_db = strdb_init (50); // for error message @@ -1526,7 +1520,7 @@ unsigned char *parse_script (unsigned char *src, int line) exit (1); } set_label (l, script_pos); - strdb_insert (scriptlabel_db, p, script_pos); // 外部用label db登録 + strdb_insert (scriptlabel_db, (const char*)p, script_pos); // 外部用label db登録 *skip_word (p) = c; p = tmpp + 1; continue; @@ -1546,7 +1540,7 @@ unsigned char *parse_script (unsigned char *src, int line) add_scriptc (C_NOP); script_size = script_pos; - script_buf = (char *) aRealloc (script_buf, script_pos + 1); + script_buf = (char *) realloc (script_buf, script_pos + 1); // 未解決のラベルを解決 for (i = LABEL_START; i < str_num; i++) @@ -1772,7 +1766,7 @@ char *conv_str (struct script_state *st, struct script_data *data) if (data->type == C_INT) { char *buf; - buf = (char *) aCalloc (16, sizeof (char)); + buf = (char *) calloc (16, 1); sprintf (buf, "%d", data->u.num); data->type = C_STR; data->u.str = buf; @@ -1816,10 +1810,9 @@ void push_val (struct script_stack *stack, int type, int val) if (stack->sp >= stack->sp_max) { stack->sp_max += 64; - stack->stack_data = - (struct script_data *) aRealloc (stack->stack_data, - sizeof (stack->stack_data[0]) * - stack->sp_max); + stack->stack_data = (struct script_data *) + realloc (stack->stack_data, sizeof (stack->stack_data[0]) * + stack->sp_max); memset (stack->stack_data + (stack->sp_max - 64), 0, 64 * sizeof (*(stack->stack_data))); } @@ -1839,10 +1832,9 @@ void push_str (struct script_stack *stack, int type, unsigned char *str) if (stack->sp >= stack->sp_max) { stack->sp_max += 64; - stack->stack_data = - (struct script_data *) aRealloc (stack->stack_data, - sizeof (stack->stack_data[0]) * - stack->sp_max); + stack->stack_data = (struct script_data *) + realloc (stack->stack_data, sizeof (stack->stack_data[0]) * + stack->sp_max); memset (stack->stack_data + (stack->sp_max - 64), '\0', 64 * sizeof (*(stack->stack_data))); } @@ -2091,7 +2083,7 @@ int buildin_menu (struct script_state *st) st->state = RERUNLINE; sd->state.menu_or_input = 1; - buf = (char *) aCalloc (len + 1, sizeof (char)); + buf = (char *) calloc (len + 1, 1); buf[0] = 0; for (i = st->start + 2; menu_choices > 0; i += 2, --menu_choices) { @@ -3180,7 +3172,7 @@ char *buildin_getpartyname_sub (int party_id) if (p != NULL) { char *buf; - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strcpy (buf, p->name); return buf; } @@ -3245,7 +3237,7 @@ char *buildin_getguildname_sub (int guild_id) if (g != NULL) { char *buf; - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strcpy (buf, g->name); return buf; } @@ -3276,7 +3268,7 @@ char *buildin_getguildmaster_sub (int guild_id) if (g != NULL) { char *buf; - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strncpy (buf, g->master, 23); return buf; } @@ -3332,7 +3324,7 @@ int buildin_strcharinfo (struct script_state *st) if (num == 0) { char *buf; - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strncpy (buf, sd->status.name, 23); push_str (st->stack, C_STR, buf); } @@ -3407,7 +3399,7 @@ int buildin_getequipname (struct script_state *st) struct item_data *item; char *buf; - buf = (char *) aCalloc (64, sizeof (char)); + buf = (char *) calloc (64, 1); sd = script_rid2sd (st); num = conv_num (st, &(st->stack->stack_data[st->start + 2])); i = pc_checkequip (sd, equip[num - 1]); @@ -4208,7 +4200,7 @@ int buildin_gettimestr (struct script_state *st) fmtstr = conv_str (st, &(st->stack->stack_data[st->start + 2])); maxlen = conv_num (st, &(st->stack->stack_data[st->start + 3])); - tmpstr = (char *) aCalloc (maxlen + 1, sizeof (char)); + tmpstr = (char *) calloc (maxlen + 1, 1); strftime (tmpstr, maxlen, fmtstr, gmtime (&now)); tmpstr[maxlen] = '\0'; @@ -5773,7 +5765,7 @@ int buildin_getcastlename (struct script_state *st) { if (strcmp (mapname, gc->map_name) == 0) { - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strncpy (buf, gc->castle_name, 23); break; } @@ -6451,7 +6443,7 @@ int buildin_getitemname (struct script_state *st) i_data = itemdb_search (item_id); } - item_name = (char *) aCalloc (24, sizeof (char)); + item_name = (char *) calloc (24, 1); if (i_data) strncpy (item_name, i_data->jname, 23); else @@ -7353,11 +7345,10 @@ void op_add (struct script_state *st) else { // ssの予定 char *buf; - buf = - (char *) - aCalloc (strlen (st->stack->stack_data[st->stack->sp - 1].u.str) + - strlen (st->stack->stack_data[st->stack->sp].u.str) + 1, - sizeof (char)); + buf = (char *) + calloc (strlen (st->stack->stack_data[st->stack->sp - 1].u.str) + + strlen (st->stack->stack_data[st->stack->sp].u.str) + 1, + 1); strcpy (buf, st->stack->stack_data[st->stack->sp - 1].u.str); strcat (buf, st->stack->stack_data[st->stack->sp].u.str); if (st->stack->stack_data[st->stack->sp - 1].type == C_STR) @@ -7772,9 +7763,8 @@ int run_script_main (unsigned char *script, int pos, int rid, int oid, { if (sd->npc_stackbuf) free (sd->npc_stackbuf); - sd->npc_stackbuf = - (char *) aCalloc (sizeof (stack->stack_data[0]) * - stack->sp_max, sizeof (char)); + sd->npc_stackbuf = (char *) + calloc (sizeof (stack->stack_data[0]) * stack->sp_max, 1); memcpy (sd->npc_stackbuf, stack->stack_data, sizeof (stack->stack_data[0]) * stack->sp_max); sd->npc_stack = stack->sp; @@ -7813,9 +7803,8 @@ int run_script_l (unsigned char *script, int pos, int rid, int oid, script = sd->npc_script; stack.sp = sd->npc_stack; stack.sp_max = sd->npc_stackmax; - stack.stack_data = - (struct script_data *) aCalloc (stack.sp_max, - sizeof (stack.stack_data[0])); + stack.stack_data = (struct script_data *) + calloc (stack.sp_max, sizeof (stack.stack_data[0])); memcpy (stack.stack_data, sd->npc_stackbuf, sizeof (stack.stack_data[0]) * stack.sp_max); free (sd->npc_stackbuf); @@ -7826,9 +7815,8 @@ int run_script_l (unsigned char *script, int pos, int rid, int oid, // スタック初期化 stack.sp = 0; stack.sp_max = 64; - stack.stack_data = - (struct script_data *) aCalloc (stack.sp_max, - sizeof (stack.stack_data[0])); + stack.stack_data = (struct script_data *) + calloc (stack.sp_max, sizeof (stack.stack_data[0])); } st.stack = &stack; st.pos = pos; @@ -7880,7 +7868,7 @@ int mapreg_setregstr (int num, const char *str) mapreg_dirty = 1; return 0; } - p = (char *) aCalloc (strlen (str) + 1, sizeof (char)); + p = (char *) calloc (strlen (str) + 1, 1); strcpy (p, str); numdb_insert (mapregstr_db, num, p); mapreg_dirty = 1; @@ -7913,7 +7901,7 @@ static int script_load_mapreg () printf ("%s: %s broken data !\n", mapreg_txt, buf1); continue; } - p = (char *) aCalloc (strlen (buf2) + 1, sizeof (char)); + p = (char *) calloc (strlen (buf2) + 1, 1); strcpy (p, buf2); s = add_str (buf1); numdb_insert (mapregstr_db, (i << 24) | s, p); @@ -7938,10 +7926,10 @@ static int script_load_mapreg () * 永続的マップ変数の書き込み *------------------------------------------ */ -static int script_save_mapreg_intsub (void *key, void *data, va_list ap) +static void script_save_mapreg_intsub (db_key_t key, db_val_t data, va_list ap) { FILE *fp = va_arg (ap, FILE *); - int num = ((int) key) & 0x00ffffff, i = ((int) key) >> 24; + int num = key.i & 0x00ffffff, i = key.i >> 24; char *name = str_buf + str_data[num].str; if (name[1] != '@') { @@ -7950,13 +7938,12 @@ static int script_save_mapreg_intsub (void *key, void *data, va_list ap) else fprintf (fp, "%s,%d\t%d\n", name, i, (int) data); } - return 0; } -static int script_save_mapreg_strsub (void *key, void *data, va_list ap) +static void script_save_mapreg_strsub (db_key_t key, db_val_t data, va_list ap) { FILE *fp = va_arg (ap, FILE *); - int num = ((int) key) & 0x00ffffff, i = ((int) key) >> 24; + int num = key.i & 0x00ffffff, i = key.i >> 24; char *name = str_buf + str_data[num].str; if (name[1] != '@') { @@ -7965,7 +7952,6 @@ static int script_save_mapreg_strsub (void *key, void *data, va_list ap) else fprintf (fp, "%s,%d\t%s\n", name, i, (char *) data); } - return 0; } static int script_save_mapreg () @@ -7982,12 +7968,11 @@ static int script_save_mapreg () return 0; } -static int script_autosave_mapreg (int tid, unsigned int tick, int id, - int data) +static void script_autosave_mapreg (timer_id tid, tick_t tick, custom_id_t id, + custom_data_t data) { if (mapreg_dirty) script_save_mapreg (); - return 0; } /*========================================== @@ -8043,11 +8028,11 @@ int script_config_read (char *cfgName) i = sscanf (line, "%[^:]: %[^\r\n]", w1, w2); if (i != 2) continue; - if (strcmpi (w1, "refine_posword") == 0) + if (strcasecmp (w1, "refine_posword") == 0) { set_posword (w2); } - if (strcmpi (w1, "import") == 0) + if (strcasecmp (w1, "import") == 0) { script_config_read (w2); } @@ -8061,27 +8046,16 @@ int script_config_read (char *cfgName) * 終了 *------------------------------------------ */ -static int mapreg_db_final (void *key, void *data, va_list ap) -{ - return 0; -} -static int mapregstr_db_final (void *key, void *data, va_list ap) +static void mapregstr_db_final (db_key_t key, db_val_t data, va_list ap) { free (data); - return 0; -} - -static int scriptlabel_db_final (void *key, void *data, va_list ap) -{ - return 0; } -static int userfunc_db_final (void *key, void *data, va_list ap) +static void userfunc_db_final (db_key_t key, db_val_t data, va_list ap) { - free (key); + free ((char*)key.s); free (data); - return 0; } int do_final_script () @@ -8092,11 +8066,11 @@ int do_final_script () free (script_buf); if (mapreg_db) - numdb_final (mapreg_db, mapreg_db_final); + numdb_final (mapreg_db, NULL); if (mapregstr_db) strdb_final (mapregstr_db, mapregstr_db_final); if (scriptlabel_db) - strdb_final (scriptlabel_db, scriptlabel_db_final); + strdb_final (scriptlabel_db, NULL); if (userfunc_db) strdb_final (userfunc_db, userfunc_db_final); @@ -8118,7 +8092,6 @@ int do_init_script () mapregstr_db = numdb_init (); script_load_mapreg (); - add_timer_func_list (script_autosave_mapreg, "script_autosave_mapreg"); add_timer_interval (gettick () + MAPREG_AUTOSAVE_INTERVAL, script_autosave_mapreg, 0, 0, MAPREG_AUTOSAVE_INTERVAL); diff --git a/src/map/skill-pools.c b/src/map/skill-pools.c index 50dafcb..0c91360 100644 --- a/src/map/skill-pools.c +++ b/src/map/skill-pools.c @@ -5,7 +5,7 @@ #include "../common/timer.h" #include "../common/nullpo.h" -#include "../common/malloc.h" +#include "../common/mt_rand.h" #include "magic.h" #include "battle.h" diff --git a/src/map/skill.c b/src/map/skill.c index 54ff545..d8b64e8 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -8,7 +8,7 @@ #include "../common/timer.h" #include "../common/nullpo.h" -#include "../common/malloc.h" +#include "../common/mt_rand.h" #include "magic.h" #include "battle.h" @@ -2250,7 +2250,7 @@ int skill_area_sub_count (struct block_list *src, struct block_list *target, * *------------------------------------------ */ -static int skill_timerskill (int tid, unsigned int tick, int id, int data) +static void skill_timerskill (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = NULL; struct mob_data *md = NULL; @@ -2258,26 +2258,26 @@ static int skill_timerskill (int tid, unsigned int tick, int id, int data) struct skill_timerskill *skl = NULL; int range; - nullpo_retr (0, src); + nullpo_retv (src); if (src->prev == NULL) - return 0; + return; if (src->type == BL_PC) { - nullpo_retr (0, sd = (struct map_session_data *) src); + nullpo_retv (sd = (struct map_session_data *) src); skl = &sd->skilltimerskill[data]; } else if (src->type == BL_MOB) { - nullpo_retr (0, md = (struct mob_data *) src); + nullpo_retv (md = (struct mob_data *) src); skl = &md->skilltimerskill[data]; } else - return 0; + return; - nullpo_retr (0, skl); + nullpo_retv (skl); skl->timer = -1; if (skl->target_id) @@ -2295,17 +2295,17 @@ static int skill_timerskill (int tid, unsigned int tick, int id, int data) } } if (target == NULL) - return 0; + return; if (target->prev == NULL && skl->skill_id != RG_INTIMIDATE) - return 0; + return; if (src->m != target->m) - return 0; + return; if (sd && pc_isdead (sd)) - return 0; + return; if (target->type == BL_PC && pc_isdead ((struct map_session_data *) target) && skl->skill_id != RG_INTIMIDATE) - return 0; + return; switch (skl->skill_id) { @@ -2392,7 +2392,7 @@ static int skill_timerskill (int tid, unsigned int tick, int id, int data) else { if (src->m != skl->map) - return 0; + return; switch (skl->skill_id) { case WZ_METEOR: @@ -2410,8 +2410,6 @@ static int skill_timerskill (int tid, unsigned int tick, int id, int data) break; } } - - return 0; } /*========================================== @@ -5145,19 +5143,19 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, * スキル使用(詠唱完了、ID指定) *------------------------------------------ */ -int skill_castend_id (int tid, unsigned int tick, int id, int data) +void skill_castend_id (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = map_id2sd (id) /*,*target_sd=NULL */ ; struct block_list *bl; int range, inf2; - nullpo_retr (0, sd); + nullpo_retv ( sd); if (sd->bl.prev == NULL) //prevが無いのはありなの? - return 0; + return; if (sd->skillid != SA_CASTCANCEL && sd->skilltimer != tid) /* タイマIDの確認 */ - return 0; + return; if (sd->skillid != SA_CASTCANCEL && sd->skilltimer != -1 && pc_checkskill (sd, SA_FREECAST) > 0) { @@ -5172,14 +5170,14 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } if (sd->bl.m != bl->m || pc_isdead (sd)) { //マップが違うか自分が死んでいる sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } if (sd->skillid == PR_LEXAETERNA) @@ -5194,7 +5192,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } else if (sd->skillid == RG_BACKSTAP) @@ -5208,7 +5206,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } @@ -5219,7 +5217,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } if (inf2 & 0xC00 && sd->bl.id != bl->id) { @@ -5235,7 +5233,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } @@ -5261,7 +5259,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } if (!skill_check_condition (sd, 1)) @@ -5269,7 +5267,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } sd->skillitem = sd->skillitemlv = -1; if (battle_config.skill_out_range_consume) @@ -5279,7 +5277,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) clif_skill_fail (sd, sd->skillid, 0, 0); sd->canact_tick = tick; sd->canmove_tick = tick; - return 0; + return; } } @@ -5308,8 +5306,6 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->skilllv, tick, 0); break; } - - return 0; } /*========================================== @@ -5631,7 +5627,7 @@ int skill_castend_map (struct map_session_data *sd, int skill_num, skill_unitsetting (&sd->bl, sd->skillid, sd->skilllv, sd->skillx, sd->skilly, 0)) == NULL) return 0; - group->valstr = (char *) aCalloc (24, sizeof (char)); + CREATE (group->valstr, char, 24); memcpy (group->valstr, map, 24); group->val2 = (x << 16) | y; } @@ -7001,17 +6997,17 @@ int skill_unit_ondamaged (struct skill_unit *src, struct block_list *bl, * スキル使用(詠唱完了、場所指定) *------------------------------------------ */ -int skill_castend_pos (int tid, unsigned int tick, int id, int data) +void skill_castend_pos (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = map_id2sd (id) /*,*target_sd=NULL */ ; int range, maxcount; - nullpo_retr (0, sd); + nullpo_retv (sd); if (sd->bl.prev == NULL) - return 0; + return; if (sd->skilltimer != tid) /* タイマIDの確認 */ - return 0; + return; if (sd->skilltimer != -1 && pc_checkskill (sd, SA_FREECAST) > 0) { sd->speed = sd->prev_speed; @@ -7023,7 +7019,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } if (battle_config.pc_skill_reiteration == 0) @@ -7061,7 +7057,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } } @@ -7098,7 +7094,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } } @@ -7121,7 +7117,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } } @@ -7138,7 +7134,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } if (!skill_check_condition (sd, 1)) @@ -7146,7 +7142,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } sd->skillitem = sd->skillitemlv = -1; if (battle_config.skill_out_range_consume) @@ -7156,7 +7152,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) clif_skill_fail (sd, sd->skillid, 0, 0); sd->canact_tick = tick; sd->canmove_tick = tick; - return 0; + return; } } @@ -7166,8 +7162,6 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) skill_castend_pos2 (&sd->bl, sd->skillx, sd->skilly, sd->skillid, sd->skilllv, tick, 0); - - return 0; } /*========================================== @@ -7338,8 +7332,11 @@ static int skill_check_condition_mob_master_sub (struct block_list *bl, nullpo_retr (0, bl); nullpo_retr (0, ap); nullpo_retr (0, md = (struct mob_data *) bl); - nullpo_retr (0, src_id = va_arg (ap, int)); - nullpo_retr (0, mob_class = va_arg (ap, int)); + + if (!(src_id = va_arg (ap, int))) + return 0; + if (!(mob_class = va_arg (ap, int))) + return 0; nullpo_retr (0, c = va_arg (ap, int *)); if (md->class == mob_class && md->master_id == src_id) @@ -8418,7 +8415,6 @@ int skill_use_pos (struct map_session_data *sd, int skill_castcancel (struct block_list *bl, int type) { int inf; - int ret = 0; nullpo_retr (0, bl); @@ -8439,22 +8435,16 @@ int skill_castcancel (struct block_list *bl, int type) if (!type) { if ((inf = skill_get_inf (sd->skillid)) == 2 || inf == 32) - ret = delete_timer (sd->skilltimer, skill_castend_pos); + delete_timer (sd->skilltimer, skill_castend_pos); else - ret = delete_timer (sd->skilltimer, skill_castend_id); - if (ret < 0) - printf ("delete timer error : skillid : %d\n", - sd->skillid); + delete_timer (sd->skilltimer, skill_castend_id); } else { if ((inf = skill_get_inf (sd->skillid_old)) == 2 || inf == 32) - ret = delete_timer (sd->skilltimer, skill_castend_pos); + delete_timer (sd->skilltimer, skill_castend_pos); else - ret = delete_timer (sd->skilltimer, skill_castend_id); - if (ret < 0) - printf ("delete timer error : skillid : %d\n", - sd->skillid_old); + delete_timer (sd->skilltimer, skill_castend_id); } sd->skilltimer = -1; clif_skillcastcancel (bl); @@ -8469,14 +8459,12 @@ int skill_castcancel (struct block_list *bl, int type) if (md->skilltimer != -1) { if ((inf = skill_get_inf (md->skillid)) == 2 || inf == 32) - ret = delete_timer (md->skilltimer, mobskill_castend_pos); + delete_timer (md->skilltimer, mobskill_castend_pos); else - ret = delete_timer (md->skilltimer, mobskill_castend_id); + delete_timer (md->skilltimer, mobskill_castend_id); md->skilltimer = -1; clif_skillcastcancel (bl); } - if (ret < 0) - printf ("delete timer error : skillid : %d\n", md->skillid); return 0; } return 1; @@ -9496,7 +9484,7 @@ int skill_update_heal_animation (struct map_session_data *sd) * ステータス異常終了タイマー *------------------------------------------ */ -int skill_status_change_timer (int tid, unsigned int tick, int id, int data) +void skill_status_change_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int type = data; struct block_list *bl; @@ -9505,8 +9493,8 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) //short *sc_count; //使ってない? if ((bl = map_id2bl (id)) == NULL) - return 0; //該当IDがすでに消滅しているというのはいかにもありそうなのでスルーしてみる - nullpo_retr (0, sc_data = battle_get_sc_data (bl)); + return; //該当IDがすでに消滅しているというのはいかにもありそうなのでスルーしてみる + nullpo_retv (sc_data = battle_get_sc_data (bl)); if (bl->type == BL_PC) sd = (struct map_session_data *) bl; @@ -9543,7 +9531,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9562,7 +9550,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9581,7 +9569,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 250 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9599,7 +9587,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 250 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9613,7 +9601,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 * 600 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9626,7 +9614,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; @@ -9642,7 +9630,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (150 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9654,7 +9642,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) add_timer (1000 * 600 + tick, skill_status_change_timer, bl->id, data); sc_data[type].val2 = 1; - return 0; + return; } break; @@ -9678,7 +9666,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) (unit->group->skill_id, unit->group->skill_lv) + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; @@ -9697,7 +9685,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) (unit->group->skill_id, unit->group->skill_lv) / 10 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; @@ -9716,7 +9704,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } else if ((--sc_data[type].val3) > 0) { @@ -9740,7 +9728,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; case SC_POISON: @@ -9796,7 +9784,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 10000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } if (sd->status.max_hp <= sd->status.hp) skill_status_change_end (&sd->bl, SC_TENSIONRELAX, -1); @@ -9819,7 +9807,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 * 600 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; case SC_DANCING: //ダンススキルの時間SP消費 { @@ -9869,7 +9857,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } } @@ -9885,7 +9873,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 15000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9899,7 +9887,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 10000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9916,7 +9904,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 60000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9934,7 +9922,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; @@ -9944,7 +9932,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) } - return skill_status_change_end (bl, type, tid); + skill_status_change_end (bl, type, tid); } /*========================================== @@ -11153,8 +11141,7 @@ struct skill_unit_group *skill_initunitgroup (struct block_list *src, group->group_id = skill_unit_group_newid++; if (skill_unit_group_newid <= 0) skill_unit_group_newid = 10; - group->unit = - (struct skill_unit *) aCalloc (count, sizeof (struct skill_unit)); + CREATE (group->unit, struct skill_unit, count); group->unit_count = count; group->val1 = group->val2 = 0; group->skill_id = skillid; @@ -11493,15 +11480,13 @@ int skill_unit_timer_sub (struct block_list *bl, va_list ap) * スキルユニットタイマー処理 *------------------------------------------ */ -int skill_unit_timer (int tid, unsigned int tick, int id, int data) +void skill_unit_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { map_freeblock_lock (); map_foreachobject (skill_unit_timer_sub, BL_SKILL, tick); map_freeblock_unlock (); - - return 0; } /*========================================== @@ -11814,19 +11799,19 @@ int skill_unit_move_unit_group (struct skill_unit_group *group, int m, int dx, static int scan_stat (char *statname) { - if (!strcmpi (statname, "str")) + if (!strcasecmp (statname, "str")) return SP_STR; - if (!strcmpi (statname, "dex")) + if (!strcasecmp (statname, "dex")) return SP_DEX; - if (!strcmpi (statname, "agi")) + if (!strcasecmp (statname, "agi")) return SP_AGI; - if (!strcmpi (statname, "vit")) + if (!strcasecmp (statname, "vit")) return SP_VIT; - if (!strcmpi (statname, "int")) + if (!strcasecmp (statname, "int")) return SP_INT; - if (!strcmpi (statname, "luk")) + if (!strcasecmp (statname, "luk")) return SP_LUK; - if (!strcmpi (statname, "none")) + if (!strcasecmp (statname, "none")) return 0; else @@ -11911,18 +11896,18 @@ int skill_readdb (void) skill_db[i].num[k] = (split2[k]) ? atoi (split2[k]) : atoi (split2[0]); - if (strcmpi (split[9], "yes") == 0) + if (strcasecmp (split[9], "yes") == 0) skill_db[i].castcancel = 1; else skill_db[i].castcancel = 0; skill_db[i].cast_def_rate = atoi (split[9]); skill_db[i].inf2 = atoi (split[10]); skill_db[i].maxcount = atoi (split[11]); - if (strcmpi (split[13], "weapon") == 0) + if (strcasecmp (split[13], "weapon") == 0) skill_db[i].skill_type = BF_WEAPON; - else if (strcmpi (split[12], "magic") == 0) + else if (strcasecmp (split[12], "magic") == 0) skill_db[i].skill_type = BF_MAGIC; - else if (strcmpi (split[12], "misc") == 0) + else if (strcasecmp (split[12], "misc") == 0) skill_db[i].skill_type = BF_MISC; else skill_db[i].skill_type = 0; @@ -11938,12 +11923,12 @@ int skill_readdb (void) skill_db[i].blewcount[k] = (split2[k]) ? atoi (split2[k]) : atoi (split2[0]); - if (!strcmpi (split[15], "passive")) + if (!strcasecmp (split[15], "passive")) { skill_pool_register (i); skill_db[i].poolflags = SKILL_POOL_FLAG; } - else if (!strcmpi (split[15], "active")) + else if (!strcasecmp (split[15], "active")) { skill_pool_register (i); skill_db[i].poolflags = SKILL_POOL_FLAG | SKILL_POOL_ACTIVE; @@ -12086,29 +12071,29 @@ int skill_readdb (void) skill_db[i].weapon |= 1 << l; } - if (strcmpi (split[8], "hiding") == 0) + if (strcasecmp (split[8], "hiding") == 0) skill_db[i].state = ST_HIDING; - else if (strcmpi (split[8], "cloaking") == 0) + else if (strcasecmp (split[8], "cloaking") == 0) skill_db[i].state = ST_CLOAKING; - else if (strcmpi (split[8], "hidden") == 0) + else if (strcasecmp (split[8], "hidden") == 0) skill_db[i].state = ST_HIDDEN; - else if (strcmpi (split[8], "riding") == 0) + else if (strcasecmp (split[8], "riding") == 0) skill_db[i].state = ST_RIDING; - else if (strcmpi (split[8], "falcon") == 0) + else if (strcasecmp (split[8], "falcon") == 0) skill_db[i].state = ST_FALCON; - else if (strcmpi (split[8], "cart") == 0) + else if (strcasecmp (split[8], "cart") == 0) skill_db[i].state = ST_CART; - else if (strcmpi (split[8], "shield") == 0) + else if (strcasecmp (split[8], "shield") == 0) skill_db[i].state = ST_SHIELD; - else if (strcmpi (split[8], "sight") == 0) + else if (strcasecmp (split[8], "sight") == 0) skill_db[i].state = ST_SIGHT; - else if (strcmpi (split[8], "explosionspirits") == 0) + else if (strcasecmp (split[8], "explosionspirits") == 0) skill_db[i].state = ST_EXPLOSIONSPIRITS; - else if (strcmpi (split[8], "recover_weight_rate") == 0) + else if (strcasecmp (split[8], "recover_weight_rate") == 0) skill_db[i].state = ST_RECOV_WEIGHT_RATE; - else if (strcmpi (split[8], "move_enable") == 0) + else if (strcasecmp (split[8], "move_enable") == 0) skill_db[i].state = ST_MOVE_ENABLE; - else if (strcmpi (split[8], "water") == 0) + else if (strcasecmp (split[8], "water") == 0) skill_db[i].state = ST_WATER; else skill_db[i].state = ST_NONE; @@ -12275,10 +12260,10 @@ int skill_readdb (void) void skill_reload (void) { /* - * + * * * - * + * */ do_init_skill (); @@ -12292,12 +12277,6 @@ int do_init_skill (void) { skill_readdb (); - add_timer_func_list (skill_unit_timer, "skill_unit_timer"); - add_timer_func_list (skill_castend_id, "skill_castend_id"); - add_timer_func_list (skill_castend_pos, "skill_castend_pos"); - add_timer_func_list (skill_timerskill, "skill_timerskill"); - add_timer_func_list (skill_status_change_timer, - "skill_status_change_timer"); add_timer_interval (gettick () + SKILLUNITTIMER_INVERVAL, skill_unit_timer, 0, 0, SKILLUNITTIMER_INVERVAL); diff --git a/src/map/skill.h b/src/map/skill.h index 08f2e18..d0a698c 100644 --- a/src/map/skill.h +++ b/src/map/skill.h @@ -2,6 +2,8 @@ #ifndef _SKILL_H_ #define _SKILL_H_ +#include "../common/timer.h" + #include "map.h" #include "magic.h" @@ -149,7 +151,7 @@ int skill_status_effect (struct block_list *bl, int type, int val1, int val2, int skill_status_change_start (struct block_list *bl, int type, int val1, int val2, int val3, int val4, int tick, int flag); -int skill_status_change_timer (int tid, unsigned int tick, int id, int data); +void skill_status_change_timer (timer_id, tick_t, custom_id_t, custom_data_t); int skill_status_change_active (struct block_list *bl, int type); // [fate] int skill_encchant_eremental_end (struct block_list *bl, int type); int skill_status_change_end (struct block_list *bl, int type, int tid); diff --git a/src/map/storage.c b/src/map/storage.c index 84dedb3..4a0d934 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -7,7 +7,6 @@ #include "../common/db.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "storage.h" #include "chrif.h" @@ -40,18 +39,16 @@ int storage_comp_item (const void *_i1, const void *_i2) return i1->nameid - i2->nameid; } -static int guild_storage_db_final (void *key, void *data, va_list ap) +static void guild_storage_db_final (db_key_t key, db_val_t data, va_list ap) { struct guild_storage *gstor = (struct guild_storage *) data; free (gstor); - return 0; } -static int storage_db_final (void *key, void *data, va_list ap) +static void storage_db_final (db_key_t key, db_val_t data, va_list ap) { struct storage *stor = (struct storage *) data; free (stor); - return 0; } void sortage_sortitem (struct storage *stor) @@ -87,7 +84,7 @@ void do_final_storage (void) // by [MC Cameri] numdb_final (guild_storage_db, guild_storage_db_final); } -static int storage_reconnect_sub (void *key, void *data, va_list ap) +static void storage_reconnect_sub (db_key_t key, db_val_t data, va_list ap) { //Parses storage and saves 'dirty' ones upon reconnect. [Skotlex] int type = va_arg (ap, int); if (type) @@ -102,7 +99,6 @@ static int storage_reconnect_sub (void *key, void *data, va_list ap) if (stor->dirty && stor->storage_status == 0) //Save closed storages. storage_storage_save (stor->account_id, stor->dirty == 2 ? 1 : 0); } - return 0; } //Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex @@ -118,7 +114,7 @@ struct storage *account2storage (int account_id) (struct storage *) numdb_search (storage_db, account_id); if (stor == NULL) { - stor = (struct storage *) aCallocA (sizeof (struct storage), 1); + CREATE (stor, struct storage, 1); stor->account_id = account_id; numdb_insert (storage_db, stor->account_id, stor); } @@ -481,13 +477,7 @@ struct guild_storage *guild2storage (int guild_id) guild_id); if (gs == NULL) { - gs = (struct guild_storage *) - aCallocA (sizeof (struct guild_storage), 1); - if (gs == NULL) - { - printf ("storage: out of memory!\n"); - exit (0); - } + CREATE (gs, struct guild_storage, 1); gs->guild_id = guild_id; numdb_insert (guild_storage_db, gs->guild_id, gs); } diff --git a/src/map/tmw.c b/src/map/tmw.c index c04c9c8..3487c1d 100644 --- a/src/map/tmw.c +++ b/src/map/tmw.c @@ -8,7 +8,6 @@ #include "../common/socket.h" #include "../common/timer.h" -#include "../common/malloc.h" #include "../common/version.h" #include "../common/nullpo.h" @@ -30,7 +29,7 @@ #include "skill.h" #include "storage.h" #include "trade.h" - + int tmw_CheckChatSpam (struct map_session_data *sd, char *message) { nullpo_retr (1, sd); -- cgit v1.2.3-70-g09d2