summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c49
-rw-r--r--src/char/geoip.c3
-rw-r--r--src/char/int_auction.c5
-rw-r--r--src/char/int_guild.c13
-rw-r--r--src/char/int_homun.c18
-rw-r--r--src/char/int_mail.c2
-rw-r--r--src/char/int_party.c12
-rw-r--r--src/char/int_storage.c11
-rw-r--r--src/char/inter.c5
-rw-r--r--src/char/pincode.c5
-rw-r--r--src/common/HPM.c20
-rw-r--r--src/common/core.c13
-rw-r--r--src/common/db.c12
-rw-r--r--src/common/malloc.c5
-rw-r--r--src/common/socket.c41
-rw-r--r--src/common/sql.c53
-rw-r--r--src/common/strlib.c11
-rw-r--r--src/common/sysinfo.c2
-rw-r--r--src/common/utils.c5
-rw-r--r--src/login/account_sql.c6
-rw-r--r--src/login/login.c15
-rw-r--r--src/map/HPMmap.c10
-rw-r--r--src/map/atcommand.c143
-rw-r--r--src/map/battle.c44
-rw-r--r--src/map/battleground.c32
-rw-r--r--src/map/buyingstore.c10
-rw-r--r--src/map/chrif.c5
-rw-r--r--src/map/clif.c111
-rw-r--r--src/map/guild.c28
-rw-r--r--src/map/homunculus.c2
-rw-r--r--src/map/instance.c17
-rw-r--r--src/map/intif.c18
-rw-r--r--src/map/itemdb.c43
-rw-r--r--src/map/map.c38
-rw-r--r--src/map/mapreg_sql.c12
-rw-r--r--src/map/mob.c61
-rw-r--r--src/map/npc.c75
-rw-r--r--src/map/party.c33
-rw-r--r--src/map/pc.c162
-rw-r--r--src/map/pc.h9
-rw-r--r--src/map/pet.c32
-rw-r--r--src/map/script.c825
-rw-r--r--src/map/skill.c388
-rw-r--r--src/map/status.c238
-rw-r--r--src/map/trade.c5
-rw-r--r--src/map/unit.c45
-rw-r--r--src/test/test_spinlock.c10
-rw-r--r--src/tool/mapcache.c9
48 files changed, 1328 insertions, 1383 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 1301f2cc4..e43ebbfbc 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -1961,7 +1961,7 @@ int char_mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p) {
#endif
//When the weapon is sent and your option is riding, the client crashes on login!?
- WBUFW(buf,56) = p->option&(0x20|0x80000|0x100000|0x200000|0x400000|0x800000|0x1000000|0x2000000|0x4000000|0x8000000) ? 0 : p->weapon;
+ WBUFW(buf,56) = (p->option&(0x20|0x80000|0x100000|0x200000|0x400000|0x800000|0x1000000|0x2000000|0x4000000|0x8000000)) ? 0 : p->weapon;
WBUFW(buf,58) = p->base_level;
WBUFW(buf,60) = min(p->skill_point, INT16_MAX);
@@ -2988,12 +2988,12 @@ void char_map_received_ok(int fd)
void char_send_maps(int fd, int id, int j)
{
- unsigned char buf[16384];
- int x,i;
+ int k,i;
if (j == 0) {
ShowWarning("Map-server %d has NO maps.\n", id);
} else {
+ unsigned char buf[16384];
// Transmitting maps information to the other map-servers
WBUFW(buf,0) = 0x2b04;
WBUFW(buf,2) = j * 4 + 10;
@@ -3003,16 +3003,16 @@ void char_send_maps(int fd, int id, int j)
mapif->sendallwos(fd, buf, WBUFW(buf,2));
}
// Transmitting the maps of the other map-servers to the new map-server
- for(x = 0; x < ARRAYLENGTH(chr->server); x++) {
- if (chr->server[x].fd > 0 && x != id) {
- WFIFOHEAD(fd,10 +4*chr->server[x].maps);
+ for(k = 0; k < ARRAYLENGTH(chr->server); k++) {
+ if (chr->server[k].fd > 0 && k != id) {
+ WFIFOHEAD(fd,10 +4*chr->server[k].maps);
WFIFOW(fd,0) = 0x2b04;
- WFIFOL(fd,4) = htonl(chr->server[x].ip);
- WFIFOW(fd,8) = htons(chr->server[x].port);
+ WFIFOL(fd,4) = htonl(chr->server[k].ip);
+ WFIFOW(fd,8) = htons(chr->server[k].port);
j = 0;
- for(i = 0; i < chr->server[x].maps; i++)
- if (chr->server[x].map[i])
- WFIFOW(fd,10+(j++)*4) = chr->server[x].map[i];
+ for(i = 0; i < chr->server[k].maps; i++)
+ if (chr->server[k].map[i])
+ WFIFOW(fd,10+(j++)*4) = chr->server[k].map[i];
if (j > 0) {
WFIFOW(fd,2) = j * 4 + 10;
WFIFOSET(fd,WFIFOW(fd,2));
@@ -3123,17 +3123,15 @@ void char_parse_frommap_set_users_count(int fd, int id)
void char_parse_frommap_set_users(int fd, int id)
{
//TODO: When data mismatches memory, update guild/party online/offline states.
- int aid, cid, i;
- struct online_char_data* character;
+ int i;
chr->server[id].users = RFIFOW(fd,4);
chr->online_char_db->foreach(chr->online_char_db,chr->db_setoffline,id); //Set all chars from this server as 'unknown'
for(i = 0; i < chr->server[id].users; i++) {
- aid = RFIFOL(fd,6+i*8);
- cid = RFIFOL(fd,6+i*8+4);
- character = idb_ensure(chr->online_char_db, aid, chr->create_online_char_data);
- if( character->server > -1 && character->server != id )
- {
+ int aid = RFIFOL(fd,6+i*8);
+ int cid = RFIFOL(fd,6+i*8+4);
+ struct online_char_data *character = idb_ensure(chr->online_char_db, aid, chr->create_online_char_data);
+ if (character->server > -1 && character->server != id) {
ShowNotice("Set map user: Character (%d:%d) marked on map server %d, but map server %d claims to have (%d:%d) online!\n",
character->account_id, character->char_id, character->server, id, aid, cid);
mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2);
@@ -4153,7 +4151,7 @@ void char_delete2_cancel_ack(int fd, int char_id, uint32 result)
static void char_delete2_req(int fd, struct char_session_data* sd)
{// CH: <0827>.W <char id>.L
- int char_id, party_id, guild_id, i;
+ int char_id, i;
char* data;
time_t delete_date;
@@ -4183,12 +4181,11 @@ static void char_delete2_req(int fd, struct char_session_data* sd)
// This check is imposed by Aegis to avoid dead entries in databases
// _it is not needed_ as we clear data properly
// see issue: 7338
- if( char_aegis_delete )
- {
+ if (char_aegis_delete) {
+ int party_id = 0, guild_id = 0;
if( SQL_SUCCESS != SQL->Query(inter->sql_handle, "SELECT `party_id`, `guild_id` FROM `%s` WHERE `char_id`='%d'", char_db, char_id)
- || SQL_SUCCESS != SQL->NextRow(inter->sql_handle)
- )
- {
+ || SQL_SUCCESS != SQL->NextRow(inter->sql_handle)
+ ) {
Sql_ShowDebug(inter->sql_handle);
chr->delete2_ack(fd, char_id, 3, 0);
return;
@@ -5585,12 +5582,12 @@ int char_config_read(const char* cfgName)
start_point.y = y;
} else if (strcmpi(w1, "start_items") == 0) {
int i;
- char *split, *split2;
+ char *split;
i = 0;
split = strtok(w2, ",");
while (split != NULL && i < MAX_START_ITEMS*3) {
- split2 = split;
+ char *split2 = split;
split = strtok(NULL, ",");
start_items[i] = atoi(split2);
diff --git a/src/char/geoip.c b/src/char/geoip.c
index e5b77af1f..1268019e1 100644
--- a/src/char/geoip.c
+++ b/src/char/geoip.c
@@ -56,14 +56,13 @@ const char* geoip_getcountry(uint32 ipnum)
{
int depth;
unsigned int x;
- const unsigned char *buf;
unsigned int offset = 0;
if( geoip->data->active == false )
return geoip_countryname[0];
for (depth = 31; depth >= 0; depth--) {
- buf = geoip->data->cache + (long)6 *offset;
+ const unsigned char *buf = geoip->data->cache + (long)6 *offset;
if (ipnum & (1 << depth)) {
/* Take the right-hand branch */
x = (buf[3*1 + 0] << (0*8))
diff --git a/src/char/int_auction.c b/src/char/int_auction.c
index 5d42e6398..164ca5360 100644
--- a/src/char/int_auction.c
+++ b/src/char/int_auction.c
@@ -175,7 +175,6 @@ void inter_auctions_fromsql(void)
{
int i;
struct auction_data *auction;
- struct item *item;
char *data;
StringBuf buf;
int64 tick = timer->gettick(), endtick;
@@ -193,8 +192,8 @@ void inter_auctions_fromsql(void)
StrBuf->Destroy(&buf);
- while( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) )
- {
+ while (SQL_SUCCESS == SQL->NextRow(inter->sql_handle)) {
+ struct item *item;
CREATE(auction, struct auction_data, 1);
SQL->GetData(inter->sql_handle, 0, &data, NULL); auction->auction_id = atoi(data);
SQL->GetData(inter->sql_handle, 1, &data, NULL); auction->seller_id = atoi(data);
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index 7af01f883..20db452af 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -220,14 +220,12 @@ int inter_guild_tosql(struct guild *g,int flag)
StrBuf->Destroy(&buf);
}
- if (flag&GS_MEMBER)
- {
- struct guild_member *m;
+ if (flag&GS_MEMBER) {
strcat(t_info, " members");
// Update only needed players
for(i=0;i<g->max_member;i++){
- m = &g->member[i];
+ struct guild_member *m = &g->member[i];
if (!m->modified)
continue;
if(m->account_id) {
@@ -1509,12 +1507,11 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int
}
case GMI_EXP:
{
- uint64 exp, old_exp=g->member[i].exp;
+ uint64 old_exp = g->member[i].exp;
g->member[i].exp=*((uint64 *)data);
g->member[i].modified = GS_MEMBER_MODIFIED;
- if (g->member[i].exp > old_exp)
- {
- exp = g->member[i].exp - old_exp;
+ if (g->member[i].exp > old_exp) {
+ uint64 exp = g->member[i].exp - old_exp;
// Compute gained exp
if (guild_exp_rate != 100)
diff --git a/src/char/int_homun.c b/src/char/int_homun.c
index 7f9323bdd..dd23261c2 100644
--- a/src/char/int_homun.c
+++ b/src/char/int_homun.c
@@ -155,7 +155,6 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
// Load an homunculus
bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
{
- int i;
char* data;
size_t len;
@@ -207,24 +206,23 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
hd->hunger = cap_value(hd->hunger, 0, 100);
// Load Homunculus Skill
- if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id) )
- {
+ if (SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id)) {
Sql_ShowDebug(inter->sql_handle);
return false;
}
- while( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) )
- {
+ while (SQL_SUCCESS == SQL->NextRow(inter->sql_handle)) {
+ int idx;
// id
SQL->GetData(inter->sql_handle, 0, &data, NULL);
- i = atoi(data);
- if( i < HM_SKILLBASE || i >= HM_SKILLBASE + MAX_HOMUNSKILL )
+ idx = atoi(data);
+ if (idx < HM_SKILLBASE || idx >= HM_SKILLBASE + MAX_HOMUNSKILL)
continue;// invalid skill id
- i = i - HM_SKILLBASE;
- hd->hskill[i].id = (unsigned short)atoi(data);
+ idx -= HM_SKILLBASE;
+ hd->hskill[idx].id = (unsigned short)atoi(data);
// lv
SQL->GetData(inter->sql_handle, 1, &data, NULL);
- hd->hskill[i].lv = (unsigned char)atoi(data);
+ hd->hskill[idx].lv = (unsigned char)atoi(data);
}
SQL->FreeResult(inter->sql_handle);
diff --git a/src/char/int_mail.c b/src/char/int_mail.c
index 0e5043e14..79d20cbd1 100644
--- a/src/char/int_mail.c
+++ b/src/char/int_mail.c
@@ -27,7 +27,6 @@ static int inter_mail_fromsql(int char_id, struct mail_data* md)
{
int i, j;
struct mail_message *msg;
- struct item *item;
char *data;
StringBuf buf;
@@ -53,6 +52,7 @@ static int inter_mail_fromsql(int char_id, struct mail_data* md)
for (i = 0; i < MAIL_MAX_INBOX && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i )
{
msg = &md->msg[i];
+ struct item *item;
SQL->GetData(inter->sql_handle, 0, &data, NULL); msg->id = atoi(data);
SQL->GetData(inter->sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH);
SQL->GetData(inter->sql_handle, 2, &data, NULL); msg->send_id = atoi(data);
diff --git a/src/char/int_party.c b/src/char/int_party.c
index b16f106be..bf950ec42 100644
--- a/src/char/int_party.c
+++ b/src/char/int_party.c
@@ -54,7 +54,6 @@ static int inter_party_check_lv(struct party_data *p) {
static void inter_party_calc_state(struct party_data *p)
{
int i;
- unsigned int lv;
p->min_lv = UINT_MAX;
p->max_lv = 0;
p->party.count =
@@ -83,13 +82,12 @@ static void inter_party_calc_state(struct party_data *p)
);
}
//max/min levels.
- for(i=0;i<MAX_PARTY;i++){
- lv=p->party.member[i].lv;
+ for (i = 0; i < MAX_PARTY; i++) {
+ unsigned int lv = p->party.member[i].lv;
if (!lv) continue;
- if(p->party.member[i].online &&
- //On families, the kid is not counted towards exp share rules.
- p->party.member[i].char_id != p->family)
- {
+ if (p->party.member[i].online
+ && p->party.member[i].char_id != p->family /* In families, the kid is not counted towards exp share rules. */
+ ) {
if( lv < p->min_lv ) p->min_lv=lv;
if( p->max_lv < lv ) p->max_lv=lv;
}
diff --git a/src/char/int_storage.c b/src/char/int_storage.c
index f2dd4d47a..db49eb46e 100644
--- a/src/char/int_storage.c
+++ b/src/char/int_storage.c
@@ -36,7 +36,6 @@ int inter_storage_tosql(int account_id, struct storage_data* p)
int inter_storage_fromsql(int account_id, struct storage_data* p)
{
StringBuf buf;
- struct item* item;
char* data;
int i;
int j;
@@ -56,9 +55,8 @@ int inter_storage_fromsql(int account_id, struct storage_data* p)
StrBuf->Destroy(&buf);
- for( i = 0; i < MAX_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i )
- {
- item = &p->items[i];
+ for (i = 0; i < MAX_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i) {
+ struct item *item = &p->items[i];
SQL->GetData(inter->sql_handle, 0, &data, NULL); item->id = atoi(data);
SQL->GetData(inter->sql_handle, 1, &data, NULL); item->nameid = atoi(data);
SQL->GetData(inter->sql_handle, 2, &data, NULL); item->amount = atoi(data);
@@ -93,7 +91,6 @@ int inter_storage_guild_storage_tosql(int guild_id, struct guild_storage* p)
int inter_storage_guild_storage_fromsql(int guild_id, struct guild_storage* p)
{
StringBuf buf;
- struct item* item;
char* data;
int i;
int j;
@@ -114,8 +111,8 @@ int inter_storage_guild_storage_fromsql(int guild_id, struct guild_storage* p)
StrBuf->Destroy(&buf);
- for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i ) {
- item = &p->items[i];
+ for (i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i) {
+ struct item *item = &p->items[i];
SQL->GetData(inter->sql_handle, 0, &data, NULL); item->id = atoi(data);
SQL->GetData(inter->sql_handle, 1, &data, NULL); item->nameid = atoi(data);
SQL->GetData(inter->sql_handle, 2, &data, NULL); item->amount = atoi(data);
diff --git a/src/char/inter.c b/src/char/inter.c
index 6cd34dc39..5af9a6aab 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -764,7 +764,6 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type)
*------------------------------------------*/
static int inter_config_read(const char* cfgName)
{
- int i;
char line[1024], w1[1024], w2[1024];
FILE* fp;
@@ -775,7 +774,7 @@ static int inter_config_read(const char* cfgName)
}
while (fgets(line, sizeof(line), fp)) {
- i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
+ int i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
if(i != 2)
continue;
@@ -1149,13 +1148,13 @@ int mapif_parse_Registry(int fd)
if( count ) {
int cursor = 14, i;
char key[32], sval[254];
- unsigned int index;
bool isLoginActive = session_isActive(chr->login_fd);
if( isLoginActive )
chr->global_accreg_to_login_start(account_id,char_id);
for(i = 0; i < count; i++) {
+ unsigned int index;
safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), RFIFOB(fd, cursor));
cursor += RFIFOB(fd, cursor) + 1;
diff --git a/src/char/pincode.c b/src/char/pincode.c
index 325a705a5..b8b30a1b8 100644
--- a/src/char/pincode.c
+++ b/src/char/pincode.c
@@ -126,10 +126,11 @@ void pincode_notifyLoginPinError(int account_id) {
}
void pincode_decrypt(unsigned int userSeed, char* pin) {
- int i, pos;
+ int i;
char tab[10] = {0,1,2,3,4,5,6,7,8,9};
- for( i = 1; i < 10; i++ ){
+ for (i = 1; i < 10; i++) {
+ int pos;
userSeed = pincode->baseSeed + userSeed * pincode->multiplier;
pos = userSeed % (i + 1);
if( i != pos ){
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 10208cdad..25ca5441d 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -95,7 +95,6 @@ struct hplugin *hplugin_create(void) {
}
#define HPM_POP(x) { #x , x }
bool hplugin_populate(struct hplugin *plugin, const char *filename) {
- void **Link;
struct {
const char* name;
void *Ref;
@@ -113,7 +112,8 @@ bool hplugin_populate(struct hplugin *plugin, const char *filename) {
int i, length = ARRAYLENGTH(ToLink);
for(i = 0; i < length; i++) {
- if( !( Link = plugin_import(plugin->dll, ToLink[i].name,void **) ) ) {
+ void **Link;
+ if (!( Link = plugin_import(plugin->dll, ToLink[i].name,void **))) {
ShowWarning("HPM:plugin_load: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", ToLink[i].name, filename);
HPM->unload(plugin);
return false;
@@ -268,7 +268,7 @@ struct hplugin *hplugin_load(const char* filename) {
}
void hplugin_unload(struct hplugin* plugin) {
- unsigned int i = plugin->idx, cursor = 0;
+ unsigned int i = plugin->idx;
if( plugin->filename )
aFree(plugin->filename);
@@ -277,7 +277,8 @@ void hplugin_unload(struct hplugin* plugin) {
/* TODO: for manual packet unload */
/* - Go through known packets and unlink any belonging to the plugin being removed */
aFree(plugin);
- if( !HPM->off ) {
+ if (!HPM->off) {
+ int cursor = 0;
HPM->plugins[i] = NULL;
for(i = 0; i < HPM->plugin_count; i++) {
if( HPM->plugins[i] == NULL )
@@ -838,14 +839,13 @@ void hpm_init(void) {
#endif
return;
}
-void hpm_memdown(void) {
- unsigned int i;
-
+void hpm_memdown(void)
+{
/* this memory is handled outside of the server's memory manager and thus cleared after memory manager goes down */
- if (HPM->fnames)
- {
- for( i = 0; i < HPM->fnamec; i++ ) {
+ if (HPM->fnames) {
+ unsigned int i;
+ for (i = 0; i < HPM->fnamec; i++) {
free(HPM->fnames[i].name);
}
free(HPM->fnames);
diff --git a/src/common/core.c b/src/common/core.c
index 6ad971c86..8bf381589 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -240,7 +240,7 @@ static CMDLINEARG(help)
} else {
*altname = '\0';
}
- snprintf(paramnames, sizeof(paramnames), "%s%s%s", data->name, altname, data->options&CMDLINE_OPT_PARAM ? " <name>" : "");
+ snprintf(paramnames, sizeof(paramnames), "%s%s%s", data->name, altname, (data->options&CMDLINE_OPT_PARAM) ? " <name>" : "");
ShowInfo(" %-30s %s [%s]\n", paramnames, data->help ? data->help : "<no description provided>", cmdline->arg_source(data));
}
return false;
@@ -439,12 +439,11 @@ int main (int argc, char **argv) {
sockt->init();
do_init(argc,argv);
- {// Main runtime cycle
- int next;
- while (runflag != CORE_ST_STOP) {
- next = timer->perform(timer->gettick_nocache());
- sockt->perform(next);
- }
+
+ // Main runtime cycle
+ while (runflag != CORE_ST_STOP) {
+ int next = timer->perform(timer->gettick_nocache());
+ sockt->perform(next);
}
console->final();
diff --git a/src/common/db.c b/src/common/db.c
index 044df19aa..69e2333a9 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -497,7 +497,6 @@ static void db_rebalance_erase(DBNode *node, DBNode **root)
DBNode *y = node;
DBNode *x = NULL;
DBNode *x_parent = NULL;
- DBNode *w;
DB_COUNTSTAT(db_rebalance_erase);
// Select where to change the tree
@@ -565,6 +564,7 @@ static void db_rebalance_erase(DBNode *node, DBNode **root)
// Restore the RED-BLACK properties
if (y->color != RED) {
while (x != *root && (x == NULL || x->color == BLACK)) {
+ DBNode *w;
if (x == x_parent->left) {
w = x_parent->right;
if (w->color == RED) {
@@ -1526,7 +1526,6 @@ static bool db_obj_exists(DBMap* self, DBKey key)
{
DBMap_impl* db = (DBMap_impl*)self;
DBNode *node;
- int c;
bool found = false;
DB_COUNTSTAT(db_exists);
@@ -1548,7 +1547,7 @@ static bool db_obj_exists(DBMap* self, DBKey key)
db_free_lock(db);
node = db->ht[db->hash(key, db->maxlen)%HASH_SIZE];
while (node) {
- c = db->cmp(key, node->key, db->maxlen);
+ int c = db->cmp(key, node->key, db->maxlen);
if (c == 0) {
if (!(node->deleted)) {
db->cache = node;
@@ -1577,7 +1576,6 @@ static DBData* db_obj_get(DBMap* self, DBKey key)
{
DBMap_impl* db = (DBMap_impl*)self;
DBNode *node;
- int c;
DBData *data = NULL;
DB_COUNTSTAT(db_get);
@@ -1600,7 +1598,7 @@ static DBData* db_obj_get(DBMap* self, DBKey key)
db_free_lock(db);
node = db->ht[db->hash(key, db->maxlen)%HASH_SIZE];
while (node) {
- c = db->cmp(key, node->key, db->maxlen);
+ int c = db->cmp(key, node->key, db->maxlen);
if (c == 0) {
if (!(node->deleted)) {
data = &node->data;
@@ -1970,7 +1968,7 @@ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data)
DBMap_impl* db = (DBMap_impl*)self;
DBNode *node;
unsigned int hash;
- int c = 0, retval = 0;
+ int retval = 0;
DB_COUNTSTAT(db_remove);
if (db == NULL) return 0; // nullpo candidate
@@ -1988,7 +1986,7 @@ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data)
db_free_lock(db);
hash = db->hash(key, db->maxlen)%HASH_SIZE;
for(node = db->ht[hash]; node; ){
- c = db->cmp(key, node->key, db->maxlen);
+ int c = db->cmp(key, node->key, db->maxlen);
if (c == 0) {
if (!(node->deleted)) {
if (db->cache == node)
diff --git a/src/common/malloc.c b/src/common/malloc.c
index 43fbe4ea1..c647dc18f 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -124,8 +124,7 @@ void aFree_(void *p, const char *file, int line, const char *func)
// ShowMessage("%s:%d: in func %s: aFree %p\n",file,line,func,p);
if (p)
FREE(p, file, line, func);
-
- p = NULL;
+ //p = NULL;
}
@@ -487,13 +486,13 @@ void mfree_(void *ptr, const char *file, int line, const char *func) {
/* Allocating blocks */
static struct block* block_malloc(unsigned short hash)
{
- int i;
struct block *p;
if(hash_unfill[0] != NULL) {
/* Space for the block has already been secured */
p = hash_unfill[0];
hash_unfill[0] = hash_unfill[0]->unfill_next;
} else {
+ int i;
/* Newly allocated space for the block */
p = (struct block*)MALLOC(sizeof(struct block) * (BLOCK_ALLOC), __FILE__, __LINE__, __func__ );
memmgr_usage_bytes_t += sizeof(struct block) * (BLOCK_ALLOC);
diff --git a/src/common/socket.c b/src/common/socket.c
index 600666d21..9fe08e6f1 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -624,7 +624,6 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF
static void delete_session(int fd)
{
if( sockt->session_isValid(fd) ) {
- unsigned int i;
#ifdef SHOW_SERVER_STATS
socket_data_qi -= session[fd]->rdata_size - session[fd]->rdata_pos;
socket_data_qo -= session[fd]->wdata_size;
@@ -633,8 +632,8 @@ static void delete_session(int fd)
aFree(session[fd]->wdata);
if( session[fd]->session_data )
aFree(session[fd]->session_data);
- if( session[fd]->hdata )
- {
+ if (session[fd]->hdata) {
+ unsigned int i;
for(i = 0; i < session[fd]->hdatac; i++) {
if( session[fd]->hdata[i]->flag.free ) {
aFree(session[fd]->hdata[i]->data);
@@ -1249,38 +1248,31 @@ int socket_getips(uint32* ips, int max)
#ifdef WIN32
{
char fullhost[255];
- u_long** a;
- struct hostent* hent;
// XXX This should look up the local IP addresses in the registry
// instead of calling gethostbyname. However, the way IP addresses
// are stored in the registry is annoyingly complex, so I'll leave
// this as T.B.D. [Meruru]
- if( gethostname(fullhost, sizeof(fullhost)) == SOCKET_ERROR )
- {
+ if (gethostname(fullhost, sizeof(fullhost)) == SOCKET_ERROR) {
ShowError("socket_getips: No hostname defined!\n");
return 0;
- }
- else
- {
- hent = gethostbyname(fullhost);
+ } else {
+ u_long** a;
+ struct hostent *hent =gethostbyname(fullhost);
if( hent == NULL ){
ShowError("socket_getips: Cannot resolve our own hostname to an IP address\n");
return 0;
}
a = (u_long**)hent->h_addr_list;
- for( ; a[num] != NULL && num < max; ++num)
+ for (; num < max && a[num] != NULL; ++num)
ips[num] = (uint32)ntohl(*a[num]);
}
}
#else // not WIN32
{
- int pos;
int fd;
char buf[2*16*sizeof(struct ifreq)];
struct ifconf ic;
- struct ifreq* ir;
- struct sockaddr_in* a;
u_long ad;
fd = sSocket(AF_INET, SOCK_STREAM, 0);
@@ -1291,21 +1283,18 @@ int socket_getips(uint32* ips, int max)
// interfaces than will fit in the buffer
ic.ifc_len = sizeof(buf);
ic.ifc_buf = buf;
- if( sIoctl(fd, SIOCGIFCONF, &ic) == -1 )
- {
+ if (sIoctl(fd, SIOCGIFCONF, &ic) == -1) {
ShowError("socket_getips: SIOCGIFCONF failed!\n");
sClose(fd);
return 0;
- }
- else
- {
- for( pos=0; pos < ic.ifc_len && num < max; )
- {
- ir = (struct ifreq*)(buf+pos);
- a = (struct sockaddr_in*) &(ir->ifr_addr);
- if( a->sin_family == AF_INET ){
+ } else {
+ int pos;
+ for (pos = 0; pos < ic.ifc_len && num < max; ) {
+ struct ifreq *ir = (struct ifreq*)(buf+pos);
+ struct sockaddr_in *a = (struct sockaddr_in*) &(ir->ifr_addr);
+ if (a->sin_family == AF_INET) {
ad = ntohl(a->sin_addr.s_addr);
- if( ad != INADDR_LOOPBACK && ad != INADDR_ANY )
+ if (ad != INADDR_LOOPBACK && ad != INADDR_ANY)
ips[num++] = (uint32)ad;
}
#if (defined(BSD) && BSD >= 199103) || defined(_AIX) || defined(__APPLE__)
diff --git a/src/common/sql.c b/src/common/sql.c
index f0b2365a4..aec2ae93d 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -816,10 +816,8 @@ int SqlStmt_NextRow(SqlStmt* self)
int err;
size_t i;
size_t cols;
- MYSQL_BIND* column;
- unsigned long length;
- if( self == NULL )
+ if (self == NULL)
return SQL_ERROR;
// bind columns
@@ -829,30 +827,27 @@ int SqlStmt_NextRow(SqlStmt* self)
err = mysql_stmt_fetch(self->stmt);// fetch row
// check for errors
- if( err == MYSQL_NO_DATA )
+ if (err == MYSQL_NO_DATA)
return SQL_NO_DATA;
#if defined(MYSQL_DATA_TRUNCATED)
// MySQL 5.0/5.1 defines and returns MYSQL_DATA_TRUNCATED [FlavioJS]
- if( err == MYSQL_DATA_TRUNCATED )
- {
+ if (err == MYSQL_DATA_TRUNCATED) {
my_bool truncated;
- if( !self->bind_columns )
- {
+ if (!self->bind_columns) {
ShowSQL("DB error - data truncated (unknown source, columns are not bound)\n");
return SQL_ERROR;
}
// find truncated column
cols = SQL->StmtNumColumns(self);
- for( i = 0; i < cols; ++i )
- {
- column = &self->columns[i];
+ for (i = 0; i < cols; ++i) {
+ MYSQL_BIND *column = &self->columns[i];
column->error = &truncated;
mysql_stmt_fetch_column(self->stmt, column, (unsigned int)i, 0);
column->error = NULL;
- if( truncated )
- {// report truncated column
+ if (truncated) {
+ // report truncated column
SqlStmt_P_ShowDebugTruncatedColumn(self, i);
return SQL_ERROR;
}
@@ -861,8 +856,7 @@ int SqlStmt_NextRow(SqlStmt* self)
return SQL_ERROR;
}
#endif
- if( err )
- {
+ if (err) {
ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt));
hercules_mysql_error_handler(mysql_stmt_errno(self->stmt));
return SQL_ERROR;
@@ -870,30 +864,28 @@ int SqlStmt_NextRow(SqlStmt* self)
// propagate column lengths and clear unused parts of string/enum/blob buffers
cols = SQL->StmtNumColumns(self);
- for( i = 0; i < cols; ++i )
- {
- length = self->column_lengths[i].length;
- column = &self->columns[i];
+ for (i = 0; i < cols; ++i) {
+ unsigned long length = self->column_lengths[i].length;
+ MYSQL_BIND *column = &self->columns[i];
#if !defined(MYSQL_DATA_TRUNCATED)
// MySQL 4.1/(below?) returns success even if data is truncated, so we test truncation manually [FlavioJS]
- if( column->buffer_length < length )
- {// report truncated column
- if( column->buffer_type == MYSQL_TYPE_STRING || column->buffer_type == MYSQL_TYPE_BLOB )
- {// string/enum/blob column
+ if (column->buffer_length < length) {
+ // report truncated column
+ if (column->buffer_type == MYSQL_TYPE_STRING || column->buffer_type == MYSQL_TYPE_BLOB) {
+ // string/enum/blob column
SqlStmt_P_ShowDebugTruncatedColumn(self, i);
return SQL_ERROR;
}
// FIXME numeric types and null [FlavioJS]
}
#endif
- if( self->column_lengths[i].out_length )
+ if (self->column_lengths[i].out_length)
*self->column_lengths[i].out_length = (uint32)length;
- if( column->buffer_type == MYSQL_TYPE_STRING )
- {// clear unused part of the string/enum buffer (and null-terminate)
+ if (column->buffer_type == MYSQL_TYPE_STRING) {
+ // clear unused part of the string/enum buffer (and null-terminate)
memset((char*)column->buffer + length, 0, column->buffer_length - length + 1);
- }
- else if( column->buffer_type == MYSQL_TYPE_BLOB && length < column->buffer_length )
- {// clear unused part of the blob buffer
+ } else if (column->buffer_type == MYSQL_TYPE_BLOB && length < column->buffer_length) {
+ // clear unused part of the blob buffer
memset((char*)column->buffer + length, 0, column->buffer_length - length);
}
}
@@ -958,7 +950,6 @@ void hercules_mysql_error_handler(unsigned int ecode) {
}
}
void Sql_inter_server_read(const char* cfgName, bool first) {
- int i;
char line[1024], w1[1024], w2[1024];
FILE* fp;
@@ -973,7 +964,7 @@ void Sql_inter_server_read(const char* cfgName, bool first) {
}
while (fgets(line, sizeof(line), fp)) {
- i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
+ int i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
if (i != 2)
continue;
diff --git a/src/common/strlib.c b/src/common/strlib.c
index 8b63b4161..b5fcff576 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -946,7 +946,6 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
char** fields; // buffer for fields ([0] is reserved)
int columns, fields_length;
char path[1024], line[1024];
- char* match;
snprintf(path, sizeof(path), "%s/%s", directory, filename);
@@ -962,9 +961,11 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
// process rows one by one
while( fgets(line, sizeof(line), fp) ) {
+ char *match;
lines++;
- if( ( match = strstr(line, "//") ) != NULL ) {// strip comments
+ if ((match = strstr(line, "//") ) != NULL) {
+ // strip comments
match[0] = 0;
}
@@ -1039,13 +1040,11 @@ int StringBuf_Printf(StringBuf *self, const char *fmt, ...) {
/// Appends the result of vprintf to the StringBuf
int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) {
- int n, off;
- size_t size;
-
for(;;) {
va_list apcopy;
+ int n, off;
/* Try to print in the allocated space. */
- size = self->max_ - (self->ptr_ - self->buf_);
+ size_t size = self->max_ - (self->ptr_ - self->buf_);
va_copy(apcopy, ap);
n = vsnprintf(self->ptr_, size, fmt, apcopy);
va_end(apcopy);
diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c
index ee8ff504a..a1dbed4d1 100644
--- a/src/common/sysinfo.c
+++ b/src/common/sysinfo.c
@@ -319,12 +319,12 @@ bool sysinfo_svn_get_revision(char **out) {
bool sysinfo_git_get_revision(char **out) {
// Only include Git support if we detected it, or we're on MSVC
#if !defined(SYSINFO_VCSTYPE) || SYSINFO_VCSTYPE == VCSTYPE_GIT || SYSINFO_VCSTYPE == VCSTYPE_UNKNOWN
- FILE *fp;
char ref[128], filepath[128], line[128];
strcpy(ref, "HEAD");
while (*ref) {
+ FILE *fp;
snprintf(filepath, sizeof(filepath), ".git/%s", ref);
if ((fp = fopen(filepath, "r")) != NULL) {
if (fgets(line, sizeof(line)-1, fp) == NULL) {
diff --git a/src/common/utils.c b/src/common/utils.c
index 5ede86296..c168bd74e 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -95,8 +95,9 @@ void ShowDump(const void *buffer, size_t length) {
static char* checkpath(char *path, const char *srcpath)
{
// just make sure the char*path is not const
- char *p=path;
- if(NULL!=path && NULL!=srcpath)
+ char *p = path;
+ if (NULL == path || NULL == srcpath)
+ return path;
while(*srcpath) {
if (*srcpath=='/') {
*p++ = '\\';
diff --git a/src/login/account_sql.c b/src/login/account_sql.c
index adbb7914d..f745d3d13 100644
--- a/src/login/account_sql.c
+++ b/src/login/account_sql.c
@@ -666,12 +666,12 @@ void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
int count = RFIFOW(fd, 12);
- if( count ) {
+ if (count) {
int cursor = 14, i;
char key[32], sval[254];
- unsigned int index;
- for(i = 0; i < count; i++) {
+ for (i = 0; i < count; i++) {
+ unsigned int index;
safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), RFIFOB(fd, cursor));
cursor += RFIFOB(fd, cursor) + 1;
diff --git a/src/login/login.c b/src/login/login.c
index 036456a85..846f24027 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -677,14 +677,12 @@ void login_fromchar_parse_account_offline(int fd)
void login_fromchar_parse_online_accounts(int fd, int id)
{
- struct online_login_data *p;
- int aid;
uint32 i, users;
login->online_db->foreach(login->online_db, login->online_db_setoffline, id); //Set all chars from this char-server offline first
users = RFIFOW(fd,4);
for (i = 0; i < users; i++) {
- aid = RFIFOL(fd,6+i*4);
- p = idb_ensure(login->online_db, aid, login->create_online_user);
+ int aid = RFIFOL(fd,6+i*4);
+ struct online_login_data *p = idb_ensure(login->online_db, aid, login->create_online_user);
p->char_server = id;
if (p->waiting_disconnect != INVALID_TIMER)
{
@@ -734,15 +732,14 @@ bool login_fromchar_parse_wrong_pincode(int fd)
struct mmo_account acc;
if( accounts->load_num(accounts, &acc, RFIFOL(fd,2) ) ) {
- struct online_login_data* ld;
+ struct online_login_data* ld = (struct online_login_data*)idb_get(login->online_db,acc.account_id);
- if( ( ld = (struct online_login_data*)idb_get(login->online_db,acc.account_id) ) == NULL )
- {
+ if (ld == NULL) {
RFIFOSKIP(fd,6);
return true;
}
- login_log( host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed" );
+ login_log(host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed");
}
login->remove_online_user(acc.account_id);
@@ -1814,12 +1811,12 @@ int login_config_read(const char* cfgName)
if (sscanf(w2, "%d, %32s", &group, md5) == 2) {
struct client_hash_node *nnode;
- int i;
CREATE(nnode, struct client_hash_node, 1);
if (strcmpi(md5, "disabled") == 0) {
nnode->hash[0] = '\0';
} else {
+ int i;
for (i = 0; i < 32; i += 2) {
char buf[3];
unsigned int byte;
diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c
index cb4e79108..f3a83ff0f 100644
--- a/src/map/HPMmap.c
+++ b/src/map/HPMmap.c
@@ -173,17 +173,15 @@ void HPM_map_do_init(void) {
}
void HPM_map_do_final(void) {
- unsigned char i;
-
- if( atcommand_list )
+ if (atcommand_list)
aFree(atcommand_list);
/**
* why is pcg->HPM being cleared here? because PCG's do_final is not final,
* is used on reload, and would thus cause plugin-provided permissions to go away
**/
- if( pcg->HPMpermissions )
- {
- for( i = 0; i < pcg->HPMpermissions_count; i++ ) {
+ if (pcg->HPMpermissions) {
+ unsigned char i;
+ for (i = 0; i < pcg->HPMpermissions_count; i++) {
aFree(pcg->HPMpermissions[i].name);
}
aFree(pcg->HPMpermissions);
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 34ef4ec30..977a4f24a 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -160,7 +160,7 @@ static inline const char* atcommand_help_string(AtCommandInfo *info) {
*------------------------------------------*/
ACMD(send)
{
- int len=0,off,end,type;
+ int len=0,type;
long num;
// read message type as hex number (without the 0x)
@@ -200,24 +200,24 @@ ACMD(send)
} while(0) //define GET_VALUE
if (type > 0 && type < MAX_PACKET_DB) {
- if(len)
- {// show packet length
+ int off = 2;
+ if (len) {
+ // show packet length
sprintf(atcmd_output, msg_txt(904), type, packet_db[type].len); // Packet 0x%x length: %d
clif->message(fd, atcmd_output);
return true;
}
len=packet_db[type].len;
- off=2;
- if(len == 0)
- {// unknown packet - ERROR
+ if (len == 0) {
+ // unknown packet - ERROR
sprintf(atcmd_output, msg_txt(905), type); // Unknown packet: 0x%x
clif->message(fd, atcmd_output);
return false;
- } else if(len == -1)
- {// dynamic packet
- len=SHRT_MAX-4; // maximum length
- off=4;
+ } else if (len == -1) {
+ // dynamic packet
+ len = SHRT_MAX-4; // maximum length
+ off = 4;
}
WFIFOHEAD(sd->fd, len);
WFIFOW(sd->fd,0)=TOW(type);
@@ -251,6 +251,7 @@ ACMD(send)
} else if(TOUPPER(*message) == 'S')
{// string - escapes are valid
// get string length - num <= 0 means not fixed length (default)
+ int end;
++message;
if(*message == '"'){
num=0;
@@ -551,7 +552,6 @@ ACMD(jump)
ACMD(who) {
struct map_session_data *pl_sd = NULL;
struct s_mapiterator *iter = NULL;
- char map_name[MAP_NAME_LENGTH_EXT] = "";
char player_name[NAME_LENGTH] = "";
int count = 0;
int level = 0;
@@ -565,6 +565,7 @@ ACMD(who) {
int map_id = -1;
if (stristr(info->command, "map") != NULL) {
+ char map_name[MAP_NAME_LENGTH_EXT] = "";
if (sscanf(message, "%15s %23s", map_name, player_name) < 1 || (map_id = map->mapname2mapid(map_name)) < 0)
map_id = sd->bl.m;
} else {
@@ -652,7 +653,7 @@ ACMD(whogm)
struct map_session_data* pl_sd;
struct s_mapiterator* iter;
int j, count;
- int pl_level, level;
+ int level;
char match_text[CHAT_SIZE_MAX];
char player_name[NAME_LENGTH];
struct guild *g;
@@ -671,14 +672,12 @@ ACMD(whogm)
level = pc_get_group_level(sd);
iter = mapit_getallusers();
- for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) )
- {
- pl_level = pc_get_group_level(pl_sd);
+ for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) {
+ int pl_level = pc_get_group_level(pl_sd);
if (!pl_level)
continue;
- if (match_text[0])
- {
+ if (match_text[0]) {
memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
for (j = 0; player_name[j]; j++)
player_name[j] = TOLOWER(player_name[j]);
@@ -1716,7 +1715,6 @@ ACMD(hair_color)
* @go [city_number or city_name] - Updated by Harbin
*------------------------------------------*/
ACMD(go) {
- int i;
int town = INT_MAX; // Initialized to INT_MAX instead of -1 to avoid conflicts with those who map [-3:-1] to @memo locations.
char map_name[MAP_NAME_LENGTH];
@@ -1792,6 +1790,7 @@ ACMD(go) {
}
if (town < 0 || town >= ARRAYLENGTH(data)) {
+ int i;
map_name[MAP_NAME_LENGTH-1] = '\0';
// Match maps on the list
@@ -1861,7 +1860,7 @@ ACMD(monster)
int mob_id;
int number = 0;
int count;
- int i, k, range;
+ int i, range;
short mx, my;
unsigned int size;
@@ -1921,6 +1920,7 @@ ACMD(monster)
count = 0;
range = (int)sqrt((float)number) +2; // calculation of an odd number (+ 4 area around)
for (i = 0; i < number; i++) {
+ int k;
map->search_freecell(&sd->bl, 0, &mx, &my, range, range, 0);
k = mob->once_spawn(sd, sd->bl.m, mx, my, name, mob_id, 1, eventname, size, AI_NONE|(mob_id == MOBID_EMPERIUM?0x200:0x0));
count += (k != 0) ? 1 : 0;
@@ -1989,7 +1989,7 @@ ACMD(killmonster) {
*------------------------------------------*/
ACMD(refine)
{
- int i,j, position = 0, refine = 0, current_position, final_refine;
+ int j, position = 0, refine = 0, current_position, final_refine;
int count;
memset(atcmd_output, '\0', sizeof(atcmd_output));
@@ -2023,28 +2023,29 @@ ACMD(refine)
count = 0;
for (j = 0; j < EQI_MAX; j++) {
- if ((i = sd->equip_index[j]) < 0)
+ int idx = sd->equip_index[j];
+ if (idx < 0)
continue;
if(j == EQI_AMMO) continue; /* can't equip ammo */
- if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == i)
+ if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == idx)
continue;
- if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == i)
+ if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == idx)
continue;
- if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == i || sd->equip_index[EQI_HEAD_LOW] == i))
+ if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == idx || sd->equip_index[EQI_HEAD_LOW] == idx))
continue;
- if(position && !(sd->status.inventory[i].equip & position))
+ if(position && !(sd->status.inventory[idx].equip & position))
continue;
- final_refine = cap_value(sd->status.inventory[i].refine + refine, 0, MAX_REFINE);
- if (sd->status.inventory[i].refine != final_refine) {
- sd->status.inventory[i].refine = final_refine;
- current_position = sd->status.inventory[i].equip;
- pc->unequipitem(sd, i, 3);
- clif->refine(fd, 0, i, sd->status.inventory[i].refine);
- clif->delitem(sd, i, 1, 3);
- clif->additem(sd, i, 1, 0);
- pc->equipitem(sd, i, current_position);
+ final_refine = cap_value(sd->status.inventory[idx].refine + refine, 0, MAX_REFINE);
+ if (sd->status.inventory[idx].refine != final_refine) {
+ sd->status.inventory[idx].refine = final_refine;
+ current_position = sd->status.inventory[idx].equip;
+ pc->unequipitem(sd, idx, 3);
+ clif->refine(fd, 0, idx, sd->status.inventory[idx].refine);
+ clif->delitem(sd, idx, 1, 3);
+ clif->additem(sd, idx, 1, 0);
+ pc->equipitem(sd, idx, current_position);
clif->misceffect(&sd->bl, 3);
count++;
}
@@ -2707,8 +2708,8 @@ ACMD(char_block)
*------------------------------------------*/
ACMD(char_ban)
{
- char * modif_p;
- int year, month, day, hour, minute, second, value;
+ char *modif_p;
+ int year, month, day, hour, minute, second;
time_t timestamp;
struct tm *tmtime;
@@ -2725,7 +2726,7 @@ ACMD(char_ban)
modif_p = atcmd_output;
year = month = day = hour = minute = second = 0;
while (modif_p[0] != '\0') {
- value = atoi(modif_p);
+ int value = atoi(modif_p);
if (value == 0)
modif_p++;
else {
@@ -3649,7 +3650,6 @@ ACMD(reloadscript) {
ACMD(mapinfo) {
struct map_session_data* pl_sd;
struct s_mapiterator* iter;
- struct npc_data *nd = NULL;
struct chat_data *cd = NULL;
char direction[12];
int i, m_id, chat_num = 0, list = 0, vend_num = 0;
@@ -3841,7 +3841,7 @@ ACMD(mapinfo) {
case 2:
clif->message(fd, msg_txt(1100)); // ----- NPCs in Map -----
for (i = 0; i < map->list[m_id].npc_num;) {
- nd = map->list[m_id].npc[i];
+ struct npc_data *nd = map->list[m_id].npc[i];
switch(nd->dir) {
case 0: strcpy(direction, msg_txt(1101)); break; // North
case 1: strcpy(direction, msg_txt(1102)); break; // North West
@@ -4441,7 +4441,7 @@ ACMD(unjail) {
ACMD(jailfor) {
struct map_session_data *pl_sd = NULL;
- int year, month, day, hour, minute, value;
+ int year, month, day, hour, minute;
char * modif_p;
int jailtime = 0,x,y;
short m_index = 0;
@@ -4456,7 +4456,7 @@ ACMD(jailfor) {
modif_p = atcmd_output;
year = month = day = hour = minute = 0;
while (modif_p[0] != '\0') {
- value = atoi(modif_p);
+ int value = atoi(modif_p);
if (value == 0)
modif_p++;
else {
@@ -4664,7 +4664,6 @@ ACMD(disguiseguild)
{
int id = 0, i;
char monster[NAME_LENGTH], guild_name[NAME_LENGTH];
- struct map_session_data *pl_sd;
struct guild *g;
memset(monster, '\0', sizeof(monster));
@@ -4696,9 +4695,11 @@ ACMD(disguiseguild)
return false;
}
- for (i = 0; i < g->max_member; i++)
- if ((pl_sd = g->member[i].sd) && !pc_hasmount(pl_sd))
+ for (i = 0; i < g->max_member; i++) {
+ struct map_session_data *pl_sd = g->member[i].sd;
+ if (pl_sd && !pc_hasmount(pl_sd))
pc->disguise(pl_sd, id);
+ }
clif->message(fd, msg_txt(122)); // Disguise applied.
return true;
@@ -4745,7 +4746,6 @@ ACMD(undisguiseall) {
ACMD(undisguiseguild)
{
char guild_name[NAME_LENGTH];
- struct map_session_data *pl_sd;
struct guild *g;
int i;
@@ -4761,9 +4761,11 @@ ACMD(undisguiseguild)
return false;
}
- for(i = 0; i < g->max_member; i++)
- if( (pl_sd = g->member[i].sd) && pl_sd->disguise != -1 )
+ for(i = 0; i < g->max_member; i++) {
+ struct map_session_data *pl_sd = g->member[i].sd;
+ if (pl_sd && pl_sd->disguise != -1)
pc->disguise(pl_sd, -1);
+ }
clif->message(fd, msg_txt(124)); // Disguise removed.
@@ -5177,7 +5179,7 @@ ACMD(clearcart)
#define MAX_SKILLID_PARTIAL_RESULTS 5
#define MAX_SKILLID_PARTIAL_RESULTS_LEN 74 /* "skill " (6) + "%d:" (up to 5) + "%s" (up to 30) + " (%s)" (up to 33) */
ACMD(skillid) {
- int idx, i, found = 0;
+ int i, found = 0;
size_t skillen;
DBIterator* iter;
DBKey key;
@@ -5193,8 +5195,8 @@ ACMD(skillid) {
iter = db_iterator(skill->name2id_db);
- for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
- idx = skill->get_index(DB->data2i(data));
+ for (data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key)) {
+ int idx = skill->get_index(DB->data2i(data));
if (strnicmp(key.str, message, skillen) == 0 || strnicmp(skill->db[idx].desc, message, skillen) == 0) {
sprintf(atcmd_output, msg_txt(1164), DB->data2i(data), skill->db[idx].desc, key.str); // skill %d: %s (%s)
clif->message(fd, atcmd_output);
@@ -5703,7 +5705,6 @@ ACMD(autolootitem)
* chriser,Aleos
*------------------------------------------*/
ACMD(autoloottype) {
- int i;
uint8 action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
enum item_types type = -1;
int ITEM_NONE = 0;
@@ -5777,6 +5778,7 @@ ACMD(autoloottype) {
if (sd->state.autoloottype == ITEM_NONE) {
clif->message(fd, msg_txt(1495)); // Your autoloottype list is empty.
} else {
+ int i;
clif->message(fd, msg_txt(1496)); // Item types on your autoloottype list:
for(i=0; i < IT_MAX; i++) {
if (sd->state.autoloottype&(1<<i)) {
@@ -6153,7 +6155,6 @@ ACMD(pettalk)
ACMD(users)
{
char buf[CHAT_SIZE_MAX];
- int i;
int users[MAX_MAPINDEX];
int users_all;
struct s_mapiterator* iter;
@@ -6177,11 +6178,12 @@ ACMD(users)
}
mapit->free(iter);
- if( users_all ) {
+ if (users_all) {
+ int i;
// display results for each map
- for( i = 0; i < MAX_MAPINDEX; ++i ) {
- if( users[i] == 0 )
- continue;// empty
+ for (i = 0; i < MAX_MAPINDEX; ++i) {
+ if (users[i] == 0)
+ continue; // empty
safesnprintf(buf, sizeof(buf), "%s: %d (%.2f%%)", mapindex_id2name(i), users[i], (float)(100.0f*users[i]/users_all));
clif->message(sd->fd, buf);
@@ -6504,7 +6506,7 @@ ACMD(mobinfo)
struct item_data *item_data;
struct mob_db *monster, *mob_array[MAX_SEARCH];
int count;
- int i, j, k;
+ int i, k;
memset(atcmd_output, '\0', sizeof(atcmd_output));
memset(atcmd_output2, '\0', sizeof(atcmd_output2));
@@ -6534,6 +6536,7 @@ ACMD(mobinfo)
for (k = 0; k < count; k++) {
unsigned int job_exp, base_exp;
+ int j;
monster = mob_array[k];
@@ -6566,12 +6569,14 @@ ACMD(mobinfo)
#ifdef RENEWAL
sprintf(atcmd_output, msg_txt(1291), // ATK : %d~%d MATK : %d~%d Range : %d~%d~%d Size : %s Race : %s Element : %s(Lv : %d)
MOB_ATK1(monster), MOB_ATK2(monster), MOB_MATK1(monster), MOB_MATK2(monster), monster->status.rhw.range,
+ monster->range2 , monster->range3, msize[monster->status.size],
+ mrace[monster->status.race], melement[monster->status.def_ele], monster->status.ele_lv);
#else
sprintf(atcmd_output, msg_txt(1244), // ATK:%d~%d Range:%d~%d~%d Size:%s Race: %s Element: %s (Lv:%d)
monster->status.rhw.atk, monster->status.rhw.atk2, monster->status.rhw.range,
-#endif
monster->range2 , monster->range3, msize[monster->status.size],
mrace[monster->status.race], melement[monster->status.def_ele], monster->status.ele_lv);
+#endif
clif->message(fd, atcmd_output);
// drops
@@ -7054,7 +7059,7 @@ ACMD(homshuffle)
*------------------------------------------*/
ACMD(iteminfo)
{
- struct item_data *item_data, *item_array[MAX_SEARCH];
+ struct item_data *item_array[MAX_SEARCH];
int i, count = 1;
if (!message || !*message) {
@@ -7075,7 +7080,7 @@ ACMD(iteminfo)
count = MAX_SEARCH;
}
for (i = 0; i < count; i++) {
- item_data = item_array[i];
+ struct item_data *item_data = item_array[i];
sprintf(atcmd_output, msg_txt(1277), // Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s
item_data->name,item_data->jname,item_data->slot,item_data->nameid,
itemdb->typename(item_data->type),
@@ -7105,7 +7110,7 @@ ACMD(iteminfo)
*------------------------------------------*/
ACMD(whodrops)
{
- struct item_data *item_data, *item_array[MAX_SEARCH];
+ struct item_data *item_array[MAX_SEARCH];
int i,j, count = 1;
if (!message || !*message) {
@@ -7126,7 +7131,7 @@ ACMD(whodrops)
count = MAX_SEARCH;
}
for (i = 0; i < count; i++) {
- item_data = item_array[i];
+ struct item_data *item_data = item_array[i];
sprintf(atcmd_output, msg_txt(1285), item_data->jname,item_data->slot); // Item: '%s'[%d]
clif->message(fd, atcmd_output);
@@ -7149,7 +7154,7 @@ ACMD(whodrops)
ACMD(whereis)
{
- struct mob_db *monster, *mob_array[MAX_SEARCH];
+ struct mob_db *mob_array[MAX_SEARCH];
int count;
int i, j, k;
@@ -7177,7 +7182,7 @@ ACMD(whereis)
count = MAX_SEARCH;
}
for (k = 0; k < count; k++) {
- monster = mob_array[k];
+ struct mob_db *monster = mob_array[k];
snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1289), monster->jname); // %s spawns in:
clif->message(fd, atcmd_output);
@@ -7650,7 +7655,7 @@ ACMD(duel) {
}
if( message[0] ) {
- if(sscanf(message, "%d", &maxpl) >= 1) {
+ if(sscanf(message, "%u", &maxpl) >= 1) {
if(maxpl < 2 || maxpl > 65535) {
clif->message(fd, msg_txt(357)); // "Duel: Invalid value."
return false;
@@ -8664,9 +8669,10 @@ ACMD(join) {
clif->message(fd, atcmd_output);
}
if( channel->type == hChSys_ALLY ) {
- struct guild *g = sd->guild, *sg = NULL;
+ struct guild *g = sd->guild;
int i;
for (i = 0; i < MAX_GUILDALLIANCE; i++) {
+ struct guild *sg = NULL;
if( g->alliance[i].opposition == 0 && g->alliance[i].guild_id && (sg = guild->search(g->alliance[i].guild_id) ) ) {
if( !(sg->channel->banned && idb_exists(sg->channel->banned, sd->status.account_id))) {
clif->chsys_join(sg->channel,sd);
@@ -9304,7 +9310,7 @@ ACMD(costume){
/* for debugging purposes (so users can easily provide us with debug info) */
/* should be trashed as soon as its no longer necessary */
ACMD(skdebug) {
- sprintf(atcmd_output,"second: %d; third: %d",sd->sktree.second,sd->sktree.third);
+ sprintf(atcmd_output,"second: %u; third: %u", sd->sktree.second, sd->sktree.third);
clif->message(fd,atcmd_output);
sprintf(atcmd_output,"pc_calc_skilltree_normalize_job: %d",pc->calc_skilltree_normalize_job(sd));
clif->message(fd,atcmd_output);
@@ -9767,7 +9773,7 @@ void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bo
*/
bool atcommand_exec(const int fd, struct map_session_data *sd, const char *message, bool player_invoked) {
char charname[NAME_LENGTH], params[100];
- char charname2[NAME_LENGTH], params2[100];
+ char charname2[NAME_LENGTH];
char command[100];
char output[CHAT_SIZE_MAX];
@@ -9805,6 +9811,7 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa
if (*message == atcommand->char_symbol) {
do {
+ char params2[100];
int x, y, z;
//Checks to see if #command has a name or a name + parameters.
diff --git a/src/map/battle.c b/src/map/battle.c
index ddfa8df0b..0201e0e3a 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -261,7 +261,7 @@ int battle_delay_damage(int64 tick, int amotion, struct block_list *src, struct
if (sc && sc->data[SC_DEVOTION] && sc->data[SC_DEVOTION]->val1)
d_tbl = map->id2bl(sc->data[SC_DEVOTION]->val1);
- if( d_tbl && check_distance_bl(target, d_tbl, sc->data[SC_DEVOTION]->val3) && damage > 0 && skill_id != PA_PRESSURE && skill_id != CR_REFLECTSHIELD )
+ if (d_tbl && sc && check_distance_bl(target, d_tbl, sc->data[SC_DEVOTION]->val3) && damage > 0 && skill_id != PA_PRESSURE && skill_id != CR_REFLECTSHIELD)
damage = 0;
if ( !battle_config.delay_battle_damage || amotion <= 1 ) {
@@ -488,11 +488,12 @@ int64 battle_calc_weapon_damage(struct block_list *src, struct block_list *bl, u
*/
/* 'battle_calc_base_damage' is used on renewal, 'battle_calc_base_damage2' otherwise. */
int64 battle_calc_base_damage(struct block_list *src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int nk, bool n_ele, short s_ele, short s_ele_, int type, int flag, int flag2) {
- int64 damage, batk;
+ int64 damage;
struct status_data *st = status->get_status_data(src);
struct status_change *sc = status->get_sc(src);
- if (src->type == BL_PC){
+ if (src->type == BL_PC) {
+ int64 batk;
// Property from mild wind bypasses it
if (sc && sc->data[SC_TK_SEVENWIND])
batk = battle->calc_elefix(src, bl, skill_id, skill_lv, status->calc_batk(bl, sc, st->batk, false), nk, n_ele, s_ele, s_ele_, false, flag);
@@ -2740,7 +2741,6 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
}
if ((sce=sc->data[SC_AUTOGUARD]) && flag&BF_WEAPON && !(skill->get_nk(skill_id)&NK_NO_CARDFIX_ATK) && rnd()%100 < sce->val2) {
int delay;
- struct block_list *d_bl = NULL;
struct status_change_entry *sce_d = sc->data[SC_DEVOTION];
// different delay depending on skill level [celest]
@@ -2754,7 +2754,8 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
if (sce_d) {
// If the target is too far away from the devotion caster, autoguard has no effect
// Autoguard will be disabled later on
- if ((d_bl = map->id2bl(sce_d->val1)) && check_distance_bl(bl, d_bl, sce_d->val3)
+ struct block_list *d_bl = map->id2bl(sce_d->val1);
+ if (d_bl && check_distance_bl(bl, d_bl, sce_d->val3)
&& ((d_bl->type == BL_MER && ((TBL_MER*)d_bl)->master && ((TBL_MER*)d_bl)->master->bl.id == bl->id)
|| (d_bl->type == BL_PC && ((TBL_PC*)d_bl)->devotion[sce_d->val2] == bl->id))
) {
@@ -3108,9 +3109,9 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
}
}
if( tsc->data[SC_POISONINGWEAPON] ) {
- short rate = 100;
struct status_data *tstatus = status->get_status_data(bl);
if ( !(flag&BF_SKILL) && (flag&BF_WEAPON) && damage > 0 && rnd()%100 < tsc->data[SC_POISONINGWEAPON]->val3 ) {
+ short rate = 100;
if ( tsc->data[SC_POISONINGWEAPON]->val1 == 9 ) // Oblivion Curse gives a 2nd success chance after the 1st one passes which is reducible. [Rytech]
rate = 100 - tstatus->int_ * 4 / 5;
sc_start(src,bl,tsc->data[SC_POISONINGWEAPON]->val2,rate,tsc->data[SC_POISONINGWEAPON]->val1,skill->get_time2(GC_POISONINGWEAPON,1) - (tstatus->vit + tstatus->luk) / 2 * 1000);
@@ -3348,7 +3349,7 @@ int battle_blewcount_bonus(struct map_session_data *sd, uint16 skill_id) {
* battle_calc_magic_attack [DracoRPG]
*------------------------------------------*/
struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list *target,uint16 skill_id,uint16 skill_lv,int mflag) {
- int i, nk;
+ int nk;
short s_ele = 0;
unsigned int skillratio = 100; //Skill dmg modifiers.
@@ -3371,13 +3372,13 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
//Initial Values
ad.damage = 1;
ad.div_=skill->get_num(skill_id,skill_lv);
- ad.amotion=skill->get_inf(skill_id)&INF_GROUND_SKILL?0:sstatus->amotion; //Amotion should be 0 for ground skills.
+ ad.amotion = (skill->get_inf(skill_id)&INF_GROUND_SKILL) ? 0 : sstatus->amotion; //Amotion should be 0 for ground skills.
ad.dmotion=tstatus->dmotion;
ad.blewcount = skill->get_blewcount(skill_id,skill_lv);
ad.flag=BF_MAGIC|BF_SKILL;
ad.dmg_lv=ATK_DEF;
nk = skill->get_nk(skill_id);
- flag.imdef = nk&NK_IGNORE_DEF?1:0;
+ flag.imdef = (nk&NK_IGNORE_DEF)? 1 : 0;
sd = BL_CAST(BL_PC, src);
@@ -3389,6 +3390,7 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
if (s_ele == -1){ // pl=-1 : the skill takes the weapon's element
s_ele = sstatus->rhw.ele;
if( sd ){ //Summoning 10 spiritcharm will endow your weapon
+ int i;
ARR_FIND(SPIRITS_TYPE_CHARM_WATER, SPIRITS_TYPE_SPHERE, i, sd->spiritcharm[i] >= MAX_SPIRITCHARM);
if( i < SPIRITS_TYPE_SPHERE ) s_ele = i;
}
@@ -3414,7 +3416,7 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
//Skill Range Criteria
ad.flag |= battle->range_type(src, target, skill_id, skill_lv);
- flag.infdef=(tstatus->mode&MD_PLANT?1:0);
+ flag.infdef = (tstatus->mode&MD_PLANT) ? 1 : 0;
if( !flag.infdef && target->type == BL_SKILL && ((TBL_SKILL*)target)->group->unit_id == UNT_REVERBERATION )
flag.infdef = 1; // Reverberation takes 1 damage
@@ -3432,7 +3434,8 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
s_ele = ELE_DARK;
break;
case KO_KAIHOU:
- if( sd ){
+ if (sd) {
+ int i;
ARR_FIND(SPIRITS_TYPE_CHARM_WATER, SPIRITS_TYPE_SPHERE, i, sd->spiritcharm[i] > 0);
if( i < SPIRITS_TYPE_SPHERE )
s_ele = i;
@@ -3449,6 +3452,7 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
if (!flag.infdef) //No need to do the math for plants
{
+ int i;
#ifdef RENEWAL
ad.damage = 0; //reinitialize..
#endif
@@ -3703,7 +3707,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *
nullpo_retr(md, target);
//Some initial values
- md.amotion=skill->get_inf(skill_id)&INF_GROUND_SKILL?0:sstatus->amotion;
+ md.amotion = (skill->get_inf(skill_id)&INF_GROUND_SKILL) ? 0 : sstatus->amotion;
md.dmotion=tstatus->dmotion;
md.div_=skill->get_num( skill_id,skill_lv );
md.blewcount=skill->get_blewcount(skill_id,skill_lv);
@@ -4174,8 +4178,8 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list
nk = skill->get_nk(skill_id);
if( !skill_id && wflag ) //If flag, this is splash damage from Baphomet Card and it always hits.
nk |= NK_NO_CARDFIX_ATK|NK_IGNORE_FLEE;
- flag.hit = nk&NK_IGNORE_FLEE?1:0;
- flag.idef = flag.idef2 = nk&NK_IGNORE_DEF?1:0;
+ flag.hit = (nk&NK_IGNORE_FLEE) ? 1 : 0;
+ flag.idef = flag.idef2 = (nk&NK_IGNORE_DEF) ? 1 : 0;
#ifdef RENEWAL
flag.tdef = 0;
#endif
@@ -5427,7 +5431,6 @@ void battle_reflect_damage(struct block_list *target, struct block_list *src, st
int64 damage = wd->damage + wd->damage2, rdamage = 0, trdamage = 0;
struct map_session_data *sd, *tsd;
struct status_change *sc;
- struct status_change *ssc;
int64 tick = timer->gettick();
int delay = 50, rdelay = 0;
#ifdef RENEWAL
@@ -5515,6 +5518,7 @@ void battle_reflect_damage(struct block_list *target, struct block_list *src, st
}
if( wd->dmg_lv >= ATK_BLOCK ) {/* yes block still applies, somehow gravity thinks it makes sense. */
+ struct status_change *ssc;
if( sc ) {
struct status_change_entry *sce_d = sc->data[SC_DEVOTION];
struct block_list *d_bl = NULL;
@@ -5604,10 +5608,8 @@ void battle_reflect_damage(struct block_list *target, struct block_list *src, st
}
}
-#ifdef __clang_analyzer__
- // Tell Clang's static analyzer that we want to += it even the value is currently unused (it'd be used if we added new checks)
+ // Tell analyzers/compilers that we want to += it even the value is currently unused (it'd be used if we added new checks)
(void)delay;
-#endif // __clang_analyzer
/* something caused reflect */
if( trdamage ) {
@@ -5737,10 +5739,10 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
{
int index = sd->equip_index[EQI_AMMO];
if (index<0) {
- if (sd->weapontype1 > W_KATAR || sd->weapontype1 < W_HUUMA)
- clif->skill_fail(sd, 0, USESKILL_FAIL_NEED_MORE_BULLET, 0);
- else
+ if (sd->weapontype1 > W_KATAR && sd->weapontype1 < W_HUUMA)
clif->arrow_fail(sd, 0);
+ else
+ clif->skill_fail(sd, 0, USESKILL_FAIL_NEED_MORE_BULLET, 0);
return ATK_NONE;
}
//Ammo check by Ishizu-chan
diff --git a/src/map/battleground.c b/src/map/battleground.c
index ee241c5b8..2d4ba6bf1 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -47,12 +47,12 @@ struct map_session_data* bg_getavailablesd(struct battleground_data *bgd) {
/// Deletes BG Team from db
bool bg_team_delete(int bg_id) {
int i;
- struct map_session_data *sd;
struct battleground_data *bgd = bg->team_search(bg_id);
if( bgd == NULL ) return false;
for( i = 0; i < MAX_BG_MEMBERS; i++ ) {
- if( (sd = bgd->members[i].sd) == NULL )
+ struct map_session_data *sd = bgd->members[i].sd;
+ if (sd == NULL)
continue;
bg->send_dot_remove(sd);
@@ -81,7 +81,6 @@ void bg_send_dot_remove(struct map_session_data *sd) {
bool bg_team_join(int bg_id, struct map_session_data *sd) {
int i;
struct battleground_data *bgd = bg->team_search(bg_id);
- struct map_session_data *pl_sd;
if( bgd == NULL || sd == NULL || sd->bg_id ) return false;
@@ -106,7 +105,8 @@ bool bg_team_join(int bg_id, struct map_session_data *sd) {
guild->send_dot_remove(sd);
for( i = 0; i < MAX_BG_MEMBERS; i++ ) {
- if( (pl_sd = bgd->members[i].sd) != NULL && pl_sd != sd )
+ struct map_session_data *pl_sd = bgd->members[i].sd;
+ if (pl_sd != NULL && pl_sd != sd)
clif->hpmeter_single(sd->fd, pl_sd->bl.id, pl_sd->battle_status.hp, pl_sd->battle_status.max_hp);
}
@@ -119,7 +119,6 @@ bool bg_team_join(int bg_id, struct map_session_data *sd) {
int bg_team_leave(struct map_session_data *sd, enum bg_team_leave_type flag) {
int i, bg_id;
struct battleground_data *bgd;
- char output[128];
if( sd == NULL || !sd->bg_id )
return 0;
@@ -139,8 +138,9 @@ int bg_team_leave(struct map_session_data *sd, enum bg_team_leave_type flag) {
memset(&bgd->members[i], 0, sizeof(bgd->members[0]));
}
- if( --bgd->count != 0 ) {
- switch( flag ) {
+ if (--bgd->count != 0) {
+ char output[128];
+ switch (flag) {
default:
case BGTL_QUIT:
sprintf(output, "Server : %s has quit the game...", sd->status.name);
@@ -305,7 +305,7 @@ void bg_config_read(void) {
config_setting_t *settings = libconfig->setting_get_elem(data, 0);
config_setting_t *arenas;
const char *delay_var;
- int i, arena_count = 0, offline = 0;
+ int offline = 0;
if( !libconfig->setting_lookup_string(settings, "global_delay_var", &delay_var) )
delay_var = "BG_Delay_Tick";
@@ -319,7 +319,8 @@ void bg_config_read(void) {
bg->queue_on = true;
if( (arenas = libconfig->setting_get_member(settings, "arenas")) != NULL ) {
- arena_count = libconfig->setting_length(arenas);
+ int i;
+ int arena_count = libconfig->setting_length(arenas);
CREATE( bg->arena, struct bg_arena *, arena_count );
for(i = 0; i < arena_count; i++) {
config_setting_t *arena = libconfig->setting_get_elem(arenas, i);
@@ -855,15 +856,14 @@ void do_init_battleground(bool minimal) {
bg->config_read();
}
-void do_final_battleground(void) {
- int i;
-
+void do_final_battleground(void)
+{
db_destroy(bg->team_db);
- if( bg->arena )
- {
- for( i = 0; i < bg->arenas; i++ ) {
- if( bg->arena[i] )
+ if (bg->arena) {
+ int i;
+ for (i = 0; i < bg->arenas; i++) {
+ if (bg->arena[i])
aFree(bg->arena[i]);
}
aFree(bg->arena);
diff --git a/src/map/buyingstore.c b/src/map/buyingstore.c
index 8efffa342..a53acdbb0 100644
--- a/src/map/buyingstore.c
+++ b/src/map/buyingstore.c
@@ -65,10 +65,9 @@ bool buyingstore_setup(struct map_session_data* sd, unsigned char slots)
void buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned char result, const char* storename, const uint8* itemlist, unsigned int count)
{
unsigned int i, weight, listidx;
- struct item_data* id;
- if( !result || count == 0 )
- {// canceled, or no items
+ if (!result || count == 0) {
+ // canceled, or no items
return;
}
@@ -107,10 +106,11 @@ void buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned cha
weight = sd->weight;
// check item list
- for( i = 0; i < count; i++ )
- {// itemlist: <name id>.W <amount>.W <price>.L
+ for (i = 0; i < count; i++) {
+ // itemlist: <name id>.W <amount>.W <price>.L
unsigned short nameid, amount;
int price, idx;
+ struct item_data* id;
nameid = RBUFW(itemlist,i*8+0);
amount = RBUFW(itemlist,i*8+2);
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 153216cef..fd12ed013 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -655,9 +655,9 @@ void chrif_authfail(int fd) {/* HELLO WORLD. ip in RFIFOL 15 is not being used (
*/
int auth_db_cleanup_sub(DBKey key, DBData *data, va_list ap) {
struct auth_node *node = DB->data2ptr(data);
- const char* states[] = { "Login", "Logout", "Map change" };
if(DIFF_TICK(timer->gettick(),node->node_created)>60000) {
+ const char* states[] = { "Login", "Logout", "Map change" };
switch (node->state) {
case ST_LOGOUT:
//Re-save attempt (->sd should never be null here).
@@ -1148,7 +1148,6 @@ bool chrif_load_scdata(int fd) {
#ifdef ENABLE_SC_SAVING
struct map_session_data *sd;
- struct status_change_data *data;
int aid, cid, i, count;
aid = RFIFOL(fd,4); //Player Account ID
@@ -1169,7 +1168,7 @@ bool chrif_load_scdata(int fd) {
count = RFIFOW(fd,12); //sc_count
for (i = 0; i < count; i++) {
- data = (struct status_change_data*)RFIFOP(fd,14 + i*sizeof(struct status_change_data));
+ struct status_change_data *data = (struct status_change_data*)RFIFOP(fd,14 + i*sizeof(struct status_change_data));
status->change_start(NULL, &sd->bl, (sc_type)data->type, 10000, data->val1, data->val2, data->val3, data->val4,
data->tick, SCFLAG_NOAVOID|SCFLAG_FIXEDTICK|SCFLAG_LOADED|SCFLAG_FIXEDRATE);
}
diff --git a/src/map/clif.c b/src/map/clif.c
index da3b7b07f..d39d87a8f 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -1512,7 +1512,7 @@ void clif_homskillinfoblock(struct map_session_data *sd) {
struct homun_data *hd;
int fd;
int i,j;
- int len=4,id;
+ int len=4;
nullpo_retv(sd);
fd = sd->fd;
@@ -1525,7 +1525,8 @@ void clif_homskillinfoblock(struct map_session_data *sd) {
WFIFOW(fd,0)=0x235;
for ( i = 0; i < MAX_HOMUNSKILL; i++){
- if( (id = hd->homunculus.hskill[i].id) != 0 ){
+ int id = hd->homunculus.hskill[i].id;
+ if (id != 0) {
j = id - HM_SKILLBASE;
WFIFOW(fd,len ) = id;
WFIFOW(fd,len+2) = skill->get_inf(id);
@@ -2421,7 +2422,7 @@ void clif_item_equip(short idx, struct EQUIPITEM_INFO *p, struct item *i, struct
#endif
#if PACKETVER >= 20100629
- p->wItemSpriteNumber = id->equip&EQP_VISIBLE ? id->look : 0;
+ p->wItemSpriteNumber = (id->equip&EQP_VISIBLE) ? id->look : 0;
#endif
#if PACKETVER >= 20120925
@@ -3242,18 +3243,16 @@ void clif_changelook(struct block_list *bl,int type,int val)
if( !vd->cloth_color )
break;
- if( sd ) {
- if( sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette )
- vd->cloth_color = 0;
- if( sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette )
- vd->cloth_color = 0;
- if( sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette )
- vd->cloth_color = 0;
- if( sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette )
- vd->cloth_color = 0;
- if( sd->sc.option&OPTION_OKTOBERFEST /* TODO: config? */ )
- vd->cloth_color = 0;
- }
+ if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
+ vd->cloth_color = 0;
+ if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
+ vd->cloth_color = 0;
+ if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
+ vd->cloth_color = 0;
+ if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
+ vd->cloth_color = 0;
+ if (sd->sc.option&OPTION_OKTOBERFEST /* TODO: config? */)
+ vd->cloth_color = 0;
break;
case LOOK_HAIR:
vd->hair_style = val;
@@ -3477,7 +3476,7 @@ void clif_arrow_fail(struct map_session_data *sd,int type)
/// 01ad <packet len>.W { <name id>.W }*
void clif_arrow_create_list(struct map_session_data *sd)
{
- int i, c, j;
+ int i, c;
int fd;
nullpo_retv(sd);
@@ -3487,6 +3486,7 @@ void clif_arrow_create_list(struct map_session_data *sd)
WFIFOW(fd,0) = 0x1ad;
for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
+ int j;
if (skill->arrow_db[i].nameid > 0
&& (j = pc->search_inventory(sd, skill->arrow_db[i].nameid)) != INDEX_NOT_FOUND
&& !sd->status.inventory[j].equip && sd->status.inventory[j].identify
@@ -5420,11 +5420,11 @@ void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst) {
WBUFW(buf, 4) = status->get_lv(dst);
WBUFW(buf, 6) = dstatus->size;
WBUFL(buf, 8) = dstatus->hp;
- WBUFW(buf,12) = (battle_config.estimation_type&1?dstatus->def:0)
- + (battle_config.estimation_type&2?dstatus->def2:0);
+ WBUFW(buf,12) = ((battle_config.estimation_type&1) ? dstatus->def : 0)
+ + ((battle_config.estimation_type&2) ? dstatus->def2 : 0);
WBUFW(buf,14) = dstatus->race;
- WBUFW(buf,16) = (battle_config.estimation_type&1?dstatus->mdef:0)
- + (battle_config.estimation_type&2?dstatus->mdef2:0);
+ WBUFW(buf,16) = ((battle_config.estimation_type&1) ? dstatus->mdef : 0)
+ + ((battle_config.estimation_type&2) ? dstatus->mdef2 : 0);
WBUFW(buf,18) = dstatus->def_ele;
for(i=0;i<9;i++) {
WBUFB(buf,20+i)= (unsigned char)battle->attr_ratio(i+1,dstatus->def_ele, dstatus->ele_lv);
@@ -6103,7 +6103,6 @@ void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *
{
int i,c;
int fd;
- int nameid;
nullpo_retv(sd);
nullpo_retv(dstsd);
@@ -6112,8 +6111,9 @@ void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *
WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
WFIFOW(fd,0)=0x1fc;
- for(i=c=0;i<MAX_INVENTORY;i++){
- if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
+ for (i = c = 0; i < MAX_INVENTORY; i++) {
+ int nameid = dstsd->status.inventory[i].nameid;
+ if (nameid > 0 && dstsd->status.inventory[i].attribute != 0) { // && skill_can_repair(sd,nameid)) {
WFIFOW(fd,c*13+4) = i;
WFIFOW(fd,c*13+6) = nameid;
WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
@@ -6177,7 +6177,6 @@ void clif_item_refine_list(struct map_session_data *sd)
int i,c;
int fd;
uint16 skill_lv;
- int wlv;
nullpo_retv(sd);
@@ -6187,9 +6186,9 @@ void clif_item_refine_list(struct map_session_data *sd)
WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
WFIFOW(fd,0)=0x221;
- for(i=c=0;i<MAX_INVENTORY;i++){
+ for (i = c = 0; i < MAX_INVENTORY; i++) {
if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify
- && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1
+ && itemdb_wlv(sd->status.inventory[i].nameid) >= 1
&& !sd->inventory_data[i]->flag.no_refine
&& !(sd->status.inventory[i].equip&EQP_ARMS)){
WFIFOW(fd,c*13+ 4)=i+2;
@@ -8540,7 +8539,7 @@ void clif_refresh(struct map_session_data *sd)
void clif_charnameack (int fd, struct block_list *bl)
{
unsigned char buf[103];
- int cmd = 0x95, i, ps = -1;
+ int cmd = 0x95;
nullpo_retv(bl);
@@ -8553,6 +8552,7 @@ void clif_charnameack (int fd, struct block_list *bl)
struct map_session_data *ssd = (struct map_session_data *)bl;
struct party_data *p = NULL;
struct guild *g = NULL;
+ int ps = -1;
//Requesting your own "shadow" name. [Skotlex]
if (ssd->fd == fd && ssd->disguise != -1)
@@ -8570,7 +8570,8 @@ void clif_charnameack (int fd, struct block_list *bl)
p = party->search(ssd->status.party_id);
}
if( ssd->status.guild_id ) {
- if( ( g = ssd->guild ) != NULL ) {
+ if ((g = ssd->guild ) != NULL) {
+ int i;
ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
if( i < g->max_member ) ps = g->member[i].position;
}
@@ -8634,7 +8635,7 @@ void clif_charnameack (int fd, struct block_list *bl)
if( battle_config.show_mob_info&1 )
str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
if( battle_config.show_mob_info&2 )
- str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
+ str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
//Even thought mobhp ain't a name, we send it as one so the client
//can parse it. [Skotlex]
if( str_p != mobhp )
@@ -8952,19 +8953,18 @@ void clif_equpcheckbox(struct map_session_data* sd)
/// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20101124)
/// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20110111)
void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd) {
- int i, k, equip = 0;
+ int i, equip = 0;
nullpo_retv(sd);
nullpo_retv(tsd);
- for( i = 0; i < EQI_MAX; i++ ) {
- if( (k = tsd->equip_index[i]) >= 0 ) {
-
+ for (i = 0; i < EQI_MAX; i++) {
+ int k = tsd->equip_index[i];
+ if (k >= 0) {
if (tsd->status.inventory[k].nameid <= 0 || tsd->inventory_data[k] == NULL) // Item doesn't exist
continue;
clif_item_equip(k+2,&viewequip_list.list[equip++],&tsd->status.inventory[k],tsd->inventory_data[k],pc->equippoint(tsd,k));
-
}
}
@@ -10267,12 +10267,11 @@ void clif_hercules_chsys_left(struct hChSysCh *channel, struct map_session_data
void clif_hercules_chsys_quitg(struct map_session_data *sd) {
unsigned char i;
- struct hChSysCh *channel = NULL;
for( i = 0; i < sd->channel_count; i++ ) {
- if( (channel = sd->channels[i] ) != NULL && channel->type == hChSys_ALLY ) {
-
- if ( !idb_remove(channel->users,sd->status.char_id) )
+ struct hChSysCh *channel = sd->channels[i];
+ if (channel != NULL && channel->type == hChSys_ALLY) {
+ if (!idb_remove(channel->users,sd->status.char_id))
continue;
if( channel == sd->gcbind )
@@ -10310,10 +10309,10 @@ void clif_hercules_chsys_quitg(struct map_session_data *sd) {
void clif_hercules_chsys_quit(struct map_session_data *sd) {
unsigned char i;
- struct hChSysCh *channel = NULL;
- for( i = 0; i < sd->channel_count; i++ ) {
- if( (channel = sd->channels[i] ) != NULL ) {
+ for (i = 0; i < sd->channel_count; i++) {
+ struct hChSysCh *channel = sd->channels[i];
+ if (channel != NULL) {
idb_remove(channel->users,sd->status.char_id);
if( channel == sd->gcbind )
@@ -10480,8 +10479,9 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
clif->chsys_send(channel,sd,message);
} else if( channel->pass[0] == '\0' && !(channel->banned && idb_exists(channel->banned, sd->status.account_id)) ) {
if( channel->type == hChSys_ALLY ) {
- struct guild *g = sd->guild, *sg = NULL;
+ struct guild *g = sd->guild;
for (k = 0; k < MAX_GUILDALLIANCE; k++) {
+ struct guild *sg = NULL;
if( g->alliance[k].opposition == 0 && g->alliance[k].guild_id && (sg = guild->search(g->alliance[k].guild_id) ) ) {
if( !(sg->channel->banned && idb_exists(sg->channel->banned, sd->status.account_id)))
clif->chsys_join(sg->channel,sd);
@@ -13081,7 +13081,7 @@ bool clif_validate_emblem(const uint8 *emblem, unsigned long emblem_len) {
#endif // not NetBSD < 6 / Solaris
uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
unsigned long buf_len = sizeof(buf);
- int header = 0, bitmap = 0, offbits = 0, palettesize = 0, i = 0;
+ int header = 0, bitmap = 0, offbits = 0, palettesize = 0;
if( decode_zip(buf, &buf_len, emblem, emblem_len) != 0 || buf_len < BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE
|| RBUFW(buf,0) != 0x4d42 // BITMAPFILEHEADER.bfType (signature)
@@ -13127,6 +13127,7 @@ bool clif_validate_emblem(const uint8 *emblem, unsigned long emblem_len) {
if( battle_config.client_emblem_max_blank_percent < 100 ) {
int required_pixels = BITMAP_WIDTH * BITMAP_HEIGHT * (100 - battle_config.client_emblem_max_blank_percent) / 100;
int found_pixels = 0;
+ int i;
/// Checks what percentage of a guild emblem is blank. A blank emblem
/// consists solely of magenta pixels. Since the client uses 16-bit
/// colors, any magenta shade that reduces to #ff00ff passes off as
@@ -13141,7 +13142,7 @@ bool clif_validate_emblem(const uint8 *emblem, unsigned long emblem_len) {
const uint8 *indexes = (const uint8 *)RBUFP(buf,offbits);
const uint32 *palette = (const uint32 *)RBUFP(buf,BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE);
- for( i = 0; i < BITMAP_WIDTH * BITMAP_HEIGHT; i++ ) {
+ for (i = 0; i < BITMAP_WIDTH * BITMAP_HEIGHT; i++) {
if( indexes[i] >= palettesize ) // Invalid color
return false;
@@ -13159,7 +13160,7 @@ bool clif_validate_emblem(const uint8 *emblem, unsigned long emblem_len) {
{
const struct s_bitmaptripple *pixels = (const struct s_bitmaptripple*)RBUFP(buf,offbits);
- for( i = 0; i < BITMAP_WIDTH * BITMAP_HEIGHT; i++ ) {
+ for (i = 0; i < BITMAP_WIDTH * BITMAP_HEIGHT; i++) {
// if( pixels[i].r < 0xF8 || pixels[i].g > 0x07 || pixels[i].b < 0xF8 )
if( ( pixels[i].rgb&0xF8F8F8 ) != 0xF800F8 ) {
if( ++found_pixels >= required_pixels ) {
@@ -15221,7 +15222,6 @@ void clif_Auction_results(struct map_session_data *sd, short count, short pages,
int i, fd = sd->fd, len = sizeof(struct auction_data);
struct auction_data auction;
struct item_data *item;
- int k;
WFIFOHEAD(fd,12 + (count * 83));
WFIFOW(fd,0) = 0x252;
@@ -15230,8 +15230,8 @@ void clif_Auction_results(struct map_session_data *sd, short count, short pages,
WFIFOL(fd,8) = count;
for( i = 0; i < count; i++ ) {
+ int k = 12 + (i * 83);
memcpy(&auction, RBUFP(buf,i * len), len);
- k = 12 + (i * 83);
WFIFOL(fd,k) = auction.auction_id;
safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
@@ -15904,7 +15904,6 @@ void clif_quest_send_mission(struct map_session_data *sd) {
void clif_quest_add(struct map_session_data *sd, struct quest *qd) {
int fd = sd->fd;
int i;
- struct mob_db *monster;
struct quest_db *qi = quest->db(qd->quest_id);
WFIFOHEAD(fd, packet_len(0x2b3));
@@ -15916,6 +15915,7 @@ void clif_quest_add(struct map_session_data *sd, struct quest *qd) {
WFIFOW(fd, 15) = qi->num_objectives;
for( i = 0; i < qi->num_objectives; i++ ) {
+ struct mob_db *monster;
WFIFOL(fd, i*30+17) = qi->mob[i];
WFIFOW(fd, i*30+21) = qd->count[i];
monster = mob->db(qi->mob[i]);
@@ -16142,7 +16142,7 @@ void clif_mercenary_info(struct map_session_data *sd) {
void clif_mercenary_skillblock(struct map_session_data *sd)
{
struct mercenary_data *md;
- int fd, i, len = 4, id, j;
+ int fd, i, len = 4, j;
if( sd == NULL || (md = sd->md) == NULL )
return;
@@ -16150,9 +16150,9 @@ void clif_mercenary_skillblock(struct map_session_data *sd)
fd = sd->fd;
WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
WFIFOW(fd,0) = 0x29d;
- for( i = 0; i < MAX_MERCSKILL; i++ )
- {
- if( (id = md->db->skill[i].id) == 0 )
+ for (i = 0; i < MAX_MERCSKILL; i++) {
+ int id = md->db->skill[i].id;
+ if (id == 0)
continue;
j = id - MC_SKILLBASE;
WFIFOW(fd,len) = id;
@@ -16177,10 +16177,11 @@ void clif_mercenary_skillblock(struct map_session_data *sd)
void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
{
int option = RFIFOB(fd,2);
- if( sd->md == NULL )
+ if (sd->md == NULL)
return;
- if( option == 2 ) mercenary->delete(sd->md, 2);
+ if (option == 2)
+ mercenary->delete(sd->md, 2);
}
@@ -18264,11 +18265,11 @@ void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
#if PACKETVER >= 20131223
struct npc_item_list *shop = nd->u.scr.shop->item;
unsigned short shop_size = nd->u.scr.shop->items, i, c;
- struct item_data *id = NULL;
npcmarket_open.PacketType = npcmarketopenType;
for(i = 0, c = 0; i < shop_size; i++) {
+ struct item_data *id = NULL;
if( shop[i].nameid && (id = itemdb->exists(shop[i].nameid)) ) {
npcmarket_open.list[c].nameid = shop[i].nameid;
npcmarket_open.list[c].price = shop[i].value;
diff --git a/src/map/guild.c b/src/map/guild.c
index 3d5a0e09e..913bd0e4a 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -746,12 +746,12 @@ void guild_member_joined(struct map_session_data *sd)
sd->guild = g;
if (clif->hChSys->ally && clif->hChSys->ally_autojoin) {
- struct guild* sg = NULL;
struct hChSysCh *channel = g->channel;
if( !(channel->banned && idb_exists(channel->banned, sd->status.account_id) ) )
clif->chsys_join(channel,sd);
for (i = 0; i < MAX_GUILDALLIANCE; i++) {
+ struct guild* sg = NULL;
if( g->alliance[i].opposition == 0 && g->alliance[i].guild_id && (sg = guild->search(g->alliance[i].guild_id) ) ) {
if( !(sg->channel->banned && idb_exists(sg->channel->banned, sd->status.account_id)))
clif->chsys_join(sg->channel,sd);
@@ -1155,7 +1155,6 @@ int guild_change_notice(struct map_session_data *sd,int guild_id,const char *mes
int guild_notice_changed(int guild_id,const char *mes1,const char *mes2)
{
int i;
- struct map_session_data *sd;
struct guild *g=guild->search(guild_id);
if(g==NULL)
return 0;
@@ -1164,7 +1163,8 @@ int guild_notice_changed(int guild_id,const char *mes1,const char *mes2)
memcpy(g->mes2,mes2,MAX_GUILDMES2);
for(i=0;i<g->max_member;i++){
- if((sd=g->member[i].sd)!=NULL)
+ struct map_session_data *sd = g->member[i].sd;
+ if (sd != NULL)
clif->guild_notice(sd,g);
}
return 0;
@@ -1688,11 +1688,13 @@ int guild_allianceack(int guild_id1,int guild_id2,int account_id1,int account_id
for (i = 0; i < 2 - (flag & 1); i++) { // Retransmission of the relationship list to all members
- struct map_session_data *msd;
- if(g[i]!=NULL)
- for(j=0;j<g[i]->max_member;j++)
- if((msd=g[i]->member[j].sd)!=NULL)
+ if (g[i] != NULL) {
+ for (j = 0; j < g[i]->max_member; j++) {
+ struct map_session_data *msd = g[i]->member[j].sd;
+ if (msd != NULL)
clif->guild_allianceinfo(msd);
+ }
+ }
}
return 0;
}
@@ -1939,12 +1941,12 @@ int guild_break(struct map_session_data *sd,char *name) {
*/
void guild_castle_map_init(void)
{
- DBIterator* iter = NULL;
int num = db_size(guild->castle_db);
if (num > 0) {
struct guild_castle* gc = NULL;
int *castle_ids, *cursor;
+ DBIterator* iter = NULL;
CREATE(castle_ids, int, num);
cursor = castle_ids;
@@ -1980,11 +1982,12 @@ int guild_castledatasave(int castle_id, int index, int value)
case 1: // The castle's owner has changed? Update or remove Guardians too. [Skotlex]
{
int i;
- struct mob_data *gd;
gc->guild_id = value;
- for (i = 0; i < MAX_GUARDIANS; i++)
+ for (i = 0; i < MAX_GUARDIANS; i++) {
+ struct mob_data *gd;
if (gc->guardian[i].visible && (gd = map->id2md(gc->guardian[i].id)) != NULL)
mob->guardian_guildchange(gd);
+ }
break;
}
case 2:
@@ -1992,11 +1995,12 @@ int guild_castledatasave(int castle_id, int index, int value)
case 3: // defense invest change -> recalculate guardian hp
{
int i;
- struct mob_data *gd;
gc->defense = value;
- for (i = 0; i < MAX_GUARDIANS; i++)
+ for (i = 0; i < MAX_GUARDIANS; i++) {
+ struct mob_data *gd;
if (gc->guardian[i].visible && (gd = map->id2md(gc->guardian[i].id)) != NULL)
status_calc_mob(gd, SCO_NONE);
+ }
break;
}
case 4:
diff --git a/src/map/homunculus.c b/src/map/homunculus.c
index 1d226749b..17336a00d 100644
--- a/src/map/homunculus.c
+++ b/src/map/homunculus.c
@@ -1211,7 +1211,6 @@ void homunculus_skill_db_read(void) {
}
void homunculus_exp_db_read(void) {
- FILE *fp;
char line[1024];
int i, j=0;
char *filename[]={
@@ -1220,6 +1219,7 @@ void homunculus_exp_db_read(void) {
memset(homun->exptable,0,sizeof(homun->exptable));
for(i = 0; i < 2; i++) {
+ FILE *fp;
sprintf(line, "%s/%s", map->db_path, filename[i]);
if( (fp=fopen(line,"r")) == NULL) {
if(i != 0)
diff --git a/src/map/instance.c b/src/map/instance.c
index 890d455ff..a2d363fc9 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -57,7 +57,7 @@ int instance_create(int owner_id, const char *name, enum instance_owner_type typ
struct party_data *p = NULL;
struct guild *g = NULL;
short *iptr = NULL;
- int i, j;
+ int i;
switch ( type ) {
case IOT_NONE:
@@ -122,8 +122,9 @@ int instance_create(int owner_id, const char *name, enum instance_owner_type typ
safestrncpy( instance->list[i].name, name, sizeof(instance->list[i].name) );
if( type != IOT_NONE ) {
+ int j;
ARR_FIND(0, *icptr, j, iptr[j] == -1);
- if( j == *icptr ) {
+ if (j == *icptr) {
switch( type ) {
case IOT_CHAR:
RECREATE(sd->instance, short, ++*icptr);
@@ -138,8 +139,9 @@ int instance_create(int owner_id, const char *name, enum instance_owner_type typ
g->instance[g->instances-1] = i;
break;
}
- } else
+ } else {
iptr[j] = i;
+ }
}
clif->instance(i, 1, 0); // Start instancing window
@@ -507,7 +509,7 @@ void instance_destroy(int instance_id) {
struct party_data *p = NULL;
struct guild *g = NULL;
short *iptr = NULL;
- int type, j, last = 0;
+ int type, j;
unsigned int now = (unsigned int)time(NULL);
if( !instance->valid(instance_id) )
@@ -557,9 +559,10 @@ void instance_destroy(int instance_id) {
iptr[j] = -1;
}
- if (instance->list[instance_id].map)
- {
- while( instance->list[instance_id].num_map && last != instance->list[instance_id].map[0] ) { // Remove all maps from instance
+ if (instance->list[instance_id].map) {
+ int last = 0;
+ while (instance->list[instance_id].num_map && last != instance->list[instance_id].map[0]) {
+ // Remove all maps from instance
last = instance->list[instance_id].map[0];
instance->del_map( instance->list[instance_id].map[0] );
}
diff --git a/src/map/intif.c b/src/map/intif.c
index aac04df33..4dbb7e3eb 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -395,9 +395,9 @@ int intif_request_registry(struct map_session_data *sd, int flag)
WFIFOW(inter_fd,0) = 0x3005;
WFIFOL(inter_fd,2) = sd->status.account_id;
WFIFOL(inter_fd,6) = sd->status.char_id;
- WFIFOB(inter_fd,10) = (flag&1?1:0); //Request Acc Reg 2
- WFIFOB(inter_fd,11) = (flag&2?1:0); //Request Acc Reg
- WFIFOB(inter_fd,12) = (flag&4?1:0); //Request Char Reg
+ WFIFOB(inter_fd,10) = (flag&1) ? 1 : 0; //Request Acc Reg 2
+ WFIFOB(inter_fd,11) = (flag&2) ? 1 : 0; //Request Acc Reg
+ WFIFOB(inter_fd,12) = (flag&4) ? 1 : 0; //Request Char Reg
WFIFOSET(inter_fd,13);
return 0;
@@ -968,7 +968,7 @@ void mapif_parse_WisToGM(int fd)
{
int permission, mes_len;
char Wisp_name[NAME_LENGTH];
- char mbuf[255];
+ char mbuf[255] = { 0 };
char *message;
mes_len = RFIFOW(fd,2) - 32;
@@ -987,7 +987,7 @@ void mapif_parse_WisToGM(int fd)
// Request player registre
void intif_parse_Registers(int fd)
{
- int i, flag;
+ int flag;
struct map_session_data *sd;
int account_id = RFIFOL(fd,4), char_id = RFIFOL(fd,8);
struct auth_node *node = chrif->auth_check(account_id, char_id, ST_LOGIN);
@@ -1025,9 +1025,9 @@ void intif_parse_Registers(int fd)
pc->reg_load = true;
if( RFIFOW(fd, 14) ) {
- char key[32], sval[254];
+ char key[32];
unsigned int index;
- int max = RFIFOW(fd, 14), cursor = 16, ival;
+ int max = RFIFOW(fd, 14), cursor = 16, i;
script->parser_current_file = "loading char/acc variables";//for script_add_str to refer to here in case errors occur
@@ -1037,8 +1037,9 @@ void intif_parse_Registers(int fd)
* str type
* { keyLength(B), key(<keyLength>), index(L), valLength(B), val(<valLength>) }
**/
- if( type ) {
+ if (type) {
for(i = 0; i < max; i++) {
+ char sval[254];
safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), RFIFOB(fd, cursor));
cursor += RFIFOB(fd, cursor) + 1;
@@ -1058,6 +1059,7 @@ void intif_parse_Registers(int fd)
**/
} else {
for(i = 0; i < max; i++) {
+ int ival;
safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), RFIFOB(fd, cursor));
cursor += RFIFOB(fd, cursor) + 1;
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index be182be72..6559005a2 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -1122,7 +1122,7 @@ void itemdb_read_packages(void) {
void itemdb_read_chains(void) {
config_t item_chain_conf;
- config_setting_t *itc = NULL, *entry = NULL;
+ config_setting_t *itc = NULL;
#ifdef RENEWAL
const char *config_filename = "db/re/item_chain.conf"; // FIXME hardcoded name
#else
@@ -1146,6 +1146,7 @@ void itemdb_read_chains(void) {
struct item_chain_entry *prev = NULL;
const char *name = config_setting_name(itc);
int c = 0;
+ config_setting_t *entry = NULL;
script->set_constant2(name,i-1,0);
itemdb->chains[count].qty = (unsigned short)libconfig->setting_length(itc);
@@ -2094,7 +2095,6 @@ bool itemdb_is_item_usable(struct item_data *item)
/// Destroys the item_data.
void destroy_item_data(struct item_data* self, int free_self)
{
- int v;
if( self == NULL )
return;
// free scripts
@@ -2108,11 +2108,12 @@ void destroy_item_data(struct item_data* self, int free_self)
aFree(self->combos);
if (self->hdata)
{
- for (v = 0; v < self->hdatac; v++ ) {
- if (self->hdata[v]->flag.free ) {
- aFree(self->hdata[v]->data);
+ int i;
+ for (i = 0; i < self->hdatac; i++ ) {
+ if (self->hdata[i]->flag.free ) {
+ aFree(self->hdata[i]->data);
}
- aFree(self->hdata[v]);
+ aFree(self->hdata[i]);
}
aFree(self->hdata);
}
@@ -2157,10 +2158,9 @@ void itemdb_clear(bool total) {
itemdb->groups = NULL;
itemdb->group_count = 0;
- if( itemdb->chains )
- {
- for( i = 0; i < itemdb->chain_count; i++ ) {
- if( itemdb->chains[i].items )
+ if (itemdb->chains) {
+ for (i = 0; i < itemdb->chain_count; i++) {
+ if (itemdb->chains[i].items)
aFree(itemdb->chains[i].items);
}
aFree(itemdb->chains);
@@ -2169,14 +2169,12 @@ void itemdb_clear(bool total) {
itemdb->chains = NULL;
itemdb->chain_count = 0;
- if( itemdb->packages )
- {
- for( i = 0; i < itemdb->package_count; i++ ) {
- int c;
- if (itemdb->packages[i].random_groups)
- {
- for( c = 0; c < itemdb->packages[i].random_qty; c++ )
- aFree(itemdb->packages[i].random_groups[c].random_list);
+ if (itemdb->packages) {
+ for (i = 0; i < itemdb->package_count; i++) {
+ if (itemdb->packages[i].random_groups) {
+ int j;
+ for (j = 0; j < itemdb->packages[i].random_qty; j++)
+ aFree(itemdb->packages[i].random_groups[j].random_list);
aFree(itemdb->packages[i].random_groups);
}
if( itemdb->packages[i].must_items )
@@ -2187,10 +2185,9 @@ void itemdb_clear(bool total) {
}
itemdb->package_count = 0;
- if( itemdb->combos )
- {
- for(i = 0; i < itemdb->combo_count; i++) {
- if( itemdb->combos[i]->script ) // Check if script was loaded
+ if (itemdb->combos) {
+ for (i = 0; i < itemdb->combo_count; i++) {
+ if (itemdb->combos[i]->script) // Check if script was loaded
script->free_code(itemdb->combos[i]->script);
aFree(itemdb->combos[i]);
}
@@ -2200,7 +2197,7 @@ void itemdb_clear(bool total) {
itemdb->combos = NULL;
itemdb->combo_count = 0;
- if( total )
+ if (total)
return;
itemdb->other->clear(itemdb->other, itemdb->final_sub);
diff --git a/src/map/map.c b/src/map/map.c
index e71085fda..dcc0532dd 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1251,7 +1251,6 @@ int map_vforeachinpath(int (*func)(struct block_list*, va_list), int16 m, int16
//method specific variables
int magnitude2, len_limit; //The square of the magnitude
- int k;
int mx0 = x0, mx1 = x1, my0 = y0, my1 = y1;
len_limit = magnitude2 = MAGNITUDE2(x0, y0, x1, y1);
@@ -1260,7 +1259,7 @@ int map_vforeachinpath(int (*func)(struct block_list*, va_list), int16 m, int16
if (length) { //Adjust final position to fit in the given area.
//TODO: Find an alternate method which does not requires a square root calculation.
- k = (int)sqrt((float)magnitude2);
+ int k = (int)sqrt((float)magnitude2);
mx1 = x0 + (x1 - x0) * length / k;
my1 = y0 + (y1 - y0) * length / k;
len_limit = MAGNITUDE2(x0, y0, mx1, my1);
@@ -1596,7 +1595,7 @@ int map_addflooritem(struct item *item_data,int amount,int16 m,int16 x,int16 y,i
nullpo_ret(item_data);
- if(!map->searchrandfreecell(m,&x,&y,flags&2?1:0))
+ if (!map->searchrandfreecell(m, &x, &y, (flags&2)?1:0))
return 0;
r=rnd();
@@ -1614,11 +1613,11 @@ int map_addflooritem(struct item *item_data,int amount,int16 m,int16 x,int16 y,i
}
fitem->first_get_charid = first_charid;
- fitem->first_get_tick = timer->gettick() + (flags&1 ? battle_config.mvp_item_first_get_time : battle_config.item_first_get_time);
+ fitem->first_get_tick = timer->gettick() + ((flags&1) ? battle_config.mvp_item_first_get_time : battle_config.item_first_get_time);
fitem->second_get_charid = second_charid;
- fitem->second_get_tick = fitem->first_get_tick + (flags&1 ? battle_config.mvp_item_second_get_time : battle_config.item_second_get_time);
+ fitem->second_get_tick = fitem->first_get_tick + ((flags&1) ? battle_config.mvp_item_second_get_time : battle_config.item_second_get_time);
fitem->third_get_charid = third_charid;
- fitem->third_get_tick = fitem->second_get_tick + (flags&1 ? battle_config.mvp_item_third_get_time : battle_config.item_third_get_time);
+ fitem->third_get_tick = fitem->second_get_tick + ((flags&1) ? battle_config.mvp_item_third_get_time : battle_config.item_third_get_time);
memcpy(&fitem->item_data,item_data,sizeof(*item_data));
fitem->item_data.amount=amount;
@@ -1649,7 +1648,6 @@ void map_addnickdb(int charid, const char* nick)
{
struct charid2nick* p;
struct charid_request* req;
- struct map_session_data* sd;
if( map->charid2sd(charid) )
return;// already online
@@ -1657,11 +1655,12 @@ void map_addnickdb(int charid, const char* nick)
p = idb_ensure(map->nick_db, charid, map->create_charid2nick);
safestrncpy(p->nick, nick, sizeof(p->nick));
- while( p->requests ) {
+ while (p->requests) {
+ struct map_session_data* sd;
req = p->requests;
p->requests = req->next;
sd = map->charid2sd(req->charid);
- if( sd )
+ if (sd)
clif->solved_charname(sd->fd, charid, p->nick);
aFree(req);
}
@@ -1673,17 +1672,17 @@ void map_delnickdb(int charid, const char* name)
{
struct charid2nick* p;
struct charid_request* req;
- struct map_session_data* sd;
DBData data;
if (!map->nick_db->remove(map->nick_db, DB->i2key(charid), &data) || (p = DB->data2ptr(&data)) == NULL)
return;
- while( p->requests ) {
+ while (p->requests) {
+ struct map_session_data* sd;
req = p->requests;
p->requests = req->next;
sd = map->charid2sd(req->charid);
- if( sd )
+ if (sd)
clif->solved_charname(sd->fd, charid, name);
aFree(req);
}
@@ -2557,16 +2556,15 @@ int map_random_dir(struct block_list *bl, int16 *x, int16 *y)
{
short xi = *x-bl->x;
short yi = *y-bl->y;
- short i=0, j;
+ short i=0;
int dist2 = xi*xi + yi*yi;
short dist = (short)sqrt((float)dist2);
- short segment;
if (dist < 1) dist =1;
do {
- j = 1 + 2*(rnd()%4); //Pick a random diagonal direction
- segment = 1+(rnd()%dist); //Pick a random interval from the whole vector in that direction
+ int j = 1 + 2*(rnd()%4); //Pick a random diagonal direction
+ short segment = 1+(rnd()%dist); //Pick a random interval from the whole vector in that direction
xi = bl->x + segment*dirx[j];
segment = (short)sqrt((float)(dist2 - segment*segment)); //The complement of the previously picked segment
yi = bl->y + segment*diry[j];
@@ -2613,10 +2611,10 @@ int map_cell2gat(struct mapcell cell) {
return 1; // default to 'wall'
}
void map_cellfromcache(struct map_data *m) {
- char decode_buffer[MAX_MAP_SIZE];
- struct map_cache_map_info *info = NULL;
+ struct map_cache_map_info *info = (struct map_cache_map_info *)m->cellPos;
- if( (info = (struct map_cache_map_info *)m->cellPos) ) {
+ if (info) {
+ char decode_buffer[MAX_MAP_SIZE];
unsigned long size, xy;
int i;
@@ -4588,7 +4586,7 @@ bool map_zone_mf_cache(int m, char *flag, char *params) {
} else if ( !strcmpi(flag,"invincible_time_inc") ) {
if( !state ) {
if( map->list[m].invincible_time_inc != 0 ) {
- sprintf(rflag,"invincible_time_inc\t%d",map->list[m].invincible_time_inc);
+ sprintf(rflag,"invincible_time_inc\t%u",map->list[m].invincible_time_inc);
map_zone_mf_cache_add(m,rflag);
}
} if( sscanf(params, "%d", &state) == 1 ) {
diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c
index f026fde00..0092a6c61 100644
--- a/src/map/mapreg_sql.c
+++ b/src/map/mapreg_sql.c
@@ -220,13 +220,11 @@ void script_load_mapreg(void) {
* Saves permanent variables to database.
*/
void script_save_mapreg(void) {
- DBIterator* iter;
- struct mapreg_save *m = NULL;
-
- if( mapreg->dirty ) {
- iter = db_iterator(mapreg->regs.vars);
- for( m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter) ) {
- if( m->save ) {
+ if (mapreg->dirty) {
+ DBIterator *iter = db_iterator(mapreg->regs.vars);
+ struct mapreg_save *m;
+ for (m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter)) {
+ if (m->save) {
int num = script_getvarid(m->uid);
int i = script_getvaridx(m->uid);
const char* name = script->get_str(num);
diff --git a/src/map/mob.c b/src/map/mob.c
index 3d883a2f1..26cb51ddc 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -96,9 +96,8 @@ struct mob_chat *mob_chat(short id) {
int mobdb_searchname(const char *str)
{
int i;
- struct mob_db* monster;
for(i=0;i<=MAX_MOB_DB;i++){
- monster = mob->db(i);
+ struct mob_db *monster = mob->db(i);
if(monster == mob->dummy) //Skip dummy mobs.
continue;
if(strcmpi(monster->name,str)==0 || strcmpi(monster->jname,str)==0)
@@ -345,7 +344,6 @@ bool mob_ksprotected(struct block_list *src, struct block_list *target) {
*sd, // Source
*pl_sd, // Owner
*t_sd; // Mob Target
- struct status_change_entry *sce;
struct mob_data *md;
int64 tick = timer->gettick();
char output[128];
@@ -369,6 +367,7 @@ bool mob_ksprotected(struct block_list *src, struct block_list *target) {
t_sd = BL_CAST(BL_PC,s_bl);
do {
+ struct status_change_entry *sce;
if( map->list[md->bl.m].flag.allowks || map_flag_ks(md->bl.m) )
return false; // Ignores GVG, PVP and AllowKS map flags
@@ -947,7 +946,7 @@ int mob_spawn (struct mob_data *md)
//md->master_id = 0;
md->master_dist = 0;
- md->state.aggressive = md->status.mode&MD_ANGRY?1:0;
+ md->state.aggressive = (md->status.mode&MD_ANGRY) ? 1 : 0;
md->state.skillstate = MSS_IDLE;
md->next_walktime = tick+rnd()%1000+MIN_RANDOMWALKTIME;
md->last_linktime = tick;
@@ -1323,7 +1322,7 @@ int mob_unlocktarget(struct mob_data *md, int64 tick) {
*------------------------------------------*/
int mob_randomwalk(struct mob_data *md, int64 tick) {
const int retrycount=20;
- int i,x,y,c,d;
+ int i,c,d;
int speed;
nullpo_ret(md);
@@ -1339,8 +1338,8 @@ int mob_randomwalk(struct mob_data *md, int64 tick) {
for (i = 0; i < retrycount; i++) {
// Search of a movable place
int r=rnd();
- x=r%(d*2+1)-d;
- y=r/(d*2+1)%(d*2+1)-d;
+ int x=r%(d*2+1)-d;
+ int y=r/(d*2+1)%(d*2+1)-d;
x+=md->bl.x;
y+=md->bl.y;
@@ -1814,10 +1813,11 @@ struct item_drop* mob_setlootitem(struct item* item)
*------------------------------------------*/
int mob_delay_item_drop(int tid, int64 tick, int id, intptr_t data) {
struct item_drop_list *list;
- struct item_drop *ditem, *ditem_prev;
+ struct item_drop *ditem;
list=(struct item_drop_list *)data;
ditem = list->item;
while (ditem) {
+ struct item_drop *ditem_prev;
map->addflooritem(&ditem->item_data,ditem->item_data.amount,
list->m,list->x,list->y,
list->first_charid,list->second_charid,list->third_charid,0);
@@ -2095,7 +2095,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) {
int id,zeny;
unsigned int base_exp,job_exp;
} pt[DAMAGELOG_SIZE];
- int i, temp, count, m = md->bl.m, pnum = 0;
+ int i, temp, count, m = md->bl.m;
int dmgbltypes = 0; // bitfield of all bl types, that caused damage to the mob and are eligible for exp distribution
unsigned int mvp_damage;
int64 tick = timer->gettick();
@@ -2179,6 +2179,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) {
&& (!map->list[m].flag.nobaseexp || !map->list[m].flag.nojobexp) //Gives Exp
) { //Experience calculation.
int bonus = 100; //Bonus on top of your share (common to all attackers).
+ int pnum = 0;
if (md->sc.data[SC_RICHMANKIM])
bonus += md->sc.data[SC_RICHMANKIM]->val2;
if(sd) {
@@ -2422,7 +2423,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) {
if ( sd->add_drop[i].race == -md->class_ ||
( sd->add_drop[i].race > 0 && (
sd->add_drop[i].race & (1<<mstatus->race) ||
- sd->add_drop[i].race & (1<<(mstatus->mode&MD_BOSS?RC_BOSS:RC_NONBOSS))
+ sd->add_drop[i].race & (1<<((mstatus->mode&MD_BOSS)?RC_BOSS:RC_NONBOSS))
)))
{
//check if the bonus item drop rate should be multiplied with mob level/10 [Lupus]
@@ -3101,7 +3102,7 @@ int mobskill_use(struct mob_data *md, int64 tick, int event) {
return 0; //Skill act delay only affects non-event skills.
//Pick a starting position and loop from that.
- i = battle_config.mob_ai&0x100?rnd()%md->db->maxskill:0;
+ i = (battle_config.mob_ai&0x100) ? rnd()%md->db->maxskill : 0;
for (n = 0; n < md->db->maxskill; i++, n++) {
int c2, flag = 0;
@@ -3346,7 +3347,7 @@ int mob_is_clone(int class_)
//Returns: ID of newly crafted copy.
int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, int mode, int flag, unsigned int duration) {
int class_;
- int i,j,h,inf,skill_id, fd;
+ int i,j,h,inf, fd;
struct mob_data *md;
struct mob_skill *ms;
struct mob_db* db;
@@ -3399,7 +3400,7 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons
//Go Backwards to give better priority to advanced skills.
for (i=0,j = MAX_SKILL_TREE-1;j>=0 && i< MAX_MOBSKILL ;j--) {
int idx = pc->skill_tree[pc->class2idx(sd->status.class_)][j].idx;
- skill_id = pc->skill_tree[pc->class2idx(sd->status.class_)][j].id;
+ int skill_id = pc->skill_tree[pc->class2idx(sd->status.class_)][j].id;
if (!skill_id || sd->status.skill[idx].lv < 1 ||
(skill->db[idx].inf2&(INF2_WEDDING_SKILL|INF2_GUILD_SKILL))
)
@@ -3660,7 +3661,7 @@ static inline int mob_parse_dbrow_cap_value(int class_, int min, int max, int va
bool mob_parse_dbrow(char** str) {
struct mob_db *db, entry;
struct status_data *mstatus;
- int class_, i, k;
+ int class_, i;
double exp, maxhp;
struct mob_data data;
@@ -3832,7 +3833,7 @@ bool mob_parse_dbrow(char** str) {
int rate = 0, rate_adjust, type;
unsigned short ratemin, ratemax;
struct item_data *id;
- k = 31 + MAX_MVP_DROP*2 + i*2;
+ int k = 31 + MAX_MVP_DROP*2 + i*2;
db->dropitem[i].nameid = atoi(str[k]);
if (!db->dropitem[i].nameid) {
db->dropitem[i].p = 0; //No drop.
@@ -4055,7 +4056,6 @@ bool mob_readdb_mobavail(char* str[], int columns, int current)
*------------------------------------------*/
int mob_read_randommonster(void)
{
- FILE *fp;
char line[1024];
char *str[10],*p;
int i,j;
@@ -4068,7 +4068,8 @@ int mob_read_randommonster(void)
memset(&summon, 0, sizeof(summon));
- for( i = 0; i < ARRAYLENGTH(mobfile) && i < MAX_RANDOMMONSTER; i++ ) {
+ for (i = 0; i < ARRAYLENGTH(mobfile) && i < MAX_RANDOMMONSTER; i++) {
+ FILE *fp;
unsigned int count = 0;
mob->db_data[0]->summonper[i] = 1002; // Default fallback value, in case the database does not provide one
sprintf(line, "%s/%s", map->db_path, mobfile[i]);
@@ -4577,21 +4578,18 @@ int mob_read_sqlskilldb(void) {
*------------------------------------------*/
bool mob_readdb_race2(char* fields[], int columns, int current)
{
- int race, mobid, i;
+ int race, i;
race = atoi(fields[0]);
- if (race < RC2_NONE || race >= RC2_MAX)
- {
+ if (race < RC2_NONE || race >= RC2_MAX) {
ShowWarning("mob_readdb_race2: Unknown race2 %d.\n", race);
return false;
}
- for(i = 1; i<columns; i++)
- {
- mobid = atoi(fields[i]);
- if (mob->db(mobid) == mob->dummy)
- {
+ for (i = 1; i < columns; i++) {
+ int mobid = atoi(fields[i]);
+ if (mob->db(mobid) == mob->dummy) {
ShowWarning("mob_readdb_race2: Unknown mob id %d for race2 %d.\n", mobid, race);
continue;
}
@@ -4715,14 +4713,13 @@ int do_init_mob(bool minimal) {
void mob_destroy_mob_db(int index)
{
struct mob_db *data = mob->db_data[index];
- int v;
- if (data->hdata)
- {
- for (v = 0; v < data->hdatac; v++ ) {
- if (data->hdata[v]->flag.free ) {
- aFree(data->hdata[v]->data);
+ if (data->hdata) {
+ int i;
+ for (i = 0; i < data->hdatac; i++) {
+ if (data->hdata[i]->flag.free ) {
+ aFree(data->hdata[i]->data);
}
- aFree(data->hdata[v]);
+ aFree(data->hdata[i]);
}
aFree(data->hdata);
}
diff --git a/src/map/npc.c b/src/map/npc.c
index c00094f8c..6cc192f66 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -646,12 +646,11 @@ int npc_timerevent_start(struct npc_data* nd, int rid) {
int npc_timerevent_stop(struct npc_data* nd)
{
struct map_session_data *sd = NULL;
- const struct TimerData *td = NULL;
int *tid;
nullpo_ret(nd);
- if( nd->u.scr.rid && !(sd = map->id2sd(nd->u.scr.rid)) ) {
+ if (nd->u.scr.rid && !(sd = map->id2sd(nd->u.scr.rid))) {
ShowError("npc_timerevent_stop: Attached player not found!\n");
return 1;
}
@@ -660,17 +659,15 @@ int npc_timerevent_stop(struct npc_data* nd)
return 0;
// Delete timer
- if ( *tid != INVALID_TIMER )
- {
- td = timer->get(*tid);
- if( td && td->data )
+ if (*tid != INVALID_TIMER) {
+ const struct TimerData *td = timer->get(*tid);
+ if (td && td->data)
ers_free(npc->timer_event_ers, (void*)td->data);
timer->delete(*tid,npc->timerevent);
*tid = INVALID_TIMER;
}
- if( !sd && nd->u.scr.timertick )
- {
+ if (!sd && nd->u.scr.timertick) {
nd->u.scr.timer += DIFF_TICK32(timer->gettick(),nd->u.scr.timertick); // Set 'timer' to the time that has passed since the beginning of the timers
nd->u.scr.timertick = 0; // Set 'tick' to zero so that we know it's off.
}
@@ -2013,7 +2010,7 @@ int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short* item_li
{
char npc_ev[EVENT_NAME_LENGTH];
char card_slot[NAME_LENGTH];
- int i, j, idx;
+ int i, j;
int key_nameid = 0;
int key_amount = 0;
int key_refine = 0;
@@ -2036,21 +2033,20 @@ int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short* item_li
}
// save list of to be sold items
- for( i = 0; i < n; i++ )
- {
- idx = item_list[i*2]-2;
+ for (i = 0; i < n; i++) {
+ int idx = item_list[i*2]-2;
script->setarray_pc(sd, "@sold_nameid", i, (void*)(intptr_t)sd->status.inventory[idx].nameid, &key_nameid);
script->setarray_pc(sd, "@sold_quantity", i, (void*)(intptr_t)item_list[i*2+1], &key_amount);
- if( itemdb->isequip(sd->status.inventory[idx].nameid) )
- {// process equipment based information into the arrays
+ if (itemdb->isequip(sd->status.inventory[idx].nameid)) {
+ // process equipment based information into the arrays
script->setarray_pc(sd, "@sold_refine", i, (void*)(intptr_t)sd->status.inventory[idx].refine, &key_refine);
script->setarray_pc(sd, "@sold_attribute", i, (void*)(intptr_t)sd->status.inventory[idx].attribute, &key_attribute);
script->setarray_pc(sd, "@sold_identify", i, (void*)(intptr_t)sd->status.inventory[idx].identify, &key_identify);
- for( j = 0; j < MAX_SLOTS; j++ )
- {// store each of the cards from the equipment in the array
+ for (j = 0; j < MAX_SLOTS; j++) {
+ // store each of the cards from the equipment in the array
snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1);
script->setarray_pc(sd, card_slot, i, (void*)(intptr_t)sd->status.inventory[idx].card[j], &key_card[j]);
}
@@ -2224,9 +2220,8 @@ void npc_unload_duplicates(struct npc_data* nd) {
//Removes an npc from map and db.
//Single is to free name (for duplicates).
-int npc_unload(struct npc_data* nd, bool single) {
- unsigned int i;
-
+int npc_unload(struct npc_data* nd, bool single)
+{
nullpo_ret(nd);
if( nd->ud && nd->ud != &npc->base_ud ) {
@@ -2322,10 +2317,10 @@ int npc_unload(struct npc_data* nd, bool single) {
nd->ud = NULL;
}
- if( nd->hdata )
- {
- for( i = 0; i < nd->hdatac; i++ ) {
- if( nd->hdata[i]->flag.free ) {
+ if (nd->hdata) {
+ unsigned int i;
+ for (i = 0; i < nd->hdatac; i++) {
+ if (nd->hdata[i]->flag.free) {
aFree(nd->hdata[i]->data);
}
aFree(nd->hdata[i]);
@@ -2346,11 +2341,9 @@ int npc_unload(struct npc_data* nd, bool single) {
void npc_clearsrcfile(void)
{
struct npc_src_list* file = npc->src_files;
- struct npc_src_list* file_tofree;
- while( file != NULL )
- {
- file_tofree = file;
+ while (file != NULL) {
+ struct npc_src_list *file_tofree = file;
file = file->next;
aFree(file_tofree);
}
@@ -2889,9 +2882,9 @@ const char* npc_skip_script(const char* start, const char* buffer, const char* f
/// -%TAB%script%TAB%<NPC Name>%TAB%-1,{<code>}
/// <map name>,<x>,<y>,<facing>%TAB%script%TAB%<NPC Name>%TAB%<sprite id>,{<code>}
/// <map name>,<x>,<y>,<facing>%TAB%script%TAB%<NPC Name>%TAB%<sprite id>,<triggerX>,<triggerY>,{<code>}
-const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, int options, int *retval) {
+const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, int options, int *retval)
+{
int x, y, dir = 0, m, xs = 0, ys = 0; // [Valaris] thanks to fov
- char mapname[32];
struct script_code *scriptroot;
int i;
const char* end;
@@ -2901,13 +2894,15 @@ const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char*
int label_list_num;
struct npc_data* nd;
- if( strcmp(w1, "-") == 0 )
- {// floating npc
+ if (strcmp(w1, "-") == 0) {
+ // floating npc
x = 0;
y = 0;
m = -1;
- } else {// npc in a map
- if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 ) {
+ } else {
+ // npc in a map
+ char mapname[32];
+ if (sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4) {
ShowError("npc_parse_script: Invalid placement format for a script in file '%s', line '%d'. Skipping the rest of file...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
if (retval) *retval = EXIT_FAILURE;
return NULL;// unknown format, don't continue
@@ -3020,7 +3015,6 @@ const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char*
/// !!Only NPO_ONINIT is available trough options!!
const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, int options, int *retval) {
int x, y, dir, m, xs = -1, ys = -1;
- char mapname[32];
char srcname[128];
int i;
const char* end;
@@ -3053,14 +3047,18 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
type = dnd->subtype;
// get placement
- if( (type==SHOP || type==CASHSHOP || type==SCRIPT) && strcmp(w1, "-") == 0 ) {// floating shop/chashshop/script
+ if ((type==SHOP || type==CASHSHOP || type==SCRIPT) && strcmp(w1, "-") == 0) {
+ // floating shop/chashshop/script
x = y = dir = 0;
m = -1;
} else {
+ char mapname[32];
int fields = sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir);
- if( type == WARP && fields == 3 ) { // <map name>,<x>,<y>
+ if (type == WARP && fields == 3) {
+ // <map name>,<x>,<y>
dir = 0;
- } else if( fields != 4 ) {// <map name>,<x>,<y>,<facing>
+ } else if (fields != 4) {
+ // <map name>,<x>,<y>,<facing>
ShowError("npc_parse_duplicate: Invalid placement format for duplicate in file '%s', line '%d'. Skipping line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
if (retval) *retval = EXIT_FAILURE;
return end;// next line, try to continue
@@ -4383,7 +4381,6 @@ void npc_process_files( int npc_min ) {
//Clear then reload npcs files
int npc_reload(void) {
- int16 m, i;
int npc_new_min = npc_id;
struct s_mapiterator* iter;
struct block_list* bl;
@@ -4421,7 +4418,9 @@ int npc_reload(void) {
mapit->free(iter);
if(battle_config.dynamic_mobs) {// dynamic check by [random]
+ int16 m;
for (m = 0; m < map->count; m++) {
+ int16 i;
for (i = 0; i < MAX_MOB_LIST_PER_MAP; i++) {
if (map->list[m].moblist[i] != NULL) {
aFree(map->list[m].moblist[i]);
diff --git a/src/map/party.c b/src/map/party.c
index 1df916630..f2071de12 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -98,19 +98,17 @@ TBL_PC* party_sd_check(int party_id, int account_id, int char_id) {
int party_db_final(DBKey key, DBData *data, va_list ap) {
struct party_data *p;
- if( ( p = DB->data2ptr(data) ) ) {
- int j;
-
- if( p->instance )
+ if ((p = DB->data2ptr(data))) {
+ if (p->instance)
aFree(p->instance);
- if (p->hdata)
- {
- for (j = 0; j < p->hdatac; j++) {
- if (p->hdata[j]->flag.free) {
- aFree(p->hdata[j]->data);
+ if (p->hdata) {
+ int i;
+ for (i = 0; i < p->hdatac; i++) {
+ if (p->hdata[i]->flag.free) {
+ aFree(p->hdata[i]->data);
}
- aFree(p->hdata[j]);
+ aFree(p->hdata[i]);
}
aFree(p->hdata);
}
@@ -245,31 +243,32 @@ int party_recv_info(struct party* sp, int char_id)
int removed_count = 0;
int added[MAX_PARTY];// member_id in new data
int added_count = 0;
- int i,j;
+ int j;
int member_id;
nullpo_ret(sp);
p = (struct party_data*)idb_get(party->db, sp->party_id);
if( p != NULL ) {// diff members
- for( member_id = 0; member_id < MAX_PARTY; ++member_id ) {
+ int i;
+ for (member_id = 0; member_id < MAX_PARTY; ++member_id) {
member = &p->party.member[member_id];
- if( member->char_id == 0 )
+ if (member->char_id == 0)
continue;// empty
ARR_FIND(0, MAX_PARTY, i,
sp->member[i].account_id == member->account_id &&
sp->member[i].char_id == member->char_id);
- if( i == MAX_PARTY )
+ if (i == MAX_PARTY)
removed[removed_count++] = member_id;
}
- for( member_id = 0; member_id < MAX_PARTY; ++member_id ) {
+ for (member_id = 0; member_id < MAX_PARTY; ++member_id) {
member = &sp->member[member_id];
- if( member->char_id == 0 )
+ if (member->char_id == 0)
continue;// empty
ARR_FIND(0, MAX_PARTY, i,
p->party.member[i].account_id == member->account_id &&
p->party.member[i].char_id == member->char_id);
- if( i == MAX_PARTY )
+ if (i == MAX_PARTY)
added[added_count++] = member_id;
}
} else {
diff --git a/src/map/pc.c b/src/map/pc.c
index b64bdea80..af630a5c6 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -273,7 +273,7 @@ int pc_check_banding( struct block_list *bl, va_list ap ) {
int pc_banding(struct map_session_data *sd, uint16 skill_lv) {
int c;
int b_sd[MAX_PARTY]; // In case of a full Royal Guard party.
- int i, j, hp, extra_hp = 0, tmp_qty = 0, tmp_hp;
+ int i, j, hp, extra_hp = 0, tmp_qty = 0;
struct map_session_data *bsd;
struct status_change *sc;
int range = skill->get_splash(LG_BANDING,skill_lv);
@@ -309,10 +309,10 @@ int pc_banding(struct map_session_data *sd, uint16 skill_lv) {
hp = hp / i;
// If a Royal Guard have full HP, give more HP to others that haven't full HP.
- for( j = 0; j < i; j++ ) {
+ for (j = 0; j < i; j++) {
+ int tmp_hp;
bsd = map->id2sd(b_sd[j]);
- if( bsd != NULL && (tmp_hp = hp - status_get_max_hp(&bsd->bl)) > 0 )
- {
+ if (bsd != NULL && (tmp_hp = hp - status_get_max_hp(&bsd->bl)) > 0) {
extra_hp += tmp_hp;
tmp_qty++;
}
@@ -664,12 +664,12 @@ int pc_equippoint(struct map_session_data *sd,int n)
int pc_setinventorydata(struct map_session_data *sd)
{
- int i,id;
+ int i;
nullpo_ret(sd);
- for(i=0;i<MAX_INVENTORY;i++) {
- id = sd->status.inventory[i].nameid;
+ for (i = 0; i < MAX_INVENTORY; i++) {
+ int id = sd->status.inventory[i].nameid;
sd->inventory_data[i] = id?itemdb->search(id):NULL;
}
return 0;
@@ -760,11 +760,10 @@ int pc_setequipindex(struct map_session_data *sd)
bool pc_isequipped(struct map_session_data *sd, int nameid)
{
- int i, j, index;
+ int i, j;
- for( i = 0; i < EQI_MAX; i++ )
- {
- index = sd->equip_index[i];
+ for (i = 0; i < EQI_MAX; i++) {
+ int index = sd->equip_index[i];
if( index < 0 ) continue;
if( i == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index ) continue;
@@ -1241,7 +1240,7 @@ int pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl)
*------------------------------------------*/
int pc_reg_received(struct map_session_data *sd)
{
- int i,j, idx = 0;
+ int i, idx = 0;
sd->vars_ok = true;
@@ -1263,8 +1262,10 @@ int pc_reg_received(struct map_session_data *sd)
}
//SG map and mob read [Komurka]
- for(i=0;i<MAX_PC_FEELHATE;i++) { //for now - someone need to make reading from txt/sql
- if ((j = pc_readglobalreg(sd,script->add_str(pc->sg_info[i].feel_var)))!=0) {
+ for (i = 0; i < MAX_PC_FEELHATE; i++) {
+ //for now - someone need to make reading from txt/sql
+ int j = pc_readglobalreg(sd,script->add_str(pc->sg_info[i].feel_var));
+ if (j != 0) {
sd->feel_map[i].index = j;
sd->feel_map[i].m = map->mapindex2mapid(j);
} else {
@@ -1355,12 +1356,13 @@ int pc_reg_received(struct map_session_data *sd)
}
int pc_calc_skillpoint(struct map_session_data* sd) {
- int i,skill_lv,inf2,skill_point=0;
+ int i,inf2,skill_point=0;
nullpo_ret(sd);
- for(i=1;i<MAX_SKILL;i++){
- if( (skill_lv = pc->checkskill2(sd,i)) > 0) {
+ for (i = 1; i < MAX_SKILL; i++) {
+ int skill_lv = pc->checkskill2(sd,i);
+ if (skill_lv > 0) {
inf2 = skill->db[i].inf2;
if((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
!(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL|INF2_GUILD_SKILL)) //Do not count wedding/link skills. [Skotlex]
@@ -1570,22 +1572,23 @@ void pc_check_skilltree(struct map_session_data *sd, int skill_id)
c = pc->class2idx(c);
do {
flag = 0;
- for( i = 0; i < MAX_SKILL_TREE && (id=pc->skill_tree[c][i].id)>0; i++ ) {
- int j, f = 1, k, idx = pc->skill_tree[c][i].idx;
+ for (i = 0; i < MAX_SKILL_TREE && (id=pc->skill_tree[c][i].id)>0; i++) {
+ int j, f = 1, idx = pc->skill_tree[c][i].idx;
if( sd->status.skill[idx].id ) //Already learned
continue;
- for( j = 0; j < MAX_PC_SKILL_REQUIRE; j++ ) {
- if( (k = pc->skill_tree[c][i].need[j].id) ) {
+ for (j = 0; j < MAX_PC_SKILL_REQUIRE; j++) {
+ int k = pc->skill_tree[c][i].need[j].id;
+ if (k) {
int idx2 = pc->skill_tree[c][i].need[j].idx;
- if( sd->status.skill[idx2].id == 0 || sd->status.skill[idx2].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[idx2].flag == SKILL_FLAG_PLAGIARIZED )
+ if (sd->status.skill[idx2].id == 0 || sd->status.skill[idx2].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[idx2].flag == SKILL_FLAG_PLAGIARIZED)
k = 0; //Not learned.
- else if( sd->status.skill[idx2].flag >= SKILL_FLAG_REPLACED_LV_0) //Real lerned level
+ else if (sd->status.skill[idx2].flag >= SKILL_FLAG_REPLACED_LV_0) //Real lerned level
k = sd->status.skill[idx2].flag - SKILL_FLAG_REPLACED_LV_0;
else
k = pc->checkskill2(sd,idx2);
- if( k < pc->skill_tree[c][i].need[j].lv ) {
+ if (k < pc->skill_tree[c][i].need[j].lv) {
f = 0;
break;
}
@@ -3475,12 +3478,12 @@ int pc_bonus4(struct map_session_data *sd,int type,int type2,int type3,int type4
switch(type) {
case SP_AUTOSPELL:
if(sd->state.lr_flag != 2)
- pc->bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, status->current_equip_card_id);
+ pc->bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1) ? type2 : -type2, (val&2) ? -type3 : type3, type4, 0, status->current_equip_card_id);
break;
case SP_AUTOSPELL_WHENHIT:
if(sd->state.lr_flag != 2)
- pc->bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, BF_NORMAL|BF_SKILL, status->current_equip_card_id);
+ pc->bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1) ? type2 : -type2, (val&2) ? -type3 : type3, type4, BF_NORMAL|BF_SKILL, status->current_equip_card_id);
break;
case SP_AUTOSPELL_ONSKILL:
@@ -3539,17 +3542,17 @@ int pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type4
switch(type){
case SP_AUTOSPELL:
if(sd->state.lr_flag != 2)
- pc->bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, status->current_equip_card_id);
+ pc->bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1) ? type2 : -type2, (val&2) ? -type3 : type3, type4, type5, status->current_equip_card_id);
break;
case SP_AUTOSPELL_WHENHIT:
if(sd->state.lr_flag != 2)
- pc->bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, status->current_equip_card_id);
+ pc->bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1) ? type2 : -type2, (val&2) ? -type3 : type3, type4, type5, status->current_equip_card_id);
break;
case SP_AUTOSPELL_ONSKILL:
if(sd->state.lr_flag != 2)
- pc->bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, (val&1?-type3:type3), (val&2?-type4:type4), type5, status->current_equip_card_id);
+ pc->bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, (val&1) ? -type3 : type3, (val&2) ? -type4 : type4, type5, status->current_equip_card_id);
break;
default:
@@ -4165,7 +4168,6 @@ int pc_takeitem(struct map_session_data *sd,struct flooritem_data *fitem)
{
int flag=0;
int64 tick = timer->gettick();
- struct map_session_data *first_sd = NULL,*second_sd = NULL,*third_sd = NULL;
struct party_data *p=NULL;
nullpo_ret(sd);
@@ -4180,29 +4182,25 @@ int pc_takeitem(struct map_session_data *sd,struct flooritem_data *fitem)
if (sd->status.party_id)
p = party->search(sd->status.party_id);
- if(fitem->first_get_charid > 0 && fitem->first_get_charid != sd->status.char_id) {
- first_sd = map->charid2sd(fitem->first_get_charid);
- if(DIFF_TICK(tick,fitem->first_get_tick) < 0) {
+ if (fitem->first_get_charid > 0 && fitem->first_get_charid != sd->status.char_id) {
+ struct map_session_data *first_sd = map->charid2sd(fitem->first_get_charid);
+ if (DIFF_TICK(tick,fitem->first_get_tick) < 0) {
if (!(p && p->party.item&1 &&
first_sd && first_sd->status.party_id == sd->status.party_id
))
return 0;
- }
- else
- if(fitem->second_get_charid > 0 && fitem->second_get_charid != sd->status.char_id) {
- second_sd = map->charid2sd(fitem->second_get_charid);
- if(DIFF_TICK(tick, fitem->second_get_tick) < 0) {
- if(!(p && p->party.item&1 &&
+ } else if (fitem->second_get_charid > 0 && fitem->second_get_charid != sd->status.char_id) {
+ struct map_session_data *second_sd = map->charid2sd(fitem->second_get_charid);
+ if (DIFF_TICK(tick, fitem->second_get_tick) < 0) {
+ if (!(p && p->party.item&1 &&
((first_sd && first_sd->status.party_id == sd->status.party_id) ||
(second_sd && second_sd->status.party_id == sd->status.party_id))
))
return 0;
- }
- else
- if(fitem->third_get_charid > 0 && fitem->third_get_charid != sd->status.char_id) {
- third_sd = map->charid2sd(fitem->third_get_charid);
- if(DIFF_TICK(tick,fitem->third_get_tick) < 0) {
- if(!(p && p->party.item&1 &&
+ } else if (fitem->third_get_charid > 0 && fitem->third_get_charid != sd->status.char_id) {
+ struct map_session_data *third_sd = map->charid2sd(fitem->third_get_charid);
+ if (DIFF_TICK(tick,fitem->third_get_tick) < 0) {
+ if (!(p && p->party.item&1 &&
((first_sd && first_sd->status.party_id == sd->status.party_id) ||
(second_sd && second_sd->status.party_id == sd->status.party_id) ||
(third_sd && third_sd->status.party_id == sd->status.party_id))
@@ -4383,7 +4381,7 @@ int pc_isUseitem(struct map_session_data *sd,int n)
//Not equipable by class. [Skotlex]
if (!(
(1<<(sd->class_&MAPID_BASEMASK)) &
- (item->class_base[sd->class_&JOBL_2_1?1:(sd->class_&JOBL_2_2?2:0)])
+ (item->class_base[(sd->class_&JOBL_2_1) ? 1 : ((sd->class_&JOBL_2_2) ? 2 : 0)])
))
return 0;
@@ -6013,7 +6011,7 @@ void pc_calcexp(struct map_session_data *sd, unsigned int *base_exp, unsigned in
if (sd->expaddrace[st->race])
bonus += sd->expaddrace[st->race];
- bonus += sd->expaddrace[st->mode&MD_BOSS?RC_BOSS:RC_NONBOSS];
+ bonus += sd->expaddrace[(st->mode&MD_BOSS) ? RC_BOSS : RC_NONBOSS];
if (battle_config.pk_mode
&& (int)(status->get_lv(src) - sd->status.base_level) >= 20)
@@ -6453,7 +6451,7 @@ int pc_skillup(struct map_session_data *sd,uint16 skill_id) {
*------------------------------------------*/
int pc_allskillup(struct map_session_data *sd)
{
- int i,id;
+ int i;
nullpo_ret(sd);
@@ -6481,10 +6479,10 @@ int pc_allskillup(struct map_session_data *sd)
}
}
} else {
- int inf2;
- for(i=0;i < MAX_SKILL_TREE && (id=pc->skill_tree[pc->class2idx(sd->status.class_)][i].id)>0;i++){
+ int id;
+ for (i = 0; i < MAX_SKILL_TREE && (id=pc->skill_tree[pc->class2idx(sd->status.class_)][i].id) > 0; i++) {
int idx = pc->skill_tree[pc->class2idx(sd->status.class_)][i].idx;
- inf2 = skill->db[idx].inf2;
+ int inf2 = skill->db[idx].inf2;
if (
(inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) ||
@@ -6607,7 +6605,7 @@ int pc_resetstate(struct map_session_data* sd)
return 0;
}
- sd->status.status_point = pc->statp[sd->status.base_level] + ( sd->class_&JOBL_UPPER ? 52 : 0 ); // extra 52+48=100 stat points
+ sd->status.status_point = pc->statp[sd->status.base_level] + ((sd->class_&JOBL_UPPER) ? 52 : 0); // extra 52+48=100 stat points
}
else
{
@@ -6664,7 +6662,7 @@ int pc_resetstate(struct map_session_data* sd)
*------------------------------------------*/
int pc_resetskill(struct map_session_data* sd, int flag)
{
- int i, lv, inf2, skill_point=0;
+ int i, inf2, skill_point=0;
nullpo_ret(sd);
if( flag&4 && (sd->class_&MAPID_UPPERMASK) != MAPID_BARDDANCER )
@@ -6708,8 +6706,10 @@ int pc_resetskill(struct map_session_data* sd, int flag)
}
for( i = 1; i < MAX_SKILL; i++ ) {
+ // FIXME: We're looping on i = [1..MAX_SKILL-1] (which makes sense as index for sd->status.skill[]) but then we're using the
+ // same i to access skill->db[], and especially to check skill_ischangesex(). This is wrong.
uint16 skill_id = 0;
- lv = sd->status.skill[i].lv;
+ int lv = sd->status.skill[i].lv;
if (lv < 1) continue;
inf2 = skill->db[i].inf2;
@@ -7311,7 +7311,7 @@ int pc_readparam(struct map_session_data* sd,int type)
case SP_JOBLEVEL: val = sd->status.job_level; break;
case SP_CLASS: val = sd->status.class_; break;
case SP_BASEJOB: val = pc->mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex); break; //Base job, extracting upper type.
- case SP_UPPER: val = sd->class_&JOBL_UPPER?1:(sd->class_&JOBL_BABY?2:0); break;
+ case SP_UPPER: val = (sd->class_&JOBL_UPPER) ? 1 : ((sd->class_&JOBL_BABY) ? 2 : 0); break;
case SP_BASECLASS: val = pc->mapid2jobid(sd->class_&MAPID_BASEMASK, sd->status.sex); break; //Extract base class tree. [Skotlex]
case SP_SEX: val = sd->status.sex; break;
case SP_WEIGHT: val = sd->weight; break;
@@ -7452,8 +7452,6 @@ int pc_readparam(struct map_session_data* sd,int type)
*------------------------------------------*/
int pc_setparam(struct map_session_data *sd,int type,int val)
{
- int i = 0;
-
nullpo_ret(sd);
switch(type){
@@ -7461,7 +7459,7 @@ int pc_setparam(struct map_session_data *sd,int type,int val)
if ((unsigned int)val > pc->maxbaselv(sd)) //Capping to max
val = pc->maxbaselv(sd);
if ((unsigned int)val > sd->status.base_level) {
- int stat=0;
+ int stat = 0, i;
for (i = 0; i < (int)((unsigned int)val - sd->status.base_level); i++)
stat += pc->gets_status_point(sd->status.base_level + i);
sd->status.status_point += stat;
@@ -8464,7 +8462,6 @@ char* pc_readregistry_str(struct map_session_data *sd, int64 reg) {
**/
int pc_setregistry(struct map_session_data *sd, int64 reg, int val) {
struct script_reg_num *p = NULL;
- int i;
const char *regname = script->get_str( script_getvarid(reg) );
unsigned int index = script_getvaridx(reg);
@@ -8472,7 +8469,7 @@ int pc_setregistry(struct map_session_data *sd, int64 reg, int val) {
switch( regname[0] ) {
default: //Char reg
if( !strcmp(regname,"PC_DIE_COUNTER") && sd->die_counter != val ) {
- i = (!sd->die_counter && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE);
+ int i = (!sd->die_counter && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE);
sd->die_counter = val;
if( i )
status_calc_pc(sd,SCO_NONE); // Lost the bonus.
@@ -9267,27 +9264,28 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) {
*------------------------------------------*/
int pc_checkitem(struct map_session_data *sd)
{
- int i, id, calc_flag = 0;
+ int i, calc_flag = 0;
nullpo_ret(sd);
- if( sd->state.vending ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam)
+ if (sd->state.vending) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam)
return 0;
- if( sd->state.itemcheck ) { // check for invalid(ated) items
- for( i = 0; i < MAX_INVENTORY; i++ ) {
+ if (sd->state.itemcheck) { // check for invalid(ated) items
+ int id;
+ for (i = 0; i < MAX_INVENTORY; i++) {
id = sd->status.inventory[i].nameid;
if (!id)
continue;
- if( !itemdb_available(id) ) {
+ if (!itemdb_available(id)) {
ShowWarning("Removed invalid/disabled item id %d from inventory (amount=%d, char_id=%d).\n", id, sd->status.inventory[i].amount, sd->status.char_id);
pc->delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_OTHER);
continue;
}
- if ( !sd->status.inventory[i].unique_id && !itemdb->isstackable(id) )
+ if (!sd->status.inventory[i].unique_id && !itemdb->isstackable(id))
sd->status.inventory[i].unique_id = itemdb->unique_id(sd);
}
@@ -9959,8 +9957,8 @@ int pc_split_atoui(char* str, unsigned int* val, char sep, int max)
{
static int warning=0;
int i,j;
- double f;
for (i=0; i<max; i++) {
+ double f;
if (!str) break;
f = atof(str);
if (f < 0)
@@ -10121,8 +10119,8 @@ void pc_read_skill_tree(void) {
jnamelen = ARRAYLENGTH(jnames);
- while( (skt = libconfig->setting_get_elem(skill_tree_conf.root,i++)) ) {
- int k, idx;
+ while ((skt = libconfig->setting_get_elem(skill_tree_conf.root,i++))) {
+ int k;
const char *name = config_setting_name(skt);
ARR_FIND(0, jnamelen, k, strcmpi(jnames[k].name,name) == 0 );
@@ -10135,15 +10133,14 @@ void pc_read_skill_tree(void) {
if( ( skills = libconfig->setting_get_member(skt,"skills") ) ) {
int c = 0;
+ int idx = pc->class2idx(jnames[k].id);
- idx = pc->class2idx(jnames[k].id);
-
- while( ( sk = libconfig->setting_get_elem(skills,c++) ) ) {
+ while ((sk = libconfig->setting_get_elem(skills,c++))) {
const char *sk_name = config_setting_name(sk);
int skill_id;
if( ( skill_id = skill->name2id(sk_name) ) ) {
- int skidx, offset = 0, h = 0, rlen = 0, rskid = 0;
+ int skidx, offset = 0, h = 0, rlen = 0;
ARR_FIND( 0, MAX_SKILL_TREE, skidx, pc->skill_tree[idx][skidx].id == 0 || pc->skill_tree[idx][skidx].id == skill_id );
if (skidx == MAX_SKILL_TREE) {
@@ -10169,9 +10166,10 @@ void pc_read_skill_tree(void) {
pc->skill_tree[idx][skidx].joblv = 0;
}
- for( h = offset; h < rlen && h < MAX_PC_SKILL_REQUIRE; h++ ) {
+ for (h = offset; h < rlen && h < MAX_PC_SKILL_REQUIRE; h++) {
config_setting_t *rsk = libconfig->setting_get_elem(sk,h);
- if( rsk && ( rskid = skill->name2id(config_setting_name(rsk)) ) ) {
+ int rskid;
+ if (rsk && ( rskid = skill->name2id(config_setting_name(rsk)))) {
pc->skill_tree[idx][skidx].need[h].id = rskid;
pc->skill_tree[idx][skidx].need[h].idx = skill->get_index(rskid);
pc->skill_tree[idx][skidx].need[h].lv = (unsigned char)libconfig->setting_get_int(rsk);
@@ -10191,9 +10189,8 @@ void pc_read_skill_tree(void) {
i = 0;
while( (skt = libconfig->setting_get_elem(skill_tree_conf.root,i++)) ) {
- int k, idx, v = 0;
+ int k, idx;
const char *name = config_setting_name(skt);
- const char *iname;
ARR_FIND(0, jnamelen, k, strcmpi(jnames[k].name,name) == 0 );
@@ -10205,7 +10202,9 @@ void pc_read_skill_tree(void) {
idx = pc->class2idx(jnames[k].id);
if( ( inherit = libconfig->setting_get_member(skt,"inherit") ) ) {
- while( ( iname = libconfig->setting_get_string_elem(inherit, v++) ) ) {
+ const char *iname;
+ int v = 0;
+ while ((iname = libconfig->setting_get_string_elem(inherit, v++))) {
int b = 0, a, d, f, fidx;
ARR_FIND(0, jnamelen, b, strcmpi(jnames[b].name,iname) == 0 );
@@ -10638,14 +10637,15 @@ void pc_expire_check(struct map_session_data *sd) {
/**
* Loads autotraders
***/
-void pc_autotrade_load(void) {
- struct map_session_data *sd;
+void pc_autotrade_load(void)
+{
char *data;
if (SQL_ERROR == SQL->Query(map->mysql_handle, "SELECT `account_id`,`char_id`,`sex`,`title` FROM `%s`",map->autotrade_merchants_db))
Sql_ShowDebug(map->mysql_handle);
- while( SQL_SUCCESS == SQL->NextRow(map->mysql_handle) ) {
+ while (SQL_SUCCESS == SQL->NextRow(map->mysql_handle)) {
+ struct map_session_data *sd;
int account_id, char_id;
char title[MESSAGE_SIZE];
unsigned char sex;
diff --git a/src/map/pc.h b/src/map/pc.h
index 152701119..b7839147d 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -599,7 +599,14 @@ struct map_session_data {
#define pc_isinvisible(sd) ( (sd)->sc.option&OPTION_INVISIBLE )
#define pc_is50overweight(sd) ( (sd)->weight*100 >= (sd)->max_weight*battle->bc->natural_heal_weight_rate )
#define pc_is90overweight(sd) ( (sd)->weight*10 >= (sd)->max_weight*9 )
-#define pc_maxparameter(sd) ( (((sd)->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO || ((sd)->class_&MAPID_UPPERMASK) == MAPID_REBELLION || ((sd)->class_&MAPID_THIRDMASK) == MAPID_SUPER_NOVICE_E) ? battle->bc->max_extended_parameter : (sd)->class_&JOBL_THIRD ? ((sd)->class_&JOBL_BABY ? battle->bc->max_baby_third_parameter : battle->bc->max_third_parameter) : ((sd)->class_&JOBL_BABY ? battle->bc->max_baby_parameter : battle->bc->max_parameter) )
+#define pc_maxparameter(sd) ( \
+ ( ((sd)->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO \
+ || ((sd)->class_&MAPID_UPPERMASK) == MAPID_REBELLION \
+ || ((sd)->class_&MAPID_THIRDMASK) == MAPID_SUPER_NOVICE_E \
+ ) ? battle->bc->max_extended_parameter : ((sd)->class_&JOBL_THIRD) ? \
+ (((sd)->class_&JOBL_BABY) ? battle->bc->max_baby_third_parameter : battle->bc->max_third_parameter ) : \
+ (((sd)->class_&JOBL_BABY) ? battle->bc->max_baby_parameter : battle->bc->max_parameter) \
+ )
/// Generic check for mounts
#define pc_hasmount(sd) ( (sd)->sc.option&(OPTION_RIDING|OPTION_WUGRIDER|OPTION_DRAGON|OPTION_MADOGEAR) )
/// Knight classes Peco / Gryphon
diff --git a/src/map/pet.c b/src/map/pet.c
index 3d155b179..f78a4a488 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -120,7 +120,7 @@ int pet_attackskill(struct pet_data *pd, int target_id) {
if (inf & INF_GROUND_SKILL)
unit->skilluse_pos(&pd->bl, bl->x, bl->y, pd->a_skill->id, pd->a_skill->lv);
else //Offensive self skill? Could be stuff like GX.
- unit->skilluse_id(&pd->bl,(inf&INF_SELF_SKILL?pd->bl.id:bl->id), pd->a_skill->id, pd->a_skill->lv);
+ unit->skilluse_id(&pd->bl,(inf&INF_SELF_SKILL) ? pd->bl.id : bl->id, pd->a_skill->id, pd->a_skill->lv);
return 1; //Skill invoked.
}
return 0;
@@ -786,14 +786,15 @@ int pet_randomwalk(struct pet_data *pd, int64 tick) {
Assert((pd->msd == 0) || (pd->msd->pd == pd));
- if(DIFF_TICK(pd->next_walktime,tick) < 0 && unit->can_move(&pd->bl)) {
+ if (DIFF_TICK(pd->next_walktime,tick) < 0 && unit->can_move(&pd->bl)) {
const int retrycount=20;
- int i,x,y,c,d=12-pd->move_fail_count;
- if(d<5) d=5;
- for(i=0;i<retrycount;i++){
+ int i,c,d=12-pd->move_fail_count;
+ if (d < 5)
+ d=5;
+ for (i = 0; i < retrycount; i++) {
int r=rnd();
- x=pd->bl.x+r%(d*2+1)-d;
- y=pd->bl.y+r/(d*2+1)%(d*2+1)-d;
+ int x=pd->bl.x+r%(d*2+1)-d;
+ int y=pd->bl.y+r/(d*2+1)%(d*2+1)-d;
if(map->getcell(pd->bl.m,x,y,CELL_CHKPASS) && unit->walktoxy(&pd->bl,x,y,0)) {
pd->move_fail_count=0;
break;
@@ -976,10 +977,11 @@ int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
int pet_delay_item_drop(int tid, int64 tick, int id, intptr_t data) {
struct item_drop_list *list;
- struct item_drop *ditem, *ditem_prev;
+ struct item_drop *ditem;
list=(struct item_drop_list *)data;
ditem = list->item;
while (ditem) {
+ struct item_drop *ditem_prev;
map->addflooritem(&ditem->item_data,ditem->item_data.amount,
list->m,list->x,list->y,
list->first_charid,list->second_charid,list->third_charid,0);
@@ -996,7 +998,6 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
int i,flag=0;
struct item_drop_list *dlist;
struct item_drop *ditem;
- struct item *it;
if(!pd || !pd->loot || !pd->loot->count)
return 0;
dlist = ers_alloc(pet->item_drop_list_ers, struct item_drop_list);
@@ -1008,18 +1009,17 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
dlist->third_charid = 0;
dlist->item = NULL;
- for(i=0;i<pd->loot->count;i++) {
- it = &pd->loot->item[i];
- if(sd){
- if((flag = pc->additem(sd,it,it->amount,LOG_TYPE_PICKDROP_PLAYER))){
+ for (i = 0; i < pd->loot->count; i++) {
+ struct item *it = &pd->loot->item[i];
+ if (sd) {
+ if ((flag = pc->additem(sd,it,it->amount,LOG_TYPE_PICKDROP_PLAYER))) {
clif->additem(sd,0,0,flag);
ditem = ers_alloc(pet->item_drop_ers, struct item_drop);
memcpy(&ditem->item_data, it, sizeof(struct item));
ditem->next = dlist->item;
dlist->item = ditem;
}
- }
- else {
+ } else {
ditem = ers_alloc(pet->item_drop_ers, struct item_drop);
memcpy(&ditem->item_data, it, sizeof(struct item));
ditem->next = dlist->item;
@@ -1163,7 +1163,6 @@ int pet_skill_support_timer(int tid, int64 tick, int id, intptr_t data) {
int read_petdb()
{
char* filename[] = {"pet_db.txt","pet_db2.txt"};
- FILE *fp;
int nameid,i,j,k;
// Remove any previous scripts in case reloaddb was invoked.
@@ -1188,6 +1187,7 @@ int read_petdb()
for( i = 0; i < ARRAYLENGTH(filename); i++ ) {
char line[1024];
int lines, entries;
+ FILE *fp;
sprintf(line, "%s/%s", map->db_path, filename[i]);
fp=fopen(line,"r");
diff --git a/src/map/script.c b/src/map/script.c
index 828e02ab1..b098ed899 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -245,35 +245,32 @@ void script_reportdata(struct script_data* data)
/// Reports on the console information about the current built-in function.
void script_reportfunc(struct script_state* st)
{
- int i, params, id;
+ int params, id;
struct script_data* data;
- if( !script_hasdata(st,0) )
- {// no stack
+ if (!script_hasdata(st,0)) {
+ // no stack
return;
}
data = script_getdata(st,0);
- if( !data_isreference(data) || script->str_data[reference_getid(data)].type != C_FUNC )
- {// script currently not executing a built-in function or corrupt stack
+ if (!data_isreference(data) || script->str_data[reference_getid(data)].type != C_FUNC) {
+ // script currently not executing a built-in function or corrupt stack
return;
}
id = reference_getid(data);
params = script_lastdata(st)-1;
- if( params > 0 )
- {
+ if (params > 0) {
+ int i;
ShowDebug("Function: %s (%d parameter%s):\n", script->get_str(id), params, ( params == 1 ) ? "" : "s");
- for( i = 2; i <= script_lastdata(st); i++ )
- {
+ for (i = 2; i <= script_lastdata(st); i++) {
script->reportdata(script_getdata(st,i));
}
- }
- else
- {
+ } else {
ShowDebug("Function: %s (no parameters)\n", script->get_str(id));
}
}
@@ -427,21 +424,24 @@ void script_local_casecheck_clear(void) {
script_casecheck_clear_sub(&script->local_casecheck);
}
-const char *script_casecheck_add_str_sub(struct casecheck_data *ccd, const char *p) {
+const char *script_casecheck_add_str_sub(struct casecheck_data *ccd, const char *p)
+{
#ifdef ENABLE_CASE_CHECK
- int len, i;
+ int len;
int h = script->calc_hash_ci(p);
- if( ccd->str_hash[h] == 0 ) { //empty bucket, add new node here
+ if (ccd->str_hash[h] == 0) {
+ //empty bucket, add new node here
ccd->str_hash[h] = ccd->str_num;
} else {
- const char *s = NULL;
- for( i = ccd->str_hash[h]; ; i = ccd->str_data[i].next ) {
+ int i;
+ for (i = ccd->str_hash[h]; ; i = ccd->str_data[i].next) {
+ const char *s = NULL;
Assert( i >= 0 && i < ccd->str_size );
s = ccd->str_buf+ccd->str_data[i].str;
- if( strcasecmp(s,p) == 0 ) {
+ if (strcasecmp(s,p) == 0) {
return s; // string already in list
}
- if( ccd->str_data[i].next == 0 )
+ if (ccd->str_data[i].next == 0)
break; // reached the end
}
@@ -492,15 +492,18 @@ const char *script_local_casecheck_add_str(const char *p) {
/// If an identical string is already present, returns its id instead.
int script_add_str(const char* p)
{
- int i, len, h = script->calc_hash(p);
+ int len, h = script->calc_hash(p);
#ifdef ENABLE_CASE_CHECK
const char *existingentry = NULL;
#endif // ENABLE_CASE_CHECK
- if( script->str_hash[h] == 0 ) {// empty bucket, add new node here
+ if (script->str_hash[h] == 0) {
+ // empty bucket, add new node here
script->str_hash[h] = script->str_num;
- } else {// scan for end of list, or occurence of identical string
- for( i = script->str_hash[h]; ; i = script->str_data[i].next ) {
+ } else {
+ // scan for end of list, or occurence of identical string
+ int i;
+ for (i = script->str_hash[h]; ; i = script->str_data[i].next) {
if( strcmp(script->get_str(i),p) == 0 ) {
return i; // string already in list
}
@@ -513,9 +516,10 @@ int script_add_str(const char* p)
}
#ifdef ENABLE_CASE_CHECK
- if( (strncmp(p, ".@", 2) == 0) ) // Local scope vars are checked separately to decrease false positives
+ if( (strncmp(p, ".@", 2) == 0) ) {
+ // Local scope vars are checked separately to decrease false positives
existingentry = script->local_casecheck.add_str(p);
- else {
+ } else {
existingentry = script->global_casecheck.add_str(p);
if( existingentry ) {
if( strcasecmp(p, "disguise") == 0 || strcasecmp(p, "Poison_Spore") == 0
@@ -646,7 +650,7 @@ void add_scriptl(int l)
*------------------------------------------*/
void set_label(int l,int pos, const char* script_pos)
{
- int i,next;
+ int i;
if(script->str_data[l].type==C_INT || script->str_data[l].type==C_PARAM || script->str_data[l].type==C_FUNC) {
//Prevent overwriting constants values, parameters and built-in functions [Skotlex]
@@ -659,11 +663,11 @@ void set_label(int l,int pos, const char* script_pos)
}
script->str_data[l].type=(script->str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
script->str_data[l].label=pos;
- for(i=script->str_data[l].backpatch;i>=0 && i!=0x00ffffff;) {
- next=GETVALUE(script->buf,i);
+ for (i = script->str_data[l].backpatch; i >= 0 && i != 0x00ffffff; ) {
+ int next = GETVALUE(script->buf,i);
script->buf[i-1]=(script->str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
SETVALUE(script->buf,i,pos);
- i=next;
+ i = next;
}
}
@@ -882,10 +886,10 @@ void parse_nextline(bool first, const char* p)
* Pushes a variable into stack, processing its array index if needed.
* @see parse_variable
*/
-void parse_variable_sub_push(int word, const char *p2) {
- const char* p3 = NULL;
-
+void parse_variable_sub_push(int word, const char *p2)
+{
if( p2 ) {
+ const char* p3 = NULL;
// process the variable index
// push the getelementofarray method into the stack
@@ -913,8 +917,9 @@ void parse_variable_sub_push(int word, const char *p2) {
/// Parse a variable assignment using the direct equals operator
/// @param p script position where the function should run from
/// @return NULL if not a variable assignment, the new position otherwise
-const char* parse_variable(const char* p) {
- int i, j, word;
+const char* parse_variable(const char* p)
+{
+ int word;
c_op type = C_NOP;
const char *p2 = NULL;
const char *var = p;
@@ -934,9 +939,10 @@ const char* parse_variable(const char* p) {
return NULL;
}
- if( *p == '[' ) {
+ if (*p == '[') {
+ int i, j;
// array variable so process the array as appropriate
- for( p2 = p, i = 0, j = 1; p; ++ i ) {
+ for (p2 = p, i = 0, j = 1; p; ++ i) {
if( *p ++ == ']' && --(j) == 0 ) break;
if( *p == '[' ) ++ j;
}
@@ -1086,14 +1092,15 @@ bool is_number(const char *p) {
/*==========================================
* Analysis section
*------------------------------------------*/
-const char* parse_simpleexpr(const char *p) {
- int i;
+const char* parse_simpleexpr(const char *p)
+{
p=script->skip_space(p);
if(*p==';' || *p==',')
disp_error_message("parse_simpleexpr: unexpected end of expression",p);
if(*p=='(') {
- if( (i=script->syntax.curly_count-1) >= 0 && script->syntax.curly[i].type == TYPE_ARGLIST )
+ int i = script->syntax.curly_count-1;
+ if (i >= 0 && script->syntax.curly[i].type == TYPE_ARGLIST)
++script->syntax.curly[i].count;
p=script->parse_subexpr(p+1,-1);
p=script->skip_space(p);
@@ -1199,14 +1206,14 @@ const char* parse_simpleexpr(const char *p) {
/*==========================================
* Analysis of the expression
*------------------------------------------*/
-const char* script_parse_subexpr(const char* p,int limit) {
+const char* script_parse_subexpr(const char* p,int limit)
+{
int op,opl,len;
- const char* tmpp;
p=script->skip_space(p);
if( *p == '-' ) {
- tmpp = script->skip_space(p+1);
+ const char *tmpp = script->skip_space(p+1);
if( *tmpp == ';' || *tmpp == ',' ) {
script->addl(LABEL_NEXTLINE);
p++;
@@ -2342,19 +2349,18 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
RECREATE(script->buf,unsigned char,script->pos);
// default unknown references to variables
- for(i=LABEL_START;i<script->str_num;i++) {
- if(script->str_data[i].type==C_NOP) {
- int j,next;
+ for (i = LABEL_START; i < script->str_num; i++) {
+ if (script->str_data[i].type == C_NOP) {
+ int j;
script->str_data[i].type=C_NAME;
script->str_data[i].label=i;
- for(j=script->str_data[i].backpatch;j>=0 && j!=0x00ffffff;) {
- next=GETVALUE(script->buf,j);
+ for (j = script->str_data[i].backpatch; j >= 0 && j != 0x00ffffff; ) {
+ int next = GETVALUE(script->buf,j);
SETVALUE(script->buf,j,i);
- j=next;
+ j = next;
}
- }
- else if( script->str_data[i].type == C_USERFUNC )
- {// 'function name;' without follow-up code
+ } else if(script->str_data[i].type == C_USERFUNC) {
+ // 'function name;' without follow-up code
ShowError("parse_script: function '%s' declared but not defined.\n", script->str_buf+script->str_data[i].str);
if (retval) *retval = EXIT_FAILURE;
unresolved_names = true;
@@ -2596,12 +2602,12 @@ void script_array_ensure_zero(struct script_state *st, struct map_session_data *
const char *name = script->get_str(script_getvarid(uid));
// is here st can be null pointer and st->rid is wrong?
struct reg_db *src = script->array_src(st, sd ? sd : st->rid ? map->id2sd(st->rid) : NULL, name, ref);
- struct script_array *sa = NULL;
bool insert = false;
- if( sd && !st ) /* when sd comes, st isn't available */
+ if (sd && !st) {
+ /* when sd comes, st isn't available */
insert = true;
- else {
+ } else {
if( is_string_variable(name) ) {
char* str = (char*)script->get_val2(st, uid, ref);
if( str && *str )
@@ -2615,8 +2621,9 @@ void script_array_ensure_zero(struct script_state *st, struct map_session_data *
}
}
- if( src && src->arrays ) {
- if( (sa = idb_get(src->arrays, script_getvarid(uid)) ) ) {
+ if (src && src->arrays) {
+ struct script_array *sa = idb_get(src->arrays, script_getvarid(uid));
+ if (sa) {
unsigned int i;
ARR_FIND(0, sa->size, i, sa->members[i] == 0);
@@ -2627,7 +2634,7 @@ void script_array_ensure_zero(struct script_state *st, struct map_session_data *
}
script->array_add_member(sa,0);
- } else if( insert ) {
+ } else if (insert) {
script->array_update(src,reference_uid(script_getvarid(uid), 0),false);
}
}
@@ -3669,75 +3676,75 @@ void op_1(struct script_state* st, int op)
/// @param func Built-in function for which the arguments are intended.
void script_check_buildin_argtype(struct script_state* st, int func)
{
- char type;
int idx, invalid = 0;
char* sf = script->buildin[script->str_data[func].val];
- for( idx = 2; script_hasdata(st, idx); idx++ ) {
+ for (idx = 2; script_hasdata(st, idx); idx++) {
struct script_data* data = script_getdata(st, idx);
+ char type = sf[idx-2];
+ const char* name = NULL;
- type = sf[idx-2];
-
- if( type == '?' || type == '*' ) {// optional argument or unknown number of optional parameters ( no types are after this )
+ if (type == '?' || type == '*') {
+ // optional argument or unknown number of optional parameters ( no types are after this )
break;
- } else if( type == 0 ) {// more arguments than necessary ( should not happen, as it is checked before )
+ }
+ if (type == 0) {
+ // more arguments than necessary ( should not happen, as it is checked before )
ShowWarning("Found more arguments than necessary. unexpected arg type %s\n",script->op2name(data->type));
invalid++;
break;
- } else {
- const char* name = NULL;
+ }
- if( data_isreference(data) )
- {// get name for variables to determine the type they refer to
- name = reference_getname(data);
- }
+ if (data_isreference(data)) {
+ // get name for variables to determine the type they refer to
+ name = reference_getname(data);
+ }
- switch( type ) {
- case 'v':
- if( !data_isstring(data) && !data_isint(data) && !data_isreference(data) )
- {// variant
- ShowWarning("Unexpected type for argument %d. Expected string, number or variable.\n", idx-1);
- script->reportdata(data);
- invalid++;
- }
- break;
- case 's':
- if( !data_isstring(data) && !( data_isreference(data) && is_string_variable(name) ) )
- {// string
- ShowWarning("Unexpected type for argument %d. Expected string.\n", idx-1);
- script->reportdata(data);
- invalid++;
- }
- break;
- case 'i':
- if( !data_isint(data) && !( data_isreference(data) && ( reference_toparam(data) || reference_toconstant(data) || !is_string_variable(name) ) ) )
- {// int ( params and constants are always int )
- ShowWarning("Unexpected type for argument %d. Expected number.\n", idx-1);
- script->reportdata(data);
- invalid++;
- }
- break;
- case 'r':
- if( !data_isreference(data) || reference_toconstant(data) )
- {// variables
- ShowWarning("Unexpected type for argument %d. Expected variable, got %s.\n", idx-1,script->op2name(data->type));
- script->reportdata(data);
- invalid++;
- }
- break;
- case 'l':
- if( !data_islabel(data) && !data_isfunclabel(data) )
- {// label
- ShowWarning("Unexpected type for argument %d. Expected label, got %s\n", idx-1,script->op2name(data->type));
- script->reportdata(data);
- invalid++;
- }
- break;
- }
+ switch (type) {
+ case 'v':
+ if (!data_isstring(data) && !data_isint(data) && !data_isreference(data)) {
+ // variant
+ ShowWarning("Unexpected type for argument %d. Expected string, number or variable.\n", idx-1);
+ script->reportdata(data);
+ invalid++;
+ }
+ break;
+ case 's':
+ if (!data_isstring(data) && !(data_isreference(data) && is_string_variable(name))) {
+ // string
+ ShowWarning("Unexpected type for argument %d. Expected string.\n", idx-1);
+ script->reportdata(data);
+ invalid++;
+ }
+ break;
+ case 'i':
+ if (!data_isint(data) && !(data_isreference(data) && (reference_toparam(data) || reference_toconstant(data) || !is_string_variable(name)))) {
+ // int ( params and constants are always int )
+ ShowWarning("Unexpected type for argument %d. Expected number.\n", idx-1);
+ script->reportdata(data);
+ invalid++;
+ }
+ break;
+ case 'r':
+ if (!data_isreference(data) || reference_toconstant(data)) {
+ // variables
+ ShowWarning("Unexpected type for argument %d. Expected variable, got %s.\n", idx-1,script->op2name(data->type));
+ script->reportdata(data);
+ invalid++;
+ }
+ break;
+ case 'l':
+ if (!data_islabel(data) && !data_isfunclabel(data)) {
+ // label
+ ShowWarning("Unexpected type for argument %d. Expected label, got %s\n", idx-1,script->op2name(data->type));
+ script->reportdata(data);
+ invalid++;
+ }
+ break;
}
}
- if(invalid) {
+ if (invalid) {
ShowDebug("Function: %s\n", script->get_str(func));
script->reportsrc(st);
}
@@ -4649,13 +4656,11 @@ BUILDIN(menu)
#endif
// TODO detect multiple scripts waiting for input at the same time, and what to do when that happens
- if( sd->state.menu_or_input == 0 )
- {
+ if (sd->state.menu_or_input == 0) {
struct StringBuf buf;
- struct script_data* data;
- if( script_lastdata(st) % 2 == 0 )
- {// argument count is not even (1st argument is at index 2)
+ if (script_lastdata(st) % 2 == 0) {
+ // argument count is not even (1st argument is at index 2)
ShowError("script:menu: illegal number of arguments (%d).\n", (script_lastdata(st) - 1));
st->state = END;
return false;
@@ -4663,13 +4668,12 @@ BUILDIN(menu)
StrBuf->Init(&buf);
sd->npc_menu = 0;
- for( i = 2; i < script_lastdata(st); i += 2 )
- {
+ for (i = 2; i < script_lastdata(st); i += 2) {
+ // target label
+ struct script_data* data = script_getdata(st, i+1);
// menu options
text = script_getstr(st, i);
- // target label
- data = script_getdata(st, i+1);
if( !data_islabel(data) )
{// not a label
StrBuf->Destroy(&buf);
@@ -5131,22 +5135,21 @@ BUILDIN(rand)
{
int range;
int min;
- int max;
- if( script_hasdata(st,3) )
- {// min,max
+ if (script_hasdata(st,3)) {
+ // min,max
+ int max;
min = script_getnum(st,2);
max = script_getnum(st,3);
if( max < min )
swap(min, max);
range = max - min + 1;
- }
- else
- {// range
+ } else {
+ // range
min = 0;
range = script_getnum(st,2);
}
- if( range <= 1 )
+ if (range <= 1)
script_pushint(st, min);
else
script_pushint(st, rnd()%range + min);
@@ -6258,7 +6261,7 @@ BUILDIN(countitem2) {
*------------------------------------------*/
BUILDIN(checkweight)
{
- int nameid, amount, slots, amount2=0;
+ int slots, amount2=0;
unsigned int weight=0, i, nbargs;
struct item_data* id = NULL;
struct map_session_data* sd;
@@ -6274,11 +6277,12 @@ BUILDIN(checkweight)
}
slots = pc->inventoryblank(sd); //nb of empty slot
- for( i = 2; i < nbargs; i += 2 ) {
- if( script_isstringtype(st, i) ) {
+ for (i = 2; i < nbargs; i += 2) {
+ int nameid, amount;
+ if (script_isstringtype(st, i)) {
// item name
id = itemdb->search_name(script_getstr(st, i));
- } else if ( script_isinttype(st, i) ) {
+ } else if (script_isinttype(st, i)) {
// item id
id = itemdb->exists(script_getnum(st, i));
} else {
@@ -6340,7 +6344,6 @@ BUILDIN(checkweight)
BUILDIN(checkweight2)
{
//variable sub checkweight
- int32 nameid=-1, amount=-1;
int i=0, amount2=0, slots=0, weight=0;
short fail=0;
@@ -6388,7 +6391,8 @@ BUILDIN(checkweight2)
slots = pc->inventoryblank(sd);
for(i=0; i<nb_it; i++) {
- nameid = (int32)h64BPTRSIZE(script->get_val2(st,reference_uid(id_it,idx_it+i),reference_getref(data_it)));
+ int32 nameid = (int32)h64BPTRSIZE(script->get_val2(st,reference_uid(id_it,idx_it+i),reference_getref(data_it)));
+ int32 amount;
script_removetop(st, -1, 0);
amount = (int32)h64BPTRSIZE(script->get_val2(st,reference_uid(id_nb,idx_nb+i),reference_getref(data_nb)));
script_removetop(st, -1, 0);
@@ -6527,8 +6531,9 @@ BUILDIN(getitem) {
/*==========================================
*
*------------------------------------------*/
-BUILDIN(getitem2) {
- int nameid,amount,i,flag = 0, offset = 0;
+BUILDIN(getitem2)
+{
+ int nameid,amount,flag = 0, offset = 0;
int iden,ref,attr,c1,c2,c3,c4, bound = 0;
TBL_PC *sd;
@@ -6574,15 +6579,15 @@ BUILDIN(getitem2) {
return false;
}
- if(nameid<0) { // Invalide nameid
+ if (nameid < 0) { // Invalide nameid
nameid = -nameid;
flag = 1;
}
- if(nameid > 0) {
+ if (nameid > 0) {
struct item item_tmp;
struct item_data *item_data = itemdb->exists(nameid);
- int get_count;
+ int get_count, i;
memset(&item_tmp,0,sizeof(item_tmp));
if (item_data == NULL)
return -1;
@@ -6779,17 +6784,17 @@ BUILDIN(makeitem)
int x,y,m;
const char *mapname;
struct item item_tmp;
- struct item_data *item_data;
if( script_isstringtype(st, 2) ) {
const char *name = script_getstr(st, 2);
- if( (item_data = itemdb->search_name(name)) )
- nameid=item_data->nameid;
+ struct item_data *item_data = itemdb->search_name(name);
+ if (item_data)
+ nameid = item_data->nameid;
else
- nameid=UNKNOWN_ITEM_ID;
+ nameid = UNKNOWN_ITEM_ID;
} else {
nameid = script_getnum(st, 2);
- if( nameid <= 0 || !(item_data = itemdb->exists(nameid)) ) {
+ if( nameid <= 0 || !itemdb->exists(nameid)) {
ShowError("makeitem: Nonexistant item %d requested.\n", nameid);
return false; //No item created.
}
@@ -6854,60 +6859,52 @@ void buildin_delitem_delete(struct map_session_data* sd, int idx, int* amount, b
bool buildin_delitem_search(struct map_session_data* sd, struct item* it, bool exact_match)
{
bool delete_items = false;
- int i, amount, important;
+ int i, amount;
struct item* inv;
// prefer always non-equipped items
it->equip = 0;
// when searching for nameid only, prefer additionally
- if( !exact_match )
- {
+ if (!exact_match) {
// non-refined items
it->refine = 0;
// card-less items
memset(it->card, 0, sizeof(it->card));
}
- for(;;)
- {
+ for (;;) {
+ int important = 0;
amount = it->amount;
- important = 0;
// 1st pass -- less important items / exact match
- for( i = 0; amount && i < ARRAYLENGTH(sd->status.inventory); i++ )
- {
+ for (i = 0; amount && i < ARRAYLENGTH(sd->status.inventory); i++) {
inv = &sd->status.inventory[i];
- if( !inv->nameid || !sd->inventory_data[i] || inv->nameid != it->nameid )
- {// wrong/invalid item
+ if (!inv->nameid || !sd->inventory_data[i] || inv->nameid != it->nameid) {
+ // wrong/invalid item
continue;
}
- if( inv->equip != it->equip || inv->refine != it->refine )
- {// not matching attributes
+ if (inv->equip != it->equip || inv->refine != it->refine) {
+ // not matching attributes
important++;
continue;
}
- if( exact_match )
- {
- if( inv->identify != it->identify || inv->attribute != it->attribute || memcmp(inv->card, it->card, sizeof(inv->card)) )
- {// not matching exact attributes
+ if (exact_match) {
+ if (inv->identify != it->identify || inv->attribute != it->attribute || memcmp(inv->card, it->card, sizeof(inv->card))) {
+ // not matching exact attributes
continue;
}
- }
- else
- {
- if( sd->inventory_data[i]->type == IT_PETEGG )
- {
- if( inv->card[0] == CARD0_PET && intif->CheckForCharServer() )
- {// pet which cannot be deleted
+ } else {
+ if (sd->inventory_data[i]->type == IT_PETEGG) {
+ if (inv->card[0] == CARD0_PET && intif->CheckForCharServer()) {
+ // pet which cannot be deleted
continue;
}
- }
- else if( memcmp(inv->card, it->card, sizeof(inv->card)) )
- {// named/carded item
+ } else if (memcmp(inv->card, it->card, sizeof(inv->card))) {
+ // named/carded item
important++;
continue;
}
@@ -6918,46 +6915,44 @@ bool buildin_delitem_search(struct map_session_data* sd, struct item* it, bool e
}
// 2nd pass -- any matching item
- if( amount == 0 || important == 0 )
- {// either everything was already consumed or no items were skipped
+ if (amount == 0 || important == 0) {
+ // either everything was already consumed or no items were skipped
;
- }
- else for( i = 0; amount && i < ARRAYLENGTH(sd->status.inventory); i++ )
- {
- inv = &sd->status.inventory[i];
-
- if( !inv->nameid || !sd->inventory_data[i] || inv->nameid != it->nameid )
- {// wrong/invalid item
- continue;
- }
+ } else {
+ for (i = 0; amount && i < ARRAYLENGTH(sd->status.inventory); i++) {
+ inv = &sd->status.inventory[i];
- if( sd->inventory_data[i]->type == IT_PETEGG && inv->card[0] == CARD0_PET && intif->CheckForCharServer() )
- {// pet which cannot be deleted
- continue;
- }
+ if (!inv->nameid || !sd->inventory_data[i] || inv->nameid != it->nameid) {
+ // wrong/invalid item
+ continue;
+ }
- if( exact_match )
- {
- if( inv->refine != it->refine || inv->identify != it->identify || inv->attribute != it->attribute || memcmp(inv->card, it->card, sizeof(inv->card)) )
- {// not matching attributes
+ if (sd->inventory_data[i]->type == IT_PETEGG && inv->card[0] == CARD0_PET && intif->CheckForCharServer()) {
+ // pet which cannot be deleted
continue;
}
- }
- // count / delete item
- script->buildin_delitem_delete(sd, i, &amount, delete_items);
+ if (exact_match) {
+ if (inv->refine != it->refine || inv->identify != it->identify || inv->attribute != it->attribute
+ || memcmp(inv->card, it->card, sizeof(inv->card))) {
+ // not matching attributes
+ continue;
+ }
+ }
+
+ // count / delete item
+ script->buildin_delitem_delete(sd, i, &amount, delete_items);
+ }
}
- if( amount )
- {// not enough items
+ if (amount) {
+ // not enough items
return false;
- }
- else if( delete_items )
- {// we are done with the work
+ } else if(delete_items) {
+ // we are done with the work
return true;
- }
- else
- {// get rid of the items now
+ } else {
+ // get rid of the items now
delete_items = true;
}
}
@@ -7233,15 +7228,16 @@ BUILDIN(getpartyname)
BUILDIN(getpartymember)
{
struct party_data *p;
- int i,j=0,type=0;
+ int j=0,type=0;
p=party->search(script_getnum(st,2));
- if( script_hasdata(st,3) )
+ if (script_hasdata(st,3))
type=script_getnum(st,3);
- if(p!=NULL) {
- for(i=0;i<MAX_PARTY;i++) {
+ if ( p != NULL) {
+ int i;
+ for (i = 0; i < MAX_PARTY; i++) {
if(p->party.member[i].account_id) {
switch (type) {
case 2:
@@ -7853,22 +7849,23 @@ BUILDIN(getequippercentrefinery) {
/*==========================================
* Refine +1 item at pos and log and display refine
*------------------------------------------*/
-BUILDIN(successrefitem) {
- int i = -1 , num, ep, up = 1;
+BUILDIN(successrefitem)
+{
+ int i = -1 , num, up = 1;
TBL_PC *sd;
num = script_getnum(st,2);
sd = script->rid2sd(st);
- if( sd == NULL )
+ if (sd == NULL)
return true;
- if( script_hasdata(st, 3) )
+ if (script_hasdata(st, 3))
up = script_getnum(st, 3);
if (num > 0 && num <= ARRAYLENGTH(script->equip))
i=pc->checkequip(sd,script->equip[num-1]);
- if(i >= 0) {
- ep=sd->status.inventory[i].equip;
+ if (i >= 0) {
+ int ep = sd->status.inventory[i].equip;
//Logs items, got from (N)PC scripts [Lupus]
logs->pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i],sd->inventory_data[i]);
@@ -7943,20 +7940,20 @@ BUILDIN(failedrefitem)
*------------------------------------------*/
BUILDIN(downrefitem)
{
- int i = -1,num,ep, down = 1;
+ int i = -1, num, down = 1;
TBL_PC *sd;
sd = script->rid2sd(st);
- if( sd == NULL )
+ if (sd == NULL)
return true;
num = script_getnum(st,2);
- if( script_hasdata(st, 3) )
+ if (script_hasdata(st, 3))
down = script_getnum(st, 3);
if (num > 0 && num <= ARRAYLENGTH(script->equip))
i = pc->checkequip(sd,script->equip[num-1]);
- if(i >= 0) {
- ep = sd->status.inventory[i].equip;
+ if (i >= 0) {
+ int ep = sd->status.inventory[i].equip;
//Logs items, got from (N)PC scripts [Lupus]
logs->pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i],sd->inventory_data[i]);
@@ -9367,7 +9364,7 @@ BUILDIN(clone) {
TBL_PC *sd, *msd=NULL;
int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
unsigned int duration = 0;
- const char *mapname, *event="";
+ const char *mapname, *event;
mapname=script_getstr(st,2);
x=script_getnum(st,3);
@@ -9953,7 +9950,7 @@ BUILDIN(getmapguildusers)
const char *str;
int16 m;
int gid;
- int i=0,c=0;
+ int c=0;
struct guild *g = NULL;
str=script_getstr(st,2);
gid=script_getnum(st,3);
@@ -9964,8 +9961,8 @@ BUILDIN(getmapguildusers)
g = guild->search(gid);
if (g) {
- for(i = 0; i < g->max_member; i++)
- {
+ int i;
+ for (i = 0; i < g->max_member; i++) {
if (g->member[i].sd && g->member[i].sd->bl.m == m)
c++;
}
@@ -10375,9 +10372,8 @@ BUILDIN(homunculus_evolution)
* Checks for vaporized morph state
* and deletes ITEMID_STRANGE_EMBRYO.
*------------------------------------------*/
-BUILDIN(homunculus_mutate) {
- int homun_id;
- enum homun_type m_class, m_id;
+BUILDIN(homunculus_mutate)
+{
TBL_PC *sd;
bool success = false;
@@ -10385,9 +10381,11 @@ BUILDIN(homunculus_mutate) {
if( sd == NULL || sd->hd == NULL )
return true;
- if( sd->hd->homunculus.vaporize == HOM_ST_MORPH ) {
+ if (sd->hd->homunculus.vaporize == HOM_ST_MORPH) {
+ enum homun_type m_class, m_id;
+ int homun_id;
int i = pc->search_inventory(sd, ITEMID_STRANGE_EMBRYO);
- if( script_hasdata(st,2) )
+ if (script_hasdata(st,2))
homun_id = script_getnum(st,2);
else
homun_id = 6048 + (rnd() % 4);
@@ -10395,17 +10393,19 @@ BUILDIN(homunculus_mutate) {
m_class = homun->class2type(sd->hd->homunculus.class_);
m_id = homun->class2type(homun_id);
- if( m_class == HT_EVO && m_id == HT_S &&
+ if (m_class == HT_EVO && m_id == HT_S &&
sd->hd->homunculus.level >= 99 && i != INDEX_NOT_FOUND &&
!pc->delitem(sd, i, 1, 0, 0, LOG_TYPE_SCRIPT) ) {
sd->hd->homunculus.vaporize = HOM_ST_REST; // Remove morph state.
homun->call(sd); // Respawn homunculus.
homun->mutate(sd->hd, homun_id);
success = true;
- } else
+ } else {
clif->emotion(&sd->hd->bl, E_SWT);
- } else
+ }
+ } else {
clif->emotion(&sd->hd->bl, E_SWT);
+ }
script_pushint(st,success?1:0);
return true;
@@ -10415,9 +10415,8 @@ BUILDIN(homunculus_mutate) {
* Puts homunculus into morph state
* and gives ITEMID_STRANGE_EMBRYO.
*------------------------------------------*/
-BUILDIN(homunculus_morphembryo) {
- enum homun_type m_class;
- int i = 0;
+BUILDIN(homunculus_morphembryo)
+{
TBL_PC *sd;
bool success = false;
@@ -10425,27 +10424,30 @@ BUILDIN(homunculus_morphembryo) {
if( sd == NULL || sd->hd == NULL )
return true;
- if( homun_alive(sd->hd) ) {
- m_class = homun->class2type(sd->hd->homunculus.class_);
+ if (homun_alive(sd->hd)) {
+ enum homun_type m_class = homun->class2type(sd->hd->homunculus.class_);
- if ( m_class == HT_EVO && sd->hd->homunculus.level >= 99 ) {
+ if (m_class == HT_EVO && sd->hd->homunculus.level >= 99) {
struct item item_tmp;
+ int i = 0;
memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = ITEMID_STRANGE_EMBRYO;
item_tmp.identify = 1;
- if( (i = pc->additem(sd, &item_tmp, 1, LOG_TYPE_SCRIPT)) ) {
+ if ((i = pc->additem(sd, &item_tmp, 1, LOG_TYPE_SCRIPT))) {
clif->additem(sd, 0, 0, i);
clif->emotion(&sd->hd->bl, E_SWT);
} else {
homun->vaporize(sd, HOM_ST_MORPH);
success = true;
}
- } else
+ } else {
clif->emotion(&sd->hd->bl, E_SWT);
- } else
+ }
+ } else {
clif->emotion(&sd->hd->bl, E_SWT);
+ }
script_pushint(st, success?1:0);
return true;
@@ -10701,9 +10703,9 @@ BUILDIN(globalmes) {
/// Creates a waiting room (chat room) for this npc.
///
/// waitingroom "<title>",<limit>{,"<event>"{,<trigger>{,<zeny>{,<minlvl>{,<maxlvl>}}}}};
-BUILDIN(waitingroom) {
+BUILDIN(waitingroom)
+{
struct npc_data* nd;
- int pub = 1;
const char* title = script_getstr(st, 2);
int limit = script_getnum(st, 3);
const char* ev = script_hasdata(st,4) ? script_getstr(st,4) : "";
@@ -10713,8 +10715,10 @@ BUILDIN(waitingroom) {
int maxLvl = script_hasdata(st,8) ? script_getnum(st,8) : MAX_LEVEL;
nd = (struct npc_data *)map->id2bl(st->oid);
- if( nd != NULL )
+ if (nd != NULL) {
+ int pub = 1;
chat->create_npc_chat(nd, title, limit, pub, trigger, ev, zeny, minLvl, maxLvl);
+ }
return true;
}
@@ -10845,15 +10849,12 @@ BUILDIN(getwaitingroomstate) {
///
/// warpwaitingpc "<map name>",<x>,<y>,<number of players>;
/// warpwaitingpc "<map name>",<x>,<y>;
-BUILDIN(warpwaitingpc) {
- int x;
- int y;
- int i;
- int n;
+BUILDIN(warpwaitingpc)
+{
+ int x, y, i, n;
const char* map_name;
struct npc_data* nd;
struct chat_data* cd;
- TBL_PC* sd;
nd = (struct npc_data *)map->id2bl(st->oid);
if( nd == NULL || (cd=(struct chat_data *)map->id2bl(nd->chat_id)) == NULL )
@@ -10867,15 +10868,15 @@ BUILDIN(warpwaitingpc) {
if( script_hasdata(st,5) )
n = script_getnum(st,5);
- for( i = 0; i < n && cd->users > 0; i++ ) {
- sd = cd->usersd[0];
+ for (i = 0; i < n && cd->users > 0; i++) {
+ TBL_PC* sd = cd->usersd[0];
- if( strcmp(map_name,"SavePoint") == 0 && map->list[sd->bl.m].flag.noteleport ) {
+ if (strcmp(map_name,"SavePoint") == 0 && map->list[sd->bl.m].flag.noteleport) {
// can't teleport on this map
break;
}
- if( cd->zeny ) {
+ if (cd->zeny) {
// fee set
if( (uint32)sd->status.zeny < cd->zeny ) {
// no zeny to cover set fee
@@ -11644,8 +11645,9 @@ BUILDIN(getequipcardcnt)
/// Removes all cards from the item found in the specified equipment slot of the invoking character,
/// and give them to the character. If any cards were removed in this manner, it will also show a success effect.
/// successremovecards <slot>;
-BUILDIN(successremovecards) {
- int i=-1,j,c,cardflag=0;
+BUILDIN(successremovecards)
+{
+ int i=-1,c,cardflag=0;
TBL_PC* sd = script->rid2sd(st);
int num = script_getnum(st,2);
@@ -11680,8 +11682,9 @@ BUILDIN(successremovecards) {
}
}
- if(cardflag == 1) {//if card was remove remplace item with no card
- int flag;
+ if (cardflag == 1) {
+ //if card was remove replace item with no card
+ int flag, j;
struct item item_tmp;
memset(&item_tmp,0,sizeof(item_tmp));
@@ -11696,7 +11699,7 @@ BUILDIN(successremovecards) {
item_tmp.card[j]=sd->status.inventory[i].card[j];
pc->delitem(sd,i,1,0,3,LOG_TYPE_SCRIPT);
- if((flag=pc->additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))) {
+ if ((flag=pc->additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))) {
//chk if can be spawn in inventory otherwise put on floor
clif->additem(sd,0,0,flag);
map->addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
@@ -11713,8 +11716,9 @@ BUILDIN(successremovecards) {
/// <type>=1 : will keep the item, but destroy the cards.
/// <type>=2 : will keep the cards, but destroy the item.
/// <type>=? : will just display the failure effect.
-BUILDIN(failedremovecards) {
- int i=-1,j,c,cardflag=0;
+BUILDIN(failedremovecards)
+{
+ int i=-1,c,cardflag=0;
TBL_PC* sd = script->rid2sd(st);
int num = script_getnum(st,2);
@@ -11753,14 +11757,13 @@ BUILDIN(failedremovecards) {
}
}
- if(cardflag == 1) {
- if(typefail == 0 || typefail == 2) {
+ if (cardflag == 1) {
+ if (typefail == 0 || typefail == 2) {
// destroy the item
pc->delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT);
- }
- if(typefail == 1) {
+ } else if (typefail == 1) {
// destroy the card
- int flag;
+ int flag, j;
struct item item_tmp;
memset(&item_tmp,0,sizeof(item_tmp));
@@ -12213,7 +12216,6 @@ BUILDIN(getitemslots)
BUILDIN(getiteminfo)
{
int item_id,n;
- int *item_arr;
struct item_data *i_data;
item_id = script_getnum(st,2);
@@ -12221,10 +12223,11 @@ BUILDIN(getiteminfo)
i_data = itemdb->exists(item_id);
if (i_data && n>=0 && n<=14) {
- item_arr = (int*)&i_data->value_buy;
+ int *item_arr = (int*)&i_data->value_buy;
script_pushint(st,item_arr[n]);
- } else
+ } else {
script_pushint(st,-1);
+ }
return true;
}
@@ -12254,7 +12257,6 @@ BUILDIN(getiteminfo)
BUILDIN(setiteminfo)
{
int item_id,n,value;
- int *item_arr;
struct item_data *i_data;
item_id = script_getnum(st,2);
@@ -12263,11 +12265,12 @@ BUILDIN(setiteminfo)
i_data = itemdb->exists(item_id);
if (i_data && n>=0 && n<=14) {
- item_arr = (int*)&i_data->value_buy;
+ int *item_arr = (int*)&i_data->value_buy;
item_arr[n] = value;
script_pushint(st,value);
- } else
+ } else {
script_pushint(st,-1);
+ }
return true;
}
@@ -12552,12 +12555,10 @@ BUILDIN(misceffect)
*------------------------------------------*/
BUILDIN(playbgm)
{
- const char* name;
- struct map_session_data* sd;
+ struct map_session_data* sd = script->rid2sd(st);
- if( ( sd = script->rid2sd(st) ) != NULL )
- {
- name = script_getstr(st,2);
+ if (sd != NULL) {
+ const char *name = script_getstr(st,2);
clif->playBGM(sd, name);
}
@@ -13075,23 +13076,24 @@ BUILDIN(gethominfo)
/// Retrieves information about character's mercenary
/// getmercinfo <type>[,<char id>];
-BUILDIN(getmercinfo) {
- int type, char_id;
+BUILDIN(getmercinfo)
+{
+ int type;
struct map_session_data* sd;
struct mercenary_data* md;
type = script_getnum(st,2);
- if( script_hasdata(st,3) ) {
- char_id = script_getnum(st,3);
+ if (script_hasdata(st,3)) {
+ int char_id = script_getnum(st,3);
- if( ( sd = map->charid2sd(char_id) ) == NULL ) {
+ if ((sd = map->charid2sd(char_id)) == NULL) {
ShowError("buildin_getmercinfo: No such character (char_id=%d).\n", char_id);
script_pushnil(st);
return false;
}
} else {
- if( ( sd = script->rid2sd(st) ) == NULL )
+ if ((sd = script->rid2sd(st)) == NULL)
return true;
}
@@ -13213,15 +13215,13 @@ BUILDIN(message) {
/*==========================================
* npctalk (sends message to surrounding area)
*------------------------------------------*/
-BUILDIN(npctalk) {
- const char* str;
- char name[NAME_LENGTH], message[256];
-
+BUILDIN(npctalk)
+{
struct npc_data* nd = (struct npc_data *)map->id2bl(st->oid);
- str = script_getstr(st,2);
+ const char *str = script_getstr(st,2);
- if(nd)
- {
+ if (nd) {
+ char name[NAME_LENGTH], message[256];
safestrncpy(name, nd->name, sizeof(name));
strtok(name, "#"); // discard extra name identifier if present
safesnprintf(message, sizeof(message), "%s : %s", name, str);
@@ -13895,15 +13895,13 @@ BUILDIN(day) {
//-------------------------------------------------------
BUILDIN(unequip)
{
- int i;
size_t num;
TBL_PC *sd;
num = script_getnum(st,2);
sd = script->rid2sd(st);
- if( sd != NULL && num >= 1 && num <= ARRAYLENGTH(script->equip) )
- {
- i = pc->checkequip(sd,script->equip[num-1]);
+ if (sd != NULL && num >= 1 && num <= ARRAYLENGTH(script->equip)) {
+ int i = pc->checkequip(sd,script->equip[num-1]);
if (i >= 0)
pc->unequipitem(sd,i,1|2);
}
@@ -14307,10 +14305,8 @@ BUILDIN(explode)
BUILDIN(implode)
{
struct script_data* data = script_getdata(st, 2);
- const char *glue = NULL, *name, *temp;
+ const char *name;
uint32 array_size, id;
- size_t len = 0, glue_len = 0, k = 0;
- int i;
TBL_PC* sd = NULL;
@@ -14345,12 +14341,15 @@ BUILDIN(implode)
//count chars
array_size = script->array_highest_key(st,sd,name,reference_getref(data)) - 1;
- if(array_size == -1) {
+ if (array_size == -1) {
//empty array check (AmsTaff)
ShowWarning("script:implode: array length = 0\n");
output = (char*)aMalloc(sizeof(char)*5);
sprintf(output,"%s","NULL");
} else {
+ int i;
+ size_t len = 0, glue_len = 0, k = 0;
+ const char *glue = NULL, *temp;
for(i = 0; i <= array_size; ++i) {
temp = (char*) script->get_val2(st, reference_uid(id, i), reference_getref(data));
len += strlen(temp);
@@ -14591,7 +14590,7 @@ BUILDIN(sscanf) {
if(!data_isreference(data) || !reference_tovariable(data)) {
ShowError("buildin_sscanf: Target argument is not a variable!\n");
script_pushint(st, -1);
- if(buf) aFree(buf);
+ aFree(buf);
if(ref_str) aFree(ref_str);
return false;
}
@@ -15276,12 +15275,11 @@ BUILDIN(npcshopdelitem)
{
const char* npcname = script_getstr(st,2);
struct npc_data* nd = npc->name2id(npcname);
- unsigned int nameid;
int n, i;
int amount;
int size;
- if( !nd || ( nd->subtype != SHOP && nd->subtype != CASHSHOP ) ) {
+ if (!nd || (nd->subtype != SHOP && nd->subtype != CASHSHOP)) {
//Not found.
script_pushint(st,0);
return true;
@@ -15291,13 +15289,11 @@ BUILDIN(npcshopdelitem)
size = nd->u.shop.count;
// remove specified items from the shop item list
- for( i = 3; i < 3 + amount; i++ )
- {
- nameid = script_getnum(st,i);
+ for (i = 3; i < 3 + amount; i++) {
+ unsigned int nameid = script_getnum(st,i);
- ARR_FIND( 0, size, n, nd->u.shop.shop_item[n].nameid == nameid );
- if( n < size )
- {
+ ARR_FIND(0, size, n, nd->u.shop.shop_item[n].nameid == nameid);
+ if (n < size) {
memmove(&nd->u.shop.shop_item[n], &nd->u.shop.shop_item[n+1], sizeof(nd->u.shop.shop_item[0])*(size-n));
size--;
}
@@ -16447,7 +16443,7 @@ BUILDIN(readbook)
BUILDIN(questinfo)
{
struct npc_data *nd = map->id2nd(st->oid);
- int quest_id, icon, job, color = 0;
+ int quest_id, icon;
struct questinfo qi;
if( nd == NULL || nd->bl.m == -1 )
@@ -16470,9 +16466,9 @@ BUILDIN(questinfo)
qi.icon = (unsigned char)icon;
qi.nd = nd;
- if( script_hasdata(st, 4) ) {
- color = script_getnum(st, 4);
- if( color < 0 || color > 3 ) {
+ if (script_hasdata(st, 4)) {
+ int color = script_getnum(st, 4);
+ if (color < 0 || color > 3) {
ShowWarning("buildin_questinfo: invalid color '%d', changing to 0\n",color);
script->reportfunc(st);
color = 0;
@@ -16482,12 +16478,12 @@ BUILDIN(questinfo)
qi.hasJob = false;
- if(script_hasdata(st, 5)) {
- job = script_getnum(st, 5);
+ if (script_hasdata(st, 5)) {
+ int job = script_getnum(st, 5);
- if (!pc->db_checkid(job))
+ if (!pc->db_checkid(job)) {
ShowError("buildin_questinfo: Nonexistant Job Class.\n");
- else {
+ } else {
qi.hasJob = true;
qi.job = (unsigned short)job;
}
@@ -16525,14 +16521,15 @@ BUILDIN(setquest) {
return true;
}
-BUILDIN(erasequest) {
+BUILDIN(erasequest)
+{
struct map_session_data *sd = script->rid2sd(st);
- int quest_id;
if( sd == NULL )
return false;
if (script_hasdata(st, 3)) {
+ int quest_id;
if (script_getnum(st, 3) < script_getnum(st, 2)) {
ShowError("buildin_erasequest: The second quest id must be greater than the id of the first.\n");
return false;
@@ -16547,14 +16544,15 @@ BUILDIN(erasequest) {
return true;
}
-BUILDIN(completequest) {
+BUILDIN(completequest)
+{
struct map_session_data *sd = script->rid2sd(st);
- int quest_id;
if( sd == NULL )
return false;
if (script_hasdata(st, 3)) {
+ int quest_id;
if (script_getnum(st, 3) < script_getnum(st, 2)) {
ShowError("buildin_completequest: The second quest id must be greater than the id of the first.\n");
return false;
@@ -16663,7 +16661,6 @@ BUILDIN(waitingroom2bg) {
struct chat_data *cd;
const char *map_name, *ev = "", *dev = "";
int x, y, i, map_index = 0, bg_id, n;
- struct map_session_data *sd;
if( script_hasdata(st,7) )
nd = npc->name2id(script_getstr(st,7));
@@ -16691,16 +16688,16 @@ BUILDIN(waitingroom2bg) {
ev = script_getstr(st,5); // Logout Event
dev = script_getstr(st,6); // Die Event
- if( (bg_id = bg->create(map_index, x, y, ev, dev)) == 0 )
- { // Creation failed
+ if ((bg_id = bg->create(map_index, x, y, ev, dev)) == 0) {
+ // Creation failed
script_pushint(st,0);
return true;
}
- n = cd->users;
- for( i = 0; i < n && i < MAX_BG_MEMBERS; i++ )
- {
- if( (sd = cd->usersd[i]) != NULL && bg->team_join(bg_id, sd) )
+ n = cd->users; // This is always < MAX_CHAT_USERS
+ for (i = 0; i < n && i < MAX_BG_MEMBERS; i++) {
+ struct map_session_data *sd = cd->usersd[i];
+ if (sd != NULL && bg->team_join(bg_id, sd))
mapreg->setreg(reference_uid(script->add_str("$@arenamembers"), i), sd->bl.id);
else
mapreg->setreg(reference_uid(script->add_str("$@arenamembers"), i), 0);
@@ -16826,13 +16823,13 @@ BUILDIN(bg_destroy)
return true;
}
-BUILDIN(bg_getareausers) {
+BUILDIN(bg_getareausers)
+{
const char *str;
int16 m, x0, y0, x1, y1;
int bg_id;
int i = 0, c = 0;
struct battleground_data *bgd = NULL;
- struct map_session_data *sd;
bg_id = script_getnum(st,2);
str = script_getstr(st,3);
@@ -16847,11 +16844,11 @@ BUILDIN(bg_getareausers) {
x1 = script_getnum(st,6);
y1 = script_getnum(st,7);
- for( i = 0; i < MAX_BG_MEMBERS; i++ )
- {
- if( (sd = bgd->members[i].sd) == NULL )
+ for (i = 0; i < MAX_BG_MEMBERS; i++) {
+ struct map_session_data *sd = bgd->members[i].sd;
+ if (sd == NULL)
continue;
- if( sd->bl.m != m || sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1 )
+ if (sd->bl.m != m || sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1)
continue;
c++;
}
@@ -16956,21 +16953,21 @@ BUILDIN(instance_destroy) {
return true;
}
-BUILDIN(instance_attachmap) {
- const char *name, *map_name = NULL;
+BUILDIN(instance_attachmap)
+{
+ const char *map_name = NULL;
int16 m;
- int instance_id = -1;
bool usebasename = false;
+ const char *name = script_getstr(st,2);
+ int instance_id = script_getnum(st,3);
- name = script_getstr(st,2);
- instance_id = script_getnum(st,3);
- if( script_hasdata(st,4) && script_getnum(st,4) > 0 )
+ if (script_hasdata(st,4) && script_getnum(st,4) > 0)
usebasename = true;
- if( script_hasdata(st, 5) )
+ if (script_hasdata(st, 5))
map_name = script_getstr(st, 5);
- if( (m = instance->add_map(name, instance_id, usebasename, map_name)) < 0 ) { // [Saithis]
+ if ((m = instance->add_map(name, instance_id, usebasename, map_name)) < 0) { // [Saithis]
ShowError("buildin_instance_attachmap: instance creation failed (%s): %d\n", name, m);
script_pushconststr(st, "");
return true;
@@ -17001,10 +16998,10 @@ BUILDIN(instance_detachmap) {
return true;
}
-BUILDIN(instance_attach) {
- int instance_id = -1;
+BUILDIN(instance_attach)
+{
+ int instance_id = script_getnum(st, 2);
- instance_id = script_getnum(st, 2);
if( !instance->valid(instance_id) )
return true;
@@ -17228,8 +17225,8 @@ BUILDIN(instance_warpall) {
* Example: instance_check_party (getcharid(1){,amount}{,min}{,max});
* Example 2: instance_check_party (getcharid(1),1,1,99);
*------------------------------------------*/
-BUILDIN(instance_check_party) {
- struct map_session_data *pl_sd;
+BUILDIN(instance_check_party)
+{
int amount, min, max, i, party_id, c = 0;
struct party_data *p = NULL;
@@ -17254,18 +17251,20 @@ BUILDIN(instance_check_party) {
return true;
}
- for( i = 0; i < MAX_PARTY; i++ )
- if( (pl_sd = p->data[i].sd) )
- if(map->id2bl(pl_sd->bl.id)) {
- if(pl_sd->status.base_level < min) {
- script_pushint(st, 0);
- return true;
- } else if(pl_sd->status.base_level > max) {
- script_pushint(st, 0);
- return true;
- }
- c++;
+ for (i = 0; i < MAX_PARTY; i++) {
+ struct map_session_data *pl_sd = p->data[i].sd;
+ if (pl_sd && map->id2bl(pl_sd->bl.id)) {
+ if (pl_sd->status.base_level < min) {
+ script_pushint(st, 0);
+ return true;
+ }
+ if (pl_sd->status.base_level > max) {
+ script_pushint(st, 0);
+ return true;
}
+ c++;
+ }
+ }
if(c < amount) {
script_pushint(st, 0); // Not enough Members in the Party to join Instance.
@@ -17285,8 +17284,8 @@ BUILDIN(instance_check_party) {
* Example: instance_check_guild (getcharid(2){,amount}{,min}{,max});
* Example 2: instance_check_guild (getcharid(2),1,1,99);
*------------------------------------------*/
-BUILDIN(instance_check_guild){
- struct map_session_data *pl_sd;
+BUILDIN(instance_check_guild)
+{
int amount, min, max, i, guild_id, c = 0;
struct guild *g = NULL;
@@ -17311,18 +17310,20 @@ BUILDIN(instance_check_guild){
return true;
}
- for( i = 0; i < MAX_GUILD; i++ )
- if( (pl_sd = g->member[i].sd) )
- if( map->id2bl(pl_sd->bl.id) ){
- if( pl_sd->status.base_level < min ){
- script_pushint(st,0);
- return true;
- } else if( pl_sd->status.base_level > max ){
- script_pushint(st,0);
- return true;
- }
- c++;
+ for( i = 0; i < MAX_GUILD; i++ ) {
+ struct map_session_data *pl_sd = g->member[i].sd;
+ if (pl_sd && map->id2bl(pl_sd->bl.id)) {
+ if (pl_sd->status.base_level < min) {
+ script_pushint(st,0);
+ return true;
}
+ if (pl_sd->status.base_level > max) {
+ script_pushint(st,0);
+ return true;
+ }
+ c++;
+ }
+ }
if( c < amount )
script_pushint(st,0);
@@ -18011,23 +18012,21 @@ int script_cleanfloor_sub(struct block_list *bl, va_list ap) {
return 0;
}
-BUILDIN(cleanmap) {
- const char *mapname;
- int16 m = -1;
- int16 x0 = 0, y0 = 0, x1 = 0, y1 = 0;
+BUILDIN(cleanmap)
+{
+ const char *mapname = script_getstr(st, 2);
+ int16 m = map->mapname2mapid(mapname);
- mapname = script_getstr(st, 2);
- m = map->mapname2mapid(mapname);
if ( m == -1 )
return false;
if ((script_lastdata(st) - 2) < 4) {
map->foreachinmap(script->cleanfloor_sub, m, BL_ITEM);
} else {
- x0 = script_getnum(st, 3);
- y0 = script_getnum(st, 4);
- x1 = script_getnum(st, 5);
- y1 = script_getnum(st, 6);
+ int16 x0 = script_getnum(st, 3);
+ int16 y0 = script_getnum(st, 4);
+ int16 x1 = script_getnum(st, 5);
+ int16 y1 = script_getnum(st, 6);
if (x0 > 0 && y0 > 0 && x1 > 0 && y1 > 0) {
map->foreachinarea(script->cleanfloor_sub, m, x0, y0, x1, y1, BL_ITEM);
} else {
@@ -18095,7 +18094,6 @@ BUILDIN(montransform) {
int tick;
enum sc_type type;
struct block_list* bl;
- char msg[CHAT_SIZE_MAX];
int mob_id, val1, val2, val3, val4;
val1 = val2 = val3 = val4 = 0;
@@ -18145,6 +18143,7 @@ BUILDIN(montransform) {
if( tick != 0 ) {
struct map_session_data *sd = map->id2sd(bl->id);
struct mob_db *monster = mob->db(mob_id);
+ char msg[CHAT_SIZE_MAX];
if( !sd )
return true;
@@ -18220,41 +18219,41 @@ BUILDIN(queuesize) {
return true;
}
-bool script_hqueue_add(int idx, int var) {
+bool script_hqueue_add(int idx, int var)
+{
if( idx < 0 || idx >= script->hqs || script->hq[idx].size == -1 ) {
ShowWarning("script_hqueue_add: unknown queue id %d\n",idx);
return true;
} else {
- struct map_session_data *sd;
int i;
-
- for(i = 0; i < script->hq[idx].size; i++) {
- if( script->hq[idx].item[i] == var ) {
+ for (i = 0; i < script->hq[idx].size; i++) {
+ if (script->hq[idx].item[i] == var) {
return true;
}
}
- if( i == script->hq[idx].size ) {
+ if (i == script->hq[idx].size) {
+ struct map_session_data *sd;
- for(i = 0; i < script->hq[idx].size; i++) {
+ for (i = 0; i < script->hq[idx].size; i++) {
if( script->hq[idx].item[i] == 0 ) {
break;
}
}
- if( i == script->hq[idx].size )
+ if (i == script->hq[idx].size)
RECREATE(script->hq[idx].item, int, ++script->hq[idx].size);
script->hq[idx].item[i] = var;
script->hq[idx].items++;
- if( var >= START_ACCOUNT_NUM && (sd = map->id2sd(var)) ) {
- for(i = 0; i < sd->queues_count; i++) {
- if( sd->queues[i] == -1 ) {
+ if (var >= START_ACCOUNT_NUM && (sd = map->id2sd(var))) {
+ for (i = 0; i < sd->queues_count; i++) {
+ if (sd->queues[i] == -1) {
break;
}
}
- if( i == sd->queues_count )
+ if (i == sd->queues_count)
RECREATE(sd->queues, int, ++sd->queues_count);
sd->queues[i] = idx;
@@ -18362,15 +18361,15 @@ BUILDIN(queueopt) {
return true;
}
-bool script_hqueue_del(int idx) {
+bool script_hqueue_del(int idx)
+{
if( idx < 0 || idx >= script->hqs || script->hq[idx].size == -1 ) {
ShowWarning("script_queue_del: unknown queue id %d\n",idx);
return true;
} else {
- struct map_session_data *sd;
int i;
-
- for(i = 0; i < script->hq[idx].size; i++) {
+ for (i = 0; i < script->hq[idx].size; i++) {
+ struct map_session_data *sd;
if( script->hq[idx].item[i] >= START_ACCOUNT_NUM && (sd = map->id2sd(script->hq[idx].item[i])) ) {
int j;
for(j = 0; j < sd->queues_count; j++) {
@@ -18641,9 +18640,10 @@ BUILDIN(countbound)
* 3 - Party Bound
* 4 - Character Bound
*------------------------------------------*/
-BUILDIN(checkbound){
+BUILDIN(checkbound)
+{
int i, nameid = script_getnum(st,2);
- int bound_type = 0, ref, attr, c1, c2, c3, c4;
+ int bound_type = 0;
TBL_PC *sd;
sd = script->rid2sd(st);
@@ -18663,13 +18663,13 @@ BUILDIN(checkbound){
}
ARR_FIND( 0, MAX_INVENTORY, i, (sd->status.inventory[i].nameid == nameid &&
- ( sd->status.inventory[i].refine == (script_hasdata(st,4)? (ref = script_getnum(st,4)) : sd->status.inventory[i].refine) ) &&
- ( sd->status.inventory[i].attribute == (script_hasdata(st,5)? (attr = script_getnum(st,5)) : sd->status.inventory[i].attribute) ) &&
- ( sd->status.inventory[i].card[0] == (script_hasdata(st,6)? (c1 = script_getnum(st,6)) : sd->status.inventory[i].card[0]) ) &&
- ( sd->status.inventory[i].card[1] == (script_hasdata(st,7)? (c2 = script_getnum(st,7)) : sd->status.inventory[i].card[1]) ) &&
- ( sd->status.inventory[i].card[2] == (script_hasdata(st,8)? (c3 = script_getnum(st,8)) : sd->status.inventory[i].card[2]) ) &&
- ( sd->status.inventory[i].card[3] == (script_hasdata(st,9)? (c4 = script_getnum(st,9)) : sd->status.inventory[i].card[3]) ) &&
- ((sd->status.inventory[i].bound > 0 && !bound_type) || sd->status.inventory[i].bound == bound_type )) );
+ ( sd->status.inventory[i].refine == (script_hasdata(st,4)? script_getnum(st,4) : sd->status.inventory[i].refine) ) &&
+ ( sd->status.inventory[i].attribute == (script_hasdata(st,5)? script_getnum(st,5) : sd->status.inventory[i].attribute) ) &&
+ ( sd->status.inventory[i].card[0] == (script_hasdata(st,6)? script_getnum(st,6) : sd->status.inventory[i].card[0]) ) &&
+ ( sd->status.inventory[i].card[1] == (script_hasdata(st,7)? script_getnum(st,7) : sd->status.inventory[i].card[1]) ) &&
+ ( sd->status.inventory[i].card[2] == (script_hasdata(st,8)? script_getnum(st,8) : sd->status.inventory[i].card[2]) ) &&
+ ( sd->status.inventory[i].card[3] == (script_hasdata(st,9)? script_getnum(st,9) : sd->status.inventory[i].card[3]) ) &&
+ ((sd->status.inventory[i].bound > 0 && !bound_type) || sd->status.inventory[i].bound == bound_type )) );
if( i < MAX_INVENTORY ){
script_pushint(st, sd->status.inventory[i].bound);
@@ -18766,30 +18766,30 @@ BUILDIN(instance_set_respawn) {
*
* @return 1 on success, 0 otherwise.
**/
-BUILDIN(openshop) {
+BUILDIN(openshop)
+{
struct npc_data *nd;
struct map_session_data *sd;
- const char *name = NULL;
- if( script_hasdata(st, 2) ) {
- name = script_getstr(st, 2);
- if( !(nd = npc->name2id(name)) || nd->subtype != SCRIPT ) {
+ if (script_hasdata(st, 2)) {
+ const char *name = script_getstr(st, 2);
+ if (!(nd = npc->name2id(name)) || nd->subtype != SCRIPT) {
ShowWarning("buildin_openshop(\"%s\"): trying to run without a proper NPC!\n",name);
return false;
}
- } else if( !(nd = map->id2nd(st->oid)) ) {
+ } else if (!(nd = map->id2nd(st->oid))) {
ShowWarning("buildin_openshop: trying to run without a proper NPC!\n");
return false;
}
- if( !( sd = script->rid2sd(st) ) ) {
+ if (!( sd = script->rid2sd(st))) {
ShowWarning("buildin_openshop: trying to run without a player attached!\n");
return false;
- } else if ( !nd->u.scr.shop || !nd->u.scr.shop->items ) {
+ } else if (!nd->u.scr.shop || !nd->u.scr.shop->items) {
ShowWarning("buildin_openshop: trying to open without any items!\n");
return false;
}
- if( !npc->trader_open(sd,nd) )
+ if (!npc->trader_open(sd,nd))
script_pushint(st, 0);
else
script_pushint(st, 1);
@@ -18925,12 +18925,13 @@ BUILDIN(stopselling) {
* updates currently-attached player shop currency
**/
/* setcurrency(<Val1>,{<Val2>}) */
-BUILDIN(setcurrency) {
+BUILDIN(setcurrency)
+{
int val1 = script_getnum(st,2),
val2 = script_hasdata(st, 3) ? script_getnum(st,3) : 0;
- struct npc_data *nd;
+ struct npc_data *nd = map->id2nd(st->oid);
- if( !(nd = map->id2nd(st->oid)) ) {
+ if (!nd) {
ShowWarning("buildin_setcurrency: trying to run without a proper NPC!\n");
return false;
}
diff --git a/src/map/skill.c b/src/map/skill.c
index 2d992d24f..81095b4ac 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -384,16 +384,16 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk
hp += hp * sc->data[SC_OFFERTORIUM]->val2 / 100;
}
sc = status->get_sc(target);
- if( sc && sc->count ) {
- if( sc->data[SC_CRITICALWOUND] && heal ) // Critical Wound has no effect on offensive heal. [Inkfish]
+ if (sc && sc->count) {
+ if(sc->data[SC_CRITICALWOUND] && heal) // Critical Wound has no effect on offensive heal. [Inkfish]
hp -= hp * sc->data[SC_CRITICALWOUND]->val2/100;
- if( sc->data[SC_DEATHHURT] && heal )
+ if(sc->data[SC_DEATHHURT] && heal)
hp -= hp * 20/100;
- if( sc->data[SC_HEALPLUS] && skill_id != NPC_EVILLAND && skill_id != BA_APPLEIDUN )
+ if(sc->data[SC_HEALPLUS] && skill_id != NPC_EVILLAND && skill_id != BA_APPLEIDUN)
hp += hp * sc->data[SC_HEALPLUS]->val1/100; // Only affects Heal, Sanctuary and PotionPitcher.(like bHealPower) [Inkfish]
- if( sc->data[SC_WATER_INSIGNIA] && sc->data[SC_WATER_INSIGNIA]->val1 == 2)
+ if(sc->data[SC_WATER_INSIGNIA] && sc->data[SC_WATER_INSIGNIA]->val1 == 2)
hp += hp / 10;
- if ( sc && sc->data[SC_VITALITYACTIVATION] )
+ if (sc->data[SC_VITALITYACTIVATION])
hp = hp * 150 / 100;
}
@@ -1367,7 +1367,7 @@ int skill_additional_effect(struct block_list* src, struct block_list *bl, uint1
if( sd && sd->special_state.bonus_coma ) {
rate = sd->weapon_coma_ele[tstatus->def_ele];
rate += sd->weapon_coma_race[tstatus->race];
- rate += sd->weapon_coma_race[tstatus->mode&MD_BOSS?RC_BOSS:RC_NONBOSS];
+ rate += sd->weapon_coma_race[(tstatus->mode&MD_BOSS) ? RC_BOSS : RC_NONBOSS];
if (rate)
status->change_start(src, bl, SC_COMA, rate, 0, 0, src->id, 0, 0, SCFLAG_NONE);
}
@@ -1533,7 +1533,7 @@ int skill_additional_effect(struct block_list* src, struct block_list *bl, uint1
rate = skill->delay_fix(src, temp, auto_skill_lv);
if (DIFF_TICK(ud->canact_tick, tick + rate) < 0){
ud->canact_tick = tick+rate;
- if ( battle_config.display_status_timers && sd )
+ if (battle_config.display_status_timers)
clif->status_change(src, SI_POSTDELAY, 1, rate, 0, 0, 0);
}
}
@@ -1885,7 +1885,7 @@ int skill_counter_additional_effect(struct block_list* src, struct block_list *b
rate = skill->delay_fix(bl, auto_skill_id, auto_skill_lv);
if (DIFF_TICK(ud->canact_tick, tick + rate) < 0){
ud->canact_tick = tick+rate;
- if ( battle_config.display_status_timers && dstsd )
+ if (battle_config.display_status_timers)
clif->status_change(bl, SI_POSTDELAY, 1, rate, 0, 0, 0);
}
}
@@ -1920,12 +1920,13 @@ void skill_counter_additional_effect_unknown(struct block_list* src, struct bloc
* - flag is a BCT_ flag to indicate which type of adjustment should be used
* (BCT_ENEMY/BCT_PARTY/BCT_SELF) are the valid values.
*------------------------------------------------------------------------*/
-int skill_break_equip (struct block_list *bl, unsigned short where, int rate, int flag) {
+int skill_break_equip (struct block_list *bl, unsigned short where, int rate, int flag)
+{
const int where_list[4] = {EQP_WEAPON, EQP_ARMOR, EQP_SHIELD, EQP_HELM};
const enum sc_type scatk[4] = {SC_NOEQUIPWEAPON, SC_NOEQUIPARMOR, SC_NOEQUIPSHIELD, SC_NOEQUIPHELM};
const enum sc_type scdef[4] = {SC_PROTECTWEAPON, SC_PROTECTARMOR, SC_PROTECTSHIELD, SC_PROTECTHELM};
struct status_change *sc = status->get_sc(bl);
- int i,j;
+ int i;
TBL_PC *sd;
sd = BL_CAST(BL_PC, bl);
if (sc && !sc->count)
@@ -1973,7 +1974,7 @@ int skill_break_equip (struct block_list *bl, unsigned short where, int rate, in
return 0;
if (sd) {
for (i = 0; i < EQI_MAX; i++) {
- j = sd->equip_index[i];
+ int j = sd->equip_index[i];
if (j < 0 || sd->status.inventory[j].attribute == 1 || !sd->inventory_data[j])
continue;
@@ -2258,16 +2259,16 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
#endif
{
short s_ele = skill->get_ele(skill_id, skill_lv);
-
+
if (s_ele == -1) // the skill takes the weapon's element
s_ele = sstatus->rhw.ele;
else if (s_ele == -2) //Use status element
s_ele = status_get_attack_sc_element(src,status->get_sc(src));
else if( s_ele == -3 ) //Use random element
s_ele = rnd()%ELE_MAX;
-
+
dmg.damage = battle->attr_fix(bl, bl, dmg.damage, s_ele, status_get_element(bl), status_get_element_level(bl));
-
+
if( sc && sc->data[SC_ENERGYCOAT] ) {
struct status_data *st = status->get_status_data(bl);
int per = 100*st->sp / st->max_sp -1; //100% should be counted as the 80~99% interval
@@ -2296,7 +2297,7 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
if( (skill_id == AL_INCAGI || skill_id == AL_BLESSING ||
skill_id == CASH_BLESSING || skill_id == CASH_INCAGI ||
- skill_id == MER_INCAGI || skill_id == MER_BLESSING) && tsd->sc.data[SC_PROPERTYUNDEAD] )
+ skill_id == MER_INCAGI || skill_id == MER_BLESSING) && tsd && tsd->sc.data[SC_PROPERTYUNDEAD] )
damage = 1;
if( damage && sc && sc->data[SC_GENSOU] && dmg.flag&BF_MAGIC ){
@@ -2520,14 +2521,14 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
case RA_CLUSTERBOMB:
case RA_FIRINGTRAP:
case RA_ICEBOUNDTRAP:
- dmg.dmotion = clif->skill_damage(src,bl,tick, dmg.amotion, dmg.dmotion, damage, dmg.div_, skill_id,flag&SD_LEVEL?-1:skill_lv, 5);
+ dmg.dmotion = clif->skill_damage(src,bl,tick, dmg.amotion, dmg.dmotion, damage, dmg.div_, skill_id, (flag&SD_LEVEL) ? -1 : skill_lv, 5);
if( dsrc != src ) // avoid damage display redundancy
break;
case HT_LANDMINE:
dmg.dmotion = clif->skill_damage(dsrc,bl,tick, dmg.amotion, dmg.dmotion, damage, dmg.div_, skill_id, -1, type);
break;
case WZ_SIGHTBLASTER:
- dmg.dmotion = clif->skill_damage(src,bl,tick, dmg.amotion, dmg.dmotion, damage, dmg.div_, skill_id, flag&SD_LEVEL?-1:skill_lv, 5);
+ dmg.dmotion = clif->skill_damage(src,bl,tick, dmg.amotion, dmg.dmotion, damage, dmg.div_, skill_id, (flag&SD_LEVEL) ? -1 : skill_lv, 5);
break;
case AB_DUPLELIGHT_MELEE:
case AB_DUPLELIGHT_MAGIC:
@@ -2642,7 +2643,7 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
if (ud && DIFF_TICK(ud->attackabletime, tick + type) < 0)
ud->attackabletime = tick + type;
}
-
+
shadow_flag = skill->check_shadowform(bl, damage, dmg.div_);
if( !dmg.amotion ) {
@@ -2690,11 +2691,11 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
break;
}
-
+
/* monsters with skill lv higher than MAX_SKILL_LEVEL may get this value beyond the max depending on conditions, we cap to the system's limit */
if( dsrc && dsrc->type == BL_MOB && skill_lv > MAX_SKILL_LEVEL && dmg.blewcount > 25 )
dmg.blewcount = 25;
-
+
//blown-specific handling
switch( skill_id ) {
case LG_OVERBRAND_BRANDISH:
@@ -2840,9 +2841,9 @@ void skill_attack_display_unknown(int *attack_type, struct block_list* src, stru
if (bl->type == BL_SKILL ) {
TBL_SKILL *su = (TBL_SKILL*)bl;
if (su->group && skill->get_inf2(su->group->skill_id) & INF2_TRAP) // show damage on trap targets
- clif->skill_damage(src, bl, *tick, dmg->amotion, dmg->dmotion, *damage, dmg->div_, *skill_id, *flag & SD_LEVEL ? -1 : *skill_lv, 5);
+ clif->skill_damage(src, bl, *tick, dmg->amotion, dmg->dmotion, *damage, dmg->div_, *skill_id, (*flag & SD_LEVEL) ? -1 : *skill_lv, 5);
}
- dmg->dmotion = clif->skill_damage(dsrc, bl, *tick, dmg->amotion, dmg->dmotion, *damage, dmg->div_, *skill_id, *flag & SD_LEVEL ? -1 : *skill_lv, *type);
+ dmg->dmotion = clif->skill_damage(dsrc, bl, *tick, dmg->amotion, dmg->dmotion, *damage, dmg->div_, *skill_id, (*flag & SD_LEVEL) ? -1 : *skill_lv, *type);
}
int skill_attack_copy_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag) {
@@ -3248,22 +3249,20 @@ int skill_timerskill(int tid, int64 tick, int id, intptr_t data) {
/**
* Warlock
**/
- case WL_CHAINLIGHTNING_ATK: {
- struct block_list *nbl = NULL; // Next Target of Chain
- skill->attack(BF_MAGIC, src, src, target, skl->skill_id, skl->skill_lv, tick, (9-skl->type)); // Hit a Lightning on the current Target
- skill->toggle_magicpower(src, skl->skill_id); // only the first hit will be amplify
-
- if( skl->type < (4 + skl->skill_lv - 1) && skl->x < 3 )
- { // Remaining Chains Hit
- nbl = battle->get_enemy_area(src, target->x, target->y, (skl->type>2)?2:3, // After 2 bounces, it will bounce to other targets in 7x7 range.
- BL_CHAR|BL_SKILL, target->id); // Search for a new Target around current one...
- if( nbl == NULL)
- skl->x++;
- else
- skl->x = 0;
-
- skill->addtimerskill(src, tick + 651, (nbl?nbl:target)->id, skl->x, 0, WL_CHAINLIGHTNING_ATK, skl->skill_lv, skl->type + 1, skl->flag);
- }
+ case WL_CHAINLIGHTNING_ATK:
+ skill->attack(BF_MAGIC, src, src, target, skl->skill_id, skl->skill_lv, tick, (9-skl->type)); // Hit a Lightning on the current Target
+ skill->toggle_magicpower(src, skl->skill_id); // only the first hit will be amplify
+
+ if (skl->type < (4 + skl->skill_lv - 1) && skl->x < 3) {
+ // Remaining Chains Hit
+ struct block_list *nbl = battle->get_enemy_area(src, target->x, target->y, (skl->type>2)?2:3, /* After 2 bounces, it will bounce to other targets in 7x7 range. */
+ BL_CHAR|BL_SKILL, target->id); // Search for a new Target around current one...
+ if (nbl == NULL)
+ skl->x++;
+ else
+ skl->x = 0;
+
+ skill->addtimerskill(src, tick + 651, (nbl?nbl:target)->id, skl->x, 0, WL_CHAINLIGHTNING_ATK, skl->skill_lv, skl->type + 1, skl->flag);
}
break;
case WL_TETRAVORTEX_FIRE:
@@ -3795,7 +3794,7 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
short x, y, i = 2; // Move 2 cells for Issen(from target)
struct block_list *mbl = bl;
short dir = 0;
-
+
skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,flag);
if( skill_id == MO_EXTREMITYFIST ) {
@@ -4294,7 +4293,7 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
skill->blown(src,bl,distance_bl(src,bl)-1,unit->getdir(src),0);
- if( sd && tsd && sd->status.party_id && sd->status.party_id && sd->status.party_id == tsd->status.party_id ) // Don't damage party members.
+ if( sd && tsd && sd->status.party_id && tsd->status.party_id && sd->status.party_id == tsd->status.party_id ) // Don't damage party members.
; // No damage to Members
else
skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,flag);
@@ -4371,16 +4370,17 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
break;
case WL_TETRAVORTEX:
- if( sc ){
+ if (sc) {
int i = SC_SUMMON5, x = 0;
int types[][2] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
- for(; i >= SC_SUMMON1; i--){
- if( sc->data[i] ){
- int skillid = WL_TETRAVORTEX_FIRE + (sc->data[i]->val1 - WLS_FIRE) + (sc->data[i]->val1 == WLS_WIND) - (sc->data[i]->val1 == WLS_WATER), sc_index = 0, rate = 0;
- if( x < 4 ){
+ for(; i >= SC_SUMMON1; i--) {
+ if (sc->data[i]) {
+ int skillid = WL_TETRAVORTEX_FIRE + (sc->data[i]->val1 - WLS_FIRE) + (sc->data[i]->val1 == WLS_WIND) - (sc->data[i]->val1 == WLS_WATER);
+ if (x < 4) {
+ int sc_index = 0, rate = 0;
types[x][0] = (sc->data[i]->val1 - WLS_FIRE) + 1;
types[x][1] = 25; // 25% each for equal sharing
- if( x == 3 ){
+ if (x == 3) {
x = 0;
sc_index = types[rnd()%4][0];
for(; x < 4; x++)
@@ -4397,14 +4397,16 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
break;
case WL_RELEASE:
- if( sd ) {
- int i, cooldown;
+ if (sd) {
+ int i;
clif->skill_nodamage(src, bl, skill_id, skill_lv, 1);
skill->toggle_magicpower(src, skill_id);
// Priority is to release SpellBook
- if( sc && sc->data[SC_READING_SB] ) { // SpellBook
+ if (sc && sc->data[SC_READING_SB]) {
+ // SpellBook
uint16 spell_skill_id, spell_skill_lv, point, s = 0;
int spell[SC_SPELLBOOK7-SC_SPELLBOOK1 + 1];
+ int cooldown;
for(i = SC_SPELLBOOK7; i >= SC_SPELLBOOK1; i--) // List all available spell to be released
if( sc->data[i] ) spell[s++] = i;
@@ -4418,9 +4420,11 @@ int skill_castend_damage_id(struct block_list* src, struct block_list *bl, uint1
spell_skill_lv = sc->data[i]->val2;
point = sc->data[i]->val3;
status_change_end(src, (sc_type)i, INVALID_TIMER);
- }else //something went wrong :(
+ } else {
+ //something went wrong :(
break;
-
+ }
+
if( sc->data[SC_READING_SB]->val2 > point )
sc->data[SC_READING_SB]->val2 -= point;
else // Last spell to be released
@@ -4949,11 +4953,11 @@ int skill_castend_id(int tid, int64 tick, int id, intptr_t data) {
else
inf = 0;
- if(inf2 & (INF2_PARTY_ONLY|INF2_GUILD_ONLY) && src != target)
- {
- inf |=
- (inf2&INF2_PARTY_ONLY?BCT_PARTY:0)|
- (inf2&INF2_GUILD_ONLY?BCT_GUILD:0);
+ if (inf2 & (INF2_PARTY_ONLY|INF2_GUILD_ONLY) && src != target) {
+ if (inf2&INF2_PARTY_ONLY)
+ inf |= BCT_PARTY;
+ if (inf2&INF2_GUILD_ONLY)
+ inf |= BCT_GUILD;
//Remove neutral targets (but allow enemy if skill is designed to be so)
inf &= ~BCT_NEUTRAL;
}
@@ -5074,11 +5078,11 @@ int skill_castend_id(int tid, int64 tick, int id, intptr_t data) {
// SC_MAGICPOWER needs to switch states before any damage is actually dealt
skill->toggle_magicpower(src, ud->skill_id);
-
- /* On aegis damage skills are also increase by camouflage. Need confirmation on kRO.
+
+#if 0 // On aegis damage skills are also increase by camouflage. Need confirmation on kRO.
if( ud->skill_id != RA_CAMOUFLAGE ) // only normal attack and auto cast skills benefit from its bonuses
status_change_end(src,SC_CAMOUFLAGE, INVALID_TIMER);
- */
+#endif // 0
if (skill->get_casttype(ud->skill_id) == CAST_NODAMAGE)
skill->castend_nodamage_id(src,target,ud->skill_id,ud->skill_lv,tick,flag);
@@ -5888,12 +5892,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
clif->skill_nodamage(src,bl,skill_id,skill_lv,
sc_start(src,bl,type,100,skill_lv,skill->get_time(skill_id,skill_lv)));
break;
-
case KN_AUTOCOUNTER:
sc_start(src,bl,type,100,skill_lv,skill->get_time(skill_id,skill_lv));
skill->addtimerskill(src, tick + 100, bl->id, 0, 0, skill_id, skill_lv, BF_WEAPON, flag);
break;
-
case SO_STRIKING:
if (sd) {
int bonus = 25 + 10 * skill_lv;
@@ -5905,7 +5907,6 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
);
}
break;
-
case NPC_STOP:
if( clif->skill_nodamage(src,bl,skill_id,skill_lv,
sc_start2(src,bl,type,100,skill_lv,src->id,skill->get_time(skill_id,skill_lv)) ) )
@@ -6881,7 +6882,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
}
}
-
+
if( (i = pc->skillheal_bonus(sd, skill_id)) ) {
hp += hp * i / 100;
sp += sp * i / 100;
@@ -7360,7 +7361,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
//If mode gets set by NPC_EMOTION then the target should be reset [Playtester]
if(skill_id == NPC_EMOTION && md->db->skill[md->skill_idx].val[1])
mob->unlocktarget(md,tick);
-
+
if(md->db->skill[md->skill_idx].val[1] || md->db->skill[md->skill_idx].val[2])
sc_start4(src, src, type, 100, skill_lv,
md->db->skill[md->skill_idx].val[1],
@@ -7693,8 +7694,8 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case CG_TAROTCARD:
{
- int eff, count = -1;
- if( tsc && tsc->data[type] ){
+ int count = -1;
+ if (tsc && tsc->data[type]) {
map->freeblock_unlock();
return 0;
}
@@ -7707,7 +7708,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
}
status_zap(src,0,skill->db[skill->get_index(skill_id)].sp[skill_lv]); // consume sp only if succeeded [Inkfish]
do {
- eff = rnd() % 14;
+ int eff = rnd() % 14;
if( eff == 5 )
clif->specialeffect(src, 528, AREA);
else
@@ -8396,7 +8397,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
break;
case AB_CHEAL:
if( sd == NULL || sd->status.party_id == 0 || flag&1 ) {
- if( sd && tstatus && !battle->check_undead(tstatus->race, tstatus->def_ele) && !tsc->data[SC_BERSERK] ) {
+ if (sd && tstatus && !battle->check_undead(tstatus->race, tstatus->def_ele) && !(tsc && tsc->data[SC_BERSERK])) {
int lv = pc->checkskill(sd, AL_HEAL);
int heal = skill->calc_heal(src, bl, AL_HEAL, lv, true);
@@ -8473,9 +8474,9 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
//As of the behavior in official server Clearance is just a super version of Dispell skill. [Jobbie]
if( bl->type != BL_MOB && battle->check_target(src,bl,BCT_PARTY) <= 0 && sd ) // Only affect mob, party or self.
break;
-
+
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
-
+
if((dstsd && (dstsd->class_&MAPID_UPPERMASK) == MAPID_SOUL_LINKER) || rnd()%100 >= 60 + 8 * skill_lv) {
if (sd)
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
@@ -9421,7 +9422,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
int duration = 3000;
if( !sd->ed )
break;
-
+
switch(sd->ed->db->class_){
case 2115:case 2124:
case 2118:case 2121:
@@ -9432,11 +9433,11 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
duration = 9000;
break;
}
-
+
sd->skill_id_old = skill_id;
elemental->action(sd->ed, bl, tick);
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
-
+
skill->blockpc_start(sd, skill_id, duration);
}
break;
@@ -9778,12 +9779,12 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
case MH_PYROCLASTIC:
if( hd ){
struct block_list *s_bl = battle->get_master(src);
-
+
if(s_bl)
sc_start2(src, s_bl, type, 100, skill_lv, hd->homunculus.level, skill->get_time(skill_id, skill_lv)); //start on master
-
+
sc_start2(src, bl, type, 100, skill_lv, hd->homunculus.level, skill->get_time(skill_id, skill_lv));
-
+
skill->blockhomun_start(hd, skill_id, skill->get_cooldown(skill_id, skill_lv));
}
break;
@@ -9881,9 +9882,9 @@ bool skill_castend_nodamage_id_unknown(struct block_list *src, struct block_list
/*==========================================
*
*------------------------------------------*/
-int skill_castend_pos(int tid, int64 tick, int id, intptr_t data) {
+int skill_castend_pos(int tid, int64 tick, int id, intptr_t data)
+{
struct block_list* src = map->id2bl(id);
- int maxcount;
struct map_session_data *sd;
struct unit_data *ud = unit->bl2ud(src);
struct mob_data *md;
@@ -9913,6 +9914,7 @@ int skill_castend_pos(int tid, int64 tick, int id, intptr_t data) {
ud->skilltimer = INVALID_TIMER;
do {
+ int maxcount;
if( status->isdead(src) )
break;
@@ -10041,10 +10043,10 @@ int skill_castend_pos(int tid, int64 tick, int id, intptr_t data) {
}
static int check_npc_chaospanic(struct block_list* bl, va_list args) {
TBL_NPC* nd = (TBL_NPC*)bl;
-
+
if( nd->option&(OPTION_HIDE|OPTION_INVISIBLE) || nd->class_ != 45 )
return 0;
-
+
return 1;
}
/* skill count without self */
@@ -10436,7 +10438,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
clif->skill_fail(sd,skill_id,USESKILL_FAIL,0);
return 1;
}
-
+
skill->clear_unitgroup(src);
if( skill->unitsetting(src,skill_id,skill_lv,x,y,0) )
sc_start4(src,src,type,100,skill_lv,0,0,src->id,skill->get_time(skill_id,skill_lv));
@@ -10971,13 +10973,13 @@ int skill_dance_overlap_sub(struct block_list* bl, va_list ap) {
int skill_dance_overlap(struct skill_unit* su, int flag) {
if (!su || !su->group || !(su->group->state.song_dance&0x1))
return 0;
-
+
if (su->val1 != su->group->skill_id) {
//Reset state
su->val1 = su->group->skill_id;
su->val2 &= ~UF_ENSEMBLE;
}
-
+
return map->foreachincell(skill->dance_overlap_sub, su->bl.m,su->bl.x,su->bl.y,BL_SKILL, su,flag);
}
@@ -11011,9 +11013,9 @@ bool skill_dance_switch(struct skill_unit* su, int flag) {
}
prevflag = flag;
- if( !flag ) {
+ if (!flag) {
//Transform
- uint16 skill_id = su->val2&UF_SONG ? BA_DISSONANCE : DC_UGLYDANCE;
+ uint16 skill_id = (su->val2&UF_SONG) ? BA_DISSONANCE : DC_UGLYDANCE;
// backup
backup.skill_id = group->skill_id;
@@ -11073,7 +11075,7 @@ struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_
limit = limit * map->list[src->m].units[i]->modifier / 100;
}
}
-
+
sd = BL_CAST(BL_PC, src);
st = status->get_status_data(src);
sc = status->get_sc(src); // for traps, firewall and fogwall - celest
@@ -11418,7 +11420,7 @@ struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_
group->target_flag=target;
group->bl_flag= skill->get_unit_bl_target(skill_id);
group->state.ammo_consume = (sd && sd->state.arrow_atk && skill_id != GS_GROUNDDRIFT); //Store if this skill needs to consume ammo.
- group->state.song_dance = (unit_flag&(UF_DANCE|UF_SONG)?1:0)|(unit_flag&UF_ENSEMBLE?2:0); //Signals if this is a song/dance/duet
+ group->state.song_dance = ((unit_flag&(UF_DANCE|UF_SONG)) ? 1 : 0)|((unit_flag&UF_ENSEMBLE) ? 2 : 0); //Signals if this is a song/dance/duet
group->state.guildaura = ( skill_id >= GD_LEADERSHIP && skill_id <= GD_HAWKEYES )?1:0;
group->item_id = req_item;
//if tick is greater than current, do not invoke onplace function just yet. [Skotlex]
@@ -11440,7 +11442,7 @@ struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_
}
if (
sc_start4(src,src, SC_DANCING, 100, skill_id, group->group_id, skill_lv,
- (group->state.song_dance&2?BCT_SELF:0), limit+1000) &&
+ (group->state.song_dance&2) ? BCT_SELF : 0, limit+1000) &&
sd && group->state.song_dance&2 && skill_id != CG_HERMODE //Hermod is a encore with a warp!
)
skill->check_pc_partner(sd, skill_id, &skill_lv, 1, 1);
@@ -12147,8 +12149,8 @@ int skill_unit_onplace_timer(struct skill_unit *src, struct block_list *bl, int6
|| (sg->src_id == bl->id && !(tsc && tsc->data[SC_SOULLINK] && tsc->data[SC_SOULLINK]->val2 == SL_BARDDANCER))
)
break;
-
- sc_start4(ss, bl, type, 100, sg->skill_lv, sg->val1, sg->val2, 0, sg->limit);
+
+ sc_start4(ss, bl, type, 100, sg->skill_lv, sg->val1, sg->val2, 0, sg->limit);
break;
case UNT_TATAMIGAESHI:
case UNT_DEMONSTRATION:
@@ -13178,7 +13180,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
if( skill_lv < 1 || skill_lv > MAX_SKILL_LEVEL )
return 0;
-
+
require = skill->get_requirement(sd,skill_id,skill_lv);
//Can only update state when weapon/arrow info is checked.
@@ -13226,7 +13228,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
return 0;
if(sc->data[SC_BLADESTOP])
break;
- if( sc && sc->data[SC_COMBOATTACK] ) {
+ if (sc->data[SC_COMBOATTACK]) {
if( sc->data[SC_COMBOATTACK]->val1 == MO_TRIPLEATTACK )
break;
clif->skill_fail(sd, skill_id, USESKILL_FAIL_COMBOSKILL, MO_TRIPLEATTACK);
@@ -13371,11 +13373,11 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
break;
case CG_MOONLIT: //Check there's no wall in the range+1 area around the caster. [Skotlex]
{
- int i,x,y,range = skill->get_splash(skill_id, skill_lv)+1;
+ int i,range = skill->get_splash(skill_id, skill_lv)+1;
int size = range*2+1;
for (i=0;i<size*size;i++) {
- x = sd->bl.x+(i%size-range);
- y = sd->bl.y+(i/size-range);
+ int x = sd->bl.x+(i%size-range);
+ int y = sd->bl.y+(i/size-range);
if (map->getcell(sd->bl.m,x,y,CELL_CHKWALL)) {
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return 0;
@@ -14034,7 +14036,7 @@ int skill_check_condition_castend(struct map_session_data* sd, uint16 skill_id,
}
case NC_SILVERSNIPER:
case NC_MAGICDECOY: {
- int c = 0, j;
+ int c = 0;
int maxcount = skill->get_maxcount(skill_id,skill_lv);
int mob_class = 2042;
if( skill_id == NC_MAGICDECOY )
@@ -14042,7 +14044,8 @@ int skill_check_condition_castend(struct map_session_data* sd, uint16 skill_id,
if( battle_config.land_skill_limit && maxcount > 0 && ( battle_config.land_skill_limit&BL_PC ) ) {
if( skill_id == NC_MAGICDECOY ) {
- for( j = mob_class; j <= 2046; j++ )
+ int j;
+ for(j = mob_class; j <= 2046; j++)
map->foreachinmap(skill->check_condition_mob_master_sub, sd->bl.m, BL_MOB, sd->bl.id, j, skill_id, &c);
} else
map->foreachinmap(skill->check_condition_mob_master_sub, sd->bl.m, BL_MOB, sd->bl.id, mob_class, skill_id, &c);
@@ -14163,8 +14166,7 @@ int skill_consume_requirement( struct map_session_data *sd, uint16 skill_id, uin
req = skill->get_requirement(sd,skill_id,skill_lv);
- if( type&1 ) {
-
+ if (type&1) {
switch( skill_id ) {
case CG_TAROTCARD: // TarotCard will consume sp in skill_cast_nodamage_id [Inkfish]
case MC_IDENTIFY:
@@ -14175,7 +14177,7 @@ int skill_consume_requirement( struct map_session_data *sd, uint16 skill_id, uin
req.sp = 0;
break;
}
-
+
if(req.hp || req.sp)
status_zap(&sd->bl, req.hp, req.sp);
@@ -14632,7 +14634,7 @@ int skill_castfix_sc (struct block_list *bl, int time) {
if( time < 0 )
return 0;
-
+
if( bl->type == BL_MOB ) // mobs casttime is fixed nothing to alter.
return time;
@@ -15128,22 +15130,20 @@ void skill_weaponrefine (struct map_session_data *sd, int idx)
{
nullpo_retv(sd);
- if (idx >= 0 && idx < MAX_INVENTORY)
- {
- int i = 0, ep = 0, per;
- int material[5] = {
- 0,
- ITEMID_PHRACON,
- ITEMID_EMVERETARCON,
- ITEMID_ORIDECON,
- ITEMID_ORIDECON,
- };
+ if (idx >= 0 && idx < MAX_INVENTORY) {
struct item *item;
struct item_data *ditem = sd->inventory_data[idx];
item = &sd->status.inventory[idx];
- if(item->nameid > 0 && ditem->type == IT_WEAPON)
- {
+ if (item->nameid > 0 && ditem->type == IT_WEAPON) {
+ int material[5] = {
+ 0,
+ ITEMID_PHRACON,
+ ITEMID_EMVERETARCON,
+ ITEMID_ORIDECON,
+ ITEMID_ORIDECON,
+ };
+ int i = 0, per;
if( ditem->flag.no_refine ) {
// if the item isn't refinable
clif->skill_fail(sd,sd->menuskill_id,USESKILL_FAIL_LEVEL,0);
@@ -15159,15 +15159,16 @@ void skill_weaponrefine (struct map_session_data *sd, int idx)
}
per = status->get_refine_chance(ditem->wlv, (int)item->refine) * 10;
-
+
// Aegis leaked formula. [malufett]
if( sd->status.class_ == JOB_MECHANIC_T )
per += 100;
else
per += 5 * ((signed int)sd->status.job_level - 50);
-
+
pc->delitem(sd, i, 1, 0, 0, LOG_TYPE_OTHER);
if (per > rnd() % 1000) {
+ int ep = 0;
logs->pick_pc(sd, LOG_TYPE_OTHER, -1, item, ditem);
item->refine++;
logs->pick_pc(sd, LOG_TYPE_OTHER, 1, item, ditem);
@@ -15510,7 +15511,7 @@ int skill_graffitiremover (struct block_list *bl, va_list ap) {
if(bl->type != BL_SKILL)
return 0;
-
+
su = ((struct skill_unit *)bl);
if((su->group) && (su->group->unit_id == UNT_GRAFFITI))
@@ -15542,9 +15543,9 @@ int skill_detonator(struct block_list *bl, va_list ap) {
if( bl->type != BL_SKILL )
return 0;
-
+
su = (struct skill_unit *)bl;
-
+
if( !su->group || su->group->src_id != src->id )
return 0;
@@ -15594,10 +15595,10 @@ int skill_cell_overlap(struct block_list *bl, va_list ap) {
if( su == NULL || su->group == NULL || (*alive) == 0 )
return 0;
-
+
if( su->group->state.guildaura ) /* guild auras are not canceled! */
return 0;
-
+
switch (skill_id) {
case SA_LANDPROTECTOR:
if( su->group->skill_id == SA_LANDPROTECTOR ) {//Check for offensive Land Protector to delete both. [Skotlex]
@@ -15907,16 +15908,16 @@ bool skill_check_camouflage(struct block_list *bl, struct status_change_entry *s
return wall;
}
-bool skill_check_shadowform(struct block_list *bl, int64 damage, int hit){
+bool skill_check_shadowform(struct block_list *bl, int64 damage, int hit)
+{
struct status_change *sc;
- struct block_list *src;
nullpo_retr(false, bl);
sc = status->get_sc(bl);
- if( sc && sc->data[SC__SHADOWFORM] && damage ) {
- src = map->id2bl(sc->data[SC__SHADOWFORM]->val2);
+ if (sc && sc->data[SC__SHADOWFORM] && damage) {
+ struct block_list *src = map->id2bl(sc->data[SC__SHADOWFORM]->val2);
if( !src || src->m != bl->m ) {
status_change_end(bl, SC__SHADOWFORM, INVALID_TIMER);
@@ -16113,12 +16114,14 @@ struct skill_unit_group* skill_initunitgroup (struct block_list* src, int count,
if(i == MAX_SKILLUNITGROUP) {
// array is full, make room by discarding oldest group
int j=0;
- int64 maxdiff = 0, x, tick = timer->gettick();
- for(i=0;i<MAX_SKILLUNITGROUP && ud->skillunit[i];i++)
- if( (x=DIFF_TICK(tick,ud->skillunit[i]->tick)) > maxdiff ) {
- maxdiff = x;
+ int64 maxdiff = 0, tick = timer->gettick();
+ for(i=0;i<MAX_SKILLUNITGROUP && ud->skillunit[i];i++) {
+ int64 diff = DIFF_TICK(tick,ud->skillunit[i]->tick);
+ if (diff > maxdiff) {
+ maxdiff = diff;
j = i;
}
+ }
skill->del_unitgroup(ud->skillunit[j],ALC_MARK);
//Since elements must have shifted, we use the last slot.
i = MAX_SKILLUNITGROUP-1;
@@ -16304,8 +16307,9 @@ int skill_clear_unitgroup (struct block_list *src)
/*==========================================
*
*------------------------------------------*/
-struct skill_unit_group_tickset *skill_unitgrouptickset_search(struct block_list *bl, struct skill_unit_group *group, int64 tick) {
- int i,j=-1,k,s,id;
+struct skill_unit_group_tickset *skill_unitgrouptickset_search(struct block_list *bl, struct skill_unit_group *group, int64 tick)
+{
+ int i,j=-1,s,id;
struct unit_data *ud;
struct skill_unit_group_tickset *set;
@@ -16324,7 +16328,7 @@ struct skill_unit_group_tickset *skill_unitgrouptickset_search(struct block_list
id = s = group->group_id;
for (i=0; i<MAX_SKILLUNITGROUPTICKSET; i++) {
- k = (i+s) % MAX_SKILLUNITGROUPTICKSET;
+ int k = (i+s) % MAX_SKILLUNITGROUPTICKSET;
if (set[k].id == id)
return &set[k];
else if (j==-1 && (DIFF_TICK(tick,set[k].tick)>0 || set[k].id==0))
@@ -16841,14 +16845,15 @@ int skill_can_produce_mix (struct map_session_data *sd, int nameid, int trigger,
}
}
- for(j=0;j<MAX_PRODUCE_RESOURCE;j++){
- int id,x,y;
- if( (id=skill->produce_db[i].mat_id[j]) <= 0 )
+ for (j = 0; j < MAX_PRODUCE_RESOURCE; j++) {
+ int id = skill->produce_db[i].mat_id[j];
+ if (id <= 0)
continue;
if (skill->produce_db[i].mat_amount[j] <= 0) {
if (pc->search_inventory(sd,id) == INDEX_NOT_FOUND)
return 0;
} else {
+ int x, y;
for(y=0,x=0;y<MAX_INVENTORY;y++)
if( sd->status.inventory[y].nameid == id )
x+=sd->status.inventory[y].amount;
@@ -17657,7 +17662,7 @@ int skill_select_menu(struct map_session_data *sd,uint16 skill_id) {
aslvl = sd->sc.data[SC_STOP]->val1;
status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
}
-
+
idx = skill->get_index(skill_id);
if( skill_id >= GS_GLITTERING || skill->get_type(skill_id) != BF_MAGIC ||
@@ -17681,8 +17686,8 @@ int skill_elementalanalysis(struct map_session_data* sd, int n, uint16 skill_lv,
if( n <= 0 )
return 1;
- for( i = 0; i < n; i++ ) {
- int nameid, add_amount, del_amount, idx, product, flag;
+ for (i = 0; i < n; i++) {
+ int nameid, add_amount, del_amount, idx, product;
struct item tmp_item;
idx = item_list[i*2+0]-2;
@@ -17730,8 +17735,9 @@ int skill_elementalanalysis(struct map_session_data* sd, int n, uint16 skill_lv,
tmp_item.amount = add_amount;
tmp_item.identify = 1;
- if( tmp_item.amount ) {
- if( (flag = pc->additem(sd,&tmp_item,tmp_item.amount,LOG_TYPE_CONSUME)) ) {
+ if (tmp_item.amount) {
+ int flag = pc->additem(sd,&tmp_item,tmp_item.amount,LOG_TYPE_CONSUME);
+ if (flag) {
clif->additem(sd,0,0,flag);
map->addflooritem(&tmp_item,tmp_item.amount,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
}
@@ -17835,21 +17841,21 @@ int skill_blockpc_end(int tid, int64 tick, int id, intptr_t data) {
if( ( cd = idb_get(skill->cd_db,sd->status.char_id) ) ) {
int i;
-
+
for( i = 0; i < cd->cursor; i++ ) {
if( cd->entry[i]->skidx == data )
break;
}
-
+
if (i == cd->cursor) {
ShowError("skill_blockpc_end: '%s': no data found for '%"PRIdPTR"'\n", sd->status.name, data);
} else {
int cursor = 0;
-
+
ers_free(skill->cd_entry_ers, cd->entry[i]);
-
+
cd->entry[i] = NULL;
-
+
for( i = 0, cursor = 0; i < cd->cursor; i++ ) {
if( !cd->entry[i] )
continue;
@@ -17857,14 +17863,14 @@ int skill_blockpc_end(int tid, int64 tick, int id, intptr_t data) {
cd->entry[cursor] = cd->entry[i];
cursor++;
}
-
+
if( (cd->cursor = cursor) == 0 ) {
idb_remove(skill->cd_db,sd->status.char_id);
ers_free(skill->cd_ers, cd);
}
}
}
-
+
sd->blockskill[data] = false;
return 1;
}
@@ -17890,15 +17896,14 @@ int skill_blockpc_start_(struct map_session_data *sd, uint16 skill_id, int tick)
sd->blockskill[idx] = false;
return -1;
}
-
+
if( battle_config.display_status_timers )
clif->skill_cooldown(sd, skill_id, tick);
-
+
if( !(cd = idb_get(skill->cd_db,sd->status.char_id)) ) {// create a new skill cooldown object for map storage
cd = ers_alloc(skill->cd_ers, struct skill_cd);
-
+
idb_put( skill->cd_db, sd->status.char_id, cd );
-
} else {
int i;
@@ -17906,7 +17911,7 @@ int skill_blockpc_start_(struct map_session_data *sd, uint16 skill_id, int tick)
if( cd->entry[i] && cd->entry[i]->skidx == idx )
break;
}
-
+
if( i != cd->cursor ) {/* duplicate, update necessary */
cd->entry[i]->duration = tick;
#if PACKETVER >= 20120604
@@ -17919,9 +17924,9 @@ int skill_blockpc_start_(struct map_session_data *sd, uint16 skill_id, int tick)
int cursor;
/** somehow, the timer vanished. (bugreport:8367) **/
ers_free(skill->cd_entry_ers, cd->entry[i]);
-
+
cd->entry[i] = NULL;
-
+
for( i = 0, cursor = 0; i < cd->cursor; i++ ) {
if( !cd->entry[i] )
continue;
@@ -17929,20 +17934,19 @@ int skill_blockpc_start_(struct map_session_data *sd, uint16 skill_id, int tick)
cd->entry[cursor] = cd->entry[i];
cursor++;
}
-
+
cd->cursor = cursor;
}
}
-
}
-
+
if( cd->cursor == MAX_SKILL_TREE ) {
ShowError("skill_blockpc_start: '%s' got over '%d' skill cooldowns, no room to save!\n",sd->status.name,MAX_SKILL_TREE);
return -1;
}
-
+
cd->entry[cd->cursor] = ers_alloc(skill->cd_entry_ers,struct skill_cd_entry);
-
+
cd->entry[cd->cursor]->duration = tick;
#if PACKETVER >= 20120604
cd->entry[cd->cursor]->total = tick;
@@ -17951,7 +17955,7 @@ int skill_blockpc_start_(struct map_session_data *sd, uint16 skill_id, int tick)
cd->entry[cd->cursor]->skill_id = skill_id;
cd->entry[cd->cursor]->started = now;
cd->entry[cd->cursor]->timer = timer->add(now+tick,skill->blockpc_end,sd->bl.id,idx);
-
+
cd->cursor++;
sd->blockskill[idx] = true;
@@ -18041,23 +18045,9 @@ void skill_usave_trigger(struct map_session_data *sd) {
/*
*
*/
-int skill_split_str (char *str, char **val, int num) {
- int i;
-
- for( i = 0; i < num && str; i++ ) {
- val[i] = str;
- str = strchr(str,',');
- if( str )
- *str++=0;
- }
-
- return i;
-}
-/*
- *
- */
-int skill_split_atoi (char *str, int *val) {
- int i, j, diff, step = 1;
+int skill_split_atoi(char *str, int *val)
+{
+ int i, j, step = 1;
for (i=0; i<MAX_SKILL_LEVEL; i++) {
if (!str) break;
@@ -18076,7 +18066,7 @@ int skill_split_atoi (char *str, int *val) {
}
//Check for linear change with increasing steps until we reach half of the data acquired.
for (step = 1; step <= i/2; step++) {
- diff = val[i-1] - val[i-step-1];
+ int diff = val[i-1] - val[i-step-1];
for(j = i-1; j >= step; j--)
if ((val[j]-val[j-step]) != diff)
break;
@@ -18100,8 +18090,9 @@ int skill_split_atoi (char *str, int *val) {
/*
*
*/
-void skill_init_unit_layout (void) {
- int i,j,size,pos = 0;
+void skill_init_unit_layout (void)
+{
+ int i,j,pos = 0;
//when != it was already cleared during skill_defaults() no need to repeat
if( runflag == MAPSERVER_ST_RUNNING )
@@ -18109,7 +18100,7 @@ void skill_init_unit_layout (void) {
// standard square layouts go first
for (i=0; i<=MAX_SQUARE_LAYOUT; i++) {
- size = i*2+1;
+ int size = i*2+1;
skill->unit_layout[i].count = size*size;
for (j=0; j<size*size; j++) {
skill->unit_layout[i].dx[j] = (j%size-i);
@@ -18122,7 +18113,7 @@ void skill_init_unit_layout (void) {
for (i=0;i<MAX_SKILL_DB;i++) {
if (!skill->db[i].unit_id[0] || skill->db[i].unit_layout_type[0] != -1)
continue;
-
+
switch (skill->db[i].nameid) {
case MG_FIREWALL:
case WZ_ICEWALL:
@@ -18541,16 +18532,16 @@ void skill_cooldown_save(struct map_session_data * sd) {
int i;
struct skill_cd* cd = NULL;
int64 now = 0;
-
+
// always check to make sure the session properly exists
nullpo_retv(sd);
-
+
if( !(cd = idb_get(skill->cd_db, sd->status.char_id)) ) {// no skill cooldown is associated with this character
return;
}
-
+
now = timer->gettick();
-
+
// process each individual cooldown associated with the character
for( i = 0; i < cd->cursor; i++ ) {
cd->entry[i]->duration = DIFF_TICK32(cd->entry[i]->started+cd->entry[i]->duration,now);
@@ -18560,7 +18551,7 @@ void skill_cooldown_save(struct map_session_data * sd) {
}
}
}
-
+
/**
* reload stored skill cooldowns when a player logs in.
* @param sd the affected player structure
@@ -18578,9 +18569,9 @@ void skill_cooldown_load(struct map_session_data * sd) {
}
clif->cooldown_list(sd->fd,cd);
-
+
now = timer->gettick();
-
+
// process each individual cooldown associated with the character
for( i = 0; i < cd->cursor; i++ ) {
cd->entry[i]->started = now;
@@ -18608,7 +18599,7 @@ bool skill_parse_row_skilldb(char* split[], int columns, int current) {
idx = skill->get_index(skill_id);
if( !idx ) // invalid skill id
return false;
-
+
skill->db[idx].nameid = skill_id;
skill->split_atoi(split[1],skill->db[idx].range);
skill->db[idx].hit = atoi(split[2]);
@@ -18639,7 +18630,7 @@ bool skill_parse_row_skilldb(char* split[], int columns, int current) {
safestrncpy(skill->db[idx].desc, trim(split[16]), sizeof(skill->db[idx].desc));
strdb_iput(skill->name2id_db, skill->db[idx].name, skill_id);
script->set_constant2(skill->db[idx].name,(int)skill_id,0);
-
+
return true;
}
@@ -18820,7 +18811,7 @@ bool skill_parse_row_producedb(char* split[], int columns, int current) {
skill->produce_db[current].mat_id[y] = atoi(split[x]);
skill->produce_db[current].mat_amount[y] = atoi(split[x+1]);
}
-
+
return true;
}
@@ -18987,7 +18978,7 @@ bool skill_parse_row_changematerialdb(char* split[], int columns, int current) {
void skill_readdb(bool minimal) {
// init skill db structures
db_clear(skill->name2id_db);
-
+
/* when != it was called during init and this procedure was already performed by skill_defaults() */
if( runflag == MAPSERVER_ST_RUNNING ) {
memset(skill->db,0,sizeof(skill->db)
@@ -19043,9 +19034,9 @@ void skill_reload (void) {
struct s_mapiterator *iter;
struct map_session_data *sd;
int i,c,k;
-
+
skill->read_db(false);
-
+
//[Ind/Hercules] refresh index cache
for(c = 0; c < CLASS_COUNT; c++) {
for( i = 0; i < MAX_SKILL_TREE; i++ ) {
@@ -19091,7 +19082,7 @@ int do_init_skill(bool minimal) {
ers_chunk_size(skill->cd_entry_ers, 100);
ers_chunk_size(skill->unit_ers, 150);
ers_chunk_size(skill->timer_ers, 150);
-
+
timer->add_func_list(skill->unit_timer,"skill_unit_timer");
timer->add_func_list(skill->castend_id,"skill_castend_id");
timer->add_func_list(skill->castend_pos,"skill_castend_pos");
@@ -19099,12 +19090,11 @@ int do_init_skill(bool minimal) {
timer->add_func_list(skill->blockpc_end, "skill_blockpc_end");
timer->add_interval(timer->gettick()+SKILLUNITTIMER_INTERVAL,skill->unit_timer,0,0,SKILLUNITTIMER_INTERVAL);
-
+
return 0;
}
int do_final_skill(void) {
-
db_destroy(skill->name2id_db);
db_destroy(skill->group_db);
db_destroy(skill->unit_db);
@@ -19121,7 +19111,7 @@ int do_final_skill(void) {
void skill_defaults(void) {
const int skill_enchant_eff[5] = { 10, 14, 17, 19, 20 };
const int skill_deluge_eff[5] = { 5, 9, 12, 14, 15 };
-
+
skill = &skill_s;
skill->init = do_init_skill;
skill->final = do_final_skill;
diff --git a/src/map/status.c b/src/map/status.c
index 6836d9b70..9ad8d849f 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -1284,7 +1284,7 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp,
//&4: Also delete object from memory.
switch (target->type) {
case BL_PC: flag = pc->dead((TBL_PC*)target,src); break;
- case BL_MOB: flag = mob->dead((TBL_MOB*)target, src, flag&4?3:0); break;
+ case BL_MOB: flag = mob->dead((TBL_MOB*)target, src, (flag&4) ? 3 : 0); break;
case BL_HOM: flag = homun->dead((TBL_HOM*)target); break;
case BL_MER: flag = mercenary->dead((TBL_MER*)target); break;
case BL_ELEM: flag = elemental->dead((TBL_ELEM*)target); break;
@@ -1423,7 +1423,7 @@ int status_heal(struct block_list *bl,int64 in_hp,int64 in_sp, int flag) {
// send hp update to client
switch(bl->type) {
- case BL_PC: pc->heal((TBL_PC*)bl,hp,sp,flag&2?1:0); break;
+ case BL_PC: pc->heal((TBL_PC*)bl,hp,sp,(flag&2) ? 1 : 0); break;
case BL_MOB: mob->heal((TBL_MOB*)bl,hp); break;
case BL_HOM: homun->healed((TBL_HOM*)bl); break;
case BL_MER: mercenary->heal((TBL_MER*)bl,hp,sp); break;
@@ -1905,7 +1905,7 @@ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) {
if (flag&8 && mbl) {
struct status_data *masterstatus = status->get_base_status(mbl);
if ( masterstatus ) {
- if (battle_config.slaves_inherit_speed&(masterstatus->mode&MD_CANMOVE ? 1 : 2))
+ if (battle_config.slaves_inherit_speed&((masterstatus->mode&MD_CANMOVE) ? 1 : 2))
mstatus->speed = masterstatus->speed;
if (mstatus->speed < 2) /* minimum for the unit to function properly */
mstatus->speed = 2;
@@ -2479,16 +2479,16 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
if(i == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index))
continue;
- if(sd->inventory_data[index]) {
- int j,c;
+ if (sd->inventory_data[index]) {
+ int j;
struct item_data *data;
//Card script execution.
- if(itemdb_isspecial(sd->status.inventory[index].card[0]))
+ if (itemdb_isspecial(sd->status.inventory[index].card[0]))
continue;
- for(j=0;j<MAX_SLOTS;j++) {
+ for (j = 0; j < MAX_SLOTS; j++) {
// Uses MAX_SLOTS to support Soul Bound system [Inkfish]
- status->current_equip_card_id= c= sd->status.inventory[index].card[j];
+ int c = status->current_equip_card_id = sd->status.inventory[index].card[j];
if(!c)
continue;
data = itemdb->exists(c);
@@ -3689,7 +3689,7 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
if(flag&SCB_MATK) {
status->update_matk(bl);
}
-
+
if ( flag&SCB_DSPD ) {
int dmotion;
if ( bl->type&BL_PC ) {
@@ -4691,7 +4691,7 @@ unsigned short status_calc_watk(struct block_list *bl, struct status_change *sc,
|| (sc->data[SC_EARTH_INSIGNIA] && sc->data[SC_EARTH_INSIGNIA]->val1 == 2)
)
watk += watk / 10;
- if( sc && sc->data[SC_TIDAL_WEAPON] )
+ if(sc->data[SC_TIDAL_WEAPON])
watk += watk * sc->data[SC_TIDAL_WEAPON]->val2 / 100;
if(sc->data[SC_ANGRIFFS_MODUS])
watk += watk * sc->data[SC_ANGRIFFS_MODUS]->val2/100;
@@ -4975,100 +4975,101 @@ signed short status_calc_flee2(struct block_list *bl, struct status_change *sc,
return (short)cap_value(flee2,10,SHRT_MAX);
}
-defType status_calc_def(struct block_list *bl, struct status_change *sc, int def, bool viewable) {
+defType status_calc_def(struct block_list *bl, struct status_change *sc, int def, bool viewable)
+{
- if(!sc || !sc->count)
+ if (!sc || !sc->count)
return (defType)cap_value(def,DEFTYPE_MIN,DEFTYPE_MAX);
- if( !viewable ){
+ if (!viewable) {
/* some statuses that are hidden in the status window */
- if( sc && sc->data[SC_CAMOUFLAGE] )
+ if (sc->data[SC_CAMOUFLAGE])
def -= def * 5 * (10-sc->data[SC_CAMOUFLAGE]->val4) / 100;
- if( sc->data[SC_OVERED_BOOST] && bl->type == BL_PC )
+ if (sc->data[SC_OVERED_BOOST] && bl->type == BL_PC)
def -= def * 50 / 100;
- if( sc->data[SC_NEUTRALBARRIER] )
+ if (sc->data[SC_NEUTRALBARRIER])
def += def * (10 + 5*sc->data[SC_NEUTRALBARRIER]->val1) / 100;
- if( sc->data[SC_FORCEOFVANGUARD] )
+ if (sc->data[SC_FORCEOFVANGUARD])
def += def * 2 * sc->data[SC_FORCEOFVANGUARD]->val1 / 100;
- if(sc->data[SC_DEFSET])
+ if (sc->data[SC_DEFSET])
return sc->data[SC_DEFSET]->val1;
return (defType)cap_value(def,DEFTYPE_MIN,DEFTYPE_MAX);
}
if (sc->data[SC_BERSERK])
return 0;
- if(sc->data[SC_SKA])
+ if (sc->data[SC_SKA])
return sc->data[SC_SKA]->val3;
- if(sc->data[SC_BARRIER])
+ if (sc->data[SC_BARRIER])
return 100;
- if(sc->data[SC_KEEPING])
+ if (sc->data[SC_KEEPING])
return 90;
#ifndef RENEWAL // does not provide 90 DEF in renewal mode
- if(sc->data[SC_STEELBODY])
+ if (sc->data[SC_STEELBODY])
return 90;
#endif
- if(sc->data[SC_STONEHARDSKIN])
+ if (sc->data[SC_STONEHARDSKIN])
def += sc->data[SC_STONEHARDSKIN]->val1;
- if(sc->data[SC_DRUMBATTLE])
+ if (sc->data[SC_DRUMBATTLE])
def += sc->data[SC_DRUMBATTLE]->val3;
- if(sc->data[SC_STONESKIN])
+ if (sc->data[SC_STONESKIN])
def += sc->data[SC_STONESKIN]->val2;
- if(sc->data[SC_HAMI_DEFENCE]) //[orn]
+ if (sc->data[SC_HAMI_DEFENCE]) //[orn]
def += sc->data[SC_HAMI_DEFENCE]->val2;
- if(sc->data[SC_EARTH_INSIGNIA] && sc->data[SC_EARTH_INSIGNIA]->val1 == 2)
+ if (sc->data[SC_EARTH_INSIGNIA] && sc->data[SC_EARTH_INSIGNIA]->val1 == 2)
def += 50;
- if(sc->data[SC_ODINS_POWER])
+ if (sc->data[SC_ODINS_POWER])
def -= 20;
#ifndef RENEWAL
- if(sc->data[SC_STONE] && sc->opt1 == OPT1_STONE)
+ if (sc->data[SC_STONE] && sc->opt1 == OPT1_STONE)
def >>=1;
- if(sc->data[SC_FREEZE])
+ if (sc->data[SC_FREEZE])
def >>=1;
- if(sc->data[SC_INCDEFRATE])
+ if (sc->data[SC_INCDEFRATE])
def += def * sc->data[SC_INCDEFRATE]->val1/100;
#endif
- if( sc->data[SC_ANGRIFFS_MODUS] )
+ if (sc->data[SC_ANGRIFFS_MODUS])
def -= 30 + 20 * sc->data[SC_ANGRIFFS_MODUS]->val1;
- if(sc->data[SC_CRUCIS])
+ if (sc->data[SC_CRUCIS])
def -= def * sc->data[SC_CRUCIS]->val2/100;
- if(sc->data[SC_LKCONCENTRATION])
+ if (sc->data[SC_LKCONCENTRATION])
def -= def * sc->data[SC_LKCONCENTRATION]->val4/100;
- if(sc->data[SC_SKE])
+ if (sc->data[SC_SKE])
def >>=1;
- if(sc->data[SC_PROVOKE] && bl->type != BL_PC) // Provoke doesn't alter player defense->
+ if (sc->data[SC_PROVOKE] && bl->type != BL_PC) // Provoke doesn't alter player defense->
def -= def * sc->data[SC_PROVOKE]->val4/100;
- if(sc->data[SC_NOEQUIPSHIELD])
+ if (sc->data[SC_NOEQUIPSHIELD])
def -= def * sc->data[SC_NOEQUIPSHIELD]->val2/100;
if (sc->data[SC_FLING])
def -= def * (sc->data[SC_FLING]->val2)/100;
- if( sc->data[SC_ANALYZE] )
+ if (sc->data[SC_ANALYZE])
def -= def * ( 14 * sc->data[SC_ANALYZE]->val1 ) / 100;
- if(sc->data[SC_SATURDAY_NIGHT_FEVER])
+ if (sc->data[SC_SATURDAY_NIGHT_FEVER])
def -= def * (10 + 10 * sc->data[SC_SATURDAY_NIGHT_FEVER]->val1) / 100;
- if(sc->data[SC_EARTHDRIVE])
+ if (sc->data[SC_EARTHDRIVE])
def -= def * 25 / 100;
- if( sc->data[SC_ROCK_CRUSHER] )
+ if (sc->data[SC_ROCK_CRUSHER])
def -= def * sc->data[SC_ROCK_CRUSHER]->val2 / 100;
- if( sc->data[SC_FROSTMISTY] )
+ if (sc->data[SC_FROSTMISTY])
def -= def * 10 / 100;
- if( sc->data[SC_OVERED_BOOST] && bl->type == BL_HOM )
+ if (sc->data[SC_OVERED_BOOST] && bl->type == BL_HOM)
def -= def * 50 / 100;
- if( sc->data[SC_POWER_OF_GAIA] )
+ if (sc->data[SC_POWER_OF_GAIA])
def += def * sc->data[SC_POWER_OF_GAIA]->val2 / 100;
- if( sc->data[SC_SHIELDSPELL_REF] && sc->data[SC_SHIELDSPELL_REF]->val1 == 2 )
+ if (sc->data[SC_SHIELDSPELL_REF] && sc->data[SC_SHIELDSPELL_REF]->val1 == 2)
def += sc->data[SC_SHIELDSPELL_REF]->val2;
- if( sc->data[SC_PRESTIGE] )
+ if (sc->data[SC_PRESTIGE])
def += def * sc->data[SC_PRESTIGE]->val1 / 100;
- if(sc->data[SC_VOLCANIC_ASH] && (bl->type==BL_MOB)){
- if(status_get_race(bl)==RC_PLANT)
+ if (sc->data[SC_VOLCANIC_ASH] && (bl->type==BL_MOB)) {
+ if (status_get_race(bl)==RC_PLANT)
def /= 2;
}
- if(sc->data[SC_UNLIMIT])
+ if (sc->data[SC_UNLIMIT])
return 1;
return (defType)cap_value(def,DEFTYPE_MIN,DEFTYPE_MAX);
@@ -5083,17 +5084,17 @@ signed short status_calc_def2(struct block_list *bl, struct status_change *sc, i
return (short)cap_value(def2,1,SHRT_MAX);
#endif
- if( !viewable ){
+ if (!viewable) {
/* some statuses that are hidden in the status window */
#ifdef RENEWAL
- if( sc && sc->data[SC_ASSUMPTIO] )
+ if (sc->data[SC_ASSUMPTIO])
def2 <<= 1;
#endif
- if( sc && sc->data[SC_CAMOUFLAGE] )
+ if (sc->data[SC_CAMOUFLAGE])
def2 -= def2 * 5 * (10-sc->data[SC_CAMOUFLAGE]->val4) / 100;
- if(sc->data[SC_GENTLETOUCH_REVITALIZE])
+ if (sc->data[SC_GENTLETOUCH_REVITALIZE])
def2 += sc->data[SC_GENTLETOUCH_REVITALIZE]->val2;
- if(sc->data[SC_DEFSET])
+ if (sc->data[SC_DEFSET])
return sc->data[SC_DEFSET]->val1;
#ifdef RENEWAL
return (short)cap_value(def2,SHRT_MIN,SHRT_MAX);
@@ -5104,39 +5105,39 @@ signed short status_calc_def2(struct block_list *bl, struct status_change *sc, i
if (sc->data[SC_BERSERK])
return 0;
- if(sc->data[SC_ETERNALCHAOS])
+ if (sc->data[SC_ETERNALCHAOS])
return 0;
- if(sc->data[SC_SUN_COMFORT])
+ if (sc->data[SC_SUN_COMFORT])
def2 += sc->data[SC_SUN_COMFORT]->val2;
- if( sc->data[SC_BANDING] && sc->data[SC_BANDING]->val2 > 1 )
+ if (sc->data[SC_BANDING] && sc->data[SC_BANDING]->val2 > 1)
def2 += (5 + sc->data[SC_BANDING]->val1) * (sc->data[SC_BANDING]->val2);
- if(sc->data[SC_ANGELUS])
+ if (sc->data[SC_ANGELUS])
#ifdef RENEWAL //in renewal only the VIT stat bonus is boosted by angelus
def2 += status_get_vit(bl) / 2 * sc->data[SC_ANGELUS]->val2/100;
#else
def2 += def2 * sc->data[SC_ANGELUS]->val2/100;
- if(sc->data[SC_LKCONCENTRATION])
+ if (sc->data[SC_LKCONCENTRATION])
def2 -= def2 * sc->data[SC_LKCONCENTRATION]->val4/100;
#endif
- if(sc->data[SC_POISON])
+ if (sc->data[SC_POISON])
def2 -= def2 * 25/100;
- if(sc->data[SC_DPOISON])
+ if (sc->data[SC_DPOISON])
def2 -= def2 * 25/100;
- if(sc->data[SC_SKE])
+ if (sc->data[SC_SKE])
def2 -= def2 * 50/100;
- if(sc->data[SC_PROVOKE])
+ if (sc->data[SC_PROVOKE])
def2 -= def2 * sc->data[SC_PROVOKE]->val4/100;
- if(sc->data[SC_JOINTBEAT])
- def2 -= def2 * ( sc->data[SC_JOINTBEAT]->val2&BREAK_SHOULDER ? 50 : 0 ) / 100
- + def2 * ( sc->data[SC_JOINTBEAT]->val2&BREAK_WAIST ? 25 : 0 ) / 100;
- if(sc->data[SC_FLING])
+ if (sc->data[SC_JOINTBEAT])
+ def2 -= def2 * ((sc->data[SC_JOINTBEAT]->val2&BREAK_SHOULDER) ? 50 : 0) / 100
+ + def2 * ((sc->data[SC_JOINTBEAT]->val2&BREAK_WAIST) ? 25 : 0) / 100;
+ if (sc->data[SC_FLING])
def2 -= def2 * (sc->data[SC_FLING]->val3)/100;
- if(sc->data[SC_ANALYZE])
+ if (sc->data[SC_ANALYZE])
def2 -= def2 * ( 14 * sc->data[SC_ANALYZE]->val1 ) / 100;
- if( sc->data[SC_ECHOSONG] )
+ if (sc->data[SC_ECHOSONG])
def2 += def2 * sc->data[SC_ECHOSONG]->val3/100;
- if(sc->data[SC_VOLCANIC_ASH] && (bl->type==BL_MOB)){
- if(status_get_race(bl)==RC_PLANT)
+ if (sc->data[SC_VOLCANIC_ASH] && (bl->type==BL_MOB)) {
+ if (status_get_race(bl)==RC_PLANT)
def2 /= 2;
}
if (sc->data[SC_NEEDLE_OF_PARALYZE])
@@ -5313,7 +5314,7 @@ unsigned short status_calc_speed(struct block_list *bl, struct status_change *sc
if( sc->data[SC_WEDDING] )
val = max( val, 100 );
if( sc->data[SC_JOINTBEAT] && sc->data[SC_JOINTBEAT]->val2&(BREAK_ANKLE|BREAK_KNEE) )
- val = max( val, (sc->data[SC_JOINTBEAT]->val2&BREAK_ANKLE ? 50 : 0) + (sc->data[SC_JOINTBEAT]->val2&BREAK_KNEE ? 30 : 0) );
+ val = max( val, ((sc->data[SC_JOINTBEAT]->val2&BREAK_ANKLE) ? 50 : 0) + ((sc->data[SC_JOINTBEAT]->val2&BREAK_KNEE) ? 30 : 0) );
if( sc->data[SC_CLOAKING] && (sc->data[SC_CLOAKING]->val4&1) == 0 )
val = max( val, sc->data[SC_CLOAKING]->val1 < 3 ? 300 : 30 - 3 * sc->data[SC_CLOAKING]->val1 );
if( sc->data[SC_GOSPEL] && sc->data[SC_GOSPEL]->val4 == BCT_ENEMY )
@@ -5430,12 +5431,13 @@ unsigned short status_calc_speed(struct block_list *bl, struct status_change *sc
// flag&2 - percentage value
short status_calc_aspd(struct block_list *bl, struct status_change *sc, short flag) {
#ifdef RENEWAL_ASPD
- int i, pots = 0, bonus = 0;
+ int pots = 0, bonus = 0;
if (!sc || !sc->count)
return 0;
if (flag&1) {
+ int i;
// ASPD fixed values
if (sc->data[i=SC_ATTHASTE_INFINITY]
|| sc->data[i=SC_ATTHASTE_POTION3]
@@ -5443,7 +5445,7 @@ short status_calc_aspd(struct block_list *bl, struct status_change *sc, short fl
|| sc->data[i=SC_ATTHASTE_POTION1]
)
pots += sc->data[i]->val1;
-
+
if (!sc->data[SC_QUAGMIRE]) {
if(sc->data[SC_TWOHANDQUICKEN] && bonus < 7)
bonus = 7;
@@ -5559,9 +5561,9 @@ short status_calc_fix_aspd(struct block_list *bl, struct status_change *sc, int
if ((sc->data[SC_GUST_OPTION] || sc->data[SC_BLAST_OPTION]
|| sc->data[SC_WILD_STORM_OPTION]))
aspd -= 50; // +5 ASPD
- if( sc && sc->data[SC_FIGHTINGSPIRIT] && sc->data[SC_FIGHTINGSPIRIT]->val2 )
+ if (sc->data[SC_FIGHTINGSPIRIT] && sc->data[SC_FIGHTINGSPIRIT]->val2)
aspd -= (bl->type==BL_PC?pc->checkskill((TBL_PC *)bl, RK_RUNEMASTERY):10) / 10 * 40;
- if( sc && sc->data[SC_MTF_ASPD] )
+ if (sc->data[SC_MTF_ASPD])
aspd -= 10;
if (sc->data[SC_OVERED_BOOST]) // should be final and unmodifiable by any means
@@ -7957,9 +7959,9 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t
case SC_AUTOGUARD:
if( !(flag&SCFLAG_NOAVOID) ) {
struct map_session_data *tsd;
- int i,t;
- for( i = val2 = 0; i < val1; i++) {
- t = 5-(i>>1);
+ int i;
+ for (i = val2 = 0; i < val1; i++) {
+ int t = 5-(i>>1);
val2 += (t < 0)? 1:t;
}
@@ -8124,17 +8126,17 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t
struct block_list *d_bl;
struct status_change *d_sc;
- if( (d_bl = map->id2bl(val1)) && (d_sc = status->get_sc(d_bl)) && d_sc->count ) {
+ if ((d_bl = map->id2bl(val1)) && (d_sc = status->get_sc(d_bl)) && d_sc->count) {
// Inherits Status From Source
const enum sc_type types[] = { SC_AUTOGUARD, SC_DEFENDER, SC_REFLECTSHIELD, SC_ENDURE };
- enum sc_type type2;
int i = (map_flag_gvg(bl->m) || map->list[bl->m].flag.battleground)?2:3;
- while( i >= 0 ) {
- type2 = types[i];
- if( d_sc->data[type2] )
+ while (i >= 0) {
+ enum sc_type type2 = types[i];
+ if (d_sc->data[type2]) {
status->change_start(bl, bl, type2, 10000, d_sc->data[type2]->val1, 0, 0, 0,
skill->get_time(status->sc2skill(type2),d_sc->data[type2]->val1),
(type2 != SC_DEFENDER) ? SCFLAG_NOICON : SCFLAG_NONE);
+ }
i--;
}
}
@@ -9919,28 +9921,23 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
int prevline = 0;
struct map_session_data *dsd;
struct status_change_entry *dsc;
- struct skill_unit_group *group;
- if( sd )
- {
- if( sd->delunit_prevfile )
- {// initially this is NULL, when a character logs in
+ if (sd) {
+ if (sd->delunit_prevfile) {
+ // initially this is NULL, when a character logs in
prevfile = sd->delunit_prevfile;
prevline = sd->delunit_prevline;
- }
- else
- {
+ } else {
prevfile = "<none>";
}
sd->delunit_prevfile = file;
sd->delunit_prevline = line;
}
- if(sce->val4 && sce->val4 != BCT_SELF && (dsd=map->id2sd(sce->val4)))
- {// end status on partner as well
+ if (sce->val4 && sce->val4 != BCT_SELF && (dsd=map->id2sd(sce->val4))) {
+ // end status on partner as well
dsc = dsd->sc.data[SC_DANCING];
- if(dsc) {
-
+ if (dsc) {
//This will prevent recursive loops.
dsc->val2 = dsc->val4 = 0;
@@ -9948,12 +9945,11 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
}
}
- if(sce->val2)
- {// erase associated land skill
- group = skill->id2group(sce->val2);
+ if (sce->val2) {
+ // erase associated land skill
+ struct skill_unit_group *group = skill->id2group(sce->val2);
- if( group == NULL )
- {
+ if (group == NULL) {
ShowDebug("status_change_end: SC_DANCING is missing skill unit group (val1=%d, val2=%d, val3=%d, val4=%d, timer=%d, tid=%d, char_id=%d, map=%s, x=%d, y=%d, prev=%s:%d, from=%s:%d). Please report this! (#3504)\n",
sce->val1, sce->val2, sce->val3, sce->val4, sce->timer, tid,
sd ? sd->status.char_id : 0,
@@ -9966,7 +9962,7 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
skill->del_unitgroup(group,ALC_MARK);
}
- if((sce->val1&0xFFFF) == CG_MOONLIT)
+ if ((sce->val1&0xFFFF) == CG_MOONLIT)
clif->sc_end(bl,bl->id,AREA,SI_MOON);
status_change_end(bl, SC_LONGING, INVALID_TIMER);
@@ -10922,14 +10918,13 @@ int status_change_timer(int tid, int64 tick, int id, intptr_t data) {
if( !flag ) { // Random Skill Cast
if (sd && !pc_issit(sd)) { //can't cast if sit
- int mushroom_skill_id = 0, i;
+ int mushroom_skill_id = 0;
unit->stop_attack(bl);
unit->skillcastcancel(bl,0);
do {
- i = rnd() % MAX_SKILL_MAGICMUSHROOM_DB;
+ int i = rnd() % MAX_SKILL_MAGICMUSHROOM_DB;
mushroom_skill_id = skill->magicmushroom_db[i].skill_id;
- }
- while( mushroom_skill_id == 0 );
+ } while (mushroom_skill_id == 0);
switch( skill->get_casttype(mushroom_skill_id) ) { // Magic Mushroom skills are buffs or area damage
case CAST_GROUND:
@@ -10989,9 +10984,9 @@ int status_change_timer(int tid, int64 tick, int id, intptr_t data) {
return 0;
case SC_RENOVATIO:
- if( --(sce->val4) > 0 ) {
+ if (--(sce->val4) > 0 ){
int heal = st->max_hp * 3 / 100;
- if( sc && sc->data[SC_AKAITSUKI] && heal )
+ if (sc->count && sc->data[SC_AKAITSUKI] && heal)
heal = ~heal + 1;
status->heal(bl, heal, 0, 2);
sc_timer_next(5000 + tick, status->change_timer, bl->id, data);
@@ -11452,14 +11447,16 @@ int status_change_timer_sub(struct block_list* bl, va_list ap) {
int status_get_total_def(struct block_list *src) { return status->get_status_data(src)->def2 + (short)status->get_def(src); }
int status_get_total_mdef(struct block_list *src) { return status->get_status_data(src)->mdef2 + (short)status_get_mdef(src); }
-int status_get_weapon_atk(struct block_list *bl, struct weapon_atk *watk, int flag) {
+int status_get_weapon_atk(struct block_list *bl, struct weapon_atk *watk, int flag)
+{
#ifdef RENEWAL
- int min = 0, max = 0, dstr;
- float strdex_bonus, variance;
+ int min = 0, max = 0;
struct status_change *sc = status->get_sc(bl);
- if ( bl->type == BL_PC && watk->atk ){
- if ( flag&2 )
+ if (bl->type == BL_PC && watk->atk) {
+ float strdex_bonus, variance;
+ int dstr;
+ if (flag&2)
dstr = status_get_dex(bl);
else
dstr = status_get_str(bl);
@@ -11469,23 +11466,20 @@ int status_get_weapon_atk(struct block_list *bl, struct weapon_atk *watk, int fl
min = (int)(watk->atk - variance + strdex_bonus) + watk->atk2;
max = (int)(watk->atk + variance + strdex_bonus) + watk->atk2;
- }
- else if ((bl->type == BL_MOB || bl->type == BL_MER) && watk->atk){
+ } else if ((bl->type == BL_MOB || bl->type == BL_MER) && watk->atk) {
min = watk->atk * 80 / 100;
max = watk->atk * 120 / 100;
- }
- else if (bl->type == BL_HOM && watk->atk){
- if (flag & 4){
+ } else if (bl->type == BL_HOM && watk->atk) {
+ if (flag & 4) {
max = min = status->get_matk(bl, 2);
- }
- else{
+ } else {
min = watk->atk;
max = watk->atk2;
}
}
- if( !(flag&1) ){
- if( max > min )
+ if (!(flag&1)) {
+ if (max > min)
max = min + rnd()%(max - min + 1);
else
max = min;
diff --git a/src/map/trade.c b/src/map/trade.c
index 46acb4e16..379756394 100644
--- a/src/map/trade.c
+++ b/src/map/trade.c
@@ -239,7 +239,6 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd)
struct item inventory2[MAX_INVENTORY];
struct item_data *data;
int trade_i, i, n;
- short amount;
// check zenys value against hackers (Zeny was already checked on time of adding, but you never know when you lost some zeny since then.
if(sd->deal.zeny > sd->status.zeny || (tsd->status.zeny > MAX_ZENY - sd->deal.zeny))
@@ -252,8 +251,8 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd)
memcpy(&inventory2, &tsd->status.inventory, sizeof(struct item) * MAX_INVENTORY);
// check free slot in both inventory
- for(trade_i = 0; trade_i < 10; trade_i++) {
- amount = sd->deal.item[trade_i].amount;
+ for (trade_i = 0; trade_i < 10; trade_i++) {
+ short amount = sd->deal.item[trade_i].amount;
if (amount) {
n = sd->deal.item[trade_i].index;
if (amount > inventory[n].amount)
diff --git a/src/map/unit.c b/src/map/unit.c
index a6edef408..a1c739af3 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -112,13 +112,13 @@ int unit_walktoxy_sub(struct block_list *bl)
if (ud->target_to && ud->chaserange>1) {
//Generally speaking, the walk path is already to an adjacent tile
//so we only need to shorten the path if the range is greater than 1.
- uint8 dir;
+
//Trim the last part of the path to account for range,
//but always move at least one cell when requested to move.
for (i = (ud->chaserange*10)-10; i > 0 && ud->walkpath.path_len>1;) {
- ud->walkpath.path_len--;
- dir = ud->walkpath.path[ud->walkpath.path_len];
- if(dir&1)
+ ud->walkpath.path_len--;
+ uint8 dir = ud->walkpath.path[ud->walkpath.path_len];
+ if (dir&1)
i -= MOVE_COST*20; //When chasing, units will target a diamond-shaped area in range [Playtester]
else
i -= MOVE_COST;
@@ -594,7 +594,7 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
ud->state.walk_easy = flag&1;
ud->target_to = tbl->id;
ud->chaserange = range; //Note that if flag&2, this SHOULD be attack-range
- ud->state.attack_continue = flag&2?1:0; //Chase to attack.
+ ud->state.attack_continue = (flag&2) ? 1 : 0; //Chase to attack.
unit->stop_attack(bl); //Sets target to 0
sc = status->get_sc(bl);
@@ -1760,12 +1760,11 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
*----------------------------------------*/
int unit_set_target(struct unit_data* ud, int target_id)
{
- struct unit_data * ux;
- struct block_list* target;
-
nullpo_ret(ud);
- if( ud->target != target_id ) {
+ if (ud->target != target_id) {
+ struct unit_data * ux;
+ struct block_list* target;
if( ud->target && (target = map->id2bl(ud->target)) && (ux = unit->bl2ud(target)) && ux->target_count > 0 )
ux->target_count --;
if( target_id && (target = map->id2bl(target_id)) && (ux = unit->bl2ud(target)) )
@@ -1949,7 +1948,6 @@ bool unit_can_reach_pos(struct block_list *bl,int x,int y, int easy)
*------------------------------------------*/
bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range, int easy, short *x, short *y)
{
- int i;
short dx,dy;
nullpo_retr(false, bl);
nullpo_retr(false, tbl);
@@ -1970,6 +1968,7 @@ bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range,
dy=(dy>0)?1:((dy<0)?-1:0);
if (map->getcell(tbl->m,tbl->x-dx,tbl->y-dy,CELL_CHKNOPASS)) {
+ int i;
//Look for a suitable cell to place in.
for(i=0;i<8 && map->getcell(tbl->m,tbl->x-dirx[i],tbl->y-diry[i],CELL_CHKNOPASS);i++);
if (i==8) return false; //No valid cells.
@@ -1986,7 +1985,7 @@ bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range,
*------------------------------------------*/
int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
{
- int dx, dy, x, y, i, k;
+ int dx, dy, x, y;
struct unit_data *ud = unit->bl2ud(bl);
nullpo_ret(ud);
@@ -2002,33 +2001,29 @@ int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
x = tx + dx;
y = ty + dy;
- if( !unit->can_reach_pos(bl, x, y, 0) )
- {
+ if (!unit->can_reach_pos(bl, x, y, 0)) {
if( dx > 0 ) x--; else if( dx < 0 ) x++;
if( dy > 0 ) y--; else if( dy < 0 ) y++;
- if( !unit->can_reach_pos(bl, x, y, 0) )
- {
- for( i = 0; i < 12; i++ )
- {
- k = rnd()%8; // Pick a Random Dir
+ if (!unit->can_reach_pos(bl, x, y, 0)) {
+ int i;
+ for (i = 0; i < 12; i++) {
+ int k = rnd()%8; // Pick a Random Dir
dx = -dirx[k] * 2;
dy = -diry[k] * 2;
x = tx + dx;
y = ty + dy;
- if( unit->can_reach_pos(bl, x, y, 0) )
+ if (unit->can_reach_pos(bl, x, y, 0)) {
break;
- else
- {
+ } else {
if( dx > 0 ) x--; else if( dx < 0 ) x++;
if( dy > 0 ) y--; else if( dy < 0 ) y++;
if( unit->can_reach_pos(bl, x, y, 0) )
break;
}
}
- if( i == 12 )
- {
+ if (i == 12) {
x = tx; y = tx; // Exactly Master Position
- if( !unit->can_reach_pos(bl, x, y, 0) )
+ if (!unit->can_reach_pos(bl, x, y, 0))
return 1;
}
}
@@ -2726,7 +2721,6 @@ int unit_free(struct block_list *bl, clr_type clrtype) {
}
case BL_MOB:
{
- unsigned int k;
struct mob_data *md = (struct mob_data*)bl;
if( md->spawn_timer != INVALID_TIMER )
{
@@ -2784,6 +2778,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) {
if (md->hdata)
{
+ unsigned int k;
for (k = 0; k < md->hdatac; k++) {
if( md->hdata[k]->flag.free ) {
aFree(md->hdata[k]->data);
diff --git a/src/test/test_spinlock.c b/src/test/test_spinlock.c
index 1b31e9b46..19ae9aee7 100644
--- a/src/test/test_spinlock.c
+++ b/src/test/test_spinlock.c
@@ -20,7 +20,7 @@
static SPIN_LOCK lock;
-static int val = 0;
+static unsigned int val = 0;
static volatile int32 done_threads = 0;
static void *worker(void *p){
@@ -72,10 +72,10 @@ int do_init(int argc, char **argv){
FinalizeSpinLock(&lock);
// Everything fine?
- if(val != (THRC*PERINC) ){
- printf("FAILED! (Result: %u, Expected: %u)\n", val, (THRC*PERINC) );
- }else{
- printf("OK! (Result: %u, Expected: %u)\n", val, (THRC*PERINC) );
+ if (val != (THRC*PERINC)) {
+ printf("FAILED! (Result: %u, Expected: %u)\n", val, (THRC*PERINC));
+ } else {
+ printf("OK! (Result: %u, Expected: %u)\n", val, (THRC*PERINC));
ok++;
}
diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c
index 5376458dc..4b2b4bd49 100644
--- a/src/tool/mapcache.c
+++ b/src/tool/mapcache.c
@@ -66,8 +66,6 @@ int read_map(char *name, struct map_data *m)
unsigned char *gat, *rsw;
int water_height;
size_t xy, off, num_cells;
- float height;
- uint32 type;
// Open map GAT
sprintf(filename,"data\\%s.gat", name);
@@ -98,12 +96,11 @@ int read_map(char *name, struct map_data *m)
// Set cell properties
off = 14;
- for (xy = 0; xy < num_cells; xy++)
- {
+ for (xy = 0; xy < num_cells; xy++) {
// Height of the bottom-left corner
- height = GetFloat( gat + off );
+ float height = GetFloat(gat + off);
// Type of cell
- type = GetULong( gat + off + 16 );
+ uint32 type = GetULong(gat + off + 16);
off += 20;
if (type == 0 && water_height != NO_WATER && height > water_height)