summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaruna <haru@dotalux.com>2013-12-16 19:25:58 -0800
committerHaruna <haru@dotalux.com>2013-12-16 19:25:58 -0800
commit8b84026c292fed6f6218278c870c4f8839fbd40a (patch)
tree4b62aa52844a1916db1f18faba8b9cf29ff30810 /src
parent9e223137eba56dcd41bececf4360f321c9117247 (diff)
parent3917562fc493c031bb20181b5d9ae6ab15ce9b76 (diff)
downloadhercules-8b84026c292fed6f6218278c870c4f8839fbd40a.tar.gz
hercules-8b84026c292fed6f6218278c870c4f8839fbd40a.tar.bz2
hercules-8b84026c292fed6f6218278c870c4f8839fbd40a.tar.xz
hercules-8b84026c292fed6f6218278c870c4f8839fbd40a.zip
Merge pull request #237 from HerculesWS/warnings
This adds an Xcode project file (for those who develop on OS X) and fixes several - potential or real - issues we detected thanks to its more strict warnings settings. It also updates the unix build script with similar warning settings.
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c57
-rw-r--r--src/char/int_guild.c30
-rw-r--r--src/char/int_quest.c1
-rw-r--r--src/char/inter.c2
-rw-r--r--src/common/HPM.h4
-rw-r--r--src/common/Makefile.in9
-rw-r--r--src/common/cbasetypes.h26
-rw-r--r--src/common/core.c3
-rw-r--r--src/common/db.h6
-rw-r--r--src/common/grfio.c23
-rw-r--r--src/common/malloc.c2
-rw-r--r--src/common/mmo.h3
-rw-r--r--src/common/nullpo.c94
-rw-r--r--src/common/nullpo.h302
-rw-r--r--src/common/socket.c12
-rw-r--r--src/common/sql.c4
-rw-r--r--src/common/strlib.c19
-rw-r--r--src/common/timer.c8
-rw-r--r--src/config/renewal.h1
-rw-r--r--src/login/account_sql.c7
-rw-r--r--src/login/login.c10
-rw-r--r--src/login/login.h4
-rw-r--r--src/map/atcommand.c52
-rw-r--r--src/map/battle.c50
-rw-r--r--src/map/clif.c95
-rw-r--r--src/map/clif.h24
-rw-r--r--src/map/guild.c14
-rw-r--r--src/map/homunculus.c2
-rw-r--r--src/map/intif.c10
-rw-r--r--src/map/intif.h8
-rw-r--r--src/map/irc-bot.c7
-rw-r--r--src/map/irc-bot.h2
-rw-r--r--src/map/itemdb.c9
-rw-r--r--src/map/map.c16
-rw-r--r--src/map/mob.c19
-rw-r--r--src/map/mob.h2
-rw-r--r--src/map/npc.c21
-rw-r--r--src/map/party.h10
-rw-r--r--src/map/path.c2
-rw-r--r--src/map/pc.c19
-rw-r--r--src/map/pc_groups.c28
-rw-r--r--src/map/script.c56
-rw-r--r--src/map/script.h5
-rw-r--r--src/map/skill.c589
-rw-r--r--src/map/status.c90
-rw-r--r--src/map/status.h15
-rw-r--r--src/map/unit.c12
-rw-r--r--src/tool/Makefile.in4
-rw-r--r--src/tool/mapcache.c2
49 files changed, 857 insertions, 933 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 6534f484c..8d7ff1ab4 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -331,15 +331,15 @@ void set_char_offline(int char_id, int account_id)
static int char_db_setoffline(DBKey key, DBData *data, va_list ap)
{
struct online_char_data* character = (struct online_char_data*)DB->data2ptr(data);
- int server = va_arg(ap, int);
- if (server == -1) {
+ int server_id = va_arg(ap, int);
+ if (server_id == -1) {
character->char_id = -1;
character->server = -1;
if(character->waiting_disconnect != INVALID_TIMER){
timer->delete(character->waiting_disconnect, chardb_waiting_disconnect);
character->waiting_disconnect = INVALID_TIMER;
}
- } else if (character->server == server)
+ } else if (character->server == server_id)
character->server = -2; //In some map server that we aren't connected to.
return 0;
}
@@ -2209,7 +2209,6 @@ void loginif_on_ready(void)
int parse_fromlogin(int fd) {
struct char_session_data* sd = NULL;
- int i;
// only process data from the login-server
if( fd != login_fd ) {
@@ -2242,10 +2241,9 @@ int parse_fromlogin(int fd) {
uint16 command = RFIFOW(fd,0);
if( HPM->packetsc[hpParse_FromLogin] ) {
- if( (i = HPM->parse_packets(fd,hpParse_FromLogin)) ) {
- if( i == 1 ) continue;
- if( i == 2 ) return 0;
- }
+ int success = HPM->parse_packets(fd,hpParse_FromLogin);
+ if( success == 1 ) continue;
+ else if( success == 2 ) return 0;
}
switch( command ) {
@@ -2316,6 +2314,8 @@ int parse_fromlogin(int fd) {
break;
case 0x2717: // account data
+ {
+ int i;
if (RFIFOREST(fd) < 72)
return 0;
@@ -2358,6 +2358,7 @@ int parse_fromlogin(int fd) {
}
}
RFIFOSKIP(fd,72);
+ }
break;
// login-server alive packet
@@ -2385,6 +2386,7 @@ int parse_fromlogin(int fd) {
int class_[MAX_CHARS];
int guild_id[MAX_CHARS];
int num;
+ int i;
char* data;
struct auth_node* node = (struct auth_node*)idb_get(auth_db, acc);
@@ -3209,7 +3211,7 @@ int parse_frommap(int fd)
SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) )
+ if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) )
Sql_ShowDebug(sql_handle);
else if( SQL->NumRows(sql_handle) == 0 ) {
result = 1; // 1-player not found
@@ -3217,15 +3219,13 @@ int parse_frommap(int fd)
Sql_ShowDebug(sql_handle);
result = 1; // 1-player not found
} else {
- char name[NAME_LENGTH];
int account_id, char_id;
char* data;
time_t unban_time;
SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data);
- SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
- SQL->GetData(sql_handle, 2, &data, NULL); char_id = atoi(data);
- SQL->GetData(sql_handle, 3, &data, NULL); unban_time = atol(data);
+ SQL->GetData(sql_handle, 1, &data, NULL); char_id = atoi(data);
+ SQL->GetData(sql_handle, 2, &data, NULL); unban_time = atol(data);
if( login_fd <= 0 )
result = 3; // 3-login-server offline
@@ -3465,7 +3465,6 @@ int parse_frommap(int fd)
{
struct status_change_data data;
StringBuf buf;
- int i;
StrBuf->Init(&buf);
StrBuf->Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", scdata_db);
@@ -3905,7 +3904,6 @@ static void char_delete2_cancel(int fd, struct char_session_data* sd)
int parse_char(int fd)
{
- int i;
char email[40];
unsigned short cmd;
int map_fd;
@@ -3937,10 +3935,9 @@ int parse_char(int fd)
#define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0)
if( HPM->packetsc[hpParse_Char] ) {
- if( (i = HPM->parse_packets(fd,hpParse_Char)) ) {
- if( i == 1 ) continue;
- if( i == 2 ) return 0;
- }
+ int success = HPM->parse_packets(fd,hpParse_Char);
+ if( success == 1 ) continue;
+ else if( success == 2 ) return 0;
}
cmd = RFIFOW(fd,0);
@@ -4043,6 +4040,7 @@ int parse_char(int fd)
uint32 subnet_map_ip;
struct auth_node* node;
int server_id = 0;
+ int i;
int slot = RFIFOB(fd,2);
RFIFOSKIP(fd,3);
@@ -4214,31 +4212,35 @@ int parse_char(int fd)
#if PACKETVER >= 20120307
// S 0970 <name>.24B <slot>.B <hair color>.W <hair style>.W
case 0x970:
+ {
+ int result;
FIFOSD_CHECK(31);
#else
// S 0067 <name>.24B <str>.B <agi>.B <vit>.B <int>.B <dex>.B <luk>.B <slot>.B <hair color>.W <hair style>.W
case 0x67:
+ {
+ int result;
FIFOSD_CHECK(37);
#endif
if( !char_new ) //turn character creation on/off [Kevin]
- i = -2;
+ result = -2;
else
#if PACKETVER >= 20120307
- i = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOW(fd,27),RFIFOW(fd,29));
+ result = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOW(fd,27),RFIFOW(fd,29));
#else
- i = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27),RFIFOB(fd,28),RFIFOB(fd,29),RFIFOB(fd,30),RFIFOB(fd,31),RFIFOB(fd,32),RFIFOW(fd,33),RFIFOW(fd,35));
+ result = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27),RFIFOB(fd,28),RFIFOB(fd,29),RFIFOB(fd,30),RFIFOB(fd,31),RFIFOB(fd,32),RFIFOW(fd,33),RFIFOW(fd,35));
#endif
//'Charname already exists' (-1), 'Char creation denied' (-2) and 'You are underaged' (-3)
- if (i < 0) {
+ if (result < 0) {
WFIFOHEAD(fd,3);
WFIFOW(fd,0) = 0x6e;
/* Others I found [Ind] */
/* 0x02 = Symbols in Character Names are forbidden */
/* 0x03 = You are not elegible to open the Character Slot. */
/* 0x0B = This service is only available for premium users. */
- switch (i) {
+ switch (result) {
case -1: WFIFOB(fd,2) = 0x00; break;
case -2: WFIFOB(fd,2) = 0xFF; break;
case -3: WFIFOB(fd,2) = 0x01; break;
@@ -4249,7 +4251,7 @@ int parse_char(int fd)
int len;
// retrieve data
struct mmo_charstatus char_dat;
- mmo_char_fromsql(i, &char_dat, false); //Only the short data is needed.
+ mmo_char_fromsql(result, &char_dat, false); //Only the short data is needed.
// send to player
WFIFOHEAD(fd,2+MAX_CHAR_BUF);
@@ -4258,13 +4260,14 @@ int parse_char(int fd)
WFIFOSET(fd,len);
// add new entry to the chars list
- sd->found_char[char_dat.slot] = i; // the char_id of the new char
+ sd->found_char[char_dat.slot] = result; // the char_id of the new char
}
#if PACKETVER >= 20120307
RFIFOSKIP(fd,31);
#else
RFIFOSKIP(fd,37);
#endif
+ }
break;
// delete char
@@ -4275,6 +4278,7 @@ int parse_char(int fd)
if (cmd == 0x1fb) FIFOSD_CHECK(56);
{
int cid = RFIFOL(fd,2);
+ int i;
#if PACKETVER >= 20110309
if( *pincode->enabled ){ // hack check
struct online_char_data* character;
@@ -4483,6 +4487,7 @@ int parse_char(int fd)
{
char* l_user = (char*)RFIFOP(fd,2);
char* l_pass = (char*)RFIFOP(fd,26);
+ int i;
l_user[23] = '\0';
l_pass[23] = '\0';
ARR_FIND( 0, ARRAYLENGTH(server), i, server[i].fd <= 0 );
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index 5f033f4d7..6bd8ca568 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -447,16 +447,16 @@ struct guild * inter_guild_fromsql(int guild_id)
while( SQL_SUCCESS == SQL->NextRow(sql_handle) )
{
int position;
- struct guild_position* p;
+ struct guild_position *pos;
SQL->GetData(sql_handle, 0, &data, NULL); position = atoi(data);
if( position < 0 || position >= MAX_GUILDPOSITION )
continue;// invalid position
- p = &g->position[position];
- SQL->GetData(sql_handle, 1, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH));
- SQL->GetData(sql_handle, 2, &data, NULL); p->mode = atoi(data);
- SQL->GetData(sql_handle, 3, &data, NULL); p->exp_mode = atoi(data);
- p->modified = GS_POSITION_UNMODIFIED;
+ pos = &g->position[position];
+ SQL->GetData(sql_handle, 1, &data, &len); memcpy(pos->name, data, min(len, NAME_LENGTH));
+ SQL->GetData(sql_handle, 2, &data, NULL); pos->mode = atoi(data);
+ SQL->GetData(sql_handle, 3, &data, NULL); pos->exp_mode = atoi(data);
+ pos->modified = GS_POSITION_UNMODIFIED;
}
//printf("- Read guild_alliance %d from sql \n",guild_id);
@@ -1664,7 +1664,7 @@ static int mapif_parse_GuildDeleteAlliance(struct guild *g, int guild_id, int ac
int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,int account_id1,int account_id2,int flag)
{
// Could speed up
- struct guild *g[2];
+ struct guild *g[2] = { NULL };
int j,i;
g[0] = inter_guild_fromsql(guild_id1);
g[1] = inter_guild_fromsql(guild_id2);
@@ -1675,25 +1675,19 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,int account_id1
if(g[0]==NULL || g[1]==NULL)
return 0;
- if(flag&GUILD_ALLIANCE_REMOVE)
- {
+ if( flag&GUILD_ALLIANCE_REMOVE ) {
// Remove alliance/opposition, in case of alliance, remove on both side
- for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++)
- {
+ for( i = 0; i < ((flag&GUILD_ALLIANCE_TYPE_MASK) ? 1 : 2); i++ ) {
ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == g[1-i]->guild_id && g[i]->alliance[j].opposition == (flag&GUILD_ALLIANCE_TYPE_MASK) );
if( j < MAX_GUILDALLIANCE )
g[i]->alliance[j].guild_id = 0;
}
- }
- else
- {
+ } else {
// Add alliance, in case of alliance, add on both side
- for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++)
- {
+ for( i = 0; i < ((flag&GUILD_ALLIANCE_TYPE_MASK) ? 1 : 2); i++ ) {
// Search an empty slot
ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == 0 );
- if( j < MAX_GUILDALLIANCE )
- {
+ if( j < MAX_GUILDALLIANCE ) {
g[i]->alliance[j].guild_id=g[1-i]->guild_id;
memcpy(g[i]->alliance[j].name,g[1-i]->name,NAME_LENGTH);
// Set alliance type
diff --git a/src/char/int_quest.c b/src/char/int_quest.c
index ce63a5581..f8a05bc8f 100644
--- a/src/char/int_quest.c
+++ b/src/char/int_quest.c
@@ -38,6 +38,7 @@ struct quest *mapif_quests_fromsql(int char_id, int *count) {
stmt = SQL->StmtMalloc(sql_handle);
if (stmt == NULL) {
SqlStmt_ShowDebug(stmt);
+ *count = 0;
return NULL;
}
diff --git a/src/char/inter.c b/src/char/inter.c
index 771b51602..63e1564ff 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -872,7 +872,7 @@ int inter_mapif_init(int fd)
//--------------------------------------------------------
// broadcast sending
-int mapif_broadcast(unsigned char *mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd)
+int mapif_broadcast(unsigned char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd)
{
unsigned char *buf = (unsigned char*)aMalloc((len)*sizeof(unsigned char));
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 5466693ab..d5a5cbb6a 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -28,8 +28,10 @@
#define plugin_import(x,y,z) (z)dlsym((x),(y))
#define plugin_close(x) dlclose(x)
- #ifdef CYGWIN
+ #if defined CYGWIN
#define DLL_EXT ".dll"
+ #elif defined __DARWIN__
+ #define DLL_EXT ".dylib"
#else
#define DLL_EXT ".so"
#endif
diff --git a/src/common/Makefile.in b/src/common/Makefile.in
index 1e23ab5e8..7bb9ae630 100644
--- a/src/common/Makefile.in
+++ b/src/common/Makefile.in
@@ -15,8 +15,8 @@ MT19937AR_H = $(MT19937AR_D)/mt19937ar.h
MT19937AR_INCLUDE = -I$(MT19937AR_D)
COMMON_SHARED_C = conf.c db.c des.c ers.c grfio.c HPM.c mapindex.c md5calc.c \
- mempool.c mutex.c nullpo.c raconf.c random.c showmsg.c strlib.c \
- thread.c timer.c utils.c
+ mutex.c nullpo.c random.c showmsg.c strlib.c thread.c \
+ timer.c utils.c
COMMON_C = $(COMMON_SHARED_C)
COMMON_SHARED_OBJ = $(patsubst %.c,%.o,$(COMMON_SHARED_C))
COMMON_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \
@@ -25,9 +25,8 @@ COMMON_MINI_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \
miniconsole.o minicore.o minimalloc.o minisocket.o)
COMMON_C += console.c core.c malloc.c socket.c
COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \
- evdp.h grfio.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h \
- mempool.h mmo.h mutex.h netbuffer.h network.h nullpo.h raconf.h \
- random.h showmsg.h socket.h spinlock.h sql.h strlib.h \
+ grfio.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h mmo.h mutex.h \
+ nullpo.h random.h showmsg.h socket.h spinlock.h sql.h strlib.h \
thread.h timer.h utils.h winapi.h
COMMON_SQL_OBJ = obj_sql/sql.o
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index 6de2ace01..120f4f861 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -255,6 +255,13 @@ typedef uintptr_t uintptr;
#define ra_align(n) __attribute__(( aligned(n) ))
#endif
+// Directives for the (clang) static analyzer
+#ifdef __clang__
+#define analyzer_noreturn __attribute__((analyzer_noreturn))
+#else
+#define analyzer_noreturn
+#endif
+
/////////////////////////////
// for those still not building c++
@@ -353,23 +360,6 @@ typedef char bool;
#endif
//////////////////////////////////////////////////////////////////////////
-// Assert
-
-#if ! defined(Assert)
-#if defined(RELEASE)
-#define Assert(EX)
-#else
-// extern "C" {
-#include <assert.h>
-// }
-#if !defined(DEFCPP) && defined(WIN32) && !defined(MINGW)
-#include <crtdbg.h>
-#endif
-#define Assert(EX) assert(EX)
-#endif
-#endif /* ! defined(Assert) */
-
-//////////////////////////////////////////////////////////////////////////
// Has to be unsigned to avoid problems in some systems
// Problems arise when these functions expect an argument in the range [0,256[ and are fed a signed char.
#include <ctype.h>
@@ -405,7 +395,7 @@ typedef char bool;
//////////////////////////////////////////////////////////////////////////
-// Use the preprocessor to 'stringify' stuff (concert to a string).
+// Use the preprocessor to 'stringify' stuff (convert to a string).
// example:
// #define TESTE blabla
// QUOTE(TESTE) -> "TESTE"
diff --git a/src/common/core.c b/src/common/core.c
index dd839b372..8178a48a5 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -15,7 +15,6 @@
#include "../common/socket.h"
#include "../common/timer.h"
#include "../common/thread.h"
- #include "../common/mempool.h"
#include "../common/sql.h"
#include "../config/core.h"
#include "../common/HPM.h"
@@ -328,7 +327,6 @@ int main (int argc, char **argv) {
Sql_Init();
rathread_init();
- mempool_init();
DB->init();
signals_init();
@@ -370,7 +368,6 @@ int main (int argc, char **argv) {
timer->final();
socket_final();
DB->final();
- mempool_final();
rathread_final();
#endif
diff --git a/src/common/db.h b/src/common/db.h
index b9d6af382..5f4478909 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -1121,8 +1121,10 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
#define VECTOR_ENSURE(__vec,__n,__step) \
do{ \
size_t _empty_ = VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec); \
- while( (__n) > _empty_ ) _empty_ += (__step); \
- if( _empty_ != VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec) ) VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec)); \
+ if( (__n) > _empty_ ) { \
+ while( (__n) > _empty_ ) _empty_ += (__step); \
+ VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec)); \
+ } \
}while(0)
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 77b976926..57e8a5187 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -8,6 +8,7 @@
#include "../common/showmsg.h"
#include "../common/strlib.h"
#include "../common/utils.h"
+#include "../common/nullpo.h"
#include "grfio.h"
#include <stdio.h>
@@ -305,17 +306,21 @@ static FILELIST* filelist_find(const char* fname)
// returns the original file name
char* grfio_find_file(const char* fname)
{
- FILELIST *filelist = filelist_find(fname);
- if (!filelist) return NULL;
- return (!filelist->fnd ? filelist->fn : filelist->fnd);
+ FILELIST *flist = filelist_find(fname);
+ if (!flist) return NULL;
+ return (!flist->fnd ? flist->fn : flist->fnd);
}
// adds a FILELIST entry into the list of loaded files
-static FILELIST* filelist_add(FILELIST* entry)
-{
+static FILELIST* filelist_add(FILELIST* entry) {
int hash;
+ nullpo_ret(entry);
+#ifdef __clang_analyzer__
+ // Make clang's static analyzer shut up about a possible NULL pointer in &filelist[filelist_entrys]
+ nullpo_ret(&filelist[filelist_entrys]);
+#endif // __clang_analyzer__
- #define FILELIST_ADDS 1024 // number increment of file lists `
+#define FILELIST_ADDS 1024 // number increment of file lists `
if (filelist_entrys >= filelist_maxentry) {
filelist = (FILELIST *)aRealloc(filelist, (filelist_maxentry + FILELIST_ADDS) * sizeof(FILELIST));
@@ -323,7 +328,9 @@ static FILELIST* filelist_add(FILELIST* entry)
filelist_maxentry += FILELIST_ADDS;
}
- memcpy (&filelist[filelist_entrys], entry, sizeof(FILELIST));
+#undef FILELIST_ADDS
+
+ memcpy(&filelist[filelist_entrys], entry, sizeof(FILELIST));
hash = filehash(entry->fn);
filelist[filelist_entrys].next = filelist_hash[hash];
@@ -405,7 +412,7 @@ void* grfio_reads(const char* fname, int* size)
if( in != NULL ) {
int declen;
fseek(in,0,SEEK_END);
- declen = ftell(in);
+ declen = (int)ftell(in);
fseek(in,0,SEEK_SET);
buf2 = (unsigned char *)aMalloc(declen+1); // +1 for resnametable zero-termination
if(fread(buf2, 1, declen, in) != (size_t)declen) ShowError("An error occured in fread grfio_reads, fname=%s \n",fname);
diff --git a/src/common/malloc.c b/src/common/malloc.c
index 1cb7836ab..23e28a65f 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -669,7 +669,7 @@ void memmgr_report (int extra) {
struct {
const char *file;
unsigned short line;
- unsigned int size;
+ size_t size;
unsigned int count;
} data[100];
memset(&data, 0, sizeof(data));
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 47257265f..b33b01fa7 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -284,7 +284,8 @@ struct accreg {
// For saving status changes across sessions. [Skotlex]
struct status_change_data {
unsigned short type; //SC_type
- long val1, val2, val3, val4, tick; //Remaining duration.
+ int val1, val2, val3, val4;
+ unsigned int tick; //Remaining duration.
};
struct storage_data {
diff --git a/src/common/nullpo.c b/src/common/nullpo.c
index 4383109a7..20180dd3b 100644
--- a/src/common/nullpo.c
+++ b/src/common/nullpo.c
@@ -4,88 +4,26 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
-#include "nullpo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
-// #include "logs.h" // 布石してみる
-static void nullpo_info_core(const char *file, int line, const char *func,
- const char *fmt, va_list ap);
-
-/*======================================
- * Nullチェック 及び 情報出力
- *--------------------------------------*/
-int nullpo_chk_f(const char *file, int line, const char *func, const void *target,
- const char *fmt, ...)
-{
- va_list ap;
-
- if (target != NULL)
- return 0;
-
- va_start(ap, fmt);
- nullpo_info_core(file, line, func, fmt, ap);
- va_end(ap);
- return 1;
-}
-
-int nullpo_chk(const char *file, int line, const char *func, const void *target)
-{
- if (target != NULL)
- return 0;
-
- nullpo_info_core(file, line, func, NULL, NULL);
- return 1;
-}
-
-
-/*======================================
- * nullpo情報出力(外部呼出し向けラッパ)
- *--------------------------------------*/
-void nullpo_info_f(const char *file, int line, const char *func,
- const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- nullpo_info_core(file, line, func, fmt, ap);
- va_end(ap);
-}
-
-void nullpo_info(const char *file, int line, const char *func)
-{
- nullpo_info_core(file, line, func, NULL, NULL);
-}
-
-
-/*======================================
- * nullpo情報出力(Main)
- *--------------------------------------*/
-static void nullpo_info_core(const char *file, int line, const char *func,
- const char *fmt, va_list ap)
-{
+/**
+ * Reports failed assertions or NULL pointers
+ *
+ * @param file Source file where the error was detected
+ * @param line Line
+ * @param func Function
+ * @param targetname Name of the checked symbol
+ * @param title Message title to display (i.e. failed assertion or nullpo info)
+ */
+void assert_report(const char *file, int line, const char *func, const char *targetname, const char *title) {
if (file == NULL)
file = "??";
- func =
- func == NULL ? "unknown":
- func[0] == '\0' ? "unknown":
- func;
-
- ShowMessage("--- nullpo info --------------------------------------------\n");
- ShowMessage("%s:%d: in func `%s'\n", file, line, func);
- if (fmt != NULL)
- {
- if (fmt[0] != '\0')
- {
- vprintf(fmt, ap);
-
- // 最後に改行したか確認
- if (fmt[strlen(fmt)-1] != '\n')
- ShowMessage("\n");
- }
- }
- ShowMessage("--- end nullpo info ----------------------------------------\n");
+ if (func == NULL || *func == '\0')
+ func = "unknown";
- // ここらでnullpoログをファイルに書き出せたら
- // まとめて提出できるなと思っていたり。
+ ShowError("--- %s --------------------------------------------\n", title);
+ ShowError("%s:%d: '%s' in function `%s'\n", file, line, targetname, func);
+ ShowError("--- end %s ----------------------------------------\n", title);
}
diff --git a/src/common/nullpo.h b/src/common/nullpo.h
index 8ee86a782..ae39b1151 100644
--- a/src/common/nullpo.h
+++ b/src/common/nullpo.h
@@ -1,225 +1,127 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _NULLPO_H_
-#define _NULLPO_H_
-
+#ifndef COMMON_NULLPO_H
+#define COMMON_NULLPO_H
#include "../common/cbasetypes.h"
-#define NLP_MARK __FILE__, __LINE__, __func__
-
// enabled by default on debug builds
#if defined(DEBUG) && !defined(NULLPO_CHECK)
#define NULLPO_CHECK
#endif
-/*----------------------------------------------------------------------------
- * Macros
- *----------------------------------------------------------------------------
- */
-/*======================================
- * Nullチェック 及び 情報出力後 return
- *・展開するとifとかreturn等が出るので
- * 一行単体で使ってください。
- *・nullpo_ret(x = func());
- * のような使用法も想定しています。
- *--------------------------------------
- * nullpo_ret(t)
- * 戻り値 0固定
- * [引数]
- * t チェック対象
- *--------------------------------------
- * nullpo_retv(t)
- * 戻り値 なし
- * [引数]
- * t チェック対象
- *--------------------------------------
- * nullpo_retr(ret, t)
- * 戻り値 指定
- * [引数]
- * ret return(ret);
- * t チェック対象
- *--------------------------------------
- * nullpo_ret_f(t, fmt, ...)
- * 詳細情報出力用
- * 戻り値 0
- * [引数]
- * t チェック対象
- * fmt ... vprintfに渡される
- * 備考や関係変数の書き出しなどに
- *--------------------------------------
- * nullpo_retv_f(t, fmt, ...)
- * 詳細情報出力用
- * 戻り値 なし
- * [引数]
- * t チェック対象
- * fmt ... vprintfに渡される
- * 備考や関係変数の書き出しなどに
- *--------------------------------------
- * nullpo_retr_f(ret, t, fmt, ...)
- * 詳細情報出力用
- * 戻り値 指定
- * [引数]
- * ret return(ret);
- * t チェック対象
- * fmt ... vprintfに渡される
- * 備考や関係変数の書き出しなどに
- *--------------------------------------
- */
+// Skip assert checks on release builds
+#if !defined(RELEASE) && !defined(ASSERT_CHECK)
+#define ASSERT_CHECK
+#endif
+
+/** Assert */
+
+#if defined(ASSERT_CHECK)
+// extern "C" {
+#include <assert.h>
+// }
+#if !defined(DEFCPP) && defined(WIN32) && !defined(MINGW)
+#include <crtdbg.h>
+#endif // !DEFCPP && WIN && !MINGW
+#define Assert(EX) assert(EX)
+#define Assert_chk(EX) ( (EX) ? false : (assert_report(__FILE__, __LINE__, __func__, #EX, "failed assertion"), true) )
+#else // ! ASSERT_CHECK
+#define Assert(EX) (EX)
+#define Assert_chk(EX) ((EX), false)
+#endif // ASSERT_CHECK
#if defined(NULLPO_CHECK)
+/**
+ * Reports NULL pointer information if the passed pointer is NULL
+ *
+ * @param t pointer to check
+ * @return true if the passed pointer is NULL, false otherwise
+ */
+#define nullpo_chk(t) ( (t) != NULL ? false : (assert_report(__FILE__, __LINE__, __func__, #t, "nullpo info"), true) )
+#else // ! NULLPO_CHECK
+#define nullpo_chk(t) ((t), false)
+#endif // NULLPO_CHECK
+
+/**
+ * The following macros check for NULL pointers and return from the current
+ * function or block in case one is found.
+ *
+ * It is guaranteed that the argument is evaluated once and only once, so it
+ * is safe to call them as:
+ * nullpo_ret(x = func());
+ * The macros can be used safely in any context, as they expand to a do/while
+ * construct, except nullpo_retb, which expands to an if/else construct.
+ */
+/**
+ * Returns 0 if a NULL pointer is found.
+ *
+ * @param t pointer to check
+ */
#define nullpo_ret(t) \
- if (nullpo_chk(NLP_MARK, (void *)(t))) {return(0);}
-
-#define nullpo_retv(t) \
- if (nullpo_chk(NLP_MARK, (void *)(t))) {return;}
-
-#define nullpo_retr(ret, t) \
- if (nullpo_chk(NLP_MARK, (void *)(t))) {return(ret);}
-
-#define nullpo_retb(t) \
- if (nullpo_chk(NLP_MARK, (void *)(t))) {break;}
-
-// 可変引数マクロに関する条件コンパイル
-#if __STDC_VERSION__ >= 199901L
-/* C99に対応 */
-#define nullpo_ret_f(t, fmt, ...) \
- if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return(0);}
-
-#define nullpo_retv_f(t, fmt, ...) \
- if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return;}
-
-#define nullpo_retr_f(ret, t, fmt, ...) \
- if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return(ret);}
-
-#define nullpo_retb_f(t, fmt, ...) \
- if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {break;}
+ do { if (nullpo_chk(t)) return(0); } while(0)
-#elif __GNUC__ >= 2
-/* GCC用 */
-#define nullpo_ret_f(t, fmt, args...) \
- if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return(0);}
-
-#define nullpo_retv_f(t, fmt, args...) \
- if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return;}
-
-#define nullpo_retr_f(ret, t, fmt, args...) \
- if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return(ret);}
-
-#define nullpo_retb_f(t, fmt, args...) \
- if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {break;}
-
-#else
-
-/* その他の場合・・・ orz */
-
-#endif
-
-#else /* NULLPO_CHECK */
-/* No Nullpo check */
-
-// if((t)){;}
-// 良い方法が思いつかなかったので・・・苦肉の策です。
-// 一応ワーニングは出ないはず
-
-#define nullpo_ret(t) (void)(t)
-#define nullpo_retv(t) (void)(t)
-#define nullpo_retr(ret, t) (void)(t)
-#define nullpo_retb(t) (void)(t)
-
-// 可変引数マクロに関する条件コンパイル
-#if __STDC_VERSION__ >= 199901L
-/* C99に対応 */
-#define nullpo_ret_f(t, fmt, ...) (void)(t)
-#define nullpo_retv_f(t, fmt, ...) (void)(t)
-#define nullpo_retr_f(ret, t, fmt, ...) (void)(t)
-#define nullpo_retb_f(t, fmt, ...) (void)(t)
-
-#elif __GNUC__ >= 2
-/* GCC用 */
-#define nullpo_ret_f(t, fmt, args...) (void)(t)
-#define nullpo_retv_f(t, fmt, args...) (void)(t)
-#define nullpo_retr_f(ret, t, fmt, args...) (void)(t)
-#define nullpo_retb_f(t, fmt, args...) (void)(t)
-
-#else
-/* その他の場合・・・ orz */
-#endif
+/**
+ * Returns 0 if the given assertion fails.
+ *
+ * @param t statement to check
+ */
+#define Assert_ret(t) \
+ do { if (Assert_chk(t)) return(0); } while(0)
-#endif /* NULLPO_CHECK */
+/**
+ * Returns void if a NULL pointer is found.
+ *
+ * @param t pointer to check
+ */
+#define nullpo_retv(t) \
+ do { if (nullpo_chk(t)) return; } while(0)
-/*----------------------------------------------------------------------------
- * Functions
- *----------------------------------------------------------------------------
+/**
+ * Returns void if the given assertion fails.
+ *
+ * @param t statement to check
*/
-/*======================================
- * nullpo_chk
- * Nullチェック 及び 情報出力
- * [引数]
- * file __FILE__
- * line __LINE__
- * func __func__ (関数名)
- * これらには NLP_MARK を使うとよい
- * target チェック対象
- * [返り値]
- * 0 OK
- * 1 NULL
- *--------------------------------------
+#define Assert_retv(t) \
+ do { if (Assert_chk(t)) return; } while(0)
+
+/**
+ * Returns the given value if a NULL pointer is found.
+ *
+ * @param ret value to return
+ * @param t pointer to check
*/
-int nullpo_chk(const char *file, int line, const char *func, const void *target);
-
-
-/*======================================
- * nullpo_chk_f
- * Nullチェック 及び 詳細な情報出力
- * [引数]
- * file __FILE__
- * line __LINE__
- * func __func__ (関数名)
- * これらには NLP_MARK を使うとよい
- * target チェック対象
- * fmt ... vprintfに渡される
- * 備考や関係変数の書き出しなどに
- * [返り値]
- * 0 OK
- * 1 NULL
- *--------------------------------------
+#define nullpo_retr(ret, t) \
+ do { if (nullpo_chk(t)) return(ret); } while(0)
+
+/**
+ * Returns the given value if the given assertion fails.
+ *
+ * @param ret value to return
+ * @param t statement to check
*/
-int nullpo_chk_f(const char *file, int line, const char *func, const void *target,
- const char *fmt, ...)
- __attribute__((format(printf,5,6)));
-
-
-/*======================================
- * nullpo_info
- * nullpo情報出力
- * [引数]
- * file __FILE__
- * line __LINE__
- * func __func__ (関数名)
- * これらには NLP_MARK を使うとよい
- *--------------------------------------
+#define Assert_retr(ret, t) \
+ do { if (Assert_chk(t)) return(ret); } while(0)
+
+/**
+ * Breaks from the current loop/switch if a NULL pointer is found.
+ *
+ * @param t pointer to check
*/
-void nullpo_info(const char *file, int line, const char *func);
-
-
-/*======================================
- * nullpo_info_f
- * nullpo詳細情報出力
- * [引数]
- * file __FILE__
- * line __LINE__
- * func __func__ (関数名)
- * これらには NLP_MARK を使うとよい
- * fmt ... vprintfに渡される
- * 備考や関係変数の書き出しなどに
- *--------------------------------------
+#define nullpo_retb(t) \
+ if (nullpo_chk(t)) break; else (void)0
+
+/**
+ * Breaks from the current loop/switch if the given assertion fails.
+ *
+ * @param t statement to check
*/
-void nullpo_info_f(const char *file, int line, const char *func,
- const char *fmt, ...)
- __attribute__((format(printf,4,5)));
+#define Assert_retb(t) \
+ if (Assert_chk(t)) break; else (void)0
+
+void assert_report(const char *file, int line, const char *func, const char *targetname, const char *title);
-#endif /* _NULLPO_H_ */
+#endif /* COMMON_NULLPO_H */
diff --git a/src/common/socket.c b/src/common/socket.c
index 2ae9d44b3..9c6938008 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -340,7 +340,7 @@ void set_eof(int fd)
int recv_to_fifo(int fd)
{
- int len;
+ ssize_t len;
if( !session_isActive(fd) )
return -1;
@@ -377,7 +377,7 @@ int recv_to_fifo(int fd)
int send_from_fifo(int fd)
{
- int len;
+ ssize_t len;
if( !session_isValid(fd) )
return -1;
@@ -855,6 +855,10 @@ int do_sockets(int next)
}
}
+#ifdef __clang_analyzer__
+ // Let Clang's static analyzer know this never happens (it thinks it might because of a NULL check in session_isValid)
+ if (!session[i]) continue;
+#endif // __clang_analyzer__
session[i]->func_parse(i);
if(!session[i])
@@ -1330,7 +1334,7 @@ int socket_getips(uint32* ips, int max)
void socket_init(void)
{
char *SOCKET_CONF_FILENAME = "conf/packet.conf";
- unsigned int rlim_cur = FD_SETSIZE;
+ uint64 rlim_cur = FD_SETSIZE;
#ifdef WIN32
{// Start up windows networking
@@ -1403,7 +1407,7 @@ void socket_init(void)
timer->add_interval(timer->gettick()+1000, connect_check_clear, 0, 0, 5*60*1000);
#endif
- ShowInfo("Server supports up to '"CL_WHITE"%u"CL_RESET"' concurrent connections.\n", rlim_cur);
+ ShowInfo("Server supports up to '"CL_WHITE"%lld"CL_RESET"' concurrent connections.\n", rlim_cur);
/* Hercules Plugin Manager */
HPM->share(session,"session");
diff --git a/src/common/sql.c b/src/common/sql.c
index 0e06d6d18..79ccc8e92 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -1036,7 +1036,7 @@ void Sql_HerculesUpdateCheck(Sql* self) {
fseek (ufp,1,SEEK_SET);/* woo. skip the # */
if( fgets(timestamp,sizeof(timestamp),ufp) ) {
- unsigned int timestampui = atol(timestamp);
+ unsigned int timestampui = (unsigned int)atol(timestamp);
if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) )
Sql_ShowDebug(self);
if( Sql_NumRows(self) != 1 ) {
@@ -1079,7 +1079,7 @@ void Sql_HerculesUpdateSkip(Sql* self,const char *filename) {
fseek (ifp,1,SEEK_SET);/* woo. skip the # */
if( fgets(timestamp,sizeof(timestamp),ifp) ) {
- unsigned int timestampui = atol(timestamp);
+ unsigned int timestampui = (unsigned int)atol(timestamp);
if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) )
Sql_ShowDebug(self);
else if( Sql_NumRows(self) == 1 ) {
diff --git a/src/common/strlib.c b/src/common/strlib.c
index e45cb0789..0f68eb206 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -952,7 +952,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
continue;
- columns = sv_split(line, strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
+ columns = sv_split(line, (int)strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
if( columns < mincols ) {
ShowError("sv_readdb: Insufficient columns in line %d of \"%s\" (found %d, need at least %d).\n", lines, path, columns, mincols);
@@ -1018,7 +1018,8 @@ int StringBuf_Printf(StringBuf* self, const char* fmt, ...) {
/// Appends the result of vprintf to the StringBuf
int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) {
- int n, size, off;
+ int n, off;
+ size_t size;
for(;;) {
va_list apcopy;
@@ -1028,7 +1029,7 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) {
n = vsnprintf(self->ptr_, size, fmt, apcopy);
va_end(apcopy);
/* If that worked, return the length. */
- if( n > -1 && n < size ) {
+ if( n > -1 && (size_t)n < size ) {
self->ptr_ += n;
return (int)(self->ptr_ - self->buf_);
}
@@ -1042,11 +1043,11 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) {
/// Appends the contents of another StringBuf to the StringBuf
int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) {
- int available = self->max_ - (self->ptr_ - self->buf_);
- int needed = (int)(sbuf->ptr_ - sbuf->buf_);
+ size_t available = self->max_ - (self->ptr_ - self->buf_);
+ size_t needed = sbuf->ptr_ - sbuf->buf_;
if( needed >= available ) {
- int off = (int)(self->ptr_ - self->buf_);
+ size_t off = (self->ptr_ - self->buf_);
self->max_ += needed;
self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1);
self->ptr_ = self->buf_ + off;
@@ -1059,12 +1060,12 @@ int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) {
// Appends str to the StringBuf
int StringBuf_AppendStr(StringBuf* self, const char* str) {
- int available = self->max_ - (self->ptr_ - self->buf_);
- int needed = (int)strlen(str);
+ size_t available = self->max_ - (self->ptr_ - self->buf_);
+ size_t needed = strlen(str);
if( needed >= available ) {
// not enough space, expand the buffer (minimum expansion = 1024)
- int off = (int)(self->ptr_ - self->buf_);
+ size_t off = (self->ptr_ - self->buf_);
self->max_ += max(needed, 1024);
self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1);
self->ptr_ = self->buf_ + off;
diff --git a/src/common/timer.c b/src/common/timer.c
index e5cf5df2a..7f9e20dad 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -142,7 +142,7 @@ static void rdtsc_calibrate(){
* platform-abstracted tick retrieval
* @return server's current tick
*/
-static int64 tick(void) {
+static int64 sys_tick(void) {
#if defined(WIN32)
// Windows: GetTickCount/GetTickCount64: Return the number of
// milliseconds that have elapsed since the system was started.
@@ -206,7 +206,7 @@ static int gettick_count = 1;
int64 timer_gettick_nocache(void) {
gettick_count = TICK_CACHE;
- gettick_cache = tick();
+ gettick_cache = sys_tick();
return gettick_cache;
}
@@ -219,11 +219,11 @@ int64 timer_gettick(void) {
// tick doesn't get cached
int64 timer_gettick_nocache(void)
{
- return tick();
+ return sys_tick();
}
int64 timer_gettick(void) {
- return tick();
+ return sys_tick();
}
//////////////////////////////////////////////////////////////////////////
#endif
diff --git a/src/config/renewal.h b/src/config/renewal.h
index a7fd22c37..3b11aff74 100644
--- a/src/config/renewal.h
+++ b/src/config/renewal.h
@@ -13,6 +13,7 @@
* @INFO: This file holds general-purpose renewal settings, for class-specific ones check /src/config/classes folder
**/
+//#define DISABLE_RENEWAL
#ifndef DISABLE_RENEWAL
/// game renewal server mode
diff --git a/src/login/account_sql.c b/src/login/account_sql.c
index 533b3d860..283eb3a0d 100644
--- a/src/login/account_sql.c
+++ b/src/login/account_sql.c
@@ -543,16 +543,16 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc
SQL->GetData(sql_handle, 3, &data, NULL); acc->sex = data[0];
SQL->GetData(sql_handle, 4, &data, NULL); safestrncpy(acc->email, data, sizeof(acc->email));
SQL->GetData(sql_handle, 5, &data, NULL); acc->group_id = atoi(data);
- SQL->GetData(sql_handle, 6, &data, NULL); acc->state = strtoul(data, NULL, 10);
+ SQL->GetData(sql_handle, 6, &data, NULL); acc->state = (unsigned int)strtoul(data, NULL, 10);
SQL->GetData(sql_handle, 7, &data, NULL); acc->unban_time = atol(data);
SQL->GetData(sql_handle, 8, &data, NULL); acc->expiration_time = atol(data);
- SQL->GetData(sql_handle, 9, &data, NULL); acc->logincount = strtoul(data, NULL, 10);
+ SQL->GetData(sql_handle, 9, &data, NULL); acc->logincount = (unsigned int)strtoul(data, NULL, 10);
SQL->GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data, sizeof(acc->lastlogin));
SQL->GetData(sql_handle, 11, &data, NULL); safestrncpy(acc->last_ip, data, sizeof(acc->last_ip));
SQL->GetData(sql_handle, 12, &data, NULL); safestrncpy(acc->birthdate, data, sizeof(acc->birthdate));
SQL->GetData(sql_handle, 13, &data, NULL); acc->char_slots = (uint8)atoi(data);
SQL->GetData(sql_handle, 14, &data, NULL); safestrncpy(acc->pincode, data, sizeof(acc->pincode));
- SQL->GetData(sql_handle, 15, &data, NULL); acc->pincode_change = atol(data);
+ SQL->GetData(sql_handle, 15, &data, NULL); acc->pincode_change = (unsigned int)atol(data);
SQL->FreeResult(sql_handle);
@@ -568,7 +568,6 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc
while( SQL_SUCCESS == SQL->NextRow(sql_handle) )
{
- char* data;
SQL->GetData(sql_handle, 0, &data, NULL); safestrncpy(acc->account_reg2[i].str, data, sizeof(acc->account_reg2[i].str));
SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->account_reg2[i].value, data, sizeof(acc->account_reg2[i].value));
++i;
diff --git a/src/login/login.c b/src/login/login.c
index 75247845d..feed7239b 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -140,8 +140,8 @@ static int waiting_disconnect_timer(int tid, int64 tick, int id, intptr_t data)
static int online_db_setoffline(DBKey key, DBData *data, va_list ap)
{
struct online_login_data* p = DB->data2ptr(data);
- int server = va_arg(ap, int);
- if( server == -1 )
+ int server_id = va_arg(ap, int);
+ if( server_id == -1 )
{
p->char_server = -1;
if( p->waiting_disconnect != INVALID_TIMER )
@@ -150,7 +150,7 @@ static int online_db_setoffline(DBKey key, DBData *data, va_list ap)
p->waiting_disconnect = INVALID_TIMER;
}
}
- else if( p->char_server == server )
+ else if( p->char_server == server_id )
p->char_server = -2; //Char server disconnected.
return 0;
}
@@ -948,7 +948,7 @@ int mmo_auth_new(const char* userid, const char* pass, const char sex, const cha
//-----------------------------------------------------
int mmo_auth(struct login_session_data* sd, bool isServer) {
struct mmo_account acc;
- int len;
+ size_t len;
char ip[16];
ip2str(session[sd->fd]->client_addr, ip);
@@ -1615,7 +1615,7 @@ int login_config_read(const char* cfgName)
else if(!strcmpi(w1, "check_client_version"))
login_config.check_client_version = (bool)config_switch(w2);
else if(!strcmpi(w1, "client_version_to_connect"))
- login_config.client_version_to_connect = strtoul(w2, NULL, 10);
+ login_config.client_version_to_connect = (unsigned int)strtoul(w2, NULL, 10);
else if(!strcmpi(w1, "use_MD5_passwords"))
login_config.use_md5_passwds = (bool)config_switch(w2);
else if(!strcmpi(w1, "group_id_to_connect"))
diff --git a/src/login/login.h b/src/login/login.h
index 15edb14dc..494912698 100644
--- a/src/login/login.h
+++ b/src/login/login.h
@@ -23,8 +23,8 @@ enum E_LOGINSERVER_ST
struct login_session_data {
int account_id;
- long login_id1;
- long login_id2;
+ int login_id1;
+ int login_id2;
char sex;// 'F','M','S'
char userid[NAME_LENGTH];
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 9d01b2b37..51c447ed9 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -993,7 +993,7 @@ ACMD(alive)
*------------------------------------------*/
ACMD(kami)
{
- unsigned long color=0;
+ unsigned int color=0;
memset(atcmd_output, '\0', sizeof(atcmd_output));
@@ -1009,7 +1009,7 @@ ACMD(kami)
else
intif->broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(info->command + 4) == 'b' || *(info->command + 4) == 'B') ? BC_BLUE : BC_YELLOW);
} else {
- if(!message || !*message || (sscanf(message, "%lx %199[^\n]", &color, atcmd_output) < 2)) {
+ if(!message || !*message || (sscanf(message, "%u %199[^\n]", &color, atcmd_output) < 2)) {
clif->message(fd, msg_txt(981)); // Please enter color and message (usage: @kamic <color> <message>).
return false;
}
@@ -4278,9 +4278,9 @@ char* txt_time(unsigned int duration)
else
tlen += sprintf(tlen + temp1, msg_txt(224), minutes); // %d minutes
if (seconds == 1)
- tlen += sprintf(tlen + temp1, msg_txt(225), seconds); // and %d second
+ sprintf(tlen + temp1, msg_txt(225), seconds); // and %d second
else if (seconds > 1)
- tlen += sprintf(tlen + temp1, msg_txt(226), seconds); // and %d seconds
+ sprintf(tlen + temp1, msg_txt(226), seconds); // and %d seconds
return temp1;
}
@@ -5200,7 +5200,8 @@ ACMD(clearcart)
#define MAX_SKILLID_PARTIAL_RESULTS 5
#define MAX_SKILLID_PARTIAL_RESULTS_LEN 74 /* "skill " (6) + "%d:" (up to 5) + "%s" (up to 30) + " (%s)" (up to 33) */
ACMD(skillid) {
- int skillen, idx, i, found = 0;
+ int idx, i, found = 0;
+ size_t skillen;
DBIterator* iter;
DBKey key;
DBData *data;
@@ -6061,7 +6062,7 @@ ACMD(npctalk)
char name[NAME_LENGTH],mes[100],temp[100];
struct npc_data *nd;
bool ifcolor=(*(info->command + 7) != 'c' && *(info->command + 7) != 'C')?0:1;
- unsigned long color=0;
+ unsigned int color = 0;
if (sd->sc.count && //no "chatting" while muted.
(sd->sc.data[SC_BERSERK] || sd->sc.data[SC_DEEP_SLEEP] ||
@@ -6075,7 +6076,7 @@ ACMD(npctalk)
}
}
else {
- if (!message || !*message || sscanf(message, "%lx %23[^,], %99[^\n]", &color, name, mes) < 3) {
+ if (!message || !*message || sscanf(message, "%u %23[^,], %99[^\n]", &color, name, mes) < 3) {
clif->message(fd, msg_txt(1223)); // Please enter the correct parameters (usage: @npctalkc <color> <npc name>, <message>).
return false;
}
@@ -8286,7 +8287,7 @@ void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommand
clif->message(fd, msg_txt(273)); // "Commands available:"
for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
- unsigned int slen = 0;
+ size_t slen;
switch( type ) {
case COMMAND_CHARCOMMAND:
@@ -8384,8 +8385,9 @@ ACMD(accinfo) {
ACMD(set) {
char reg[32], val[128];
struct script_data* data;
- int toset = 0, len;
+ int toset = 0;
bool is_str = false;
+ size_t len;
if( !message || !*message || (toset = sscanf(message, "%31s %128[^\n]s", reg, val)) < 1 ) {
clif->message(fd, msg_txt(1367)); // Usage: @set <variable name> <value>
@@ -8746,16 +8748,16 @@ static inline void atcmd_channel_help(int fd, const char *command, bool can_crea
/* [Ind/Hercules] */
ACMD(channel) {
struct hChSysCh *channel;
- char key[HCHSYS_NAME_LENGTH], sub1[HCHSYS_NAME_LENGTH], sub2[HCHSYS_NAME_LENGTH], sub3[HCHSYS_NAME_LENGTH];
+ char subcmd[HCHSYS_NAME_LENGTH], sub1[HCHSYS_NAME_LENGTH], sub2[HCHSYS_NAME_LENGTH], sub3[HCHSYS_NAME_LENGTH];
unsigned char k = 0;
sub1[0] = sub2[0] = sub3[0] = '\0';
- if( !message || !*message || sscanf(message, "%s %s %s %s", key, sub1, sub2, sub3) < 1 ) {
+ if( !message || !*message || sscanf(message, "%s %s %s %s", subcmd, sub1, sub2, sub3) < 1 ) {
atcmd_channel_help(fd,command,( hChSys.allow_user_channel_creation || pc->has_permission(sd, PC_PERM_HCHSYS_ADMIN) ));
return true;
}
- if( strcmpi(key,"create") == 0 && ( hChSys.allow_user_channel_creation || pc->has_permission(sd, PC_PERM_HCHSYS_ADMIN) ) ) {
+ if( strcmpi(subcmd,"create") == 0 && ( hChSys.allow_user_channel_creation || pc->has_permission(sd, PC_PERM_HCHSYS_ADMIN) ) ) {
if( sub1[0] != '#' ) {
clif->message(fd, msg_txt(1405));// Channel name must start with a '#'
return false;
@@ -8787,7 +8789,7 @@ ACMD(channel) {
clif->chsys_join(channel,sd);
- } else if ( strcmpi(key,"list") == 0 ) {
+ } else if ( strcmpi(subcmd,"list") == 0 ) {
if( sub1[0] != '\0' && strcmpi(sub1,"colors") == 0 ) {
char mout[40];
for( k = 0; k < hChSys.colors_count; k++ ) {
@@ -8824,7 +8826,7 @@ ACMD(channel) {
}
dbi_destroy(iter);
}
- } else if ( strcmpi(key,"setcolor") == 0 ) {
+ } else if ( strcmpi(subcmd,"setcolor") == 0 ) {
if( sub1[0] != '#' ) {
clif->message(fd, msg_txt(1405));// Channel name must start with a '#'
@@ -8855,7 +8857,7 @@ ACMD(channel) {
channel->color = k;
sprintf(atcmd_output, msg_txt(1413),sub1,hChSys.colors_name[k]);// '%s' channel color updated to '%s'
clif->message(fd, atcmd_output);
- } else if ( strcmpi(key,"leave") == 0 ) {
+ } else if ( strcmpi(subcmd,"leave") == 0 ) {
if( sub1[0] != '#' ) {
clif->message(fd, msg_txt(1405));// Channel name must start with a '#'
@@ -8883,7 +8885,7 @@ ACMD(channel) {
clif->chsys_left(sd->channels[k],sd);
sprintf(atcmd_output, msg_txt(1426),sub1); // You've left the '%s' channel
clif->message(fd, atcmd_output);
- } else if ( strcmpi(key,"bindto") == 0 ) {
+ } else if ( strcmpi(subcmd,"bindto") == 0 ) {
if( sub1[0] != '#' ) {
clif->message(fd, msg_txt(1405));// Channel name must start with a '#'
@@ -8903,7 +8905,7 @@ ACMD(channel) {
sd->gcbind = sd->channels[k];
sprintf(atcmd_output, msg_txt(1431),sub1); // Your global chat is now binded to the '%s' channel
clif->message(fd, atcmd_output);
- } else if ( strcmpi(key,"unbind") == 0 ) {
+ } else if ( strcmpi(subcmd,"unbind") == 0 ) {
if( sd->gcbind == NULL ) {
clif->message(fd, msg_txt(1432));// Your global chat is not binded to any channel
@@ -8914,7 +8916,7 @@ ACMD(channel) {
clif->message(fd, atcmd_output);
sd->gcbind = NULL;
- } else if ( strcmpi(key,"ban") == 0 ) {
+ } else if ( strcmpi(subcmd,"ban") == 0 ) {
struct map_session_data *pl_sd = NULL;
struct hChSysBanEntry *entry = NULL;
@@ -8935,7 +8937,7 @@ ACMD(channel) {
return false;
}
- if (!message || !*message || sscanf(message, "%s %s %24[^\n]", key, sub1, sub2) < 1) {
+ if (!message || !*message || sscanf(message, "%s %s %24[^\n]", subcmd, sub1, sub2) < 1) {
sprintf(atcmd_output, msg_txt(1434), sub2);// Player '%s' was not found
clif->message(fd, atcmd_output);
return false;
@@ -8971,7 +8973,7 @@ ACMD(channel) {
sprintf(atcmd_output, msg_txt(1437),pl_sd->status.name,sub1); // Player '%s' has now been banned from '%s' channel
clif->message(fd, atcmd_output);
- } else if ( strcmpi(key,"unban") == 0 ) {
+ } else if ( strcmpi(subcmd,"unban") == 0 ) {
struct map_session_data *pl_sd = NULL;
if( sub1[0] != '#' ) {
@@ -9018,7 +9020,7 @@ ACMD(channel) {
sprintf(atcmd_output, msg_txt(1441),pl_sd->status.name,sub1); // Player '%s' has now been unbanned from the '%s' channel
clif->message(fd, atcmd_output);
- } else if ( strcmpi(key,"unbanall") == 0 ) {
+ } else if ( strcmpi(subcmd,"unbanall") == 0 ) {
if( sub1[0] != '#' ) {
clif->message(fd, msg_txt(1405));// Channel name must start with a '#'
return false;
@@ -9047,7 +9049,7 @@ ACMD(channel) {
sprintf(atcmd_output, msg_txt(1442),sub1); // Removed all bans from '%s' channel
clif->message(fd, atcmd_output);
- } else if ( strcmpi(key,"banlist") == 0 ) {
+ } else if ( strcmpi(subcmd,"banlist") == 0 ) {
DBIterator *iter = NULL;
DBKey key;
DBData *data;
@@ -9092,7 +9094,7 @@ ACMD(channel) {
dbi_destroy(iter);
- } else if ( strcmpi(key,"setopt") == 0 ) {
+ } else if ( strcmpi(subcmd,"setopt") == 0 ) {
const char* opt_str[3] = {
"None",
"JoinAnnounce",
@@ -9817,7 +9819,7 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message
return true;
} while(0);
}
- else if (*message == atcommand->at_symbol) {
+ else /*if (*message == atcommand->at_symbol)*/ {
//atcmd_msg is constructed above differently for charcommands
//it's copied from message if not a charcommand so it can
//pass through the rest of the code compatible with both symbols
@@ -10037,7 +10039,7 @@ void atcommand_config_read(const char* config_filename) {
else {
if( commandinfo->help == NULL ) {
const char *str = config_setting_get_string(command);
- int len = strlen(str);
+ size_t len = strlen(str);
commandinfo->help = aMalloc( len * sizeof(char) );
safestrncpy(commandinfo->help, str, len);
}
diff --git a/src/map/battle.c b/src/map/battle.c
index b3e7e6dc2..802d2ec02 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -335,11 +335,11 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d
if( atk_elem == ELE_FIRE && battle->get_current_skill(target) == GN_WALLOFTHORN ) {
struct skill_unit *su = (struct skill_unit*)target;
struct skill_unit_group *sg;
- struct block_list *src;
+ struct block_list *sgsrc;
if( !su || !su->alive
|| (sg = su->group) == NULL || sg->val3 == -1
- || (src = map->id2bl(sg->src_id)) == NULL || status->isdead(src)
+ || (sgsrc = map->id2bl(sg->src_id)) == NULL || status->isdead(sgsrc)
)
return 0;
@@ -347,7 +347,7 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d
int x,y;
x = sg->val3 >> 16;
y = sg->val3 & 0xffff;
- skill->unitsetting(src,su->group->skill_id,su->group->skill_lv,x,y,1);
+ skill->unitsetting(sgsrc,su->group->skill_id,su->group->skill_lv,x,y,1);
sg->val3 = -1;
sg->limit = DIFF_TICK32(timer->gettick(),sg->tick)+300;
}
@@ -2332,11 +2332,12 @@ int battle_calc_skillratio(int attack_type, struct block_list *src, struct block
break;
case SR_RAMPAGEBLASTER:
skillratio += 20 * skill_lv * (sd?sd->spiritball_old:5) - 100;
- if( sc && sc->data[SC_EXPLOSIONSPIRITS] ){
+ if( sc && sc->data[SC_EXPLOSIONSPIRITS] ) {
skillratio += sc->data[SC_EXPLOSIONSPIRITS]->val1 * 20;
RE_LVL_DMOD(120);
- }else
+ } else {
RE_LVL_DMOD(150);
+ }
break;
case SR_KNUCKLEARROW:
if( flag&4 ){ // ATK [(Skill Level x 150) + (1000 x Target current weight / Maximum weight) + (Target Base Level x 5) x (Caster Base Level / 150)] %
@@ -2600,10 +2601,10 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
if( sc->data[SC_SAFETYWALL] && (flag&(BF_SHORT|BF_MAGIC))==BF_SHORT )
{
struct skill_unit_group* group = skill->id2group(sc->data[SC_SAFETYWALL]->val3);
- uint16 skill_id = sc->data[SC_SAFETYWALL]->val2;
+ uint16 src_skill_id = sc->data[SC_SAFETYWALL]->val2;
if (group) {
d->dmg_lv = ATK_BLOCK;
- if(skill_id == MH_STEINWAND){
+ if(src_skill_id == MH_STEINWAND){
if (--group->val2<=0)
skill->del_unitgroup(group,ALC_MARK);
return 0;
@@ -3209,11 +3210,9 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
memset(&ad,0,sizeof(ad));
memset(&flag,0,sizeof(flag));
- if(src==NULL || target==NULL)
- {
- nullpo_info(NLP_MARK);
- return ad;
- }
+ nullpo_retr(ad, src);
+ nullpo_retr(ad, target);
+
//Initial Values
ad.damage = 1;
ad.div_=skill->get_num(skill_id,skill_lv);
@@ -3521,10 +3520,8 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *
memset(&md,0,sizeof(md));
- if( src == NULL || target == NULL ){
- nullpo_info(NLP_MARK);
- return md;
- }
+ nullpo_retr(md, src);
+ nullpo_retr(md, target);
//Some initial values
md.amotion=skill->get_inf(skill_id)&INF_GROUND_SKILL?0:sstatus->amotion;
@@ -3642,12 +3639,12 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *
md.damage = 7 * md.damage / 20;
}*/
}else{
- float vitfactor = 0.0f, temp;
+ float vitfactor = 0.0f, ftemp;
if( (vitfactor=(status_get_vit(target)-120.0f)) > 0)
vitfactor = (vitfactor * (matk + atk) / 10) / status_get_vit(target);
- temp = max(0, vitfactor) + (targetVit * (matk + atk)) / 10;
- md.damage = (int64)(temp * 70 * skill_lv / 100);
+ ftemp = max(0, vitfactor) + (targetVit * (matk + atk)) / 10;
+ md.damage = (int64)(ftemp * 70 * skill_lv / 100);
}
md.damage -= totaldef;
}
@@ -3947,11 +3944,9 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list
memset(&wd,0,sizeof(wd));
memset(&flag,0,sizeof(flag));
- if(src==NULL || target==NULL)
- {
- nullpo_info(NLP_MARK);
- return wd;
- }
+ nullpo_retr(wd, src);
+ nullpo_retr(wd, target);
+
//Initial flag
flag.rh=1;
flag.weapon=1;
@@ -4559,7 +4554,7 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list
short index = sd?sd->equip_index[EQI_HAND_R]:0;
GET_NORMAL_ATTACK( (sc && sc->data[SC_MAXIMIZEPOWER]?1:0)|(sc && sc->data[SC_WEAPONPERFECT]?8:0) );
wd.damage = wd.damage * 70 / 100;
- n_ele = true;
+ //n_ele = true; // FIXME: This is has no effect if it's after GET_NORMAL_ATTACK (was this intended, or was it supposed to be put above?)
if (sd && index >= 0 &&
sd->inventory_data[index] &&
@@ -5267,6 +5262,11 @@ void battle_reflect_damage(struct block_list *target, struct block_list *src, st
delay += 100;/* gradual increase so the numbers don't clip in the client */
}
}
+
+#ifdef __clang_analyzer__
+ // Tell Clang's static analyzer that we want to += it even the value is currently unused (it'd be used if we added new checks)
+ (void)delay;
+#endif // __clang_analyzer
/* something caused reflect */
if( trdamage ) {
diff --git a/src/map/clif.c b/src/map/clif.c
index a04ac0e27..e51c59461 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -578,12 +578,12 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target
struct hQueue *queue = &script->hq[sd->bg_queue.arena->queue_id];
for( i = 0; i < queue->size; i++ ) {
- struct map_session_data * sd = NULL;
+ struct map_session_data *qsd = NULL;
- if( queue->item[i] > 0 && ( sd = map->id2sd(queue->item[i]) ) ) {
- WFIFOHEAD(sd->fd,len);
- memcpy(WFIFOP(sd->fd,0), buf, len);
- WFIFOSET(sd->fd,len);
+ if( queue->item[i] > 0 && ( qsd = map->id2sd(queue->item[i]) ) ) {
+ WFIFOHEAD(qsd->fd,len);
+ memcpy(WFIFOP(qsd->fd,0), buf, len);
+ WFIFOSET(qsd->fd,len);
}
}
}
@@ -930,6 +930,8 @@ void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enu
struct view_data* vd = status->get_viewdata(bl);
struct packet_idle_unit p;
int g_id = status->get_guild_id(bl);
+
+ nullpo_retv(bl);
#if PACKETVER < 20091103
if( !pcdb_checkid(vd->class_) ) {
@@ -1060,6 +1062,8 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) {
struct packet_spawn_unit p;
int g_id = status->get_guild_id(bl);
+ nullpo_retv(bl);
+
#if PACKETVER < 20091103
if( !pcdb_checkid(vd->class_) ) {
clif->spawn_unit2(bl,target);
@@ -1123,6 +1127,7 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) {
}
#endif
if( disguised(bl) ) {
+ nullpo_retv(sd);
if( sd->status.class_ != sd->disguise )
clif->send(&p,sizeof(p),bl,target);
#if PACKETVER >= 20091103
@@ -1146,6 +1151,8 @@ void clif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd,
struct view_data* vd = status->get_viewdata(bl);
struct packet_unit_walking p;
int g_id = status->get_guild_id(bl);
+
+ nullpo_retv(bl);
sd = BL_CAST(BL_PC, bl);
@@ -1831,7 +1838,7 @@ void clif_selllist(struct map_session_data *sd)
/// - append this text
void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes) {
int fd = sd->fd;
- int slen = strlen(mes) + 9;
+ size_t slen = strlen(mes) + 9;
sd->state.dialog = 1;
@@ -1943,7 +1950,7 @@ void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
/// TODO investigate behavior of other windows [FlavioJS]
void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes) {
int fd = sd->fd;
- int slen = strlen(mes) + 9;
+ size_t slen = strlen(mes) + 9;
struct block_list *bl = NULL;
if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = map->id2bl(npcid)) && (bl->m!=sd->bl.m ||
@@ -2714,7 +2721,7 @@ void read_channels_config(void) {
if( (colors = config_setting_get_member(settings, "colors")) != NULL ) {
int color_count = config_setting_length(colors);
- CREATE( hChSys.colors, unsigned long, color_count );
+ CREATE( hChSys.colors, unsigned int, color_count );
CREATE( hChSys.colors_name, char *, color_count );
for(i = 0; i < color_count; i++) {
config_setting_t *color = config_setting_get_elem(colors, i);
@@ -2723,7 +2730,7 @@ void read_channels_config(void) {
safestrncpy(hChSys.colors_name[i], config_setting_name(color), HCHSYS_NAME_LENGTH);
- hChSys.colors[i] = strtoul(config_setting_get_string_elem(colors,i),NULL,0);
+ hChSys.colors[i] = (unsigned int)strtoul(config_setting_get_string_elem(colors,i),NULL,0);
hChSys.colors[i] = (hChSys.colors[i] & 0x0000FF) << 16 | (hChSys.colors[i] & 0x00FF00) | (hChSys.colors[i] & 0xFF0000) >> 16;//RGB to BGR
}
hChSys.colors_count = color_count;
@@ -3141,7 +3148,7 @@ void clif_changelook(struct block_list *bl,int type,int val)
sd = BL_CAST(BL_PC, bl);
sc = status->get_sc(bl);
vd = status->get_viewdata(bl);
- //nullpo_ret(vd);
+
if( vd ) //temp hack to let Warp Portal change appearance
switch(type) {
case LOOK_WEAPON:
@@ -3250,6 +3257,7 @@ void clif_changelook(struct block_list *bl,int type,int val)
WBUFW(buf,0)=0x1d7;
WBUFL(buf,2)=bl->id;
if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
+ nullpo_retv(vd);
WBUFB(buf,6)=LOOK_WEAPON;
WBUFW(buf,7)=vd->weapon;
WBUFW(buf,9)=vd->shield;
@@ -3258,7 +3266,7 @@ void clif_changelook(struct block_list *bl,int type,int val)
WBUFL(buf,7)=val;
}
clif->send(buf,packet_len(0x1d7),bl,target);
- if( disguised(bl) && ((TBL_PC*)sd)->fontcolor ) {
+ if( disguised(bl) && sd && sd->fontcolor ) {
WBUFL(buf,2)=-bl->id;
clif->send(buf,packet_len(0x1d7),bl,SELF);
}
@@ -4696,6 +4704,7 @@ int clif_outsight(struct block_list *bl,va_list ap)
tsd = BL_CAST(BL_PC, tbl);
if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
+ nullpo_ret(bl);
switch(bl->type){
case BL_PC:
if (sd->vd.class_ != INVISIBLE_CLASS)
@@ -4728,6 +4737,7 @@ int clif_outsight(struct block_list *bl,va_list ap)
}
}
if (sd && sd->fd) { //sd is watching tbl go out of view.
+ nullpo_ret(tbl);
if (((vd=status->get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
!(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->option&OPTION_INVISIBLE)))
clif->clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
@@ -4750,6 +4760,7 @@ int clif_insight(struct block_list *bl,va_list ap)
tsd = BL_CAST(BL_PC, tbl);
if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
+ nullpo_ret(bl);
switch(bl->type) {
case BL_ITEM:
clif->getareachar_item(tsd,(struct flooritem_data*)bl);
@@ -5528,7 +5539,7 @@ void clif_displaymessage(const int fd, const char* mes) {
if( fd == -2 ) {
ShowInfo("HCP: %s\n",mes);
} else if ( fd > 0 ) {
- int len;
+ size_t len;
if ( ( len = strnlen(mes, 255) ) > 0 ) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
WFIFOHEAD(fd, 5 + len);
@@ -5554,7 +5565,7 @@ void clif_displaymessage2(const int fd, const char* mes) {
line = strtok(message, "\n");
while(line != NULL) {
// Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
- int len = strnlen(line, 255);
+ size_t len = strnlen(line, 255);
if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
if( fd == -2 ) {
@@ -5606,7 +5617,7 @@ void clif_displaymessage_sprintf(const int fd, const char* mes, ...) {
}
/// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
/// 009a <packet len>.W <message>.?B
-void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
+void clif_broadcast(struct block_list* bl, const char* mes, size_t len, int type, enum send_target target)
{
int lp = (type&BC_COLOR_MASK) ? 4 : 0;
unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
@@ -5630,7 +5641,7 @@ void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, e
*------------------------------------------*/
void clif_GlobalMessage(struct block_list* bl, const char* message) {
char buf[256];
- int len;
+ size_t len;
nullpo_retv(bl);
if(!message)
@@ -5653,7 +5664,7 @@ void clif_GlobalMessage(struct block_list* bl, const char* message) {
/// Send broadcast message with font formatting (ZC_BROADCAST2).
/// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
-void clif_broadcast2(struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
+void clif_broadcast2(struct block_list* bl, const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
{
unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
@@ -5829,7 +5840,7 @@ void clif_upgrademessage(int fd, int result, int item_id)
/// Whisper is transmitted to the destination player (ZC_WHISPER).
/// 0097 <packet len>.W <nick>.24B <message>.?B
/// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
-void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len) {
+void clif_wis_message(int fd, const char* nick, const char* mes, size_t mes_len) {
#if PACKETVER < 20091104
WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
WFIFOW(fd,0) = 0x97;
@@ -8053,14 +8064,14 @@ void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_sess
/*==========================================
*
*------------------------------------------*/
-void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len) {
+void clif_disp_onlyself(struct map_session_data *sd, const char *mes, size_t len) {
clif->disp_message(&sd->bl, mes, len, SELF);
}
/*==========================================
* Displays a message using the guild-chat colors to the specified targets. [Skotlex]
*------------------------------------------*/
-void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
+void clif_disp_message(struct block_list* src, const char* mes, size_t len, enum send_target target)
{
unsigned char buf[256];
@@ -8317,7 +8328,7 @@ void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, sen
// Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
/// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
int clif_colormes(int fd, enum clif_colors color, const char* msg) {
- unsigned short msg_len = strlen(msg) + 1;
+ size_t msg_len = strlen(msg) + 1;
WFIFOHEAD(fd,msg_len + 12);
WFIFOW(fd,0) = 0x2C1;
@@ -8332,8 +8343,8 @@ int clif_colormes(int fd, enum clif_colors color, const char* msg) {
/// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
/// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
-void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
- unsigned short msg_len = strlen(msg) + 1;
+void clif_messagecolor(struct block_list* bl, unsigned int color, const char* msg) {
+ size_t msg_len = strlen(msg) + 1;
uint8 buf[256];
color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
@@ -8657,7 +8668,7 @@ void clif_slide(struct block_list *bl, int x, int y)
void clif_disp_overhead(struct block_list *bl, const char* mes)
{
unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
- int len_mes = strlen(mes)+1; //Account for \0
+ size_t len_mes = strlen(mes)+1; //Account for \0
if (len_mes > sizeof(buf)-8) {
ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
@@ -8946,9 +8957,10 @@ void clif_viewequip_fail(struct map_session_data* sd)
/// Returns true if the packet was parsed successfully.
/// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
/// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
-bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_) {
+bool clif_process_message(struct map_session_data *sd, int format, char **name_, size_t *namelen_, char **message_, size_t *messagelen_) {
char *text, *name, *message;
- unsigned int packetlen, textlen, namelen, messagelen;
+ unsigned int packetlen, textlen;
+ size_t namelen, messagelen;
int fd = sd->fd;
*name_ = NULL;
@@ -9604,7 +9616,7 @@ void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
/// Displays cast-like progress bar (ZC_PROGRESS).
/// 02f0 <color>.L <time>.L
-void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
+void clif_progressbar(struct map_session_data * sd, unsigned int color, unsigned int second)
{
int fd = sd->fd;
@@ -9766,10 +9778,10 @@ int clif_undisguise_timer(int tid, int64 tick, int id, intptr_t data) {
void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
{
const char* text = (char*)RFIFOP(fd,4);
- int textlen = RFIFOW(fd,2) - 4;
+ size_t textlen = RFIFOW(fd,2) - 4;
char *name, *message, *fakename = NULL;
- int namelen, messagelen;
+ size_t namelen, messagelen;
bool is_fake;
@@ -10274,7 +10286,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
int i;
char *target, *message;
- int namelen, messagelen;
+ size_t namelen, messagelen;
// validate packet and retrieve name and message
if( !clif->process_message(sd, 1, &target, &namelen, &message, &messagelen) )
@@ -10354,7 +10366,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
channel = (struct hChSysCh *)g->channel;
}
if( channel || (channel = strdb_get(clif->channel_db,chname)) ) {
- unsigned char k;
+ int k;
for( k = 0; k < sd->channel_count; k++ ) {
if( sd->channels[k] == channel )
break;
@@ -10364,7 +10376,6 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
} else if( channel->pass[0] == '\0' && !(channel->banned && idb_exists(channel->banned, sd->status.account_id)) ) {
if( channel->type == hChSys_ALLY ) {
struct guild *g = sd->guild, *sg = NULL;
- int k;
for (k = 0; k < MAX_GUILDALLIANCE; k++) {
if( g->alliance[k].opposition == 0 && g->alliance[k].guild_id && (sg = guild->search(g->alliance[k].guild_id) ) ) {
if( !(((struct hChSysCh*)sg->channel)->banned && idb_exists(((struct hChSysCh*)sg->channel)->banned, sd->status.account_id)))
@@ -12097,7 +12108,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
int textlen = RFIFOW(fd,2) - 4;
char *name, *message;
- int namelen, messagelen;
+ size_t namelen, messagelen;
// validate packet and retrieve name and message
if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) )
@@ -12629,7 +12640,7 @@ void clif_PartyBookingFailedRecall(int fd, struct map_session_data *sd)
void clif_parse_PartyBookingRefuseVolunteer(int fd, struct map_session_data *sd)
{
#ifdef PARTY_RECRUIT
- unsigned long aid = RFIFOL(fd, 2);
+ unsigned int aid = RFIFOL(fd, 2);
clif->PartyBookingRefuseVolunteer(aid, sd);
#else
@@ -12638,7 +12649,7 @@ void clif_parse_PartyBookingRefuseVolunteer(int fd, struct map_session_data *sd)
}
/// 08fa <index>.L
-void clif_PartyBookingRefuseVolunteer(unsigned long aid, struct map_session_data *sd)
+void clif_PartyBookingRefuseVolunteer(unsigned int aid, struct map_session_data *sd)
{
#ifdef PARTY_RECRUIT
unsigned char buf[2+6];
@@ -13035,7 +13046,7 @@ bool clif_validate_emblem(const uint8 *emblem, unsigned long emblem_len) {
/// 0153 <packet len>.W <emblem data>.?B
void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
{
- unsigned long emblem_len = RFIFOW(fd,2)-4;
+ unsigned int emblem_len = RFIFOW(fd,2)-4;
const uint8* emblem = RFIFOP(fd,4);
if( !emblem_len || !sd->state.gmaster_flag )
@@ -13157,7 +13168,7 @@ void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
int textlen = RFIFOW(fd,2) - 4;
char *name, *message;
- int namelen, messagelen;
+ size_t namelen, messagelen;
// validate packet and retrieve name and message
if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) )
@@ -14761,7 +14772,7 @@ void clif_Mail_read(struct map_session_data *sd, int mail_id)
struct mail_message *msg = &sd->mail.inbox.msg[i];
struct item *item = &msg->item;
struct item_data *data;
- int msg_len = strlen(msg->body), len;
+ size_t msg_len = strlen(msg->body), len;
if( msg_len == 0 ) {
strcpy(msg->body, "(no message)");
@@ -16087,7 +16098,7 @@ void clif_bg_xy_remove(struct map_session_data *sd)
/// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
/// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
-void clif_bg_message(struct battleground_data *bgd, int src_id, const char *name, const char *mes, int len)
+void clif_bg_message(struct battleground_data *bgd, int src_id, const char *name, const char *mes, size_t len)
{
struct map_session_data *sd;
unsigned char *buf;
@@ -16116,7 +16127,7 @@ void clif_parse_BattleChat(int fd, struct map_session_data* sd)
int textlen = RFIFOW(fd,2) - 4;
char *name, *message;
- int namelen, messagelen;
+ size_t namelen, messagelen;
if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) )
return;
@@ -16994,7 +17005,7 @@ void clif_parse_debug(int fd,struct map_session_data *sd) {
}
ShowDebug("Packet debug of 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id);
} else {
- packet_len = RFIFOREST(fd);
+ packet_len = (int)RFIFOREST(fd);
ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
}
@@ -17602,7 +17613,7 @@ void clif_partytickack(struct map_session_data* sd, bool flag) {
void clif_ShowScript(struct block_list* bl, const char* message) {
char buf[256];
- int len;
+ size_t len;
nullpo_retv(bl);
if(!message)
@@ -18297,7 +18308,7 @@ int do_init_clif(bool minimal) {
* Setup Color Table (saves unnecessary load of strtoul on every call)
**/
for(i = 0; i < COLOR_MAX; i++) {
- color_table[i] = strtoul(colors[i],NULL,0);
+ color_table[i] = (unsigned int)strtoul(colors[i],NULL,0);
color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
}
diff --git a/src/map/clif.h b/src/map/clif.h
index 6ccd951a0..c4088893a 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -472,7 +472,7 @@ struct s_packet_db {
};
struct {
- unsigned long *colors;
+ unsigned int *colors;
char **colors_name;
unsigned char colors_count;
bool local, ally, irc;
@@ -517,7 +517,7 @@ struct cdelayed_damage {
* Vars
**/
struct s_packet_db packet_db[MAX_PACKET_DB + 1];
-unsigned long color_table[COLOR_MAX];
+unsigned int color_table[COLOR_MAX];
/**
* Clif.c Interface
@@ -706,7 +706,7 @@ struct clif_interface {
void (*equpcheckbox) (struct map_session_data* sd);
void (*displayexp) (struct map_session_data *sd, unsigned int exp, char type, bool is_quest);
void (*font) (struct map_session_data *sd);
- void (*progressbar) (struct map_session_data * sd, unsigned long color, unsigned int second);
+ void (*progressbar) (struct map_session_data * sd, unsigned int color, unsigned int second);
void (*progressbar_abort) (struct map_session_data * sd);
void (*showdigit) (struct map_session_data* sd, unsigned char type, int value);
int (*elementalconverter_list) (struct map_session_data *sd);
@@ -783,13 +783,13 @@ struct clif_interface {
void (*clearchat) (struct chat_data *cd,int fd);
void (*leavechat) (struct chat_data* cd, struct map_session_data* sd, bool flag);
void (*changechatstatus) (struct chat_data* cd);
- void (*wis_message) (int fd, const char* nick, const char* mes, int mes_len);
+ void (*wis_message) (int fd, const char* nick, const char* mes, size_t mes_len);
void (*wis_end) (int fd, int flag);
- void (*disp_onlyself) (struct map_session_data *sd, const char *mes, int len);
- void (*disp_message) (struct block_list* src, const char* mes, int len, enum send_target target);
- void (*broadcast) (struct block_list* bl, const char* mes, int len, int type, enum send_target target);
- void (*broadcast2) (struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target);
- void (*messagecolor) (struct block_list* bl, unsigned long color, const char* msg);
+ void (*disp_onlyself) (struct map_session_data *sd, const char *mes, size_t len);
+ void (*disp_message) (struct block_list* src, const char* mes, size_t len, enum send_target target);
+ void (*broadcast) (struct block_list* bl, const char* mes, size_t len, int type, enum send_target target);
+ void (*broadcast2) (struct block_list* bl, const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target);
+ void (*messagecolor) (struct block_list* bl, unsigned int color, const char* msg);
void (*disp_overhead) (struct block_list *bl, const char* mes);
void (*msg) (struct map_session_data* sd, unsigned short id);
void (*msg_value) (struct map_session_data* sd, unsigned short id, int value);
@@ -801,7 +801,7 @@ struct clif_interface {
/* message+s(printf) */
void (*messages) (const int fd, const char* mes, ...);
int (*colormes) (int fd, enum clif_colors color, const char* msg);
- bool (*process_message) (struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_);
+ bool (*process_message) (struct map_session_data *sd, int format, char **name_, size_t *namelen_, char **message_, size_t *messagelen_);
void (*wisexin) (struct map_session_data *sd,int type,int flag);
void (*wisall) (struct map_session_data *sd,int type,int flag);
void (*PMIgnoreList) (struct map_session_data* sd);
@@ -887,7 +887,7 @@ struct clif_interface {
void (*bg_hp) (struct map_session_data *sd);
void (*bg_xy) (struct map_session_data *sd);
void (*bg_xy_remove) (struct map_session_data *sd);
- void (*bg_message) (struct battleground_data *bgd, int src_id, const char *name, const char *mes, int len);
+ void (*bg_message) (struct battleground_data *bgd, int src_id, const char *name, const char *mes, size_t len);
void (*bg_updatescore) (int16 m);
void (*bg_updatescore_single) (struct map_session_data *sd);
void (*sendbgemblem_area) (struct map_session_data *sd);
@@ -970,7 +970,7 @@ struct clif_interface {
void (*PartyRecruitInsertNotify) (struct map_session_data* sd, struct party_booking_ad_info* pb_ad);
/* Group Search System Update */
void (*PartyBookingVolunteerInfo) (int index, struct map_session_data *sd);
- void (*PartyBookingRefuseVolunteer) (unsigned long aid, struct map_session_data *sd);
+ void (*PartyBookingRefuseVolunteer) (unsigned int aid, struct map_session_data *sd);
void (*PartyBookingCancelVolunteer) (int index, struct map_session_data *sd);
void (*PartyBookingAddFilteringList) (int index, struct map_session_data *sd);
void (*PartyBookingSubFilteringList) (int gid, struct map_session_data *sd);
diff --git a/src/map/guild.c b/src/map/guild.c
index 66376a2a8..8a34b7f4b 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -1594,10 +1594,10 @@ int guild_opposition(struct map_session_data *sd,struct map_session_data *tsd)
* Notification of a relationship between 2 guilds
*---------------------------------------------------*/
int guild_allianceack(int guild_id1,int guild_id2,int account_id1,int account_id2,int flag,const char *name1,const char *name2) {
- struct guild *g[2];
- int guild_id[2];
- const char *guild_name[2];
- struct map_session_data *sd[2];
+ struct guild *g[2] = { NULL };
+ int guild_id[2] = { 0 };
+ const char *guild_name[2] = { NULL };
+ struct map_session_data *sd[2] = { NULL };
int j,i;
guild_id[0] = guild_id1;
@@ -1664,11 +1664,11 @@ int guild_allianceack(int guild_id1,int guild_id2,int account_id1,int account_id
for (i = 0; i < 2 - (flag & 1); i++) { // Retransmission of the relationship list to all members
- struct map_session_data *sd;
+ struct map_session_data *msd;
if(g[i]!=NULL)
for(j=0;j<g[i]->max_member;j++)
- if((sd=g[i]->member[j].sd)!=NULL)
- clif->guild_allianceinfo(sd);
+ if((msd=g[i]->member[j].sd)!=NULL)
+ clif->guild_allianceinfo(msd);
}
return 0;
}
diff --git a/src/map/homunculus.c b/src/map/homunculus.c
index 7ab471b9d..c6fa68d7f 100644
--- a/src/map/homunculus.c
+++ b/src/map/homunculus.c
@@ -1209,7 +1209,7 @@ void homunculus_exp_db_read(void) {
if(line[0] == '/' && line[1] == '/')
continue;
- if (!(homun->exptable[j++] = strtoul(line, NULL, 10)))
+ if (!(homun->exptable[j++] = (unsigned int)strtoul(line, NULL, 10)))
break;
}
// Last permitted level have to be 0!
diff --git a/src/map/intif.c b/src/map/intif.c
index df7a16db7..75ca714c9 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -125,7 +125,7 @@ int intif_rename(struct map_session_data *sd, int type, char *name)
}
// GM Send a message
-int intif_broadcast(const char* mes, int len, int type)
+int intif_broadcast(const char* mes, size_t len, int type)
{
int lp = (type|BC_COLOR_MASK) ? 4 : 0;
@@ -155,7 +155,7 @@ int intif_broadcast(const char* mes, int len, int type)
return 0;
}
-int intif_broadcast2(const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY)
+int intif_broadcast2(const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY)
{
// Send to the local players
clif->broadcast2(NULL, mes, len, fontColor, fontType, fontSize, fontAlign, fontY, ALL_CLIENT);
@@ -201,7 +201,7 @@ int intif_main_message(struct map_session_data* sd, const char* message)
}
// The transmission of Wisp/Page to inter-server (player not found on this server)
-int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, int mes_len)
+int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, size_t mes_len)
{
nullpo_ret(sd);
if (intif->CheckForCharServer())
@@ -247,7 +247,7 @@ int intif_wis_replay(int id, int flag)
// The transmission of GM only Wisp/Page from server to inter-server
int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes)
{
- int mes_len;
+ size_t mes_len;
if (intif->CheckForCharServer())
return 0;
mes_len = strlen(mes) + 1; // + null
@@ -560,7 +560,7 @@ int intif_guild_addmember(int guild_id,struct guild_member *m)
}
// Request a new leader for guild
-int intif_guild_change_gm(int guild_id, const char* name, int len)
+int intif_guild_change_gm(int guild_id, const char* name, size_t len)
{
if (intif->CheckForCharServer())
return 0;
diff --git a/src/map/intif.h b/src/map/intif.h
index fbee3f270..bd3908ce7 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -40,10 +40,10 @@ struct intif_interface {
int (*parse) (int fd);
int (*create_pet)(int account_id, int char_id, short pet_type, short pet_lv, short pet_egg_id,
short pet_equip, short intimate, short hungry, char rename_flag, char incuvate, char *pet_name);
- int (*broadcast) (const char* mes, int len, int type);
- int (*broadcast2) (const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY);
+ int (*broadcast) (const char* mes, size_t len, int type);
+ int (*broadcast2) (const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY);
int (*main_message) (struct map_session_data* sd, const char* message);
- int (*wis_message) (struct map_session_data *sd,char *nick,char *mes,int mes_len);
+ int (*wis_message) (struct map_session_data *sd,char *nick,char *mes,size_t mes_len);
int (*wis_message_to_gm) (char *Wisp_name, int permission, char *mes);
int (*saveregistry) (struct map_session_data *sd, int type);
int (*request_registry) (struct map_session_data *sd, int flag);
@@ -65,7 +65,7 @@ struct intif_interface {
int (*guild_memberinfoshort) (int guild_id, int account_id, int char_id, int online, int lv, int class_);
int (*guild_break) (int guild_id);
int (*guild_message) (int guild_id, int account_id, const char *mes, int len);
- int (*guild_change_gm) (int guild_id, const char* name, int len);
+ int (*guild_change_gm) (int guild_id, const char* name, size_t len);
int (*guild_change_basicinfo) (int guild_id, int type, const void *data, int len);
int (*guild_change_memberinfo) (int guild_id, int account_id, int char_id, int type, const void *data, int len);
int (*guild_position) (int guild_id, int idx, struct guild_position *p);
diff --git a/src/map/irc-bot.c b/src/map/irc-bot.c
index 2b6dcfccd..ff28082e7 100644
--- a/src/map/irc-bot.c
+++ b/src/map/irc-bot.c
@@ -152,7 +152,8 @@ int irc_parse(int fd) {
* NULL, needs to be able to fit an IRC_HOST_LENGTH long string)
*/
void irc_parse_source(char *source, char *nick, char *ident, char *host) {
- int i, len = strlen(source), pos = 0;
+ int i, pos = 0;
+ size_t len = strlen(source);
unsigned char stage = 0;
for(i = 0; i < len; i++) {
@@ -208,7 +209,7 @@ void irc_parse_sub(int fd, char *str) {
* @param str Command to send
*/
void irc_send(char *str) {
- int len = strlen(str) + 2;
+ size_t len = strlen(str) + 2;
if (len > IRC_MESSAGE_LENGTH-3)
len = IRC_MESSAGE_LENGTH-3;
WFIFOHEAD(ircbot->fd, len);
@@ -298,7 +299,7 @@ void irc_privmsg(int fd, char *cmd, char *source, char *target, char *msg) {
ircbot->parse_source(source,source_nick,source_ident,source_host);
if( ircbot->channel ) {
- int padding_len = strlen(ircbot->channel->name) + strlen(source_nick) + 13;
+ size_t padding_len = strlen(ircbot->channel->name) + strlen(source_nick) + 13;
while (1) {
snprintf(send_string, 150, "[ #%s ] IRC.%s : %s",ircbot->channel->name,source_nick,msg);
clif->chsys_msg2(ircbot->channel,send_string);
diff --git a/src/map/irc-bot.h b/src/map/irc-bot.h
index 305cdfd91..7d6a19eba 100644
--- a/src/map/irc-bot.h
+++ b/src/map/irc-bot.h
@@ -24,7 +24,7 @@ struct irc_bot_interface {
bool isIn, isOn;
int64 last_try;
unsigned char fails;
- unsigned long ip;
+ uint32 ip;
unsigned short port;
/* */
struct hChSysCh *channel;
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 30f81c354..3f7d06e36 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -806,7 +806,7 @@ bool itemdb_read_cached_packages(const char *config_filename) {
for( i = 0; i < pcount; i++ ) {
unsigned short id = 0, random_qty = 0, must_qty = 0;
- struct item_data *data;
+ struct item_data *pdata;
struct item_package *package = &itemdb->packages[i];
unsigned short c;
@@ -817,10 +817,10 @@ bool itemdb_read_cached_packages(const char *config_filename) {
//next 2 bytes = random count
hread(&random_qty,sizeof(random_qty),1,file);
- if( !(data = itemdb->exists(id)) )
+ if( !(pdata = itemdb->exists(id)) )
ShowWarning("itemdb_read_packages: unknown package item '%d', skipping..\n",id);
else
- data->package = &itemdb->packages[i];
+ pdata->package = &itemdb->packages[i];
package->id = id;
package->random_qty = random_qty;
@@ -1022,7 +1022,6 @@ void itemdb_read_packages(void) {
for(r = 0; r < highest_gcount; r++) {
prev[r] = NULL;
}
- r = 0;
data->package = &itemdb->packages[count];
@@ -1300,7 +1299,7 @@ bool itemdb_read_stack(char* fields[], int columns, int current)
}
amount = (unsigned short)strtoul(fields[1], NULL, 10);
- type = strtoul(fields[2], NULL, 10);
+ type = (unsigned int)strtoul(fields[2], NULL, 10);
if( !amount )
{// ignore
diff --git a/src/map/map.c b/src/map/map.c
index b68a1f6a5..3a018828a 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -2239,7 +2239,7 @@ bool map_addnpc(int16 m,struct npc_data *nd) {
// Stores the spawn data entry in the mob list.
// Returns the index of successful, or -1 if the list was full.
int map_addmobtolist(unsigned short m, struct spawn_data *spawn) {
- size_t i;
+ int i;
ARR_FIND( 0, MAX_MOB_LIST_PER_MAP, i, map->list[m].moblist[i] == NULL );
if( i < MAX_MOB_LIST_PER_MAP ) {
map->list[m].moblist[i] = spawn;
@@ -3684,7 +3684,7 @@ void map_zone_remove(int m) {
unsigned short k;
char empty[1] = "\0";
for(k = 0; k < map->list[m].zone_mf_count; k++) {
- int len = strlen(map->list[m].zone_mf[k]),j;
+ size_t len = strlen(map->list[m].zone_mf[k]),j;
params[0] = '\0';
memcpy(flag, map->list[m].zone_mf[k], MAP_ZONE_MAPFLAG_LENGTH);
for(j = 0; j < len; j++) {
@@ -4236,7 +4236,7 @@ bool map_zone_mf_cache(int m, char *flag, char *params) {
} else if (!strcmpi(flag,"adjust_unit_duration")) {
int skill_id, k;
char skill_name[MAP_ZONE_MAPFLAG_LENGTH], modifier[MAP_ZONE_MAPFLAG_LENGTH];
- int len = strlen(params);
+ size_t len = strlen(params);
modifier[0] = '\0';
memcpy(skill_name, params, MAP_ZONE_MAPFLAG_LENGTH);
@@ -4254,7 +4254,6 @@ bool map_zone_mf_cache(int m, char *flag, char *params) {
} else {
int idx = map->list[m].unit_count;
- k = 0;
ARR_FIND(0, idx, k, map->list[m].units[k]->skill_id == skill_id);
if( k < idx ) {
@@ -4270,7 +4269,7 @@ bool map_zone_mf_cache(int m, char *flag, char *params) {
} else if (!strcmpi(flag,"adjust_skill_damage")) {
int skill_id, k;
char skill_name[MAP_ZONE_MAPFLAG_LENGTH], modifier[MAP_ZONE_MAPFLAG_LENGTH];
- int len = strlen(params);
+ size_t len = strlen(params);
modifier[0] = '\0';
memcpy(skill_name, params, MAP_ZONE_MAPFLAG_LENGTH);
@@ -4288,7 +4287,6 @@ bool map_zone_mf_cache(int m, char *flag, char *params) {
} else {
int idx = map->list[m].skill_count;
- k = 0;
ARR_FIND(0, idx, k, map->list[m].skills[k]->skill_id == skill_id);
if( k < idx ) {
@@ -4414,7 +4412,7 @@ void map_zone_apply(int m, struct map_zone_data *zone, const char* start, const
char flag[MAP_ZONE_MAPFLAG_LENGTH], params[MAP_ZONE_MAPFLAG_LENGTH];
map->list[m].zone = zone;
for(i = 0; i < zone->mapflags_count; i++) {
- int len = strlen(zone->mapflags[i]);
+ size_t len = strlen(zone->mapflags[i]);
int k;
params[0] = '\0';
memcpy(flag, zone->mapflags[i], MAP_ZONE_MAPFLAG_LENGTH);
@@ -4442,7 +4440,7 @@ void map_zone_init(void) {
zone = &map->zone_all;
for(i = 0; i < zone->mapflags_count; i++) {
- int len = strlen(zone->mapflags[i]);
+ size_t len = strlen(zone->mapflags[i]);
params[0] = '\0';
memcpy(flag, zone->mapflags[i], MAP_ZONE_MAPFLAG_LENGTH);
for(k = 0; k < len; k++) {
@@ -4465,7 +4463,7 @@ void map_zone_init(void) {
if( battle_config.pk_mode ) {
zone = &map->zone_pk;
for(i = 0; i < zone->mapflags_count; i++) {
- int len = strlen(zone->mapflags[i]);
+ size_t len = strlen(zone->mapflags[i]);
params[0] = '\0';
memcpy(flag, zone->mapflags[i], MAP_ZONE_MAPFLAG_LENGTH);
for(k = 0; k < len; k++) {
diff --git a/src/map/mob.c b/src/map/mob.c
index 8c02503aa..90a967d61 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -878,14 +878,15 @@ int mob_setdelayspawn(struct mob_data *md)
}
int mob_count_sub(struct block_list *bl, va_list ap) {
- int mobid[10], i;
- ARR_FIND(0, 10, i, (mobid[i] = va_arg(ap, int)) == 0); //fetch till 0
- if (mobid[0]) { //if there one let's check it otherwise go backward
- TBL_MOB *md = BL_CAST(BL_MOB, bl);
- ARR_FIND(0, 10, i, md->class_ == mobid[i]);
- return (i < 10) ? 1 : 0;
- }
- return 1; //backward compatibility
+ int mobid[10] = { 0 }, i;
+ ARR_FIND(0, 10, i, (mobid[i] = va_arg(ap, int)) == 0); //fetch till 0
+ if (mobid[0]) { //if there one let's check it otherwise go backward
+ TBL_MOB *md = BL_CAST(BL_MOB, bl);
+ nullpo_ret(md);
+ ARR_FIND(0, 10, i, md->class_ == mobid[i]);
+ return (i < 10) ? 1 : 0;
+ }
+ return 1; //backward compatibility
}
/*==========================================
@@ -4104,7 +4105,7 @@ bool mob_parse_row_chatdb(char** str, const char* source, int line, int* last_ms
//MSG ID
ms->msg_id=msg_id;
//Color
- ms->color=strtoul(str[1],NULL,0);
+ ms->color=(unsigned int)strtoul(str[1],NULL,0);
//Message
msg = str[2];
len = strlen(msg);
diff --git a/src/map/mob.h b/src/map/mob.h
index 605a8b465..9321cb4fd 100644
--- a/src/map/mob.h
+++ b/src/map/mob.h
@@ -91,7 +91,7 @@ struct mob_skill {
struct mob_chat {
unsigned short msg_id;
- unsigned long color;
+ unsigned int color;
char msg[CHAT_SIZE_MAX];
};
diff --git a/src/map/npc.c b/src/map/npc.c
index b57627495..84a2446ad 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -460,10 +460,10 @@ void npc_event_do_oninit(void)
*------------------------------------------*/
int npc_timerevent_export(struct npc_data *nd, int i)
{
- int t = 0, k = 0;
+ int t = 0, len = 0;
char *lname = nd->u.scr.label_list[i].name;
int pos = nd->u.scr.label_list[i].pos;
- if (sscanf(lname, "OnTimer%d%n", &t, &k) == 1 && lname[k] == '\0') {
+ if (sscanf(lname, "OnTimer%d%n", &t, &len) == 1 && lname[len] == '\0') {
// Timer event
struct npc_timerevent_list *te = nd->u.scr.timer_event;
int j, k = nd->u.scr.timeramount;
@@ -1616,7 +1616,7 @@ int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short* item_li
/// @return result code for clif->parse_NpcSellListSend
int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list) {
double z;
- int i,skill_t, idx = skill->get_index(MC_OVERCHARGE);
+ int i,skill_t, skill_idx = skill->get_index(MC_OVERCHARGE);
struct npc_data *nd;
nullpo_retr(1, sd);
@@ -1680,9 +1680,9 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list)
pc->getzeny(sd, (int)z, LOG_TYPE_NPC, NULL);
// custom merchant shop exp bonus
- if( battle_config.shop_exp > 0 && z > 0 && ( skill_t = pc->checkskill2(sd,idx) ) > 0) {
- if( sd->status.skill[idx].flag >= SKILL_FLAG_REPLACED_LV_0 )
- skill_t = sd->status.skill[idx].flag - SKILL_FLAG_REPLACED_LV_0;
+ if( battle_config.shop_exp > 0 && z > 0 && ( skill_t = pc->checkskill2(sd,skill_idx) ) > 0) {
+ if( sd->status.skill[skill_idx].flag >= SKILL_FLAG_REPLACED_LV_0 )
+ skill_t = sd->status.skill[skill_idx].flag - SKILL_FLAG_REPLACED_LV_0;
if( skill_t > 0 ) {
z = z * (double)skill_t * (double)battle_config.shop_exp/10000.;
@@ -2311,7 +2311,7 @@ void npc_convertlabel_db(struct npc_label_list* label_list, const char *filepath
int lpos = script->labels[i].pos;
struct npc_label_list* label;
const char *p;
- int len;
+ size_t len;
// In case of labels not terminated with ':', for user defined function support
p = lname;
@@ -2859,7 +2859,6 @@ int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const c
}
if( sd->npc_id != 0 ) { // Enqueue the event trigger.
- int i;
ARR_FIND( 0, MAX_EVENTQUEUE, i, sd->eventqueue[i][0] == '\0' );
if( i < MAX_EVENTQUEUE ) {
safestrncpy(sd->eventqueue[i],eventname,50); //Event enqueued.
@@ -3370,7 +3369,7 @@ const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, const char
else if (!strcmpi(w3,"adjust_unit_duration")) {
int skill_id, k;
char skill_name[MAP_ZONE_MAPFLAG_LENGTH], modifier[MAP_ZONE_MAPFLAG_LENGTH];
- int len = w4 ? strlen(w4) : 0;
+ size_t len = w4 ? strlen(w4) : 0;
modifier[0] = '\0';
if( w4 )
@@ -3425,7 +3424,7 @@ const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, const char
} else if (!strcmpi(w3,"adjust_skill_damage")) {
int skill_id, k;
char skill_name[MAP_ZONE_MAPFLAG_LENGTH], modifier[MAP_ZONE_MAPFLAG_LENGTH];
- int len = w4 ? strlen(w4) : 0;
+ size_t len = w4 ? strlen(w4) : 0;
modifier[0] = '\0';
@@ -3554,7 +3553,7 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) {
lines++;
// w1<TAB>w2<TAB>w3<TAB>w4
- count = sv->parse(p, len+buffer-p, 0, '\t', pos, ARRAYLENGTH(pos), (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
+ count = sv->parse(p, (int)(len+buffer-p), 0, '\t', pos, ARRAYLENGTH(pos), (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
if( count < 0 )
{
ShowError("npc_parsesrcfile: Parse error in file '%s', line '%d'. Stopping...\n", filepath, strline(buffer,p-buffer));
diff --git a/src/map/party.h b/src/map/party.h
index 91f4c1b7d..0041b1462 100644
--- a/src/map/party.h
+++ b/src/map/party.h
@@ -44,9 +44,9 @@ struct party_booking_detail {
};
struct party_booking_ad_info {
- unsigned long index;
+ unsigned int index;
char charname[NAME_LENGTH];
- long expiretime;
+ int expiretime;
struct party_booking_detail p_detail;
};
#else /* PARTY_RECRUIT */
@@ -56,8 +56,8 @@ struct party_booking_detail {
};
struct party_booking_ad_info {
- unsigned long index;
- long expiretime;
+ unsigned int index;
+ int expiretime;
char charname[NAME_LENGTH];
struct party_booking_detail p_detail;
};
@@ -71,7 +71,7 @@ struct party_booking_ad_info {
struct party_interface {
DBMap* db; // int party_id -> struct party_data* (releases data)
DBMap* booking_db; // int char_id -> struct party_booking_ad_info* (releases data) // Party Booking [Spiria]
- unsigned long booking_nextid;
+ unsigned int booking_nextid;
/* funcs */
void (*init) (bool minimal);
void (*final) (void);
diff --git a/src/map/path.c b/src/map/path.c
index a47677cf5..21d14c815 100644
--- a/src/map/path.c
+++ b/src/map/path.c
@@ -184,8 +184,10 @@ bool path_search_long(struct shootpath_data *spd,int16 m,int16 x0,int16 y0,int16
/// Ensures there is enough space in array to store new element.
static void heap_push_node(struct node_heap *heap, struct path_node *node)
{
+#ifndef __clang_analyzer__ // TODO: Figure out why clang's static analyzer doesn't like this
BHEAP_ENSURE(*heap, 1, 256);
BHEAP_PUSH(*heap, node, NODE_MINTOPCMP, swap_ptr);
+#endif // __clang_analyzer__
}
/// Updates path_node in the binary node_heap.
diff --git a/src/map/pc.c b/src/map/pc.c
index ab5749eb1..24b57c826 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -4437,7 +4437,6 @@ int pc_useitem(struct map_session_data *sd,int n) {
return 0;
if( sd->inventory_data[n]->delay > 0 ) {
- int i;
ARR_FIND(0, MAX_ITEMDELAYS, i, sd->item_delay[i].nameid == nameid );
if( i == MAX_ITEMDELAYS ) /* item not found. try first empty now */
ARR_FIND(0, MAX_ITEMDELAYS, i, !sd->item_delay[i].nameid );
@@ -4922,9 +4921,10 @@ int pc_setpos(struct map_session_data* sd, unsigned short map_index, int x, int
if( i != sd->guild->instances ) {
m = instance->list[sd->guild->instance[i]].map[j];
map_index = map_id2index(m);
- stop = true;
+ //stop = true; Uncomment if adding new checks
}
}
+
/* we hit a instance, if empty we populate the spawn data */
if( map->list[m].instance_id >= 0 && instance->list[map->list[m].instance_id].respawn.map == 0 &&
instance->list[map->list[m].instance_id].respawn.x == 0 &&
@@ -6789,15 +6789,15 @@ void pc_damage(struct map_session_data *sd,struct block_list *src,unsigned int h
* Invoked when a player has negative current hp
*------------------------------------------*/
int pc_dead(struct map_session_data *sd,struct block_list *src) {
- int i=0,j=0,k=0;
+ int i=0,j=0;
int64 tick = timer->gettick();
- for(k = 0; k < 5; k++)
- if (sd->devotion[k]){
- struct map_session_data *devsd = map->id2sd(sd->devotion[k]);
+ for(j = 0; j < 5; j++)
+ if (sd->devotion[j]){
+ struct map_session_data *devsd = map->id2sd(sd->devotion[j]);
if (devsd)
status_change_end(&devsd->bl, SC_DEVOTION, INVALID_TIMER);
- sd->devotion[k] = 0;
+ sd->devotion[j] = 0;
}
if(sd->status.pet_id > 0 && sd->pd) {
@@ -7057,14 +7057,13 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
if(id == 0)
continue;
if(id == -1){
- int eq_num=0,eq_n[MAX_INVENTORY];
+ int eq_num=0,eq_n[MAX_INVENTORY],k;
memset(eq_n,0,sizeof(eq_n));
for(i=0;i<MAX_INVENTORY;i++){
if( (type == 1 && !sd->status.inventory[i].equip)
|| (type == 2 && sd->status.inventory[i].equip)
|| type == 3)
{
- int k;
ARR_FIND( 0, MAX_INVENTORY, k, eq_n[k] <= 0 );
if( k < MAX_INVENTORY )
eq_n[k] = i;
@@ -10206,7 +10205,7 @@ int pc_readdb(void) {
int stat;
if(line[0]=='/' && line[1]=='/')
continue;
- if ((stat=strtoul(line,NULL,10))<0)
+ if ((stat=(int)strtol(line,NULL,10))<0)
stat=0;
if (i > MAX_LEVEL)
break;
diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c
index f95878e97..59dd951c7 100644
--- a/src/map/pc_groups.c
+++ b/src/map/pc_groups.c
@@ -131,7 +131,7 @@ static void read_config(void) {
iter = db_iterator(pcg->db);
for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
config_setting_t *commands = group_settings->commands, *permissions = group_settings->permissions;
- int count = 0, i;
+ int count = 0;
// Make sure there is "commands" group
if (commands == NULL)
@@ -209,15 +209,15 @@ static void read_config(void) {
// Copy settings (commands/permissions) that are not defined yet
if (inherited_group->commands != NULL) {
- int i = 0, commands_count = config_setting_length(inherited_group->commands);
- for (i = 0; i < commands_count; ++i)
- config_setting_copy(commands, config_setting_get_elem(inherited_group->commands, i));
+ int k = 0, commands_count = config_setting_length(inherited_group->commands);
+ for (k = 0; k < commands_count; ++k)
+ config_setting_copy(commands, config_setting_get_elem(inherited_group->commands, k));
}
if (inherited_group->permissions != NULL) {
- int i = 0, permissions_count = config_setting_length(inherited_group->permissions);
- for (i = 0; i < permissions_count; ++i)
- config_setting_copy(permissions, config_setting_get_elem(inherited_group->permissions, i));
+ int k = 0, permissions_count = config_setting_length(inherited_group->permissions);
+ for (k = 0; k < permissions_count; ++k)
+ config_setting_copy(permissions, config_setting_get_elem(inherited_group->permissions, k));
}
++done; // copied commands and permissions from one of inherited groups
@@ -241,7 +241,7 @@ static void read_config(void) {
iter = db_iterator(pcg->db);
for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
config_setting_t *permissions = group_settings->permissions;
- int i, count = config_setting_length(permissions);
+ int count = config_setting_length(permissions);
for (i = 0; i < count; ++i) {
config_setting_t *perm = config_setting_get_elem(permissions, i);
@@ -261,20 +261,20 @@ static void read_config(void) {
// Fetch all groups and relevant config setting and send them
// to atcommand->load_group() for processing.
if (group_count > 0) {
- int i = 0;
- GroupSettings **groups = NULL;
+ GroupSettings **pc_groups = NULL;
config_setting_t **commands = NULL;
- CREATE(groups, GroupSettings*, group_count);
+ CREATE(pc_groups, GroupSettings*, group_count);
CREATE(commands, config_setting_t*, group_count);
+ i = 0;
iter = db_iterator(pcg->db);
for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
- groups[i] = group_settings;
+ pc_groups[i] = group_settings;
commands[i] = group_settings->commands;
i++;
}
- atcommand->load_groups(groups, commands, group_count);
+ atcommand->load_groups(pc_groups, commands, group_count);
dbi_destroy(iter);
- aFree(groups);
+ aFree(pc_groups);
aFree(commands);
}
}
diff --git a/src/map/script.c b/src/map/script.c
index 008298fa3..744825257 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -275,14 +275,14 @@ void script_reportfunc(struct script_state* st)
/*==========================================
* Output error message
*------------------------------------------*/
-void disp_error_message2(const char *mes,const char *pos,int report)
-{
+static void disp_error_message2(const char *mes,const char *pos,int report) analyzer_noreturn;
+static void disp_error_message2(const char *mes,const char *pos,int report) {
script->error_msg = aStrdup(mes);
script->error_pos = pos;
script->error_report = report;
longjmp( script->error_jump, 1 );
}
-#define disp_error_message(mes,pos) (script->disp_error_message2((mes),(pos),1))
+#define disp_error_message(mes,pos) (disp_error_message2((mes),(pos),1))
void disp_warning_message(const char *mes, const char *pos) {
script->warning(script->parser_current_src,script->parser_current_file,script->parser_current_line,mes,pos);
@@ -728,7 +728,7 @@ const char* skip_word(const char* p) {
/// @see skip_word
/// @see script->add_str
int add_word(const char* p) {
- int len;
+ size_t len;
int i;
// Check for a word
@@ -1204,7 +1204,7 @@ const char* script_parse_subexpr(const char* p,int limit) {
}
}
- if( (op=C_ADD_PRE,p[0]=='+'&&p[1]=='+') || (op=C_SUB_PRE,p[0]=='-'&&p[1]=='-') ) { // Pre ++ -- operators
+ if( (p[0]=='+' && p[1]=='+') /* C_ADD_PRE */ || (p[0]=='-'&&p[1]=='-') /* C_SUB_PRE */ ) { // Pre ++ -- operators
p=script->parse_variable(p);
} else if( (op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~') ) { // Unary - ! ~ operators
p=script->parse_subexpr(p+1,11);
@@ -1459,7 +1459,7 @@ const char* parse_syntax(const char* p)
// check whether case label is integer or not
if(is_number(p)) {
//Numeric value
- v = strtol(p,&np,0);
+ v = (int)strtol(p,&np,0);
if((*p == '-' || *p == '+') && ISDIGIT(p[1])) // pre-skip because '-' can not skip_word
p++;
p = script->skip_word(p);
@@ -1468,7 +1468,7 @@ const char* parse_syntax(const char* p)
} else {
//Check for constants
p2 = script->skip_word(p);
- v = p2-p; // length of word at p2
+ v = (int)(size_t) (p2-p); // length of word at p2
memcpy(label,p,v);
label[v]='\0';
if( !script->get_constant(label, &v) )
@@ -1936,8 +1936,6 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
}
return p;
} else if(script->syntax.curly[pos].type == TYPE_DO) {
- int l;
- char label[256];
const char *p2;
if(script->syntax.curly[pos].flag) {
@@ -2023,10 +2021,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
script->set_label(l,script->pos,p);
script->syntax.curly_count--;
return p;
- } else if(script->syntax.curly[script->syntax.curly_count-1].type == TYPE_USERFUNC) {
- int pos = script->syntax.curly_count-1;
- char label[256];
- int l;
+ } else if(script->syntax.curly[pos].type == TYPE_USERFUNC) {
// Back
sprintf(label,"return;");
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
@@ -2275,7 +2270,6 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
if( setjmp( script->error_jump ) != 0 ) {
//Restore program state when script has problems. [from jA]
- int i;
const int size = ARRAYLENGTH(script->syntax.curly);
if( script->error_report )
script->error(src,file,line,script->error_msg,script->error_pos);
@@ -6165,10 +6159,8 @@ BUILDIN(getitem)
*------------------------------------------*/
BUILDIN(getitem2)
{
- int nameid,amount,get_count,i,flag = 0, offset = 0;
+ int nameid,amount,i,flag = 0, offset = 0;
int iden,ref,attr,c1,c2,c3,c4, bound = 0;
- struct item_data *item_data;
- struct item item_tmp;
TBL_PC *sd;
struct script_data *data;
@@ -6221,8 +6213,10 @@ BUILDIN(getitem2)
}
if(nameid > 0) {
+ struct item item_tmp;
+ struct item_data *item_data = itemdb->exists(nameid);
+ int get_count;
memset(&item_tmp,0,sizeof(item_tmp));
- item_data=itemdb->exists(nameid);
if (item_data == NULL)
return -1;
if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR){
@@ -9332,12 +9326,12 @@ BUILDIN(announce) {
}
if (fontColor)
- clif->broadcast2(bl, mes, (int)strlen(mes)+1, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, target);
+ clif->broadcast2(bl, mes, (int)strlen(mes)+1, (unsigned int)strtoul(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, target);
else
clif->broadcast(bl, mes, (int)strlen(mes)+1, flag&BC_COLOR_MASK, target);
} else {
if (fontColor)
- intif->broadcast2(mes, (int)strlen(mes)+1, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY);
+ intif->broadcast2(mes, (int)strlen(mes)+1, (unsigned int)strtoul(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY);
else
intif->broadcast(mes, (int)strlen(mes)+1, flag&BC_COLOR_MASK);
}
@@ -9356,7 +9350,7 @@ int buildin_announce_sub(struct block_list *bl, va_list ap)
short fontAlign = (short)va_arg(ap, int);
short fontY = (short)va_arg(ap, int);
if (fontColor)
- clif->broadcast2(bl, mes, len, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, SELF);
+ clif->broadcast2(bl, mes, len, (unsigned int)strtoul(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, SELF);
else
clif->broadcast(bl, mes, len, type, SELF);
return 0;
@@ -13502,7 +13496,7 @@ BUILDIN(insertchar)
if(index < 0)
index = 0;
else if(index > len)
- index = len;
+ index = (int)len;
output = (char*)aMalloc(len + 2);
@@ -13685,9 +13679,9 @@ BUILDIN(implode)
{
struct script_data* data = script_getdata(st, 2);
const char *glue = NULL, *name, *temp;
- int32 glue_len = 0, array_size, id;
- size_t len = 0;
- int i, k = 0;
+ int32 array_size, id;
+ size_t len = 0, glue_len = 0, k = 0;
+ int i;
TBL_PC* sd = NULL;
@@ -13782,13 +13776,14 @@ BUILDIN(implode)
//-------------------------------------------------------
BUILDIN(sprintf)
{
- unsigned int len, argc = 0, arg = 0, buf2_len = 0;
+ unsigned int argc = 0, arg = 0;
const char* format;
char* p;
char* q;
char* buf = NULL;
char* buf2 = NULL;
struct script_data* data;
+ size_t len, buf2_len = 0;
StringBuf final_buf;
// Fetch init data
@@ -13913,7 +13908,7 @@ BUILDIN(sprintf)
// Implements C sscanf.
//-------------------------------------------------------
BUILDIN(sscanf){
- unsigned int argc, arg = 0, len;
+ unsigned int argc, arg = 0;
struct script_data* data;
struct map_session_data* sd = NULL;
const char* str;
@@ -13924,6 +13919,7 @@ BUILDIN(sscanf){
char* buf_p;
char* ref_str = NULL;
int ref_int;
+ size_t len;
// Get data
str = script_getstr(st, 2);
@@ -16704,7 +16700,7 @@ BUILDIN(progressbar)
sd->progressbar.timeout = timer->gettick() + second*1000;
sd->state.workinprogress = 3;
- clif->progressbar(sd, strtol(color, (char **)NULL, 0), second);
+ clif->progressbar(sd, (unsigned int)strtoul(color, (char **)NULL, 0), second);
return true;
}
@@ -18034,7 +18030,8 @@ BUILDIN(instance_set_respawn) {
* @return Whether the function was successfully added.
*/
bool script_add_builtin(const struct script_function *buildin, bool override) {
- int slen = 0, n = 0, offset = 0;
+ int n = 0, offset = 0;
+ size_t slen;
if( !buildin ) {
return false;
}
@@ -18769,7 +18766,6 @@ void script_defaults(void) {
script->reportsrc = script_reportsrc;
script->reportdata = script_reportdata;
script->reportfunc = script_reportfunc;
- script->disp_error_message2 = disp_error_message2;
script->disp_warning_message = disp_warning_message;
script->check_event = check_event;
script->calc_hash = calc_hash;
diff --git a/src/map/script.h b/src/map/script.h
index d1d131af3..8076ea02e 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -480,12 +480,12 @@ struct script_interface {
int str_num; // next id to be assigned
// str_buf holds the strings themselves
char *str_buf;
- int str_size; // size of the buffer
+ size_t str_size; // size of the buffer
int str_pos; // next position to be assigned
int str_hash[SCRIPT_HASH_SIZE];
/* */
char *word_buf;
- int word_size;
+ size_t word_size;
/* */
unsigned short current_item_id;
/* */
@@ -594,7 +594,6 @@ struct script_interface {
void (*reportsrc) (struct script_state *st);
void (*reportdata) (struct script_data *data);
void (*reportfunc) (struct script_state *st);
- void (*disp_error_message2) (const char *mes, const char *pos, int report);
void (*disp_warning_message) (const char *mes, const char *pos);
void (*check_event) (struct script_state *st, const char *evt);
unsigned int (*calc_hash) (const char *p);
diff --git a/src/map/skill.c b/src/map/skill.c
index 650594abc..245df05e5 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -328,6 +328,8 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk
struct map_session_data *tsd = BL_CAST(BL_PC, target);
struct status_change* sc;
+ nullpo_ret(src);
+
switch( skill_id ) {
case BA_APPLEIDUN:
#ifdef RENEWAL
@@ -1434,7 +1436,7 @@ int skill_additional_effect(struct block_list* src, struct block_list *bl, uint1
if( sd && !status->isdead(bl) && sd->autospell[0].id ) {
struct block_list *tbl;
struct unit_data *ud;
- int i, skill_lv, type, notok;
+ int i, auto_skill_lv, type, notok;
for (i = 0; i < ARRAYLENGTH(sd->autospell) && sd->autospell[i].id; i++) {
@@ -1452,8 +1454,8 @@ int skill_additional_effect(struct block_list* src, struct block_list *bl, uint1
if ( notok )
continue;
- skill_lv = sd->autospell[i].lv?sd->autospell[i].lv:1;
- if (skill_lv < 0) skill_lv = 1+rnd()%(-skill_lv);
+ auto_skill_lv = sd->autospell[i].lv?sd->autospell[i].lv:1;
+ if (auto_skill_lv < 0) auto_skill_lv = 1+rnd()%(-auto_skill_lv);
rate = (!sd->state.arrow_atk) ? sd->autospell[i].rate : sd->autospell[i].rate / 2;
@@ -1466,18 +1468,18 @@ int skill_additional_effect(struct block_list* src, struct block_list *bl, uint1
int maxcount = 0;
if( !(BL_PC&battle_config.skill_reiteration) &&
skill->get_unit_flag(temp)&UF_NOREITERATION &&
- skill->check_unit_range(src,tbl->x,tbl->y,temp,skill_lv)
+ skill->check_unit_range(src,tbl->x,tbl->y,temp,auto_skill_lv)
) {
continue;
}
if( BL_PC&battle_config.skill_nofootset &&
skill->get_unit_flag(temp)&UF_NOFOOTSET &&
- skill->check_unit_range2(src,tbl->x,tbl->y,temp,skill_lv)
+ skill->check_unit_range2(src,tbl->x,tbl->y,temp,auto_skill_lv)
) {
continue;
}
if( BL_PC&battle_config.land_skill_limit &&
- (maxcount = skill->get_maxcount(temp, skill_lv)) > 0
+ (maxcount = skill->get_maxcount(temp, auto_skill_lv)) > 0
) {
int v;
for(v=0;v<MAX_SKILLUNITGROUP && sd->ud.skillunit[v] && maxcount;v++) {
@@ -1490,7 +1492,7 @@ int skill_additional_effect(struct block_list* src, struct block_list *bl, uint1
}
}
if( battle_config.autospell_check_range &&
- !battle->check_range(src, tbl, skill->get_range2(src, temp,skill_lv) + (temp == RG_CLOSECONFINE?0:1)) )
+ !battle->check_range(src, tbl, skill->get_range2(src, temp,auto_skill_lv) + (temp == RG_CLOSECONFINE?0:1)) )
continue;
if (temp == AS_SONICBLOW)
@@ -1499,24 +1501,24 @@ int skill_additional_effect(struct block_list* src, struct block_list *bl, uint1
type = CAST_GROUND;
sd->state.autocast = 1;
- skill->consume_requirement(sd,temp,skill_lv,1);
+ skill->consume_requirement(sd,temp,auto_skill_lv,1);
skill->toggle_magicpower(src, temp);
switch (type) {
case CAST_GROUND:
- skill->castend_pos2(src, tbl->x, tbl->y, temp, skill_lv, tick, 0);
+ skill->castend_pos2(src, tbl->x, tbl->y, temp, auto_skill_lv, tick, 0);
break;
case CAST_NODAMAGE:
- skill->castend_nodamage_id(src, tbl, temp, skill_lv, tick, 0);
+ skill->castend_nodamage_id(src, tbl, temp, auto_skill_lv, tick, 0);
break;
case CAST_DAMAGE:
- skill->castend_damage_id(src, tbl, temp, skill_lv, tick, 0);
+ skill->castend_damage_id(src, tbl, temp, auto_skill_lv, tick, 0);
break;
}
sd->state.autocast = 0;
//Set canact delay. [Skotlex]
ud = unit->bl2ud(src);
if (ud) {
- rate = skill->delay_fix(src, temp, skill_lv);
+ rate = skill->delay_fix(src, temp, auto_skill_lv);
if (DIFF_TICK(ud->canact_tick, tick + rate) < 0){
ud->canact_tick = tick+rate;
if ( battle_config.display_status_timers && sd )
@@ -1779,7 +1781,7 @@ int skill_counter_additional_effect(struct block_list* src, struct block_list *b
if(dstsd && !status->isdead(bl) && dstsd->autospell2[0].id && !(skill_id && skill->get_nk(skill_id)&NK_NO_DAMAGE)) {
struct block_list *tbl;
struct unit_data *ud;
- int i, skill_id, skill_lv, rate, type, notok;
+ int i, auto_skill_id, auto_skill_lv, type, notok;
for (i = 0; i < ARRAYLENGTH(dstsd->autospell2) && dstsd->autospell2[i].id; i++) {
@@ -1788,16 +1790,16 @@ int skill_counter_additional_effect(struct block_list* src, struct block_list *b
dstsd->autospell2[i].flag&attack_type&BF_SKILLMASK))
continue; // one or more trigger conditions were not fulfilled
- skill_id = (dstsd->autospell2[i].id > 0) ? dstsd->autospell2[i].id : -dstsd->autospell2[i].id;
- skill_lv = dstsd->autospell2[i].lv?dstsd->autospell2[i].lv:1;
- if (skill_lv < 0) skill_lv = 1+rnd()%(-skill_lv);
+ auto_skill_id = (dstsd->autospell2[i].id > 0) ? dstsd->autospell2[i].id : -dstsd->autospell2[i].id;
+ auto_skill_lv = dstsd->autospell2[i].lv?dstsd->autospell2[i].lv:1;
+ if (auto_skill_lv < 0) auto_skill_lv = 1+rnd()%(-auto_skill_lv);
rate = dstsd->autospell2[i].rate;
if (attack_type&BF_LONG)
rate>>=1;
dstsd->state.autocast = 1;
- notok = skill->not_ok(skill_id, dstsd);
+ notok = skill->not_ok(auto_skill_id, dstsd);
dstsd->state.autocast = 0;
if ( notok )
@@ -1808,26 +1810,26 @@ int skill_counter_additional_effect(struct block_list* src, struct block_list *b
tbl = (dstsd->autospell2[i].id < 0) ? bl : src;
- if( (type = skill->get_casttype(skill_id)) == CAST_GROUND ) {
+ if( (type = skill->get_casttype(auto_skill_id)) == CAST_GROUND ) {
int maxcount = 0;
if( !(BL_PC&battle_config.skill_reiteration) &&
- skill->get_unit_flag(skill_id)&UF_NOREITERATION &&
- skill->check_unit_range(bl,tbl->x,tbl->y,skill_id,skill_lv)
+ skill->get_unit_flag(auto_skill_id)&UF_NOREITERATION &&
+ skill->check_unit_range(bl,tbl->x,tbl->y,auto_skill_id,auto_skill_lv)
) {
continue;
}
if( BL_PC&battle_config.skill_nofootset &&
- skill->get_unit_flag(skill_id)&UF_NOFOOTSET &&
- skill->check_unit_range2(bl,tbl->x,tbl->y,skill_id,skill_lv)
+ skill->get_unit_flag(auto_skill_id)&UF_NOFOOTSET &&
+ skill->check_unit_range2(bl,tbl->x,tbl->y,auto_skill_id,auto_skill_lv)
) {
continue;
}
if( BL_PC&battle_config.land_skill_limit &&
- (maxcount = skill->get_maxcount(skill_id, skill_lv)) > 0
+ (maxcount = skill->get_maxcount(auto_skill_id, auto_skill_lv)) > 0
) {
int v;
for(v=0;v<MAX_SKILLUNITGROUP && dstsd->ud.skillunit[v] && maxcount;v++) {
- if(dstsd->ud.skillunit[v]->skill_id == skill_id)
+ if(dstsd->ud.skillunit[v]->skill_id == auto_skill_id)
maxcount--;
}
if( maxcount == 0 ) {
@@ -1836,27 +1838,27 @@ int skill_counter_additional_effect(struct block_list* src, struct block_list *b
}
}
- if( !battle->check_range(src, tbl, skill->get_range2(src, skill_id,skill_lv) + (skill_id == RG_CLOSECONFINE?0:1)) && battle_config.autospell_check_range )
+ if( !battle->check_range(src, tbl, skill->get_range2(src, auto_skill_id,auto_skill_lv) + (auto_skill_id == RG_CLOSECONFINE?0:1)) && battle_config.autospell_check_range )
continue;
dstsd->state.autocast = 1;
- skill->consume_requirement(dstsd,skill_id,skill_lv,1);
+ skill->consume_requirement(dstsd,auto_skill_id,auto_skill_lv,1);
switch (type) {
case CAST_GROUND:
- skill->castend_pos2(bl, tbl->x, tbl->y, skill_id, skill_lv, tick, 0);
+ skill->castend_pos2(bl, tbl->x, tbl->y, auto_skill_id, auto_skill_lv, tick, 0);
break;
case CAST_NODAMAGE:
- skill->castend_nodamage_id(bl, tbl, skill_id, skill_lv, tick, 0);
+ skill->castend_nodamage_id(bl, tbl, auto_skill_id, auto_skill_lv, tick, 0);
break;
case CAST_DAMAGE:
- skill->castend_damage_id(bl, tbl, skill_id, skill_lv, tick, 0);
+ skill->castend_damage_id(bl, tbl, auto_skill_id, auto_skill_lv, tick, 0);
break;
}
dstsd->state.autocast = 0;
//Set canact delay. [Skotlex]
ud = unit->bl2ud(bl);
if (ud) {
- rate = skill->delay_fix(bl, skill_id, skill_lv);
+ rate = skill->delay_fix(bl, auto_skill_id, auto_skill_lv);
if (DIFF_TICK(ud->canact_tick, tick + rate) < 0){
ud->canact_tick = tick+rate;
if ( battle_config.display_status_timers && dstsd )
@@ -2276,7 +2278,7 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
}
if(sd) {
- int flag = 0; //Used to signal if this skill can be combo'ed later on.
+ int combo = 0; //Used to signal if this skill can be combo'ed later on.
struct status_change_entry *sce;
if ((sce = sd->sc.data[SC_COMBOATTACK])) {//End combo state after skill is invoked. [Skotlex]
switch (skill_id) {
@@ -2302,23 +2304,23 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
switch(skill_id) {
case MO_TRIPLEATTACK:
if (pc->checkskill(sd, MO_CHAINCOMBO) > 0 || pc->checkskill(sd, SR_DRAGONCOMBO) > 0)
- flag=1;
+ combo=1;
break;
case MO_CHAINCOMBO:
if(pc->checkskill(sd, MO_COMBOFINISH) > 0 && sd->spiritball > 0)
- flag=1;
+ combo=1;
break;
case MO_COMBOFINISH:
if (sd->status.party_id>0) //bonus from SG_FRIEND [Komurka]
party->skill_check(sd, sd->status.party_id, MO_COMBOFINISH, skill_lv);
if (pc->checkskill(sd, CH_TIGERFIST) > 0 && sd->spiritball > 0)
- flag=1;
+ combo=1;
case CH_TIGERFIST:
- if (!flag && pc->checkskill(sd, CH_CHAINCRUSH) > 0 && sd->spiritball > 1)
- flag=1;
+ if (!combo && pc->checkskill(sd, CH_CHAINCRUSH) > 0 && sd->spiritball > 1)
+ combo=1;
case CH_CHAINCRUSH:
- if (!flag && pc->checkskill(sd, MO_EXTREMITYFIST) > 0 && sd->spiritball > 0 && sd->sc.data[SC_EXPLOSIONSPIRITS])
- flag=1;
+ if (!combo && pc->checkskill(sd, MO_EXTREMITYFIST) > 0 && sd->spiritball > 0 && sd->sc.data[SC_EXPLOSIONSPIRITS])
+ combo=1;
break;
case AC_DOUBLE:
if( (tstatus->race == RC_BRUTE || tstatus->race == RC_INSECT) && pc->checkskill(sd, HT_POWER))
@@ -2346,21 +2348,21 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
break;
case TK_DODGE:
if( pc->checkskill(sd, TK_JUMPKICK) > 0 )
- flag = 1;
+ combo = 1;
break;
case SR_DRAGONCOMBO:
if( pc->checkskill(sd, SR_FALLENEMPIRE) > 0 )
- flag = 1;
+ combo = 1;
break;
case SR_FALLENEMPIRE:
if( pc->checkskill(sd, SR_TIGERCANNON) > 0 || pc->checkskill(sd, SR_GATEOFHELL) > 0 )
- flag = 1;
+ combo = 1;
break;
} //Switch End
- if (flag) { //Possible to chain
- if ( (flag = DIFF_TICK32(sd->ud.canact_tick, tick)) < 50 ) flag = 50;/* less is a waste. */
- sc_start2(src,SC_COMBOATTACK,100,skill_id,bl->id,flag);
- clif->combo_delay(src, flag);
+ if (combo) { //Possible to chain
+ if ( (combo = DIFF_TICK32(sd->ud.canact_tick, tick)) < 50 ) combo = 50;/* less is a waste. */
+ sc_start2(src,SC_COMBOATTACK,100,skill_id,bl->id,combo);
+ clif->combo_delay(src, combo);
}
}
@@ -4171,7 +4173,7 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
skill->toggle_magicpower(src, skill_id);
// Priority is to release SpellBook
if( sc && sc->data[SC_READING_SB] ) { // SpellBook
- uint16 skill_id, skill_lv, point, s = 0;
+ uint16 spell_skill_id, spell_skill_lv, point, s = 0;
int spell[SC_SPELLBOOK7-SC_SPELLBOOK1 + 1];
for(i = SC_SPELLBOOK7; i >= SC_SPELLBOOK1; i--) // List all available spell to be released
@@ -4182,8 +4184,8 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
i = spell[s==1?0:rand()%s];// Random select of spell to be released.
if( s && sc->data[i] ){// Now extract the data from the preserved spell
- skill_id = sc->data[i]->val1;
- skill_lv = sc->data[i]->val2;
+ spell_skill_id = sc->data[i]->val1;
+ spell_skill_lv = sc->data[i]->val2;
point = sc->data[i]->val3;
status_change_end(src, (sc_type)i, INVALID_TIMER);
}else //something went wrong :(
@@ -4194,36 +4196,35 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
else // Last spell to be released
status_change_end(src, SC_READING_SB, INVALID_TIMER);
- if( !skill->check_condition_castbegin(sd, skill_id, skill_lv) )
+ if( !skill->check_condition_castbegin(sd, spell_skill_id, spell_skill_lv) )
break;
- switch( skill->get_casttype(skill_id) ) {
+ switch( skill->get_casttype(spell_skill_id) ) {
case CAST_GROUND:
- skill->castend_pos2(src, bl->x, bl->y, skill_id, skill_lv, tick, 0);
+ skill->castend_pos2(src, bl->x, bl->y, spell_skill_id, spell_skill_lv, tick, 0);
break;
case CAST_NODAMAGE:
- skill->castend_nodamage_id(src, bl, skill_id, skill_lv, tick, 0);
+ skill->castend_nodamage_id(src, bl, spell_skill_id, spell_skill_lv, tick, 0);
break;
case CAST_DAMAGE:
- skill->castend_damage_id(src, bl, skill_id, skill_lv, tick, 0);
+ skill->castend_damage_id(src, bl, spell_skill_id, spell_skill_lv, tick, 0);
break;
}
- sd->ud.canact_tick = tick + skill->delay_fix(src, skill_id, skill_lv);
- clif->status_change(src, SI_POSTDELAY, 1, skill->delay_fix(src, skill_id, skill_lv), 0, 0, 0);
+ sd->ud.canact_tick = tick + skill->delay_fix(src, spell_skill_id, spell_skill_lv);
+ clif->status_change(src, SI_POSTDELAY, 1, skill->delay_fix(src, spell_skill_id, spell_skill_lv), 0, 0, 0);
- cooldown = skill_get_cooldown(skill_id, skill_lv);
+ cooldown = skill_get_cooldown(spell_skill_id, spell_skill_lv);
for (i = 0; i < ARRAYLENGTH(sd->skillcooldown) && sd->skillcooldown[i].id; i++) {
- if (sd->skillcooldown[i].id == skill_id){
+ if (sd->skillcooldown[i].id == spell_skill_id){
cooldown += sd->skillcooldown[i].val;
break;
}
}
if(cooldown)
- skill->blockpc_start(sd, skill_id, cooldown);
+ skill->blockpc_start(sd, spell_skill_id, cooldown);
}else if( sc ){ // Summon Balls
- int i = SC_SUMMON5;
- for(; i >= SC_SUMMON1; i--){
+ for(i = SC_SUMMON5; i >= SC_SUMMON1; i--){
if( sc->data[i] ){
int skillid = WL_SUMMON_ATK_FIRE + (sc->data[i]->val1 - WLS_FIRE);
skill->addtimerskill(src, tick + status_get_adelay(src) * (SC_SUMMON5 - i), bl->id, 0, 0, skillid, skill_lv, BF_MAGIC, flag);
@@ -4460,14 +4461,14 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
case EL_TIDAL_WEAPON:
if( src->type == BL_ELEM ) {
struct elemental_data *ele = BL_CAST(BL_ELEM,src);
- struct status_change *sc = status->get_sc(&ele->bl);
+ struct status_change *esc = status->get_sc(&ele->bl);
struct status_change *tsc = status->get_sc(bl);
sc_type type = status->skill2sc(skill_id), type2;
type2 = type-1;
clif->skill_nodamage(src,battle->get_master(src),skill_id,skill_lv,1);
clif->skill_damage(src, src, tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, 6);
- if( (sc && sc->data[type2]) || (tsc && tsc->data[type]) ) {
+ if( (esc && esc->data[type2]) || (tsc && tsc->data[type]) ) {
elemental->clean_single_effect(ele, skill_id);
}
if( rnd()%100 < 50 )
@@ -4893,7 +4894,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
struct status_change *tsc;
struct status_change_entry *tsce;
- int i = 0;
+ int element = 0;
enum sc_type type;
if(skill_id > 0 && !skill_lv) return 0; // celest
@@ -5008,9 +5009,9 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
tsce = (tsc && type != -1)?tsc->data[type]:NULL;
if (src!=bl && type > -1 &&
- (i = skill->get_ele(skill_id, skill_lv)) > ELE_NEUTRAL &&
+ (element = skill->get_ele(skill_id, skill_lv)) > ELE_NEUTRAL &&
skill->get_inf(skill_id) != INF_SUPPORT_SKILL &&
- battle->attr_fix(NULL, NULL, 100, i, tstatus->def_ele, tstatus->ele_lv) <= 0)
+ battle->attr_fix(NULL, NULL, 100, element, tstatus->def_ele, tstatus->ele_lv) <= 0)
return 1; //Skills that cause an status should be blocked if the target element blocks its element.
map->freeblock_lock();
@@ -5175,13 +5176,13 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case SA_ABRACADABRA:
{
- int abra_skill_id = 0, abra_skill_lv;
+ int abra_skill_id = 0, abra_skill_lv, abra_idx;
do {
- i = rnd() % MAX_SKILL_ABRA_DB;
- abra_skill_id = skill->abra_db[i].skill_id;
+ abra_idx = rnd() % MAX_SKILL_ABRA_DB;
+ abra_skill_id = skill->abra_db[abra_idx].skill_id;
} while (abra_skill_id == 0 ||
- skill->abra_db[i].req_lv > skill_lv || //Required lv for it to appear
- rnd()%10000 >= skill->abra_db[i].per
+ skill->abra_db[abra_idx].req_lv > skill_lv || //Required lv for it to appear
+ rnd()%10000 >= skill->abra_db[abra_idx].per
);
abra_skill_lv = min(skill_lv, skill->get_max(abra_skill_id));
clif->skill_nodamage (src, bl, skill_id, skill_lv, 1);
@@ -5279,6 +5280,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
mob->class_change(dstmd,class_);
if( tsc && dstmd->status.mode&MD_BOSS )
{
+ int i;
const enum sc_type scs[] = { SC_QUAGMIRE, SC_PROVOKE, SC_ROKISWEIL, SC_GRAVITATION, SC_NJ_SUITON, SC_NOEQUIPWEAPON, SC_NOEQUIPSHIELD, SC_NOEQUIPARMOR, SC_NOEQUIPHELM, SC_BLADESTOP };
for (i = SC_COMMON_MIN; i <= SC_COMMON_MAX; i++)
if (tsc->data[i]) status_change_end(bl, (sc_type)i, INVALID_TIMER);
@@ -5308,6 +5310,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case SA_TAMINGMONSTER:
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
if (sd && dstmd) {
+ int i;
ARR_FIND( 0, MAX_PET_DB, i, dstmd->class_ == pet->db[i].class_ );
if( i < MAX_PET_DB )
pet->catch_process1(sd, dstmd->class_);
@@ -5582,9 +5585,11 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
case HLIF_AVOID:
case HAMI_DEFENCE:
- i = skill->get_time(skill_id,skill_lv);
- clif->skill_nodamage(bl,bl,skill_id,skill_lv,sc_start(bl,type,100,skill_lv,i)); // Master
- clif->skill_nodamage(src,src,skill_id,skill_lv,sc_start(src,type,100,skill_lv,i)); // Homunc
+ {
+ int duration = skill->get_time(skill_id,skill_lv);
+ clif->skill_nodamage(bl,bl,skill_id,skill_lv,sc_start(bl,type,100,skill_lv,duration)); // Master
+ clif->skill_nodamage(src,src,skill_id,skill_lv,sc_start(src,type,100,skill_lv,duration)); // Homunc
+ }
break;
case NJ_BUNSINJYUTSU:
clif->skill_nodamage(src,bl,skill_id,skill_lv,
@@ -5681,14 +5686,16 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case SM_PROVOKE:
case SM_SELFPROVOKE:
case MER_PROVOKE:
+ {
+ int failure;
if( (tstatus->mode&MD_BOSS) || battle->check_undead(tstatus->race,tstatus->def_ele) ) {
map->freeblock_unlock();
return 1;
}
//TODO: How much does base level affects? Dummy value of 1% per level difference used. [Skotlex]
clif->skill_nodamage(src,bl,skill_id == SM_SELFPROVOKE ? SM_PROVOKE : skill_id,skill_lv,
- (i = sc_start(bl,type, skill_id == SM_SELFPROVOKE ? 100:( 50 + 3*skill_lv + status->get_lv(src) - status->get_lv(bl)), skill_lv, skill->get_time(skill_id,skill_lv))));
- if( !i ) {
+ (failure = sc_start(bl,type, skill_id == SM_SELFPROVOKE ? 100:( 50 + 3*skill_lv + status->get_lv(src) - status->get_lv(bl)), skill_lv, skill->get_time(skill_id,skill_lv))));
+ if( !failure ) {
if( sd )
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
map->freeblock_unlock();
@@ -5710,12 +5717,13 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
dstmd->state.provoke_flag = src->id;
mob->target(dstmd, src, skill->get_range2(src,skill_id,skill_lv));
}
+ }
break;
case ML_DEVOTION:
case CR_DEVOTION:
{
- int count, lv;
+ int count, lv, i;
if( !dstsd || (!sd && !mer) )
{ // Only players can be devoted
if( sd )
@@ -5776,7 +5784,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case CH_SOULCOLLECT:
if(sd) {
- int limit = 5;
+ int limit = 5, i;
if( sd->sc.data[SC_RAISINGDRAGON] )
limit += sd->sc.data[SC_RAISINGDRAGON]->val1;
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
@@ -5800,18 +5808,20 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
case MO_ABSORBSPIRITS:
- i = 0;
+ {
+ int sp = 0;
if (dstsd && dstsd->spiritball && (sd == dstsd || map_flag_vs(src->m)) && ((dstsd->class_&MAPID_BASEMASK)!=MAPID_GUNSLINGER || (dstsd->class_&MAPID_UPPERMASK)!=MAPID_REBELLION))
{ // split the if for readability, and included gunslingers in the check so that their coins cannot be removed [Reddozen]
- i = dstsd->spiritball * 7;
+ sp = dstsd->spiritball * 7;
pc->delspiritball(dstsd,dstsd->spiritball,0);
} else if (dstmd && !(tstatus->mode&MD_BOSS) && rnd() % 100 < 20)
{ // check if target is a monster and not a Boss, for the 20% chance to absorb 2 SP per monster's level [Reddozen]
- i = 2 * dstmd->level;
+ sp = 2 * dstmd->level;
mob->target(dstmd,src,0);
}
- if (i) status->heal(src, 0, i, 3);
- clif->skill_nodamage(src,bl,skill_id,skill_lv,i?1:0);
+ if (sp) status->heal(src, 0, sp, 3);
+ clif->skill_nodamage(src,bl,skill_id,skill_lv,sp?1:0);
+ }
break;
case AC_MAKINGARROW:
@@ -5858,12 +5868,15 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case SR_RAMPAGEBLASTER:
case SR_HOWLINGOFLION:
case KO_HAPPOKUNAI:
+ {
+ int count = 0;
skill->area_temp[1] = 0;
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- i = map->foreachinrange(skill->area_sub, bl, skill->get_splash(skill_id, skill_lv), splash_target(src),
+ count = map->foreachinrange(skill->area_sub, bl, skill->get_splash(skill_id, skill_lv), splash_target(src),
src, skill_id, skill_lv, tick, flag|BCT_ENEMY|SD_SPLASH|1, skill->castend_damage_id);
- if( !i && ( skill_id == NC_AXETORNADO || skill_id == SR_SKYNETBLOW || skill_id == KO_HAPPOKUNAI ) )
+ if( !count && ( skill_id == NC_AXETORNADO || skill_id == SR_SKYNETBLOW || skill_id == KO_HAPPOKUNAI ) )
clif->skill_damage(src,src,tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, 6);
+ }
break;
case NC_EMERGENCYCOOL:
@@ -5911,18 +5924,20 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case HVAN_EXPLOSION: //[orn]
case NPC_SELFDESTRUCTION:
+ {
//Self Destruction hits everyone in range (allies+enemies)
//Except for Summoned Marine spheres on non-versus maps, where it's just enemy.
- i = ((!md || md->special_state.ai == 2) && !map_flag_vs(src->m))?
+ int targetmask = ((!md || md->special_state.ai == 2) && !map_flag_vs(src->m))?
BCT_ENEMY:BCT_ALL;
clif->skill_nodamage(src, src, skill_id, -1, 1);
map->delblock(src); //Required to prevent chain-self-destructions hitting back.
map->foreachinrange(skill->area_sub, bl,
skill->get_splash(skill_id, skill_lv), splash_target(src),
- src, skill_id, skill_lv, tick, flag|i,
+ src, skill_id, skill_lv, tick, flag|targetmask,
skill->castend_damage_id);
map->addblock(src);
status->damage(src, src, sstatus->max_hp,0,0,1);
+ }
break;
case AL_ANGELUS:
@@ -6009,11 +6024,14 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
case SM_AUTOBERSERK:
case MER_AUTOBERSERK:
+ {
+ int failure;
if( tsce )
- i = status_change_end(bl, type, INVALID_TIMER);
+ failure = status_change_end(bl, type, INVALID_TIMER);
else
- i = sc_start(bl,type,100,skill_lv,60000);
- clif->skill_nodamage(src,bl,skill_id,skill_lv,i);
+ failure = sc_start(bl,type,100,skill_lv,60000);
+ clif->skill_nodamage(src,bl,skill_id,skill_lv,failure);
+ }
break;
case TF_HIDING:
case ST_CHASEWALK:
@@ -6046,20 +6064,22 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case SC_REPRODUCE:
case SC_INVISIBILITY:
if (tsce) {
- i = status_change_end(bl, type, INVALID_TIMER);
- if( i )
- clif->skill_nodamage(src,bl,skill_id,( skill_id == LG_FORCEOFVANGUARD ) ? skill_lv : -1,i);
+ int failure = status_change_end(bl, type, INVALID_TIMER);
+ if( failure )
+ clif->skill_nodamage(src,bl,skill_id,( skill_id == LG_FORCEOFVANGUARD ) ? skill_lv : -1,failure);
else if( sd )
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
map->freeblock_unlock();
return 0;
}
case RA_CAMOUFLAGE:
- i = sc_start(bl,type,100,skill_lv,skill->get_time(skill_id,skill_lv));
- if( i )
- clif->skill_nodamage(src,bl,skill_id,( skill_id == LG_FORCEOFVANGUARD ) ? skill_lv : -1,i);
+ {
+ int failure = sc_start(bl,type,100,skill_lv,skill->get_time(skill_id,skill_lv));
+ if( failure )
+ clif->skill_nodamage(src,bl,skill_id,( skill_id == LG_FORCEOFVANGUARD ) ? skill_lv : -1,failure);
else if( sd )
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
+ }
break;
case BD_ADAPTATION:
@@ -6376,18 +6396,18 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case GC_WEAPONCRUSH:
case SC_STRIPACCESSARY: {
unsigned short location = 0;
- int d = 0;
+ int d = 0, rate;
//Rate in percent
if ( skill_id == ST_FULLSTRIP ) {
- i = 5 + 2*skill_lv + (sstatus->dex - tstatus->dex)/5;
+ rate = 5 + 2*skill_lv + (sstatus->dex - tstatus->dex)/5;
} else if( skill_id == SC_STRIPACCESSARY ) {
- i = 12 + 2 * skill_lv + (sstatus->dex - tstatus->dex)/5;
+ rate = 12 + 2 * skill_lv + (sstatus->dex - tstatus->dex)/5;
} else {
- i = 5 + 5*skill_lv + (sstatus->dex - tstatus->dex)/5;
+ rate = 5 + 5*skill_lv + (sstatus->dex - tstatus->dex)/5;
}
- if (i < 5) i = 5; //Minimum rate 5%
+ if (rate < 5) rate = 5; //Minimum rate 5%
//Duration in ms
if( skill_id == GC_WEAPONCRUSH){
@@ -6431,11 +6451,11 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
}
//Attempts to strip at rate i and duration d
- if( (i = skill->strip_equip(bl, location, i, skill_lv, d)) || (skill_id != ST_FULLSTRIP && skill_id != GC_WEAPONCRUSH ) )
- clif->skill_nodamage(src,bl,skill_id,skill_lv,i);
+ if( (rate = skill->strip_equip(bl, location, rate, skill_lv, d)) || (skill_id != ST_FULLSTRIP && skill_id != GC_WEAPONCRUSH ) )
+ clif->skill_nodamage(src,bl,skill_id,skill_lv,rate);
//Nothing stripped.
- if( sd && !i )
+ if( sd && !rate )
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
break;
}
@@ -6601,8 +6621,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
}
break;
case SA_DISPELL:
- if (flag&1 || (i = skill->get_splash(skill_id, skill_lv)) < 1)
- {
+ {
+ int splash;
+ if (flag&1 || (splash = skill->get_splash(skill_id, skill_lv)) < 1) {
+ int i;
if( sd && dstsd && !map_flag_vs(sd->bl.m)
&& (sd->status.party_id == 0 || sd->status.party_id != dstsd->status.party_id) ) {
// Outside PvP it should only affect party members and no skill fail message.
@@ -6653,11 +6675,13 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
status_change_end(bl, (sc_type)i, INVALID_TIMER);
}
break;
+ } else {
+ //Affect all targets on splash area.
+ map->foreachinrange(skill->area_sub, bl, splash, BL_CHAR,
+ src, skill_id, skill_lv, tick, flag|1,
+ skill->castend_damage_id);
}
- //Affect all targets on splash area.
- map->foreachinrange(skill->area_sub, bl, i, BL_CHAR,
- src, skill_id, skill_lv, tick, flag|1,
- skill->castend_damage_id);
+ }
break;
case TF_BACKSLIDING: //This is the correct implementation as per packet logging information. [Skotlex]
@@ -7049,16 +7073,17 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
if( sd && !(sg->unit_id == UNT_USED_TRAPS || (sg->unit_id == UNT_ANKLESNARE && sg->val2 != 0 )) ) {
// prevent picking up expired traps
if( battle_config.skill_removetrap_type ) {
+ int i;
// get back all items used to deploy the trap
for( i = 0; i < 10; i++ ) {
if( skill->db[su->group->skill_id].itemid[i] > 0 ) {
- int flag;
+ int success;
struct item item_tmp;
memset(&item_tmp,0,sizeof(item_tmp));
item_tmp.nameid = skill->db[su->group->skill_id].itemid[i];
item_tmp.identify = 1;
- if( item_tmp.nameid && (flag=pc->additem(sd,&item_tmp,skill->db[su->group->skill_id].amount[i],LOG_TYPE_OTHER)) ) {
- clif->additem(sd,0,0,flag);
+ if( item_tmp.nameid && (success=pc->additem(sd,&item_tmp,skill->db[su->group->skill_id].amount[i],LOG_TYPE_OTHER)) ) {
+ clif->additem(sd,0,0,success);
map->addflooritem(&item_tmp,skill->db[su->group->skill_id].amount[i],sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
}
}
@@ -7479,7 +7504,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
{
int dx[9]={-1, 1, 0, 0,-1, 1,-1, 1, 0};
int dy[9]={ 0, 0, 1,-1, 1,-1,-1, 1, 0};
- int j = 0;
+ int i, j = 0;
struct guild *g;
// i don't know if it actually summons in a circle, but oh well. ;P
g = sd ? sd->guild : guild->search(status->get_guild_id(src));
@@ -7533,10 +7558,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
/* per official standards, this skill works on players and mobs. */
if (sd && (dstsd || dstmd))
{
- i =65 -5*distance_bl(src,bl); //Base rate
- if (i < 30) i = 30;
+ int rate = 65 -5*distance_bl(src,bl); //Base rate
+ if (rate < 30) rate = 30;
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- sc_start(bl,SC_STUN, i,skill_lv,skill->get_time2(skill_id,skill_lv));
+ sc_start(bl,SC_STUN, rate,skill_lv,skill->get_time2(skill_id,skill_lv));
}
break;
@@ -7591,20 +7616,21 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
{
static const int per[5][2]={{20,50},{50,60},{25,75},{60,64},{34,67}};
int r = rnd()%100;
- i = (skill_lv-1)%5;
- if(r<per[i][0]) //Self
+ int target = (skill_lv-1)%5;
+ int hp;
+ if(r<per[target][0]) //Self
bl = src;
- else if(r<per[i][1]) //Master
+ else if(r<per[target][1]) //Master
bl = battle->get_master(src);
else //Enemy
bl = map->id2bl(battle->get_target(src));
if (!bl) bl = src;
- i = skill->calc_heal(src, bl, skill_id, 1+rnd()%skill_lv, true);
+ hp = skill->calc_heal(src, bl, skill_id, 1+rnd()%skill_lv, true);
//Eh? why double skill packet?
- clif->skill_nodamage(src,bl,AL_HEAL,i,1);
- clif->skill_nodamage(src,bl,skill_id,i,1);
- status->heal(bl, i, 0, 0);
+ clif->skill_nodamage(src,bl,AL_HEAL,hp,1);
+ clif->skill_nodamage(src,bl,skill_id,hp,1);
+ status->heal(bl, hp, 0, 0);
}
break;
//Homun single-target support skills [orn]
@@ -7623,7 +7649,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case NPC_DRAGONFEAR:
if (flag&1) {
const enum sc_type sc[] = { SC_STUN, SC_SILENCE, SC_CONFUSION, SC_BLOODING };
- int j;
+ int i, j;
j = i = rnd()%ARRAYLENGTH(sc);
while ( !sc_start2(bl,sc[i],100,skill_lv,src->id,skill->get_time2(skill_id,i+1)) ) {
i++;
@@ -7725,14 +7751,17 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
case RK_IGNITIONBREAK:
case LG_EARTHDRIVE:
+ {
+ int splash;
clif->skill_damage(src,bl,tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, 6);
- i = skill->get_splash(skill_id,skill_lv);
+ splash = skill->get_splash(skill_id,skill_lv);
if( skill_id == LG_EARTHDRIVE ) {
int dummy = 1;
- map->foreachinarea(skill->cell_overlap, src->m, src->x-i, src->y-i, src->x+i, src->y+i, BL_SKILL, LG_EARTHDRIVE, &dummy, src);
+ map->foreachinarea(skill->cell_overlap, src->m, src->x-splash, src->y-splash, src->x+splash, src->y+splash, BL_SKILL, LG_EARTHDRIVE, &dummy, src);
}
- map->foreachinrange(skill->area_sub, bl,i,BL_CHAR,
+ map->foreachinrange(skill->area_sub, bl,splash,BL_CHAR,
src,skill_id,skill_lv,tick,flag|BCT_ENEMY|1,skill->castend_damage_id);
+ }
break;
case RK_STONEHARDSKIN:
if( sd ) {
@@ -7770,8 +7799,8 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
sc_start(bl,type,100,skill->area_temp[5]/4,skill->get_time(skill_id,skill_lv));
} else if( sd ) {
if( sd->status.party_id ) {
- i = party->foreachsamemap(skill->area_sub,sd,skill->get_splash(skill_id,skill_lv),src,skill_id,skill_lv,tick,BCT_PARTY,skill->area_sub_count);
- skill->area_temp[5] = 7 * i; // ATK
+ int members = party->foreachsamemap(skill->area_sub,sd,skill->get_splash(skill_id,skill_lv),src,skill_id,skill_lv,tick,BCT_PARTY,skill->area_sub_count);
+ skill->area_temp[5] = 7 * members; // ATK
party->foreachsamemap(skill->area_sub,sd,skill->get_splash(skill_id,skill_lv),src,skill_id,skill_lv,tick,flag|BCT_PARTY|1,skill->castend_nodamage_id);
} else
sc_start2(bl,type,100,7,5,skill->get_time(skill_id,skill_lv));
@@ -7784,28 +7813,28 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
if( src == bl )
break;
while( skill->area_temp[5] >= 0x10 ){
+ int value = 0;
type = SC_NONE;
- i = 0;
if( skill->area_temp[5]&0x10 ){
if( dstsd ){
- i = (rnd()%100<50) ? 4 : ((rnd()%100<80) ? 3 : 2);
- clif->millenniumshield(dstsd,i);
+ value = (rnd()%100<50) ? 4 : ((rnd()%100<80) ? 3 : 2);
+ clif->millenniumshield(dstsd,value);
skill->area_temp[5] &= ~0x10;
type = SC_MILLENNIUMSHIELD;
}
}else if( skill->area_temp[5]&0x20 ){
- i = status_get_max_hp(bl) * 25 / 100;
+ value = status_get_max_hp(bl) * 25 / 100;
status->change_clear_buffs(bl,4);
skill->area_temp[5] &= ~0x20;
- status->heal(bl,i,0,1);
+ status->heal(bl,value,0,1);
type = SC_REFRESH;
}else if( skill->area_temp[5]&0x40 ){
skill->area_temp[5] &= ~0x40;
type = SC_GIANTGROWTH;
}else if( skill->area_temp[5]&0x80 ){
if( dstsd ){
- i = sstatus->hp / 4;
- if( status->charge(bl,i,0) )
+ value = sstatus->hp / 4;
+ if( status->charge(bl,value,0) )
type = SC_STONEHARDSKIN;
skill->area_temp[5] &= ~0x80;
}
@@ -7818,7 +7847,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
}
if( type > SC_NONE )
clif->skill_nodamage(bl, bl, skill_id, skill_lv,
- sc_start4(bl, type, 100, skill_lv, i, 0, 1, skill->get_time(skill_id, skill_lv)));
+ sc_start4(bl, type, 100, skill_lv, value, 0, 1, skill->get_time(skill_id, skill_lv)));
}
}else if( sd ){
if( tsc && tsc->count ){
@@ -7930,16 +7959,19 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case AB_CLEMENTIA:
case AB_CANTO:
+ {
+ int level = 0;
if( sd )
- i = skill_id == AB_CLEMENTIA ? pc->checkskill(sd,AL_BLESSING) : pc->checkskill(sd,AL_INCAGI);
+ level = skill_id == AB_CLEMENTIA ? pc->checkskill(sd,AL_BLESSING) : pc->checkskill(sd,AL_INCAGI);
if( sd == NULL || sd->status.party_id == 0 || flag&1 )
- clif->skill_nodamage(bl, bl, skill_id, skill_lv, sc_start(bl, type, 100, i + (sd?(sd->status.job_level / 10):0), skill->get_time(skill_id,skill_lv)));
+ clif->skill_nodamage(bl, bl, skill_id, skill_lv, sc_start(bl, type, 100, level + (sd?(sd->status.job_level / 10):0), skill->get_time(skill_id,skill_lv)));
else if( sd ) {
- if( !i )
+ if( !level )
clif->skill_fail(sd,skill_id,USESKILL_FAIL,0);
else
party->foreachsamemap(skill->area_sub, sd, skill->get_splash(skill_id, skill_lv), src, skill_id, skill_lv, tick, flag|BCT_PARTY|1, skill->castend_nodamage_id);
}
+ }
break;
case AB_PRAEFATIO:
@@ -7952,15 +7984,15 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case AB_CHEAL:
if( sd == NULL || sd->status.party_id == 0 || flag&1 ) {
if( sd && tstatus && !battle->check_undead(tstatus->race, tstatus->def_ele) ) {
- i = skill->calc_heal(src, bl, AL_HEAL, pc->checkskill(sd, AL_HEAL), true);
+ int heal = skill->calc_heal(src, bl, AL_HEAL, pc->checkskill(sd, AL_HEAL), true);
if( (dstsd && pc_ismadogear(dstsd)) || status->isimmune(bl))
- i = 0; // Should heal by 0 or won't do anything?? in iRO it breaks the healing to members.. [malufett]
+ heal = 0; // Should heal by 0 or won't do anything?? in iRO it breaks the healing to members.. [malufett]
- clif->skill_nodamage(bl, bl, skill_id, i, 1);
- if( tsc && tsc->data[SC_AKAITSUKI] && i )
- i = ~i + 1;
- status->heal(bl, i, 0, 0);
+ clif->skill_nodamage(bl, bl, skill_id, heal, 1);
+ if( tsc && tsc->data[SC_AKAITSUKI] && heal )
+ heal = ~heal + 1;
+ status->heal(bl, heal, 0, 0);
}
}
else if( sd )
@@ -8015,7 +8047,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
case AB_CLEARANCE:
- if( flag&1 || (i = skill->get_splash(skill_id, skill_lv)) < 1 ) {
+ {
+ int splash;
+ if( flag&1 || (splash = skill->get_splash(skill_id, skill_lv)) < 1 ) {
+ int i;
//As of the behavior in official server Clearance is just a super version of Dispell skill. [Jobbie]
if( bl->type != BL_MOB && battle->check_target(src,bl,BCT_PARTY) <= 0 ) // Only affect mob or party.
break;
@@ -8048,8 +8083,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
status_change_end(bl,(sc_type)i,INVALID_TIMER);
}
break;
+ } else {
+ map->foreachinrange(skill->area_sub, bl, splash, BL_CHAR, src, skill_id, skill_lv, tick, flag|1, skill->castend_damage_id);
}
- map->foreachinrange(skill->area_sub, bl, i, BL_CHAR, src, skill_id, skill_lv, tick, flag|1, skill->castend_damage_id);
+ }
break;
case AB_SILENTIUM:
@@ -8080,9 +8117,9 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
else rate += 40 + 10 * skill_lv; // On Monsters, (40 + 10 * Skill Level) %
if( !(tsc && tsc->data[type]) ){
- i = sc_start2(bl,type,rate,skill_lv,src->id,(src == bl)?5000:(bl->type == BL_PC)?skill->get_time(skill_id,skill_lv):skill->get_time2(skill_id, skill_lv));
- clif->skill_nodamage(src,bl,skill_id,skill_lv,i);
- if( sd && !i )
+ int failure = sc_start2(bl,type,rate,skill_lv,src->id,(src == bl)?5000:(bl->type == BL_PC)?skill->get_time(skill_id,skill_lv):skill->get_time2(skill_id, skill_lv));
+ clif->skill_nodamage(src,bl,skill_id,skill_lv,failure);
+ if( sd && !failure )
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
}
}else
@@ -8127,6 +8164,8 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case WL_SUMMONBL:
case WL_SUMMONWB:
case WL_SUMMONSTONE:
+ {
+ int i;
for( i = SC_SUMMON1; i <= SC_SUMMON5; i++ ){
if( tsc && !tsc->data[i] ){ // officially it doesn't work like a stack
int ele = WLS_FIRE + (skill_id - WL_SUMMONFB) - (skill_id == WL_SUMMONSTONE ? 4 : 0);
@@ -8135,11 +8174,13 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
}
}
+ }
break;
case WL_READING_SB:
if( sd ) {
struct status_change *sc = status->get_sc(bl);
+ int i;
for( i = SC_SPELLBOOK1; i <= SC_SPELLBOOK7; i++)
if( sc && !sc->data[i] )
@@ -8233,13 +8274,16 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
case NC_MAGNETICFIELD:
- if( (i = sc_start2(bl,type,100,skill_lv,src->id,skill->get_time(skill_id,skill_lv))) )
+ {
+ int failure;
+ if( (failure = sc_start2(bl,type,100,skill_lv,src->id,skill->get_time(skill_id,skill_lv))) )
{
map->foreachinrange(skill->area_sub,src,skill->get_splash(skill_id,skill_lv),splash_target(src),src,skill_id,skill_lv,tick,flag|BCT_ENEMY|SD_SPLASH|1,skill->castend_damage_id);;
clif->skill_damage(src,src,tick,status_get_amotion(src),0,-30000,1,skill_id,skill_lv,6);
if (sd) pc->overheat(sd,1);
}
- clif->skill_nodamage(src,src,skill_id,skill_lv,i);
+ clif->skill_nodamage(src,src,skill_id,skill_lv,failure);
+ }
break;
case NC_REPAIR:
@@ -8480,6 +8524,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
case LG_KINGS_GRACE:
if( flag&1 ){
+ int i;
sc_start(bl,type,100,skill_lv,skill->get_time(skill_id,skill_lv));
for(i=0; i<SC_MAX; i++)
{
@@ -8541,6 +8586,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case SR_RAISINGDRAGON:
if( sd ) {
short max = 5 + skill_lv;
+ int i;
sc_start(bl, SC_EXPLOSIONSPIRITS, 100, skill_lv, skill->get_time(skill_id, skill_lv));
for( i = 0; i < max; i++ ) // Don't call more than max available spheres.
pc->addspiritball(sd, skill->get_time(skill_id, skill_lv), max);
@@ -8550,14 +8596,14 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case SR_ASSIMILATEPOWER:
if( flag&1 ) {
- i = 0;
+ int sp = 0;
if( dstsd && dstsd->spiritball && (sd == dstsd || map_flag_vs(src->m)) && (dstsd->class_&MAPID_BASEMASK)!=MAPID_GUNSLINGER )
{
- i = dstsd->spiritball; //1%sp per spiritball.
+ sp = dstsd->spiritball; //1%sp per spiritball.
pc->delspiritball(dstsd, dstsd->spiritball, 0);
}
- if( i ) status_percent_heal(src, 0, i);
- clif->skill_nodamage(src, bl, skill_id, skill_lv, i ? 1:0);
+ if( sp ) status_percent_heal(src, 0, sp);
+ clif->skill_nodamage(src, bl, skill_id, skill_lv, sp ? 1:0);
} else {
clif->skill_damage(src,bl,tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, 6);
map->foreachinrange(skill->area_sub, bl, skill->get_splash(skill_id, skill_lv), splash_target(src), src, skill_id, skill_lv, tick, flag|BCT_ENEMY|BCT_SELF|SD_SPLASH|1, skill->castend_nodamage_id);
@@ -8568,6 +8614,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
if( !dstsd )
break;
if( sd && dstsd->spiritball <= 5 ) {
+ int i;
for(i = 0; i <= 5; i++) {
pc->addspiritball(dstsd, skill->get_time(MO_CALLSPIRITS, pc->checkskill(sd,MO_CALLSPIRITS)), i);
pc->delspiritball(sd, sd->spiritball, 0);
@@ -8609,9 +8656,12 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
sc_start2(bl,type,100,skill_lv,src->id,skill->get_time(skill_id,skill_lv)));
break;
case SR_FLASHCOMBO:
+ {
+ int i;
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
for(i = SR_FLASHCOMBO_ATK_STEP1; i <= SR_FLASHCOMBO_ATK_STEP4; i++)
skill->addtimerskill(src, tick + 500 * (i - SR_FLASHCOMBO_ATK_STEP1), bl->id, 0, 0, i, skill_lv, BF_WEAPON, flag|SD_LEVEL);
+ }
break;
case WA_SWING_DANCE:
case WA_MOONLIT_SERENADE:
@@ -8742,11 +8792,11 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
case WM_RANDOMIZESPELL: {
- int improv_skill_id = 0, improv_skill_lv;
+ int improv_skill_id = 0, improv_skill_lv, improv_idx;
do {
- i = rnd() % MAX_SKILL_IMPROVISE_DB;
- improv_skill_id = skill->improvise_db[i].skill_id;
- } while( improv_skill_id == 0 || rnd()%10000 >= skill->improvise_db[i].per );
+ improv_idx = rnd() % MAX_SKILL_IMPROVISE_DB;
+ improv_skill_id = skill->improvise_db[improv_idx].skill_id;
+ } while( improv_skill_id == 0 || rnd()%10000 >= skill->improvise_db[improv_idx].per );
improv_skill_lv = 4 + skill_lv;
clif->skill_nodamage (src, bl, skill_id, skill_lv, 1);
@@ -8983,10 +9033,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case GN_SLINGITEM:
if( sd ) {
short ammo_id;
- i = sd->equip_index[EQI_AMMO];
- if( i <= 0 )
+ int equip_idx = sd->equip_index[EQI_AMMO];
+ if( equip_idx <= 0 )
break; // No ammo.
- ammo_id = sd->inventory_data[i]->nameid;
+ ammo_id = sd->inventory_data[equip_idx]->nameid;
if( ammo_id <= 0 )
break;
sd->itemid = ammo_id;
@@ -8999,7 +9049,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
} else //Otherwise, it fails, shows animation and removes items.
clif->skill_fail(sd,GN_SLINGITEM_RANGEMELEEATK,0xa,0);
} else if( itemdb_is_GNthrowable(ammo_id) ) {
- struct script_code *scriptroot = sd->inventory_data[i]->script;
+ struct script_code *scriptroot = sd->inventory_data[equip_idx]->script;
if( !scriptroot )
break;
if( dstsd )
@@ -9098,6 +9148,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case KO_KAZEHU_SEIRAN:
case KO_DOHU_KOUKAI:
if(sd) {
+ int i;
int ttype = skill->get_ele(skill_id, skill_lv);
clif->skill_nodamage(src, bl, skill_id, skill_lv, 1);
ARR_FIND(1, 6, i, sd->charm[i] > 0 && ttype != i);
@@ -9109,16 +9160,16 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case KO_ZANZOU:
if(sd) {
- struct mob_data *md;
-
- md = mob->once_spawn_sub(src, src->m, src->x, src->y, status->get_name(src), 2308, "", SZ_MEDIUM, AI_NONE);
- if( md ) {
- md->master_id = src->id;
- md->special_state.ai = AI_ZANZOU;
- if( md->deletetimer != INVALID_TIMER )
- timer->delete(md->deletetimer, mob->timer_delete);
- md->deletetimer = timer->add(timer->gettick() + skill->get_time(skill_id, skill_lv), mob->timer_delete, md->bl.id, 0);
- mob->spawn( md );
+ struct mob_data *summon_md;
+
+ summon_md = mob->once_spawn_sub(src, src->m, src->x, src->y, status->get_name(src), 2308, "", SZ_MEDIUM, AI_NONE);
+ if( summon_md ) {
+ summon_md->master_id = src->id;
+ summon_md->special_state.ai = AI_ZANZOU;
+ if( summon_md->deletetimer != INVALID_TIMER )
+ timer->delete(summon_md->deletetimer, mob->timer_delete);
+ summon_md->deletetimer = timer->add(timer->gettick() + skill->get_time(skill_id, skill_lv), mob->timer_delete, summon_md->bl.id, 0);
+ mob->spawn( summon_md );
pc->setinvincibletimer(sd,500);// unlock target lock
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
skill->blown(src,bl,skill->get_blewcount(skill_id,skill_lv),unit->getdir(bl),0);
@@ -9227,6 +9278,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
};
int heal;
if(tsc){
+ int i;
for (i = 0; i < ARRAYLENGTH(scs); i++) {
if (tsc->data[scs[i]]) status_change_end(bl, scs[i], INVALID_TIMER);
}
@@ -9294,22 +9346,22 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
{
int summons[5] = {1004, 1303, 1303, 1994, 1994};
int qty[5] = {3 , 3 , 4 , 4 , 5};
- struct mob_data *md;
+ struct mob_data *summon_md;
int i, dummy = 0;
- i = map->foreachinmap(skill->check_condition_mob_master_sub ,hd->bl.m, BL_MOB, hd->bl.id, summons[skill_lv-1], skill_id, &dummy);
+ i = map->foreachinmap(skill->check_condition_mob_master_sub, src->m, BL_MOB, src->id, summons[skill_lv-1], skill_id, &dummy);
if(i >= qty[skill_lv-1])
break;
for(i=0; i<qty[skill_lv - 1]; i++){ //easy way
- md = mob->once_spawn_sub(src, src->m, src->x, src->y, status->get_name(src), summons[skill_lv - 1], "", SZ_MEDIUM, AI_ATTACK);
- if (md) {
- md->master_id = src->id;
- if (md->deletetimer != INVALID_TIMER)
- timer->delete(md->deletetimer, mob->timer_delete);
- md->deletetimer = timer->add(timer->gettick() + skill->get_time(skill_id, skill_lv), mob->timer_delete, md->bl.id, 0);
- mob->spawn(md); //Now it is ready for spawning.
- sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_CANATTACK|MD_AGGRESSIVE, 0, 60000);
+ summon_md = mob->once_spawn_sub(src, src->m, src->x, src->y, status->get_name(src), summons[skill_lv - 1], "", SZ_MEDIUM, AI_ATTACK);
+ if (summon_md) {
+ summon_md->master_id = src->id;
+ if (summon_md->deletetimer != INVALID_TIMER)
+ timer->delete(summon_md->deletetimer, mob->timer_delete);
+ summon_md->deletetimer = timer->add(timer->gettick() + skill->get_time(skill_id, skill_lv), mob->timer_delete, summon_md->bl.id, 0);
+ mob->spawn(summon_md); //Now it is ready for spawning.
+ sc_start4(&summon_md->bl, SC_MODECHANGE, 100, 1, 0, MD_CANATTACK|MD_AGGRESSIVE, 0, 60000);
}
}
if (hd)
@@ -9658,7 +9710,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
struct status_change_entry *sce;
struct skill_unit_group* sg;
enum sc_type type;
- int i;
+ int r;
//if(skill_lv <= 0) return 0;
if(skill_id > 0 && !skill_lv) return 0; // celest
@@ -9694,47 +9746,46 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
switch(skill_id) {
case PR_BENEDICTIO:
+ r = skill->get_splash(skill_id, skill_lv);
skill->area_temp[1] = src->id;
- i = skill->get_splash(skill_id, skill_lv);
map->foreachinarea(skill->area_sub,
- src->m, x-i, y-i, x+i, y+i, BL_PC,
+ src->m, x-r, y-r, x+r, y+r, BL_PC,
src, skill_id, skill_lv, tick, flag|BCT_ALL|1,
skill->castend_nodamage_id);
map->foreachinarea(skill->area_sub,
- src->m, x-i, y-i, x+i, y+i, BL_CHAR,
+ src->m, x-r, y-r, x+r, y+r, BL_CHAR,
src, skill_id, skill_lv, tick, flag|BCT_ENEMY|1,
skill->castend_damage_id);
break;
case BS_HAMMERFALL:
- i = skill->get_splash(skill_id, skill_lv);
+ r = skill->get_splash(skill_id, skill_lv);
map->foreachinarea(skill->area_sub,
- src->m, x-i, y-i, x+i, y+i, BL_CHAR,
+ src->m, x-r, y-r, x+r, y+r, BL_CHAR,
src, skill_id, skill_lv, tick, flag|BCT_ENEMY|2,
skill->castend_nodamage_id);
break;
case HT_DETECTING:
- i = skill->get_splash(skill_id, skill_lv);
+ r = skill->get_splash(skill_id, skill_lv);
map->foreachinarea(status->change_timer_sub,
- src->m, x-i, y-i, x+i,y+i,BL_CHAR,
+ src->m, x-r, y-r, x+r,y+r,BL_CHAR,
src,NULL,SC_SIGHT,tick);
if(battle_config.traps_setting&1)
map->foreachinarea(skill_reveal_trap,
- src->m, x-i, y-i, x+i,y+i,BL_SKILL);
+ src->m, x-r, y-r, x+r, y+r, BL_SKILL);
break;
case SR_RIDEINLIGHTNING:
- i = skill->get_splash(skill_id, skill_lv);
- map->foreachinarea(skill->area_sub, src->m, x-i, y-i, x+i, y+i, BL_CHAR,
+ r = skill->get_splash(skill_id, skill_lv);
+ map->foreachinarea(skill->area_sub, src->m, x-r, y-r, x+r, y+r, BL_CHAR,
src, skill_id, skill_lv, tick, flag|BCT_ENEMY|1, skill->castend_damage_id);
break;
case SA_VOLCANO:
case SA_DELUGE:
case SA_VIOLENTGALE:
- { //Does not consumes if the skill is already active. [Skotlex]
- struct skill_unit_group *sg;
+ //Does not consumes if the skill is already active. [Skotlex]
if ((sg= skill->locate_element_field(src)) != NULL && ( sg->skill_id == SA_VOLCANO || sg->skill_id == SA_DELUGE || sg->skill_id == SA_VIOLENTGALE ))
{
if (sg->limit - DIFF_TICK(timer->gettick(), sg->tick) > 0) {
@@ -9745,7 +9796,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
}
skill->unitsetting(src,skill_id,skill_lv,x,y,0);
break;
- }
+
case MG_SAFETYWALL:
case MG_FIREWALL:
case MG_THUNDERSTORM:
@@ -9888,8 +9939,8 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
flag|=1;
break;
case RG_CLEANER: // [Valaris]
- i = skill->get_splash(skill_id, skill_lv);
- map->foreachinarea(skill->graffitiremover,src->m,x-i,y-i,x+i,y+i,BL_SKILL);
+ r = skill->get_splash(skill_id, skill_lv);
+ map->foreachinarea(skill->graffitiremover,src->m,x-r,y-r,x+r,y+r,BL_SKILL);
break;
case SO_WARMER:
@@ -9898,9 +9949,11 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
skill->unitsetting(src,skill_id,skill_lv,x,y,0);
break;
- case WZ_METEOR: {
+ case WZ_METEOR:
+ {
int area = skill->get_splash(skill_id, skill_lv);
short tmpx = 0, tmpy = 0, x1 = 0, y1 = 0;
+ int i;
for( i = 0; i < 2 + (skill_lv>>1); i++ ) {
// Creates a random Cell in the Splash Area
@@ -10033,8 +10086,8 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
if (rnd()%100 < 80) {
int dummy = 1;
clif->skill_poseffect(src,skill_id,skill_lv,x,y,tick);
- i = skill->get_splash(skill_id, skill_lv);
- map->foreachinarea(skill->cell_overlap, src->m, x-i, y-i, x+i, y+i, BL_SKILL, HW_GANBANTEIN, &dummy, src);
+ r = skill->get_splash(skill_id, skill_lv);
+ map->foreachinarea(skill->cell_overlap, src->m, x-r, y-r, x+r, y+r, BL_SKILL, HW_GANBANTEIN, &dummy, src);
} else {
if (sd) clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return 1;
@@ -10115,14 +10168,14 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
case NC_ARMSCANNON:
case RK_DRAGONBREATH:
case RK_DRAGONBREATH_WATER:
- i = skill->get_splash(skill_id,skill_lv);
- map->foreachinarea(skill->area_sub,src->m,x-i,y-i,x+i,y+i,splash_target(src),
+ r = skill->get_splash(skill_id,skill_lv);
+ map->foreachinarea(skill->area_sub,src->m,x-r,y-r,x+r,y+r,splash_target(src),
src,skill_id,skill_lv,tick,flag|BCT_ENEMY|1,skill->castend_damage_id);
break;
case SO_ARRULLO:
- i = skill->get_splash(skill_id,skill_lv);
- map->foreachinarea(skill->area_sub,src->m,x-i,y-i,x+i,y+i,splash_target(src),
+ r = skill->get_splash(skill_id,skill_lv);
+ map->foreachinarea(skill->area_sub,src->m,x-r,y-r,x+r,y+r,splash_target(src),
src, skill_id, skill_lv, tick, flag|BCT_ENEMY|1, skill->castend_nodamage_id);
break;
/**
@@ -10143,8 +10196,8 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
**/
case AB_EPICLESIS:
if( (sg = skill->unitsetting(src, skill_id, skill_lv, x, y, 0)) ) {
- i = sg->unit->range;
- map->foreachinarea(skill->area_sub, src->m, x - i, y - i, x + i, y + i, BL_CHAR, src, ALL_RESURRECTION, 1, tick, flag|BCT_NOENEMY|1,skill->castend_nodamage_id);
+ r = sg->unit->range;
+ map->foreachinarea(skill->area_sub, src->m, x - r, y - r, x + r, y + r, BL_CHAR, src, ALL_RESURRECTION, 1, tick, flag|BCT_NOENEMY|1,skill->castend_nodamage_id);
}
break;
@@ -10169,8 +10222,8 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
* Ranger
**/
case RA_DETONATOR:
- i = skill->get_splash(skill_id, skill_lv);
- map->foreachinarea(skill->detonator, src->m, x-i, y-i, x+i, y+i, BL_SKILL, src);
+ r = skill->get_splash(skill_id, skill_lv);
+ map->foreachinarea(skill->detonator, src->m, x-r, y-r, x+r, y+r, BL_SKILL, src);
clif->skill_damage(src, src, tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, 6);
break;
/**
@@ -10222,6 +10275,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
case LG_OVERBRAND:
{
int width;//according to data from irowiki it actually is a square
+ int i;
for( width = 0; width < 7; width++ )
for( i = 0; i < 7; i++ )
map->foreachincell(skill->area_sub, src->m, x-2+i, y-2+width, splash_target(src), src, LG_OVERBRAND_BRANDISH, skill_lv, tick, flag|BCT_ENEMY,skill->castend_damage_id);
@@ -10243,26 +10297,28 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
case LG_RAYOFGENESIS:
if( status->charge(src,status_get_max_hp(src)*3*skill_lv / 100,0) ) {
- i = skill->get_splash(skill_id,skill_lv);
- map->foreachinarea(skill->area_sub,src->m,x-i,y-i,x+i,y+i,splash_target(src),
+ r = skill->get_splash(skill_id,skill_lv);
+ map->foreachinarea(skill->area_sub,src->m,x-r,y-r,x+r,y+r,splash_target(src),
src,skill_id,skill_lv,tick,flag|BCT_ENEMY|1,skill->castend_damage_id);
} else if( sd )
clif->skill_fail(sd,skill_id,USESKILL_FAIL,0);
break;
case WM_DOMINION_IMPULSE:
- i = skill->get_splash(skill_id, skill_lv);
+ r = skill->get_splash(skill_id, skill_lv);
map->foreachinarea( skill->activate_reverberation,
- src->m, x-i, y-i, x+i,y+i,BL_SKILL);
+ src->m, x-r, y-r, x+r,y+r,BL_SKILL);
break;
case WM_GREAT_ECHO:
flag|=1; // Should counsume 1 item per skill usage.
map->foreachinrange(skill->area_sub, src, skill->get_splash(skill_id,skill_lv),splash_target(src), src, skill_id, skill_lv, tick, flag|BCT_ENEMY, skill->castend_damage_id);
break;
- case GN_CRAZYWEED: {
+ case GN_CRAZYWEED:
+ {
int area = skill->get_splash(GN_CRAZYWEED_ATK, skill_lv);
short x1 = 0, y1 = 0;
+ int i;
for( i = 0; i < 3 + (skill_lv/2); i++ ) {
x1 = x - area + rnd()%(area * 2 + 1);
@@ -10315,11 +10371,14 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
break;
case KO_MAKIBISHI:
+ {
+ int i;
for( i = 0; i < (skill_lv+2); i++ ) {
x = src->x - 1 + rnd()%3;
y = src->y - 1 + rnd()%3;
skill->unitsetting(src,skill_id,skill_lv,x,y,0);
}
+ }
break;
default:
@@ -10848,9 +10907,9 @@ struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_
struct skill_unit *su;
int ux = x + layout->dx[i];
int uy = y + layout->dy[i];
- int val1 = skill_lv;
- int val2 = 0;
int alive = 1;
+ val1 = skill_lv;
+ val2 = 0;
if( !group->state.song_dance && !map->getcell(src->m,ux,uy,CELL_CHKREACH) )
continue; // don't place skill units on walls (except for songs/dances/encores)
@@ -12294,7 +12353,6 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
struct status_data *st;
struct status_change *sc;
struct skill_condition require;
- int i;
nullpo_ret(sd);
@@ -12336,6 +12394,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
if( sd->state.abra_flag ) // Hocus-Pocus was used. [Inkfish]
sd->state.abra_flag = 0;
else {
+ int i;
// When a target was selected, consume items that were skipped in pc_use_item [Skotlex]
if( (i = sd->itemindex) == -1 ||
sd->status.inventory[i].nameid != sd->itemid ||
@@ -12489,34 +12548,38 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
return 0;
if(sc->data[SC_BLADESTOP])
break;
- if( (i=(sc && sc->data[SC_COMBOATTACK])) && sc->data[SC_COMBOATTACK]->val1 == MO_TRIPLEATTACK )
- break;
- if( i )
+ if( sc && sc->data[SC_COMBOATTACK] ) {
+ if( sc->data[SC_COMBOATTACK]->val1 == MO_TRIPLEATTACK )
+ break;
clif->skill_fail(sd, skill_id, USESKILL_FAIL_COMBOSKILL, MO_TRIPLEATTACK);
+ }
return 0;
case MO_COMBOFINISH:
if(!sc)
return 0;
- if( (i=(sc && sc->data[SC_COMBOATTACK])) && sc->data[SC_COMBOATTACK]->val1 == MO_CHAINCOMBO )
- break;
- if( i )
+ if( sc && sc->data[SC_COMBOATTACK] ) {
+ if ( sc->data[SC_COMBOATTACK]->val1 == MO_CHAINCOMBO )
+ break;
clif->skill_fail(sd, skill_id, USESKILL_FAIL_COMBOSKILL, MO_CHAINCOMBO);
+ }
return 0;
case CH_TIGERFIST:
if(!sc)
return 0;
- if( (i=(sc && sc->data[SC_COMBOATTACK])) && sc->data[SC_COMBOATTACK]->val1 == MO_COMBOFINISH )
- break;
- if( i )
+ if( sc && sc->data[SC_COMBOATTACK] ) {
+ if ( sc->data[SC_COMBOATTACK]->val1 == MO_COMBOFINISH )
+ break;
clif->skill_fail(sd, skill_id, USESKILL_FAIL_COMBOSKILL, MO_COMBOFINISH);
+ }
return 0;
case CH_CHAINCRUSH:
if(!sc)
return 0;
- if( (i=(sc && sc->data[SC_COMBOATTACK])) && sc->data[SC_COMBOATTACK]->val1 == CH_TIGERFIST )
- break;
- if( i )
+ if( sc && sc->data[SC_COMBOATTACK] ) {
+ if( sc->data[SC_COMBOATTACK]->val1 == CH_TIGERFIST )
+ break;
clif->skill_fail(sd, skill_id, USESKILL_FAIL_COMBOSKILL, CH_TIGERFIST);
+ }
return 0;
case MO_EXTREMITYFIST:
// if(sc && sc->data[SC_EXTREMITYFIST]) //To disable Asura during the 5 min skill block uncomment this...
@@ -12664,8 +12727,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
case SG_STAR_WARM:
if (sc && sc->data[SC_MIRACLE])
break;
- i = skill_id-SG_SUN_WARM;
- if (sd->bl.m == sd->feel_map[i].m)
+ if (sd->bl.m == sd->feel_map[skill_id-SG_SUN_WARM].m)
break;
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return 0;
@@ -12675,9 +12737,8 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
case SG_STAR_COMFORT:
if (sc && sc->data[SC_MIRACLE])
break;
- i = skill_id-SG_SUN_COMFORT;
- if (sd->bl.m == sd->feel_map[i].m &&
- (battle_config.allow_skill_without_day || pc->sg_info[i].day_func()))
+ if (sd->bl.m == sd->feel_map[skill_id-SG_SUN_COMFORT].m &&
+ (battle_config.allow_skill_without_day || pc->sg_info[skill_id-SG_SUN_COMFORT].day_func()))
break;
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return 0;
@@ -12758,7 +12819,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
**/
case AB_ANCILLA:
{
- int count = 0;
+ int count = 0, i;
for( i = 0; i < MAX_INVENTORY; i ++ )
if( sd->status.inventory[i].nameid == ITEMID_ANCILLA )
count += sd->status.inventory[i].amount;
@@ -12785,12 +12846,15 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
* Warlock
**/
case WL_COMET:
- if( skill->check_pc_partner(sd,skill_id,&skill_lv,1,0) <= 0 && ((i = pc->search_inventory(sd,require.itemid[0])) < 0 || sd->status.inventory[i].amount < require.amount[0]) )
+ {
+ int idx;
+ if( skill->check_pc_partner(sd,skill_id,&skill_lv,1,0) <= 0 && ((idx = pc->search_inventory(sd,require.itemid[0])) < 0 || sd->status.inventory[idx].amount < require.amount[0]) )
{
//clif->skill_fail(sd,skill_id,USESKILL_FAIL_NEED_ITEM,require.amount[0],require.itemid[0]);
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return 0;
}
+ }
break;
case WL_SUMMONFB:
case WL_SUMMONBL:
@@ -12799,10 +12863,9 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
case WL_TETRAVORTEX:
case WL_RELEASE:
{
- int x = SC_SUMMON1;
- i = 0;
- for(; x <= SC_SUMMON5; x++)
- if( sc && sc->data[x] )
+ int j, i = 0;
+ for(j = SC_SUMMON1; j <= SC_SUMMON5; j++)
+ if( sc && sc->data[j] )
i++;
switch(skill_id){
@@ -12813,8 +12876,8 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
}
break;
case WL_RELEASE:
- for(x = SC_SPELLBOOK7; x >= SC_SPELLBOOK1; x--)
- if( sc && sc->data[x] )
+ for(j = SC_SPELLBOOK7; j >= SC_SPELLBOOK1; j--)
+ if( sc && sc->data[j] )
i++;
if( i == 0 ){
clif->skill_fail(sd,skill_id,USESKILL_FAIL_SUMMON_NONE,0);
@@ -12910,12 +12973,11 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
}
break;
case SR_FALLENEMPIRE:
- if( !sc )
- return 0;
- if( (i=(sc && sc->data[SC_COMBOATTACK])) && sc->data[SC_COMBOATTACK]->val1 == SR_DRAGONCOMBO )
- break;
- if( i )
+ if( sc && sc->data[SC_COMBOATTACK] ) {
+ if( sc->data[SC_COMBOATTACK]->val1 == SR_DRAGONCOMBO )
+ break;
clif->skill_fail(sd, skill_id, USESKILL_FAIL_COMBOSKILL, SR_DRAGONCOMBO);
+ }
return 0;
case SR_CRESCENTELBOW:
if( sc && sc->data[SC_CRESCENTELBOW] ) {
@@ -13002,11 +13064,14 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
break;
case KO_KAIHOU:
case KO_ZENKAI:
- ARR_FIND(1, 6, i, sd->charm[i] > 0);
+ {
+ int i;
+ ARR_FIND(1, 6, i, sd->charm[i] > 0); // FIXME: 4 or 6?
if( i > 4 ) {
clif->skill_fail(sd,skill_id,USESKILL_FAIL_SUMMON,0);
return 0;
}
+ }
break;
}
@@ -14887,17 +14952,17 @@ int skill_chastle_mob_changetarget(struct block_list *bl,va_list ap)
int skill_trap_splash(struct block_list *bl, va_list ap) {
struct block_list *src;
int64 tick;
- struct skill_unit *su;
+ struct skill_unit *src_su;
struct skill_unit_group *sg;
struct block_list *ss;
src = va_arg(ap,struct block_list *);
- su = (struct skill_unit *)src;
+ src_su = (struct skill_unit *)src;
tick = va_arg(ap,int64);
- if( !su->alive || bl->prev == NULL )
+ if( !src_su->alive || bl->prev == NULL )
return 0;
- nullpo_ret(sg = su->group);
+ nullpo_ret(sg = src_su->group);
nullpo_ret(ss = map->id2bl(sg->src_id));
if(battle->check_target(src,bl,sg->target_flag) <= 0)
@@ -16101,11 +16166,11 @@ int skill_produce_mix(struct map_session_data *sd, uint16 skill_id, int nameid,
}
if( skill_id == RK_RUNEMASTERY ) {
- int temp_qty, skill_lv = pc->checkskill(sd,skill_id);
+ int temp_qty, rune_skill_lv = pc->checkskill(sd,skill_id);
data = itemdb->search(nameid);
- if( skill_lv == 10 ) temp_qty = 1 + rnd()%3;
- else if( skill_lv > 5 ) temp_qty = 1 + rnd()%2;
+ if( rune_skill_lv == 10 ) temp_qty = 1 + rnd()%3;
+ else if( rune_skill_lv > 5 ) temp_qty = 1 + rnd()%2;
else temp_qty = 1;
if (data->stack.inventory) {
@@ -17844,8 +17909,8 @@ bool skill_parse_row_unitdb(char* split[], int columns, int current) {
if( !idx ) // invalid skill id
return false;
- skill->db[idx].unit_id[0] = strtol(split[1],NULL,16);
- skill->db[idx].unit_id[1] = strtol(split[2],NULL,16);
+ skill->db[idx].unit_id[0] = (int)strtol(split[1],NULL,16);
+ skill->db[idx].unit_id[1] = (int)strtol(split[2],NULL,16);
skill->split_atoi(split[3],skill->db[idx].unit_layout_type);
skill->split_atoi(split[4],skill->db[idx].unit_range);
skill->db[idx].unit_interval = atoi(split[5]);
@@ -17860,9 +17925,9 @@ bool skill_parse_row_unitdb(char* split[], int columns, int current) {
else if( strcmpi(split[6],"self")==0 ) skill->db[idx].unit_target = BCT_SELF;
else if( strcmpi(split[6],"sameguild")==0 ) skill->db[idx].unit_target = BCT_GUILD|BCT_SAMEGUILD;
else if( strcmpi(split[6],"noone")==0 ) skill->db[idx].unit_target = BCT_NOONE;
- else skill->db[idx].unit_target = strtol(split[6],NULL,16);
+ else skill->db[idx].unit_target = (int)strtol(split[6],NULL,16);
- skill->db[idx].unit_flag = strtol(split[7],NULL,16);
+ skill->db[idx].unit_flag = (int)strtol(split[7],NULL,16);
if (skill->db[idx].unit_flag&UF_DEFNOTENEMY && battle_config.defnotenemy)
skill->db[idx].unit_target = BCT_NOENEMY;
diff --git a/src/map/status.c b/src/map/status.c
index ed29bacf9..6cfd799f1 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -1418,34 +1418,28 @@ int status_percent_change(struct block_list *src,struct block_list *target,signe
st = status->get_status_data(target);
-
- //It's safe now [MarkZD]
- if (hp_rate > 99)
- hp = st->hp;
- else if (hp_rate > 0)
- hp = st->hp>10000?
- hp_rate*(st->hp/100):
- ((int64)hp_rate*st->hp)/100;
- else if (hp_rate < -99)
- hp = st->max_hp;
- else if (hp_rate < 0)
- hp = st->max_hp>10000?
- (-hp_rate)*(st->max_hp/100):
- ((int64)-hp_rate*st->max_hp)/100;
+ if (hp_rate > 100)
+ hp_rate = 100;
+ else if (hp_rate < -100)
+ hp_rate = -100;
+ if (hp_rate > 0)
+ hp = APPLY_RATE(st->hp, hp_rate);
+ else
+ hp = APPLY_RATE(st->max_hp, -hp_rate);
if (hp_rate && !hp)
hp = 1;
if (flag == 2 && hp >= st->hp)
hp = st->hp-1; //Must not kill target.
- if (sp_rate > 99)
- sp = st->sp;
- else if (sp_rate > 0)
- sp = ((int64)sp_rate*st->sp)/100;
- else if (sp_rate < -99)
- sp = st->max_sp;
- else if (sp_rate < 0)
- sp = ((int64)-sp_rate)*st->max_sp/100;
+ if (sp_rate > 100)
+ sp_rate = 100;
+ else if (sp_rate < -100)
+ sp_rate = -100;
+ if (sp_rate > 0)
+ sp = APPLY_RATE(st->sp, sp_rate);
+ else
+ sp = APPLY_RATE(st->max_sp, -sp_rate);
if (sp_rate && !sp)
sp = 1;
@@ -1479,8 +1473,8 @@ int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per
if (st == &status->dummy)
return 0; //Invalid target.
- hp = (int64)st->max_hp * per_hp/100;
- sp = (int64)st->max_sp * per_sp/100;
+ hp = APPLY_RATE(st->max_hp, per_hp);
+ sp = APPLY_RATE(st->max_sp, per_sp);
if(hp > st->max_hp - st->hp)
hp = st->max_hp - st->hp;
@@ -2059,12 +2053,12 @@ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) {
mbl = map->id2bl(md->master_id);
if (flag&8 && mbl) {
- struct status_data *mstatus;
- if ( (mstatus = status->get_base_status(mbl)) ) {
- if( battle_config.slaves_inherit_speed&(mstatus->mode&MD_CANMOVE?1:2) )
- mstatus->speed = mstatus->speed;
- if( mstatus->speed < 2 ) /* minimum for the unit to function properly */
- mstatus->speed = 2;
+ struct status_data *masterstatus = status->get_base_status(mbl);
+ if ( masterstatus ) {
+ if( battle_config.slaves_inherit_speed&(masterstatus->mode&MD_CANMOVE?1:2) )
+ masterstatus->speed = masterstatus->speed;
+ if( masterstatus->speed < 2 ) /* minimum for the unit to function properly */
+ masterstatus->speed = 2;
}
}
@@ -2778,9 +2772,9 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
if(sd->hprate < 0)
sd->hprate = 0;
if(sd->hprate!=100)
- bstatus->max_hp = (int64)bstatus->max_hp * sd->hprate/100;
+ bstatus->max_hp = APPLY_RATE(bstatus->max_hp, sd->hprate);
if(battle_config.hp_rate != 100)
- bstatus->max_hp = (int64)bstatus->max_hp * battle_config.hp_rate/100;
+ bstatus->max_hp = APPLY_RATE(bstatus->max_hp, battle_config.hp_rate);
if(bstatus->max_hp > (unsigned int)battle_config.max_hp)
bstatus->max_hp = battle_config.max_hp;
@@ -2812,9 +2806,9 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
if(sd->sprate < 0)
sd->sprate = 0;
if(sd->sprate!=100)
- bstatus->max_sp = (int64)bstatus->max_sp * sd->sprate/100;
+ bstatus->max_sp = APPLY_RATE(bstatus->max_sp, sd->sprate);
if(battle_config.sp_rate != 100)
- bstatus->max_sp = (int64)bstatus->max_sp * battle_config.sp_rate/100;
+ bstatus->max_sp = APPLY_RATE(bstatus->max_sp, battle_config.sp_rate);
if(bstatus->max_sp > (unsigned int)battle_config.max_sp)
bstatus->max_sp = battle_config.max_sp;
@@ -2833,11 +2827,11 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
&& battle_config.restart_hp_rate < 50)
bstatus->hp = bstatus->max_hp>>1;
else
- bstatus->hp = (int64)bstatus->max_hp * battle_config.restart_hp_rate/100;
+ bstatus->hp = APPLY_RATE(bstatus->max_hp, battle_config.restart_hp_rate);
if(!bstatus->hp)
bstatus->hp = 1;
- bstatus->sp = (int64)bstatus->max_sp * battle_config.restart_sp_rate /100;
+ bstatus->sp = APPLY_RATE(bstatus->max_sp, battle_config.restart_sp_rate);
if( !bstatus->sp ) /* the minimum for the respawn setting is SP:1 */
bstatus->sp = 1;
@@ -6573,10 +6567,8 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
case SC_NIBELUNGEN:
case SC_INTOABYSS:
case SC_SIEGFRIED:
- if( bl->type == BL_PC) {
- struct map_session_data *sd = BL_CAST(BL_PC,bl);
- if (!sd->status.party_id) return 0;
- }
+ if( sd && !sd->status.party_id )
+ return 0;
break;
case SC_ANGRIFFS_MODUS:
case SC_GOLDENE_FERSE:
@@ -7302,7 +7294,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
val2 = val1*20; //SP gained
break;
case SC_KYRIE:
- val2 = (int64)st->max_hp * (val1 * 2 + 10) / 100; //%Max HP to absorb
+ val2 = APPLY_RATE(st->max_hp, (val1 * 2 + 10)); //%Max HP to absorb
val3 = (val1 / 2 + 5); //Hits
break;
case SC_MAGICPOWER:
@@ -9402,15 +9394,15 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
case SC_BLADESTOP:
if(sce->val4) {
- int tid = sce->val4;
- struct block_list *tbl = map->id2bl(tid);
+ int target_id = sce->val4;
+ struct block_list *tbl = map->id2bl(target_id);
struct status_change *tsc = status->get_sc(tbl);
sce->val4 = 0;
if(tbl && tsc && tsc->data[SC_BLADESTOP]) {
tsc->data[SC_BLADESTOP]->val4 = 0;
status_change_end(tbl, SC_BLADESTOP, INVALID_TIMER);
}
- clif->bladestop(bl, tid, 0);
+ clif->bladestop(bl, target_id, 0);
}
break;
case SC_DANCING:
@@ -9708,8 +9700,8 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
case SC_CURSEDCIRCLE_TARGET:
{
struct block_list *src = map->id2bl(sce->val2);
- struct status_change *sc = status->get_sc(src);
- if( sc && sc->data[SC_CURSEDCIRCLE_ATKER] && --(sc->data[SC_CURSEDCIRCLE_ATKER]->val2) == 0 ){
+ struct status_change *ssc = status->get_sc(src);
+ if( ssc && ssc->data[SC_CURSEDCIRCLE_ATKER] && --(ssc->data[SC_CURSEDCIRCLE_ATKER]->val2) == 0 ){
status_change_end(src, SC_CURSEDCIRCLE_ATKER, INVALID_TIMER);
clif->bladestop(bl, sce->val2, 0);
}
@@ -9719,8 +9711,8 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
if( sce->val2 ){
struct block_list *src = map->id2bl(sce->val2);
if(src) {
- struct status_change *sc = status->get_sc(src);
- sc->bs_counter--;
+ struct status_change *ssc = status->get_sc(src);
+ ssc->bs_counter--;
}
}
break;
@@ -10977,7 +10969,7 @@ int status_get_matk(struct block_list *bl, int flag) {
st->matk_min = status_base_matk_min(st) + (sd?sd->bonus.ematk:0);
st->matk_max = status_base_matk_max(st) + (sd?sd->bonus.ematk:0);
#endif
- if (bl->type&BL_PC && sd->matk_rate != 100) {
+ if (sd && sd->matk_rate != 100) {
st->matk_max = st->matk_max * sd->matk_rate/100;
st->matk_min = st->matk_min * sd->matk_rate/100;
}
diff --git a/src/map/status.h b/src/map/status.h
index 2a281aef4..cdf3e03d6 100644
--- a/src/map/status.h
+++ b/src/map/status.h
@@ -14,6 +14,21 @@ struct homun_data;
struct mercenary_data;
struct status_change;
+//Change the equation when the values are high enough to discard the
+//imprecision in exchange of overflow protection [Skotlex]
+//Also add 100% checks since those are the most used cases where we don't
+//want aproximation errors.
+#define APPLY_RATE(value, rate) ( \
+ (rate) == 100 ? \
+ (value) \
+ : ( \
+ (value) > 100000 ? \
+ (rate) * ( (value) / 100 ) \
+ : \
+ (value) * (rate) / 100 \
+ ) \
+)
+
/**
* Max Refine available to your server
* Changing this limit requires edits to refine_db.txt
diff --git a/src/map/unit.c b/src/map/unit.c
index 28dd68e7d..7f722684d 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -670,15 +670,15 @@ int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool
if( sd->status.pet_id > 0 && sd->pd && sd->pd->pet.intimate > 0 )
{ // Check if pet needs to be teleported. [Skotlex]
int flag = 0;
- struct block_list* bl = &sd->pd->bl;
- if( !checkpath && !path->search(NULL,bl->m,bl->x,bl->y,dst_x,dst_y,0,CELL_CHKNOPASS) )
+ struct block_list* pbl = &sd->pd->bl;
+ if( !checkpath && !path->search(NULL,pbl->m,pbl->x,pbl->y,dst_x,dst_y,0,CELL_CHKNOPASS) )
flag = 1;
- else if (!check_distance_bl(&sd->bl, bl, AREA_SIZE)) //Too far, teleport.
+ else if (!check_distance_bl(&sd->bl, pbl, AREA_SIZE)) //Too far, teleport.
flag = 2;
if( flag )
{
- unit->movepos(bl,sd->bl.x,sd->bl.y, 0, 0);
- clif->slide(bl,bl->x,bl->y);
+ unit->movepos(pbl,sd->bl.x,sd->bl.y, 0, 0);
+ clif->slide(pbl,pbl->x,pbl->y);
}
}
}
@@ -720,6 +720,8 @@ int unit_blown(struct block_list* bl, int dx, int dy, int count, int flag)
struct skill_unit* su = NULL;
int nx, ny, result;
+ nullpo_ret(bl);
+
sd = BL_CAST(BL_PC, bl);
su = BL_CAST(BL_SKILL, bl);
diff --git a/src/tool/Makefile.in b/src/tool/Makefile.in
index 307aa6d2c..3d0de1122 100644
--- a/src/tool/Makefile.in
+++ b/src/tool/Makefile.in
@@ -4,9 +4,9 @@ CONFIG_H = $(wildcard $(CONFIG_D)/*.h) $(wildcard $(CONFIG_D)/*/*.h)
COMMON_D = ../common
COMMON_OBJ = $(addprefix $(COMMON_D)/obj_all/, des.o grfio.o malloc.o \
- miniconsole.o minicore.o showmsg.o strlib.o utils.o)
+ nullpo.o miniconsole.o minicore.o showmsg.o strlib.o utils.o)
COMMON_H = $(addprefix $(COMMON_D)/, cbasetypes.h console.h core.h des.h \
- grfio.h malloc.h mmo.h showmsg.h strlib.h utils.h)
+ grfio.h malloc.h mmo.h nullpo.h showmsg.h strlib.h utils.h)
LIBCONFIG_D = ../../3rdparty/libconfig
LIBCONFIG_OBJ = $(addprefix $(LIBCONFIG_D)/, libconfig.o grammar.o scanctx.o \
diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c
index 49f948709..caa55c87a 100644
--- a/src/tool/mapcache.c
+++ b/src/tool/mapcache.c
@@ -181,7 +181,7 @@ void cache_map(char *name, struct map_data *m)
strncpy(info.name, name, MAP_NAME_LENGTH);
info.xs = MakeShortLE(m->xs);
info.ys = MakeShortLE(m->ys);
- info.len = MakeLongLE(len);
+ info.len = MakeLongLE((uint32)len);
// Append map header then compressed cells at the end of the file
fseek(map_cache_fp, header.file_size, SEEK_SET);