summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/char/char.c2
-rw-r--r--src/char/char.h2
-rw-r--r--src/char/inter.h9
-rw-r--r--src/common/HPM.c1
-rw-r--r--src/common/HPM.h24
-rw-r--r--src/common/HPMi.h32
-rw-r--r--src/common/cbasetypes.h10
-rw-r--r--src/common/console.c4
-rw-r--r--src/common/core.c2
-rw-r--r--src/common/db.c2
-rw-r--r--src/common/db.h12
-rw-r--r--src/common/ers.h10
-rw-r--r--src/common/grfio.h2
-rw-r--r--src/common/malloc.c64
-rw-r--r--src/common/malloc.h16
-rw-r--r--src/common/mapindex.h2
-rw-r--r--src/common/mempool.c10
-rw-r--r--src/common/mmo.h2
-rw-r--r--src/common/netbuffer.h10
-rw-r--r--src/common/network.c2
-rw-r--r--src/common/raconf.c29
-rw-r--r--src/common/showmsg.c111
-rw-r--r--src/common/socket.c26
-rw-r--r--src/common/socket.h21
-rw-r--r--src/common/spinlock.h4
-rw-r--r--src/common/sql.h14
-rw-r--r--src/common/strlib.h32
-rw-r--r--src/common/timer.h2
-rw-r--r--src/common/utils.h2
-rw-r--r--src/config/const.h7
-rw-r--r--src/login/login.h4
-rw-r--r--src/map/atcommand.c69
-rw-r--r--src/map/battle.c50
-rw-r--r--src/map/battle.h14
-rw-r--r--src/map/chrif.c2
-rw-r--r--src/map/clif.c4
-rw-r--r--src/map/clif.h2
-rw-r--r--src/map/elemental.h4
-rw-r--r--src/map/homunculus.h2
-rw-r--r--src/map/intif.c2
-rw-r--r--src/map/intif.h6
-rw-r--r--src/map/itemdb.h75
-rw-r--r--src/map/map.c4
-rw-r--r--src/map/map.h18
-rw-r--r--src/map/mob.c2
-rw-r--r--src/map/mob.h7
-rw-r--r--src/map/path.h12
-rw-r--r--src/map/pc.h30
-rw-r--r--src/map/pet.h4
-rw-r--r--src/map/script.c15
-rw-r--r--src/map/script.h37
-rw-r--r--src/map/skill.c36
-rw-r--r--src/map/status.c32
-rw-r--r--src/map/status.h106
54 files changed, 495 insertions, 508 deletions
diff --git a/src/char/char.c b/src/char/char.c
index f1b95474e..a1c6f73b1 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -3933,7 +3933,7 @@ int parse_char(int fd)
while( RFIFOREST(fd) >= 2 ) {
//For use in packets that depend on an sd being present [Skotlex]
- #define FIFOSD_CHECK(rest) { if(RFIFOREST(fd) < rest) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,rest); return 0; } }
+ #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)) ) {
diff --git a/src/char/char.h b/src/char/char.h
index c7a387645..c6aa1b66d 100644
--- a/src/char/char.h
+++ b/src/char/char.h
@@ -48,7 +48,7 @@ DBMap* online_char_db; // int account_id -> struct online_char_data*
#define MAX_MAP_SERVERS 2
-#define DEFAULT_AUTOSAVE_INTERVAL 300*1000
+#define DEFAULT_AUTOSAVE_INTERVAL (300*1000)
enum {
TABLE_INVENTORY,
diff --git a/src/char/inter.h b/src/char/inter.h
index 88501c9a0..9b958dc72 100644
--- a/src/char/inter.h
+++ b/src/char/inter.h
@@ -30,13 +30,12 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg *reg, int type
uint64 inter_chk_lastuid(int8 flag, uint64 value);
#ifdef NSI_UNIQUE_ID
- #define updateLastUid(val_) inter_chk_lastuid(1, val_)
- #define dbUpdateUid(handler_)\
- { \
+ #define updateLastUid(val_) inter_chk_lastuid(1, (val_))
+ #define dbUpdateUid(handler_) do { \
uint64 unique_id_ = inter_chk_lastuid(0, 0); \
- if (unique_id_ && SQL_ERROR == SQL->Query(handler_, "UPDATE `%s` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", interreg_db, unique_id_)) \
+ if (unique_id_ && SQL_ERROR == SQL->Query((handler_), "UPDATE `%s` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", interreg_db, unique_id_)) \
Sql_ShowDebug(handler_);\
- }
+ } while(0)
#else
#define dbUpdateUid(handler_)
#define updateLastUid(val_)
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 1f4d4d532..641ffe2e6 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -108,6 +108,7 @@ bool hplugin_populate(struct hplugin *plugin, const char *filename) {
return true;
}
+#undef HPM_POP
struct hplugin *hplugin_load(const char* filename) {
struct hplugin *plugin;
struct hplugin_info *info;
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 9a6bda713..5466693ab 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -12,29 +12,29 @@
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
- #define plugin_open(x) LoadLibraryA(x)
- #define plugin_import(x,y,z) (z)GetProcAddress(x,y)
- #define plugin_close(x) FreeLibrary(x)
+ #define plugin_open(x) LoadLibraryA(x)
+ #define plugin_import(x,y,z) (z)GetProcAddress((x),(y))
+ #define plugin_close(x) FreeLibrary(x)
- #define DLL_EXT ".dll"
- #define DLL HINSTANCE
+ #define DLL_EXT ".dll"
+ #define DLL HINSTANCE
#else // ! WIN32
#include <dlfcn.h>
#ifdef RTLD_DEEPBIND // Certain linux ditributions require this, but it's not available everywhere
- #define plugin_open(x) dlopen(x,RTLD_NOW|RTLD_DEEPBIND)
+ #define plugin_open(x) dlopen((x),RTLD_NOW|RTLD_DEEPBIND)
#else // ! RTLD_DEEPBIND
- #define plugin_open(x) dlopen(x,RTLD_NOW)
+ #define plugin_open(x) dlopen((x),RTLD_NOW)
#endif // RTLD_DEEPBIND
- #define plugin_import(x,y,z) (z)dlsym(x,y)
- #define plugin_close(x) dlclose(x)
+ #define plugin_import(x,y,z) (z)dlsym((x),(y))
+ #define plugin_close(x) dlclose(x)
#ifdef CYGWIN
- #define DLL_EXT ".dll"
+ #define DLL_EXT ".dll"
#else
- #define DLL_EXT ".so"
+ #define DLL_EXT ".so"
#endif
- #define DLL void *
+ #define DLL void *
#include <string.h> // size_t
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index 940782dce..7637dc832 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -47,9 +47,9 @@ struct hplugin_info {
HPExport void *(*import_symbol) (char *name, unsigned int pID);
HPExport Sql *mysql_handle;
-#define GET_SYMBOL(n) import_symbol(n,HPMi->pid)
+#define GET_SYMBOL(n) import_symbol((n),HPMi->pid)
-#define SERVER_TYPE_ALL SERVER_TYPE_LOGIN|SERVER_TYPE_CHAR|SERVER_TYPE_MAP
+#define SERVER_TYPE_ALL (SERVER_TYPE_LOGIN|SERVER_TYPE_CHAR|SERVER_TYPE_MAP)
enum hp_event_types {
HPET_INIT,/* server starts */
@@ -83,27 +83,27 @@ enum HPluginDataTypes {
HPDT_NPCD,
};
-#define addHookPre(tname,hook) HPMi->AddHook(HOOK_TYPE_PRE,tname,hook,HPMi->pid)
-#define addHookPost(tname,hook) HPMi->AddHook(HOOK_TYPE_POST,tname,hook,HPMi->pid)
+#define addHookPre(tname,hook) (HPMi->AddHook(HOOK_TYPE_PRE,(tname),(hook),HPMi->pid))
+#define addHookPost(tname,hook) (HPMi->AddHook(HOOK_TYPE_POST,(tname),(hook),HPMi->pid))
/* need better names ;/ */
/* will not run the original function after pre-hook processing is complete (other hooks will run) */
-#define hookStop() HPMi->HookStop(__func__,HPMi->pid)
-#define hookStopped() HPMi->HookStopped()
+#define hookStop() (HPMi->HookStop(__func__,HPMi->pid))
+#define hookStopped() (HPMi->HookStopped())
-#define addArg(name,param,func,help) HPMi->addArg(HPMi->pid,name,param,func,help)
+#define addArg(name,param,func,help) (HPMi->addArg(HPMi->pid,(name),(param),(func),(help)))
/* HPData handy redirects */
/* session[] */
-#define addToSession(ptr,data,index,autofree) HPMi->addToHPData(HPDT_SESSION,HPMi->pid,ptr,data,index,autofree)
-#define getFromSession(ptr,index) HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,ptr,index)
-#define removeFromSession(ptr,index) HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,ptr,index)
+#define addToSession(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_SESSION,HPMi->pid,(ptr),(data),(index),(autofree)))
+#define getFromSession(ptr,index) (HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,(ptr),(index)))
+#define removeFromSession(ptr,index) (HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,(ptr),(index)))
/* map_session_data */
-#define addToMSD(ptr,data,index,autofree) HPMi->addToHPData(HPDT_MSD,HPMi->pid,ptr,data,index,autofree)
-#define getFromMSD(ptr,index) HPMi->getFromHPData(HPDT_MSD,HPMi->pid,ptr,index)
-#define removeFromMSD(ptr,index) HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,ptr,index)
+#define addToMSD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MSD,HPMi->pid,(ptr),(data),(index),(autofree)))
+#define getFromMSD(ptr,index) (HPMi->getFromHPData(HPDT_MSD,HPMi->pid,(ptr),(index)))
+#define removeFromMSD(ptr,index) (HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,(ptr),(index)))
/* npc_data */
-#define addToNPCD(ptr,data,index,autofree) HPMi->addToHPData(HPDT_NPCD,HPMi->pid,ptr,data,index,autofree)
-#define getFromNPCD(ptr,index) HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,ptr,index)
-#define removeFromNPCD(ptr,index) HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,ptr,index)
+#define addToNPCD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_NPCD,HPMi->pid,(ptr),(data),(index),(autofree)))
+#define getFromNPCD(ptr,index) (HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index)))
+#define removeFromNPCD(ptr,index) (HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index)))
/* Hercules Plugin Mananger Include Interface */
HPExport struct HPMi_interface {
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index d2a0a5dd9..6de2ace01 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -293,7 +293,9 @@ typedef char bool;
// if using macros then something that is type independent
//#define swap(a,b) ((a == b) || ((a ^= b), (b ^= a), (a ^= b)))
// Avoid "value computed is not used" warning and generates the same assembly code
-#define swap(a,b) if (a != b) ((a ^= b), (b ^= a), (a ^= b))
+//#define swap(a,b) if (a != b) ((a ^= b), (b ^= a), (a ^= b))
+// but is vulnerable to 'if (foo) swap(bar, baz); else quux();', causing the else to nest incorrectly.
+#define swap(a,b) do { if ((a) != (b)) { (a) ^= (b); (b) ^= (a); (a) ^= (b); } } while(0)
#if 0 //to be activated soon, more tests needed on how VS works with the macro above
#ifdef WIN32
#undef swap
@@ -313,7 +315,7 @@ typedef char bool;
#endif
#endif
-#define swap_ptr(a,b) if ((a) != (b)) ((a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (b) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)))
+#define swap_ptr(a,b) do { if ((a) != (b)) (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)); (b) = (void*)((intptr_t)(a) ^ (intptr_t)(b)); (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)); } while(0)
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
@@ -429,8 +431,8 @@ void SET_FUNCPOINTER(T1& var, T2 p)
var = tmp.out;
}
#else
-#define SET_POINTER(var,p) (var) = (p)
-#define SET_FUNCPOINTER(var,p) (var) = (p)
+#define SET_POINTER(var,p) ((var) = (p))
+#define SET_FUNCPOINTER(var,p) ((var) = (p))
#endif
diff --git a/src/common/console.c b/src/common/console.c
index cb8ed5917..94824dc25 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -175,6 +175,10 @@ void console_load_defaults(void) {
}
}
}
+#undef CP_DEF_C
+#undef CP_DEF_C2
+#undef CP_DEF_S
+#undef CP_DEF
void console_parse_create(char *name, CParseFunc func) {
unsigned int i;
char *tok;
diff --git a/src/common/core.c b/src/common/core.c
index a414a5d0b..dd839b372 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -53,7 +53,7 @@ char *SERVER_NAME = NULL;
#endif
#ifndef POSIX
-#define compat_signal(signo, func) signal(signo, func)
+#define compat_signal(signo, func) signal((signo), (func))
#else
sigfunc *compat_signal(int signo, sigfunc *func) {
struct sigaction sact, oact;
diff --git a/src/common/db.c b/src/common/db.c
index b3a58e0a4..c3ca7e0a4 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -315,7 +315,7 @@ static struct db_stats {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
};
-#define DB_COUNTSTAT(token) if (stats. ## token != UINT32_MAX) ++stats. ## token
+#define DB_COUNTSTAT(token) do { if (stats. ## token != UINT32_MAX) ++stats. ## token ; } while(0)
#else /* !defined(DB_ENABLE_STATS) */
#define DB_COUNTSTAT(token)
#endif /* !defined(DB_ENABLE_STATS) */
diff --git a/src/common/db.h b/src/common/db.h
index dffd2356d..b9d6af382 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -659,14 +659,14 @@ struct DBMap {
#define stridb_alloc(opt,maxlen) DB->alloc(__FILE__,__func__,__LINE__,DB_ISTRING,(opt),(maxlen))
#define db_destroy(db) ( (db)->destroy((db),NULL) )
// Other macros
-#define db_clear(db) ( (db)->clear(db,NULL) )
+#define db_clear(db) ( (db)->clear((db),NULL) )
#define db_size(db) ( (db)->size(db) )
#define db_iterator(db) ( (db)->iterator(db) )
-#define dbi_first(dbi) ( DB->data2ptr((dbi)->first(dbi,NULL)) )
-#define dbi_last(dbi) ( DB->data2ptr((dbi)->last(dbi,NULL)) )
-#define dbi_next(dbi) ( DB->data2ptr((dbi)->next(dbi,NULL)) )
-#define dbi_prev(dbi) ( DB->data2ptr((dbi)->prev(dbi,NULL)) )
-#define dbi_remove(dbi) ( (dbi)->remove(dbi,NULL) )
+#define dbi_first(dbi) ( DB->data2ptr((dbi)->first((dbi),NULL)) )
+#define dbi_last(dbi) ( DB->data2ptr((dbi)->last((dbi),NULL)) )
+#define dbi_next(dbi) ( DB->data2ptr((dbi)->next((dbi),NULL)) )
+#define dbi_prev(dbi) ( DB->data2ptr((dbi)->prev((dbi),NULL)) )
+#define dbi_remove(dbi) ( (dbi)->remove((dbi),NULL) )
#define dbi_exists(dbi) ( (dbi)->exists(dbi) )
#define dbi_destroy(dbi) ( (dbi)->destroy(dbi) )
diff --git a/src/common/ers.h b/src/common/ers.h
index 51701d778..4ff2a6230 100644
--- a/src/common/ers.h
+++ b/src/common/ers.h
@@ -137,11 +137,11 @@ typedef struct eri {
#else /* not DISABLE_ERS */
// These defines should be used to allow the code to keep working whenever
// the system is disabled
-# define ers_alloc(obj,type) (type *)(obj)->alloc(obj)
-# define ers_free(obj,entry) (obj)->free((obj),(entry))
-# define ers_entry_size(obj) (obj)->entry_size(obj)
-# define ers_destroy(obj) (obj)->destroy(obj)
-# define ers_chunk_size(obj,size) (obj)->chunk_size(obj,size)
+# define ers_alloc(obj,type) ((type *)(obj)->alloc(obj))
+# define ers_free(obj,entry) ((obj)->free((obj),(entry)))
+# define ers_entry_size(obj) ((obj)->entry_size(obj))
+# define ers_destroy(obj) ((obj)->destroy(obj))
+# define ers_chunk_size(obj,size) ((obj)->chunk_size((obj),(size)))
/**
* Get a new instance of the manager that handles the specified entry size.
diff --git a/src/common/grfio.h b/src/common/grfio.h
index c5a56a14e..a88b20393 100644
--- a/src/common/grfio.h
+++ b/src/common/grfio.h
@@ -8,7 +8,7 @@ void grfio_init(const char* fname);
void grfio_final(void);
void* grfio_reads(const char* fname, int* size);
char* grfio_find_file(const char* fname);
-#define grfio_read(fn) grfio_reads(fn, NULL)
+#define grfio_read(fn) grfio_reads((fn), NULL)
unsigned long grfio_crc32(const unsigned char *buf, unsigned int len);
int decode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen);
diff --git a/src/common/malloc.c b/src/common/malloc.c
index 4d2c93b77..1cb7836ab 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -19,28 +19,28 @@ struct malloc_interface iMalloc_s;
# include <string.h>
# include "memwatch.h"
-# define MALLOC(n,file,line,func) mwMalloc((n),(file),(line))
-# define CALLOC(m,n,file,line,func) mwCalloc((m),(n),(file),(line))
-# define REALLOC(p,n,file,line,func) mwRealloc((p),(n),(file),(line))
-# define STRDUP(p,file,line,func) mwStrdup((p),(file),(line))
-# define FREE(p,file,line,func) mwFree((p),(file),(line))
-# define MEMORY_USAGE() 0
-# define MEMORY_VERIFY(ptr) mwIsSafeAddr(ptr, 1)
-# define MEMORY_CHECK() CHECK()
+# define MALLOC(n,file,line,func) mwMalloc((n),(file),(line))
+# define CALLOC(m,n,file,line,func) mwCalloc((m),(n),(file),(line))
+# define REALLOC(p,n,file,line,func) mwRealloc((p),(n),(file),(line))
+# define STRDUP(p,file,line,func) mwStrdup((p),(file),(line))
+# define FREE(p,file,line,func) mwFree((p),(file),(line))
+# define MEMORY_USAGE() (size_t)0
+# define MEMORY_VERIFY(ptr) mwIsSafeAddr((ptr), 1)
+# define MEMORY_CHECK() CHECK()
#elif defined(DMALLOC)
# include <string.h>
# include <stdlib.h>
# include "dmalloc.h"
-# define MALLOC(n,file,line,func) dmalloc_malloc((file),(line),(n),DMALLOC_FUNC_MALLOC,0,0)
-# define CALLOC(m,n,file,line,func) dmalloc_malloc((file),(line),(m)*(n),DMALLOC_FUNC_CALLOC,0,0)
-# define REALLOC(p,n,file,line,func) dmalloc_realloc((file),(line),(p),(n),DMALLOC_FUNC_REALLOC,0)
-# define STRDUP(p,file,line,func) strdup(p)
-# define FREE(p,file,line,func) free(p)
-# define MEMORY_USAGE() dmalloc_memory_allocated()
-# define MEMORY_VERIFY(ptr) (dmalloc_verify(ptr) == DMALLOC_VERIFY_NOERROR)
-# define MEMORY_CHECK() dmalloc_log_stats(); dmalloc_log_unfreed()
+# define MALLOC(n,file,line,func) dmalloc_malloc((file),(line),(n),DMALLOC_FUNC_MALLOC,0,0)
+# define CALLOC(m,n,file,line,func) dmalloc_malloc((file),(line),(m)*(n),DMALLOC_FUNC_CALLOC,0,0)
+# define REALLOC(p,n,file,line,func) dmalloc_realloc((file),(line),(p),(n),DMALLOC_FUNC_REALLOC,0)
+# define STRDUP(p,file,line,func) strdup(p)
+# define FREE(p,file,line,func) free(p)
+# define MEMORY_USAGE() dmalloc_memory_allocated()
+# define MEMORY_VERIFY(ptr) (dmalloc_verify(ptr) == DMALLOC_VERIFY_NOERROR)
+# define MEMORY_CHECK() do { dmalloc_log_stats(); dmalloc_log_unfreed() } while(0)
#elif defined(GCOLLECT)
@@ -50,24 +50,26 @@ struct malloc_interface iMalloc_s;
# else
# define RETURN_ADDR
# endif
-# define MALLOC(n,file,line,func) GC_debug_malloc((n), RETURN_ADDR (file),(line))
-# define CALLOC(m,n,file,line,func) GC_debug_malloc((m)*(n), RETURN_ADDR (file),(line))
-# define REALLOC(p,n,file,line,func) GC_debug_realloc((p),(n), RETURN_ADDR (file),(line))
-# define STRDUP(p,file,line,func) GC_debug_strdup((p), RETURN_ADDR (file),(line))
-# define FREE(p,file,line,func) GC_debug_free(p)
-# define MEMORY_USAGE() GC_get_heap_size()
-# define MEMORY_VERIFY(ptr) (GC_base(ptr) != NULL)
-# define MEMORY_CHECK() GC_gcollect()
+# define MALLOC(n,file,line,func) GC_debug_malloc((n), RETURN_ADDR (file),(line))
+# define CALLOC(m,n,file,line,func) GC_debug_malloc((m)*(n), RETURN_ADDR (file),(line))
+# define REALLOC(p,n,file,line,func) GC_debug_realloc((p),(n), RETURN_ADDR (file),(line))
+# define STRDUP(p,file,line,func) GC_debug_strdup((p), RETURN_ADDR (file),(line))
+# define FREE(p,file,line,func) GC_debug_free(p)
+# define MEMORY_USAGE() GC_get_heap_size()
+# define MEMORY_VERIFY(ptr) (GC_base(ptr) != NULL)
+# define MEMORY_CHECK() GC_gcollect()
+
+# undef RETURN_ADDR
#else
-# define MALLOC(n,file,line,func) malloc(n)
-# define CALLOC(m,n,file,line,func) calloc((m),(n))
-# define REALLOC(p,n,file,line,func) realloc((p),(n))
-# define STRDUP(p,file,line,func) strdup(p)
-# define FREE(p,file,line,func) free(p)
-# define MEMORY_USAGE() 0
-# define MEMORY_VERIFY(ptr) true
+# define MALLOC(n,file,line,func) malloc(n)
+# define CALLOC(m,n,file,line,func) calloc((m),(n))
+# define REALLOC(p,n,file,line,func) realloc((p),(n))
+# define STRDUP(p,file,line,func) strdup(p)
+# define FREE(p,file,line,func) free(p)
+# define MEMORY_USAGE() (size_t)0
+# define MEMORY_VERIFY(ptr) true
# define MEMORY_CHECK()
#endif
diff --git a/src/common/malloc.h b/src/common/malloc.h
index bc8aa9a20..cd0ef238b 100644
--- a/src/common/malloc.h
+++ b/src/common/malloc.h
@@ -30,11 +30,11 @@
#undef LOG_MEMMGR
#endif
-# define aMalloc(n) iMalloc->malloc (n,ALC_MARK)
-# define aCalloc(m,n) iMalloc->calloc (m,n,ALC_MARK)
-# define aRealloc(p,n) iMalloc->realloc (p,n,ALC_MARK)
-# define aStrdup(p) iMalloc->astrdup (p,ALC_MARK)
-# define aFree(p) iMalloc->free (p,ALC_MARK)
+# define aMalloc(n) (iMalloc->malloc((n),ALC_MARK))
+# define aCalloc(m,n) (iMalloc->calloc((m),(n),ALC_MARK))
+# define aRealloc(p,n) (iMalloc->realloc((p),(n),ALC_MARK))
+# define aStrdup(p) (iMalloc->astrdup((p),ALC_MARK))
+# define aFree(p) (iMalloc->free((p),ALC_MARK))
/////////////// Buffer Creation /////////////////
// Full credit for this goes to Shinomori [Ajarn]
@@ -46,15 +46,15 @@
#else // others don't, so we emulate them
-#define CREATE_BUFFER(name, type, size) type *name = (type *) aCalloc (size, sizeof(type))
+#define CREATE_BUFFER(name, type, size) type *name = (type *) aCalloc((size), sizeof(type))
#define DELETE_BUFFER(name) aFree(name)
#endif
////////////// Others //////////////////////////
// should be merged with any of above later
-#define CREATE(result, type, number) (result) = (type *) aCalloc ((number), sizeof(type))
-#define RECREATE(result, type, number) (result) = (type *) aRealloc ((result), sizeof(type) * (number))
+#define CREATE(result, type, number) ((result) = (type *) aCalloc((number), sizeof(type)))
+#define RECREATE(result, type, number) ((result) = (type *) aRealloc((result), sizeof(type) * (number)))
////////////////////////////////////////////////
diff --git a/src/common/mapindex.h b/src/common/mapindex.h
index 646f73f18..cf5486808 100644
--- a/src/common/mapindex.h
+++ b/src/common/mapindex.h
@@ -60,7 +60,7 @@ bool mapindex_exists(int id);
const char* mapindex_getmapname(const char* string, char* output);
const char* mapindex_getmapname_ext(const char* string, char* output);
unsigned short mapindex_name2id(const char*);
-#define mapindex_id2name(n) mapindex_id2name_sub(n,__FILE__, __LINE__, __func__)
+#define mapindex_id2name(n) mapindex_id2name_sub((n),__FILE__, __LINE__, __func__)
const char* mapindex_id2name_sub(unsigned short,const char *file, int line, const char *func);
int mapindex_init(void);
void mapindex_final(void);
diff --git a/src/common/mempool.c b/src/common/mempool.c
index 5eccbf178..4559d8f2a 100644
--- a/src/common/mempool.c
+++ b/src/common/mempool.c
@@ -30,16 +30,16 @@
#include "../common/malloc.h"
#include "../common/mutex.h"
-#define ALIGN16 ra_align(16)
-#define ALIGN_TO(x, a) (x + ( a - ( x % a) ) )
-#define ALIGN_TO_16(x) ALIGN_TO(x, 16)
+#define ALIGN16 ra_align(16)
+#define ALIGN_TO(x, a) ((x) + ( (a) - ( (x) % (a)) ) )
+#define ALIGN_TO_16(x) ALIGN_TO((x), 16)
#undef MEMPOOL_DEBUG
#define MEMPOOLASSERT
-#define NODE_TO_DATA(x) ( ((char*)x) + sizeof(struct node) )
-#define DATA_TO_NODE(x) ( (struct node*)(((char*)x) - sizeof(struct node)) )
+#define NODE_TO_DATA(x) ( ((char*)(x)) + sizeof(struct node) )
+#define DATA_TO_NODE(x) ( (struct node*)(((char*)(x)) - sizeof(struct node)) )
struct ra_align(16) node{
void *next;
void *segment;
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 309203aa8..5816b467c 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -112,7 +112,7 @@
#define MAX_STORAGE 600
#define MAX_GUILD_STORAGE 600
#define MAX_PARTY 12
-#define MAX_GUILD 16+10*6 // Increased max guild members +6 per 1 extension levels [Lupus]
+#define MAX_GUILD (16+10*6) // Increased max guild members +6 per 1 extension levels [Lupus]
#define MAX_GUILDPOSITION 20 // Increased max guild positions to accomodate for all members [Valaris] (removed) [PoW]
#define MAX_GUILDEXPULSION 32
#define MAX_GUILDALLIANCE 16
diff --git a/src/common/netbuffer.h b/src/common/netbuffer.h
index 844241226..6ddecfdd9 100644
--- a/src/common/netbuffer.h
+++ b/src/common/netbuffer.h
@@ -73,11 +73,9 @@ void netbuffer_incref( netbuf buf );
// Some Useful macros
-#define NBUFP(netbuf,pos) (((uint8*)(netbuf->buf)) + (pos))
-#define NBUFB(netbuf,pos) (*(uint8*)((netbuf->buf) + (pos)))
-#define NBUFW(netbuf,pos) (*(uint16*)((netbuf->buf) + (pos)))
-#define NBUFL(netbuf,pos) (*(uint32*)((netbuf->buf) + (pos)))
-
-
+#define NBUFP(netbuf,pos) (((uint8*)((netbuf)->buf)) + (pos))
+#define NBUFB(netbuf,pos) (*(uint8*)(((netbuf)->buf) + (pos)))
+#define NBUFW(netbuf,pos) (*(uint16*)(((netbuf)->buf) + (pos)))
+#define NBUFL(netbuf,pos) (*(uint32*)(((netbuf)->buf) + (pos)))
#endif
diff --git a/src/common/network.c b/src/common/network.c
index 1f1621363..a40cbd602 100644
--- a/src/common/network.c
+++ b/src/common/network.c
@@ -50,7 +50,7 @@ SESSION g_Session[MAXCONN];
static bool onSend(int32 fd);
-#define _network_free_netbuf_async( buf ) add_timer( 0, _network_async_free_netbuf_proc, 0, (intptr_t) buf)
+#define _network_free_netbuf_async( buf ) add_timer( 0, _network_async_free_netbuf_proc, 0, (intptr_t)(buf))
static int _network_async_free_netbuf_proc(int tid, unsigned int tick, int id, intptr_t data){
// netbuf is in data
netbuffer_put( (netbuf)data );
diff --git a/src/common/raconf.c b/src/common/raconf.c
index f7d1284b7..abeed444b 100644
--- a/src/common/raconf.c
+++ b/src/common/raconf.c
@@ -382,21 +382,20 @@ static bool configParse(raconf inst, const char *fileName){
}//end: configParse()
-#define MAKEKEY(dest, section, key) { size_t section_len, key_len; \
- if(section == NULL || *section == '\0'){ \
- strncpy(dest, "<unnamed>", 9); \
- section_len = 9; \
- }else{ \
- section_len = strlen(section); \
- strncpy(dest, section, section_len); \
- } \
- \
- dest[section_len] = '.'; \
- \
- key_len = strlen(key); \
- strncpy(&dest[section_len+1], key, key_len); \
- dest[section_len + key_len + 1] = '\0'; \
- }
+#define MAKEKEY(dest, section, key) do { \
+ size_t section_len_, key_len_; \
+ if((section) == NULL || *(section) == '\0'){ \
+ strncpy((dest), "<unnamed>", 9); \
+ section_len_ = 9; \
+ } else { \
+ section_len_ = strlen(section); \
+ strncpy((dest), (section), section_len_); \
+ } \
+ (dest)[section_len_] = '.'; \
+ key_len_ = strlen(key); \
+ strncpy(&(dest)[section_len_+1], (key), key_len_); \
+ (dest)[section_len_ + key_len_ + 1] = '\0'; \
+} while(0)
raconf raconf_parse(const char *file_name){
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index 9e0f63003..14342fe5e 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -16,33 +16,17 @@
#include "../../3rdparty/libconfig/libconfig.h"
#ifdef WIN32
- #include "../common/winapi.h"
-
- #ifdef DEBUGLOGMAP
- #define DEBUGLOGPATH "log\\map-server.log"
- #else
- #ifdef DEBUGLOGCHAR
- #define DEBUGLOGPATH "log\\char-server.log"
- #else
- #ifdef DEBUGLOGLOGIN
- #define DEBUGLOGPATH "log\\login-server.log"
- #endif
- #endif
- #endif
-#else
- #include <unistd.h>
-
- #ifdef DEBUGLOGMAP
- #define DEBUGLOGPATH "log/map-server.log"
- #else
- #ifdef DEBUGLOGCHAR
- #define DEBUGLOGPATH "log/char-server.log"
- #else
- #ifdef DEBUGLOGLOGIN
- #define DEBUGLOGPATH "log/login-server.log"
- #endif
- #endif
- #endif
+#include "../common/winapi.h"
+#else // not WIN32
+#include <unistd.h>
+#endif // WIN32
+
+#if defined(DEBUGLOGMAP)
+#define DEBUGLOGPATH "log"PATHSEP_STR"map-server.log"
+#elif defined(DEBUGLOGCHAR)
+#define DEBUGLOGPATH "log"PATHSEP_STR"char-server.log"
+#elif defined(DEBUGLOGLOGIN)
+#define DEBUGLOGPATH "log"PATHSEP_STR"login-server.log"
#endif
///////////////////////////////////////////////////////////////////////////////
@@ -61,41 +45,40 @@ int console_msg_log = 0;//[Ind] msg error logging
#define SBUF_SIZE 2054 // never put less that what's required for the debug message
-#define NEWBUF(buf) \
- struct { \
- char s_[SBUF_SIZE]; \
- StringBuf *d_; \
- char *v_; \
- int l_; \
- } buf ={"",NULL,NULL,0}; \
+#define NEWBUF(buf) \
+ struct { \
+ char s_[SBUF_SIZE]; \
+ StringBuf *d_; \
+ char *v_; \
+ int l_; \
+ } buf ={"",NULL,NULL,0}; \
//define NEWBUF
-#define BUFVPRINTF(buf,fmt,args) \
- buf.l_ = vsnprintf(buf.s_, SBUF_SIZE, fmt, args); \
- if( buf.l_ >= 0 && buf.l_ < SBUF_SIZE ) \
- {/* static buffer */ \
- buf.v_ = buf.s_; \
- } \
- else \
- {/* dynamic buffer */ \
- buf.d_ = StrBuf->Malloc(); \
- buf.l_ = StrBuf->Vprintf(buf.d_, fmt, args); \
- buf.v_ = StrBuf->Value(buf.d_); \
- ShowDebug("showmsg: dynamic buffer used, increase the static buffer size to %d or more.\n", buf.l_+1);\
- } \
-//define BUFVPRINTF
-
-#define BUFVAL(buf) buf.v_
-#define BUFLEN(buf) buf.l_
-
-#define FREEBUF(buf) \
- if( buf.d_ ) \
- { \
- StrBuf->Free(buf.d_); \
- buf.d_ = NULL; \
- } \
- buf.v_ = NULL; \
-//define FREEBUF
+#define BUFVPRINTF(buf,fmt,args) do { \
+ (buf).l_ = vsnprintf((buf).s_, SBUF_SIZE, (fmt), args); \
+ if( (buf).l_ >= 0 && (buf).l_ < SBUF_SIZE ) \
+ {/* static buffer */ \
+ (buf).v_ = (buf).s_; \
+ } \
+ else \
+ {/* dynamic buffer */ \
+ (buf).d_ = StrBuf->Malloc(); \
+ (buf).l_ = StrBuf->Vprintf((buf).d_, (fmt), args); \
+ (buf).v_ = StrBuf->Value((buf).d_); \
+ ShowDebug("showmsg: dynamic buffer used, increase the static buffer size to %d or more.\n", (buf).l_+1); \
+ } \
+} while(0) //define BUFVPRINTF
+
+#define BUFVAL(buf) ((buf).v_)
+#define BUFLEN(buf) ((buf).l_)
+
+#define FREEBUF(buf) do {\
+ if( (buf).d_ ) { \
+ StrBuf->Free((buf).d_); \
+ (buf).d_ = NULL; \
+ } \
+ (buf).v_ = NULL; \
+} while(0) //define FREEBUF
///////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
@@ -666,14 +649,6 @@ int FPRINTF(FILE *file, const char *fmt, ...)
#endif// not _WIN32
-
-
-
-
-
-
-
-
char timestamp_format[20] = ""; //For displaying Timestamps
int _vShowMessage(enum msg_type flag, const char *string, va_list ap)
diff --git a/src/common/socket.c b/src/common/socket.c
index 6e877d9be..2ae9d44b3 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -157,19 +157,19 @@ char* sErr(int code)
return sbuf;
}
-#define sBind(fd,name,namelen) bind(fd2sock(fd),name,namelen)
-#define sConnect(fd,name,namelen) connect(fd2sock(fd),name,namelen)
-#define sIoctl(fd,cmd,argp) ioctlsocket(fd2sock(fd),cmd,argp)
-#define sListen(fd,backlog) listen(fd2sock(fd),backlog)
-#define sRecv(fd,buf,len,flags) recv(fd2sock(fd),buf,len,flags)
-#define sSelect select
-#define sSend(fd,buf,len,flags) send(fd2sock(fd),buf,len,flags)
-#define sSetsockopt(fd,level,optname,optval,optlen) setsockopt(fd2sock(fd),level,optname,optval,optlen)
-#define sShutdown(fd,how) shutdown(fd2sock(fd),how)
-#define sFD_SET(fd,set) FD_SET(fd2sock(fd),set)
-#define sFD_CLR(fd,set) FD_CLR(fd2sock(fd),set)
-#define sFD_ISSET(fd,set) FD_ISSET(fd2sock(fd),set)
-#define sFD_ZERO FD_ZERO
+#define sBind(fd,name,namelen) bind(fd2sock(fd),(name),(namelen))
+#define sConnect(fd,name,namelen) connect(fd2sock(fd),(name),(namelen))
+#define sIoctl(fd,cmd,argp) ioctlsocket(fd2sock(fd),(cmd),(argp))
+#define sListen(fd,backlog) listen(fd2sock(fd),(backlog))
+#define sRecv(fd,buf,len,flags) recv(fd2sock(fd),(buf),(len),(flags))
+#define sSelect select
+#define sSend(fd,buf,len,flags) send(fd2sock(fd),(buf),(len),(flags))
+#define sSetsockopt(fd,level,optname,optval,optlen) setsockopt(fd2sock(fd),(level),(optname),(optval),(optlen))
+#define sShutdown(fd,how) shutdown(fd2sock(fd),(how))
+#define sFD_SET(fd,set) FD_SET(fd2sock(fd),(set))
+#define sFD_CLR(fd,set) FD_CLR(fd2sock(fd),(set))
+#define sFD_ISSET(fd,set) FD_ISSET(fd2sock(fd),(set))
+#define sFD_ZERO FD_ZERO
/////////////////////////////////////////////////////////////////////
#else
diff --git a/src/common/socket.h b/src/common/socket.h
index 923fa2515..02817f653 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -24,18 +24,18 @@ struct HPluginData;
// socket I/O macros
#define RFIFOHEAD(fd)
-#define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo(fd, size); }while(0)
+#define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo((fd), (size)); }while(0)
#define RFIFOP(fd,pos) (session[fd]->rdata + session[fd]->rdata_pos + (pos))
#define WFIFOP(fd,pos) (session[fd]->wdata + session[fd]->wdata_size + (pos))
-#define RFIFOB(fd,pos) (*(uint8*)RFIFOP(fd,pos))
-#define WFIFOB(fd,pos) (*(uint8*)WFIFOP(fd,pos))
-#define RFIFOW(fd,pos) (*(uint16*)RFIFOP(fd,pos))
-#define WFIFOW(fd,pos) (*(uint16*)WFIFOP(fd,pos))
-#define RFIFOL(fd,pos) (*(uint32*)RFIFOP(fd,pos))
-#define WFIFOL(fd,pos) (*(uint32*)WFIFOP(fd,pos))
-#define RFIFOQ(fd,pos) (*(uint64*)RFIFOP(fd,pos))
-#define WFIFOQ(fd,pos) (*(uint64*)WFIFOP(fd,pos))
+#define RFIFOB(fd,pos) (*(uint8*)RFIFOP((fd),(pos)))
+#define WFIFOB(fd,pos) (*(uint8*)WFIFOP((fd),(pos)))
+#define RFIFOW(fd,pos) (*(uint16*)RFIFOP((fd),(pos)))
+#define WFIFOW(fd,pos) (*(uint16*)WFIFOP((fd),(pos)))
+#define RFIFOL(fd,pos) (*(uint32*)RFIFOP((fd),(pos)))
+#define WFIFOL(fd,pos) (*(uint32*)WFIFOP((fd),(pos)))
+#define RFIFOQ(fd,pos) (*(uint64*)RFIFOP((fd),(pos)))
+#define WFIFOQ(fd,pos) (*(uint64*)WFIFOP((fd),(pos)))
#define RFIFOSPACE(fd) (session[fd]->max_rdata - session[fd]->rdata_size)
#define WFIFOSPACE(fd) (session[fd]->max_wdata - session[fd]->wdata_size)
@@ -146,8 +146,9 @@ void set_defaultparse(ParseFunc defaultparse);
uint32 host2ip(const char* hostname);
const char* ip2str(uint32 ip, char ip_str[16]);
uint32 str2ip(const char* ip_str);
+// Note: purposely returns four comma-separated arguments
#define CONVIP(ip) ((ip)>>24)&0xFF,((ip)>>16)&0xFF,((ip)>>8)&0xFF,((ip)>>0)&0xFF
-#define MAKEIP(a,b,c,d) (uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) )
+#define MAKEIP(a,b,c,d) ((uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) ))
uint16 ntows(uint16 netshort);
int socket_getips(uint32* ips, int max);
diff --git a/src/common/spinlock.h b/src/common/spinlock.h
index 3419bfdd5..9b9e4ce94 100644
--- a/src/common/spinlock.h
+++ b/src/common/spinlock.h
@@ -52,8 +52,8 @@ static forceinline void FinalizeSpinLock(PSPIN_LOCK lck){
}
-#define getsynclock(l) { while(1){ if(InterlockedCompareExchange(l, 1, 0) == 0) break; rathread_yield(); } }
-#define dropsynclock(l) { InterlockedExchange(l, 0); }
+#define getsynclock(l) do { if(InterlockedCompareExchange((l), 1, 0) == 0) break; rathread_yield(); } while(/*always*/1)
+#define dropsynclock(l) do { InterlockedExchange((l), 0); } while(0)
static forceinline void EnterSpinLock(PSPIN_LOCK lck){
int tid = rathread_get_tid();
diff --git a/src/common/sql.h b/src/common/sql.h
index da00edf2d..1fb436853 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -11,7 +11,7 @@
// Return codes
-#define SQL_ERROR -1
+#define SQL_ERROR (-1)
#define SQL_SUCCESS 0
#define SQL_NO_DATA 100
@@ -277,7 +277,7 @@ void sql_defaults(void);
#if defined(SQL_REMOVE_SHOWDEBUG)
#define Sql_ShowDebug(self) (void)0
#else
-#define Sql_ShowDebug(self) SQL->ShowDebug_(self, __FILE__, __LINE__)
+#define Sql_ShowDebug(self) (SQL->ShowDebug_((self), __FILE__, __LINE__))
#endif
void Sql_HerculesUpdateCheck(Sql* self);
@@ -286,16 +286,10 @@ void Sql_HerculesUpdateSkip(Sql* self,const char *filename);
#if defined(SQL_REMOVE_SHOWDEBUG)
#define SqlStmt_ShowDebug(self) (void)0
#else
-#define SqlStmt_ShowDebug(self) SQL->StmtShowDebug_(self, __FILE__, __LINE__)
-#endif
/// Shows debug information (with statement).
-
-
-
-
-
+#define SqlStmt_ShowDebug(self) (SQL->StmtShowDebug_((self), __FILE__, __LINE__))
+#endif
void Sql_Init(void);
-
#endif /* _COMMON_SQL_H_ */
diff --git a/src/common/strlib.h b/src/common/strlib.h
index 5ef455a0e..0c3b0a486 100644
--- a/src/common/strlib.h
+++ b/src/common/strlib.h
@@ -168,28 +168,28 @@ void strlib_defaults(void);
/* the purpose of these macros is simply to not make calling them be an annoyance */
#ifndef STRLIB_C
- #define jstrescape(pt) strlib->jstrescape(pt)
- #define jstrescapecpy(pt,spt) strlib->jstrescapecpy(pt,spt)
- #define jmemescapecpy(pt,spt,size) strlib->jmemescapecpy(pt,spt,size)
- #define remove_control_chars(str) strlib->remove_control_chars(str)
- #define trim(str) strlib->trim(str)
- #define normalize_name(str,delims) strlib->normalize_name(str,delims)
- #define stristr(haystack,needle) strlib->stristr(haystack,needle)
+ #define jstrescape(pt) (strlib->jstrescape(pt))
+ #define jstrescapecpy(pt,spt) (strlib->jstrescapecpy((pt),(spt)))
+ #define jmemescapecpy(pt,spt,size) (strlib->jmemescapecpy((pt),(spt),(size)))
+ #define remove_control_chars(str) (strlib->remove_control_chars(str))
+ #define trim(str) (strlib->trim(str))
+ #define normalize_name(str,delims) (strlib->normalize_name((str),(delims)))
+ #define stristr(haystack,needle) (strlib->stristr((haystack),(needle)))
#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)
- #define strnln(string,maxlen) strlib->strnlen(string,maxlen)
+ #define strnln(string,maxlen) (strlib->strnlen((string),(maxlen)))
#endif
#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200
- #define strtoull(str,endptr,base) strlib->strtoull(str,endptr,base)
+ #define strtoull(str,endptr,base) (strlib->strtoull((str),(endptr),(base)))
#endif
- #define e_mail_check(email) strlib->e_mail_check(email)
- #define config_switch(str) strlib->config_switch(str)
- #define safestrncpy(dst,src,n) strlib->safestrncpy(dst,src,n)
- #define safestrnlen(string,maxlen) strlib->safestrnlen(string,maxlen)
- #define safesnprintf(buf,sz,fmt,...) strlib->safesnprintf(buf,sz,fmt,##__VA_ARGS__)
- #define strline(str,pos) strlib->strline(str,pos)
- #define bin2hex(output,input,count) strlib->bin2hex(output,input,count)
+ #define e_mail_check(email) (strlib->e_mail_check(email))
+ #define config_switch(str) (strlib->config_switch(str))
+ #define safestrncpy(dst,src,n) (strlib->safestrncpy((dst),(src),(n)))
+ #define safestrnlen(string,maxlen) (strlib->safestrnlen((string),(maxlen)))
+ #define safesnprintf(buf,sz,fmt,...) (strlib->safesnprintf((buf),(sz),(fmt),##__VA_ARGS__))
+ #define strline(str,pos) (strlib->strline((str),(pos)))
+ #define bin2hex(output,input,count) (strlib->bin2hex((output),(input),(count)))
#endif /* STRLIB_C */
#endif /* _STRLIB_H_ */
diff --git a/src/common/timer.h b/src/common/timer.h
index 4a2bebe7d..9aa29861e 100644
--- a/src/common/timer.h
+++ b/src/common/timer.h
@@ -8,7 +8,7 @@
#define DIFF_TICK(a,b) ((a)-(b))
#define DIFF_TICK32(a,b) ((int32)((a)-(b)))
-#define INVALID_TIMER -1
+#define INVALID_TIMER (-1)
// timer flags
enum {
diff --git a/src/common/utils.h b/src/common/utils.h
index 3e1463d6b..719e1e533 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -20,7 +20,7 @@ void findfile(const char *p, const char *pat, void (func)(const char*));
bool exists(const char* filename);
//Caps values to min/max
-#define cap_value(a, min, max) ((a >= max) ? max : (a <= min) ? min : a)
+#define cap_value(a, min, max) (((a) >= (max)) ? (max) : ((a) <= (min)) ? (min) : (a))
/// calculates the value of A / B, in percent (rounded down)
unsigned int get_percentage(const unsigned int A, const unsigned int B);
diff --git a/src/config/const.h b/src/config/const.h
index 6f0dc6311..fc82d66f9 100644
--- a/src/config/const.h
+++ b/src/config/const.h
@@ -114,13 +114,6 @@
#undef CONSOLE_INPUT
#endif
-#ifdef RENEWAL
- #define ITEMDB_SQL_COLUMNS 24
-#else
- #define ITEMDB_SQL_COLUMNS 22
-#endif
-
-
/**
* End of File
**/
diff --git a/src/login/login.h b/src/login/login.h
index 0a41b803f..15edb14dc 100644
--- a/src/login/login.h
+++ b/src/login/login.h
@@ -89,8 +89,8 @@ struct Login_Config {
struct client_hash_node *client_hash_nodes; // linked list containg md5 hash for each gm group
};
-#define sex_num2str(num) ( (num == SEX_FEMALE ) ? 'F' : (num == SEX_MALE ) ? 'M' : 'S' )
-#define sex_str2num(str) ( (str == 'F' ) ? SEX_FEMALE : (str == 'M' ) ? SEX_MALE : SEX_SERVER )
+#define sex_num2str(num) ( ((num) == SEX_FEMALE) ? 'F' : ((num) == SEX_MALE) ? 'M' : 'S' )
+#define sex_str2num(str) ( ((str) == 'F') ? SEX_FEMALE : ((str) == 'M') ? SEX_MALE : SEX_SERVER )
#define MAX_SERVERS 30
extern struct mmo_char_server server[MAX_SERVERS];
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 4a471fe5d..3b06140d4 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -164,38 +164,32 @@ ACMD(send)
clif->message(fd, msg_txt(i));
return false;
}
-
-#define PARSE_ERROR(error,p) \
-{\
-clif->message(fd, (error));\
-sprintf(atcmd_output, ">%s", (p));\
-clif->message(fd, atcmd_output);\
-}
- //define PARSE_ERROR
-
-#define CHECK_EOS(p) \
-if(*(p) == 0){\
-clif->message(fd, "Unexpected end of string");\
-return false;\
-}
- //define CHECK_EOS
-
-#define SKIP_VALUE(p) \
-{\
-while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\
-while(*(p) && ISSPACE(*(p))) ++(p); /* space */\
-}
- //define SKIP_VALUE
-
-#define GET_VALUE(p,num) \
-{\
-if(sscanf((p), "x%lx", &(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\
-PARSE_ERROR("Invalid number in:",(p));\
-return false;\
-}\
-}
- //define GET_VALUE
-
+
+#define PARSE_ERROR(error,p) do {\
+ clif->message(fd, (error));\
+ sprintf(atcmd_output, ">%s", (p));\
+ clif->message(fd, atcmd_output);\
+} while(0) //define PARSE_ERROR
+
+#define CHECK_EOS(p) do { \
+ if(*(p) == 0){ \
+ clif->message(fd, "Unexpected end of string");\
+ return false;\
+ } \
+} while(0) //define CHECK_EOS
+
+#define SKIP_VALUE(p) do { \
+ while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\
+ while(*(p) && ISSPACE(*(p))) ++(p); /* space */\
+} while(0) //define SKIP_VALUE
+
+#define GET_VALUE(p,num) do { \
+ if(sscanf((p), "x%lx", &(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\
+ PARSE_ERROR("Invalid number in:",(p));\
+ return false;\
+ }\
+} while(0) //define GET_VALUE
+
if (type > 0 && type < MAX_PACKET_DB) {
if(len)
@@ -8585,10 +8579,11 @@ ACMD(unloadnpcfile) {
return true;
}
ACMD(cart) {
-#define MC_CART_MDFY(x,idx) \
-sd->status.skill[idx].id = x?MC_PUSHCART:0; \
-sd->status.skill[idx].lv = x?1:0; \
-sd->status.skill[idx].flag = x?1:0;
+#define MC_CART_MDFY(x,idx) do { \
+ sd->status.skill[idx].id = (x)?MC_PUSHCART:0; \
+ sd->status.skill[idx].lv = (x)?1:0; \
+ sd->status.skill[idx].flag = (x)?1:0; \
+} while(0)
int val = atoi(message);
bool need_skill = pc->checkskill(sd, MC_PUSHCART) ? false : true;
@@ -9616,6 +9611,8 @@ void atcommand_basecommands(void) {
return;
}
+#undef ACMD_DEF
+#undef ACMD_DEF2
bool atcommand_add(char *name,AtCommandFunc func, bool replace) {
AtCommandInfo* cmd;
diff --git a/src/map/battle.c b/src/map/battle.c
index cd8c36b69..78f54733c 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -3189,7 +3189,7 @@ int battle_blewcount_bonus(struct map_session_data *sd, uint16 skill_id) {
return 0;
}
//For quick div adjustment.
-#define damage_div_fix(dmg, div) { if (div > 1) (dmg)*=div; else if (div < 0) (div)*=-1; }
+#define damage_div_fix(dmg, div) do { if ((div) > 1) (dmg)*=(div); else if ((div) < 0) (div)*=-1; } while(0)
/*==========================================
* battle_calc_magic_attack [DracoRPG]
*------------------------------------------*/
@@ -3305,11 +3305,11 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
ad.damage = 0; //reinitialize..
#endif
//MATK_RATE scales the damage. 100 = no change. 50 is halved, 200 is doubled, etc
-#define MATK_RATE( a ) { ad.damage= ad.damage*(a)/100; }
+#define MATK_RATE( a ) ( ad.damage= ad.damage*(a)/100 )
//Adds dmg%. 100 = +100% (double) damage. 10 = +10% damage
-#define MATK_ADDRATE( a ) { ad.damage+= ad.damage*(a)/100; }
+#define MATK_ADDRATE( a ) ( ad.damage+= ad.damage*(a)/100 )
//Adds an absolute value to damage. 100 = +100 damage
-#define MATK_ADD( a ) { ad.damage+= a; }
+#define MATK_ADD( a ) ( ad.damage+= (a) )
switch (skill_id)
{ //Calc base damage according to skill
@@ -3499,6 +3499,9 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
}
return ad;
+#undef MATK_RATE
+#undef MATK_ADDRATE
+#undef MATK_ADD
}
/*==========================================
@@ -4359,19 +4362,19 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list
//Assuming that 99% of the cases we will not need to check for the flag.rh... we don't.
//ATK_RATE scales the damage. 100 = no change. 50 is halved, 200 is doubled, etc
-#define ATK_RATE( a ) { wd.damage= wd.damage*(a)/100 ; if(flag.lh) wd.damage2= wd.damage2*(a)/100; }
-#define ATK_RATE2( a , b ) { wd.damage= wd.damage*(a)/100 ; if(flag.lh) wd.damage2= wd.damage2*(b)/100; }
-#define ATK_RATER(a){ wd.damage = wd.damage*(a)/100;}
-#define ATK_RATEL(a){ wd.damage2 = wd.damage2*(a)/100;}
+#define ATK_RATE( a ) do { int64 temp__ = (a); wd.damage= wd.damage*temp__/100 ; if(flag.lh) wd.damage2= wd.damage2*temp__/100; } while(0)
+#define ATK_RATE2( a , b ) do { wd.damage= wd.damage*(a)/100 ; if(flag.lh) wd.damage2= wd.damage2*(b)/100; } while(0)
+#define ATK_RATER(a) ( wd.damage = wd.damage*(a)/100 )
+#define ATK_RATEL(a) ( wd.damage2 = wd.damage2*(a)/100 )
//Adds dmg%. 100 = +100% (double) damage. 10 = +10% damage
-#define ATK_ADDRATE( a ) { wd.damage+= wd.damage*(a)/100 ; if(flag.lh) wd.damage2+= wd.damage2*(a)/100; }
-#define ATK_ADDRATE2( a , b ) { wd.damage+= wd.damage*(a)/100 ; if(flag.lh) wd.damage2+= wd.damage2*(b)/100; }
+#define ATK_ADDRATE( a ) do { int64 temp__ = (a); wd.damage+= wd.damage*temp__/100; if(flag.lh) wd.damage2+= wd.damage2*temp__/100; } while(0)
+#define ATK_ADDRATE2( a , b ) do { wd.damage+= wd.damage*(a)/100 ; if(flag.lh) wd.damage2+= wd.damage2*(b)/100; } while(0)
//Adds an absolute value to damage. 100 = +100 damage
-#define ATK_ADD( a ) { wd.damage+= a; if (flag.lh) wd.damage2+= a; }
-#define ATK_ADD2( a , b ) { wd.damage+= a; if (flag.lh) wd.damage2+= b; }
+#define ATK_ADD( a ) do { int64 temp__ = (a); wd.damage += temp__; if (flag.lh) wd.damage2 += temp__; } while(0)
+#define ATK_ADD2( a , b ) do { wd.damage += (a); if (flag.lh) wd.damage2 += (b); } while(0)
#ifdef RENEWAL
-#define GET_NORMAL_ATTACK( f ) { wd.damage = battle->calc_base_damage(src, target, skill_id, skill_lv, nk, n_ele, s_ele, s_ele_, EQI_HAND_R, f, wd.flag); }
-#define GET_NORMAL_ATTACK2( f ) { wd.damage2 = battle->calc_base_damage(src, target, skill_id, skill_lv, nk, n_ele, s_ele, s_ele_, EQI_HAND_L, f, wd.flag); }
+#define GET_NORMAL_ATTACK( f ) ( wd.damage = battle->calc_base_damage(src, target, skill_id, skill_lv, nk, n_ele, s_ele, s_ele_, EQI_HAND_R, (f), wd.flag) )
+#define GET_NORMAL_ATTACK2( f ) ( wd.damage2 = battle->calc_base_damage(src, target, skill_id, skill_lv, nk, n_ele, s_ele, s_ele_, EQI_HAND_L, (f), wd.flag) )
#endif
switch (skill_id)
{ //Calc base damage according to skill
@@ -5070,7 +5073,7 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list
)) &&
rnd()%100 < tsc->data[SC_SWORDREJECT]->val2
) {
- ATK_RATER(50)
+ ATK_RATER(50);
status_fix_damage(target,src,wd.damage,clif->damage(target,src,timer->gettick(),0,0,wd.damage,0,0,0));
clif->skill_nodamage(target,target,ST_REJECTSWORD,tsc->data[SC_SWORDREJECT]->val1,1);
if( --(tsc->data[SC_SWORDREJECT]->val3) <= 0 )
@@ -5147,9 +5150,9 @@ int64 battle_calc_return_damage(struct block_list* bl, struct block_list *src, i
sc = status->get_sc(bl);
#ifdef RENEWAL
-#define NORMALIZE_RDAMAGE(d){ trdamage += rdamage = max(1, min(max_reflect_damage, d)); }
+#define NORMALIZE_RDAMAGE(d) ( trdamage += rdamage = max(1, min(max_reflect_damage, (d))) )
#else
-#define NORMALIZE_RDAMAGE(d){ trdamage += rdamage = max(1, d); }
+#define NORMALIZE_RDAMAGE(d) ( trdamage += rdamage = max(1, (d)) )
#endif
if( sc && sc->data[SC_CRESCENTELBOW] && !is_boss(src) && rnd()%100 < sc->data[SC_CRESCENTELBOW]->val2 ){
@@ -5214,6 +5217,7 @@ int64 battle_calc_return_damage(struct block_list* bl, struct block_list *src, i
}
return max(0, trdamage);
+#undef NORMALIZE_RDAMAGE
}
void battle_drain(TBL_PC *sd, struct block_list *tbl, int64 rdamage, int64 ldamage, int race, int boss)
@@ -5468,7 +5472,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
if( sc && sc->count ) {
if (sc->data[SC_EXEEDBREAK]) {
- ATK_RATER(sc->data[SC_EXEEDBREAK]->val1)
+ ATK_RATER(sc->data[SC_EXEEDBREAK]->val1);
status_change_end(src, SC_EXEEDBREAK, INVALID_TIMER);
}
if( sc->data[SC_SPELLFIST] ) {
@@ -5670,6 +5674,16 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
map->freeblock_unlock();
return wd.dmg_lv;
}
+#undef ATK_RATE
+#undef ATK_RATE2
+#undef ATK_RATER
+#undef ATK_RATEL
+#undef ATK_ADDRATE
+#undef ATK_ADDRATE2
+#undef ATK_ADD
+#undef ATK_ADD2
+#undef GET_NORMAL_ATTACK
+#undef GET_NORMAL_ATTACK2
int battle_check_undead(int race,int element)
{
diff --git a/src/map/battle.h b/src/map/battle.h
index fd6699f4d..a8b291818 100644
--- a/src/map/battle.h
+++ b/src/map/battle.h
@@ -21,14 +21,14 @@ struct status_data;
/**
* Defines
**/
-#define MIN_HAIR_STYLE battle_config.min_hair_style
-#define MAX_HAIR_STYLE battle_config.max_hair_style
-#define MIN_HAIR_COLOR battle_config.min_hair_color
-#define MAX_HAIR_COLOR battle_config.max_hair_color
-#define MIN_CLOTH_COLOR battle_config.min_cloth_color
-#define MAX_CLOTH_COLOR battle_config.max_cloth_color
+#define MIN_HAIR_STYLE (battle_config.min_hair_style)
+#define MAX_HAIR_STYLE (battle_config.max_hair_style)
+#define MIN_HAIR_COLOR (battle_config.min_hair_color)
+#define MAX_HAIR_COLOR (battle_config.max_hair_color)
+#define MIN_CLOTH_COLOR (battle_config.min_cloth_color)
+#define MAX_CLOTH_COLOR (battle_config.max_cloth_color)
-#define is_boss(bl) (status_get_mode(bl)&MD_BOSS) // Can refine later [Aru]
+#define is_boss(bl) (status_get_mode(bl)&MD_BOSS) // Can refine later [Aru]
/**
* Enumerations
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 5927e31bf..e9c3bbabf 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -88,7 +88,7 @@ struct chrif_interface chrif_s;
//2b27: Incoming, chrif_authfail -> 'client authentication failed'
//This define should spare writing the check in every function. [Skotlex]
-#define chrif_check(a) { if(!chrif->isconnected()) return a; }
+#define chrif_check(a) do { if(!chrif->isconnected()) return a; } while(0)
/// Resets all the data.
void chrif_reset(void) {
diff --git a/src/map/clif.c b/src/map/clif.c
index 84976d67c..913f55784 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -18201,8 +18201,8 @@ void packetdb_loaddb(void) {
memset(packet_db,0,sizeof(packet_db));
- #define packet(id, size, ...) packetdb_addpacket(id, size, ##__VA_ARGS__, 0xFFFF)
- #define packetKeys(a,b,c) { clif->cryptKey[0] = a; clif->cryptKey[1] = b; clif->cryptKey[2] = c; }
+ #define packet(id, size, ...) packetdb_addpacket((id), (size), ##__VA_ARGS__, 0xFFFF)
+ #define packetKeys(a,b,c) do { clif->cryptKey[0] = (a); clif->cryptKey[1] = (b); clif->cryptKey[2] = (c); } while(0)
#include "packets.h" /* load structure data */
#undef packet
#undef packetKeys
diff --git a/src/map/clif.h b/src/map/clif.h
index 88f3383d1..76d52311f 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -45,7 +45,7 @@ struct skill_cd;
**/
#define packet_len(cmd) packet_db[cmd].len
#define P2PTR(fd) RFIFO2PTR(fd)
-#define clif_menuskill_clear(sd) (sd)->menuskill_id = (sd)->menuskill_val = (sd)->menuskill_val2 = 0;
+#define clif_menuskill_clear(sd) ((sd)->menuskill_id = (sd)->menuskill_val = (sd)->menuskill_val2 = 0)
#define HCHSYS_NAME_LENGTH 20
/**
diff --git a/src/map/elemental.h b/src/map/elemental.h
index 8ffffa5e3..830a6a577 100644
--- a/src/map/elemental.h
+++ b/src/map/elemental.h
@@ -21,8 +21,8 @@
#define EL_SKILLMODE_ASSIST 0x2
#define EL_SKILLMODE_AGGRESSIVE 0x4
-#define elemental_stop_walking(ed, type) unit->stop_walking(&(ed)->bl, type)
-#define elemental_stop_attack(ed) unit->stop_attack(&(ed)->bl)
+#define elemental_stop_walking(ed, type) (unit->stop_walking(&(ed)->bl, (type)))
+#define elemental_stop_attack(ed) (unit->stop_attack(&(ed)->bl))
/**
* Structures
diff --git a/src/map/homunculus.h b/src/map/homunculus.h
index b7906d4c8..117f9da8e 100644
--- a/src/map/homunculus.h
+++ b/src/map/homunculus.h
@@ -10,7 +10,7 @@
#include "pc.h"
#define MAX_HOM_SKILL_REQUIRE 5
-#define homdb_checkid(id) (id >= HM_CLASS_BASE && id <= HM_CLASS_MAX)
+#define homdb_checkid(id) ((id) >= HM_CLASS_BASE && (id) <= HM_CLASS_MAX)
#define homun_alive(x) ((x) && (x)->homunculus.vaporize == HOM_ST_ACTIVE && (x)->battle_status.hp > 0)
struct h_stats {
diff --git a/src/map/intif.c b/src/map/intif.c
index e6ff91af7..36ae753db 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -35,7 +35,7 @@
struct intif_interface intif_s;
-#define inter_fd chrif->fd // alias
+#define inter_fd (chrif->fd) // alias
//-----------------------------------------------------------------
// Send to inter server
diff --git a/src/map/intif.h b/src/map/intif.h
index 5e996b6fe..d0dfd25cd 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -22,9 +22,9 @@ struct auction_data;
/**
* Defines
**/
-#define intif_rename_pc(sd, name) intif->rename(sd, 0, name)
-#define intif_rename_pet(sd, name) intif->rename(sd, 1, name)
-#define intif_rename_hom(sd, name) intif->rename(sd, 2, name)
+#define intif_rename_pc(sd, name) (intif->rename((sd), 0, (name)))
+#define intif_rename_pet(sd, name) (intif->rename((sd), 1, (name)))
+#define intif_rename_hom(sd, name) (intif->rename((sd), 2, (name)))
#define INTIF_PACKET_LEN_TABLE_SIZE 161
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index 3f31c79d4..4ee6637c1 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -28,7 +28,7 @@ struct item_package;
#define CARD0_PET ((short)0xFF00)
//Marks if the card0 given is "special" (non-item id used to mark pets/created items. [Skotlex]
-#define itemdb_isspecial(i) (i == CARD0_FORGE || i == CARD0_CREATE || i == CARD0_PET)
+#define itemdb_isspecial(i) ((i) == CARD0_FORGE || (i) == CARD0_CREATE || (i) == CARD0_PET)
//Use apple for unknown items.
#define UNKNOWN_ITEM_ID 512
@@ -236,44 +236,45 @@ struct item_package {
unsigned short must_qty;
};
-#define itemdb_name(n) itemdb->search(n)->name
-#define itemdb_jname(n) itemdb->search(n)->jname
-#define itemdb_type(n) itemdb->search(n)->type
-#define itemdb_atk(n) itemdb->search(n)->atk
-#define itemdb_def(n) itemdb->search(n)->def
-#define itemdb_look(n) itemdb->search(n)->look
-#define itemdb_weight(n) itemdb->search(n)->weight
-#define itemdb_equip(n) itemdb->search(n)->equip
-#define itemdb_usescript(n) itemdb->search(n)->script
-#define itemdb_equipscript(n) itemdb->search(n)->script
-#define itemdb_wlv(n) itemdb->search(n)->wlv
-#define itemdb_range(n) itemdb->search(n)->range
-#define itemdb_slot(n) itemdb->search(n)->slot
-#define itemdb_available(n) (itemdb->search(n)->flag.available)
-#define itemdb_viewid(n) (itemdb->search(n)->view_id)
-#define itemdb_autoequip(n) (itemdb->search(n)->flag.autoequip)
-#define itemdb_is_rune(n) ((n >= ITEMID_NAUTHIZ && n <= ITEMID_HAGALAZ) || n == ITEMID_LUX_ANIMA)
-#define itemdb_is_element(n) (n >= 990 && n <= 993)
-#define itemdb_is_spellbook(n) (n >= 6188 && n <= 6205)
-#define itemdb_is_poison(n) (n >= 12717 && n <= 12724)
-#define itemid_isgemstone(id) ( (id) >= ITEMID_YELLOW_GEMSTONE && (id) <= ITEMID_BLUE_GEMSTONE )
-#define itemdb_iscashfood(id) ( (id) >= 12202 && (id) <= 12207 )
-#define itemdb_is_GNbomb(n) (n >= 13260 && n <= 13267)
-#define itemdb_is_GNthrowable(n) (n >= 13268 && n <= 13290)
+#define itemdb_name(n) (itemdb->search(n)->name)
+#define itemdb_jname(n) (itemdb->search(n)->jname)
+#define itemdb_type(n) (itemdb->search(n)->type)
+#define itemdb_atk(n) (itemdb->search(n)->atk)
+#define itemdb_def(n) (itemdb->search(n)->def)
+#define itemdb_look(n) (itemdb->search(n)->look)
+#define itemdb_weight(n) (itemdb->search(n)->weight)
+#define itemdb_equip(n) (itemdb->search(n)->equip)
+#define itemdb_usescript(n) (itemdb->search(n)->script)
+#define itemdb_equipscript(n) (itemdb->search(n)->script)
+#define itemdb_wlv(n) (itemdb->search(n)->wlv)
+#define itemdb_range(n) (itemdb->search(n)->range)
+#define itemdb_slot(n) (itemdb->search(n)->slot)
+#define itemdb_available(n) (itemdb->search(n)->flag.available)
+#define itemdb_viewid(n) (itemdb->search(n)->view_id)
+#define itemdb_autoequip(n) (itemdb->search(n)->flag.autoequip)
+#define itemdb_value_buy(n) (itemdb->search(n)->value_buy)
+#define itemdb_value_sell(n) (itemdb->search(n)->value_sell)
+#define itemdb_canrefine(n) (!itemdb->search(n)->flag.no_refine)
+
+#define itemdb_is_rune(n) (((n) >= ITEMID_NAUTHIZ && (n) <= ITEMID_HAGALAZ) || (n) == ITEMID_LUX_ANIMA)
+#define itemdb_is_element(n) ((n) >= 990 && (n) <= 993)
+#define itemdb_is_spellbook(n) ((n) >= 6188 && (n) <= 6205)
+#define itemdb_is_poison(n) ((n) >= 12717 && (n) <= 12724)
+#define itemid_isgemstone(n) ((n) >= ITEMID_YELLOW_GEMSTONE && (n) <= ITEMID_BLUE_GEMSTONE)
+#define itemdb_iscashfood(n) ((n) >= 12202 && (n) <= 12207)
+#define itemdb_is_GNbomb(n) ((n) >= 13260 && (n) <= 13267)
+#define itemdb_is_GNthrowable(n) ((n) >= 13268 && (n) <= 13290)
-#define itemdb_value_buy(n) itemdb->search(n)->value_buy
-#define itemdb_value_sell(n) itemdb->search(n)->value_sell
-#define itemdb_canrefine(n) (!itemdb->search(n)->flag.no_refine)
//Item trade restrictions [Skotlex]
-#define itemdb_isdropable(item, gmlv) itemdb->isrestricted(item, gmlv, 0, itemdb->isdropable_sub)
-#define itemdb_cantrade(item, gmlv, gmlv2) itemdb->isrestricted(item, gmlv, gmlv2, itemdb->cantrade_sub)
-#define itemdb_canpartnertrade(item, gmlv, gmlv2) itemdb->isrestricted(item, gmlv, gmlv2, itemdb->canpartnertrade_sub)
-#define itemdb_cansell(item, gmlv) itemdb->isrestricted(item, gmlv, 0, itemdb->cansell_sub)
-#define itemdb_cancartstore(item, gmlv) itemdb->isrestricted(item, gmlv, 0, itemdb->cancartstore_sub)
-#define itemdb_canstore(item, gmlv) itemdb->isrestricted(item, gmlv, 0, itemdb->canstore_sub)
-#define itemdb_canguildstore(item, gmlv) itemdb->isrestricted(item , gmlv, 0, itemdb->canguildstore_sub)
-#define itemdb_canmail(item, gmlv) itemdb->isrestricted(item , gmlv, 0, itemdb->canmail_sub)
-#define itemdb_canauction(item, gmlv) itemdb->isrestricted(item , gmlv, 0, itemdb->canauction_sub)
+#define itemdb_isdropable(item, gmlv) (itemdb->isrestricted((item), (gmlv), 0, itemdb->isdropable_sub))
+#define itemdb_cantrade(item, gmlv, gmlv2) (itemdb->isrestricted((item), (gmlv), (gmlv2), itemdb->cantrade_sub))
+#define itemdb_canpartnertrade(item, gmlv, gmlv2) (itemdb->isrestricted((item), (gmlv), (gmlv2), itemdb->canpartnertrade_sub))
+#define itemdb_cansell(item, gmlv) (itemdb->isrestricted((item), (gmlv), 0, itemdb->cansell_sub))
+#define itemdb_cancartstore(item, gmlv) (itemdb->isrestricted((item), (gmlv), 0, itemdb->cancartstore_sub))
+#define itemdb_canstore(item, gmlv) (itemdb->isrestricted((item), (gmlv), 0, itemdb->canstore_sub))
+#define itemdb_canguildstore(item, gmlv) (itemdb->isrestricted((item), (gmlv), 0, itemdb->canguildstore_sub))
+#define itemdb_canmail(item, gmlv) (itemdb->isrestricted((item), (gmlv), 0, itemdb->canmail_sub))
+#define itemdb_canauction(item, gmlv) (itemdb->isrestricted((item), (gmlv), 0, itemdb->canauction_sub))
struct itemdb_interface {
void (*init) (bool minimal);
diff --git a/src/map/map.c b/src/map/map.c
index 17648a661..099d2c6ea 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -2095,9 +2095,7 @@ struct s_mapiterator
/// @param _bl_ block_list
/// @return true if it matches
#define MAPIT_MATCHES(_mapit_,_bl_) \
- ( \
- ( (_bl_)->type & (_mapit_)->types /* type matches */ ) \
- )
+ ( (_bl_)->type & (_mapit_)->types /* type matches */ )
/// Allocates a new iterator.
/// Returns the new iterator.
diff --git a/src/map/map.h b/src/map/map.h
index 4cb00f144..6580d7e50 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -26,7 +26,7 @@ enum E_MAPSERVER_ST {
};
#define MAX_NPC_PER_MAP 512
-#define AREA_SIZE battle_config.area_size
+#define AREA_SIZE (battle_config.area_size)
#define DAMAGELOG_SIZE 30
#define LOOTITEM_SIZE 10
#define MAX_MOBSKILL 50
@@ -39,7 +39,7 @@ enum E_MAPSERVER_ST {
#define MAX_LEVEL 150
#define MAX_IGNORE_LIST 20 // official is 14
#define MAX_VENDING 12
-#define MAX_MAP_SIZE 512*512 // Wasn't there something like this already? Can't find it.. [Shinryo]
+#define MAX_MAP_SIZE (512*512) // Wasn't there something like this already? Can't find it.. [Shinryo]
#define BLOCK_SIZE 8
#define block_free_max 1048576
@@ -221,7 +221,7 @@ enum {
#define CHAT_SIZE_MAX (255 + 1)
// 24 for npc name + 24 for label + 2 for a "::" and 1 for EOS
#define EVENT_NAME_LENGTH ( NAME_LENGTH * 2 + 3 )
-#define DEFAULT_AUTOSAVE_INTERVAL 5*60*1000
+#define DEFAULT_AUTOSAVE_INTERVAL (5*60*1000)
// Specifies maps where players may hit each other
#define map_flag_vs(m) (map->list[m].flag.pvp || map->list[m].flag.gvg_dungeon || map->list[m].flag.gvg || ((map->agit_flag || map->agit2_flag) && map->list[m].flag.gvg_castle) || map->list[m].flag.battleground)
// Specifies maps that have special GvG/WoE restrictions
@@ -724,7 +724,7 @@ struct map_data_other_server {
uint16 port;
};
-#define map_id2index(id) map->list[(id)].index
+#define map_id2index(id) (map->list[(id)].index)
/// Bitfield of flags for the iterator.
enum e_mapitflags {
@@ -747,11 +747,11 @@ struct mapit_interface {
struct mapit_interface *mapit;
-#define mapit_getallusers() mapit->alloc(MAPIT_NORMAL,BL_PC)
-#define mapit_geteachpc() mapit->alloc(MAPIT_NORMAL,BL_PC)
-#define mapit_geteachmob() mapit->alloc(MAPIT_NORMAL,BL_MOB)
-#define mapit_geteachnpc() mapit->alloc(MAPIT_NORMAL,BL_NPC)
-#define mapit_geteachiddb() mapit->alloc(MAPIT_NORMAL,BL_ALL)
+#define mapit_getallusers() (mapit->alloc(MAPIT_NORMAL,BL_PC))
+#define mapit_geteachpc() (mapit->alloc(MAPIT_NORMAL,BL_PC))
+#define mapit_geteachmob() (mapit->alloc(MAPIT_NORMAL,BL_MOB))
+#define mapit_geteachnpc() (mapit->alloc(MAPIT_NORMAL,BL_NPC))
+#define mapit_geteachiddb() (mapit->alloc(MAPIT_NORMAL,BL_ALL))
//Useful typedefs from jA [Skotlex]
typedef struct map_session_data TBL_PC;
diff --git a/src/map/mob.c b/src/map/mob.c
index 4e648b2a6..b41dedac1 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -52,7 +52,7 @@ struct mob_interface mob_s;
#define MOB_LAZYSKILLPERC 0 // Probability for mobs far from players from doing their IDLE skill. (rate of 1000 minute)
// Move probability for mobs away from players (rate of 1000 minute)
// in Aegis, this is 100% for mobs that have been activated by players and none otherwise.
-#define MOB_LAZYMOVEPERC(md) (md->state.spotted?1000:0)
+#define MOB_LAZYMOVEPERC(md) ((md)->state.spotted?1000:0)
#define MOB_MAX_DELAY (24*3600*1000)
#define MAX_MINCHASE 30 //Max minimum chase value to use for mobs.
#define RUDE_ATTACKED_COUNT 2 //After how many rude-attacks should the skill be used?
diff --git a/src/map/mob.h b/src/map/mob.h
index 110d027ef..48a9f078e 100644
--- a/src/map/mob.h
+++ b/src/map/mob.h
@@ -37,7 +37,7 @@
#define MOB_CLONE_END MAX_MOB_DB
//Used to determine default enemy type of mobs (for use in eachinrange calls)
-#define DEFAULT_ENEMY_TYPE(md) (md->special_state.ai?BL_CHAR:BL_MOB|BL_PC|BL_HOM|BL_MER)
+#define DEFAULT_ENEMY_TYPE(md) ((md)->special_state.ai?BL_CHAR:BL_MOB|BL_PC|BL_HOM|BL_MER)
#define MAX_MOB_CHAT 250 //Max Skill's messages
@@ -243,8 +243,9 @@ struct item_drop_list {
};
-#define mob_stop_walking(md, type) unit->stop_walking(&(md)->bl, type)
-#define mob_stop_attack(md) unit->stop_attack(&(md)->bl)
+#define mob_stop_walking(md, type) (unit->stop_walking(&(md)->bl, (type)))
+#define mob_stop_attack(md) (unit->stop_attack(&(md)->bl))
+
#define mob_is_battleground(md) ( map->list[(md)->bl.m].flag.battleground && ((md)->class_ == MOBID_BARRICADE2 || ((md)->class_ >= MOBID_FOOD_STOR && (md)->class_ <= MOBID_PINK_CRYST)) )
#define mob_is_gvg(md) (map->list[(md)->bl.m].flag.gvg_castle && ( (md)->class_ == MOBID_EMPERIUM || (md)->class_ == MOBID_BARRICADE1 || (md)->class_ == MOBID_GUARIDAN_STONE1 || (md)->class_ == MOBID_GUARIDAN_STONE2) )
#define mob_is_treasure(md) (((md)->class_ >= MOBID_TREAS01 && (md)->class_ <= MOBID_TREAS40) || ((md)->class_ >= MOBID_TREAS41 && (md)->class_ <= MOBID_TREAS49))
diff --git a/src/map/path.h b/src/map/path.h
index e872c8877..a889a6409 100644
--- a/src/map/path.h
+++ b/src/map/path.h
@@ -23,13 +23,13 @@ struct shootpath_data {
int y[MAX_WALKPATH];
};
-#define check_distance_bl(bl1, bl2, distance) path->check_distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y, distance)
-#define check_distance_blxy(bl, x1, y1, distance) path->check_distance((bl)->x-(x1), (bl)->y-(y1), distance)
-#define check_distance_xy(x0, y0, x1, y1, distance) path->check_distance((x0)-(x1), (y0)-(y1), distance)
+#define check_distance_bl(bl1, bl2, distance) (path->check_distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y, distance))
+#define check_distance_blxy(bl, x1, y1, distance) (path->check_distance((bl)->x - (x1), (bl)->y - (y1), distance))
+#define check_distance_xy(x0, y0, x1, y1, distance) (path->check_distance((x0) - (x1), (y0) - (y1), distance))
-#define distance_bl(bl1, bl2) path->distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y)
-#define distance_blxy(bl, x1, y1) path->distance((bl)->x-(x1), (bl)->y-(y1))
-#define distance_xy(x0, y0, x1, y1) path->distance((x0)-(x1), (y0)-(y1))
+#define distance_bl(bl1, bl2) (path->distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y))
+#define distance_blxy(bl, x1, y1) (path->distance((bl)->x - (x1), (bl)->y - (y1)))
+#define distance_xy(x0, y0, x1, y1) (path->distance((x0) - (x1), (y0) - (y1)))
struct path_interface {
// calculates destination cell for knockback
diff --git a/src/map/pc.h b/src/map/pc.h
index 71c76b643..f10bd0f59 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -615,8 +615,8 @@ enum equip_pos {
// Rune Knight Dragon
#define pc_isridingdragon(sd) ( (sd)->sc.option&OPTION_DRAGON )
-#define pc_stop_walking(sd, type) unit->stop_walking(&(sd)->bl, type)
-#define pc_stop_attack(sd) unit->stop_attack(&(sd)->bl)
+#define pc_stop_walking(sd, type) (unit->stop_walking(&(sd)->bl, (type)))
+#define pc_stop_attack(sd) (unit->stop_attack(&(sd)->bl))
//Weapon check considering dual wielding.
#define pc_check_weapontype(sd, type) ((type)&((sd)->status.weapon < MAX_WEAPON_TYPE? \
@@ -633,7 +633,7 @@ enum equip_pos {
|| ( (class_) >= JOB_KAGEROU && (class_) <= JOB_OBORO ) \
|| ( (class_) >= JOB_REBELLION && (class_) < JOB_MAX ) \
)
-#define pcdb_checkid(class_) pcdb_checkid_sub((unsigned int)class_)
+#define pcdb_checkid(class_) pcdb_checkid_sub((unsigned int)(class_))
// clientside display macros (values to the left/right of the "+")
#ifdef RENEWAL
@@ -671,18 +671,18 @@ enum equip_pos {
#define pc_checkoverhp(sd) ((sd)->battle_status.hp == (sd)->battle_status.max_hp)
#define pc_checkoversp(sd) ((sd)->battle_status.sp == (sd)->battle_status.max_sp)
-#define pc_readglobalreg(sd,reg) pc->readregistry(sd,reg,3)
-#define pc_setglobalreg(sd,reg,val) pc->setregistry(sd,reg,val,3)
-#define pc_readglobalreg_str(sd,reg) pc->readregistry_str(sd,reg,3)
-#define pc_setglobalreg_str(sd,reg,val) pc->setregistry_str(sd,reg,val,3)
-#define pc_readaccountreg(sd,reg) pc->readregistry(sd,reg,2)
-#define pc_setaccountreg(sd,reg,val) pc->setregistry(sd,reg,val,2)
-#define pc_readaccountregstr(sd,reg) pc->readregistry_str(sd,reg,2)
-#define pc_setaccountregstr(sd,reg,val) pc->setregistry_str(sd,reg,val,2)
-#define pc_readaccountreg2(sd,reg) pc->readregistry(sd,reg,1)
-#define pc_setaccountreg2(sd,reg,val) pc->setregistry(sd,reg,val,1)
-#define pc_readaccountreg2str(sd,reg) pc->readregistry_str(sd,reg,1)
-#define pc_setaccountreg2str(sd,reg,val) pc->setregistry_str(sd,reg,val,1)
+#define pc_readglobalreg(sd,reg) (pc->readregistry((sd),(reg),3))
+#define pc_setglobalreg(sd,reg,val) (pc->setregistry((sd),(reg),(val),3))
+#define pc_readglobalreg_str(sd,reg) (pc->readregistry_str((sd),(reg),3))
+#define pc_setglobalreg_str(sd,reg,val) (pc->setregistry_str((sd),(reg),(val),3))
+#define pc_readaccountreg(sd,reg) (pc->readregistry((sd),(reg),2))
+#define pc_setaccountreg(sd,reg,val) (pc->setregistry((sd),(reg),(val),2))
+#define pc_readaccountregstr(sd,reg) (pc->readregistry_str((sd),(reg),2))
+#define pc_setaccountregstr(sd,reg,val) (pc->setregistry_str((sd),(reg),(val),2))
+#define pc_readaccountreg2(sd,reg) (pc->readregistry((sd),(reg),1))
+#define pc_setaccountreg2(sd,reg,val) (pc->setregistry((sd),(reg),(val),1))
+#define pc_readaccountreg2str(sd,reg) (pc->readregistry_str((sd),(reg),1))
+#define pc_setaccountreg2str(sd,reg,val) (pc->setregistry_str((sd),(reg),(val),1))
struct skill_tree_entry {
short id;
diff --git a/src/map/pet.h b/src/map/pet.h
index f9a756de2..f1a219700 100644
--- a/src/map/pet.h
+++ b/src/map/pet.h
@@ -98,8 +98,8 @@ struct pet_data {
struct map_session_data *msd;
};
-#define pet_stop_walking(pd, type) unit->stop_walking(&(pd)->bl, type)
-#define pet_stop_attack(pd) unit->stop_attack(&(pd)->bl)
+#define pet_stop_walking(pd, type) (unit->stop_walking(&(pd)->bl, (type)))
+#define pet_stop_attack(pd) (unit->stop_attack(&(pd)->bl))
struct pet_interface {
struct s_pet_db db[MAX_PET_DB];
diff --git a/src/map/script.c b/src/map/script.c
index 0827258d7..0f2c86868 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -278,7 +278,7 @@ void disp_error_message2(const char *mes,const char *pos,int report)
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) (script->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);
@@ -3986,9 +3986,6 @@ const char *script_getfuncname(struct script_state *st) {
// buildin functions
//
-#define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args }
-#define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args }
-
/////////////////////////////////////////////////////////////////////
// NPC interaction
//
@@ -13016,7 +13013,7 @@ BUILDIN(isequippedcnt)
}
for (i=0; id!=0; i++) {
- script_fetch(st,i+2, id) else id = 0;
+ script_fetch(st,i+2, id);
if (id <= 0)
continue;
@@ -13074,7 +13071,7 @@ BUILDIN(isequipped)
setitem_hash = sd->bonus.setitem_hash;
setitem_hash2 = sd->bonus.setitem_hash2;
for (i=0; id!=0; i++) {
- script_fetch(st,i+2, id) else id = 0;
+ script_fetch(st,i+2, id);
if (id <= 0)
continue;
flag = 0;
@@ -13148,7 +13145,7 @@ BUILDIN(cardscnt) {
sd = script->rid2sd(st);
for (i=0; id!=0; i++) {
- script_fetch(st,i+2, id) else id = 0;
+ script_fetch(st,i+2, id);
if (id <= 0)
continue;
@@ -17961,6 +17958,8 @@ bool script_hp_add(char *name, char *args, bool (*func)(struct script_state *st)
return true;
}
+#define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args }
+#define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args }
void script_parse_builtin(void) {
struct script_function BUILDIN[] = {
// NPC interaction
@@ -18504,6 +18503,8 @@ void script_parse_builtin(void) {
}
}
}
+#undef BUILDIN_DEF
+#undef BUILDIN_DEF2
void script_label_add(int key, int pos) {
int idx = script->label_count;
diff --git a/src/map/script.h b/src/map/script.h
index 0bb92c433..32426e988 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -22,9 +22,9 @@ struct eri;
**/
// TODO: Remove temporary code
#define ENABLE_CASE_CHECK
-#define DeprecationWarning(func, bad, good, file, line) ShowWarning("%s: use of deprecated keyword '%s' (use '%s' instead) in file '%s', line '%d'. This will be a critical error in a near future.\n", func, bad, good, file, line);
-#define DeprecationWarning2(func, bad, good, where) ShowWarning("%s: detected possible use of wrong case in a script. Found '%s', probably meant to be '%s' (in '%s'). If it is a local (.@) variable, and you're absolutely sure you used the correct case, please disragard this message, otherwise please correct your scripts, as this will become fatal in a near future.\n", func, bad, good, where);
-#define disp_deprecation_message(func, good, p) disp_warning_message(func": use of deprecated keyword (use '"good"' instead). This will be a critical error in a near future.", p);
+#define DeprecationWarning(func, bad, good, file, line) ShowWarning("%s: use of deprecated keyword '%s' (use '%s' instead) in file '%s', line '%d'. This will be a critical error in a near future.\n", (func), (bad), (good), (file), (line));
+#define DeprecationWarning2(func, bad, good, where) ShowWarning("%s: detected possible use of wrong case in a script. Found '%s', probably meant to be '%s' (in '%s'). This will become fatal in a near future.\n", (func), (bad), (good), (where));
+#define disp_deprecation_message(func, good, p) disp_warning_message(func": use of deprecated keyword (use '"good"' instead). This will be a critical error in a near future.", (p));
#define NUM_WHISPER_VAR 10
@@ -71,24 +71,24 @@ struct eri;
/// Returns the index of the last data in the stack
#define script_lastdata(st) ( (st)->end - (st)->start - 1 )
/// Pushes an int into the stack
-#define script_pushint(st,val) script->push_val((st)->stack, C_INT, (val),NULL)
+#define script_pushint(st,val) (script->push_val((st)->stack, C_INT, (val),NULL))
/// Pushes a string into the stack (script engine frees it automatically)
-#define script_pushstr(st,val) script->push_str((st)->stack, C_STR, (val))
+#define script_pushstr(st,val) (script->push_str((st)->stack, C_STR, (val)))
/// Pushes a copy of a string into the stack
-#define script_pushstrcopy(st,val) script->push_str((st)->stack, C_STR, aStrdup(val))
+#define script_pushstrcopy(st,val) (script->push_str((st)->stack, C_STR, aStrdup(val)))
/// Pushes a constant string into the stack (must never change or be freed)
-#define script_pushconststr(st,val) script->push_str((st)->stack, C_CONSTSTR, (val))
+#define script_pushconststr(st,val) (script->push_str((st)->stack, C_CONSTSTR, (val)))
/// Pushes a nil into the stack
-#define script_pushnil(st) script->push_val((st)->stack, C_NOP, 0,NULL)
+#define script_pushnil(st) (script->push_val((st)->stack, C_NOP, 0,NULL))
/// Pushes a copy of the data in the target index
-#define script_pushcopy(st,i) script->push_copy((st)->stack, (st)->start + (i))
+#define script_pushcopy(st,i) (script->push_copy((st)->stack, (st)->start + (i)))
-#define script_isstring(st,i) data_isstring(script_getdata(st,i))
-#define script_isint(st,i) data_isint(script_getdata(st,i))
+#define script_isstring(st,i) data_isstring(script_getdata((st),(i)))
+#define script_isint(st,i) data_isint(script_getdata((st),(i)))
-#define script_getnum(st,val) script->conv_num(st, script_getdata(st,val))
-#define script_getstr(st,val) script->conv_str(st, script_getdata(st,val))
-#define script_getref(st,val) ( script_getdata(st,val)->ref )
+#define script_getnum(st,val) (script->conv_num((st), script_getdata((st),(val))))
+#define script_getstr(st,val) (script->conv_str((st), script_getdata((st),(val))))
+#define script_getref(st,val) ( script_getdata((st),(val))->ref )
// Note: "top" functions/defines use indexes relative to the top of the stack
// -1 is the index of the data at the top
@@ -147,9 +147,12 @@ struct eri;
#define BUILDIN(x) bool buildin_ ## x (struct script_state* st)
#define BUILDIN_A(x) buildin_ ## x
-#define script_fetch(st, n, t) \
- if( script_hasdata(st,n) ) \
- (t)=script_getnum(st,n);
+#define script_fetch(st, n, t) do { \
+ if( script_hasdata((st),(n)) ) \
+ (t)=script_getnum((st),(n)); \
+ else \
+ (t) = 0; \
+} while(0)
/**
diff --git a/src/map/skill.c b/src/map/skill.c
index fa26cdb12..c38363ef3 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -47,13 +47,13 @@
// ranges reserved for mapping skill ids to skilldb offsets
#define HM_SKILLRANGEMIN 750
-#define HM_SKILLRANGEMAX HM_SKILLRANGEMIN + MAX_HOMUNSKILL
-#define MC_SKILLRANGEMIN HM_SKILLRANGEMAX + 1
-#define MC_SKILLRANGEMAX MC_SKILLRANGEMIN + MAX_MERCSKILL
-#define EL_SKILLRANGEMIN MC_SKILLRANGEMAX + 1
-#define EL_SKILLRANGEMAX EL_SKILLRANGEMIN + MAX_ELEMENTALSKILL
-#define GD_SKILLRANGEMIN EL_SKILLRANGEMAX + 1
-#define GD_SKILLRANGEMAX GD_SKILLRANGEMIN + MAX_GUILDSKILL
+#define HM_SKILLRANGEMAX (HM_SKILLRANGEMIN + MAX_HOMUNSKILL)
+#define MC_SKILLRANGEMIN (HM_SKILLRANGEMAX + 1)
+#define MC_SKILLRANGEMAX (MC_SKILLRANGEMIN + MAX_MERCSKILL)
+#define EL_SKILLRANGEMIN (MC_SKILLRANGEMAX + 1)
+#define EL_SKILLRANGEMAX (EL_SKILLRANGEMIN + MAX_ELEMENTALSKILL)
+#define GD_SKILLRANGEMIN (EL_SKILLRANGEMAX + 1)
+#define GD_SKILLRANGEMAX (GD_SKILLRANGEMIN + MAX_GUILDSKILL)
#if GD_SKILLRANGEMAX > 999
#error GD_SKILLRANGEMAX is greater than 999
@@ -131,17 +131,17 @@ void skill_chk(uint16* skill_id) {
*skill_id = skill->get_index(*skill_id); // checks/adjusts id
}
-#define skill_get(var,id) { skill->chk(&id); if(!id) return 0; return var; }
-#define skill_get2(var,id,lv) { \
- skill->chk(&id); \
- if(!id) return 0; \
- if( lv > MAX_SKILL_LEVEL && var > 1 ) { \
- int lv2 = lv; lv = skill->db[id].max; \
- return (var) + ((lv2-lv)/2);\
+#define skill_get(var,id) do { skill->chk(&(id)); if(!(id)) return 0; return (var); } while(0)
+#define skill_get2(var,id,lv) do { \
+ skill->chk(&(id)); \
+ if(!(id)) return 0; \
+ if( (lv) > MAX_SKILL_LEVEL && (var) > 1 ) { \
+ int lv2__ = (lv); (lv) = skill->db[(id)].max; \
+ return (var) + ((lv2__-(lv))/2);\
} \
- return var;\
-}
-#define skill_glv(lv) min(lv,MAX_SKILL_LEVEL-1)
+ return (var);\
+} while(0)
+#define skill_glv(lv) min((lv),MAX_SKILL_LEVEL-1)
// Skill DB
int skill_get_hit( uint16 skill_id ) { skill_get (skill->db[skill_id].hit, skill_id); }
int skill_get_inf( uint16 skill_id ) { skill_get (skill->db[skill_id].inf, skill_id); }
@@ -9523,7 +9523,7 @@ int skill_castend_map (struct map_session_data *sd, uint16 skill_id, const char
nullpo_ret(sd);
//Simplify skill_failed code.
-#define skill_failed(sd) { sd->menuskill_id = sd->menuskill_val = 0; }
+#define skill_failed(sd) ( (sd)->menuskill_id = (sd)->menuskill_val = 0 )
if(skill_id != sd->menuskill_id)
return 0;
diff --git a/src/map/status.c b/src/map/status.c
index a8389691f..d64986eca 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -102,10 +102,6 @@ int status_type2relevant_bl_types(int type)
return status->RelevantBLTypes[type];
}
-#define add_sc(skill,sc) set_sc(skill,sc,SI_BLANK,SCB_NONE)
-// indicates that the status displays a visual effect for the affected unit, and should be sent to the client for all supported units
-#define set_sc_with_vfx(skill, sc, icon, flag) set_sc((skill), (sc), (icon), (flag)); if((icon) < SI_MAX) status->RelevantBLTypes[(icon)] |= BL_SCEFFECT
-
static void set_sc(uint16 skill_id, sc_type sc, int icon, unsigned int flag) {
uint16 idx;
if( (idx = skill->get_index(skill_id)) == 0 ) {
@@ -128,6 +124,10 @@ static void set_sc(uint16 skill_id, sc_type sc, int icon, unsigned int flag) {
}
void initChangeTables(void) {
+#define add_sc(skill,sc) set_sc((skill),(sc),SI_BLANK,SCB_NONE)
+// indicates that the status displays a visual effect for the affected unit, and should be sent to the client for all supported units
+#define set_sc_with_vfx(skill, sc, icon, flag) do { set_sc((skill), (sc), (icon), (flag)); if((icon) < SI_MAX) status->RelevantBLTypes[(icon)] |= BL_SCEFFECT; } while(0)
+
int i;
for (i = 0; i < SC_MAX; i++)
@@ -1034,6 +1034,8 @@ void initChangeTables(void) {
if( !battle_config.display_hallucination ) //Disable Hallucination.
status->IconChangeTable[SC_ILLUSION] = SI_BLANK;
+#undef add_sc
+#undef set_sc_with_vfx
}
void initDummyData(void)
@@ -8559,12 +8561,14 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
break;
case SC_GENSOU:
- #define PER( a ) do { \
- if( a <= 15 ) lv = 1; \
- else if( a <= 30 ) lv = 2; \
- else if( a <= 50 ) lv = 3; \
- else if( a <= 75 ) lv = 4; \
- } while(0)
+#define PER( a, lvl ) do { \
+ int temp__ = (a); \
+ if( temp__ <= 15 ) (lvl) = 1; \
+ else if( temp__ <= 30 ) (lvl) = 2; \
+ else if( temp__ <= 50 ) (lvl) = 3; \
+ else if( temp__ <= 75 ) (lvl) = 4; \
+ else (lvl) = 5; \
+} while(0)
{
int hp = status_get_hp(bl), sp = status_get_sp(bl), lv = 5;
@@ -8572,13 +8576,13 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
if( rand()%100 > (25 + 10 * val1) - status_get_int(bl) / 2)
return 0;
- PER( 100 / (status_get_max_hp(bl) / hp) );
+ PER( 100 / (status_get_max_hp(bl) / hp), lv );
status->heal(bl, (!(hp%2) ? (6-lv) *4 / 100 : -(lv*4) / 100), 0, 1);
- PER( 100 / (status_get_max_sp(bl) / sp) );
+ PER( 100 / (status_get_max_sp(bl) / sp), lv );
status->heal(bl, 0,(!(sp%2) ? (6-lv) *3 / 100 : -(lv*3) / 100), 1);
}
- #undef PER
+#undef PER
break;
case SC_ANGRIFFS_MODUS:
val2 = 50 + 20 * val1; //atk bonus
@@ -10022,7 +10026,7 @@ int status_change_timer(int tid, int64 tick, int id, intptr_t data) {
// set the next timer of the sce (don't assume the status still exists)
#define sc_timer_next(t,f,i,d) do { \
if( (sce=sc->data[type]) ) \
- sce->timer = timer->add(t,f,i,d); \
+ sce->timer = timer->add((t),(f),(i),(d)); \
else \
ShowError("status_change_timer: Unexpected NULL status change id: %d data: %d\n", id, data); \
} while(0)
diff --git a/src/map/status.h b/src/map/status.h
index cdd5fa481..75582e9a4 100644
--- a/src/map/status.h
+++ b/src/map/status.h
@@ -1764,67 +1764,67 @@ struct status_change {
//Define for standard HP damage attacks.
-#define status_fix_damage(src, target, hp, walkdelay) status->damage(src, target, hp, 0, walkdelay, 0)
+#define status_fix_damage(src, target, hp, walkdelay) (status->damage((src), (target), (hp), 0, (walkdelay), 0))
//Define for standard HP/SP damage triggers.
-#define status_zap(bl, hp, sp) status->damage(NULL, bl, hp, sp, 0, 1)
+#define status_zap(bl, hp, sp) (status->damage(NULL, (bl), (hp), (sp), 0, 1))
//Easier handling of status->percent_change
-#define status_percent_heal(bl, hp_rate, sp_rate) status->percent_change(NULL, bl, -(hp_rate), -(sp_rate), 0)
-#define status_percent_damage(src, target, hp_rate, sp_rate, kill) status->percent_change(src, target, hp_rate, sp_rate, (kill)?1:2)
+#define status_percent_heal(bl, hp_rate, sp_rate) (status->percent_change(NULL, (bl), -(hp_rate), -(sp_rate), 0))
+#define status_percent_damage(src, target, hp_rate, sp_rate, kill) (status->percent_change((src), (target), (hp_rate), (sp_rate), (kill)?1:2))
//Instant kill with no drops/exp/etc
-#define status_kill(bl) status_percent_damage(NULL, bl, 100, 0, true)
+#define status_kill(bl) status_percent_damage(NULL, (bl), 100, 0, true)
-#define status_get_range(bl) status->get_status_data(bl)->rhw.range
-#define status_get_hp(bl) status->get_status_data(bl)->hp
-#define status_get_max_hp(bl) status->get_status_data(bl)->max_hp
-#define status_get_sp(bl) status->get_status_data(bl)->sp
-#define status_get_max_sp(bl) status->get_status_data(bl)->max_sp
-#define status_get_str(bl) status->get_status_data(bl)->str
-#define status_get_agi(bl) status->get_status_data(bl)->agi
-#define status_get_vit(bl) status->get_status_data(bl)->vit
-#define status_get_int(bl) status->get_status_data(bl)->int_
-#define status_get_dex(bl) status->get_status_data(bl)->dex
-#define status_get_luk(bl) status->get_status_data(bl)->luk
-#define status_get_hit(bl) status->get_status_data(bl)->hit
-#define status_get_flee(bl) status->get_status_data(bl)->flee
-#define status_get_mdef(bl) status->get_status_data(bl)->mdef
-#define status_get_flee2(bl) status->get_status_data(bl)->flee2
-#define status_get_def2(bl) status->get_status_data(bl)->def2
-#define status_get_mdef2(bl) status->get_status_data(bl)->mdef2
-#define status_get_critical(bl) status->get_status_data(bl)->cri
-#define status_get_batk(bl) status->get_status_data(bl)->batk
-#define status_get_watk(bl) status->get_status_data(bl)->rhw.atk
-#define status_get_watk2(bl) status->get_status_data(bl)->rhw.atk2
-#define status_get_matk_max(bl) status->get_status_data(bl)->matk_max
-#define status_get_matk_min(bl) status->get_status_data(bl)->matk_min
-#define status_get_lwatk(bl) status->get_status_data(bl)->lhw.atk
-#define status_get_lwatk2(bl) status->get_status_data(bl)->lhw.atk2
-#define status_get_adelay(bl) status->get_status_data(bl)->adelay
-#define status_get_amotion(bl) status->get_status_data(bl)->amotion
-#define status_get_dmotion(bl) status->get_status_data(bl)->dmotion
-#define status_get_element(bl) status->get_status_data(bl)->def_ele
-#define status_get_element_level(bl) status->get_status_data(bl)->ele_lv
-#define status_get_attack_sc_element(bl, sc) status->calc_attack_element(bl, sc, 0)
-#define status_get_attack_element(bl) status->get_status_data(bl)->rhw.ele
-#define status_get_attack_lelement(bl) status->get_status_data(bl)->lhw.ele
-#define status_get_race(bl) status->get_status_data(bl)->race
-#define status_get_size(bl) status->get_status_data(bl)->size
-#define status_get_mode(bl) status->get_status_data(bl)->mode
+#define status_get_range(bl) (status->get_status_data(bl)->rhw.range)
+#define status_get_hp(bl) (status->get_status_data(bl)->hp)
+#define status_get_max_hp(bl) (status->get_status_data(bl)->max_hp)
+#define status_get_sp(bl) (status->get_status_data(bl)->sp)
+#define status_get_max_sp(bl) (status->get_status_data(bl)->max_sp)
+#define status_get_str(bl) (status->get_status_data(bl)->str)
+#define status_get_agi(bl) (status->get_status_data(bl)->agi)
+#define status_get_vit(bl) (status->get_status_data(bl)->vit)
+#define status_get_int(bl) (status->get_status_data(bl)->int_)
+#define status_get_dex(bl) (status->get_status_data(bl)->dex)
+#define status_get_luk(bl) (status->get_status_data(bl)->luk)
+#define status_get_hit(bl) (status->get_status_data(bl)->hit)
+#define status_get_flee(bl) (status->get_status_data(bl)->flee)
+#define status_get_mdef(bl) (status->get_status_data(bl)->mdef)
+#define status_get_flee2(bl) (status->get_status_data(bl)->flee2)
+#define status_get_def2(bl) (status->get_status_data(bl)->def2)
+#define status_get_mdef2(bl) (status->get_status_data(bl)->mdef2)
+#define status_get_critical(bl) (status->get_status_data(bl)->cri)
+#define status_get_batk(bl) (status->get_status_data(bl)->batk)
+#define status_get_watk(bl) (status->get_status_data(bl)->rhw.atk)
+#define status_get_watk2(bl) (status->get_status_data(bl)->rhw.atk2)
+#define status_get_matk_max(bl) (status->get_status_data(bl)->matk_max)
+#define status_get_matk_min(bl) (status->get_status_data(bl)->matk_min)
+#define status_get_lwatk(bl) (status->get_status_data(bl)->lhw.atk)
+#define status_get_lwatk2(bl) (status->get_status_data(bl)->lhw.atk2)
+#define status_get_adelay(bl) (status->get_status_data(bl)->adelay)
+#define status_get_amotion(bl) (status->get_status_data(bl)->amotion)
+#define status_get_dmotion(bl) (status->get_status_data(bl)->dmotion)
+#define status_get_element(bl) (status->get_status_data(bl)->def_ele)
+#define status_get_element_level(bl) (status->get_status_data(bl)->ele_lv)
+#define status_get_attack_sc_element(bl, sc) (status->calc_attack_element((bl), (sc), 0))
+#define status_get_attack_element(bl) (status->get_status_data(bl)->rhw.ele)
+#define status_get_attack_lelement(bl) (status->get_status_data(bl)->lhw.ele)
+#define status_get_race(bl) (status->get_status_data(bl)->race)
+#define status_get_size(bl) (status->get_status_data(bl)->size)
+#define status_get_mode(bl) (status->get_status_data(bl)->mode)
//Short version, receives rate in 1->100 range, and does not uses a flag setting.
-#define sc_start(bl, type, rate, val1, tick) status->change_start(bl,type,100*(rate),val1,0,0,0,tick,0)
-#define sc_start2(bl, type, rate, val1, val2, tick) status->change_start(bl,type,100*(rate),val1,val2,0,0,tick,0)
-#define sc_start4(bl, type, rate, val1, val2, val3, val4, tick) status->change_start(bl,type,100*(rate),val1,val2,val3,val4,tick,0)
+#define sc_start(bl, type, rate, val1, tick) (status->change_start((bl),(type),100*(rate),(val1),0,0,0,(tick),0))
+#define sc_start2(bl, type, rate, val1, val2, tick) (status->change_start((bl),(type),100*(rate),(val1),(val2),0,0,(tick),0))
+#define sc_start4(bl, type, rate, val1, val2, val3, val4, tick) (status->change_start((bl),(type),100*(rate),(val1),(val2),(val3),(val4),(tick),0))
-#define status_change_end(bl,type,tid) status->change_end_(bl,type,tid,__FILE__,__LINE__)
+#define status_change_end(bl,type,tid) (status->change_end_((bl),(type),(tid),__FILE__,__LINE__))
-#define status_calc_bl(bl, flag) status->calc_bl_(bl, (enum scb_flag)(flag), SCO_NONE)
-#define status_calc_mob(md, opt) status->calc_bl_(&(md)->bl, SCB_ALL, opt)
-#define status_calc_pet(pd, opt) status->calc_bl_(&(pd)->bl, SCB_ALL, opt)
-#define status_calc_pc(sd, opt) status->calc_bl_(&(sd)->bl, SCB_ALL, opt)
-#define status_calc_homunculus(hd, opt) status->calc_bl_(&(hd)->bl, SCB_ALL, opt)
-#define status_calc_mercenary(md, opt) status->calc_bl_(&(md)->bl, SCB_ALL, opt)
-#define status_calc_elemental(ed, opt) status->calc_bl_(&(ed)->bl, SCB_ALL, opt)
-#define status_calc_npc(nd, opt) status->calc_bl_(&(nd)->bl, SCB_ALL, opt)
+#define status_calc_bl(bl, flag) (status->calc_bl_((bl), (enum scb_flag)(flag), SCO_NONE))
+#define status_calc_mob(md, opt) (status->calc_bl_(&(md)->bl, SCB_ALL, (opt)))
+#define status_calc_pet(pd, opt) (status->calc_bl_(&(pd)->bl, SCB_ALL, (opt)))
+#define status_calc_pc(sd, opt) (status->calc_bl_(&(sd)->bl, SCB_ALL, (opt)))
+#define status_calc_homunculus(hd, opt) (status->calc_bl_(&(hd)->bl, SCB_ALL, (opt)))
+#define status_calc_mercenary(md, opt) (status->calc_bl_(&(md)->bl, SCB_ALL, (opt)))
+#define status_calc_elemental(ed, opt) (status->calc_bl_(&(ed)->bl, SCB_ALL, (opt)))
+#define status_calc_npc(nd, opt) (status->calc_bl_(&(nd)->bl, SCB_ALL, (opt)))
// bonus values and upgrade chances for refining equipment
struct s_refine_info {