summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-10-16 06:46:57 +0000
committerai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-10-16 06:46:57 +0000
commit6669de77431e0bb6548bdcbb13a6cf13f40b247f (patch)
tree5f374064a47b94ad9a7cbb8b3ce08305b7e58327 /src
parentf87f36b82dbf7f907555fed2fdd8efab8f869ea6 (diff)
downloadhercules-6669de77431e0bb6548bdcbb13a6cf13f40b247f.tar.gz
hercules-6669de77431e0bb6548bdcbb13a6cf13f40b247f.tar.bz2
hercules-6669de77431e0bb6548bdcbb13a6cf13f40b247f.tar.xz
hercules-6669de77431e0bb6548bdcbb13a6cf13f40b247f.zip
* Changed function-like macros into inline functions where it seemed appropriate (topic:264007).
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14976 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/map/clif.c84
-rw-r--r--src/map/script.c12
-rw-r--r--src/map/skill.c5
-rw-r--r--src/map/status.c22
-rw-r--r--src/map/status.h6
-rw-r--r--src/map/unit.c10
6 files changed, 98 insertions, 41 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 7b2a97006..e75c4f6bc 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -63,35 +63,60 @@ static inline int itemtype(int type)
return ( type == IT_PETEGG ) ? IT_WEAPON : type;
}
-#define WBUFPOS(p,pos,x,y,dir) \
- do { \
- uint8 *__p = (p); \
- __p+=(pos); \
- __p[0] = (uint8)((x)>>2); \
- __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
- __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
- } while(0)
+
+static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir)
+{
+ p += pos;
+ p[0] = (uint8)(x>>2);
+ p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
+ p[2] = (uint8)((y<<4) | (dir&0xf));
+}
+
+
// client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
-#define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
- do { \
- uint8 *__p = (p); \
- __p+=(pos); \
- __p[0]=(uint8)((x0)>>2); \
- __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
- __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
- __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
- __p[4]=(uint8)(y1); \
- __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
- } while(0)
-
-#define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
-#define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
+static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
+{
+ p += pos;
+ p[0] = (uint8)(x0>>2);
+ p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
+ p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
+ p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
+ p[4] = (uint8)y1;
+ p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
+}
+
+
+static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir)
+{
+ WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
+}
+
+
+inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
+{
+ WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
+}
+
//To idenfity disguised characters.
-#define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
+static inline bool disguised(struct block_list* bl)
+{
+ return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
+}
+
+
+//Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
+static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max)
+{
+ if( len > max )
+ len = max;
+
+ mes[len-1] = '\0';
+
+ return len;
+}
+
-//Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
-#define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
static char map_ip_str[128];
static uint32 map_ip;
static uint32 bind_ip = INADDR_ANY;
@@ -3792,7 +3817,10 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
//Modifies the type of damage according to status changes [Skotlex]
//Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
-#define clif_calc_delay(type,div,damage,delay) ((delay)==0&&(damage)>0?((div)>1?9:4):type)
+static inline int clif_calc_delay(int type, int div, int damage, int delay)
+{
+ return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
+}
/*==========================================
* Estimates walk delay based on the damage criteria. [Skotlex]
@@ -9402,7 +9430,7 @@ void clif_parse_Broadcast(int fd, struct map_session_data* sd)
return;
// as the length varies depending on the command used, just block unreasonably long strings
- mes_len_check(msg, len, CHAT_SIZE_MAX);
+ len = mes_len_check(msg, len, CHAT_SIZE_MAX);
intif_broadcast(msg, len, 0);
@@ -10505,7 +10533,7 @@ void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
return;
// as the length varies depending on the command used, just block unreasonably long strings
- mes_len_check(msg, len, CHAT_SIZE_MAX);
+ len = mes_len_check(msg, len, CHAT_SIZE_MAX);
clif_broadcast(&sd->bl, msg, len, 0, ALL_SAMEMAP);
diff --git a/src/map/script.c b/src/map/script.c
index 6a5243f74..92ae852e9 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -171,8 +171,16 @@ enum { LABEL_NEXTLINE=1,LABEL_START };
static unsigned char* script_buf = NULL;
static int script_pos = 0, script_size = 0;
-#define GETVALUE(buf,i) ((int)MakeDWord(MakeWord((buf)[i],(buf)[i+1]),MakeWord((buf)[i+2],0)))
-#define SETVALUE(buf,i,n) ((buf)[i]=GetByte(n,0),(buf)[i+1]=GetByte(n,1),(buf)[i+2]=GetByte(n,2))
+static inline int GETVALUE(const unsigned char* buf, int i)
+{
+ return (int)MakeDWord(MakeWord(buf[i], buf[i+1]), MakeWord(buf[i+2], 0));
+}
+static inline void SETVALUE(unsigned char* buf, int i, int n)
+{
+ buf[i] = GetByte(n, 0);
+ buf[i+1] = GetByte(n, 1);
+ buf[i+2] = GetByte(n, 2);
+}
// String buffer structures.
// str_data stores string information
diff --git a/src/map/skill.c b/src/map/skill.c
index ad333c17d..28bb9e389 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -65,7 +65,10 @@ int firewall_unit_pos;
int icewall_unit_pos;
//Since only mob-casted splash skills can hit ice-walls
-#define splash_target(bl) (bl->type==BL_MOB?BL_SKILL|BL_CHAR:BL_CHAR)
+static inline int splash_target(struct block_list* bl)
+{
+ return ( bl->type == BL_MOB ) ? BL_SKILL|BL_CHAR : BL_CHAR;
+}
/// Returns the id of the skill, or 0 if not found.
int skill_name2id(const char* name)
diff --git a/src/map/status.c b/src/map/status.c
index 3ec822a6a..26c0c1b2f 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -599,6 +599,14 @@ static void initDummyData(void)
dummy_status.mode = MD_CANMOVE;
}
+
+//For copying a status_data structure from b to a, without overwriting current Hp and Sp
+static inline void status_cpy(struct status_data* a, const struct status_data* b)
+{
+ memcpy((void*)&a->max_hp, (const void*)&b->max_hp, sizeof(struct status_data)-(sizeof(a->hp)+sizeof(a->sp)));
+}
+
+
/*==========================================
* B{[iX
*------------------------------------------*/
@@ -1320,8 +1328,18 @@ static unsigned short status_base_atk(const struct block_list *bl, const struct
return cap_value(str, 0, USHRT_MAX);
}
-#define status_base_matk_max(status) (status->int_+(status->int_/5)*(status->int_/5))
-#define status_base_matk_min(status) (status->int_+(status->int_/7)*(status->int_/7))
+
+static inline unsigned short status_base_matk_max(const struct status_data* status)
+{
+ return status->int_+(status->int_/5)*(status->int_/5);
+}
+
+
+static inline unsigned short status_base_matk_min(const struct status_data* status)
+{
+ return status->int_+(status->int_/7)*(status->int_/7);
+}
+
//Fills in the misc data that can be calculated from the other status info (except for level)
void status_calc_misc(struct block_list *bl, struct status_data *status, int level)
diff --git a/src/map/status.h b/src/map/status.h
index d3f5a2f48..dcd532577 100644
--- a/src/map/status.h
+++ b/src/map/status.h
@@ -1108,7 +1108,7 @@ struct weapon_atk {
//For holding basic status (which can be modified by status changes)
struct status_data {
unsigned int
- hp, sp,
+ hp, sp, // see status_cpy before adding members before hp and sp
max_hp, max_sp;
unsigned short
str, agi, vit, int_, dex, luk,
@@ -1215,10 +1215,6 @@ int status_set_sp(struct block_list *bl, unsigned int sp, int flag);
int status_heal(struct block_list *bl,int hp,int sp, int flag);
int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per_sp);
-//Define for copying a status_data structure from b to a, without overwriting current Hp and Sp
-#define status_cpy(a, b) \
- memcpy(&((a)->max_hp), &((b)->max_hp), sizeof(struct status_data)-(sizeof((a)->hp)+sizeof((a)->sp)))
-
struct regen_data *status_get_regen_data(struct block_list *bl);
struct status_data *status_get_status_data(struct block_list *bl);
struct status_data *status_get_base_status(struct block_list *bl);
diff --git a/src/map/unit.c b/src/map/unit.c
index 09a19e27d..a11b5dc28 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -323,9 +323,13 @@ int unit_walktoxy( struct block_list *bl, short x, short y, int flag)
}
//To set Mob's CHASE/FOLLOW states (shouldn't be done if there's no path to reach)
-#define set_mobstate(bl, flag) \
- if((bl)->type == BL_MOB && (flag)) \
- ((TBL_MOB*)(bl))->state.skillstate = ((TBL_MOB*)(bl))->state.aggressive?MSS_FOLLOW:MSS_RUSH;
+static inline void set_mobstate(struct block_list* bl, int flag)
+{
+ struct mob_data* md = BL_CAST(BL_MOB,bl);
+
+ if( md && flag )
+ md->state.skillstate = md->state.aggressive ? MSS_FOLLOW : MSS_RUSH;
+}
static int unit_walktobl_sub(int tid, unsigned int tick, int id, intptr_t data)
{